]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/collpaneg.cpp
Factor the brush selection out of OnPaint so it can be overridden in
[wxWidgets.git] / src / generic / collpaneg.cpp
index 962ccce1056210e4ab20bfa7949ae4080617c10b..0211001b9218ed396963786603ef1d6708050c38 100644 (file)
@@ -19,6 +19,7 @@
 
 #ifndef WX_PRECOMP
     #include "wx/button.h"
+    #include "wx/sizer.h"
 #endif // !WX_PRECOMP
 
 #include "wx/collpane.h"
@@ -102,26 +103,15 @@ wxString wxGenericCollapsiblePane::GetBtnLabel() const
     return m_strLabel + (IsCollapsed() ? wxT(" >>") : wxT(" <<"));
 }
 
-void wxGenericCollapsiblePane::Collapse(bool collapse)
+void wxGenericCollapsiblePane::OnStateChange(const wxSize& sz)
 {
-    // optimization
-    if ( IsCollapsed() == collapse )
-        return;
-
-    // update our state
-    m_pPane->Show(!collapse);
-
-    // update button label
-    // NB: this must be done after updating our "state"
-    m_pButton->SetLabel(GetBtnLabel());
-
     // minimal size has priority over the best size so set here our min size
-    wxSize sz = GetBestSize();
     SetMinSize(sz);
     SetSize(sz);
 
-    wxWindow *top = wxGetTopLevelParent(this);
-    if (top)
+    wxTopLevelWindow *
+        top = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    if ( top )
     {
         // we've changed our size, thus our top level parent needs to relayout
         // itself
@@ -142,21 +132,42 @@ void wxGenericCollapsiblePane::Collapse(bool collapse)
 #endif
             top->GetSizer()->SetSizeHints(top);
 
-        if (IsCollapsed())
-        {
-            // use SetClientSize() and not SetSize() otherwise the size for
-            // e.g. a wxFrame with a menubar wouldn't be correctly set
-            top->SetClientSize(sz);
-        }
-        else
+
+        // we shouldn't attempt to resize a maximized window, whatever happens
+        if ( !top->IsMaximized() )
         {
-            // force our parent to "fit", i.e. expand so that it can honour
-            // our minimal size
-            top->Fit();
+            if ( IsCollapsed() )
+            {
+                // use SetClientSize() and not SetSize() otherwise the size for
+                // e.g. a wxFrame with a menubar wouldn't be correctly set
+                top->SetClientSize(sz);
+            }
+            else
+            {
+                // force our parent to "fit", i.e. expand so that it can honour
+                // our minimal size
+                top->Fit();
+            }
         }
     }
 }
 
+void wxGenericCollapsiblePane::Collapse(bool collapse)
+{
+    // optimization
+    if ( IsCollapsed() == collapse )
+        return;
+
+    // update our state
+    m_pPane->Show(!collapse);
+
+    // update button label
+    // NB: this must be done after updating our "state"
+    m_pButton->SetLabel(GetBtnLabel());
+
+    OnStateChange(GetBestSize());
+}
+
 void wxGenericCollapsiblePane::SetLabel(const wxString &label)
 {
     m_strLabel = label;
@@ -223,4 +234,3 @@ void wxGenericCollapsiblePane::OnSize(wxSizeEvent& WXUNUSED(event))
     // this is very important to make the pane window layout show correctly
     m_pPane->Layout();
 }
-