]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wincmn.cpp
applied patch 939076: __SMARTPHONE__ define
[wxWidgets.git] / src / common / wincmn.cpp
index 031974f07248211e8d0cf4b40894f988385c2f86..6b6b35ab28ef78aa878c10b1df26ecef889a161d 100644 (file)
@@ -110,12 +110,13 @@ END_EVENT_TABLE()
 
 // the default initialization
 wxWindowBase::wxWindowBase()
-:   m_bestSize(wxDefaultSize)
 {
     // no window yet, no parent nor children
     m_parent = (wxWindow *)NULL;
     m_windowId = wxID_ANY;
 
+    m_initialSize = wxDefaultSize;
+    
     // no constraints on the minimal window size
     m_minWidth =
     m_minHeight =
@@ -223,13 +224,9 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent,
     SetWindowStyleFlag(style);
     SetParent(parent);
 
-    // Set the minsize to be the size passed to the ctor (if any) for
-    // non-TLWs.  This is so items used in a sizer will use this explicitly
-    // set size for layout, instead of falling back the (probably smaller)
-    // bestsize.
-    if (! IsTopLevel())
-        SetSizeHints(size);
-
+    // Save the size passed to the ctor (if any.)  This will be used later as
+    // the minimal size if the window is added to a sizer.
+    m_initialSize = size;
     
 #if wxUSE_VALIDATORS
     SetValidator(validator);
@@ -545,9 +542,9 @@ wxSize wxWindowBase::DoGetBestSize() const
         return wxSize(maxX, maxY);
     }
 #endif // wxUSE_CONSTRAINTS
-    else if ( GetChildren().GetCount() > 0 )
+    else if ( !GetChildren().empty() )
     {
-        // our minimal acceptable size is such that all our windows fit inside
+        // our minimal acceptable size is such that all our visible child windows fit inside
         int maxX = 0,
             maxY = 0;
 
@@ -556,7 +553,7 @@ wxSize wxWindowBase::DoGetBestSize() const
               node = node->GetNext() )
         {
             wxWindow *win = node->GetData();
-            if ( win->IsTopLevel()
+            if ( win->IsTopLevel()  || ( ! win->IsShown() )
 #if wxUSE_STATUSBAR
                     || wxDynamicCast(win, wxStatusBar)
 #endif // wxUSE_STATUSBAR
@@ -592,20 +589,14 @@ wxSize wxWindowBase::DoGetBestSize() const
 
         return wxSize(maxX, maxY);
     }
-    else
+    else // ! has children
     {
-        // Windows which don't implement DoGetBestSize and aren't parents.
-        // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
-
-        // If you get the following message you should do one of two things
-        // 1. Do what it says (best)
-        // 2. m_bestSize = GetSize() at end of Create() (hack)
-        if(m_bestSize == wxDefaultSize)
-        {
-            wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
-            wxConstCast(this,wxWindowBase)->m_bestSize = GetSize();
-        }
-        return m_bestSize;
+        // for a generic window there is no natural best size - just use either the
+        // minimum size if there is one, or the current size
+        if ( GetMinSize().IsFullySpecified() )
+            return GetMinSize();
+        else
+            return GetSize();
     }
 }
 
@@ -890,7 +881,7 @@ bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
 
 void wxWindowBase::InheritAttributes()
 {
-    const wxWindow * const parent = GetParent();
+    const wxWindowBase * const parent = GetParent();
     if ( !parent )
         return;
 
@@ -1637,6 +1628,26 @@ void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
     sizer->SetSizeHints( (wxWindow*) this );
 }
 
+   
+void wxWindowBase::SetContainingSizer(wxSizer* sizer)
+{
+    // adding a window to a sizer twice is going to result in fatal and
+    // hard to debug problems later because when deleting the second
+    // associated wxSizerItem we're going to dereference a dangling
+    // pointer; so try to detect this as early as possible
+    wxASSERT_MSG( !sizer || m_containingSizer != sizer,
+                  _T("Adding a window to the same sizer twice?") );
+    
+    m_containingSizer = sizer;
+
+    // If there was an initial size for this window, and if a minsize has not
+    // been set, then set the initial size as the minsize.  This helps with
+    // sizer layout when a larger than GetBestSize size is needed for
+    // controls.
+    if (m_initialSize != wxDefaultSize && GetMinSize() == wxDefaultSize)
+        SetSizeHints(m_initialSize);
+}
+   
 #if wxUSE_CONSTRAINTS
 
 void wxWindowBase::SatisfyConstraints()