diff options
author | fluxgen <fluxgen> | 2003-04-25 13:58:31 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-04-25 13:58:31 (GMT) |
commit | f801b384e5300aaa46ef2b3fb267243a3c4b78fc (patch) | |
tree | df603c2b0a4898c4ed0fa93cb162a41ebc3781f0 /src/Theme.cc | |
parent | 3d73a90a7b50a50d1c95b72da871e071f4f07cfb (diff) | |
download | fluxbox_pavel-f801b384e5300aaa46ef2b3fb267243a3c4b78fc.zip fluxbox_pavel-f801b384e5300aaa46ef2b3fb267243a3c4b78fc.tar.bz2 |
obsolete
Diffstat (limited to 'src/Theme.cc')
-rw-r--r-- | src/Theme.cc | 751 |
1 files changed, 0 insertions, 751 deletions
diff --git a/src/Theme.cc b/src/Theme.cc deleted file mode 100644 index ae32045..0000000 --- a/src/Theme.cc +++ /dev/null | |||
@@ -1,751 +0,0 @@ | |||
1 | // Theme.cc for fluxbox | ||
2 | // Copyright (c) 2001-2002 Henrik Kinnunen (fluxgen@linuxmail.org) | ||
3 | // Some code based on: | ||
4 | // Screen.cc - Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | ||
5 | // | ||
6 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
7 | // copy of this software and associated documentation files (the "Software"), | ||
8 | // to deal in the Software without restriction, including without limitation | ||
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
10 | // and/or sell copies of the Software, and to permit persons to whom the | ||
11 | // Software is furnished to do so, subject to the following conditions: | ||
12 | // | ||
13 | // The above copyright notice and this permission notice shall be included in | ||
14 | // all copies or substantial portions of the Software. | ||
15 | // | ||
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
19 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
21 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
22 | // DEALINGS IN THE SOFTWARE. | ||
23 | |||
24 | // $Id: Theme.cc,v 1.41 2003/01/12 18:48:14 fluxgen Exp $ | ||
25 | |||
26 | |||
27 | #include "Theme.hh" | ||
28 | |||
29 | #include "i18n.hh" | ||
30 | #include "StringUtil.hh" | ||
31 | |||
32 | #ifndef _GNU_SOURCE | ||
33 | #define _GNU_SOURCE | ||
34 | #endif // _GNU_SOURCE | ||
35 | |||
36 | #ifdef HAVE_CONFIG_H | ||
37 | #include "config.h" | ||
38 | #endif //HAVE_CONFIG_H_ | ||
39 | |||
40 | #include <X11/Xresource.h> | ||
41 | |||
42 | #ifdef HAVE_CTYPE_H | ||
43 | #include <ctype.h> | ||
44 | #endif // HAVE_CTYPE_H | ||
45 | |||
46 | // note: obsolete | ||
47 | extern void bexec(const char *command, char *displaystring); | ||
48 | |||
49 | #include <cstdio> | ||
50 | #include <cstdarg> | ||
51 | #include <string> | ||
52 | #include <iostream> | ||
53 | using namespace std; | ||
54 | |||
55 | Theme::Theme(Display *display, Window rootwindow, Colormap colormap, | ||
56 | int screennum, const char *filename, const char *rootcommand): | ||
57 | m_display(display), | ||
58 | m_colormap(colormap), | ||
59 | m_screennum(screennum), | ||
60 | m_rootcommand(rootcommand==0 ? "" : rootcommand) //we dont want to send 0-pointer to std::string | ||
61 | { | ||
62 | load(filename); | ||
63 | |||
64 | //-------- create gc for the styles ------------ | ||
65 | |||
66 | XGCValues gcv; | ||
67 | unsigned long gc_value_mask = GCForeground; | ||
68 | |||
69 | gcv.foreground = WhitePixel(m_display, screennum)^BlackPixel(m_display, screennum); | ||
70 | gcv.function = GXxor; | ||
71 | gcv.subwindow_mode = IncludeInferiors; | ||
72 | m_opgc = XCreateGC(m_display, rootwindow, | ||
73 | GCForeground | GCFunction | GCSubwindowMode, &gcv); | ||
74 | |||
75 | gcv.foreground = m_windowstyle.l_text_focus.pixel(); | ||
76 | m_windowstyle.l_text_focus_gc = | ||
77 | XCreateGC(m_display, rootwindow, | ||
78 | gc_value_mask, &gcv); | ||
79 | |||
80 | gcv.foreground = m_windowstyle.l_text_unfocus.pixel(); | ||
81 | m_windowstyle.l_text_unfocus_gc = | ||
82 | XCreateGC(m_display, rootwindow, | ||
83 | gc_value_mask, &gcv); | ||
84 | |||
85 | //---- Tab | ||
86 | gcv.foreground = m_windowstyle.tab.l_text_focus.pixel(); | ||
87 | |||
88 | m_windowstyle.tab.l_text_focus_gc = | ||
89 | XCreateGC(m_display, rootwindow, | ||
90 | gc_value_mask, &gcv); | ||
91 | |||
92 | gcv.foreground = m_windowstyle.tab.l_text_unfocus.pixel(); | ||
93 | m_windowstyle.tab.l_text_unfocus_gc = | ||
94 | XCreateGC(m_display, rootwindow, | ||
95 | gc_value_mask, &gcv); | ||
96 | |||
97 | //---end Tab | ||
98 | |||
99 | |||
100 | gcv.foreground = m_windowstyle.b_pic_focus.pixel(); | ||
101 | m_windowstyle.b_pic_focus_gc = | ||
102 | XCreateGC(m_display, rootwindow, | ||
103 | GCForeground, &gcv); | ||
104 | |||
105 | gcv.foreground = m_windowstyle.b_pic_unfocus.pixel(); | ||
106 | m_windowstyle.b_pic_unfocus_gc = | ||
107 | XCreateGC(m_display, rootwindow, | ||
108 | GCForeground, &gcv); | ||
109 | |||
110 | } | ||
111 | |||
112 | Theme::~Theme() { | ||
113 | freeWindowStyle(); | ||
114 | freeTabStyle(); | ||
115 | } | ||
116 | |||
117 | //----- freeWindowStyle ----- | ||
118 | // free memory allocated for m_windowstyle | ||
119 | //-------------------- | ||
120 | void Theme::freeWindowStyle() { | ||
121 | XFreeGC(m_display, m_windowstyle.l_text_focus_gc); | ||
122 | XFreeGC(m_display, m_windowstyle.l_text_unfocus_gc); | ||
123 | XFreeGC(m_display, m_windowstyle.b_pic_focus_gc); | ||
124 | XFreeGC(m_display, m_windowstyle.b_pic_unfocus_gc); | ||
125 | } | ||
126 | |||
127 | //----- freeTabStyle ----- | ||
128 | // free memory allocated for m_windowstyle.tab | ||
129 | //-------------------- | ||
130 | void Theme::freeTabStyle() { | ||
131 | XFreeGC(m_display, m_windowstyle.tab.l_text_focus_gc); | ||
132 | XFreeGC(m_display, m_windowstyle.tab.l_text_unfocus_gc); | ||
133 | } | ||
134 | |||
135 | //---------- load ------------ | ||
136 | // Loads a theme from a file | ||
137 | //---------------------------- | ||
138 | void Theme::load(const char *filename){ | ||
139 | m_database = XrmGetFileDatabase(filename); | ||
140 | if (!m_database) | ||
141 | m_database = XrmGetFileDatabase(DEFAULTSTYLE); | ||
142 | |||
143 | loadWindowStyle(); | ||
144 | loadTabStyle(); | ||
145 | loadRootCommand(); | ||
146 | loadMisc(); | ||
147 | |||
148 | XrmDestroyDatabase(m_database); | ||
149 | } | ||
150 | |||
151 | void Theme::loadWindowStyle() { | ||
152 | |||
153 | //read textures | ||
154 | |||
155 | readDatabaseTexture("window.title.focus", "Window.Title.Focus", | ||
156 | &m_windowstyle.t_focus, | ||
157 | WhitePixel(m_display, m_screennum)); | ||
158 | if ( (m_windowstyle.t_focus.type() & FbTk::Texture::PARENTRELATIVE) ) { | ||
159 | cerr<<"Warning: window.title.focus type is ParentRelative. Using flat solid!"<<endl; | ||
160 | m_windowstyle.t_focus.setType(FbTk::Texture::FLAT|FbTk::Texture::SOLID); | ||
161 | } | ||
162 | readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus", | ||
163 | &m_windowstyle.t_unfocus, | ||
164 | BlackPixel(m_display, m_screennum)); | ||
165 | if ( (m_windowstyle.t_unfocus.type() & FbTk::Texture::PARENTRELATIVE) ) { | ||
166 | cerr<<"Warning: window.title.unfocus type is ParentRelative. Using flat solid!"<<endl; | ||
167 | m_windowstyle.t_unfocus.setType(FbTk::Texture::FLAT|FbTk::Texture::SOLID); | ||
168 | } | ||
169 | |||
170 | readDatabaseTexture("window.label.focus", "Window.Label.Focus", | ||
171 | &m_windowstyle.l_focus, | ||
172 | WhitePixel(m_display, m_screennum)); | ||
173 | readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus", | ||
174 | &m_windowstyle.l_unfocus, | ||
175 | BlackPixel(m_display, m_screennum)); | ||
176 | |||
177 | |||
178 | readDatabaseTexture("window.handle.focus", "Window.Handle.Focus", | ||
179 | &m_windowstyle.h_focus, | ||
180 | WhitePixel(m_display, m_screennum)); | ||
181 | if ( (m_windowstyle.h_focus.type() & FbTk::Texture::PARENTRELATIVE) ) { | ||
182 | cerr<<"Warning: window.handle.focus is ParentReleative. Using flat solid instead."<<endl; | ||
183 | m_windowstyle.h_focus.setType(FbTk::Texture::FLAT|FbTk::Texture::SOLID); | ||
184 | } | ||
185 | readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus", | ||
186 | &m_windowstyle.h_unfocus, | ||
187 | BlackPixel(m_display, m_screennum)); | ||
188 | if ( (m_windowstyle.h_unfocus.type() & FbTk::Texture::PARENTRELATIVE) ) { | ||
189 | cerr<<"Warning: window.handle.unfocus is ParentReleative. Using flat solid instead."<<endl; | ||
190 | m_windowstyle.h_unfocus.setType(FbTk::Texture::FLAT|FbTk::Texture::SOLID); | ||
191 | } | ||
192 | |||
193 | readDatabaseTexture("window.grip.focus", "Window.Grip.Focus", | ||
194 | &m_windowstyle.g_focus, | ||
195 | WhitePixel(m_display, m_screennum)); | ||
196 | readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus", | ||
197 | &m_windowstyle.g_unfocus, | ||
198 | BlackPixel(m_display, m_screennum)); | ||
199 | readDatabaseTexture("window.button.focus", "Window.Button.Focus", | ||
200 | &m_windowstyle.b_focus, | ||
201 | WhitePixel(m_display, m_screennum)); | ||
202 | readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus", | ||
203 | &m_windowstyle.b_unfocus, | ||
204 | BlackPixel(m_display, m_screennum)); | ||
205 | readDatabaseTexture("window.button.pressed", "Window.Button.Pressed", | ||
206 | &m_windowstyle.b_pressed, | ||
207 | BlackPixel(m_display, m_screennum)); | ||
208 | |||
209 | // read colors | ||
210 | |||
211 | readDatabaseColor("window.frame.focusColor", | ||
212 | "Window.Frame.FocusColor", | ||
213 | &m_windowstyle.f_focus, | ||
214 | WhitePixel(m_display, m_screennum)); | ||
215 | readDatabaseColor("window.frame.unfocusColor", | ||
216 | "Window.Frame.UnfocusColor", | ||
217 | &m_windowstyle.f_unfocus, | ||
218 | BlackPixel(m_display, m_screennum)); | ||
219 | readDatabaseColor("window.label.focus.textColor", | ||
220 | "Window.Label.Focus.TextColor", | ||
221 | &m_windowstyle.l_text_focus, | ||
222 | BlackPixel(m_display, m_screennum)); | ||
223 | readDatabaseColor("window.label.unfocus.textColor", | ||
224 | "Window.Label.Unfocus.TextColor", | ||
225 | &m_windowstyle.l_text_unfocus, | ||
226 | WhitePixel(m_display, m_screennum)); | ||
227 | readDatabaseColor("window.button.focus.picColor", | ||
228 | "Window.Button.Focus.PicColor", | ||
229 | &m_windowstyle.b_pic_focus, | ||
230 | BlackPixel(m_display, m_screennum)); | ||
231 | readDatabaseColor("window.button.unfocus.picColor", | ||
232 | "Window.Button.Unfocus.PicColor", | ||
233 | &m_windowstyle.b_pic_unfocus, | ||
234 | WhitePixel(m_display, m_screennum)); | ||
235 | |||
236 | //----- font | ||
237 | loadFontFromDatabase(m_windowstyle.font, "window.font", "Window.Font"); | ||
238 | |||
239 | XrmValue value; | ||
240 | char *value_type; | ||
241 | |||
242 | if (XrmGetResource(m_database, "window.justify", "Window.Justify", | ||
243 | &value_type, &value)) { | ||
244 | if (strstr(value.addr, "right") || strstr(value.addr, "Right")) | ||
245 | m_windowstyle.justify = DrawUtil::Font::RIGHT; | ||
246 | else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) | ||
247 | m_windowstyle.justify = DrawUtil::Font::CENTER; | ||
248 | else | ||
249 | m_windowstyle.justify = DrawUtil::Font::LEFT; | ||
250 | } else | ||
251 | m_windowstyle.justify = DrawUtil::Font::LEFT; | ||
252 | |||
253 | } | ||
254 | |||
255 | void Theme::loadTabStyle() { | ||
256 | |||
257 | if (!readDatabaseTexture("window.tab.title.focus", "Window.Tab.Title.Focus", | ||
258 | &m_windowstyle.tab.t_focus, | ||
259 | WhitePixel(m_display, m_screennum))) | ||
260 | m_windowstyle.tab.t_focus = m_windowstyle.t_focus; | ||
261 | |||
262 | if (!readDatabaseTexture("window.tab.title.unfocus", "Window.Tab.Title.Unfocus", | ||
263 | &m_windowstyle.tab.t_unfocus, | ||
264 | BlackPixel(m_display, m_screennum))) | ||
265 | m_windowstyle.tab.t_unfocus = m_windowstyle.t_unfocus; | ||
266 | |||
267 | if (!readDatabaseTexture("window.tab.label.focus", "Window.Tab.Label.Focus", | ||
268 | &m_windowstyle.tab.l_focus, | ||
269 | WhitePixel(m_display, m_screennum))) | ||
270 | m_windowstyle.tab.l_focus = m_windowstyle.l_focus; | ||
271 | |||
272 | if (!readDatabaseTexture("window.tab.label.unfocus", "Window.Tab.Label.Unfocus", | ||
273 | &m_windowstyle.tab.l_unfocus, | ||
274 | BlackPixel(m_display, m_screennum))) | ||
275 | m_windowstyle.tab.l_unfocus = m_windowstyle.l_unfocus; | ||
276 | |||
277 | if (!readDatabaseColor("window.tab.label.focus.textColor", | ||
278 | "Window.Tab.Label.Focus.TextColor", | ||
279 | &m_windowstyle.tab.l_text_focus, | ||
280 | BlackPixel(m_display, m_screennum))) | ||
281 | m_windowstyle.tab.l_text_focus = m_windowstyle.l_text_focus; | ||
282 | |||
283 | if (!readDatabaseColor("window.tab.label.unfocus.textColor", | ||
284 | "Window.Tab.Label.Unfocus.TextColor", | ||
285 | &m_windowstyle.tab.l_text_unfocus, | ||
286 | WhitePixel(m_display, m_screennum))) | ||
287 | m_windowstyle.tab.l_text_unfocus = m_windowstyle.l_text_unfocus; | ||
288 | |||
289 | readDatabaseColor("window.tab.borderColor", "Window.Tab.BorderColor", | ||
290 | &m_windowstyle.tab.border_color, | ||
291 | BlackPixel(m_display, m_screennum)); | ||
292 | |||
293 | XrmValue value; | ||
294 | char *value_type; | ||
295 | |||
296 | if (XrmGetResource(m_database, "window.tab.borderWidth", "Window.Tab.BorderWidth", | ||
297 | &value_type, &value)) { | ||
298 | if (sscanf(value.addr, "%u", &m_windowstyle.tab.border_width) != 1) | ||
299 | m_windowstyle.tab.border_width = 1; | ||
300 | } else | ||
301 | m_windowstyle.tab.border_width = 1; | ||
302 | |||
303 | m_windowstyle.tab.border_width_2x = m_windowstyle.tab.border_width*2; | ||
304 | |||
305 | loadFontFromDatabase(m_windowstyle.tab.font, "window.tab.font", "Window.Tab.Font"); | ||
306 | |||
307 | if (XrmGetResource(m_database, "window.tab.justify", "Window.Tab.Justify", | ||
308 | &value_type, &value)) { | ||
309 | if (strstr(value.addr, "right") || strstr(value.addr, "Right")) | ||
310 | m_windowstyle.tab.justify = DrawUtil::Font::RIGHT; | ||
311 | else if (strstr(value.addr, "center") || strstr(value.addr, "Center")) | ||
312 | m_windowstyle.tab.justify = DrawUtil::Font::CENTER; | ||
313 | else | ||
314 | m_windowstyle.tab.justify = DrawUtil::Font::LEFT; | ||
315 | } else | ||
316 | m_windowstyle.tab.justify = DrawUtil::Font::LEFT; | ||
317 | |||
318 | } | ||
319 | |||
320 | void Theme::loadRootCommand() { | ||
321 | } | ||
322 | |||
323 | void Theme::loadMisc() { | ||
324 | unsigned int screen_width_div2 = WidthOfScreen(ScreenOfDisplay(m_display, m_screennum)) / 2; | ||
325 | XrmValue value; | ||
326 | char *value_type=0; | ||
327 | |||
328 | if (XrmGetResource(m_database, "bevelWidth", "BevelWidth", | ||
329 | &value_type, &value)) { | ||
330 | if (sscanf(value.addr, "%u", &m_bevel_width) != 1 || | ||
331 | m_bevel_width > screen_width_div2 || | ||
332 | m_bevel_width == 0) | ||
333 | m_bevel_width = 3; | ||
334 | } else | ||
335 | m_bevel_width = 3; | ||
336 | |||
337 | if (XrmGetResource(m_database, "handleWidth", "HandleWidth", | ||
338 | &value_type, &value)) { | ||
339 | if (sscanf(value.addr, "%u", &m_handle_width) != 1 || | ||
340 | m_handle_width > screen_width_div2 || m_handle_width == 0) | ||
341 | m_handle_width = 6; | ||
342 | } else | ||
343 | m_handle_width = 6; | ||
344 | |||
345 | if (XrmGetResource(m_database, "borderWidth", "BorderWidth", | ||
346 | &value_type, &value)) { | ||
347 | if (sscanf(value.addr, "%u", &m_border_width) != 1) | ||
348 | m_border_width = 1; | ||
349 | } else | ||
350 | m_border_width = 1; | ||
351 | |||
352 | |||
353 | if (XrmGetResource(m_database, "frameWidth", "FrameWidth", | ||
354 | &value_type, &value)) { | ||
355 | if (sscanf(value.addr, "%u", &m_frame_width) != 1 || | ||
356 | m_frame_width > screen_width_div2) | ||
357 | m_frame_width = m_bevel_width; | ||
358 | } else | ||
359 | m_frame_width = m_bevel_width; | ||
360 | |||
361 | readDatabaseColor("borderColor", "BorderColor", &m_border_color, | ||
362 | BlackPixel(m_display, m_screennum)); | ||
363 | |||
364 | // load slit style, if it wasn't found fall back to toolbarstyle | ||
365 | if (!readDatabaseTexture("slit", "Slit", | ||
366 | &m_slit_texture, | ||
367 | BlackPixel(m_display, m_screennum)) ) { | ||
368 | // m_slit_texture = m_toolbarstyle.toolbar; ///!!! TODO !!! | ||
369 | } | ||
370 | |||
371 | } | ||
372 | |||
373 | |||
374 | bool Theme::readDatabaseTexture(char *rname, char *rclass, | ||
375 | FbTk::Texture *texture, | ||
376 | unsigned long default_pixel) | ||
377 | { | ||
378 | XrmValue value; | ||
379 | char *value_type; | ||
380 | bool retval = true;//return true as default | ||
381 | |||
382 | if (XrmGetResource(m_database, rname, rclass, &value_type, | ||
383 | &value)) | ||
384 | texture->setFromString(value.addr); | ||
385 | else | ||
386 | texture->setType(FbTk::Texture::SOLID | FbTk::Texture::FLAT); | ||
387 | |||
388 | if (texture->type() & FbTk::Texture::SOLID) { | ||
389 | int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32; | ||
390 | |||
391 | char *colorclass = new char[clen], *colorname = new char[nlen]; | ||
392 | |||
393 | sprintf(colorclass, "%s.Color", rclass); | ||
394 | sprintf(colorname, "%s.color", rname); | ||
395 | |||
396 | if (!readDatabaseColor(colorname, colorclass, &texture->color(), | ||
397 | default_pixel)) | ||
398 | retval = false; | ||
399 | |||
400 | #ifdef INTERLACE | ||
401 | sprintf(colorclass, "%s.ColorTo", rclass); | ||
402 | sprintf(colorname, "%s.colorTo", rname); | ||
403 | |||
404 | readDatabaseColor(colorname, colorclass, &texture->colorTo(), default_pixel); | ||
405 | #endif // INTERLACE | ||
406 | |||
407 | delete [] colorclass; | ||
408 | delete [] colorname; | ||
409 | |||
410 | if ((! texture->color().isAllocated()) || | ||
411 | (texture->type() & FbTk::Texture::FLAT)) | ||
412 | return retval; | ||
413 | |||
414 | XColor xcol; | ||
415 | |||
416 | xcol.red = (unsigned int) (texture->color().red() + | ||
417 | (texture->color().red() >> 1)); | ||
418 | if (xcol.red >= 0xff) xcol.red = 0xffff; | ||
419 | else xcol.red *= 0xff; | ||
420 | xcol.green = (unsigned int) (texture->color().green() + | ||
421 | (texture->color().green() >> 1)); | ||
422 | if (xcol.green >= 0xff) xcol.green = 0xffff; | ||
423 | else xcol.green *= 0xff; | ||
424 | xcol.blue = (unsigned int) (texture->color().blue() + | ||
425 | (texture->color().blue() >> 1)); | ||
426 | if (xcol.blue >= 0xff) xcol.blue = 0xffff; | ||
427 | else xcol.blue *= 0xff; | ||
428 | |||
429 | if (! XAllocColor(m_display, m_colormap, &xcol)) | ||
430 | xcol.pixel = 0; | ||
431 | |||
432 | texture->hiColor().setPixel(xcol.pixel); | ||
433 | |||
434 | xcol.red = | ||
435 | (unsigned int) ((texture->color().red() >> 2) + | ||
436 | (texture->color().red() >> 1)) * 0xff; | ||
437 | xcol.green = | ||
438 | (unsigned int) ((texture->color().green() >> 2) + | ||
439 | (texture->color().green() >> 1)) * 0xff; | ||
440 | xcol.blue = | ||
441 | (unsigned int) ((texture->color().blue() >> 2) + | ||
442 | (texture->color().blue() >> 1)) * 0xff; | ||
443 | |||
444 | if (! XAllocColor(m_display, m_colormap, &xcol)) | ||
445 | xcol.pixel = 0; | ||
446 | |||
447 | texture->loColor().setPixel(xcol.pixel); | ||
448 | } else if (texture->type() & FbTk::Texture::GRADIENT) { | ||
449 | int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10; | ||
450 | |||
451 | char *colorclass = new char[clen], *colorname = new char[nlen], | ||
452 | *colortoclass = new char[clen], *colortoname = new char[nlen]; | ||
453 | |||
454 | sprintf(colorclass, "%s.Color", rclass); | ||
455 | sprintf(colorname, "%s.color", rname); | ||
456 | |||
457 | sprintf(colortoclass, "%s.ColorTo", rclass); | ||
458 | sprintf(colortoname, "%s.colorTo", rname); | ||
459 | |||
460 | if (!readDatabaseColor(colorname, colorclass, &texture->color(), | ||
461 | default_pixel)) | ||
462 | retval = false; //report failure in loading | ||
463 | |||
464 | readDatabaseColor(colortoname, colortoclass, &texture->colorTo(), default_pixel); | ||
465 | |||
466 | delete [] colorclass; | ||
467 | delete [] colorname; | ||
468 | delete [] colortoclass; | ||
469 | delete [] colortoname; | ||
470 | } | ||
471 | |||
472 | if (!retval) | ||
473 | cerr<<"Failed to load texture for: "<<rname<<endl; | ||
474 | |||
475 | return retval; | ||
476 | } | ||
477 | |||
478 | |||
479 | bool Theme::readDatabaseColor(char *rname, char *rclass, FbTk::Color *color, | ||
480 | unsigned long default_pixel) | ||
481 | { | ||
482 | XrmValue value; | ||
483 | char *value_type; | ||
484 | |||
485 | if (XrmGetResource(m_database, rname, rclass, &value_type, | ||
486 | &value)) { | ||
487 | color->setFromString(value.addr, m_screennum); | ||
488 | } else { | ||
489 | color->setPixel(default_pixel); | ||
490 | return false; | ||
491 | } | ||
492 | |||
493 | return true; | ||
494 | } | ||
495 | |||
496 | |||
497 | void Theme::readDatabaseFontSet(char *rname, char *rclass, XFontSet *fontset) { | ||
498 | if (! fontset) return; | ||
499 | |||
500 | static char *defaultFont = "fixed"; | ||
501 | |||
502 | bool load_default = false; | ||
503 | XrmValue value; | ||
504 | char *value_type; | ||
505 | |||
506 | if (*fontset) | ||
507 | XFreeFontSet(m_display, *fontset); | ||
508 | |||
509 | if (XrmGetResource(m_database, rname, rclass, &value_type, &value)) { | ||
510 | char *fontname = value.addr; | ||
511 | if (! (*fontset = createFontSet(fontname))) | ||
512 | load_default = true; | ||
513 | } else | ||
514 | load_default = true; | ||
515 | |||
516 | if (load_default) { | ||
517 | *fontset = createFontSet(defaultFont); | ||
518 | |||
519 | if (! *fontset) { | ||
520 | throw string( | ||
521 | I18n::instance()-> | ||
522 | getMessage( | ||
523 | FBNLS::ScreenSet, FBNLS::ScreenDefaultFontLoadFail, | ||
524 | "BScreen::LoadStyle(): couldn't load default font.")); | ||
525 | } | ||
526 | } | ||
527 | } | ||
528 | |||
529 | |||
530 | |||
531 | void Theme::readDatabaseFont(char *rname, char *rclass, XFontStruct **font) { | ||
532 | if (! font) return; | ||
533 | |||
534 | static char *defaultFont = "fixed"; | ||
535 | |||
536 | bool load_default = false; | ||
537 | XrmValue value; | ||
538 | char *value_type; | ||
539 | |||
540 | if (*font) | ||
541 | XFreeFont(m_display, *font); | ||
542 | |||
543 | if (XrmGetResource(m_database, rname, rclass, &value_type, &value)) { | ||
544 | #ifdef DEBUG | ||
545 | cerr<<__FILE__<<"("<<__LINE__<<"): Load font:"<<value.addr<<endl; | ||
546 | #endif | ||
547 | if ((*font = XLoadQueryFont(m_display, value.addr)) == 0) { | ||
548 | fprintf(stderr, | ||
549 | I18n::instance()-> | ||
550 | getMessage( | ||
551 | FBNLS::ScreenSet, FBNLS::ScreenFontLoadFail, | ||
552 | "BScreen::LoadStyle(): couldn't load font '%s'\n"), | ||
553 | value.addr); | ||
554 | |||
555 | load_default = true; | ||
556 | } | ||
557 | } else | ||
558 | load_default = true; | ||
559 | |||
560 | if (load_default) { | ||
561 | if ((*font = XLoadQueryFont(m_display, defaultFont)) == 0) { | ||
562 | throw string( | ||
563 | I18n::instance()-> | ||
564 | getMessage( | ||
565 | FBNLS::ScreenSet, FBNLS::ScreenDefaultFontLoadFail, | ||
566 | "BScreen::LoadStyle(): couldn't load default font.")); | ||
567 | |||
568 | } | ||
569 | } | ||
570 | } | ||
571 | |||
572 | void Theme::reconfigure(bool antialias) { | ||
573 | |||
574 | XGCValues gcv; | ||
575 | unsigned long gc_value_mask = GCForeground; | ||
576 | |||
577 | XChangeGC(m_display, m_opgc, | ||
578 | GCForeground | GCFunction | GCSubwindowMode, &gcv); | ||
579 | |||
580 | gcv.foreground = WhitePixel(m_display, m_screennum); | ||
581 | gcv.function = GXinvert; | ||
582 | gcv.subwindow_mode = IncludeInferiors; | ||
583 | XChangeGC(m_display, m_opgc, | ||
584 | GCForeground | GCFunction | GCSubwindowMode, &gcv); | ||
585 | |||
586 | gcv.foreground = m_windowstyle.l_text_focus.pixel(); | ||
587 | if (m_windowstyle.font.isAntialias() != antialias) | ||
588 | m_windowstyle.font.setAntialias(antialias); | ||
589 | |||
590 | XChangeGC(m_display, m_windowstyle.l_text_focus_gc, | ||
591 | gc_value_mask, &gcv); | ||
592 | |||
593 | gcv.foreground = m_windowstyle.l_text_unfocus.pixel(); | ||
594 | XChangeGC(m_display, m_windowstyle.l_text_unfocus_gc, | ||
595 | gc_value_mask, &gcv); | ||
596 | |||
597 | //---- Tab | ||
598 | gcv.foreground = m_windowstyle.tab.l_text_focus.pixel(); | ||
599 | if (m_windowstyle.tab.font.isAntialias() != antialias) | ||
600 | m_windowstyle.tab.font.setAntialias(antialias); | ||
601 | XChangeGC(m_display, m_windowstyle.tab.l_text_focus_gc, | ||
602 | gc_value_mask, &gcv); | ||
603 | |||
604 | gcv.foreground = m_windowstyle.tab.l_text_unfocus.pixel(); | ||
605 | XChangeGC(m_display, m_windowstyle.tab.l_text_unfocus_gc, | ||
606 | gc_value_mask, &gcv); | ||
607 | |||
608 | //--- end tab | ||
609 | |||
610 | gcv.foreground = m_windowstyle.b_pic_focus.pixel(); | ||
611 | XChangeGC(m_display, m_windowstyle.b_pic_focus_gc, | ||
612 | GCForeground, &gcv); | ||
613 | |||
614 | gcv.foreground = m_windowstyle.b_pic_unfocus.pixel(); | ||
615 | XChangeGC(m_display, m_windowstyle.b_pic_unfocus_gc, | ||
616 | GCForeground, &gcv); | ||
617 | |||
618 | } | ||
619 | |||
620 | XFontSet Theme::createFontSet(char *fontname) { | ||
621 | XFontSet fs; | ||
622 | const int FONT_ELEMENT_SIZE=50; | ||
623 | char **missing, *def = "-"; | ||
624 | int nmissing, pixel_size = 0, buf_size = 0; | ||
625 | char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE]; | ||
626 | |||
627 | fs = XCreateFontSet(m_display, | ||
628 | fontname, &missing, &nmissing, &def); | ||
629 | if (fs && (! nmissing)) return fs; | ||
630 | |||
631 | #ifdef HAVE_SETLOCALE | ||
632 | if (! fs) { | ||
633 | if (nmissing) XFreeStringList(missing); | ||
634 | |||
635 | setlocale(LC_CTYPE, "C"); | ||
636 | fs = XCreateFontSet(m_display, fontname, | ||
637 | &missing, &nmissing, &def); | ||
638 | setlocale(LC_CTYPE, ""); | ||
639 | } | ||
640 | #endif // HAVE_SETLOCALE | ||
641 | |||
642 | if (fs) { | ||
643 | XFontStruct **fontstructs; | ||
644 | char **fontnames; | ||
645 | XFontsOfFontSet(fs, &fontstructs, &fontnames); | ||
646 | fontname = fontnames[0]; | ||
647 | } | ||
648 | |||
649 | getFontElement(fontname, weight, FONT_ELEMENT_SIZE, | ||
650 | "-medium-", "-bold-", "-demibold-", "-regular-", 0); | ||
651 | getFontElement(fontname, slant, FONT_ELEMENT_SIZE, | ||
652 | "-r-", "-i-", "-o-", "-ri-", "-ro-", 0); | ||
653 | getFontSize(fontname, &pixel_size); | ||
654 | |||
655 | if (! strcmp(weight, "*")) | ||
656 | strncpy(weight, "medium", FONT_ELEMENT_SIZE); | ||
657 | if (! strcmp(slant, "*")) | ||
658 | strncpy(slant, "r", FONT_ELEMENT_SIZE); | ||
659 | if (pixel_size < 3) | ||
660 | pixel_size = 3; | ||
661 | else if (pixel_size > 97) | ||
662 | pixel_size = 97; | ||
663 | |||
664 | buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64; | ||
665 | char *pattern2 = new char[buf_size]; | ||
666 | snprintf(pattern2, buf_size - 1, | ||
667 | "%s," | ||
668 | "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*," | ||
669 | "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*", | ||
670 | fontname, weight, slant, pixel_size, pixel_size); | ||
671 | fontname = pattern2; | ||
672 | |||
673 | if (nmissing) | ||
674 | XFreeStringList(missing); | ||
675 | if (fs) | ||
676 | XFreeFontSet(m_display, fs); | ||
677 | |||
678 | fs = XCreateFontSet(m_display, fontname, | ||
679 | &missing, &nmissing, &def); | ||
680 | delete [] pattern2; | ||
681 | |||
682 | return fs; | ||
683 | } | ||
684 | |||
685 | const char *Theme::getFontSize(const char *pattern, int *size) { | ||
686 | const char *p; | ||
687 | const char *p2=0; | ||
688 | int n=0; | ||
689 | |||
690 | for (p=pattern; 1; p++) { | ||
691 | if (!*p) { | ||
692 | if (p2!=0 && n>1 && n<72) { | ||
693 | *size = n; return p2+1; | ||
694 | } else { | ||
695 | *size = 16; return 0; | ||
696 | } | ||
697 | } else if (*p=='-') { | ||
698 | if (n>1 && n<72 && p2!=0) { | ||
699 | *size = n; | ||
700 | return p2+1; | ||
701 | } | ||
702 | p2=p; n=0; | ||
703 | } else if (*p>='0' && *p<='9' && p2!=0) { | ||
704 | n *= 10; | ||
705 | n += *p-'0'; | ||
706 | } else { | ||
707 | p2=0; n=0; | ||
708 | } | ||
709 | } | ||
710 | } | ||
711 | |||
712 | const char *Theme::getFontElement(const char *pattern, char *buf, int bufsiz, ...) { | ||
713 | const char *p, *v; | ||
714 | char *p2; | ||
715 | va_list va; | ||
716 | |||
717 | va_start(va, bufsiz); | ||
718 | buf[bufsiz-1] = 0; | ||
719 | buf[bufsiz-2] = '*'; | ||
720 | while((v = va_arg(va, char *)) != 0) { | ||
721 | p = StringUtil::strcasestr(pattern, v); | ||
722 | if (p) { | ||
723 | strncpy(buf, p+1, bufsiz-2); | ||
724 | p2 = strchr(buf, '-'); | ||
725 | if (p2) *p2=0; | ||
726 | va_end(va); | ||
727 | return p; | ||
728 | } | ||
729 | } | ||
730 | va_end(va); | ||
731 | strncpy(buf, "*", bufsiz); | ||
732 | return 0; | ||
733 | } | ||
734 | |||
735 | void Theme::loadFontFromDatabase(FbTk::Font &dest, const char *name, const char *altname) { | ||
736 | assert(name); | ||
737 | assert(altname); | ||
738 | |||
739 | XrmValue value; | ||
740 | char *value_type; | ||
741 | |||
742 | if (XrmGetResource(m_database, name, altname, &value_type, &value)) { | ||
743 | #ifdef DEBUG | ||
744 | std::cerr<<__FILE__<<"("<<__LINE__<<"): Load font:"<<value.addr<<std::endl; | ||
745 | #endif // DEBUG | ||
746 | if (!dest.load(value.addr)) | ||
747 | cerr<<"Failed to load font: "<<value.addr<<endl; | ||
748 | } | ||
749 | |||
750 | |||
751 | } | ||