OBButtonWidget::OBButtonWidget(otk::OtkWidget *parent,
OBWidget::WidgetType type)
- : otk::OtkButton(parent),
- OBWidget(type)
+ : otk::OtkWidget(parent),
+ OBWidget(type),
+ _pressed(false),
+ _button(0)
{
}
}
+void OBButtonWidget::setTextures()
+{
+ switch (type()) {
+ case Type_LeftGrip:
+ case Type_RightGrip:
+ if (_focused)
+ setTexture(_style->getGripFocus());
+ else
+ setTexture(_style->getGripUnfocus());
+ break;
+ case Type_StickyButton:
+ case Type_CloseButton:
+ case Type_MaximizeButton:
+ case Type_IconifyButton:
+ if (_pressed) {
+ if (_focused)
+ setTexture(_style->getButtonPressedFocus());
+ else
+ setTexture(_style->getButtonPressedUnfocus());
+ } else {
+ if (_focused)
+ setTexture(_style->getButtonFocus());
+ else
+ setTexture(_style->getButtonUnfocus());
+ }
+ break;
+ default:
+ assert(false); // there's no other button widgets!
+ }
+}
+
+
void OBButtonWidget::setStyle(otk::Style *style)
{
- otk::OtkButton::setStyle(style);
+ otk::OtkWidget::setStyle(style);
+ setTextures();
switch (type()) {
case Type_LeftGrip:
case Type_RightGrip:
- setTexture(style->getGripFocus());
- setUnfocusTexture(style->getGripUnfocus());
- setPressedFocusTexture(style->getGripFocus());
- setPressedUnfocusTexture(style->getGripUnfocus());
- setTexture(style->getGripFocus());
- setUnfocusTexture(style->getGripUnfocus());
- setPressedFocusTexture(style->getGripFocus());
- setPressedUnfocusTexture(style->getGripUnfocus());
setBorderColor(_style->getBorderColor());
- setUnfocusBorderColor(style->getBorderColor());
break;
- default:
+ case Type_StickyButton:
+ case Type_CloseButton:
+ case Type_MaximizeButton:
+ case Type_IconifyButton:
break;
+ default:
+ assert(false); // there's no other button widgets!
}
}
-void OBButtonWidget::adjust()
+void OBButtonWidget::focus()
{
- otk::OtkButton::adjust();
+ otk::OtkWidget::focus();
+ setTextures();
+}
+
+void OBButtonWidget::unfocus()
+{
+ otk::OtkWidget::unfocus();
+ setTextures();
+}
+
+
+void OBButtonWidget::adjust()
+{
// XXX: adjust shit
}
+void OBButtonWidget::buttonPressHandler(const XButtonEvent &e)
+{
+ OtkWidget::buttonPressHandler(e);
+ if (_button) return;
+ _button = e.button;
+ _pressed = true;
+ setTextures();
+ update();
+}
+
+
+void OBButtonWidget::buttonReleaseHandler(const XButtonEvent &e)
+{
+ OtkWidget::buttonPressHandler(e);
+ if (e.button != _button) return;
+ _button = 0;
+ _pressed = false;
+ setTextures();
+ update();
+}
+
}