From 363154e24156bbc7625a7dd662054db8b2d8452b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 8 Mar 2013 06:28:52 +0100 Subject: [PATCH] MODIFIED: Preliminary support for a little cleanup when removing a widget from it's parent group ( for example when moving the widget ). --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/ctrl_text_button.h | 2 ++ code/nel/include/nel/gui/interface_element.h | 3 +++ code/nel/src/gui/ctrl_text_button.cpp | 13 ++++++++++--- code/nel/src/gui/interface_group.cpp | 15 ++++++++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index 5837a0fbf..eb9968505 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -124,6 +124,8 @@ namespace NLGUI REFLECT_LUA_METHOD("getViewText", luaGetViewText) REFLECT_EXPORT_END + void onRemoved(); + protected: enum {NumTexture= 3}; diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 2b1fa32c0..739f1b95e 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -486,6 +486,9 @@ namespace NLGUI void setSerializable( bool b ){ serializable = b; } bool IsSerializable() const{ return serializable; } + /// Called when the widget is removed from it's parent group + virtual void onRemoved(){} + protected: bool editorSelected; diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index a527bb06f..744086c38 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -64,8 +64,8 @@ namespace NLGUI { if( _ViewText != NULL ) { - if( getParent() != NULL ) - getParent()->delElement( _ViewText ); + if( _Parent != NULL ) + _Parent->delView( _ViewText ); _ViewText = NULL; } } @@ -967,6 +967,13 @@ namespace NLGUI } // *************************************************************************** - + void CCtrlTextButton::onRemoved() + { + if( _ViewText != NULL ) + { + if( _Parent != NULL ) + _Parent->delView( _ViewText, true ); + } + } } diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index bb643769a..6804df955 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -1084,9 +1084,12 @@ namespace NLGUI { if (_Views[i] == child) { - if (!dontDelete) delete _Views[i]; + CViewBase *v = _Views[i]; _Views.erase(_Views.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete v; return true; } } @@ -1100,9 +1103,12 @@ namespace NLGUI { if (_Controls[i] == child) { - if (!dontDelete) delete _Controls[i]; + CCtrlBase *c = _Controls[i]; _Controls.erase(_Controls.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete c; return true; } } @@ -1116,9 +1122,12 @@ namespace NLGUI { if (_ChildrenGroups[i] == child) { - if (!dontDelete) delete _ChildrenGroups[i]; + CInterfaceGroup *g = _ChildrenGroups[i]; _ChildrenGroups.erase(_ChildrenGroups.begin()+i); delEltOrder (child); + child->onRemoved(); + child->setParent( NULL ); + if (!dontDelete) delete g; return true; } }