]> Dogcows Code - chaz/openbox/blob - otk/button.cc
stacked cycling menu works now. add a highlighted flag to otk widgets
[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 Button::Button(Widget *parent)
12 : Label(parent),
13 _pressed(false)
14 {
15 setHighlighted(false);
16 setHorizontalJustify(RenderStyle::CenterJustify);
17 setVerticalJustify(RenderStyle::CenterJustify);
18 styleChanged(*RenderStyle::style(screen()));
19 }
20
21 Button::~Button()
22 {
23 }
24
25 void Button::press(unsigned int mouse_button)
26 {
27 if (_pressed) return;
28
29 _pressed = true;
30 _mouse_button = mouse_button;
31
32 styleChanged(*RenderStyle::style(screen()));
33 refresh();
34 }
35
36 void Button::release(unsigned int mouse_button)
37 {
38 if (!_pressed || _mouse_button != mouse_button) return; // wrong button
39
40 _pressed = false;
41
42 styleChanged(*RenderStyle::style(screen()));
43 refresh();
44 }
45
46 void Button::buttonPressHandler(const XButtonEvent &e)
47 {
48 Widget::buttonPressHandler(e);
49 press(e.button);
50 }
51
52 void Button::buttonReleaseHandler(const XButtonEvent &e)
53 {
54 Widget::buttonReleaseHandler(e);
55 release(e.button);
56 }
57
58 void Button::styleChanged(const RenderStyle &style)
59 {
60 if (isHighlighted()) {
61 if (_pressed)
62 _texture = style.buttonPressFocusBackground();
63 else
64 _texture = style.buttonUnpressFocusBackground();
65 _forecolor = style.buttonFocusColor();
66 } else {
67 if (_pressed)
68 _texture = style.buttonPressUnfocusBackground();
69 else
70 _texture = style.buttonUnpressUnfocusBackground();
71 _forecolor = style.buttonUnfocusColor();
72 }
73 Widget::styleChanged(style);
74 }
75
76 }
This page took 0.037102 seconds and 5 git commands to generate.