Add WXDestroyWithoutChildren() and use it from wxStaticBoxSizer

Factor out the code from wxStaticBoxSizer dtor into a wxStaticBox method
to improve encapsulation: the static box knows better than another class
how to detach its children from it before destroying it.

No real changes yet.
This commit is contained in:
Vadim Zeitlin
2017-12-19 21:47:01 +01:00
parent 87afebd6f2
commit aa47c15abd
3 changed files with 23 additions and 14 deletions

View File

@@ -45,6 +45,12 @@ public:
*borderOther = BORDER; *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: protected:
// choose the default border for this window // choose the default border for this window
virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; } virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; }

View File

@@ -2582,20 +2582,7 @@ wxStaticBoxSizer::~wxStaticBoxSizer()
// previous wxWidgets versions, so ensure they are left alive. // previous wxWidgets versions, so ensure they are left alive.
if ( m_staticBox ) if ( m_staticBox )
{ m_staticBox->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 = 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()

View File

@@ -36,6 +36,22 @@ wxStaticBoxBase::wxStaticBoxBase()
#endif #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 // XTI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------