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 " << color << endl;
78 void do_reverse_video(XGCValues &val)
81 val.foreground=WhitePixel(fl_display,
82 DefaultScreen(fl_display));
83 val.background=BlackPixel(fl_display,
84 DefaultScreen(fl_display));
86 val.foreground=BlackPixel(fl_display,
87 DefaultScreen(fl_display));
88 val.background=WhitePixel(fl_display,
89 DefaultScreen(fl_display));
95 GC make_normal_gc(const char* color)
98 do_reverse_video(val);
99 val.function = GXcopy;
100 val.graphics_exposures = false;
101 setForegroundColor(color, val);
102 return XCreateGC(fl_display, fl_root,
103 GCBackground | GCForeground | GCFunction |
104 GCGraphicsExposures, &val);
111 if (note_gc) return note_gc;
113 note_gc = make_normal_gc(note_color);
122 if (note_frame_gc) return note_frame_gc;
124 note_frame_gc = make_normal_gc(note_frame_color);
126 return note_frame_gc;
133 if (math_gc) return math_gc;
135 math_gc = make_normal_gc(math_color);
144 if (latex_gc) return latex_gc;
147 if (reverse_video ^ mono_video) {
148 val.foreground=WhitePixel(fl_display, DefaultScreen(fl_display));
149 val.background=BlackPixel(fl_display, DefaultScreen(fl_display));
151 val.foreground=BlackPixel(fl_display, DefaultScreen(fl_display));
152 val.background=WhitePixel(fl_display, DefaultScreen(fl_display));
155 val.graphics_exposures = false;
156 setForegroundColor(latex_color, val);
157 latex_gc = XCreateGC(fl_display, fl_root, GCBackground
158 | GCForeground | GCFunction | GCGraphicsExposures,
169 if (foot_gc) return foot_gc;
171 foot_gc = make_normal_gc(foot_color);
180 if (new_line_gc) return new_line_gc;
182 new_line_gc = make_normal_gc(new_line_color);
191 if (math_frame_gc) return math_frame_gc;
193 math_frame_gc = make_normal_gc(math_frame_color);
195 return math_frame_gc;
202 if (fill_gc) return fill_gc;
204 fill_gc = make_normal_gc(fill_color);
213 if (clear_gc) return clear_gc;
218 val.foreground=BlackPixel(fl_display,
219 DefaultScreen(fl_display));
220 val.background=WhitePixel(fl_display,
221 DefaultScreen(fl_display));
223 val.background=BlackPixel(fl_display,
224 DefaultScreen(fl_display));
225 val.foreground=WhitePixel(fl_display,
226 DefaultScreen(fl_display));
229 val.graphics_exposures = false;
230 if (!fast_selection && background_color != "white") {
231 setForegroundColor(background_color.c_str(), val);
233 background_pixels = val.foreground;
235 clear_gc = XCreateGC(fl_display, fl_root, GCBackground
236 | GCForeground | GCFunction | GCGraphicsExposures,
247 if (on_off_line_gc) return on_off_line_gc;
250 do_reverse_video(val);
253 val.graphics_exposures = false;
254 setForegroundColor(on_off_line_color, val);
256 val.line_style = LineOnOffDash;
257 on_off_line_gc = XCreateGC(fl_display, fl_root,
258 GCBackground | GCForeground | GCFunction |
259 GCGraphicsExposures | GCLineWidth |
263 return on_off_line_gc;
270 if (thick_line_gc) return thick_line_gc;
272 do_reverse_video(val);
275 val.graphics_exposures = false;
277 val.line_style = LineSolid;
278 thick_line_gc = XCreateGC(fl_display, fl_root, GCBackground
279 | GCForeground | GCFunction | GCGraphicsExposures
280 | GCLineWidth | GCLineStyle , &val);
283 return thick_line_gc;
288 GC GetThinOnOffLineGC()
290 if (thin_on_off_line_gc) return thin_on_off_line_gc;
292 do_reverse_video(val);
295 val.graphics_exposures = false;
296 val.line_style = LineOnOffDash;
298 thin_on_off_line_gc =
299 XCreateGC(fl_display, fl_root, GCBackground
300 | GCForeground | GCFunction | GCGraphicsExposures
301 | GCLineWidth | GCLineStyle , &val);
304 return thin_on_off_line_gc;
311 if (copy_gc) return copy_gc;
313 do_reverse_video(val);
316 val.graphics_exposures = false;
317 val.line_style = LineSolid;
319 copy_gc = XCreateGC(fl_display, fl_root, GCBackground
320 | GCForeground | GCFunction | GCGraphicsExposures
321 | GCLineWidth | GCLineStyle , &val);
331 if (select_gc) return select_gc;
333 unsigned int a = BlackPixel(fl_display, DefaultScreen(fl_display));
334 unsigned int b = WhitePixel(fl_display, DefaultScreen(fl_display));
335 val.plane_mask = a^b;
336 val.line_style = LineSolid;
338 val.graphics_exposures = false;
339 val.function=GXinvert;
340 select_gc = XCreateGC(fl_display, fl_root,
341 GCFunction | GCGraphicsExposures | GCPlaneMask
342 | GCLineWidth | GCLineStyle , &val);
352 if (selection_gc) return selection_gc;
356 if (!reverse_video) {
357 val.foreground=BlackPixel(fl_display,
358 DefaultScreen(fl_display));
359 val.background=WhitePixel(fl_display,
360 DefaultScreen(fl_display));
362 val.background=BlackPixel(fl_display,
363 DefaultScreen(fl_display));
364 val.foreground=WhitePixel(fl_display,
365 DefaultScreen(fl_display));
369 val.graphics_exposures = false;
370 if (!fast_selection && selection_color[0] != 0) {
371 if (!setForegroundColor(selection_color, val)) {
372 fast_selection = True;
373 if (clear_gc) clear_gc = 0;
374 lyxerr << " Will use FastSelection-method."
378 selection_gc = XCreateGC(fl_display, fl_root,
379 GCBackground | GCForeground | GCFunction
380 | GCGraphicsExposures, &val);
389 if (lighted_gc) return lighted_gc;
392 val.background=BlackPixel(fl_display, DefaultScreen(fl_display));
394 val.background=WhitePixel(fl_display, DefaultScreen(fl_display));
396 val.foreground=val.background;
398 val.graphics_exposures = false;
399 val.line_style = LineSolid;
401 setForegroundColor(lighted_color, val);
402 lighted_gc = XCreateGC(fl_display, fl_root, GCBackground
403 | GCForeground | GCFunction | GCGraphicsExposures
404 | GCLineWidth | GCLineStyle , &val);
411 GC GetColorGC(LyXFont::FONT_COLOR color)
413 if (color_gc[color]) return color_gc[color];
416 do_reverse_video(val);
419 val.graphics_exposures = false;
420 setForegroundColor(X11Color[color], val);
422 val.line_style = LineSolid;
423 color_gc[color] = XCreateGC(fl_display, fl_root,
424 GCBackground | GCForeground | GCFunction |
425 GCGraphicsExposures | GCLineWidth |
429 return color_gc[color];
433 GC GetAccentGC(LyXFont const &f, int line_width)
435 if (line_width>=10) line_width = 9;
437 if (accent_gc[line_width]) return accent_gc[line_width];
439 // Build this one from normal text GC, but change linewidth.
442 XGetGCValues(fl_display, gc, GCBackground | GCForeground |
443 GCFunction | GCGraphicsExposures | GCLineWidth |
444 GCLineStyle | GCPlaneMask, &val);
446 val.line_width = line_width;
447 val.cap_style = CapRound;
448 val.join_style = JoinRound;
450 GC ac = XCreateGC(fl_display, fl_root,
451 GCBackground | GCForeground | GCFunction |
452 GCGraphicsExposures | GCLineWidth |
453 GCLineStyle | GCPlaneMask, &val);
456 accent_gc[line_width] = ac;
458 return accent_gc[line_width];
465 if (minipage_gc) return minipage_gc;
467 do_reverse_video(val);
470 val.graphics_exposures = false;
471 val.line_style = LineOnOffDash;
473 setForegroundColor(fill_color, val);
474 minipage_gc = XCreateGC(fl_display, fl_root,
475 GCBackground | GCForeground | GCFunction |
476 GCGraphicsExposures | GCLineWidth |
484 GC getGC(gc_type typ)
504 gc = GetMathFrameGC();
516 gc = GetOnOffLineGC();
518 case gc_thin_on_off_line:
519 gc = GetThinOnOffLineGC();
522 gc = GetThickLineGC();
528 gc = GetSelectionGC();
531 gc = GetMinipageGC();
537 gc = GetNoteFrameGC();