]>
Dogcows Code - chaz/openbox/blob - otk/style.cc
3 #endif // HAVE_CONFIG_H
13 Style::Style() : font(NULL
)
17 Style::Style(BImageControl
*ctrl
)
18 : image_control(ctrl
), font(0),
19 screen_number(ctrl
->getScreenInfo()->getScreenNumber())
27 if (close_button
.mask
!= None
)
28 XFreePixmap(OBDisplay::display
, close_button
.mask
);
29 if (max_button
.mask
!= None
)
30 XFreePixmap(OBDisplay::display
, max_button
.mask
);
31 if (icon_button
.mask
!= None
)
32 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
33 if (stick_button
.mask
!= None
)
34 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
36 max_button
.mask
= None
;
37 close_button
.mask
= None
;
38 icon_button
.mask
= None
;
39 stick_button
.mask
= None
;
42 void Style::load(const Configuration
&style
) {
45 // load fonts/fontsets
49 font
= readDatabaseFont("window.", style
);
52 t_focus
= readDatabaseTexture("window.title.focus", "white", style
);
53 t_unfocus
= readDatabaseTexture("window.title.unfocus", "black", style
);
55 l_focus
= readDatabaseTexture("window.label.focus", "white", style
);
56 l_unfocus
= readDatabaseTexture("window.label.unfocus", "black", style
);
58 h_focus
= readDatabaseTexture("window.handle.focus", "white", style
);
59 h_unfocus
= readDatabaseTexture("window.handle.unfocus", "black", style
);
61 g_focus
= readDatabaseTexture("window.grip.focus", "white", style
);
62 g_unfocus
= readDatabaseTexture("window.grip.unfocus", "black", style
);
64 b_focus
= readDatabaseTexture("window.button.focus", "white", style
);
65 b_unfocus
= readDatabaseTexture("window.button.unfocus", "black", style
);
66 b_pressed
= readDatabaseTexture("window.button.pressed", "black", style
);
68 //if neither of these can be found, we will use the previous resource
69 b_pressed_focus
= readDatabaseTexture("window.button.pressed.focus",
70 "black", style
, true);
71 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed.unfocus",
72 "black", style
, true);
74 if (close_button
.mask
!= None
)
75 XFreePixmap(OBDisplay::display
, close_button
.mask
);
76 if (max_button
.mask
!= None
)
77 XFreePixmap(OBDisplay::display
, max_button
.mask
);
78 if (icon_button
.mask
!= None
)
79 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
80 if (stick_button
.mask
!= None
)
81 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
83 close_button
.mask
= max_button
.mask
= icon_button
.mask
84 = icon_button
.mask
= None
;
86 readDatabaseMask("window.button.close.mask", close_button
, style
);
87 readDatabaseMask("window.button.max.mask", max_button
, style
);
88 readDatabaseMask("window.button.icon.mask", icon_button
, style
);
89 readDatabaseMask("window.button.stick.mask", stick_button
, style
);
91 // we create the window.frame texture by hand because it exists only to
92 // make the code cleaner and is not actually used for display
93 BColor color
= readDatabaseColor("window.frame.focusColor", "white",
95 f_focus
= BTexture("solid flat", screen_number
, image_control
);
96 f_focus
.setColor(color
);
98 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
99 f_unfocus
= BTexture("solid flat", screen_number
, image_control
);
100 f_unfocus
.setColor(color
);
102 l_text_focus
= readDatabaseColor("window.label.focus.textColor",
104 l_text_unfocus
= readDatabaseColor("window.label.unfocus.textColor",
107 b_pic_focus
= readDatabaseColor("window.button.focus.picColor",
109 b_pic_unfocus
= readDatabaseColor("window.button.unfocus.picColor",
112 justify
= LeftJustify
;
114 if (style
.getValue("window.justify", s
)) {
115 if (s
== "right" || s
== "Right")
116 justify
= RightJustify
;
117 else if (s
== "center" || s
== "Center")
118 justify
= CenterJustify
;
122 if (t_focus
.texture() == BTexture::Parent_Relative
)
124 if (t_unfocus
.texture() == BTexture::Parent_Relative
)
125 t_unfocus
= f_unfocus
;
126 if (h_focus
.texture() == BTexture::Parent_Relative
)
128 if (h_unfocus
.texture() == BTexture::Parent_Relative
)
129 h_unfocus
= f_unfocus
;
131 border_color
= readDatabaseColor("borderColor", "black", style
);
133 // load bevel, border and handle widths
135 const ScreenInfo
*s_info
= OBDisplay::screenInfo(screen_number
);
136 unsigned int width
= s_info
->getRect().width();
138 if (! style
.getValue("handleWidth", handle_width
) ||
139 handle_width
> width
/2 || handle_width
== 0)
142 if (! style
.getValue("borderWidth", border_width
))
145 if (! style
.getValue("bevelWidth", bevel_width
)
146 || bevel_width
> width
/2 || bevel_width
== 0)
149 if (! style
.getValue("frameWidth", frame_width
)
150 || frame_width
> width
/2)
151 frame_width
= bevel_width
;
153 if (style
.getValue("rootCommand", s
))
154 bexec(s
, s_info
->displayString());
158 void Style::doJustify(const std::string
&text
, int &start_pos
,
159 unsigned int max_length
,
160 unsigned int modifier
) const {
161 size_t text_len
= text
.size();
165 length
= font
->measureString(std::string(text
, 0, text_len
)) + modifier
;
166 } while (length
> max_length
&& text_len
-- > 0);
170 start_pos
+= max_length
- length
;
174 start_pos
+= (max_length
- length
) / 2;
184 void Style::readDatabaseMask(const std::string
&rname
, PixmapMask
&pixmapMask
,
185 const Configuration
&style
) {
186 Window root_window
= OBDisplay::screenInfo(screen_number
)->getRootWindow();
188 int hx
, hy
; //ignored
189 int ret
= BitmapOpenFailed
; //default to failure.
191 if (style
.getValue(rname
, s
))
193 if (s
[0] != '/' && s
[0] != '~')
195 std::string xbmFile
= std::string("~/.openbox/buttons/") + s
;
196 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
197 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
198 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
200 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
201 expandTilde(s
).c_str(), &pixmapMask
.w
,
202 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
204 if (ret
== BitmapSuccess
)
208 pixmapMask
.mask
= None
;
209 pixmapMask
.w
= pixmapMask
.h
= 0;
213 BTexture
Style::readDatabaseTexture(const std::string
&rname
,
214 const std::string
&default_color
,
215 const Configuration
&style
,
221 if (style
.getValue(rname
, s
))
222 texture
= BTexture(s
);
223 else if (allowNoTexture
) //no default
224 texture
.setTexture(BTexture::NoTexture
);
226 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
228 // associate this texture with this screen
229 texture
.setScreen(screen_number
);
230 texture
.setImageControl(image_control
);
232 if (texture
.texture() != BTexture::NoTexture
) {
233 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
235 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
237 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
238 default_color
, style
));
245 BColor
Style::readDatabaseColor(const std::string
&rname
,
246 const std::string
&default_color
,
247 const Configuration
&style
) {
250 if (style
.getValue(rname
, s
))
251 color
= BColor(s
, screen_number
);
253 color
= BColor(default_color
, screen_number
);
258 BFont
*Style::readDatabaseFont(const std::string
&rbasename
,
259 const Configuration
&style
) {
260 std::string fontname
;
265 if (style
.getValue(rbasename
+ "xft.font", s
) &&
266 style
.getValue(rbasename
+ "xft.size", i
)) {
267 std::string family
= s
;
270 bool dropShadow
= False
;
272 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
273 if (s
.find("bold") != std::string::npos
)
275 if (s
.find("italic") != std::string::npos
)
277 if (s
.find("shadow") != std::string::npos
)
281 unsigned char offset
= 1;
282 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
283 offset
= atoi(s
.c_str()); //doesn't detect errors
284 if (offset
> CHAR_MAX
)
288 unsigned char tint
= 0x40;
289 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
290 tint
= atoi(s
.c_str());
294 BFont
*b
= new BFont(screen_number
, family
, i
, bold
, italic
,
295 dropShadow
&& shadow_fonts
,
296 offset
, tint
, aa_fonts
);
302 if (style
.getValue(rbasename
+ "xft.font", s
))
303 printf("Unable to load font \"%s\". Exiting\n", s
.c_str());
305 printf("Font not defined by style. Exiting\n");
306 exit(2); // can't continue without a font
This page took 0.045832 seconds and 4 git commands to generate.