diff --git a/include/wx/gtk/statbox.h b/include/wx/gtk/statbox.h index 64255f242d..cce262cbae 100644 --- a/include/wx/gtk/statbox.h +++ b/include/wx/gtk/statbox.h @@ -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); }; diff --git a/include/wx/statbox.h b/include/wx/statbox.h index 26f3f0dd14..360881031a 100644 --- a/include/wx/statbox.h +++ b/include/wx/statbox.h @@ -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); }; diff --git a/src/common/statboxcmn.cpp b/src/common/statboxcmn.cpp index 68b42d7af4..62c4b50134 100644 --- a/src/common/statboxcmn.cpp +++ b/src/common/statboxcmn.cpp @@ -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; diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index 0d144e128b..6979591287 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -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") );