Move m_labelWin to wxStaticBoxBase itself

It will be reused by all platforms and is not specific to wxGTK.

This also means WXDestroyWithoutChildren() doesn't need to be virtual
any longer.
This commit is contained in:
Vadim Zeitlin 2017-12-20 00:03:55 +01:00
parent 7c849276f8
commit 8c06a24da4
4 changed files with 16 additions and 37 deletions

View File

@ -18,7 +18,6 @@ class WXDLLIMPEXP_CORE wxStaticBox : public wxStaticBoxBase
public:
wxStaticBox()
{
Init();
}
wxStaticBox( wxWindow *parent,
@ -29,8 +28,6 @@ public:
long style = 0,
const wxString &name = wxStaticBoxNameStr )
{
Init();
Create( parent, id, label, pos, size, style, name );
}
@ -42,8 +39,6 @@ public:
long style = 0,
const wxString &name = wxStaticBoxNameStr )
{
Init();
Create( parent, id, label, pos, size, style, name );
}
@ -82,15 +77,7 @@ public:
virtual void AddChild( wxWindowBase *child ) wxOVERRIDE;
virtual void WXDestroyWithoutChildren() wxOVERRIDE;
protected:
// Common part of all ctors.
void Init()
{
m_labelWin = NULL;
}
// Common implementation of both Create() overloads: exactly one of
// labelStr and labelWin parameters must be non-null.
bool DoCreate(wxWindow *parent,
@ -107,10 +94,6 @@ protected:
void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
// If non-null, the window used as our label. This window is owned by the
// static box and will be deleted when it is.
wxWindow* m_labelWin;
wxDECLARE_DYNAMIC_CLASS(wxStaticBox);
};

View File

@ -49,12 +49,16 @@ public:
//
// Reparent all children of the static box under its parent and destroy the
// box itself.
virtual void WXDestroyWithoutChildren();
void WXDestroyWithoutChildren();
protected:
// choose the default border for this window
virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; }
// If non-null, the window used as our label. This window is owned by the
// static box and will be deleted when it is.
wxWindow* m_labelWin;
wxDECLARE_NO_COPY_CLASS(wxStaticBoxBase);
};

View File

@ -31,6 +31,8 @@ extern WXDLLEXPORT_DATA(const char) wxStaticBoxNameStr[] = "groupBox";
wxStaticBoxBase::wxStaticBoxBase()
{
m_labelWin = NULL;
#ifndef __WXGTK__
m_container.DisableSelfFocus();
#endif
@ -46,7 +48,15 @@ void wxStaticBoxBase::WXDestroyWithoutChildren()
i != children.end();
++i )
{
(*i)->Reparent(parent);
// The label window doesn't count as our child, it's really a part of
// static box itself and it makes no sense to leave it alive when the
// box is destroyed, so do it even when it's supposed to be destroyed
// without destroying its children -- by not reparenting it, we ensure
// that it's destroyed when this object itself is below.
if ( *i != m_labelWin )
{
(*i)->Reparent(parent);
}
}
delete this;

View File

@ -152,24 +152,6 @@ void wxStaticBox::AddChild( wxWindowBase *child )
wxStaticBoxBase::AddChild(child);
}
void wxStaticBox::WXDestroyWithoutChildren()
{
// The label window doesn't count as our child, it's really a part of
// static box itself and it makes no sense to leave it alive when the box
// is destroyed, so do it even when it's supposed to be destroyed without
// destroying its children.
if ( m_labelWin )
{
// By deleting it here, we indirectly remove this window from the list
// of our children and hence prevent the base class version of this
// method from reparenting it and thus keeping it alive.
delete m_labelWin;
m_labelWin = NULL;
}
wxStaticBoxBase::WXDestroyWithoutChildren();
}
void wxStaticBox::SetLabel( const wxString& label )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );