]> Dogcows Code - chaz/openbox/blob - otk/button.cc
add otk::MessageDialog
[chaz/openbox] / otk / button.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 #include "button.hh"
6
7 namespace otk {
8
9 Button::Button(Widget *parent)
10 : Label(parent),
11 _pressed(false)
12 {
13 setHorizontalJustify(RenderStyle::CenterJustify);
14 setVerticalJustify(RenderStyle::CenterJustify);
15 styleChanged(*RenderStyle::style(screen()));
16 }
17
18 Button::~Button()
19 {
20 }
21
22 void Button::press(unsigned int mouse_button)
23 {
24 if (_pressed) return;
25
26 _pressed = true;
27 _mouse_button = mouse_button;
28
29 styleChanged(*RenderStyle::style(screen()));
30 refresh();
31 }
32
33 void Button::release(unsigned int mouse_button)
34 {
35 if (!_pressed || _mouse_button != mouse_button) return; // wrong button
36
37 _pressed = false;
38
39 styleChanged(*RenderStyle::style(screen()));
40 refresh();
41
42 clickHandler(_mouse_button);
43 }
44
45 void Button::buttonPressHandler(const XButtonEvent &e)
46 {
47 Widget::buttonPressHandler(e);
48 press(e.button);
49 }
50
51 void Button::buttonReleaseHandler(const XButtonEvent &e)
52 {
53 Widget::buttonReleaseHandler(e);
54 release(e.button);
55 }
56
57 void Button::styleChanged(const RenderStyle &style)
58 {
59 if (isHighlighted()) {
60 if (_pressed)
61 _texture = style.buttonPressFocusBackground();
62 else
63 _texture = style.buttonUnpressFocusBackground();
64 _forecolor = style.buttonFocusColor();
65 } else {
66 if (_pressed)
67 _texture = style.buttonPressUnfocusBackground();
68 else
69 _texture = style.buttonUnpressUnfocusBackground();
70 _forecolor = style.buttonUnfocusColor();
71 }
72 refresh();
73 }
74
75 }
This page took 0.03634 seconds and 4 git commands to generate.