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
This commit is contained in:
Vadim Zeitlin
2014-02-18 15:08:49 +00:00
parent 0206eb6161
commit f1aac9d707

View File

@@ -2449,7 +2449,31 @@ wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s)
wxStaticBoxSizer::~wxStaticBoxSizer() 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() void wxStaticBoxSizer::RecalcSizes()