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