X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fwidget.cc;h=691c0968e81eb6f408424ea7b8ecdf64153fd44c;hb=9f1facd3a167508906f1a2911d2ed7f0010967bb;hp=4522a1c0c2f3037fbd8771f593f0f1145e375f6b;hpb=f6724de2a4592c8e706cab30750e2c697d6b6509;p=chaz%2Fopenbox diff --git a/otk/widget.cc b/otk/widget.cc index 4522a1c0..691c0968 100644 --- a/otk/widget.cc +++ b/otk/widget.cc @@ -11,6 +11,7 @@ namespace otk { OtkWidget::OtkWidget(OtkWidget *parent, Direction direction) : _parent(parent), _style(parent->getStyle()), _direction(direction), _cursor(parent->getCursor()), _bevel_width(parent->getBevelWidth()), + _ignore_config(0), _visible(false), _focused(false), _grabbed_mouse(false), _grabbed_keyboard(false), _stretchable_vert(false), _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0), @@ -24,7 +25,7 @@ OtkWidget::OtkWidget(OtkWidget *parent, Direction direction) OtkWidget::OtkWidget(Style *style, Direction direction, Cursor cursor, int bevel_width) : _parent(0), _style(style), _direction(direction), _cursor(cursor), - _bevel_width(bevel_width), _visible(false), + _bevel_width(bevel_width), _ignore_config(0), _visible(false), _focused(false), _grabbed_mouse(false), _grabbed_keyboard(false), _stretchable_vert(false), _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0), _screen(style->getScreen()), @@ -71,6 +72,7 @@ void OtkWidget::create(void) _rect.y(), _rect.width(), _rect.height(), 0, scr_info->getDepth(), InputOutput, scr_info->getVisual(), create_mask, &attrib_create); + _ignore_config++; } void OtkWidget::setWidth(int w) @@ -96,6 +98,7 @@ void OtkWidget::move(int x, int y) { _rect.setPos(x, y); XMoveWindow(otk::OBDisplay::display, _window, x, y); + _ignore_config++; } void OtkWidget::resize(const Point &to) @@ -126,6 +129,7 @@ void OtkWidget::setGeometry(int x, int y, int width, int height) _dirty = true; XMoveResizeWindow(otk::OBDisplay::display, _window, x, y, width, height); + _ignore_config++; } void OtkWidget::show(void) @@ -208,11 +212,9 @@ void OtkWidget::ungrabKeyboard(void) void OtkWidget::render(void) { - Pixmap old = _bg_pixmap; - _bg_pixmap = _texture->render(_rect.width(), _rect.height(), _bg_pixmap); - if (_bg_pixmap && _bg_pixmap != old) + if (_bg_pixmap) XSetWindowBackgroundPixmap(otk::OBDisplay::display, _window, _bg_pixmap); else { unsigned int pix = _texture->color().pixel(); @@ -245,7 +247,10 @@ void OtkWidget::adjustHorz(void) for (it = _children.begin(); it != end; ++it) { tmp = *it; - if (tmp->isStretchableHorz() && _fixed_width) + if (tmp->isStretchableVert()) + tmp->setHeight(_rect.height() > _bevel_width * 2 ? + _rect.height() - _bevel_width * 2 : _bevel_width); + if (tmp->isStretchableHorz()) stretchable.push_back(tmp); else width += tmp->_rect.width() + _bevel_width; @@ -260,10 +265,9 @@ void OtkWidget::adjustHorz(void) int str_width = _rect.width() - width / stretchable.size(); - for (; str_it != str_end; ++str_it) { - (*str_it)->setWidth(str_width - _bevel_width); - (*str_it)->update(); - } + for (; str_it != str_end; ++str_it) + (*str_it)->setWidth(str_width > _bevel_width ? str_width - _bevel_width + : _bevel_width); } OtkWidget *prev_widget = 0; @@ -296,11 +300,31 @@ void OtkWidget::adjustVert(void) int widest = 0; int height = _bevel_width; + OtkWidgetList stretchable; + for (it = _children.begin(); it != end; ++it) { tmp = *it; + if (tmp->isStretchableHorz()) + tmp->setWidth(_rect.width() > _bevel_width * 2 ? + _rect.width() - _bevel_width * 2 : _bevel_width); + if (tmp->isStretchableVert()) + stretchable.push_back(tmp); + else + height += tmp->_rect.height() + _bevel_width; + if (tmp->_rect.width() > widest) widest = tmp->_rect.width(); - height += tmp->_rect.height() + _bevel_width; + } + + if (stretchable.size() > 0) { + OtkWidgetList::iterator str_it = stretchable.begin(), + str_end = stretchable.end(); + + int str_height = _rect.height() - height / stretchable.size(); + + for (; str_it != str_end; ++str_it) + (*str_it)->setHeight(str_height > _bevel_width ? + str_height - _bevel_width : _bevel_width); } OtkWidget *prev_widget = 0; @@ -330,6 +354,11 @@ void OtkWidget::update(void) render(); XClearWindow(OBDisplay::display, _window); } + + OtkWidgetList::iterator it = _children.begin(), end = _children.end(); + for (; it != end; ++it) + (*it)->update(); + _dirty = false; } @@ -367,4 +396,42 @@ void OtkWidget::removeChild(OtkWidget *child) _children.erase(it); } +bool OtkWidget::expose(const XExposeEvent &e) +{ + if (e.window == _window) { + _dirty = true; + update(); + return true; + } else { + OtkWidgetList::iterator it = _children.begin(), end = _children.end(); + for (; it != end; ++it) + if ((*it)->expose(e)) + return true; + } + return false; +} + +bool OtkWidget::configure(const XConfigureEvent &e) +{ + if (e.window == _window) { + if (_ignore_config) { + _ignore_config--; + } else { + std::cout << "configure\n"; + if (!(e.width == _rect.width() && e.height == _rect.height())) { + _dirty = true; + _rect.setSize(e.width, e.height); + } + update(); + } + return true; + } else { + OtkWidgetList::iterator it = _children.begin(), end = _children.end(); + for (; it != end; ++it) + if ((*it)->configure(e)) + return true; + } + return false; +} + }