X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fwidget.cc;h=1a0c7d9ea40828b9a81daddb5e54f6b0d2bd38e8;hb=9c2b06668e349901791fb9fe459cc511e460287e;hp=30b03bc83839922e9575a0ecbfa41b54a9bb0560;hpb=a4c8a839a3decc54e515fd110710195eca23fd2b;p=chaz%2Fopenbox diff --git a/otk/widget.cc b/otk/widget.cc index 30b03bc8..1a0c7d9e 100644 --- a/otk/widget.cc +++ b/otk/widget.cc @@ -37,7 +37,6 @@ Widget::Widget(int screen, EventDispatcher *ed, Direction direction, int bevel, { createWindow(overrideredir); _dispatcher->registerHandler(_window, this); - styleChanged(*RenderStyle::style(_screen)); } Widget::Widget(Widget *parent, Direction direction, int bevel) @@ -87,11 +86,9 @@ void Widget::show(bool children) } } if (!_visible) { - _visible = true; if (_parent) _parent->calcDefaultSizes(); - else { - resize(_min_size); - } + else resize(_area.size()); // constrain sizes + _visible = true; XMapWindow(**display, _window); update(); } @@ -134,14 +131,15 @@ void Widget::moveresize(const Rect &r) w = std::max(std::min(r.width(), maxSize().width()), minSize().width()); h = std::max(std::min(r.height(), maxSize().height()), minSize().height()); - if (r.x() == area().x() && r.y() == area().y() && - w == area().width() && h == area().height()) { + bool sizechange = !(w == area().width() && h == area().height()); + + if (r.x() == area().x() && r.y() == area().y() && !sizechange) return; // no change, don't cause a big layout chain to occur! - } internal_moveresize(r.x(), r.y(), w, h); - update(); + if (sizechange) + update(); } void Widget::internal_moveresize(int x, int y, int w, int h) @@ -231,12 +229,14 @@ void Widget::calcDefaultSizes() } } if (_direction == Horizontal) { - _min_size = otk::Size(min_sum, min_biggest + (_bevel + _borderwidth) * 2); + _min_size = otk::Size(min_sum + (_bevel + _borderwidth) * 2, + min_biggest + (_bevel + _borderwidth) * 2); _max_size = otk::Size((fullmax ? INT_MAX : max_sum + (_bevel + _borderwidth) * 2), max_biggest); } else { - _min_size = otk::Size(min_biggest, min_sum + (_bevel + _borderwidth) * 2); + _min_size = otk::Size(min_biggest + (_bevel + _borderwidth) * 2, + min_sum + (_bevel + _borderwidth) * 2); _max_size = otk::Size(max_biggest, (fullmax ? INT_MAX : max_sum + (_bevel + _borderwidth) * 2)); } @@ -296,13 +296,10 @@ void Widget::layoutHorz() std::list::iterator it, end; // work with just the visible children - std::list visible = _children; - for (it = visible.begin(), end = visible.end(); it != end;) { - std::list::iterator next = it; ++next; - if (!(*it)->visible()) - visible.erase(it); - it = next; - } + std::list visible; + for (it = _children.begin(), end = _children.end(); it != end; ++it) + if ((*it)->visible()) + visible.push_back(*it); if (visible.empty()) return; @@ -316,16 +313,14 @@ void Widget::layoutHorz() if (free < 0) free = 0; int each; - std::list adjustable = visible; + std::list adjustable; // find the 'free' space, and how many children will be using it - for (it = adjustable.begin(), end = adjustable.end(); it != end;) { - std::list::iterator next = it; ++next; + for (it = visible.begin(), end = visible.end(); it != end; ++it) { free -= (*it)->minSize().width(); if (free < 0) free = 0; - if ((*it)->maxSize().width() - (*it)->minSize().width() <= 0) - adjustable.erase(it); - it = next; + if ((*it)->maxSize().width() - (*it)->minSize().width() > 0) + adjustable.push_back(*it); } // some widgets may have max widths that restrict them, find the 'true' // amount of free space after these widgets are not included @@ -392,13 +387,10 @@ void Widget::layoutVert() std::list::iterator it, end; // work with just the visible children - std::list visible = _children; - for (it = visible.begin(), end = visible.end(); it != end;) { - std::list::iterator next = it; ++next; - if (!(*it)->visible()) - visible.erase(it); - it = next; - } + std::list visible; + for (it = _children.begin(), end = _children.end(); it != end; ++it) + if ((*it)->visible()) + visible.push_back(*it); if (visible.empty()) return; @@ -412,16 +404,14 @@ void Widget::layoutVert() if (free < 0) free = 0; int each; - std::list adjustable = visible; + std::list adjustable; // find the 'free' space, and how many children will be using it - for (it = adjustable.begin(), end = adjustable.end(); it != end;) { - std::list::iterator next = it; ++next; + for (it = visible.begin(), end = visible.end(); it != end; ++it) { free -= (*it)->minSize().height(); if (free < 0) free = 0; - if ((*it)->maxSize().height() - (*it)->minSize().height() <= 0) - adjustable.erase(it); - it = next; + if ((*it)->maxSize().height() - (*it)->minSize().height() > 0) + adjustable.push_back(*it); } // some widgets may have max heights that restrict them, find the 'true' // amount of free space after these widgets are not included @@ -445,7 +435,7 @@ void Widget::layoutVert() // place/size the widgets if (!adjustable.empty()) - each = free / adjustable.size(); + each = free / adjustable.size(); else each = 0; for (it = visible.begin(), end = visible.end(); it != end; ++it) { @@ -485,7 +475,14 @@ void Widget::layoutVert() void Widget::render() { - if (!_texture || !_dirty) return; + if (!_dirty) return; + if (!_texture) { + // set a solid color as the default background + XSetWindowBackground(**display, _window, + RenderStyle::style(_screen)-> + titlebarUnfocusBackground()->color().pixel()); + return; + } if (_borderwidth * 2 > _area.width() || _borderwidth * 2 > _area.height()) return; // no surface to draw on @@ -502,6 +499,7 @@ void Widget::render() // delete the old surface *after* its pixmap isn't in use anymore if (_surface) delete _surface; + s->freePixelData(); // done rendering with this surface _surface = s; _dirty = false; @@ -514,9 +512,9 @@ void Widget::renderChildren() (*it)->render(); } -void Widget::styleChanged(const RenderStyle &style) +void Widget::styleChanged(const RenderStyle &) { - _texture = style.titlebarUnfocusBackground(); + refresh(); } void Widget::exposeHandler(const XExposeEvent &e) @@ -532,7 +530,7 @@ void Widget::configureHandler(const XConfigureEvent &e) } else { // only interested in these for top level windows if (_parent) return; - + XEvent ev; ev.xconfigure.width = e.width; ev.xconfigure.height = e.height;