new button that is a focuslabel
[mikachu/openbox.git] / otk / button.cc
1 #include "button.hh"
2
3 namespace otk {
4
5 OtkButton::OtkButton(OtkWidget *parent)
6   : OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
7     _pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
8 {
9   setTexture(getStyle()->getButtonFocus());
10   setUnfocusTexture(getStyle()->getButtonUnfocus());
11   _pressed_focus_tx = getStyle()->getButtonPressedFocus();
12   _pressed_unfocus_tx = getStyle()->getButtonPressedUnfocus();
13 }
14
15 OtkButton::~OtkButton()
16 {
17   if (_pressed_focus_tx) delete _pressed_focus_tx;
18   if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
19 }
20
21 void OtkButton::press(unsigned int mouse_button)
22 {
23   if (_pressed) return;
24
25   if (_pressed_focus_tx)
26     OtkFocusWidget::setTexture(_pressed_focus_tx);
27   if (_pressed_unfocus_tx)
28     OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
29   _pressed = true;
30   _mouse_button = mouse_button;
31 }
32
33 void OtkButton::release(unsigned int mouse_button)
34 {
35   if (_mouse_button != mouse_button) return; // wrong button
36
37   OtkFocusWidget::setTexture(_unpr_focus_tx);
38   OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
39   _pressed = false;
40 }
41
42 void OtkButton::setTexture(BTexture *texture)
43 {
44   OtkFocusWidget::setTexture(texture);
45   _unpr_focus_tx = texture;
46 }
47
48 void OtkButton::setUnfocusTexture(BTexture *texture)
49 {
50   OtkFocusWidget::setUnfocusTexture(texture);
51   _unpr_unfocus_tx = texture;
52 }
53
54 int OtkButton::buttonPressHandler(const XButtonEvent &e)
55 {
56   press(e.button);
57   update();
58   return OtkFocusWidget::buttonPressHandler(e);
59 }
60
61 int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
62 {
63   release(e.button);
64   update();
65   return OtkFocusWidget::buttonReleaseHandler(e);
66 }
67
68 }