]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/sizer.cpp
call gtk_toolbar_set_tooltips() from GtkSetStyle(); removed erroneous wxTB_TOOLTIPS
[wxWidgets.git] / src / common / sizer.cpp
index 892ae3ebcfac05c05cf9ed969148077c4c22a781..92377a0d0ad6ff59e6c0c3dd21536f3aa98802ec 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        sizer.cpp
+// Name:        src/common/sizer.cpp
 // Purpose:     provide new wxSizer class for layout
 // Author:      Robert Roebling and Robin Dunn, contributions by
 //              Dirk Holtwick, Ron Lee
 #ifndef WX_PRECOMP
     #include "wx/string.h"
     #include "wx/intl.h"
+    #include "wx/math.h"
+    #include "wx/utils.h"
+    #include "wx/settings.h"
 #endif // WX_PRECOMP
 
 #include "wx/sizer.h"
-#include "wx/utils.h"
 #include "wx/statbox.h"
-#include "wx/settings.h"
 #include "wx/listimpl.cpp"
-#include "wx/intl.h"
+
 #if WXWIN_COMPATIBILITY_2_4
     #include "wx/notebook.h"
 #endif
@@ -265,7 +266,7 @@ wxSize wxSizerItem::CalcMin()
 
         // if we have to preserve aspect ratio _AND_ this is
         // the first-time calculation, consider ret to be initial size
-        if ((m_flag & wxSHAPED) && !m_ratio)
+        if ( (m_flag & wxSHAPED) && wxIsNullDouble(m_ratio) )
             SetRatio(m_minSize);
     }
     else if ( IsWindow() )
@@ -446,7 +447,20 @@ bool wxSizerItem::IsShown() const
             return m_window->IsShown();
 
         case Item_Sizer:
-            return m_sizer->IsShown();
+            // arbitrarily decide that if at least one of our elements is
+            // shown, so are we (this arbitrariness is the reason for
+            // deprecating this function)
+            {
+                for ( wxSizerItemList::compatibility_iterator
+                        node = m_sizer->GetChildren().GetFirst();
+                      node;
+                      node = node->GetNext() )
+                {
+                    if ( node->GetData()->IsShown() )
+                        return true;
+                }
+            }
+            return false;
 
         case Item_Spacer:
             return m_spacer->IsShown();
@@ -459,6 +473,7 @@ bool wxSizerItem::IsShown() const
     return false;
 }
 
+#if WXWIN_COMPATIBILITY_2_6
 void wxSizerItem::SetOption( int option )
 {
     SetProportion( option );
@@ -468,17 +483,13 @@ int wxSizerItem::GetOption() const
 {
     return GetProportion();
 }
+#endif // WXWIN_COMPATIBILITY_2_6
 
 
 //---------------------------------------------------------------------------
 // wxSizer
 //---------------------------------------------------------------------------
 
-wxSizer::wxSizer()
-{
-    m_isShown = true;
-}
-
 wxSizer::~wxSizer()
 {
     WX_CLEAR_LIST(wxSizerItemList, m_children);
@@ -494,10 +505,12 @@ wxSizerItem* wxSizer::Insert( size_t index, wxSizerItem *item )
     return item;
 }
 
+#if WXWIN_COMPATIBILITY_2_6
 bool wxSizer::Remove( wxWindow *window )
 {
     return Detach( window );
 }
+#endif // WXWIN_COMPATIBILITY_2_6
 
 bool wxSizer::Remove( wxSizer *sizer )
 {
@@ -719,6 +732,15 @@ wxSize wxSizer::GetMinWindowSize( wxWindow *window )
 // Return a window size that will fit within the screens dimensions
 wxSize wxSizer::FitSize( wxWindow *window )
 {
+    if ( window->IsTopLevel() )
+    {
+        wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
+        if ( tlw && tlw->IsAlwaysMaximized() )
+        {
+            return tlw->GetClientSize();
+        }
+    }
+
     wxSize size     = GetMinWindowSize( window );
     wxSize sizeMax  = GetMaxWindowSize( window );
 
@@ -1323,10 +1345,12 @@ void wxFlexGridSizer::AdjustForFlexDirection()
         wxArrayInt& array = m_flexDirection == wxVERTICAL ? m_colWidths
                                                           : m_rowHeights;
 
-        const int count = array.GetCount();
+        const size_t count = array.GetCount();
 
         // find the largest value in this array
-        int n, largest = 0;
+        size_t n;
+        int largest = 0;
+
         for ( n = 0; n < count; ++n )
         {
             if ( array[n] > largest )
@@ -1673,16 +1697,27 @@ 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);
+}
+
+wxStaticBoxSizer::~wxStaticBoxSizer()
+{
+    delete m_staticBox;
 }
 
 static void GetStaticBoxBorders( wxStaticBox *box,
@@ -1732,6 +1767,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
@@ -1932,12 +1981,16 @@ IMPLEMENT_CLASS(wxNotebookSizer, wxBookCtrlSizer)
 
 #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 );
@@ -1983,12 +2036,16 @@ wxSize wxBookCtrlSizer::CalcMin()
 
 #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