From b9fdc86b9aa387d8b04c279ef6a3a86b8825ca17 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Feb 2014 15:09:23 +0000 Subject: [PATCH] Don't delete child controls when deleting wxStaticBoxSizer. This is an incompatible change compared to 2.8 which can make the existing code crash and it also goes against the usual rule that the windows are never owned by sizers, only other windows. Closes #15698. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/sizer.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 31bed2c619..6f810e3e44 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -2469,7 +2469,31 @@ wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s) wxStaticBoxSizer::~wxStaticBoxSizer() { - delete m_staticBox; + // As an exception to the general rule that sizers own other sizers that + // they contain but not the windows managed by them, this sizer does own + // the static box associated with it (which is not very logical but + // convenient in practice and, most importantly, can't be changed any more + // because of compatibility). However we definitely should not destroy the + // children of this static box when we're being destroyed, as this would be + // unexpected and break the existing code which worked with the windows + // created as siblings of the static box instead of its children in the + // previous wxWidgets versions, so ensure they are left alive. + + if ( m_staticBox ) + { + // Notice that we must make a copy of the list as it will be changed by + // Reparent() calls in the loop. + const wxWindowList children = m_staticBox->GetChildren(); + wxWindow* const parent = m_staticBox->GetParent(); + for ( wxWindowList::const_iterator i = children.begin(); + i != children.end(); + ++i ) + { + (*i)->Reparent(parent); + } + + delete m_staticBox; + } } void wxStaticBoxSizer::RecalcSizes()