]> Dogcows Code - chaz/openbox/commitdiff
add an OBBackgroundWidget and use it for setting colors so far.
authorDana Jansens <danakj@orodu.net>
Wed, 18 Dec 2002 02:28:44 +0000 (02:28 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 18 Dec 2002 02:28:44 +0000 (02:28 +0000)
14 files changed:
otk/button.cc
otk/focuslabel.cc
otk/focuswidget.cc
otk/focuswidget.hh
otk/label.cc
otk/label.hh
otk/widget.cc
otk/widget.hh
src/Makefile.am
src/backgroundwidget.cc [new file with mode: 0644]
src/backgroundwidget.hh [new file with mode: 0644]
src/frame.cc
src/frame.hh
src/widget.hh [new file with mode: 0644]

index fd23a5698d74d54ff15851df3c25255834459025..2b17458206432bad0e1d4714c5c939fb40f61395 100644 (file)
@@ -12,7 +12,6 @@ OtkButton::OtkButton(OtkWidget *parent)
   : OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
     _pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
 {
-  setStyle(getStyle());
 }
 
 OtkButton::~OtkButton()
index 007c795733c00186a57d9011530b7131bbc21446..c4f124e682d1d989fd459f17ac592e9907a6675c 100644 (file)
@@ -16,7 +16,6 @@ OtkFocusLabel::OtkFocusLabel(OtkWidget *parent)
   const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
   _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
                            info->getColormap());
-  setStyle(getStyle());
 }
 
 OtkFocusLabel::~OtkFocusLabel()
index 22a6100ba4d4db3d4717841bbcff72e9586e358d..f5b176bfc4bc1bd90dde1dc3fbbce33a9248e3b8 100644 (file)
@@ -9,44 +9,44 @@
 namespace otk {
 
 OtkFocusWidget::OtkFocusWidget(OtkWidget *parent, Direction direction)
-  : OtkWidget(parent, direction), _unfocus_texture(0), _focused(true)
+  : OtkWidget(parent, direction), _unfocus_texture(0), _unfocus_bcolor(0)
 {
+  _focused = true;
   _focus_texture = parent->getTexture();
+  _focus_bcolor = parent->getBorderColor();
 }
 
 OtkFocusWidget::~OtkFocusWidget()
 {
 }
 
+#include <stdio.h>
 void OtkFocusWidget::focus(void)
 {
-  if (_focused)
+  if (!isVisible() || _focused)
     return;
 
-  // XXX: what about OtkWidget::focus()
+  printf("FOCUS\n");
+  OtkWidget::focus();
+
+  if (_focus_bcolor)
+    OtkWidget::setBorderColor(_focus_bcolor);
 
-  assert(_focus_texture);
   OtkWidget::setTexture(_focus_texture);
   OtkWidget::update();
-
-  OtkWidget::OtkWidgetList children = OtkWidget::getChildren();
-
-  OtkWidget::OtkWidgetList::iterator it = children.begin(),
-    end = children.end();
-
-  OtkFocusWidget *tmp = 0;
-  for (; it != end; ++it) {
-    tmp = dynamic_cast<OtkFocusWidget*>(*it);
-    if (tmp) tmp->focus();
-  }
 }
 
 void OtkFocusWidget::unfocus(void)
 {
-  if (! _focused)
+  if (!isVisible() || !_focused)
     return;
 
-  assert(_unfocus_texture);
+  printf("UNFOCUS\n");
+  OtkWidget::unfocus();
+
+  if (_unfocus_bcolor)
+    OtkWidget::setBorderColor(_unfocus_bcolor);
+
   OtkWidget::setTexture(_unfocus_texture);
   OtkWidget::update();
 
@@ -68,4 +68,10 @@ void OtkFocusWidget::setTexture(BTexture *texture)
   _focus_texture = texture;
 }
 
+void OtkFocusWidget::setBorderColor(const BColor *color)
+{
+  OtkWidget::setBorderColor(color);
+  _focus_bcolor = color;
+}
+
 }
index d33d2abfd1624a98bfc6232dcf401188b1c39c14..2a97c6aa5991abaf304af7dd466bd47049fb4e49 100644 (file)
@@ -16,13 +16,19 @@ public:
   virtual void focus(void);
   virtual void unfocus(void);
 
-  void setTexture(BTexture *texture);
+  virtual void setTexture(BTexture *texture);
+  virtual void setBorderColor(const BColor *color);
 
   inline void setUnfocusTexture(BTexture *texture)
   { _unfocus_texture = texture; }
   inline BTexture *getUnfocusTexture(void) const
   { return _unfocus_texture; }
 
+  inline void setUnfocusBorderColor(const BColor *color)
+  { _unfocus_bcolor = color; }
+  inline const BColor *getUnfocusBorderColor(void) const
+  { return _unfocus_bcolor; }
+
   inline bool isFocused(void) const { return _focused; }
   inline bool isUnfocused(void) const { return !_focused; }
 
@@ -31,7 +37,8 @@ private:
   BTexture *_unfocus_texture;
   BTexture *_focus_texture;
 
-  bool _focused;
+  const BColor *_unfocus_bcolor;
+  const BColor *_focus_bcolor;
 };
 
 }
index fa12a0fa2f2fdb8226161f2bb0fb12ba9503041f..ceb6a49cc2a9cf7c082f585741f7d8b34d73deb8 100644 (file)
@@ -14,8 +14,6 @@ OtkLabel::OtkLabel(OtkWidget *parent)
   const ScreenInfo *info = OBDisplay::screenInfo(getScreen());
   _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(),
                            info->getColormap());
-  
-  setStyle(getStyle());
 }
 
 OtkLabel::~OtkLabel()
index 0dd81442582cfb13d01b970356d97be666de2d71..f80f76c78ac9b54e2281ac3371e260434a82fd4d 100644 (file)
@@ -19,7 +19,7 @@ public:
   void update(void);
 
   virtual void setStyle(Style *style);
-  
+
 private:
   //! Object used by Xft to render to the drawable
   XftDraw *_xftdraw;
index 6423a7af1197afa961b1ad05fb5a47beb84cd9f9..2c3c6058f274627c527d103c44a37aaf48828ffb 100644 (file)
@@ -16,38 +16,40 @@ namespace otk {
 
 OtkWidget::OtkWidget(OtkWidget *parent, Direction direction)
   : OtkEventHandler(),
-    _dirty(false),
+    _dirty(false), _focused(false),
     _parent(parent), _style(parent->getStyle()), _direction(direction),
     _cursor(parent->getCursor()), _bevel_width(parent->getBevelWidth()),
     _ignore_config(0),
-    _visible(false), _focused(false), _grabbed_mouse(false),
+    _visible(false), _grabbed_mouse(false),
     _grabbed_keyboard(false), _stretchable_vert(false),
     _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
-    _screen(parent->getScreen()), _fixed_width(false), _fixed_height(false),
-    _event_dispatcher(parent->getEventDispatcher()), _application(0)
+    _bcolor(0), _bwidth(0), _screen(parent->getScreen()), _fixed_width(false),
+    _fixed_height(false), _event_dispatcher(parent->getEventDispatcher())
 {
   assert(parent);
   parent->addChild(this);
   create();
   _event_dispatcher->registerHandler(_window, this);
+  setStyle(_style); // let the widget initialize stuff
 }
 
 OtkWidget::OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style,
                      Direction direction, Cursor cursor, int bevel_width)
   : OtkEventHandler(),
-    _dirty(false),
+    _dirty(false),_focused(false),
     _parent(0), _style(style), _direction(direction), _cursor(cursor),
     _bevel_width(bevel_width), _ignore_config(0), _visible(false),
-    _focused(false), _grabbed_mouse(false), _grabbed_keyboard(false),
+    _grabbed_mouse(false), _grabbed_keyboard(false),
     _stretchable_vert(false), _stretchable_horz(false), _texture(0),
-    _bg_pixmap(0), _bg_pixel(0), _screen(style->getScreen()),
-    _fixed_width(false), _fixed_height(false),
-    _event_dispatcher(event_dispatcher), _application(0)
+    _bg_pixmap(0), _bg_pixel(0), _bcolor(0), _bwidth(0),
+    _screen(style->getScreen()), _fixed_width(false), _fixed_height(false),
+    _event_dispatcher(event_dispatcher)
 {
   assert(event_dispatcher);
   assert(style);
   create();
   _event_dispatcher->registerHandler(_window, this);
+  setStyle(_style); // let the widget initialize stuff
 }
 
 OtkWidget::~OtkWidget()
@@ -185,11 +187,28 @@ void OtkWidget::hide(bool recursive)
 
 void OtkWidget::focus(void)
 {
-  if (! _visible)
+/*  if (! _visible)
     return;
 
   XSetInputFocus(otk::OBDisplay::display, _window, RevertToPointerRoot,
-                 CurrentTime);
+  CurrentTime);*/
+
+  _focused = true;
+  
+  OtkWidget::OtkWidgetList::iterator it = _children.begin(),
+    end = _children.end();
+  for (; it != end; ++it)
+    (*it)->focus();
+}
+
+void OtkWidget::unfocus(void)
+{
+  _focused = false;
+  
+  OtkWidget::OtkWidgetList::iterator it = _children.begin(),
+    end = _children.end();
+  for (; it != end; ++it)
+    (*it)->unfocus();
 }
 
 bool OtkWidget::grabMouse(void)
@@ -419,12 +438,22 @@ void OtkWidget::removeChild(OtkWidget *child)
   if (it != _children.end())
     _children.erase(it);
 }
-
+#include <stdio.h>
 void OtkWidget::setStyle(Style *style)
 {
   assert(style);
   _style = style;
   _dirty = true;
+
+  // reset textures/colors
+  if (_focused) {
+    unfocus();
+    focus();
+  } else {
+    focus();
+    unfocus();
+  }
+
   OtkWidgetList::iterator it, end = _children.end();
   for (it = _children.begin(); it != end; ++it)
     (*it)->setStyle(style);
index 249a4e281262d1c7c0b56038436e4f8447807509..5f1553c3502d3f37499dbf440313c5f108af6766 100644 (file)
@@ -65,6 +65,7 @@ public:
 
   inline bool isFocused(void) const { return _focused; };
   virtual void focus(void);
+  virtual void unfocus(void);
 
   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
   bool grabMouse(void);
@@ -76,7 +77,19 @@ public:
 
   inline BTexture *getTexture(void) const { return _texture; }
   virtual void setTexture(BTexture *texture)
-  { _texture = texture; _dirty = true; }
+    { _texture = texture; _dirty = true; }
+
+  inline const BColor *getBorderColor(void) const { return _bcolor; }
+  virtual void setBorderColor(const BColor *color) {
+    assert(color); _bcolor = color;
+    XSetWindowBorder(OBDisplay::display, _window, color->pixel());
+  }
+
+  inline int getBorderWidth(void) const { return _bwidth; }
+  void setBorderWidth(int width) {
+    _bwidth = width;
+    XSetWindowBorderWidth(OBDisplay::display, _window, width);
+  }
 
   virtual void addChild(OtkWidget *child, bool front = false);
   virtual void removeChild(OtkWidget *child);
@@ -112,11 +125,13 @@ public:
 protected:
   
   bool _dirty;
+  bool _focused;
+
+  virtual void adjust(void);
 
 private:
 
   void create(void);
-  void adjust(void);
   void adjustHorz(void);
   void adjustVert(void);
   void internalResize(int width, int height);
@@ -134,7 +149,6 @@ private:
   int _ignore_config;
 
   bool _visible;
-  bool _focused;
 
   bool _grabbed_mouse;
   bool _grabbed_keyboard;
@@ -146,6 +160,9 @@ private:
   Pixmap _bg_pixmap;
   unsigned int _bg_pixel;
 
+  const BColor *_bcolor;
+  unsigned int _bwidth;
+
   Rect _rect;
   unsigned int _screen;
 
@@ -155,7 +172,6 @@ private:
   bool _unmanaged;
 
   OtkEventDispatcher *_event_dispatcher;
-  OtkApplication *_application;
 };
 
 }
index bc83bb6fb80fd743dd8b9e70c7000bcac67c6276..319a9fdefae8f49c19b3e17c2fd84dacddb8cb4f 100644 (file)
@@ -16,7 +16,7 @@ bin_PROGRAMS= openbox3
 openbox3_LDADD=../otk/libotk.a @LIBINTL@
 
 openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \
-                  main.cc rootwindow.cc
+                  main.cc rootwindow.cc backgroundwidget.cc
 
 MAINTAINERCLEANFILES= Makefile.in
 
diff --git a/src/backgroundwidget.cc b/src/backgroundwidget.cc
new file mode 100644 (file)
index 0000000..7d715f5
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+#ifdef HAVE_CONFIG_H
+# include "../config.h"
+#endif
+
+#include "backgroundwidget.hh"
+
+namespace ob {
+
+OBBackgroundWidget::OBBackgroundWidget(otk::OtkWidget *parent,
+                                       OBWidget::WidgetType type)
+  : otk::OtkFocusWidget(parent),
+    OBWidget(type)
+{
+}
+
+
+OBBackgroundWidget::~OBBackgroundWidget()
+{
+}
+
+
+void OBBackgroundWidget::setStyle(otk::Style *style)
+{
+  switch (type()) {
+  case Type_Titlebar:
+    setTexture(style->getTitleFocus());
+    setUnfocusTexture(style->getTitleUnfocus());
+    setBorderColor(style->getBorderColor());
+    break;
+  case Type_Handle:
+    setTexture(style->getHandleFocus());
+    setUnfocusTexture(style->getHandleUnfocus());
+    setBorderColor(style->getBorderColor());
+    break;
+  case Type_Plate:
+    setBorderColor(&style->getFrameFocus()->color());
+    setUnfocusBorderColor(&style->getFrameUnfocus()->color());
+    break;
+  default:
+    assert(false); // there's no other background widgets!
+  }
+
+  otk::OtkFocusWidget::setStyle(style);
+}
+
+
+void OBBackgroundWidget::adjust()
+{
+  otk::OtkFocusWidget::adjust();
+
+  // XXX: adjust shit
+}
+
+
+}
diff --git a/src/backgroundwidget.hh b/src/backgroundwidget.hh
new file mode 100644 (file)
index 0000000..0cbfb3f
--- /dev/null
@@ -0,0 +1,25 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+#ifndef   __obbackgroundwidget_hh
+#define   __obbackgroundwidget_hh
+
+#include "otk/focuswidget.hh"
+#include "widget.hh"
+
+namespace ob {
+
+class OBBackgroundWidget : public otk::OtkFocusWidget, public OBWidget
+{
+private:
+  
+public:
+  OBBackgroundWidget(otk::OtkWidget *parent, OBWidget::WidgetType type);
+  virtual ~OBBackgroundWidget();
+
+  virtual void setStyle(otk::Style *style);
+
+  virtual void adjust();
+};
+
+}
+
+#endif // __obbackgroundwidget_hh
index 15404f93d68d66b4beb505504ab34e9be4e97063..fc85d6d15e20c19529b8504952c62ec09b171f78 100644 (file)
@@ -25,14 +25,14 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
   : otk::OtkWidget(Openbox::instance, style),
     _client(client),
     _screen(otk::OBDisplay::screenInfo(client->screen())),
-    _plate(this),
-    _titlebar(this),
+    _plate(this, OBWidget::Type_Plate),
+    _titlebar(this, OBWidget::Type_Titlebar),
     _button_close(&_titlebar),
     _button_iconify(&_titlebar),
     _button_max(&_titlebar),
     _button_stick(&_titlebar),
     _label(&_titlebar),
-    _handle(this),
+    _handle(this, OBWidget::Type_Handle),
     _grip_left(&_handle),
     _grip_right(&_handle),
     _decorations(client->decorations())
@@ -57,8 +57,6 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
   _grip_left.setCursor(Openbox::instance->cursors().ll_angle);
   _grip_right.setCursor(Openbox::instance->cursors().lr_angle);
   
-  _plate.show();
-
   _button_close.setText("X");
   _button_iconify.setText("I");
   _button_max.setText("M");
@@ -68,6 +66,10 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style)
   _style = 0;
   setStyle(style);
 
+  //XXX: uncomment me unfocus(); // stuff starts out focused in otk
+  
+  _plate.show(); // the other stuff is shown based on decor settings
+  
   grabClient();
 }
 
@@ -93,11 +95,6 @@ void OBFrame::setStyle(otk::Style *style)
   _grip_right.setPressedFocusTexture(style->getGripFocus());
   _grip_right.setPressedUnfocusTexture(style->getGripUnfocus());
 
-  _titlebar.setTexture(style->getTitleFocus());
-  _titlebar.setUnfocusTexture(style->getTitleUnfocus());
-  _handle.setTexture(style->getHandleFocus());
-  _handle.setUnfocusTexture(style->getHandleUnfocus());
-  
   // if a style was previously set, then 'replace' is true, cause we're
   // replacing a style
   bool replace = (_style);
@@ -109,20 +106,13 @@ void OBFrame::setStyle(otk::Style *style)
   _style = style;
 
   // XXX: change when focus changes!
-  XSetWindowBorder(otk::OBDisplay::display, _plate.getWindow(),
-                   _style->getFrameFocus()->color().pixel());
-
   XSetWindowBorder(otk::OBDisplay::display, getWindow(),
                    _style->getBorderColor()->pixel());
-  XSetWindowBorder(otk::OBDisplay::display, _titlebar.getWindow(),
-                   _style->getBorderColor()->pixel());
   XSetWindowBorder(otk::OBDisplay::display, _grip_left.getWindow(),
                    _style->getBorderColor()->pixel());
   XSetWindowBorder(otk::OBDisplay::display, _grip_right.getWindow(),
                    _style->getBorderColor()->pixel());
-  XSetWindowBorder(otk::OBDisplay::display, _handle.getWindow(),
-                   _style->getBorderColor()->pixel());
-  
+
   // if !replace, then adjust() will get called after the client is grabbed!
   if (replace) {
     // size/position everything
@@ -151,17 +141,14 @@ void OBFrame::adjustSize()
     cbwidth;
   width = _client->area().width() + cbwidth * 2;
 
-  XSetWindowBorderWidth(otk::OBDisplay::display, _plate.getWindow(), cbwidth);
-
-  XSetWindowBorderWidth(otk::OBDisplay::display, getWindow(), bwidth);
-  XSetWindowBorderWidth(otk::OBDisplay::display, _titlebar.getWindow(),
-                        bwidth);
-  XSetWindowBorderWidth(otk::OBDisplay::display, _grip_left.getWindow(),
-                        bwidth);
-  XSetWindowBorderWidth(otk::OBDisplay::display, _grip_right.getWindow(),
-                        bwidth);
-  XSetWindowBorderWidth(otk::OBDisplay::display, _handle.getWindow(), bwidth);
+  _plate.setBorderWidth(cbwidth);
 
+  setBorderWidth(bwidth);
+  _titlebar.setBorderWidth(bwidth);
+  _grip_left.setBorderWidth(bwidth);
+  _grip_right.setBorderWidth(bwidth);
+  _handle.setBorderWidth(bwidth);
+  
   if (_decorations & OBClient::Decor_Titlebar) {
     // set the titlebar size
     _titlebar.setGeometry(-bwidth,
index 7248c71fdb268831c99da864f3f30cf569c2d014..450c86702638fa26ea94ed74a0f3d9984e525811 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 }
 
 #include "client.hh"
+#include "backgroundwidget.hh"
 #include "otk/strut.hh"
 #include "otk/rect.hh"
 #include "otk/screeninfo.hh"
@@ -49,14 +50,14 @@ private:
   otk::Strut _innersize;
 
   // decoration windows
-  otk::OtkFocusWidget _plate;   // sits entirely under the client window
-  otk::OtkFocusWidget _titlebar;
+  OBBackgroundWidget  _plate;   // sits entirely under the client window
+  OBBackgroundWidget  _titlebar;
   otk::OtkButton      _button_close;
   otk::OtkButton      _button_iconify;
   otk::OtkButton      _button_max;
   otk::OtkButton      _button_stick;
   otk::OtkFocusLabel  _label;
-  otk::OtkFocusWidget _handle;
+  OBBackgroundWidget  _handle;
   otk::OtkButton      _grip_left;
   otk::OtkButton      _grip_right;
 
diff --git a/src/widget.hh b/src/widget.hh
new file mode 100644 (file)
index 0000000..c82c286
--- /dev/null
@@ -0,0 +1,26 @@
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+#ifndef   __obwidget_hh
+#define   __obwidget_hh
+
+namespace ob {
+
+class OBWidget {
+public:
+  enum WidgetType {
+    Type_Titlebar,
+    Type_Handle,
+    Type_Plate
+  };
+
+private:
+  WidgetType _type;
+
+public:
+  OBWidget(WidgetType type) : _type(type) {}
+  
+  inline WidgetType type() const { return _type; }
+};
+
+}
+
+#endif // __obwidget_hh
This page took 0.039288 seconds and 4 git commands to generate.