]> Dogcows Code - chaz/openbox/blobdiff - otk/button.cc
add an OtkAppWidget which are "root windows", i.e. the managed child of root, to...
[chaz/openbox] / otk / button.cc
index 1e8a4f03277873de917c4ca51fa0713d412ea3eb..1b2ef7cec45efee10b191d5353a1f6da47ac45dc 100644 (file)
@@ -3,9 +3,8 @@
 namespace otk {
 
 OtkButton::OtkButton(OtkWidget *parent)
-  : OtkFocusWidget(parent), _text(""), _pressed(false), _dirty(false),
-    _pressed_focus_tx(0), _pressed_unfocus_tx(0), _unpr_focus_tx(0),
-    _unpr_unfocus_tx(0)
+  : OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
+    _pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
 {
   setTexture(getStyle()->getButtonFocus());
   setUnfocusTexture(getStyle()->getButtonUnfocus());
@@ -19,17 +18,22 @@ OtkButton::~OtkButton()
   if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
 }
 
-void OtkButton::press(void)
+void OtkButton::press(unsigned int mouse_button)
 {
+  if (_pressed) return;
+
   if (_pressed_focus_tx)
     OtkFocusWidget::setTexture(_pressed_focus_tx);
   if (_pressed_unfocus_tx)
     OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
   _pressed = true;
+  _mouse_button = mouse_button;
 }
 
-void OtkButton::release(void)
+void OtkButton::release(unsigned int mouse_button)
 {
+  if (_mouse_button != mouse_button) return; // wrong button
+
   OtkFocusWidget::setTexture(_unpr_focus_tx);
   OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
   _pressed = false;
@@ -47,30 +51,18 @@ void OtkButton::setUnfocusTexture(BTexture *texture)
   _unpr_unfocus_tx = texture;
 }
 
-void OtkButton::update(void)
+void OtkButton::buttonPressHandler(const XButtonEvent &e)
 {
-  if (_dirty) {
-    const BFont ft = getStyle()->getFont();
-    BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
-                          : getStyle()->getTextUnfocus());
-    unsigned int bevel = getStyle()->getBevelWidth();
-
-    OtkFocusWidget::resize(ft.measureString(_text) + bevel * 2,
-                           ft.height() + bevel * 2);
-
-    OtkFocusWidget::update();
-
-    ft.drawString(getWindow(), bevel, bevel, *text_color, _text);
-  } else
-    OtkFocusWidget::update();
-
-  _dirty = false;
+  press(e.button);
+  update();
+  OtkFocusWidget::buttonPressHandler(e);
 }
 
-bool OtkButton::expose(const XExposeEvent &e)
+void OtkButton::buttonReleaseHandler(const XButtonEvent &e)
 {
-  _dirty = true;
-  return OtkFocusWidget::expose(e);
+  release(e.button);
+  update();
+  OtkFocusWidget::buttonReleaseHandler(e);
 }
 
 }
This page took 0.027326 seconds and 4 git commands to generate.