]> Dogcows Code - chaz/openbox/blobdiff - src/buttonwidget.cc
code style fix
[chaz/openbox] / src / buttonwidget.cc
index 867cc5be1c797d9fc2b8780c88f1ce415d224eff..853b0339f448793948e60e93bb3ff7b9e6db6cbc 100644 (file)
@@ -10,8 +10,10 @@ namespace ob {
 
 OBButtonWidget::OBButtonWidget(otk::OtkWidget *parent,
                                OBWidget::WidgetType type)
-  : otk::OtkButton(parent),
-    OBWidget(type)
+  : otk::OtkWidget(parent),
+    OBWidget(type),
+    _pressed(false),
+    _button(0)
 {
 }
 
@@ -21,36 +23,98 @@ OBButtonWidget::~OBButtonWidget()
 }
 
 
+void OBButtonWidget::setTextures()
+{
+  switch (type()) {
+  case Type_LeftGrip:
+  case Type_RightGrip:
+    if (_focused)
+      setTexture(_style->getGripFocus());
+    else
+      setTexture(_style->getGripUnfocus());
+    break;
+  case Type_StickyButton:
+  case Type_CloseButton:
+  case Type_MaximizeButton:
+  case Type_IconifyButton:
+    if (_pressed) {
+      if (_focused)
+        setTexture(_style->getButtonPressedFocus());
+      else
+        setTexture(_style->getButtonPressedUnfocus());
+    } else {
+      if (_focused)
+        setTexture(_style->getButtonFocus());
+      else
+        setTexture(_style->getButtonUnfocus());
+    }
+    break;
+  default:
+    assert(false); // there's no other button widgets!
+  }
+}
+
+
 void OBButtonWidget::setStyle(otk::Style *style)
 {
-  otk::OtkButton::setStyle(style);
+  otk::OtkWidget::setStyle(style);
+  setTextures();
 
   switch (type()) {
   case Type_LeftGrip:
   case Type_RightGrip:
-    setTexture(style->getGripFocus());
-    setUnfocusTexture(style->getGripUnfocus());
-    setPressedFocusTexture(style->getGripFocus());
-    setPressedUnfocusTexture(style->getGripUnfocus());
-    setTexture(style->getGripFocus());
-    setUnfocusTexture(style->getGripUnfocus());
-    setPressedFocusTexture(style->getGripFocus());
-    setPressedUnfocusTexture(style->getGripUnfocus());
     setBorderColor(_style->getBorderColor());
-    setUnfocusBorderColor(style->getBorderColor());
     break;
-  default:
+  case Type_StickyButton:
+  case Type_CloseButton:
+  case Type_MaximizeButton:
+  case Type_IconifyButton:
     break;
+  default:
+    assert(false); // there's no other button widgets!
   }
 }
 
 
-void OBButtonWidget::adjust()
+void OBButtonWidget::focus()
 {
-  otk::OtkButton::adjust();
+  otk::OtkWidget::focus();
+  setTextures();
+}
 
+
+void OBButtonWidget::unfocus()
+{
+  otk::OtkWidget::unfocus();
+  setTextures();
+}
+
+
+void OBButtonWidget::adjust()
+{
   // XXX: adjust shit
 }
 
 
+void OBButtonWidget::buttonPressHandler(const XButtonEvent &e)
+{
+  OtkWidget::buttonPressHandler(e);
+  if (_button) return;
+  _button = e.button;
+  _pressed = true;
+  setTextures();
+  update();
+}
+
+
+void OBButtonWidget::buttonReleaseHandler(const XButtonEvent &e)
+{
+  OtkWidget::buttonPressHandler(e);
+  if (e.button != _button) return;
+  _button = 0;
+  _pressed = false;
+  setTextures();
+  update();
+}
+
 }
This page took 0.025543 seconds and 4 git commands to generate.