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
This commit is contained in:
Vadim Zeitlin 2010-03-05 23:55:19 +00:00
parent 76680db44a
commit 175363f6b8
10 changed files with 26 additions and 78 deletions

View File

@ -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; }

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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));

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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;