]>
Dogcows Code - chaz/openbox/blob - otk/style.cc
3c40e24bb5fcc87773aac642c50b45b881c8de5d
3 #endif // HAVE_CONFIG_H
14 Style::Style() : font(NULL
)
18 Style::Style(BImageControl
*ctrl
)
19 : image_control(ctrl
), font(0),
20 screen_number(ctrl
->getScreenInfo()->getScreenNumber())
28 if (close_button
.mask
!= None
)
29 XFreePixmap(OBDisplay::display
, close_button
.mask
);
30 if (max_button
.mask
!= None
)
31 XFreePixmap(OBDisplay::display
, max_button
.mask
);
32 if (icon_button
.mask
!= None
)
33 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
34 if (stick_button
.mask
!= None
)
35 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
37 max_button
.mask
= None
;
38 close_button
.mask
= None
;
39 icon_button
.mask
= None
;
40 stick_button
.mask
= None
;
43 void Style::load(const Configuration
&style
) {
46 // load fonts/fontsets
50 font
= readDatabaseFont("window.", style
);
53 t_focus
= readDatabaseTexture("window.title.focus", "white", style
);
54 t_unfocus
= readDatabaseTexture("window.title.unfocus", "black", style
);
56 l_focus
= readDatabaseTexture("window.label.focus", "white", style
);
57 l_unfocus
= readDatabaseTexture("window.label.unfocus", "black", style
);
59 h_focus
= readDatabaseTexture("window.handle.focus", "white", style
);
60 h_unfocus
= readDatabaseTexture("window.handle.unfocus", "black", style
);
62 g_focus
= readDatabaseTexture("window.grip.focus", "white", style
);
63 g_unfocus
= readDatabaseTexture("window.grip.unfocus", "black", style
);
65 b_focus
= readDatabaseTexture("window.button.focus", "white", style
);
66 b_unfocus
= readDatabaseTexture("window.button.unfocus", "black", style
);
67 b_pressed
= readDatabaseTexture("window.button.pressed", "black", style
);
69 //if neither of these can be found, we will use the previous resource
70 b_pressed_focus
= readDatabaseTexture("window.button.pressed.focus",
71 "black", style
, true);
72 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed.unfocus",
73 "black", style
, true);
75 if (close_button
.mask
!= None
)
76 XFreePixmap(OBDisplay::display
, close_button
.mask
);
77 if (max_button
.mask
!= None
)
78 XFreePixmap(OBDisplay::display
, max_button
.mask
);
79 if (icon_button
.mask
!= None
)
80 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
81 if (stick_button
.mask
!= None
)
82 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
84 close_button
.mask
= max_button
.mask
= icon_button
.mask
85 = icon_button
.mask
= None
;
87 readDatabaseMask("window.button.close.mask", close_button
, style
);
88 readDatabaseMask("window.button.max.mask", max_button
, style
);
89 readDatabaseMask("window.button.icon.mask", icon_button
, style
);
90 readDatabaseMask("window.button.stick.mask", stick_button
, style
);
92 // we create the window.frame texture by hand because it exists only to
93 // make the code cleaner and is not actually used for display
94 BColor color
= readDatabaseColor("window.frame.focusColor", "white",
96 f_focus
= BTexture("solid flat", screen_number
, image_control
);
97 f_focus
.setColor(color
);
99 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
100 f_unfocus
= BTexture("solid flat", screen_number
, image_control
);
101 f_unfocus
.setColor(color
);
103 l_text_focus
= readDatabaseColor("window.label.focus.textColor",
105 l_text_unfocus
= readDatabaseColor("window.label.unfocus.textColor",
108 b_pic_focus
= readDatabaseColor("window.button.focus.picColor",
110 b_pic_unfocus
= readDatabaseColor("window.button.unfocus.picColor",
113 justify
= LeftJustify
;
115 if (style
.getValue("window.justify", s
)) {
116 if (s
== "right" || s
== "Right")
117 justify
= RightJustify
;
118 else if (s
== "center" || s
== "Center")
119 justify
= CenterJustify
;
123 if (t_focus
.texture() == BTexture::Parent_Relative
)
125 if (t_unfocus
.texture() == BTexture::Parent_Relative
)
126 t_unfocus
= f_unfocus
;
127 if (h_focus
.texture() == BTexture::Parent_Relative
)
129 if (h_unfocus
.texture() == BTexture::Parent_Relative
)
130 h_unfocus
= f_unfocus
;
132 border_color
= readDatabaseColor("borderColor", "black", style
);
134 // load bevel, border and handle widths
136 const ScreenInfo
*s_info
= OBDisplay::screenInfo(screen_number
);
137 unsigned int width
= s_info
->getRect().width();
139 if (! style
.getValue("handleWidth", handle_width
) ||
140 handle_width
> width
/2 || handle_width
== 0)
143 if (! style
.getValue("borderWidth", border_width
))
146 if (! style
.getValue("bevelWidth", bevel_width
)
147 || bevel_width
> width
/2 || bevel_width
== 0)
150 if (! style
.getValue("frameWidth", frame_width
)
151 || frame_width
> width
/2)
152 frame_width
= bevel_width
;
154 if (style
.getValue("rootCommand", s
))
155 bexec(s
, s_info
->displayString());
159 void Style::doJustify(const std::string
&text
, int &start_pos
,
160 unsigned int max_length
,
161 unsigned int modifier
) const {
162 size_t text_len
= text
.size();
166 length
= font
->measureString(std::string(text
, 0, text_len
)) + modifier
;
167 } while (length
> max_length
&& text_len
-- > 0);
171 start_pos
+= max_length
- length
;
175 start_pos
+= (max_length
- length
) / 2;
185 void Style::readDatabaseMask(const std::string
&rname
, PixmapMask
&pixmapMask
,
186 const Configuration
&style
) {
187 Window root_window
= OBDisplay::screenInfo(screen_number
)->getRootWindow();
189 int hx
, hy
; //ignored
190 int ret
= BitmapOpenFailed
; //default to failure.
192 if (style
.getValue(rname
, s
))
194 if (s
[0] != '/' && s
[0] != '~')
196 std::string xbmFile
= std::string("~/.openbox/buttons/") + s
;
197 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
198 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
199 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
201 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
202 expandTilde(s
).c_str(), &pixmapMask
.w
,
203 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
205 if (ret
== BitmapSuccess
)
209 pixmapMask
.mask
= None
;
210 pixmapMask
.w
= pixmapMask
.h
= 0;
214 BTexture
Style::readDatabaseTexture(const std::string
&rname
,
215 const std::string
&default_color
,
216 const Configuration
&style
,
222 if (style
.getValue(rname
, s
))
223 texture
= BTexture(s
);
224 else if (allowNoTexture
) //no default
225 texture
.setTexture(BTexture::NoTexture
);
227 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
229 // associate this texture with this screen
230 texture
.setScreen(screen_number
);
231 texture
.setImageControl(image_control
);
233 if (texture
.texture() != BTexture::NoTexture
) {
234 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
236 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
238 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
239 default_color
, style
));
246 BColor
Style::readDatabaseColor(const std::string
&rname
,
247 const std::string
&default_color
,
248 const Configuration
&style
) {
251 if (style
.getValue(rname
, s
))
252 color
= BColor(s
, screen_number
);
254 color
= BColor(default_color
, screen_number
);
259 BFont
*Style::readDatabaseFont(const std::string
&rbasename
,
260 const Configuration
&style
) {
261 std::string fontname
;
266 if (style
.getValue(rbasename
+ "xft.font", s
) &&
267 style
.getValue(rbasename
+ "xft.size", i
)) {
268 std::string family
= s
;
271 bool dropShadow
= False
;
273 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
274 if (s
.find("bold") != std::string::npos
)
276 if (s
.find("italic") != std::string::npos
)
278 if (s
.find("shadow") != std::string::npos
)
282 unsigned char offset
= 1;
283 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
284 offset
= atoi(s
.c_str()); //doesn't detect errors
285 if (offset
> CHAR_MAX
)
289 unsigned char tint
= 0x40;
290 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
291 tint
= atoi(s
.c_str());
295 BFont
*b
= new BFont(screen_number
, family
, i
, bold
, italic
,
296 dropShadow
&& shadow_fonts
,
297 offset
, tint
, aa_fonts
);
303 if (style
.getValue(rbasename
+ "xft.font", s
))
304 printf("Unable to load font \"%s\". Exiting\n", s
.c_str());
306 printf("Font not defined by style. Exiting\n");
307 exit(2); // can't continue without a font
This page took 0.050432 seconds and 4 git commands to generate.