Permalink
Browse files

widget: Keep track of screen pointer, widgets are now safe to delete …

…directly.
  • Loading branch information...
1 parent 2f5d244 commit 16eecd83904745e99d8a2664a6f7ee8e677f7a55 @Cyp Cyp committed Feb 17, 2013
Showing with 20 additions and 9 deletions.
  1. +3 −0 lib/widget/widgbase.h
  2. +17 −9 lib/widget/widget.cpp
@@ -123,8 +123,11 @@ struct WIDGET
WIDGET_CALLBACK callback; ///< User callback (if any)
void *pUserData; ///< Pointer to a user data block (if any)
UDWORD UserData; ///< User data (if any)
+ W_SCREEN * screenPointer; ///< Pointer to screen the widget is on (if attached).
private:
+ void setScreenPointer(W_SCREEN *screen); ///< Set screen pointer for us and all children.
+
WIDGET * parentWidget; ///< Parent widget.
std::vector<WIDGET *> childWidgets; ///< Child widgets. Will be deleted if we are deleted.
View
@@ -125,6 +125,10 @@ WIDGET::~WIDGET()
{
psMouseOverWidget = NULL;
}
+ if (screenPointer != NULL && screenPointer->psFocus == this)
+ {
+ screenPointer->psFocus = NULL;
+ }
if (parentWidget != NULL)
{
@@ -141,6 +145,7 @@ void WIDGET::attach(WIDGET *widget)
{
ASSERT_OR_RETURN(, widget != NULL && widget->parentWidget == NULL, "Bad attach.");
widget->parentWidget = this;
+ widget->setScreenPointer(screenPointer);
childWidgets.push_back(widget);
}
@@ -149,11 +154,21 @@ void WIDGET::detach(WIDGET *widget)
ASSERT_OR_RETURN(, widget != NULL && widget->parentWidget != NULL, "Bad detach.");
widget->parentWidget = NULL;
+ widget->setScreenPointer(NULL);
childWidgets.erase(std::find(childWidgets.begin(), childWidgets.end(), widget));
widgetLost(widget);
}
+void WIDGET::setScreenPointer(W_SCREEN *screen)
+{
+ screenPointer = screen;
+ for (Children::const_iterator i = childWidgets.begin(); i != childWidgets.end(); ++i)
+ {
+ (*i)->setScreenPointer(screen);
+ }
+}
+
void WIDGET::widgetLost(WIDGET *widget)
{
if (parentWidget != NULL)
@@ -175,6 +190,7 @@ W_SCREEN::W_SCREEN()
sInit.height = screenHeight - 1;
psForm = new W_FORM(&sInit);
+ psForm->screenPointer = this;
}
W_SCREEN::~W_SCREEN()
@@ -304,15 +320,7 @@ void widgDelete(W_SCREEN *psScreen, UDWORD id)
{
ASSERT_OR_RETURN(, psScreen != NULL, "Invalid screen pointer");
- WIDGET *widget = widgGetFromID(psScreen, id);
-
- // Clear the keyboard focus if necessary.
- if (psScreen->psFocus == widget)
- {
- screenClearFocus(psScreen);
- }
-
- delete widget;
+ delete widgGetFromID(psScreen, id);
}
/* Find a widget on a form from its id number */

0 comments on commit 16eecd8

Please sign in to comment.