]> Dogcows Code - chaz/openbox/blob - otk/button.cc
change the default titlebar layout
[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
43 void Button::buttonPressHandler(const XButtonEvent &e)
44 {
45 Widget::buttonPressHandler(e);
46 press(e.button);
47 }
48
49 void Button::buttonReleaseHandler(const XButtonEvent &e)
50 {
51 Widget::buttonReleaseHandler(e);
52 bool p = _pressed;
53 release(e.button);
54 if (p && !_pressed && e.x > 0 && e.y > 0 &&
55 e.x < area().width() && e.y < area().height())
56 clickHandler(_mouse_button);
57 }
58
59 void Button::styleChanged(const RenderStyle &style)
60 {
61 if (isHighlighted()) {
62 if (_pressed)
63 _texture = style.buttonPressFocusBackground();
64 else
65 _texture = style.buttonUnpressFocusBackground();
66 _forecolor = style.buttonFocusColor();
67 } else {
68 if (_pressed)
69 _texture = style.buttonPressUnfocusBackground();
70 else
71 _texture = style.buttonUnpressUnfocusBackground();
72 _forecolor = style.buttonUnfocusColor();
73 }
74 refresh();
75 }
76
77 }
This page took 0.040553 seconds and 4 git commands to generate.