]>
Dogcows Code - chaz/openbox/blob - otk/style.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
16 Style::Style() : font(NULL
)
20 Style::Style(BImageControl
*ctrl
)
21 : image_control(ctrl
), font(0),
22 screen_number(ctrl
->getScreenInfo()->getScreenNumber())
30 if (close_button
.mask
!= None
)
31 XFreePixmap(OBDisplay::display
, close_button
.mask
);
32 if (max_button
.mask
!= None
)
33 XFreePixmap(OBDisplay::display
, max_button
.mask
);
34 if (icon_button
.mask
!= None
)
35 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
36 if (stick_button
.mask
!= None
)
37 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
39 max_button
.mask
= None
;
40 close_button
.mask
= None
;
41 icon_button
.mask
= None
;
42 stick_button
.mask
= None
;
45 void Style::load(const Configuration
&style
) {
48 // load fonts/fontsets
52 font
= readDatabaseFont("window.", style
);
55 t_focus
= readDatabaseTexture("window.title.focus", "white", style
);
56 t_unfocus
= readDatabaseTexture("window.title.unfocus", "black", style
);
58 l_focus
= readDatabaseTexture("window.label.focus", "white", style
);
59 l_unfocus
= readDatabaseTexture("window.label.unfocus", "black", style
);
61 h_focus
= readDatabaseTexture("window.handle.focus", "white", style
);
62 h_unfocus
= readDatabaseTexture("window.handle.unfocus", "black", style
);
64 g_focus
= readDatabaseTexture("window.grip.focus", "white", style
);
65 g_unfocus
= readDatabaseTexture("window.grip.unfocus", "black", style
);
67 b_focus
= readDatabaseTexture("window.button.focus", "white", style
);
68 b_unfocus
= readDatabaseTexture("window.button.unfocus", "black", style
);
69 b_pressed
= readDatabaseTexture("window.button.pressed", "black", style
);
71 //if neither of these can be found, we will use the previous resource
72 b_pressed_focus
= readDatabaseTexture("window.button.pressed.focus",
73 "black", style
, true);
74 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed.unfocus",
75 "black", style
, true);
77 if (close_button
.mask
!= None
)
78 XFreePixmap(OBDisplay::display
, close_button
.mask
);
79 if (max_button
.mask
!= None
)
80 XFreePixmap(OBDisplay::display
, max_button
.mask
);
81 if (icon_button
.mask
!= None
)
82 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
83 if (stick_button
.mask
!= None
)
84 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
86 close_button
.mask
= max_button
.mask
= icon_button
.mask
87 = icon_button
.mask
= None
;
89 readDatabaseMask("window.button.close.mask", close_button
, style
);
90 readDatabaseMask("window.button.max.mask", max_button
, style
);
91 readDatabaseMask("window.button.icon.mask", icon_button
, style
);
92 readDatabaseMask("window.button.stick.mask", stick_button
, style
);
94 // we create the window.frame texture by hand because it exists only to
95 // make the code cleaner and is not actually used for display
96 BColor color
= readDatabaseColor("window.frame.focusColor", "white",
98 f_focus
= BTexture("solid flat", screen_number
, image_control
);
99 f_focus
.setColor(color
);
101 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
102 f_unfocus
= BTexture("solid flat", screen_number
, image_control
);
103 f_unfocus
.setColor(color
);
105 l_text_focus
= readDatabaseColor("window.label.focus.textColor",
107 l_text_unfocus
= readDatabaseColor("window.label.unfocus.textColor",
110 b_pic_focus
= readDatabaseColor("window.button.focus.picColor",
112 b_pic_unfocus
= readDatabaseColor("window.button.unfocus.picColor",
115 justify
= LeftJustify
;
117 if (style
.getValue("window.justify", s
)) {
118 if (s
== "right" || s
== "Right")
119 justify
= RightJustify
;
120 else if (s
== "center" || s
== "Center")
121 justify
= CenterJustify
;
125 if (t_focus
.texture() == BTexture::Parent_Relative
)
127 if (t_unfocus
.texture() == BTexture::Parent_Relative
)
128 t_unfocus
= f_unfocus
;
129 if (h_focus
.texture() == BTexture::Parent_Relative
)
131 if (h_unfocus
.texture() == BTexture::Parent_Relative
)
132 h_unfocus
= f_unfocus
;
134 border_color
= readDatabaseColor("borderColor", "black", style
);
136 // load bevel, border and handle widths
138 const ScreenInfo
*s_info
= OBDisplay::screenInfo(screen_number
);
139 unsigned int width
= s_info
->getRect().width();
141 if (! style
.getValue("handleWidth", handle_width
) ||
142 handle_width
> width
/2 || handle_width
== 0)
145 if (! style
.getValue("borderWidth", border_width
))
148 if (! style
.getValue("bevelWidth", bevel_width
)
149 || bevel_width
> width
/2 || bevel_width
== 0)
152 if (! style
.getValue("frameWidth", frame_width
)
153 || frame_width
> width
/2)
154 frame_width
= bevel_width
;
156 if (style
.getValue("rootCommand", s
))
157 bexec(s
, s_info
->displayString());
161 void Style::readDatabaseMask(const std::string
&rname
, PixmapMask
&pixmapMask
,
162 const Configuration
&style
) {
163 Window root_window
= OBDisplay::screenInfo(screen_number
)->getRootWindow();
165 int hx
, hy
; //ignored
166 int ret
= BitmapOpenFailed
; //default to failure.
168 if (style
.getValue(rname
, s
))
170 if (s
[0] != '/' && s
[0] != '~')
172 std::string xbmFile
= std::string("~/.openbox/buttons/") + s
;
173 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
174 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
175 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
177 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
178 expandTilde(s
).c_str(), &pixmapMask
.w
,
179 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
181 if (ret
== BitmapSuccess
)
185 pixmapMask
.mask
= None
;
186 pixmapMask
.w
= pixmapMask
.h
= 0;
190 BTexture
Style::readDatabaseTexture(const std::string
&rname
,
191 const std::string
&default_color
,
192 const Configuration
&style
,
198 if (style
.getValue(rname
, s
))
199 texture
= BTexture(s
);
200 else if (allowNoTexture
) //no default
201 texture
.setTexture(BTexture::NoTexture
);
203 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
205 // associate this texture with this screen
206 texture
.setScreen(screen_number
);
207 texture
.setImageControl(image_control
);
209 if (texture
.texture() != BTexture::NoTexture
) {
210 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
212 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
214 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
215 default_color
, style
));
222 BColor
Style::readDatabaseColor(const std::string
&rname
,
223 const std::string
&default_color
,
224 const Configuration
&style
) {
227 if (style
.getValue(rname
, s
))
228 color
= BColor(s
, screen_number
);
230 color
= BColor(default_color
, screen_number
);
235 BFont
*Style::readDatabaseFont(const std::string
&rbasename
,
236 const Configuration
&style
) {
237 std::string fontstring
, s
;
239 // XXX: load all this font stuff from the style...
241 bool dropShadow
= True
;
243 unsigned char offset
= 1;
244 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
245 offset
= atoi(s
.c_str()); //doesn't detect errors
246 if (offset
> CHAR_MAX
)
250 unsigned char tint
= 0x40;
251 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
252 tint
= atoi(s
.c_str());
255 fontstring
= "Arial,Sans-8:bold";
257 // if this fails, it ::exit()'s
258 return new BFont(screen_number
, fontstring
, dropShadow
, offset
, tint
);
This page took 0.048814 seconds and 4 git commands to generate.