From: Vadim Zeitlin Date: Sun, 22 Oct 2006 23:27:10 +0000 (+0000) Subject: avoid code duplication between the generic and GTK versions, factor the common code... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4223cec504c3699f5986f5b6b8e9fd42e7fea6b2 avoid code duplication between the generic and GTK versions, factor the common code out in OnStateChange() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42264 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/collpaneg.h b/include/wx/generic/collpaneg.h index b58bf5a395..841f2187f6 100644 --- a/include/wx/generic/collpaneg.h +++ b/include/wx/generic/collpaneg.h @@ -71,6 +71,10 @@ public: virtual wxString GetLabel() const { return m_strLabel; } + + // implementation only, don't use + void OnStateChange(const wxSize& sizeNew); + protected: // overridden methods virtual wxSize DoGetBestSize() const; diff --git a/src/generic/collpaneg.cpp b/src/generic/collpaneg.cpp index 962ccce105..cded9aef40 100644 --- a/src/generic/collpaneg.cpp +++ b/src/generic/collpaneg.cpp @@ -102,21 +102,9 @@ 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); @@ -157,6 +145,22 @@ void wxGenericCollapsiblePane::Collapse(bool collapse) } } +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; diff --git a/src/gtk/collpane.cpp b/src/gtk/collpane.cpp index 9bd6522d51..edd737d066 100644 --- a/src/gtk/collpane.cpp +++ b/src/gtk/collpane.cpp @@ -72,33 +72,7 @@ static void gtk_collapsiblepane_expanded_callback (GObject *object, sz = p->m_szCollapsed; } - // minimal size has priority over the best size so set here our min size - p->SetMinSize(sz); - p->SetSize(sz); - - wxWindow *top = wxGetTopLevelParent(p); - if (top) - { - // we've changed our size, thus our top level parent needs to relayout - // itself - top->Layout(); - - if (p->IsExpanded()) - { - // force our parent to "fit", i.e. expand so that it can honour - // our minimal size - top->Fit(); - } - else // correctly - { - if (top->GetSizer()) - top->GetSizer()->SetSizeHints(top); - - // use SetClientSize() and not SetSize() otherwise the size for - // e.g. a wxFrame with a menubar wouldn't be correctly set - top->SetClientSize(sz); - } - } + p->OnStateChange(sz); if ( p->m_bIgnoreNextChange ) {