]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/sizer.cpp
corrected signed/unsigned comparison warning
[wxWidgets.git] / src / common / sizer.cpp
index 84473ce9ccde1759eb8c5755304b2abb0fd83b23..b4ae33b5a74b76291f83d83210f92b21b43ee220 100644 (file)
@@ -33,9 +33,6 @@
 
 #include "wx/listimpl.cpp"
 
 
 #include "wx/listimpl.cpp"
 
-#if WXWIN_COMPATIBILITY_2_4
-    #include "wx/notebook.h"
-#endif
 
 //---------------------------------------------------------------------------
 
 
 //---------------------------------------------------------------------------
 
@@ -106,12 +103,10 @@ wxSizerItem::wxSizerItem()
     m_proportion = 0;
     m_border = 0;
     m_flag = 0;
     m_proportion = 0;
     m_border = 0;
     m_flag = 0;
-
-    m_kind = Item_None;
 }
 
 // window item
 }
 
 // window item
-void wxSizerItem::SetWindow(wxWindow *window)
+void wxSizerItem::DoSetWindow(wxWindow *window)
 {
     wxCHECK_RET( window, _T("NULL window in wxSizerItem::SetWindow()") );
 
 {
     wxCHECK_RET( window, _T("NULL window in wxSizerItem::SetWindow()") );
 
@@ -133,16 +128,17 @@ wxSizerItem::wxSizerItem(wxWindow *window,
                          int flag,
                          int border,
                          wxObject* userData)
                          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)
 {
              m_border(border),
              m_flag(flag),
              m_userData(userData)
 {
-    SetWindow(window);
+    DoSetWindow(window);
 }
 
 // sizer item
 }
 
 // sizer item
-void wxSizerItem::SetSizer(wxSizer *sizer)
+void wxSizerItem::DoSetSizer(wxSizer *sizer)
 {
     m_kind = Item_Sizer;
     m_sizer = sizer;
 {
     m_kind = Item_Sizer;
     m_sizer = sizer;
@@ -153,19 +149,21 @@ wxSizerItem::wxSizerItem(wxSizer *sizer,
                          int flag,
                          int border,
                          wxObject* userData)
                          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)
 {
              m_border(border),
              m_flag(flag),
              m_ratio(0.0),
              m_userData(userData)
 {
-    SetSizer(sizer);
+    DoSetSizer(sizer);
 
     // m_minSize is set later
 }
 
 // spacer item
 
     // 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);
 {
     m_kind = Item_Spacer;
     m_spacer = new wxSizerSpacer(size);
@@ -179,19 +177,25 @@ wxSizerItem::wxSizerItem(int width,
                          int flag,
                          int border,
                          wxObject* userData)
                          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)
 {
              m_proportion(proportion),
              m_border(border),
              m_flag(flag),
              m_userData(userData)
 {
-    SetSpacer(width, height);
+    DoSetSpacer(wxSize(width, height));
 }
 
 wxSizerItem::~wxSizerItem()
 {
     delete m_userData;
 }
 
 wxSizerItem::~wxSizerItem()
 {
     delete m_userData;
+    Free();
+}
 
 
+void wxSizerItem::Free()
+{
     switch ( m_kind )
     {
         case Item_None:
     switch ( m_kind )
     {
         case Item_None:
@@ -213,6 +217,8 @@ wxSizerItem::~wxSizerItem()
         default:
             wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
     }
         default:
             wxFAIL_MSG( _T("unexpected wxSizerItem::m_kind") );
     }
+
+    m_kind = Item_None;
 }
 
 wxSize wxSizerItem::GetSpacer() const
 }
 
 wxSize wxSizerItem::GetSpacer() const
@@ -581,13 +587,9 @@ bool wxSizer::Remove( int index )
 
     wxCHECK_MSG( node, false, _T("Failed to find child node") );
 
 
     wxCHECK_MSG( node, false, _T("Failed to find child node") );
 
-    wxSizerItem *item = node->GetData();
-
-    if ( item->IsWindow() )
-        item->GetWindow()->SetContainingSizer( NULL );
-
-    delete item;
+    delete node->GetData();
     m_children.Erase( node );
     m_children.Erase( node );
+
     return true;
 }
 
     return true;
 }
 
@@ -624,7 +626,6 @@ bool wxSizer::Detach( wxWindow *window )
 
         if (item->GetWindow() == window)
         {
 
         if (item->GetWindow() == window)
         {
-            item->GetWindow()->SetContainingSizer( NULL );
             delete item;
             m_children.Erase( node );
             return true;
             delete item;
             m_children.Erase( node );
             return true;
@@ -649,8 +650,6 @@ bool wxSizer::Detach( int index )
 
     if ( item->IsSizer() )
         item->DetachSizer();
 
     if ( item->IsSizer() )
         item->DetachSizer();
-    else if ( item->IsWindow() )
-        item->GetWindow()->SetContainingSizer( NULL );
 
     delete item;
     m_children.Erase( node );
 
     delete item;
     m_children.Erase( node );
@@ -669,8 +668,7 @@ bool wxSizer::Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive )
 
         if (item->GetWindow() == oldwin)
         {
 
         if (item->GetWindow() == oldwin)
         {
-            item->GetWindow()->SetContainingSizer( NULL );
-            item->SetWindow(newwin);
+            item->AssignWindow(newwin);
             newwin->SetContainingSizer( this );
             return true;
         }
             newwin->SetContainingSizer( this );
             return true;
         }
@@ -698,9 +696,7 @@ bool wxSizer::Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive )
 
         if (item->GetSizer() == oldsz)
         {
 
         if (item->GetSizer() == oldsz)
         {
-            wxSizer *old = item->GetSizer();
-            item->SetSizer(newsz);
-            delete old;
+            item->AssignSizer(newsz);
             return true;
         }
         else if (recursive && item->IsSizer())
             return true;
         }
         else if (recursive && item->IsSizer())
@@ -2025,7 +2021,8 @@ void wxStdDialogButtonSizer::Realize()
             if (m_buttonAffirmative->GetId() == wxID_SAVE){
                 // these buttons have set labels under Mac so we should use them
                 m_buttonAffirmative->SetLabel(_("Save"));
             if (m_buttonAffirmative->GetId() == wxID_SAVE){
                 // these buttons have set labels under Mac so we should use them
                 m_buttonAffirmative->SetLabel(_("Save"));
-                m_buttonNegative->SetLabel(_("Don't Save"));
+                if (m_buttonNegative)
+                    m_buttonNegative->SetLabel(_("Don't Save"));
             }
         }
 
             }
         }
 
@@ -2107,88 +2104,3 @@ void wxStdDialogButtonSizer::Realize()
 }
 
 #endif // wxUSE_BUTTON
 }
 
 #endif // wxUSE_BUTTON
-
-#if WXWIN_COMPATIBILITY_2_4
-
-// ----------------------------------------------------------------------------
-// wxNotebookSizer
-// ----------------------------------------------------------------------------
-
-#if wxUSE_BOOKCTRL
-IMPLEMENT_CLASS(wxBookCtrlSizer, wxSizer)
-#if wxUSE_NOTEBOOK
-IMPLEMENT_CLASS(wxNotebookSizer, wxBookCtrlSizer)
-#endif // wxUSE_NOTEBOOK
-#endif // wxUSE_BOOKCTRL
-
-#if wxUSE_BOOKCTRL
-
-#if WXWIN_COMPATIBILITY_2_6
-
-wxBookCtrlSizer::wxBookCtrlSizer(wxBookCtrlBase *bookctrl)
-               : m_bookctrl(bookctrl)
-{
-    wxASSERT_MSG( bookctrl, wxT("wxBookCtrlSizer needs a control") );
-}
-
-#endif // WXWIN_COMPATIBILITY_2_6
-
-void wxBookCtrlSizer::RecalcSizes()
-{
-    m_bookctrl->SetSize( m_position.x, m_position.y, m_size.x, m_size.y );
-}
-
-wxSize wxBookCtrlSizer::CalcMin()
-{
-    wxSize sizeBorder = m_bookctrl->CalcSizeFromPage(wxSize(0,0));
-
-    sizeBorder.x += 5;
-    sizeBorder.y += 5;
-
-    if ( m_bookctrl->GetPageCount() == 0 )
-    {
-        return wxSize(sizeBorder.x + 10, sizeBorder.y + 10);
-    }
-
-    int maxX = 0;
-    int maxY = 0;
-
-    wxWindowList::compatibility_iterator
-        node = m_bookctrl->GetChildren().GetFirst();
-    while (node)
-    {
-        wxWindow *item = node->GetData();
-        wxSizer *itemsizer = item->GetSizer();
-
-        if (itemsizer)
-        {
-            wxSize subsize( itemsizer->CalcMin() );
-
-            if (subsize.x > maxX)
-                maxX = subsize.x;
-            if (subsize.y > maxY)
-                maxY = subsize.y;
-        }
-
-        node = node->GetNext();
-    }
-
-    return wxSize( maxX, maxY ) + sizeBorder;
-}
-
-#if wxUSE_NOTEBOOK
-
-#if WXWIN_COMPATIBILITY_2_6
-
-wxNotebookSizer::wxNotebookSizer(wxNotebook *nb)
-{
-    wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a control") );
-    m_bookctrl = nb;
-}
-
-#endif // WXWIN_COMPATIBILITY_2_6
-
-#endif // wxUSE_NOTEBOOOK
-#endif // wxUSE_BOOKCTRL
-
-#endif // WXWIN_COMPATIBILITY_2_4