diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index eb9968505..183b6a65e 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -125,6 +125,7 @@ namespace NLGUI REFLECT_EXPORT_END void onRemoved(); + void onWidgetDeleted( CInterfaceElement *e ); protected: diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 83bda2c84..764d165ef 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -503,6 +503,10 @@ namespace NLGUI /// Unregisters a deletion watcher static void unregisterDeletionWatcher( IDeletionWatcher *watcher ); + /// Called when the widget is deleted, + /// so other widgets in the group can check if it belongs to them + virtual void onWidgetDeleted( CInterfaceElement *e ){} + protected: bool editorSelected; diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 61cdc2c9b..f72bc6f1f 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -322,6 +322,8 @@ namespace NLGUI // Return the current Depth, with no ZBias applied. float getDepthForZSort() const { return _DepthForZSort; } + void onWidgetDeleted( CInterfaceElement *e ); + protected: void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 76fa3e02d..c878ee82a 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -65,10 +65,8 @@ namespace NLGUI if( _ViewText != NULL ) { if( _Parent != NULL ) - _Parent->delView( _ViewText ); - else - delete _ViewText; - + _Parent->delView( _ViewText, true ); + delete _ViewText; _ViewText = NULL; } } @@ -124,7 +122,10 @@ namespace NLGUI else if( name == "hardtext" ) { - return _ViewText->getText().toString(); + if( _ViewText != NULL ) + return _ViewText->getText().toString(); + else + return std::string( "" ); } else if( name == "text_y" ) @@ -139,7 +140,10 @@ namespace NLGUI else if( name == "text_underlined" ) { - return toString( _ViewText->getUnderlined() ); + if( _ViewText != NULL ) + return toString( _ViewText->getUnderlined() ); + else + return std::string( "" ); } else if( name == "text_posref" ) @@ -280,7 +284,8 @@ namespace NLGUI else if( name == "hardtext" ) { - _ViewText->setText( value ); + if( _ViewText != NULL ) + _ViewText->setText( value ); return; } else @@ -303,8 +308,10 @@ namespace NLGUI if( name == "text_underlined" ) { bool b; - if( fromString( value, b ) ) - _ViewText->setUnderlined( b ); + if( _ViewText != NULL ) + if( fromString( value, b ) ) + _ViewText->setUnderlined( b ); + return; } else @@ -813,32 +820,35 @@ namespace NLGUI } } // Setup ViewText color - if ( pTxId==_TextureIdNormal || editorMode ) + if( _ViewText != NULL ) { - if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; - else viewTextColor= _TextColorNormal; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorNormal); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); + if ( pTxId==_TextureIdNormal || editorMode ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; + else viewTextColor= _TextColorNormal; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorNormal); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); + } + else if ( pTxId==_TextureIdPushed ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorPushed.A; + else viewTextColor= _TextColorPushed; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorPushed); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorPushed); + } + else if ( pTxId==_TextureIdOver ) + { + if(_TextHeaderColor) viewTextColor.A= _TextColorOver.A; + else viewTextColor= _TextColorOver; + _ViewText->setColor(viewTextColor); + _ViewText->setShadowColor(_TextShadowColorOver); + _ViewText->setModulateGlobalColor(_TextModulateGlobalColorOver); + } + if(getFrozen() && getFrozenHalfTone()) + _ViewText->setAlpha(_ViewText->getAlpha()>>2); } - else if ( pTxId==_TextureIdPushed ) - { - if(_TextHeaderColor) viewTextColor.A= _TextColorPushed.A; - else viewTextColor= _TextColorPushed; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorPushed); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorPushed); - } - else if ( pTxId==_TextureIdOver ) - { - if(_TextHeaderColor) viewTextColor.A= _TextColorOver.A; - else viewTextColor= _TextColorOver; - _ViewText->setColor(viewTextColor); - _ViewText->setShadowColor(_TextShadowColorOver); - _ViewText->setModulateGlobalColor(_TextModulateGlobalColorOver); - } - if(getFrozen() && getFrozenHalfTone()) - _ViewText->setAlpha(_ViewText->getAlpha()>>2); } @@ -978,5 +988,11 @@ namespace NLGUI _Parent->delView( _ViewText, true ); } } + + void CCtrlTextButton::onWidgetDeleted( CInterfaceElement *e ) + { + if( e == _ViewText ) + _ViewText = NULL; + } } diff --git a/code/nel/src/gui/interface_element.cpp b/code/nel/src/gui/interface_element.cpp index acc3197d7..786ac7967 100644 --- a/code/nel/src/gui/interface_element.cpp +++ b/code/nel/src/gui/interface_element.cpp @@ -47,7 +47,11 @@ namespace NLGUI } if( editorMode ) + { notifyDeletionWatchers(); + if( _Parent != NULL ) + _Parent->onWidgetDeleted( this ); + } } // ------------------------------------------------------------------------------------------------ diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 6804df955..a39a901c7 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -1088,7 +1088,6 @@ namespace NLGUI _Views.erase(_Views.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete v; return true; } @@ -1107,7 +1106,6 @@ namespace NLGUI _Controls.erase(_Controls.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete c; return true; } @@ -1126,7 +1124,6 @@ namespace NLGUI _ChildrenGroups.erase(_ChildrenGroups.begin()+i); delEltOrder (child); child->onRemoved(); - child->setParent( NULL ); if (!dontDelete) delete g; return true; } @@ -2477,4 +2474,16 @@ namespace NLGUI return "IMPLEMENT ME!"; } -} \ No newline at end of file + void CInterfaceGroup::onWidgetDeleted( CInterfaceElement *e ) + { + for( std::vector< CViewBase* >::iterator itr = _Views.begin(); itr != _Views.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + + for( std::vector< CCtrlBase* >::iterator itr = _Controls.begin(); itr != _Controls.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + + for( std::vector< CInterfaceGroup* >::iterator itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr ) + (*itr)->onWidgetDeleted( e ); + } +} +