diff --git a/include/wx/statbox.h b/include/wx/statbox.h index 968903b009..26f3f0dd14 100644 --- a/include/wx/statbox.h +++ b/include/wx/statbox.h @@ -45,6 +45,12 @@ public: *borderOther = BORDER; } + // This is an internal function currently used by wxStaticBoxSizer only. + // + // Reparent all children of the static box under its parent and destroy the + // box itself. + virtual void WXDestroyWithoutChildren(); + protected: // choose the default border for this window virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; } diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index ce59f88a1e..b0b94674b0 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -2582,20 +2582,7 @@ wxStaticBoxSizer::~wxStaticBoxSizer() // 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; - } + m_staticBox->WXDestroyWithoutChildren(); } void wxStaticBoxSizer::RecalcSizes() diff --git a/src/common/statboxcmn.cpp b/src/common/statboxcmn.cpp index 3539c3c356..68b42d7af4 100644 --- a/src/common/statboxcmn.cpp +++ b/src/common/statboxcmn.cpp @@ -36,6 +36,22 @@ wxStaticBoxBase::wxStaticBoxBase() #endif } +void wxStaticBoxBase::WXDestroyWithoutChildren() +{ + // Notice that we must make a copy of the list as it will be changed by + // Reparent() calls in the loop. + const wxWindowList children = GetChildren(); + wxWindow* const parent = GetParent(); + for ( wxWindowList::const_iterator i = children.begin(); + i != children.end(); + ++i ) + { + (*i)->Reparent(parent); + } + + delete this; +} + // ---------------------------------------------------------------------------- // XTI // ----------------------------------------------------------------------------