diff options
-rw-r--r-- | dw/layout.cc | 24 | ||||
-rw-r--r-- | dw/layout.hh | 2 |
2 files changed, 23 insertions, 3 deletions
diff --git a/dw/layout.cc b/dw/layout.cc index 542b8ea4..f16cbae7 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -308,9 +308,7 @@ Layout::~Layout () if (bgImage) bgImage->unref (); if (topLevel) { - // Sometimes, the toplevel widget does some stuff after the - // layout has been deleted. - topLevel->layout = NULL; + detachWidget (topLevel); Widget *w = topLevel; topLevel = NULL; delete w; @@ -326,6 +324,26 @@ Layout::~Layout () DBG_OBJ_DELETE (); } +void Layout::detachWidget (Widget *widget) +{ + // Called form ~Layout. Sometimes, the widgets (not only the toplevel widget) + // do some stuff after the layout has been deleted, so *all* widgets have to + // be detached, and check "layout != NULL" at relevant points. + + // Could be replaced by a virtual method in Widget, like getWidgetAtPoint, + // if performace were really a problem. + + widget->layout = NULL; + Iterator *it = + widget->iterator ((Content::Type) + (Content::WIDGET_IN_FLOW | Content::WIDGET_OOF_CONT), + false); + while (it->next ()) + detachWidget (it->getContent()->widget); + + it->unref (); +} + void Layout::addWidget (Widget *widget) { if (topLevel) { diff --git a/dw/layout.hh b/dw/layout.hh index f76d755a..6b6ceadb 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -203,6 +203,8 @@ private: enum ButtonEventType { BUTTON_PRESS, BUTTON_RELEASE, MOTION_NOTIFY }; + void detachWidget (Widget *widget); + Widget *getWidgetAtPoint (int x, int y); void moveToWidget (Widget *newWidgetAtPoint, ButtonState state); |