{
Init(flags);
- SetWindow(window);
+ DoSetWindow(window);
}
// subsizer
{
Init(flags);
- SetSizer(sizer);
+ DoSetSizer(sizer);
}
// spacer
{
Init(flags);
- SetSpacer(width, height);
+ DoSetSpacer(wxSize(width, height));
}
wxSizerItem();
wxPoint GetPosition() const
{ return m_pos; }
+ // these functions delete the current contents of the item if it's a sizer
+ // or a spacer but not if it is a window
+ void AssignWindow(wxWindow *window)
+ {
+ Free();
+ DoSetWindow(window);
+ }
+
+ void AssignSizer(wxSizer *sizer)
+ {
+ Free();
+ DoSetSizer(sizer);
+ }
+
+ void AssignSpacer(const wxSize& size)
+ {
+ Free();
+ DoSetSpacer(size);
+ }
+
+ void AssignSpacer(int w, int h) { AssignSpacer(wxSize(w, h)); }
- // these functions do not free old sizer/spacer
- void SetWindow(wxWindow *window);
- void SetSizer(wxSizer *sizer);
- void SetSpacer(const wxSize& size);
- void SetSpacer(int width, int height) { SetSpacer(wxSize(width, height)); }
+#if WXWIN_COMPATIBILITY_2_8
+ // these functions do not free the old sizer/spacer and so can easily
+ // provoke the memory leaks and so shouldn't be used, use Assign() instead
+ wxDEPRECATED( void SetWindow(wxWindow *window) );
+ wxDEPRECATED( void SetSizer(wxSizer *sizer) );
+ wxDEPRECATED( void SetSpacer(const wxSize& size) );
+ wxDEPRECATED( void SetSpacer(int width, int height) );
+#endif // WXWIN_COMPATIBILITY_2_8
protected:
// common part of several ctors
- void Init() { m_userData = NULL; }
+ void Init() { m_userData = NULL; m_kind = Item_None; }
// common part of ctors taking wxSizerFlags
void Init(const wxSizerFlags& flags);
+ // free current contents
+ void Free();
+
+ // common parts of Set/AssignXXX()
+ void DoSetWindow(wxWindow *window);
+ void DoSetSizer(wxSizer *sizer);
+ void DoSetSpacer(const wxSize& size);
// discriminated union: depending on m_kind one of the fields is valid
enum
// inline functions implementation
// ----------------------------------------------------------------------------
+#if WXWIN_COMPATIBILITY_2_8
+
+inline void wxSizerItem::SetWindow(wxWindow *window)
+{
+ DoSetWindow(window);
+}
+
+inline void wxSizerItem::SetSizer(wxSizer *sizer)
+{
+ DoSetSizer(sizer);
+}
+
+inline void wxSizerItem::SetSpacer(const wxSize& size)
+{
+ DoSetSpacer(size);
+}
+
+inline void wxSizerItem::SetSpacer(int width, int height)
+{
+ DoSetSpacer(wxSize(width, height));
+}
+
+#endif // WXWIN_COMPATIBILITY_2_8
+
+
inline wxSizerItem*
wxSizer::Add( wxSizerItem *item )
{
return Insert(index, 0, 0, prop);
}
-
#endif // __WXSIZER_H__
m_proportion = 0;
m_border = 0;
m_flag = 0;
-
- m_kind = Item_None;
}
// window item
-void wxSizerItem::SetWindow(wxWindow *window)
+void wxSizerItem::DoSetWindow(wxWindow *window)
{
wxCHECK_RET( window, _T("NULL window in wxSizerItem::SetWindow()") );
int flag,
int border,
wxObject* userData)
- : m_proportion(proportion),
+ : m_kind(Item_None),
+ m_proportion(proportion),
m_border(border),
m_flag(flag),
m_userData(userData)
{
- SetWindow(window);
+ DoSetWindow(window);
}
// sizer item
-void wxSizerItem::SetSizer(wxSizer *sizer)
+void wxSizerItem::DoSetSizer(wxSizer *sizer)
{
m_kind = Item_Sizer;
m_sizer = sizer;
int flag,
int border,
wxObject* userData)
- : m_proportion(proportion),
+ : m_kind(Item_None),
+ m_sizer(NULL),
+ m_proportion(proportion),
m_border(border),
m_flag(flag),
m_ratio(0.0),
m_userData(userData)
{
- SetSizer(sizer);
+ DoSetSizer(sizer);
// m_minSize is set later
}
// spacer item
-void wxSizerItem::SetSpacer(const wxSize& size)
+void wxSizerItem::DoSetSpacer(const wxSize& size)
{
m_kind = Item_Spacer;
m_spacer = new wxSizerSpacer(size);
int flag,
int border,
wxObject* userData)
- : m_minSize(width, height), // minimal size is the initial size
+ : m_kind(Item_None),
+ m_sizer(NULL),
+ m_minSize(width, height), // minimal size is the initial size
m_proportion(proportion),
m_border(border),
m_flag(flag),
m_userData(userData)
{
- SetSpacer(width, height);
+ DoSetSpacer(wxSize(width, height));
}
wxSizerItem::~wxSizerItem()
{
delete m_userData;
+ Free();
+}
+void wxSizerItem::Free()
+{
switch ( m_kind )
{
case Item_None:
default:
wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
}
+
+ m_kind = Item_None;
}
wxSize wxSizerItem::GetSpacer() const