might not compile... ob uses its own widgets now, which subclass only the base otk...
[mikachu/openbox.git] / src / buttonwidget.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 "buttonwidget.hh"
8
9 namespace ob {
10
11 OBButtonWidget::OBButtonWidget(otk::OtkWidget *parent,
12                                OBWidget::WidgetType type)
13   : otk::OtkWidget(parent),
14     OBWidget(type),
15     _pressed(false),
16     _button(0)
17 {
18 }
19
20
21 OBButtonWidget::~OBButtonWidget()
22 {
23 }
24
25
26 void OBButtonWidget::setTextures()
27 {
28   switch (type()) {
29   case Type_LeftGrip:
30   case Type_RightGrip:
31     if (_focused)
32       setTexture(_style->getGripFocus());
33     else
34       setTexture(_style->getGripUnfocus());
35     break;
36   case Type_StickyButton:
37   case Type_CloseButton:
38   case Type_MaximizeButton:
39   case Type_IconifyButton:
40     if (_pressed) {
41       if (_focused)
42         setTexture(_style->getButtonPressedFocus());
43       else
44         setTexture(_style->getButtonPressedUnfocus());
45     } else {
46       if (_focused)
47         setTexture(_style->getButtonFocus());
48       else
49         setTexture(_style->getButtonUnfocus());
50     }
51     break;
52   default:
53     assert(false); // there's no other button widgets!
54   }
55 }
56
57
58 void OBButtonWidget::setStyle(otk::Style *style)
59 {
60   otk::OtkWidget::setStyle(style);
61   setTextures();
62
63   switch (type()) {
64   case Type_LeftGrip:
65   case Type_RightGrip:
66     setBorderColor(_style->getBorderColor());
67     break;
68   case Type_StickyButton:
69   case Type_CloseButton:
70   case Type_MaximizeButton:
71   case Type_IconifyButton:
72     break;
73   default:
74     assert(false); // there's no other button widgets!
75   }
76 }
77
78
79 void OBButtonWidget::focus()
80 {
81   otk::OtkWidget::focus();
82   setTextures();
83 }
84
85
86 void OBButtonWidget::unfocus()
87 {
88   otk::OtkWidget::unfocus();
89   setTextures();
90 }
91
92
93 void OBButtonWidget::adjust()
94 {
95   // XXX: adjust shit
96 }
97
98
99 void OBButtonWidget::buttonPressHandler(const XButtonEvent &e)
100 {
101   OtkWidget::buttonPressHandler(e);
102   if (_button) return;
103   _button = e.button;
104   _pressed = true;
105   setTextures();
106   update();
107 }
108
109
110 void OBButtonWidget::buttonReleaseHandler(const XButtonEvent &e)
111 {
112   OtkWidget::buttonPressHandler(e);
113   if (e.button != _button) return;
114   _button = 0;
115   _pressed = false;
116   setTextures();
117   update();
118 }
119
120 }