1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
7 #include "buttonwidget.hh"
8 #include "otk/gccache.hh" // otk::BPen
12 ButtonWidget::ButtonWidget(otk::Widget *parent,
13 WidgetBase::WidgetType type)
14 : otk::Widget(parent),
22 ButtonWidget::~ButtonWidget()
27 void ButtonWidget::setTextures()
33 setTexture(_style->gripFocusBackground());
35 setTexture(_style->gripUnfocusBackground());
37 case Type_StickyButton:
38 case Type_CloseButton:
39 case Type_MaximizeButton:
40 case Type_IconifyButton:
43 setTexture(_style->buttonPressFocusBackground());
45 setTexture(_style->buttonPressUnfocusBackground());
48 setTexture(_style->buttonUnpressFocusBackground());
50 setTexture(_style->buttonUnpressUnfocusBackground());
54 assert(false); // there's no other button widgets!
59 void ButtonWidget::setStyle(otk::RenderStyle *style)
61 otk::Widget::setStyle(style);
67 setBorderColor(_style->frameBorderColor());
69 case Type_StickyButton:
70 case Type_CloseButton:
71 case Type_MaximizeButton:
72 case Type_IconifyButton:
75 assert(false); // there's no other button widgets!
80 void ButtonWidget::update()
82 printf("ButtonWidget::update()\n");
83 otk::Widget::update();
86 void ButtonWidget::renderForeground()
92 printf("ButtonWidget::renderForeground()\n");
93 otk::Widget::renderForeground();
97 case Type_StickyButton:
98 pm = _style->stickyMask();
100 case Type_CloseButton:
101 pm = _style->closeMask();
103 case Type_MaximizeButton:
104 pm = _style->maximizeMask();
106 case Type_IconifyButton:
107 pm = _style->iconifyMask();
111 return; // no drawing
113 assert(false); // there's no other button widgets!
117 if (pm->mask == None) return; // no mask for the button, leave it empty
119 width = _rect.width();
121 otk::RenderColor *color = (_focused ? _style->buttonFocusColor() :
122 _style->buttonUnfocusColor());
124 // set the clip region
125 int x = (width - pm->w) / 2, y = (width - pm->h) / 2;
126 XSetClipMask(**otk::display, color->gc(), pm->mask);
127 XSetClipOrigin(**otk::display, color->gc(), x, y);
129 // fill in the clipped region
130 XFillRectangle(**otk::display, _surface->pixmap(), color->gc(), x, y,
131 x + pm->w, y + pm->h);
133 // unset the clip region
134 XSetClipMask(**otk::display, color->gc(), None);
135 XSetClipOrigin(**otk::display, color->gc(), 0, 0);
140 void ButtonWidget::adjust()
142 // nothing to adjust. no children.
146 void ButtonWidget::focus()
148 otk::Widget::focus();
153 void ButtonWidget::unfocus()
155 otk::Widget::unfocus();
160 void ButtonWidget::buttonPressHandler(const XButtonEvent &e)
162 otk::Widget::buttonPressHandler(e);
171 void ButtonWidget::buttonReleaseHandler(const XButtonEvent &e)
173 otk::Widget::buttonPressHandler(e);
174 if (e.button != _button) return;