]> Dogcows Code - chaz/openbox/blobdiff - otk/widget.cc
watch for bad actions and contexts
[chaz/openbox] / otk / widget.cc
index 9f574ee930ba022a57ea333b3bdce1beb9ff58f2..9708977d47732ffa03f674eb06c25fa78cf63c1e 100644 (file)
@@ -8,7 +8,7 @@
 #include "display.hh"
 #include "assassin.hh"
 #include "screeninfo.hh"
-
+#include "focuslabel.hh"
 #include <algorithm>
 #include <iostream>
 
@@ -25,19 +25,18 @@ Widget::Widget(Widget *parent, Direction direction)
     _stretchable_horz(false), _texture(0), _bg_pixmap(0), _bg_pixel(0),
     _bcolor(0), _bwidth(0), _rect(0, 0, 1, 1), _screen(parent->screen()),
     _fixed_width(false), _fixed_height(false),
-    _surface(parent->screen(), _rect.size()),
+    _surface(0),
     _event_dispatcher(parent->eventDispatcher())
 {
   assert(parent);
   parent->addChild(this);
   create();
   _event_dispatcher->registerHandler(_window, this);
-  setStyle(_style); // let the widget initialize stuff
 }
 
-Widget::Widget(EventDispatcher *event_dispatcher, Style *style,
-                     Direction direction, Cursor cursor, int bevel_width,
-                     bool override_redirect)
+Widget::Widget(EventDispatcher *event_dispatcher, RenderStyle *style,
+               Direction direction, Cursor cursor, int bevel_width,
+               bool override_redirect)
   : EventHandler(),
     _dirty(false),_focused(false),
     _parent(0), _style(style), _direction(direction), _cursor(cursor),
@@ -45,15 +44,14 @@ Widget::Widget(EventDispatcher *event_dispatcher, Style *style,
     _grabbed_mouse(false), _grabbed_keyboard(false),
     _stretchable_vert(false), _stretchable_horz(false), _texture(0),
     _bg_pixmap(0), _bg_pixel(0), _bcolor(0), _bwidth(0), _rect(0, 0, 1, 1),
-    _screen(style->getScreen()), _fixed_width(false), _fixed_height(false),
-    _surface(style->getScreen(), _rect.size()),
+    _screen(style->screen()), _fixed_width(false), _fixed_height(false),
+    _surface(0),
     _event_dispatcher(event_dispatcher)
 {
   assert(event_dispatcher);
   assert(style);
   create(override_redirect);
   _event_dispatcher->registerHandler(_window, this);
-  setStyle(_style); // let the widget initialize stuff
 }
 
 Widget::~Widget()
@@ -61,6 +59,9 @@ Widget::~Widget()
   if (_visible)
     hide();
 
+  if (_surface)
+    delete _surface;
+  
   _event_dispatcher->clearHandler(_window);
 
   std::for_each(_children.begin(), _children.end(), PointerAssassin());
@@ -156,6 +157,13 @@ void Widget::setGeometry(int x, int y, int width, int height)
   _rect = Rect(x, y, width, height);
   _dirty = true;
 
+  // make all parents dirty too
+  Widget *p = _parent;
+  while (p) {
+    p->_dirty = true;
+    p = p->_parent;
+  }
+
   // don't use an XMoveResizeWindow here, because it doesn't seem to move
   // windows with StaticGravity? This works, that didn't.
   XResizeWindow(**display, _window, width, height);
@@ -175,7 +183,7 @@ void Widget::show(bool recursive)
   if (recursive) {
     WidgetList::iterator it = _children.begin(), end = _children.end();
     for (; it != end; ++it)
-      (*it)->show();
+      (*it)->show(recursive);
   }
 
   XMapWindow(**display, _window);
@@ -259,14 +267,18 @@ void Widget::ungrabKeyboard(void)
 void Widget::render(void)
 {
   if (!_texture) return;
-  printf("RENDER\n");
 
-  _surface = Surface(_screen, _rect.size());
-  display->renderControl(_screen)->drawBackground(_surface, *_texture);
+  Surface *s = _surface; // save the current surface
+  
+  _surface = new Surface(_screen, _rect.size());
+  display->renderControl(_screen)->drawBackground(*_surface, *_texture);
+
+  renderForeground(); // for inherited types to render onto the _surface
 
-  renderForeground();
+  XSetWindowBackgroundPixmap(**display, _window, _surface->pixmap());
 
-  XSetWindowBackgroundPixmap(**display, _window, _surface.pixmap());
+  if (s)
+    delete s; // delete the old surface *after* its pixmap isn't in use anymore
 }
 
 void Widget::adjust(void)
@@ -323,14 +335,13 @@ void Widget::adjustHorz(void)
     if (prev_widget)
       x = prev_widget->_rect.x() + prev_widget->_rect.width() + _bevel_width;
     else
-      x = _rect.x() + _bevel_width;
+      x = _bevel_width;
     y = (tallest - tmp->_rect.height()) / 2 + _bevel_width;
 
     tmp->move(x, y);
 
     prev_widget = tmp;
   }
-
   internalResize(width, tallest + _bevel_width * 2);
 }
 
@@ -380,7 +391,7 @@ void Widget::adjustVert(void)
     if (prev_widget)
       y = prev_widget->_rect.y() + prev_widget->_rect.height() + _bevel_width;
     else
-      y = _rect.y() + _bevel_width;
+      y = _bevel_width;
     x = (widest - tmp->_rect.width()) / 2 + _bevel_width;
 
     tmp->move(x, y);
@@ -391,7 +402,7 @@ void Widget::adjustVert(void)
   internalResize(widest + _bevel_width * 2, height);
 }
 
-void Widget::update(void)
+void Widget::update()
 {
   if (_dirty) {
     adjust();
@@ -410,12 +421,17 @@ void Widget::internalResize(int w, int h)
 {
   assert(w > 0 && h > 0);
 
-  if (! _fixed_width && ! _fixed_height)
+  bool fw = _fixed_width, fh = _fixed_height;
+  
+  if (! fw && ! fh)
     resize(w, h);
-  else if (! _fixed_width)
+  else if (! fw)
     resize(w, _rect.height());
-  else if (! _fixed_height)
+  else if (! fh)
     resize(_rect.width(), h);
+
+  _fixed_width = fw;
+  _fixed_height = fh;
 }
 
 void Widget::addChild(Widget *child, bool front)
@@ -440,7 +456,7 @@ void Widget::removeChild(Widget *child)
     _children.erase(it);
 }
 
-void Widget::setStyle(Style *style)
+void Widget::setStyle(RenderStyle *style)
 {
   assert(style);
   _style = style;
@@ -463,18 +479,28 @@ void Widget::setEventDispatcher(EventDispatcher *disp)
 void Widget::exposeHandler(const XExposeEvent &e)
 {
   EventHandler::exposeHandler(e);
-  XClearArea(**display, _window, e.x, e.y, e.width, e.height, false);
+//  XClearArea(**display, _window, e.x, e.y, e.width, e.height, false);
 }
 
 void Widget::configureHandler(const XConfigureEvent &e)
 {
   EventHandler::configureHandler(e);
+
   if (_ignore_config) {
     _ignore_config--;
   } else {
-    if (!(e.width == _rect.width() && e.height == _rect.height())) {
+    int width = e.width;
+    int height = e.height;
+
+    XEvent ev;
+    while (XCheckTypedWindowEvent(**display, _window, ConfigureNotify, &ev)) {
+      width = ev.xconfigure.width;
+      height = ev.xconfigure.height;
+    }
+
+    if (!(width == _rect.width() && height == _rect.height())) {
       _dirty = true;
-      _rect.setSize(e.width, e.height);
+      _rect.setSize(width, height);
     }
     update();
   }
This page took 0.029094 seconds and 4 git commands to generate.