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));
375 val.function= GXcopy;
376 val.graphics_exposures = false;
377 if (!fast_selection && selection_color[0] != 0) {
378 if (!setForegroundColor(selection_color, val)) {
379 fast_selection = True;
380 if (clear_gc) clear_gc = 0;
381 lyxerr << " Will use FastSelection-method."
385 selection_gc = XCreateGC(fl_display, fl_root,
386 GCBackground | GCForeground | GCFunction
387 | GCGraphicsExposures, &val);
396 if (lighted_gc) return lighted_gc;
399 val.background= BlackPixel(fl_display,
400 DefaultScreen(fl_display));
402 val.background= WhitePixel(fl_display,
403 DefaultScreen(fl_display));
405 val.foreground= val.background;
406 val.function= GXcopy;
407 val.graphics_exposures = false;
408 val.line_style = LineSolid;
410 setForegroundColor(lighted_color, val);
411 lighted_gc = XCreateGC(fl_display, fl_root, GCBackground
412 | GCForeground | GCFunction
413 | GCGraphicsExposures
414 | GCLineWidth | GCLineStyle , &val);
421 GC GetColorGC(LyXFont::FONT_COLOR color)
423 if (color_gc[color]) return color_gc[color];
426 do_reverse_video(val);
428 val.function= GXcopy;
429 val.graphics_exposures = false;
430 setForegroundColor(X11Color[color], val);
432 val.line_style = LineSolid;
433 color_gc[color] = XCreateGC(fl_display, fl_root,
434 GCBackground | GCForeground | GCFunction |
435 GCGraphicsExposures | GCLineWidth |
439 return color_gc[color];
443 GC GetAccentGC(LyXFont const &f, int line_width)
445 if (line_width >= 10) line_width = 9;
447 if (accent_gc[line_width]) return accent_gc[line_width];
449 // Build this one from normal text GC, but change linewidth.
452 XGetGCValues(fl_display, gc, GCBackground | GCForeground |
453 GCFunction | GCGraphicsExposures | GCLineWidth |
454 GCLineStyle | GCPlaneMask, &val);
456 val.line_width = line_width;
457 val.cap_style = CapRound;
458 val.join_style = JoinRound;
460 GC ac = XCreateGC(fl_display, fl_root,
461 GCBackground | GCForeground | GCFunction |
462 GCGraphicsExposures | GCLineWidth |
463 GCLineStyle | GCPlaneMask, &val);
466 accent_gc[line_width] = ac;
468 return accent_gc[line_width];
475 if (minipage_gc) return minipage_gc;
477 do_reverse_video(val);
479 val.function= GXcopy;
480 val.graphics_exposures = false;
481 val.line_style = LineOnOffDash;
483 setForegroundColor(fill_color, val);
484 minipage_gc = XCreateGC(fl_display, fl_root,
485 GCBackground | GCForeground | GCFunction |
486 GCGraphicsExposures | GCLineWidth |
494 GC getGC(gc_type typ)
514 gc = GetMathFrameGC();
526 gc = GetOnOffLineGC();
528 case gc_thin_on_off_line:
529 gc = GetThinOnOffLineGC();
532 gc = GetThickLineGC();
538 gc = GetSelectionGC();
541 gc = GetMinipageGC();
547 gc = GetNoteFrameGC();