1 // resource.cc for bbkeys - an tool for displaying and changing Blackbox
4 // Copyright (c) 1998-1999 John Kennis, j.m.b.m.kennis@tue.nl
5 // Copyright (c) 2000-2001 Jason Kasper (vanRijn) <vr at movingparts dot net>
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 // (See the included file COPYING / GPL-2.0)
27 #endif // HAVE_CONFIG_H
31 #endif // STDC_HEADERS
39 #endif // HAVE_STDIO_H
41 #include "resource.hh"
42 #include "blackboxstyle.hh"
45 Resource::Resource(ToolWindow
* toolwindow
):BaseResource(toolwindow
)
47 label
.font
= frame
.font
= menu
.font
=0;
56 void Resource::Clean()
59 XFreeFont(bbtool
->getXDisplay(), label
.font
);
61 XFreeFont(bbtool
->getXDisplay(), frame
.font
);
63 XFreeFont(bbtool
->getXDisplay(), menu
.font
);
64 frame
.font
=label
.font
=menu
.font
=0;
68 void Resource::LoadBBToolResource(void)
73 if (XrmGetResource(resource_db
, "bbkeys.autoConfig",
74 "Bbkeys.Autoconfig", &value_type
, &value
)) {
75 if (!strncasecmp("true", value
.addr
, value
.size
)) {
76 style
.auto_config
= True
;
78 style
.auto_config
= False
;
81 style
.auto_config
= False
;
84 if (XrmGetResource(resource_db
, "bbkeys.honorModifiers",
85 "Bbkeys.Honormodifiers", &value_type
, &value
)) {
86 if (!strncasecmp("true", value
.addr
, value
.size
)) {
87 style
.honor_modifiers
= True
;
89 style
.honor_modifiers
= False
;
92 style
.honor_modifiers
= False
;
95 if (XrmGetResource(resource_db
, "bbkeys.menu.stackedCycling",
96 "Bbkeys.Menu.StackedCycling", &value_type
, &value
)) {
97 if (!strncasecmp("true", value
.addr
, value
.size
))
98 menu
.stackedCycling
= True
;
100 menu
.stackedCycling
= False
;
102 menu
.stackedCycling
= True
;
104 if (XrmGetResource(resource_db
, "bbkeys.menu.showCycleMenu",
105 "Bbkeys.Menu.ShowCycleMenu", &value_type
, &value
)) {
106 if (!strncasecmp("true", value
.addr
, value
.size
))
107 menu
.showCycleMenu
= True
;
109 menu
.showCycleMenu
= False
;
111 menu
.showCycleMenu
= True
;
126 void Resource::Frame()
134 (resource_db
, "toolbar.color", "Toolbar.Color", &value_type
,
136 color
= strdup(value
.addr
);
138 color
= strdup("black");
142 (resource_db
, "toolbar", "Toolbar", &value_type
, &value
)) {
143 gradient
= strdup(value
.addr
);
145 gradient
= strdup("Raised Gradient Vertical Bevel1");
149 readTexture("bbkeys.frame", "Bbkeys.Frame", BB_FRAME
,
150 BB_FRAME2
, color
, color
, gradient
, &frame
.texture
);
153 (resource_db
, "bbkeys.bevelWidth", "Bbkeys.BevelWidth",
154 &value_type
, &value
)) {
155 if (sscanf(value
.addr
, "%u", &frame
.bevelWidth
) != 1)
156 frame
.bevelWidth
= 4;
157 else if (frame
.bevelWidth
== 0)
158 frame
.bevelWidth
= 4;
161 (resource_db
, BB_BEVELWIDTH
, BB_BEVELWIDTH2
, &value_type
, &value
)) {
162 if (sscanf(value
.addr
, "%u", &frame
.bevelWidth
) != 1)
163 frame
.bevelWidth
= 4;
164 else if (frame
.bevelWidth
== 0)
165 frame
.bevelWidth
= 4;
167 frame
.bevelWidth
= 4;
169 // strdup does a malloc to achieve its results, so make sure we free()
177 void Resource::SizeAndPosition()
182 char positionstring
[11];
184 if (!(bbtool
->position
)) {
187 (resource_db
, "bbkeys.position", "Bbkeys.Position",
188 &value_type
, &value
)))
189 strncpy(positionstring
, "-0-0", 5);
191 strncpy(positionstring
, value
.addr
, strlen(value
.addr
) + 1);
193 strncpy(positionstring
, bbtool
->position
,
194 strlen(bbtool
->position
) + 1);
198 XParseGeometry(positionstring
, &position
.x
, &position
.y
, &w
, &h
);
200 if (!(position
.mask
& XValue
))
202 if (!(position
.mask
& YValue
))
206 if (XrmGetResource(resource_db
, "bbkeys.columns",
207 "Bbkeys.Columns", &value_type
, &value
)) {
208 if (sscanf(value
.addr
, "%u", &columns
) != 1)
211 position
.vertical
= True
;
218 if (XrmGetResource(resource_db
, "bbkeys.rows", "Bbkeys.Rows",
219 &value_type
, &value
)) {
220 if (sscanf(value
.addr
, "%u", &rows
) != 1)
223 position
.horizontal
= True
;
230 if (!position
.horizontal
&& !position
.vertical
) {
231 if (bbtool
->withdrawn
)
232 position
.vertical
= True
;
234 position
.horizontal
= True
;
237 if (!(XrmGetResource(resource_db
, "bbkeys.desktop.width",
238 "Bbkeys.Desktop.Width", &value_type
, &value
))) {
239 if (!bbtool
->withdrawn
)
240 desktopSize
.width
= 40;
243 64 / columns
- ((columns
- 1)) * frame
.bevelWidth
;
244 } else if (sscanf(value
.addr
, "%u", &desktopSize
.width
) != 1) {
245 if (!bbtool
->withdrawn
)
246 desktopSize
.width
= 40;
249 64 / columns
- ((columns
- 1)) * frame
.bevelWidth
;
253 if (!(XrmGetResource(resource_db
, "bbkeys.desktop.height",
254 "Bbkeys.Desktop.Height", &value_type
, &value
))) {
255 if (!bbtool
->withdrawn
)
256 desktopSize
.height
= 30;
258 desktopSize
.height
= 48 / columns
;
259 } else if (sscanf(value
.addr
, "%u", &desktopSize
.height
) != 1) {
260 if (!bbtool
->withdrawn
)
261 desktopSize
.width
= 30;
263 desktopSize
.height
= 48 / columns
;
266 /* need this to compute the height */
267 const char *defaultFont
=
268 /* "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*"; */
269 "-*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-*";
272 XFreeFont(bbtool
->getXDisplay(), frame
.font
);
276 if (XrmGetResource
// try to load TitleFont, which will pick up *Font
277 (resource_db
, BB_FONT
, BB_FONT2
, &value_type
, &value
)) {
279 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
281 " bbkeys: couldn't load font '%s'\n"
282 " ... reverting to default font.", value
.addr
);
284 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
286 "bbkeys: couldn't load default font. please check to\n"
287 "make sure the necessary font is installed '%s'\n",
292 } else if (XrmGetResource
// try to load toolbar.font
293 (resource_db
, "toolbar.font", "Toolbar.Font", &value_type
, &value
)) {
295 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
297 " bbkeys: couldn't load font '%s'\n"
298 " ... reverting to default font.", value
.addr
);
300 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
302 "bbkeys: couldn't load default font. please check to\n"
303 "make sure the necessary font is installed '%s'\n",
308 } else if (XrmGetResource
309 (resource_db
, "bbkeys.heightBy.font", "Bbkeys.heightBy.Font",
310 &value_type
, &value
)) {
312 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
314 " bbkeys: couldn't load font '%s'\n"
315 " ... reverting to default font.", value
.addr
);
317 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
319 "bbkeys: couldn't load default font. please check to\n"
320 "make sure the necessary font is installed '%s'\n",
327 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
329 "bbkeys: couldn't load default font. please check to\n"
330 "make sure the necessary font is installed '%s'\n",
337 void Resource::Label(void)
343 /* text-label resources */
344 if (XrmGetResource(resource_db
, "bbkeys.label.transparent",
345 "Bbkeys.label.Transparent", &value_type
, &value
)) {
346 if (!strncasecmp("true", value
.addr
, value
.size
))
347 label
.transparent
= True
;
349 label
.transparent
= False
;
351 label
.transparent
= False
;
353 readTexture("bbkeys.label", "Bbkeys.Label", BB_LABEL
,
354 BB_LABEL2
, "slategrey", "darkslategrey",
355 "Sunken Gradient Diagonal Bevel1", &label
.texture
);
357 readColor("bbkeys.textColor", "Bbkeys.TextColor",
358 BB_LABEL_TEXTCOLOR
, BB_LABEL_TEXTCOLOR2
,
359 "LightGrey", &label
.textColor
);
362 const char *defaultFont
= "-*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-*";
365 XFreeFont(bbtool
->getXDisplay(), label
.font
);
370 (resource_db
, BB_FONT
, BB_FONT2
, &value_type
, &value
)) {
372 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
374 " bbkeys: couldn't load font '%s'\n"
375 " ... reverting to default font.", value
.addr
);
377 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
379 "bbkeys: couldn't load default font. please check to\n"
380 "make sure the necessary font is installed '%s'\n",
385 } else if (XrmGetResource
// try to load toolbar.font
386 (resource_db
, "toolbar.font", "Toolbar.Font", &value_type
, &value
)) {
388 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
390 " bbkeys: couldn't load font '%s'\n"
391 " ... reverting to default font.", value
.addr
);
393 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
395 "bbkeys: couldn't load default font. please check to\n"
396 "make sure the necessary font is installed '%s'\n",
401 } else if (XrmGetResource
402 (resource_db
, "bbkeys.label.font", "Bbkeys.Label.Font",
403 &value_type
, &value
)) {
405 XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
) {
407 " bbkeys: couldn't load font '%s'\n"
408 " ... reverting to default font.", value
.addr
);
410 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
412 "bbkeys: couldn't load default font. please check to\n"
413 "make sure the necessary font is installed '%s'\n",
420 XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
) {
422 "bbkeys: couldn't load default font. please check to\n"
423 "make sure the necessary font is installed '%s'\n",
430 void Resource::Button()
432 readTexture("bbkeys.button", "Bbkeys.Button",
433 BB_BUTTON
, BB_BUTTON2
,
434 "rgb:4/7/8", "rgb:2/2/2",
435 "Raised Gradient Diagonal Bevel1", &button
.texture
);
437 readTexture("bbkeys.button.pressed", "Bbkeys.Button.Pressed",
438 BB_BUTTON_PRESSED
, BB_BUTTON_PRESSED2
,
439 "rgb:4/4/4", "rgb:c/c/c",
440 "Sunken Gradient Diagonal Bevel1", &button
.texture_pressed
);
444 void Resource::Menu()
449 readTexture("bbkeys.menu.frame","Bbkeys.Menu.Frame",BB_MENU_TEXTURE
,BB_MENU_TEXTURE2
,
450 "slategrey","darkslategrey",
451 "Raised Diagonal Gradient Bevel1",&menu
.texture
);
453 readTexture("bbkeys.menu.hilight","Bbkeys.Menu.Hilight",
454 BB_MENU_HILITE_TEXTURE
,BB_MENU_HILITE_TEXTURE2
,
455 "darkslategrey","slategrey",
456 "Raised Elliptic Gradient Bevel2",&menu
.hiTexture
);
458 readColor("bbkeys.menu.highlight.color",
459 "Bbkeys.Menu.Highlight.Color",
460 BB_MENU_HIGHLIGHT_COLOR
,BB_MENU_HIGHLIGHT_COLOR2
,
461 "rgb:c/9/6",&menu
.highlightColor
);
464 BB_MENU_TEXTCOLOR
,BB_MENU_TEXTCOLOR2
,
465 "bbkeys.menu.textColor","Bbkeys.Menu.TextColor",
466 "LightGrey",&menu
.textColor
);
469 BB_MENU_HITEXTCOLOR
,BB_MENU_HITEXTCOLOR2
,
470 "bbkeys.menu.highlight.textColor", "Bbkeys.Menu.Highlight.TextColor",
471 "white",&menu
.hiTextColor
);
473 if (XrmGetResource(resource_db
,"bbkeys.menu.justify","Bbkeys.Menu.Justify",
474 &value_type
, &value
))
476 if (! strncasecmp("left", value
.addr
, value
.size
))
477 menu
.justify
= LeftJustify
;
478 else if (! strncasecmp("right", value
.addr
, value
.size
))
479 menu
.justify
= RightJustify
;
480 else if (! strncasecmp("center", value
.addr
, value
.size
))
481 menu
.justify
= CenterJustify
;
483 menu
.justify
= LeftJustify
;
485 else if (XrmGetResource(resource_db
,BB_MENU_JUSTIFY
,BB_MENU_JUSTIFY2
,
486 &value_type
, &value
))
488 if (! strncasecmp("left", value
.addr
, value
.size
))
489 menu
.justify
= LeftJustify
;
490 else if (! strncasecmp("right", value
.addr
, value
.size
))
491 menu
.justify
= RightJustify
;
492 else if (! strncasecmp("center", value
.addr
, value
.size
))
493 menu
.justify
= CenterJustify
;
495 menu
.justify
= LeftJustify
;
498 menu
.justify
= LeftJustify
;
500 if (XrmGetResource(resource_db
, "bbkeys.menu.bulletStyle",
501 "Bbkeys.Menu.BulletStyle", &value_type
, &value
)) {
502 if (! strncasecmp(value
.addr
, "empty", value
.size
))
503 menu
.bullet_style
= Empty
;
504 else if (! strncasecmp(value
.addr
, "square", value
.size
))
505 menu
.bullet_style
= Square
;
506 else if (! strncasecmp(value
.addr
, "triangle", value
.size
))
507 menu
.bullet_style
= Triangle
;
508 else if (! strncasecmp(value
.addr
, "diamond", value
.size
))
509 menu
.bullet_style
= Diamond
;
511 menu
.bullet_style
= Round
;
513 if (XrmGetResource(resource_db
, BB_MENU_BULLETSTYLE
,
514 BB_MENU_BULLETSTYLE2
, &value_type
, &value
)) {
515 if (! strncasecmp(value
.addr
, "empty", value
.size
))
516 menu
.bullet_style
= Empty
;
517 else if (! strncasecmp(value
.addr
, "square", value
.size
))
518 menu
.bullet_style
= Square
;
519 else if (! strncasecmp(value
.addr
, "triangle", value
.size
))
520 menu
.bullet_style
= Triangle
;
521 else if (! strncasecmp(value
.addr
, "diamond", value
.size
))
522 menu
.bullet_style
= Diamond
;
524 menu
.bullet_style
= Round
;
526 menu
.bullet_style
= Round
;
529 if (XrmGetResource(resource_db
, "bbkeys.menu.bulletPosition",
530 "Bbkeys.Menu.BulletPosition", &value_type
, &value
)) {
531 if (! strncasecmp(value
.addr
, "right", value
.size
))
532 menu
.bullet_pos
= Right
;
534 menu
.bullet_pos
= Left
;
536 if (XrmGetResource(resource_db
, BB_MENU_BULLETPOSITION
,
537 BB_MENU_BULLETPOSITION2
, &value_type
, &value
)) {
538 if (! strncasecmp(value
.addr
, "right", value
.size
))
539 menu
.bullet_pos
= Right
;
541 menu
.bullet_pos
= Left
;
543 menu
.bullet_pos
= Left
;
546 const char *defaultFont
= "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*";
550 XFreeFont(bbtool
->getXDisplay(), menu
.font
);
554 if (XrmGetResource(resource_db
, BB_MENU_FONT
, BB_MENU_FONT2
, &value_type
, &value
))
556 if ((menu
.font
= XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
)
558 fprintf(stderr
, " blackbox: couldn't load font '%s'\n"
559 " ... reverting to default font.", value
.addr
);
560 if ((menu
.font
= XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
)
563 "blackbox: couldn't load default font. please check to\n"
564 "make sure the necessary font is installed '%s'\n",
569 } else if (XrmGetResource(resource_db
, "bbkeys.menu.font", "Bbkeys.Menu.Font",
570 &value_type
, &value
))
572 if ((menu
.font
= XLoadQueryFont(bbtool
->getXDisplay(), value
.addr
)) == NULL
)
574 fprintf(stderr
, " blackbox: couldn't load font '%s'\n"
575 " ... reverting to default font.", value
.addr
);
576 if ((menu
.font
= XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
)
579 "blackbox: couldn't load default font. please check to\n"
580 "make sure the necessary font is installed '%s'\n",
586 if ((menu
.font
= XLoadQueryFont(bbtool
->getXDisplay(), defaultFont
)) == NULL
)
588 fprintf(stderr
,"blackbox: couldn't load default font. please check to\n"
589 "make sure the necessary font is installed '%s'\n", defaultFont
);