]> Dogcows Code - chaz/openbox/blob - otk/button.cc
fixed bugs, got otkapp to select on a fd, modded widget to make use of otkapp, press...
[chaz/openbox] / otk / button.cc
1 #include <iostream>
2 #include "button.hh"
3
4 namespace otk {
5
6 OtkButton::OtkButton(OtkWidget *parent)
7 : OtkFocusWidget(parent), _text(""), _pressed(false), _dirty(false),
8 _pressed_focus_tx(0), _pressed_unfocus_tx(0), _unpr_focus_tx(0),
9 _unpr_unfocus_tx(0)
10 {
11 setTexture(getStyle()->getButtonFocus());
12 setUnfocusTexture(getStyle()->getButtonUnfocus());
13 _pressed_focus_tx = getStyle()->getButtonPressedFocus();
14 _pressed_unfocus_tx = getStyle()->getButtonPressedUnfocus();
15 }
16
17 OtkButton::~OtkButton()
18 {
19 if (_pressed_focus_tx) delete _pressed_focus_tx;
20 if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
21 }
22
23 void OtkButton::press(void)
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 }
31
32 void OtkButton::release(void)
33 {
34 OtkFocusWidget::setTexture(_unpr_focus_tx);
35 OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
36 _pressed = false;
37 }
38
39 void OtkButton::setTexture(BTexture *texture)
40 {
41 OtkFocusWidget::setTexture(texture);
42 _unpr_focus_tx = texture;
43 }
44
45 void OtkButton::setUnfocusTexture(BTexture *texture)
46 {
47 OtkFocusWidget::setUnfocusTexture(texture);
48 _unpr_unfocus_tx = texture;
49 }
50
51 void OtkButton::update(void)
52 {
53 if (_dirty) {
54 const BFont ft = getStyle()->getFont();
55 BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
56 : getStyle()->getTextUnfocus());
57 unsigned int bevel = getStyle()->getBevelWidth();
58
59 OtkFocusWidget::resize(ft.measureString(_text) + bevel * 2,
60 ft.height() + bevel * 2);
61 OtkFocusWidget::update();
62
63 ft.drawString(getWindow(), bevel, bevel, *text_color, _text);
64 } else
65 OtkFocusWidget::update();
66
67 _dirty = false;
68 }
69
70 int OtkButton::buttonPressHandler(const XButtonEvent &e)
71 {
72 press();
73 _dirty = true;
74 update();
75 return OtkFocusWidget::buttonPressHandler(e);
76 }
77
78 int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
79 {
80 release();
81 _dirty = true;
82 update();
83 return OtkFocusWidget::buttonReleaseHandler(e);
84 }
85
86 int OtkButton::exposeHandler(const XExposeEvent &e)
87 {
88 _dirty = true;
89 return OtkFocusWidget::exposeHandler(e);
90 }
91
92 int OtkButton::configureHandler(const XConfigureEvent &e)
93 {
94 if (!(e.width == width() && e.height == height()))
95 _dirty = true;
96 return OtkFocusWidget::configureHandler(e);
97 }
98
99 }
This page took 0.036357 seconds and 4 git commands to generate.