From 5fdd493d0d2255f134114e69f028371366f4dfd3 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 27 Dec 2002 10:07:57 +0000 Subject: buttons have their pixmaps! --- src/buttonwidget.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/buttonwidget.hh | 2 ++ src/client.cc | 6 ++--- src/labelwidget.cc | 61 ++++++++++++++++++++++++--------------------------- 4 files changed, 91 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/buttonwidget.cc b/src/buttonwidget.cc index 853b0339..efb98e76 100644 --- a/src/buttonwidget.cc +++ b/src/buttonwidget.cc @@ -5,6 +5,7 @@ #endif #include "buttonwidget.hh" +#include "otk/gccache.hh" // otk::BPen namespace ob { @@ -76,6 +77,62 @@ void OBButtonWidget::setStyle(otk::Style *style) } +void OBButtonWidget::update() +{ + otk::PixmapMask *pm; + int width; + + otk::OtkWidget::update(); + + switch (type()) { + case Type_StickyButton: + pm = _style->getStickyButtonMask(); + break; + case Type_CloseButton: + pm = _style->getCloseButtonMask(); + break; + case Type_MaximizeButton: + pm = _style->getMaximizeButtonMask(); + break; + case Type_IconifyButton: + pm = _style->getIconifyButtonMask(); + break; + case Type_LeftGrip: + case Type_RightGrip: + return; // no drawing + default: + assert(false); // there's no other button widgets! + } + + if (pm->mask == None) return; // no mask for the button, leave it empty + + width = _rect.width(); + + otk::BPen pen(_focused ? *_style->getButtonPicFocus() : + *_style->getButtonPicUnfocus()); + + // set the clip region + XSetClipMask(otk::OBDisplay::display, pen.gc(), pm->mask); + XSetClipOrigin(otk::OBDisplay::display, pen.gc(), + (width - pm->w)/2, (width - pm->h)/2); + + // fill in the clipped region + XFillRectangle(otk::OBDisplay::display, _window, pen.gc(), + (width - pm->w)/2, (width - pm->h)/2, + (width + pm->w)/2, (width + pm->h)/2); + + // unset the clip region + XSetClipMask(otk::OBDisplay::display, pen.gc(), None); + XSetClipOrigin(otk::OBDisplay::display, pen.gc(), 0, 0); +} + + +void OBButtonWidget::adjust() +{ + // XXX: adjust shit +} + + void OBButtonWidget::focus() { otk::OtkWidget::focus(); @@ -90,12 +147,6 @@ void OBButtonWidget::unfocus() } -void OBButtonWidget::adjust() -{ - // XXX: adjust shit -} - - void OBButtonWidget::buttonPressHandler(const XButtonEvent &e) { OtkWidget::buttonPressHandler(e); diff --git a/src/buttonwidget.hh b/src/buttonwidget.hh index 66a9cf37..c2bb41f4 100644 --- a/src/buttonwidget.hh +++ b/src/buttonwidget.hh @@ -22,6 +22,8 @@ public: virtual void adjust(); + virtual void update(); + virtual void focus(); virtual void unfocus(); diff --git a/src/client.cc b/src/client.cc index 243390a8..e626081c 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1009,15 +1009,15 @@ void OBClient::destroyHandler(const XDestroyWindowEvent &e) void OBClient::reparentHandler(const XReparentEvent &e) { + // this is when the client is first taken captive in the frame + if (e.parent == frame->plate()) return; + #ifdef DEBUG printf("ReparentNotify for 0x%lx\n", e.window); #endif // DEBUG OtkEventHandler::reparentHandler(e); - // this is when the client is first taken captive in the frame - if (e.parent == frame->plate()) return; - /* This event is quite rare and is usually handled in unmapHandler. However, if the window is unmapped when the reparent event occurs, diff --git a/src/labelwidget.cc b/src/labelwidget.cc index 5a33cf3d..491deadc 100644 --- a/src/labelwidget.cc +++ b/src/labelwidget.cc @@ -72,41 +72,38 @@ void OBLabelWidget::unfocus() void OBLabelWidget::update() { - if (_dirty) { - std::string t = _text; - int x = _sidemargin; // x coord for the text - - // find a string that will fit inside the area for text - int max_length = width() - _sidemargin * 2; - if (max_length <= 0) { - t = ""; // can't fit anything - } else { - size_t text_len = t.size(); - int length; + OtkWidget::update(); + + std::string t = _text; + int x = _sidemargin; // x coord for the text + + // find a string that will fit inside the area for text + int max_length = width() - _sidemargin * 2; + if (max_length <= 0) { + t = ""; // can't fit anything + } else { + size_t text_len = t.size(); + int length; - do { - t.resize(text_len); - length = _font->measureString(t); - } while (length > max_length && text_len-- > 0); - - // justify the text - switch (_justify) { - case otk::Style::RightJustify: - x += max_length - length; - break; - case otk::Style::CenterJustify: - x += (max_length - length) / 2; - break; - case otk::Style::LeftJustify: - break; - } + do { + t.resize(text_len); + length = _font->measureString(t); + } while (length > max_length && text_len-- > 0); + + // justify the text + switch (_justify) { + case otk::Style::RightJustify: + x += max_length - length; + break; + case otk::Style::CenterJustify: + x += (max_length - length) / 2; + break; + case otk::Style::LeftJustify: + break; } + } - OtkWidget::update(); - - _font->drawString(_xftdraw, x, 0, *_text_color, t); - } else - OtkWidget::update(); + _font->drawString(_xftdraw, x, 0, *_text_color, t); } -- cgit v1.2.3