From: Vadim Zeitlin Date: Sun, 28 May 2006 17:24:12 +0000 (+0000) Subject: delete the associated wxStaticBox in wxStaticBoxSizer dtor (patch 1473769) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e978011a4053f11bf253dc758dc482a991b84628 delete the associated wxStaticBox in wxStaticBoxSizer dtor (patch 1473769) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39380 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 8c7ebd96a3..0626cd708e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -24,6 +24,7 @@ INCOMPATIBLE CHANGES SINCE 2.6.x use GetMouseCursor(). - wxFontEnumerator::GetFacenames() and GetEncodings() now return arrays and not pointers to arrays +- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted Deprecated methods since 2.6.x and their replacements diff --git a/docs/latex/wx/sbsizer.tex b/docs/latex/wx/sbsizer.tex index 6394efaffc..0e552ebec6 100644 --- a/docs/latex/wx/sbsizer.tex +++ b/docs/latex/wx/sbsizer.tex @@ -1,8 +1,10 @@ \section{\class{wxStaticBoxSizer}}\label{wxstaticboxsizer} wxStaticBoxSizer is a sizer derived from wxBoxSizer but adds a static -box around the sizer. This static box has to be created independently or the -sizer may create it itself as a convenience. +box around the sizer. This static box may be either created independently or +the sizer may create it itself as a convenience. In any case, the sizer owns +the \helpref{wxStaticBox}{wxstaticbox} control and will delete it if it is +deleted. \wxheading{Derived from} diff --git a/include/wx/sizer.h b/include/wx/sizer.h index 14726daa0f..fcb3a86898 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -685,6 +685,7 @@ class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer public: wxStaticBoxSizer(wxStaticBox *box, int orient); wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); + virtual ~wxStaticBoxSizer() { delete m_staticBox; } void RecalcSizes(); wxSize CalcMin(); @@ -694,6 +695,7 @@ public: // override to hide/show the static box as well virtual void ShowItems (bool show); + virtual bool Detach( wxWindow *window ); protected: wxStaticBox *m_staticBox; diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 0b918a1344..4542871dd8 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1697,16 +1697,22 @@ wxSize wxBoxSizer::CalcMin() #if wxUSE_STATBOX wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) - : wxBoxSizer( orient ) - , m_staticBox( box ) + : wxBoxSizer( orient ), + m_staticBox( box ) { wxASSERT_MSG( box, wxT("wxStaticBoxSizer needs a static box") ); + + // do this so that our Detach() is called if the static box is destroyed + // before we are + m_staticBox->SetContainingSizer(this); } wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s) : wxBoxSizer(orient), m_staticBox(new wxStaticBox(win, wxID_ANY, s)) { + // same as above + m_staticBox->SetContainingSizer(this); } static void GetStaticBoxBorders( wxStaticBox *box, @@ -1756,6 +1762,20 @@ void wxStaticBoxSizer::ShowItems( bool show ) wxBoxSizer::ShowItems( show ); } +bool wxStaticBoxSizer::Detach( wxWindow *window ) +{ + // avoid deleting m_staticBox in our dtor if it's being detached from the + // sizer (which can happen because it's being already destroyed for + // example) + if ( window == m_staticBox ) + { + m_staticBox = NULL; + return true; + } + + return wxSizer::Detach( window ); +} + #endif // wxUSE_STATBOX #if wxUSE_BUTTON