From f1aac9d707a24953a22b44438a5ff039c58d5d0f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Feb 2014 15:08:49 +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/trunk@75921 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 dae2125410..d49992155c 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -2449,7 +2449,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()