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