add the config header and emacs comment to all the .cc's
[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   if (_pressed_focus_tx) delete _pressed_focus_tx;
24   if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
25 }
26
27 void OtkButton::press(unsigned int mouse_button)
28 {
29   if (_pressed) return;
30
31   if (_pressed_focus_tx)
32     OtkFocusWidget::setTexture(_pressed_focus_tx);
33   if (_pressed_unfocus_tx)
34     OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
35   _pressed = true;
36   _mouse_button = mouse_button;
37 }
38
39 void OtkButton::release(unsigned int mouse_button)
40 {
41   if (_mouse_button != mouse_button) return; // wrong button
42
43   OtkFocusWidget::setTexture(_unpr_focus_tx);
44   OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
45   _pressed = false;
46 }
47
48 void OtkButton::setTexture(BTexture *texture)
49 {
50   OtkFocusWidget::setTexture(texture);
51   _unpr_focus_tx = texture;
52 }
53
54 void OtkButton::setUnfocusTexture(BTexture *texture)
55 {
56   OtkFocusWidget::setUnfocusTexture(texture);
57   _unpr_unfocus_tx = texture;
58 }
59
60 void OtkButton::buttonPressHandler(const XButtonEvent &e)
61 {
62   press(e.button);
63   update();
64   OtkFocusWidget::buttonPressHandler(e);
65 }
66
67 void OtkButton::buttonReleaseHandler(const XButtonEvent &e)
68 {
69   release(e.button);
70   update();
71   OtkFocusWidget::buttonReleaseHandler(e);
72 }
73
74 }