]> Dogcows Code - chaz/openbox/blobdiff - otk/style.cc
use the right lib
[chaz/openbox] / otk / style.cc
index d98c926b5a21e8d23070382c62a44085f49fafaa..f0aeddabc9d08cc57ac7e7115fc20fdbc4062571 100644 (file)
@@ -1,10 +1,13 @@
-#ifdef    HAVE_CONFIG_H
-#include "../config.h"
-#endif // HAVE_CONFIG_H
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
 
 #include <assert.h>
-#include "display.hh"
+#include <iostream>
 
+#include "display.hh"
 #include "util.hh"
 #include "style.hh"
 
@@ -14,13 +17,9 @@ Style::Style() : font(NULL)
 {
 }
 
-Style::Style(unsigned int screen)
-  : font(NULL), screen_number(screen)
-{
-}
-
-Style::Style(unsigned int screen, BImageControl *ctrl)
-  : image_control(ctrl), font(NULL), screen_number(screen)
+Style::Style(BImageControl *ctrl)
+  : image_control(ctrl), font(0),
+    screen_number(ctrl->getScreenInfo()->screen())
 {
 }
 
@@ -43,7 +42,7 @@ Style::~Style() {
   stick_button.mask = None;
 }
 
-void Style::load(Configuration &style) {
+void Style::load(const Configuration &style) {
   std::string s;
 
   // load fonts/fontsets
@@ -67,13 +66,21 @@ void Style::load(Configuration &style) {
 
   b_focus = readDatabaseTexture("window.button.focus", "white", style);
   b_unfocus = readDatabaseTexture("window.button.unfocus", "black", style);
-  b_pressed = readDatabaseTexture("window.button.pressed", "black", style);
 
   //if neither of these can be found, we will use the previous resource
   b_pressed_focus = readDatabaseTexture("window.button.pressed.focus",
                                         "black", style, true);
+  if (b_pressed_focus.texture() == BTexture::NoTexture) {
+    b_pressed_focus = readDatabaseTexture("window.button.pressed", "black",
+                                          style);
+  }
+    
   b_pressed_unfocus = readDatabaseTexture("window.button.pressed.unfocus",
                                           "black", style, true);
+  if (b_pressed_unfocus.texture() == BTexture::NoTexture) {
+    b_pressed_unfocus = readDatabaseTexture("window.button.pressed", "black",
+                                            style);
+  }
 
   if (close_button.mask != None)
     XFreePixmap(OBDisplay::display, close_button.mask);
@@ -137,7 +144,7 @@ void Style::load(Configuration &style) {
   // load bevel, border and handle widths
 
   const ScreenInfo *s_info = OBDisplay::screenInfo(screen_number);
-  unsigned int width = s_info->getRect().width();
+  unsigned int width = s_info->rect().width();
 
   if (! style.getValue("handleWidth", handle_width) ||
       handle_width > width/2 || handle_width == 0)
@@ -159,47 +166,25 @@ void Style::load(Configuration &style) {
 }
 
 
-void Style::doJustify(const std::string &text, int &start_pos,
-                      unsigned int max_length,
-                      unsigned int modifier) const {
-  size_t text_len = text.size();
-  unsigned int length;
-
-  do {
-    length = font->measureString(std::string(text, 0, text_len)) + modifier;
-  } while (length > max_length && text_len-- > 0);
-
-  switch (justify) {
-  case RightJustify:
-    start_pos += max_length - length;
-    break;
-
-  case CenterJustify:
-    start_pos += (max_length - length) / 2;
-    break;
-
-  case LeftJustify:
-  default:
-    break;
-  }
-}
-
-
 void Style::readDatabaseMask(const std::string &rname, PixmapMask &pixmapMask,
                              const Configuration &style) {
-  Window root_window = OBDisplay::screenInfo(screen_number)->getRootWindow();
+  Window root_window = OBDisplay::screenInfo(screen_number)->rootWindow();
   std::string s;
   int hx, hy; //ignored
   int ret = BitmapOpenFailed; //default to failure.
   
-  if (style.getValue(rname, s))
-  {
-    if (s[0] != '/' && s[0] != '~')
-    {
+  if (style.getValue(rname, s)) {
+    if (s[0] != '/' && s[0] != '~') {
       std::string xbmFile = std::string("~/.openbox/buttons/") + s;
       ret = XReadBitmapFile(OBDisplay::display, root_window,
                             expandTilde(xbmFile).c_str(), &pixmapMask.w,
                             &pixmapMask.h, &pixmapMask.mask, &hx, &hy);
+      if (ret != BitmapSuccess) {
+        xbmFile = std::string(BUTTONSDIR) + "/" + s;
+        ret = XReadBitmapFile(OBDisplay::display, root_window,
+                              xbmFile.c_str(), &pixmapMask.w,
+                              &pixmapMask.h, &pixmapMask.mask, &hx, &hy);
+      }
     } else
       ret = XReadBitmapFile(OBDisplay::display, root_window,
                             expandTilde(s).c_str(), &pixmapMask.w,
@@ -260,50 +245,29 @@ BColor Style::readDatabaseColor(const std::string &rname,
 
 
 BFont *Style::readDatabaseFont(const std::string &rbasename,
-                                    const Configuration &style) {
-  std::string fontname;
+                               const Configuration &style) {
+  std::string fontstring, s;
 
-  std::string s;
+  // XXX: load all this font stuff from the style...
 
-  int i;
-  if (style.getValue(rbasename + "xft.font", s) &&
-      style.getValue(rbasename + "xft.size", i)) {
-    std::string family = s;
-    bool bold = False;
-    bool italic = False;
-    bool dropShadow = False;
-
-    if (style.getValue(rbasename + "xft.flags", s)) {
-      if (s.find("bold") != std::string::npos)
-        bold = True;
-      if (s.find("italic") != std::string::npos)
-        italic = True;
-      if (s.find("shadow") != std::string::npos)
-        dropShadow = True;
-    }
+  bool dropShadow = True;
     
-    unsigned char offset = 1;
-    if (style.getValue(rbasename + "xft.shadow.offset", s)) {
-      offset = atoi(s.c_str()); //doesn't detect errors
-      if (offset > CHAR_MAX)
-        offset = 1;
-    }
-
-    unsigned char tint = 0x40;
-    if (style.getValue(rbasename + "xft.shadow.tint", s)) {
-      tint = atoi(s.c_str());
-    }
+  unsigned char offset = 1;
+  if (style.getValue(rbasename + "xft.shadow.offset", s)) {
+    offset = atoi(s.c_str()); //doesn't detect errors
+    if (offset > CHAR_MAX)
+      offset = 1;
+  }
 
-    
-    BFont *b = new BFont(screen_number, family, i, bold, italic,
-                         dropShadow && shadow_fonts,
-                         offset, tint, aa_fonts);
-    if (b->valid())
-      return b;
-    delete b;
+  unsigned char tint = 0x40;
+  if (style.getValue(rbasename + "xft.shadow.tint", s)) {
+    tint = atoi(s.c_str());
   }
-    
-  exit(2);  // can't continue without a font
+
+  fontstring = "Arial,Sans-9:bold";
+
+  // if this fails, it ::exit()'s
+  return new BFont(screen_number, fontstring, dropShadow, offset, tint);
 }
 
 }
This page took 0.028009 seconds and 4 git commands to generate.