]> Dogcows Code - chaz/openbox/blob - otk/button.cc
make shape work with the titlebar and handle
[chaz/openbox] / 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 setStyle(getStyle());
16 }
17
18 OtkButton::~OtkButton()
19 {
20 }
21
22
23 void OtkButton::setStyle(Style *style)
24 {
25 OtkFocusLabel::setStyle(style);
26
27 setTexture(getStyle()->getButtonFocus());
28 setUnfocusTexture(getStyle()->getButtonUnfocus());
29 _pressed_focus_tx = getStyle()->getButtonPressedFocus();
30 _pressed_unfocus_tx = getStyle()->getButtonPressedUnfocus();
31 }
32
33
34 void OtkButton::press(unsigned int mouse_button)
35 {
36 if (_pressed) return;
37
38 if (_pressed_focus_tx)
39 OtkFocusWidget::setTexture(_pressed_focus_tx);
40 if (_pressed_unfocus_tx)
41 OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
42 _pressed = true;
43 _mouse_button = mouse_button;
44 }
45
46 void OtkButton::release(unsigned int mouse_button)
47 {
48 if (_mouse_button != mouse_button) return; // wrong button
49
50 OtkFocusWidget::setTexture(_unpr_focus_tx);
51 OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
52 _pressed = false;
53 }
54
55 void OtkButton::setTexture(BTexture *texture)
56 {
57 OtkFocusWidget::setTexture(texture);
58 _unpr_focus_tx = texture;
59 }
60
61 void OtkButton::setUnfocusTexture(BTexture *texture)
62 {
63 OtkFocusWidget::setUnfocusTexture(texture);
64 _unpr_unfocus_tx = texture;
65 }
66
67 void OtkButton::buttonPressHandler(const XButtonEvent &e)
68 {
69 press(e.button);
70 update();
71 OtkFocusWidget::buttonPressHandler(e);
72 }
73
74 void OtkButton::buttonReleaseHandler(const XButtonEvent &e)
75 {
76 release(e.button);
77 update();
78 OtkFocusWidget::buttonReleaseHandler(e);
79 }
80
81 }
This page took 0.038428 seconds and 4 git commands to generate.