1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "buttonwidget.hh"
12 ButtonWidget::ButtonWidget(otk::Widget *parent,
13 WidgetBase::WidgetType type,
15 : otk::Widget(parent),
25 ButtonWidget::~ButtonWidget()
30 void ButtonWidget::setTextures()
35 case Type_AllDesktopsButton:
36 if (_client->desktop() == (signed)0xffffffff)
39 case Type_MaximizeButton:
40 if (_client->maxHorz() || _client->maxVert())
51 setTexture(_style->gripFocusBackground());
53 setTexture(_style->gripUnfocusBackground());
55 case Type_AllDesktopsButton:
56 case Type_MaximizeButton:
57 case Type_CloseButton:
58 case Type_IconifyButton:
61 setTexture(_style->buttonPressFocusBackground());
63 setTexture(_style->buttonPressUnfocusBackground());
66 setTexture(_style->buttonUnpressFocusBackground());
68 setTexture(_style->buttonUnpressUnfocusBackground());
72 assert(false); // there's no other button widgets!
77 void ButtonWidget::setStyle(otk::RenderStyle *style)
79 otk::Widget::setStyle(style);
85 setBorderColor(_style->frameBorderColor());
87 case Type_AllDesktopsButton:
88 case Type_CloseButton:
89 case Type_MaximizeButton:
90 case Type_IconifyButton:
93 assert(false); // there's no other button widgets!
98 void ButtonWidget::update()
101 case Type_AllDesktopsButton:
102 if ((_client->desktop() == (signed)0xffffffff) != _state) {
107 case Type_MaximizeButton:
108 if ((_client->maxHorz() || _client->maxVert()) != _state) {
117 otk::Widget::update();
121 void ButtonWidget::renderForeground()
127 otk::Widget::renderForeground();
131 case Type_AllDesktopsButton:
132 pm = _style->alldesktopsMask();
134 case Type_CloseButton:
135 pm = _style->closeMask();
137 case Type_MaximizeButton:
138 pm = _style->maximizeMask();
140 case Type_IconifyButton:
141 pm = _style->iconifyMask();
145 return; // no drawing
147 assert(false); // there's no other button widgets!
151 if (pm->mask == None) return; // no mask for the button, leave it empty
153 width = _rect.width();
155 otk::RenderColor *color = (_focused ? _style->buttonFocusColor() :
156 _style->buttonUnfocusColor());
158 // set the clip region
159 int x = (width - pm->w) / 2, y = (width - pm->h) / 2;
160 XSetClipMask(**otk::display, color->gc(), pm->mask);
161 XSetClipOrigin(**otk::display, color->gc(), x, y);
163 // fill in the clipped region
164 XFillRectangle(**otk::display, _surface->pixmap(), color->gc(), x, y,
165 x + pm->w, y + pm->h);
167 // unset the clip region
168 XSetClipMask(**otk::display, color->gc(), None);
169 XSetClipOrigin(**otk::display, color->gc(), 0, 0);
174 void ButtonWidget::adjust()
176 // nothing to adjust. no children.
180 void ButtonWidget::focus()
182 otk::Widget::focus();
187 void ButtonWidget::unfocus()
189 otk::Widget::unfocus();
194 void ButtonWidget::buttonPressHandler(const XButtonEvent &e)
196 otk::Widget::buttonPressHandler(e);
205 void ButtonWidget::buttonReleaseHandler(const XButtonEvent &e)
207 otk::Widget::buttonPressHandler(e);
208 if (e.button != _button) return;