From 175363f6b89e94e6d5f7dc39235fbc3f2989d763 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Mar 2010 23:55:19 +0000 Subject: [PATCH] Implement wxBookCtrlBase::CalcSizeFromPage() in the base class. The definition of this method was needlessly duplicated in all of wx{Choice,List,Tool,Tree}book and in all of them except the first one it didn't account correctly for the case when the size of the controller was greater than the size of the page. Avoid the duplication and fix the best size determination in such case by providing a single, correct version of the function in the base class itself. Closes #11793. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63632 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/bookctrl.h | 5 ++++- include/wx/choicebk.h | 1 - include/wx/listbook.h | 1 - include/wx/toolbook.h | 1 - include/wx/treebook.h | 1 - src/common/bookctrl.cpp | 22 ++++++++++++++++++++++ src/generic/choicbkg.cpp | 27 --------------------------- src/generic/listbkg.cpp | 18 ------------------ src/generic/toolbkg.cpp | 18 ------------------ src/generic/treebkg.cpp | 10 ---------- 10 files changed, 26 insertions(+), 78 deletions(-) diff --git a/include/wx/bookctrl.h b/include/wx/bookctrl.h index fbb493ebe5..66704cb9a1 100644 --- a/include/wx/bookctrl.h +++ b/include/wx/bookctrl.h @@ -141,7 +141,10 @@ public: wxSize GetControllerSize() const; // calculate the size of the control from the size of its page - virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; + // + // by default this simply returns size enough to fit both the page and the + // controller + virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; // get/set size of area between book control area and page area unsigned int GetInternalBorder() const { return m_internalBorder; } diff --git a/include/wx/choicebk.h b/include/wx/choicebk.h index ed7ff2bd7c..76a0387392 100644 --- a/include/wx/choicebk.h +++ b/include/wx/choicebk.h @@ -70,7 +70,6 @@ public: virtual wxString GetPageText(size_t n) const; virtual int GetPageImage(size_t n) const; virtual bool SetPageImage(size_t n, int imageId); - virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; virtual bool InsertPage(size_t n, wxWindow *page, const wxString& text, diff --git a/include/wx/listbook.h b/include/wx/listbook.h index b1fb9a73a8..a4d1d31c17 100644 --- a/include/wx/listbook.h +++ b/include/wx/listbook.h @@ -71,7 +71,6 @@ public: virtual wxString GetPageText(size_t n) const; virtual int GetPageImage(size_t n) const; virtual bool SetPageImage(size_t n, int imageId); - virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; virtual bool InsertPage(size_t n, wxWindow *page, const wxString& text, diff --git a/include/wx/toolbook.h b/include/wx/toolbook.h index 52e1de2a7e..c35c4c7ab1 100644 --- a/include/wx/toolbook.h +++ b/include/wx/toolbook.h @@ -75,7 +75,6 @@ public: virtual wxString GetPageText(size_t n) const; virtual int GetPageImage(size_t n) const; virtual bool SetPageImage(size_t n, int imageId); - virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; virtual bool InsertPage(size_t n, wxWindow *page, const wxString& text, diff --git a/include/wx/treebook.h b/include/wx/treebook.h index c9b9b625e0..db31922384 100644 --- a/include/wx/treebook.h +++ b/include/wx/treebook.h @@ -131,7 +131,6 @@ public: virtual wxString GetPageText(size_t n) const; virtual int GetPageImage(size_t n) const; virtual bool SetPageImage(size_t n, int imageId); - virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; virtual int SetSelection(size_t n) { return DoSetSelection(n, SetSelection_SendEvent); } virtual int ChangeSelection(size_t n) { return DoSetSelection(n); } virtual int HitTest(const wxPoint& pt, long *flags = NULL) const; diff --git a/src/common/bookctrl.cpp b/src/common/bookctrl.cpp index da06cdafeb..cfc13b78a3 100644 --- a/src/common/bookctrl.cpp +++ b/src/common/bookctrl.cpp @@ -137,6 +137,28 @@ void wxBookCtrlBase::DoInvalidateBestSize() wxControl::InvalidateBestSize(); } +wxSize wxBookCtrlBase::CalcSizeFromPage(const wxSize& sizePage) const +{ + // we need to add the size of the choice control and the border between + const wxSize sizeController = GetControllerSize(); + + wxSize size = sizePage; + if ( IsVertical() ) + { + if ( sizeController.x > sizePage.x ) + size.x = sizeController.x; + size.y += sizeController.y + GetInternalBorder(); + } + else // left/right aligned + { + size.x += sizeController.x + GetInternalBorder(); + if ( sizeController.y > sizePage.y ) + size.y = sizeController.y; + } + + return size; +} + void wxBookCtrlBase::SetPageSize(const wxSize& size) { SetClientSize(CalcSizeFromPage(size)); diff --git a/src/generic/choicbkg.cpp b/src/generic/choicbkg.cpp index 724c0a4215..5687ef5c09 100644 --- a/src/generic/choicbkg.cpp +++ b/src/generic/choicbkg.cpp @@ -111,33 +111,6 @@ wxChoicebook::Create(wxWindow *parent, return true; } -// ---------------------------------------------------------------------------- -// wxChoicebook geometry management -// ---------------------------------------------------------------------------- - -wxSize wxChoicebook::CalcSizeFromPage(const wxSize& sizePage) const -{ - // we need to add the size of the choice control and the border between - const wxSize sizeChoice = GetControllerSize(); - - wxSize size = sizePage; - if ( IsVertical() ) - { - if ( sizeChoice.x > sizePage.x ) - size.x = sizeChoice.x; - size.y += sizeChoice.y + GetInternalBorder(); - } - else // left/right aligned - { - size.x += sizeChoice.x + GetInternalBorder(); - if ( sizeChoice.y > sizePage.y ) - size.y = sizeChoice.y; - } - - return size; -} - - // ---------------------------------------------------------------------------- // accessing the pages // ---------------------------------------------------------------------------- diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index 5df5de104a..f829305777 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -208,24 +208,6 @@ int wxListbook::HitTest(const wxPoint& pt, long *flags) const return pagePos; } -wxSize wxListbook::CalcSizeFromPage(const wxSize& sizePage) const -{ - // we need to add the size of the list control and the border between - const wxSize sizeList = GetControllerSize(); - - wxSize size = sizePage; - if ( IsVertical() ) - { - size.y += sizeList.y + GetInternalBorder(); - } - else // left/right aligned - { - size.x += sizeList.x + GetInternalBorder(); - } - - return size; -} - void wxListbook::UpdateSize() { // we should find a more elegant way to force a layout than generating this diff --git a/src/generic/toolbkg.cpp b/src/generic/toolbkg.cpp index ae2dbbe36d..b88e45b9cd 100644 --- a/src/generic/toolbkg.cpp +++ b/src/generic/toolbkg.cpp @@ -137,24 +137,6 @@ void wxToolbook::OnSize(wxSizeEvent& event) wxBookCtrlBase::OnSize(event); } -wxSize wxToolbook::CalcSizeFromPage(const wxSize& sizePage) const -{ - // we need to add the size of the list control and the border between - const wxSize sizeToolBar = GetControllerSize(); - - wxSize size = sizePage; - if ( IsVertical() ) - { - size.y += sizeToolBar.y + GetInternalBorder(); - } - else // left/right aligned - { - size.x += sizeToolBar.x + GetInternalBorder(); - } - - return size; -} - // ---------------------------------------------------------------------------- // accessing the pages // ---------------------------------------------------------------------------- diff --git a/src/generic/treebkg.cpp b/src/generic/treebkg.cpp index ab44d27257..5cb6d44cc8 100644 --- a/src/generic/treebkg.cpp +++ b/src/generic/treebkg.cpp @@ -556,16 +556,6 @@ bool wxTreebook::SetPageImage(size_t n, int imageId) return true; } -wxSize wxTreebook::CalcSizeFromPage(const wxSize& sizePage) const -{ - const wxSize sizeTree = GetControllerSize(); - - wxSize size = sizePage; - size.x += sizeTree.x; - - return size; -} - int wxTreebook::GetSelection() const { return m_selection; -- 2.45.2