6 extern int reverse_video;
8 extern char label_color[];
9 extern char math_color[];
10 extern char math_frame_color[];
11 extern char latex_color[];
12 extern char foot_color[];
13 extern char new_line_color[];
14 extern char fill_color[];
15 extern int fast_selection;
16 extern char on_off_line_color[];
17 extern string background_color;
18 extern char lighted_color[];
19 extern char selection_color[];
20 extern char note_color[];
21 extern char note_frame_color[];
23 Colormap color_map = 0;
24 long int background_pixels;
27 char const * const X11Color[11] =
28 { "black", "black", "white", "red", "green", "blue", "cyan", "magenta",
29 "yellow", "black", "black" };
31 // Different graphic contexts
32 static GC clear_gc = 0;
33 static GC latex_gc = 0;
34 static GC foot_gc = 0;
35 static GC new_line_gc = 0;
36 static GC math_gc = 0;
37 static GC math_frame_gc = 0;
38 static GC fill_gc = 0;
39 static GC note_gc = 0;
40 static GC note_frame_gc = 0;
41 static GC copy_gc = 0;
42 static GC select_gc = 0;
43 static GC on_off_line_gc = 0;
44 static GC thin_on_off_line_gc = 0;
45 static GC thick_line_gc = 0;
46 static GC lighted_gc = 0;
47 static GC selection_gc = 0;
48 static GC accent_gc[10] = { 0, 0, 0, 0, 0,
50 static GC color_gc[11] = { 0, 0, 0, 0, 0, 0,
52 static GC minipage_gc = 0;
55 // Allocates color and sets it as foreground
56 // Returns "false" if unsuccesful
57 bool setForegroundColor(char const * const color, XGCValues & val)
61 color_map = fl_state[fl_get_vclass()].colormap;
64 if (XParseColor(fl_display, color_map, color, &xcol)
65 && XAllocColor(fl_display, color_map, &xcol))
67 val.foreground = xcol.pixel;
69 lyxerr << "LyX: Couldn't get color "
79 void do_reverse_video(XGCValues &val)
82 val.foreground= WhitePixel(fl_display,
83 DefaultScreen(fl_display));
84 val.background= BlackPixel(fl_display,
85 DefaultScreen(fl_display));
87 val.foreground= BlackPixel(fl_display,
88 DefaultScreen(fl_display));
89 val.background= WhitePixel(fl_display,
90 DefaultScreen(fl_display));
96 GC make_normal_gc(const char* color)
99 do_reverse_video(val);
100 val.function = GXcopy;
101 val.graphics_exposures = false;
102 setForegroundColor(color, val);
103 return XCreateGC(fl_display, fl_root,
104 GCBackground | GCForeground | GCFunction |
105 GCGraphicsExposures, &val);
112 if (note_gc) return note_gc;
114 note_gc = make_normal_gc(note_color);
123 if (note_frame_gc) return note_frame_gc;
125 note_frame_gc = make_normal_gc(note_frame_color);
127 return note_frame_gc;
134 if (math_gc) return math_gc;
136 math_gc = make_normal_gc(math_color);
145 if (latex_gc) return latex_gc;
148 if (reverse_video ^ mono_video) {
149 val.foreground= WhitePixel(fl_display,
150 DefaultScreen(fl_display));
151 val.background= BlackPixel(fl_display,
152 DefaultScreen(fl_display));
154 val.foreground= BlackPixel(fl_display,
155 DefaultScreen(fl_display));
156 val.background= WhitePixel(fl_display,
157 DefaultScreen(fl_display));
159 val.function= GXcopy;
160 val.graphics_exposures = false;
161 setForegroundColor(latex_color, val);
162 latex_gc = XCreateGC(fl_display, fl_root, GCBackground
163 | GCForeground | GCFunction
164 | GCGraphicsExposures,
175 if (foot_gc) return foot_gc;
177 foot_gc = make_normal_gc(foot_color);
186 if (new_line_gc) return new_line_gc;
188 new_line_gc = make_normal_gc(new_line_color);
197 if (math_frame_gc) return math_frame_gc;
199 math_frame_gc = make_normal_gc(math_frame_color);
201 return math_frame_gc;
208 if (fill_gc) return fill_gc;
210 fill_gc = make_normal_gc(fill_color);
219 if (clear_gc) return clear_gc;
224 val.foreground= BlackPixel(fl_display,
225 DefaultScreen(fl_display));
226 val.background= WhitePixel(fl_display,
227 DefaultScreen(fl_display));
229 val.background= BlackPixel(fl_display,
230 DefaultScreen(fl_display));
231 val.foreground= WhitePixel(fl_display,
232 DefaultScreen(fl_display));
234 val.function = GXcopy;
235 val.graphics_exposures = false;
236 if (!fast_selection && background_color != "white") {
237 setForegroundColor(background_color.c_str(), val);
239 background_pixels = val.foreground;
241 clear_gc = XCreateGC(fl_display, fl_root, GCBackground
242 | GCForeground | GCFunction
243 | GCGraphicsExposures,
254 if (on_off_line_gc) return on_off_line_gc;
257 do_reverse_video(val);
259 val.function= GXcopy;
260 val.graphics_exposures = false;
261 setForegroundColor(on_off_line_color, val);
263 val.line_style = LineOnOffDash;
264 on_off_line_gc = XCreateGC(fl_display, fl_root,
265 GCBackground | GCForeground | GCFunction |
266 GCGraphicsExposures | GCLineWidth |
270 return on_off_line_gc;
277 if (thick_line_gc) return thick_line_gc;
279 do_reverse_video(val);
281 val.function= GXcopy;
282 val.graphics_exposures = false;
284 val.line_style = LineSolid;
285 thick_line_gc = XCreateGC(fl_display, fl_root, GCBackground
286 | GCForeground | GCFunction
287 | GCGraphicsExposures
288 | GCLineWidth | GCLineStyle , &val);
291 return thick_line_gc;
296 GC GetThinOnOffLineGC()
298 if (thin_on_off_line_gc) return thin_on_off_line_gc;
300 do_reverse_video(val);
302 val.function= GXcopy;
303 val.graphics_exposures = false;
304 val.line_style = LineOnOffDash;
306 thin_on_off_line_gc =
307 XCreateGC(fl_display, fl_root, GCBackground
308 | GCForeground | GCFunction | GCGraphicsExposures
309 | GCLineWidth | GCLineStyle , &val);
312 return thin_on_off_line_gc;
319 if (copy_gc) return copy_gc;
321 do_reverse_video(val);
323 val.function= GXcopy;
324 val.graphics_exposures = false;
325 val.line_style = LineSolid;
327 copy_gc = XCreateGC(fl_display, fl_root, GCBackground
328 | GCForeground | GCFunction | GCGraphicsExposures
329 | GCLineWidth | GCLineStyle , &val);
339 if (select_gc) return select_gc;
341 unsigned int a = BlackPixel(fl_display, DefaultScreen(fl_display));
342 unsigned int b = WhitePixel(fl_display, DefaultScreen(fl_display));
343 val.plane_mask = a^b;
344 val.line_style = LineSolid;
346 val.graphics_exposures = false;
347 val.function= GXinvert;
348 select_gc = XCreateGC(fl_display, fl_root,
349 GCFunction | GCGraphicsExposures | GCPlaneMask
350 | GCLineWidth | GCLineStyle , &val);
360 if (selection_gc) return selection_gc;
364 if (!reverse_video) {
365 val.foreground= BlackPixel(fl_display,
366 DefaultScreen(fl_display));
367 val.background= WhitePixel(fl_display,
368 DefaultScreen(fl_display));
370 val.background= BlackPixel(fl_display,
371 DefaultScreen(fl_display));
372 val.foreground= WhitePixel(fl_display,
373 DefaultScreen(fl_display));
376 val.function= GXcopy;
377 val.graphics_exposures = false;
378 if (!fast_selection && selection_color[0] != 0) {
379 if (!setForegroundColor(selection_color, val)) {
380 fast_selection = True;
381 if (clear_gc) clear_gc = 0;
382 lyxerr << " Will use FastSelection-method."
386 selection_gc = XCreateGC(fl_display, fl_root,
387 GCBackground | GCForeground | GCFunction
388 | GCGraphicsExposures, &val);
397 if (lighted_gc) return lighted_gc;
400 val.background= BlackPixel(fl_display,
401 DefaultScreen(fl_display));
403 val.background= WhitePixel(fl_display,
404 DefaultScreen(fl_display));
406 val.foreground= val.background;
407 val.function= GXcopy;
408 val.graphics_exposures = false;
409 val.line_style = LineSolid;
411 setForegroundColor(lighted_color, val);
412 lighted_gc = XCreateGC(fl_display, fl_root, GCBackground
413 | GCForeground | GCFunction
414 | GCGraphicsExposures
415 | GCLineWidth | GCLineStyle , &val);
422 GC GetColorGC(LyXFont::FONT_COLOR color)
424 if (color_gc[color]) return color_gc[color];
427 do_reverse_video(val);
429 val.function= GXcopy;
430 val.graphics_exposures = false;
431 setForegroundColor(X11Color[color], val);
433 val.line_style = LineSolid;
434 color_gc[color] = XCreateGC(fl_display, fl_root,
435 GCBackground | GCForeground | GCFunction |
436 GCGraphicsExposures | GCLineWidth |
440 return color_gc[color];
444 GC GetAccentGC(LyXFont const &f, int line_width)
446 if (line_width >= 10) line_width = 9;
448 if (accent_gc[line_width]) return accent_gc[line_width];
450 // Build this one from normal text GC, but change linewidth.
453 XGetGCValues(fl_display, gc, GCBackground | GCForeground |
454 GCFunction | GCGraphicsExposures | GCLineWidth |
455 GCLineStyle | GCPlaneMask, &val);
457 val.line_width = line_width;
458 val.cap_style = CapRound;
459 val.join_style = JoinRound;
461 GC ac = XCreateGC(fl_display, fl_root,
462 GCBackground | GCForeground | GCFunction |
463 GCGraphicsExposures | GCLineWidth |
464 GCLineStyle | GCPlaneMask, &val);
467 accent_gc[line_width] = ac;
469 return accent_gc[line_width];
476 if (minipage_gc) return minipage_gc;
478 do_reverse_video(val);
480 val.function= GXcopy;
481 val.graphics_exposures = false;
482 val.line_style = LineOnOffDash;
484 setForegroundColor(fill_color, val);
485 minipage_gc = XCreateGC(fl_display, fl_root,
486 GCBackground | GCForeground | GCFunction |
487 GCGraphicsExposures | GCLineWidth |
495 GC getGC(gc_type typ)
515 gc = GetMathFrameGC();
527 gc = GetOnOffLineGC();
529 case gc_thin_on_off_line:
530 gc = GetThinOnOffLineGC();
533 gc = GetThickLineGC();
539 gc = GetSelectionGC();
542 gc = GetMinipageGC();
548 gc = GetNoteFrameGC();