3 #endif // HAVE_CONFIG_H
13 Style::Style() : font(NULL)
17 Style::Style(unsigned int screen)
18 : font(0), screen_number(screen)
22 Style::Style(unsigned int screen, BImageControl *ctrl)
23 : image_control(ctrl), font(0), screen_number(screen)
31 if (close_button.mask != None)
32 XFreePixmap(OBDisplay::display, close_button.mask);
33 if (max_button.mask != None)
34 XFreePixmap(OBDisplay::display, max_button.mask);
35 if (icon_button.mask != None)
36 XFreePixmap(OBDisplay::display, icon_button.mask);
37 if (stick_button.mask != None)
38 XFreePixmap(OBDisplay::display, stick_button.mask);
40 max_button.mask = None;
41 close_button.mask = None;
42 icon_button.mask = None;
43 stick_button.mask = None;
46 void Style::load(Configuration &style) {
49 // load fonts/fontsets
53 font = readDatabaseFont("window.", style);
56 t_focus = readDatabaseTexture("window.title.focus", "white", style);
57 t_unfocus = readDatabaseTexture("window.title.unfocus", "black", style);
59 l_focus = readDatabaseTexture("window.label.focus", "white", style);
60 l_unfocus = readDatabaseTexture("window.label.unfocus", "black", style);
62 h_focus = readDatabaseTexture("window.handle.focus", "white", style);
63 h_unfocus = readDatabaseTexture("window.handle.unfocus", "black", style);
65 g_focus = readDatabaseTexture("window.grip.focus", "white", style);
66 g_unfocus = readDatabaseTexture("window.grip.unfocus", "black", style);
68 b_focus = readDatabaseTexture("window.button.focus", "white", style);
69 b_unfocus = readDatabaseTexture("window.button.unfocus", "black", style);
70 b_pressed = readDatabaseTexture("window.button.pressed", "black", style);
72 //if neither of these can be found, we will use the previous resource
73 b_pressed_focus = readDatabaseTexture("window.button.pressed.focus",
74 "black", style, true);
75 b_pressed_unfocus = readDatabaseTexture("window.button.pressed.unfocus",
76 "black", style, true);
78 if (close_button.mask != None)
79 XFreePixmap(OBDisplay::display, close_button.mask);
80 if (max_button.mask != None)
81 XFreePixmap(OBDisplay::display, max_button.mask);
82 if (icon_button.mask != None)
83 XFreePixmap(OBDisplay::display, icon_button.mask);
84 if (stick_button.mask != None)
85 XFreePixmap(OBDisplay::display, stick_button.mask);
87 close_button.mask = max_button.mask = icon_button.mask
88 = icon_button.mask = None;
90 readDatabaseMask("window.button.close.mask", close_button, style);
91 readDatabaseMask("window.button.max.mask", max_button, style);
92 readDatabaseMask("window.button.icon.mask", icon_button, style);
93 readDatabaseMask("window.button.stick.mask", stick_button, style);
95 // we create the window.frame texture by hand because it exists only to
96 // make the code cleaner and is not actually used for display
97 BColor color = readDatabaseColor("window.frame.focusColor", "white",
99 f_focus = BTexture("solid flat", screen_number, image_control);
100 f_focus.setColor(color);
102 color = readDatabaseColor("window.frame.unfocusColor", "white", style);
103 f_unfocus = BTexture("solid flat", screen_number, image_control);
104 f_unfocus.setColor(color);
106 l_text_focus = readDatabaseColor("window.label.focus.textColor",
108 l_text_unfocus = readDatabaseColor("window.label.unfocus.textColor",
111 b_pic_focus = readDatabaseColor("window.button.focus.picColor",
113 b_pic_unfocus = readDatabaseColor("window.button.unfocus.picColor",
116 justify = LeftJustify;
118 if (style.getValue("window.justify", s)) {
119 if (s == "right" || s == "Right")
120 justify = RightJustify;
121 else if (s == "center" || s == "Center")
122 justify = CenterJustify;
126 if (t_focus.texture() == BTexture::Parent_Relative)
128 if (t_unfocus.texture() == BTexture::Parent_Relative)
129 t_unfocus = f_unfocus;
130 if (h_focus.texture() == BTexture::Parent_Relative)
132 if (h_unfocus.texture() == BTexture::Parent_Relative)
133 h_unfocus = f_unfocus;
135 border_color = readDatabaseColor("borderColor", "black", style);
137 // load bevel, border and handle widths
139 const ScreenInfo *s_info = OBDisplay::screenInfo(screen_number);
140 unsigned int width = s_info->getRect().width();
142 if (! style.getValue("handleWidth", handle_width) ||
143 handle_width > width/2 || handle_width == 0)
146 if (! style.getValue("borderWidth", border_width))
149 if (! style.getValue("bevelWidth", bevel_width)
150 || bevel_width > width/2 || bevel_width == 0)
153 if (! style.getValue("frameWidth", frame_width)
154 || frame_width > width/2)
155 frame_width = bevel_width;
157 if (style.getValue("rootCommand", s))
158 bexec(s, s_info->displayString());
162 void Style::doJustify(const std::string &text, int &start_pos,
163 unsigned int max_length,
164 unsigned int modifier) const {
165 size_t text_len = text.size();
169 length = font->measureString(std::string(text, 0, text_len)) + modifier;
170 } while (length > max_length && text_len-- > 0);
174 start_pos += max_length - length;
178 start_pos += (max_length - length) / 2;
188 void Style::readDatabaseMask(const std::string &rname, PixmapMask &pixmapMask,
189 const Configuration &style) {
190 Window root_window = OBDisplay::screenInfo(screen_number)->getRootWindow();
192 int hx, hy; //ignored
193 int ret = BitmapOpenFailed; //default to failure.
195 if (style.getValue(rname, s))
197 if (s[0] != '/' && s[0] != '~')
199 std::string xbmFile = std::string("~/.openbox/buttons/") + s;
200 ret = XReadBitmapFile(OBDisplay::display, root_window,
201 expandTilde(xbmFile).c_str(), &pixmapMask.w,
202 &pixmapMask.h, &pixmapMask.mask, &hx, &hy);
204 ret = XReadBitmapFile(OBDisplay::display, root_window,
205 expandTilde(s).c_str(), &pixmapMask.w,
206 &pixmapMask.h, &pixmapMask.mask, &hx, &hy);
208 if (ret == BitmapSuccess)
212 pixmapMask.mask = None;
213 pixmapMask.w = pixmapMask.h = 0;
217 BTexture Style::readDatabaseTexture(const std::string &rname,
218 const std::string &default_color,
219 const Configuration &style,
225 if (style.getValue(rname, s))
226 texture = BTexture(s);
227 else if (allowNoTexture) //no default
228 texture.setTexture(BTexture::NoTexture);
230 texture.setTexture(BTexture::Solid | BTexture::Flat);
232 // associate this texture with this screen
233 texture.setScreen(screen_number);
234 texture.setImageControl(image_control);
236 if (texture.texture() != BTexture::NoTexture) {
237 texture.setColor(readDatabaseColor(rname + ".color", default_color,
239 texture.setColorTo(readDatabaseColor(rname + ".colorTo", default_color,
241 texture.setBorderColor(readDatabaseColor(rname + ".borderColor",
242 default_color, style));
249 BColor Style::readDatabaseColor(const std::string &rname,
250 const std::string &default_color,
251 const Configuration &style) {
254 if (style.getValue(rname, s))
255 color = BColor(s, screen_number);
257 color = BColor(default_color, screen_number);
262 BFont *Style::readDatabaseFont(const std::string &rbasename,
263 const Configuration &style) {
264 std::string fontname;
269 if (style.getValue(rbasename + "xft.font", s) &&
270 style.getValue(rbasename + "xft.size", i)) {
271 std::string family = s;
274 bool dropShadow = False;
276 if (style.getValue(rbasename + "xft.flags", s)) {
277 if (s.find("bold") != std::string::npos)
279 if (s.find("italic") != std::string::npos)
281 if (s.find("shadow") != std::string::npos)
285 unsigned char offset = 1;
286 if (style.getValue(rbasename + "xft.shadow.offset", s)) {
287 offset = atoi(s.c_str()); //doesn't detect errors
288 if (offset > CHAR_MAX)
292 unsigned char tint = 0x40;
293 if (style.getValue(rbasename + "xft.shadow.tint", s)) {
294 tint = atoi(s.c_str());
298 BFont *b = new BFont(screen_number, family, i, bold, italic,
299 dropShadow && shadow_fonts,
300 offset, tint, aa_fonts);
306 exit(2); // can't continue without a font