delete the associated wxStaticBox in wxStaticBoxSizer dtor (patch 1473769)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39380 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-05-28 17:24:12 +00:00
parent 6a1b3ead3f
commit e978011a40
4 changed files with 29 additions and 4 deletions

View File

@ -24,6 +24,7 @@ INCOMPATIBLE CHANGES SINCE 2.6.x
use GetMouseCursor().
- wxFontEnumerator::GetFacenames() and GetEncodings() now return arrays and
not pointers to arrays
- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted
Deprecated methods since 2.6.x and their replacements

View File

@ -1,8 +1,10 @@
\section{\class{wxStaticBoxSizer}}\label{wxstaticboxsizer}
wxStaticBoxSizer is a sizer derived from wxBoxSizer but adds a static
box around the sizer. This static box has to be created independently or the
sizer may create it itself as a convenience.
box around the sizer. This static box may be either created independently or
the sizer may create it itself as a convenience. In any case, the sizer owns
the \helpref{wxStaticBox}{wxstaticbox} control and will delete it if it is
deleted.
\wxheading{Derived from}

View File

@ -685,6 +685,7 @@ class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
public:
wxStaticBoxSizer(wxStaticBox *box, int orient);
wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
virtual ~wxStaticBoxSizer() { delete m_staticBox; }
void RecalcSizes();
wxSize CalcMin();
@ -694,6 +695,7 @@ public:
// override to hide/show the static box as well
virtual void ShowItems (bool show);
virtual bool Detach( wxWindow *window );
protected:
wxStaticBox *m_staticBox;

View File

@ -1697,16 +1697,22 @@ wxSize wxBoxSizer::CalcMin()
#if wxUSE_STATBOX
wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient )
: wxBoxSizer( orient )
, m_staticBox( box )
: wxBoxSizer( orient ),
m_staticBox( box )
{
wxASSERT_MSG( box, wxT("wxStaticBoxSizer needs a static box") );
// do this so that our Detach() is called if the static box is destroyed
// before we are
m_staticBox->SetContainingSizer(this);
}
wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s)
: wxBoxSizer(orient),
m_staticBox(new wxStaticBox(win, wxID_ANY, s))
{
// same as above
m_staticBox->SetContainingSizer(this);
}
static void GetStaticBoxBorders( wxStaticBox *box,
@ -1756,6 +1762,20 @@ void wxStaticBoxSizer::ShowItems( bool show )
wxBoxSizer::ShowItems( show );
}
bool wxStaticBoxSizer::Detach( wxWindow *window )
{
// avoid deleting m_staticBox in our dtor if it's being detached from the
// sizer (which can happen because it's being already destroyed for
// example)
if ( window == m_staticBox )
{
m_staticBox = NULL;
return true;
}
return wxSizer::Detach( window );
}
#endif // wxUSE_STATBOX
#if wxUSE_BUTTON