Add wxWindow::GetBest{Height,Width}().

These functions will be used when it is necessary to determine the best size
of the control if one of its size components is fixed. Currently none of the
classes implements DoGetBestClient{Height,Width}() yet but wxListCtrl will do
it soon, see #13898.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71392 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-05-09 14:24:37 +00:00
parent 386279c3f2
commit d119983947
3 changed files with 88 additions and 0 deletions

View File

@@ -379,6 +379,13 @@ public:
*h = s.y;
}
// Determine the best size in the other direction if one of them is
// fixed. This is used with windows that can wrap their contents and
// returns input-independent best size for the others.
int GetBestHeight(int width) const;
int GetBestWidth(int height) const;
void SetScrollHelper( wxScrollHelper *sh ) { m_scrollHelper = sh; }
wxScrollHelper *GetScrollHelper() { return m_scrollHelper; }
@@ -1687,6 +1694,14 @@ protected:
// (GetBorderSize() will be used to add them)
virtual wxSize DoGetBestClientSize() const { return wxDefaultSize; }
// These two methods can be overridden to implement intelligent
// width-for-height and/or height-for-width best size determination for the
// window. By default the fixed best size is used.
virtual int DoGetBestClientHeight(int WXUNUSED(width)) const
{ return wxDefaultCoord; }
virtual int DoGetBestClientWidth(int WXUNUSED(height)) const
{ return wxDefaultCoord; }
// this is the virtual function to be overridden in any derived class which
// wants to change how SetSize() or Move() works - it is called by all
// versions of these functions in the base class

View File

@@ -827,6 +827,24 @@ public:
*/
wxSize GetBestSize() const;
/**
Returns the best height needed by this window if it had the given width.
@see DoGetBestClientHeight()
@since 2.9.4
*/
int GetBestHeight(int width) const;
/**
Returns the best width needed by this window if it had the given height.
@see DoGetBestClientWidth()
@since 2.9.4
*/
int GetBestWidth(int height) const;
/**
Returns the size of the window 'client area' in pixels.
@@ -3479,6 +3497,43 @@ protected:
*/
virtual wxSize DoGetBestClientSize() const;
/**
Override this method to implement height-for-width best size
calculation.
Return the height needed to fully display the control contents if its
width is fixed to the given value. Custom classes implementing
wrapping should override this method and return the height
corresponding to the number of lines needed to lay out the control
contents at this width.
Currently this method is not used by wxWidgets yet, however it is
planned that it will be used by the new sizer classes implementing
height-for-width layout strategy in the future.
Notice that implementing this method or even implementing both it and
DoGetBestClientWidth() doesn't replace overriding DoGetBestClientSize(),
i.e. you still need to implement the latter as well in order to provide
the best size when neither width nor height are constrained.
By default returns ::wxDefaultCoord meaning that the vertical component
of DoGetBestClientSize() return value should be used.
@since 2.9.4
*/
virtual int DoGetBestClientHeight(int width) const;
/**
Override this method to implement width-for-height best size
calculation.
This method is exactly the same as DoGetBestClientHeight() except that
it determines the width assuming the height is fixed instead of vice
versa.
@since 2.9.4
*/
virtual int DoGetBestClientWidth(int height) const;
/**
Sets the initial window size if none is given (i.e. at least one of the

View File

@@ -916,6 +916,24 @@ wxSize wxWindowBase::GetBestSize() const
return DoGetBestSize();
}
int wxWindowBase::GetBestHeight(int width) const
{
const int height = DoGetBestClientHeight(width);
return height == wxDefaultCoord
? GetBestSize().y
: height + DoGetBorderSize().y;
}
int wxWindowBase::GetBestWidth(int height) const
{
const int width = DoGetBestClientWidth(height);
return width == wxDefaultCoord
? GetBestSize().x
: width + DoGetBorderSize().x;
}
void wxWindowBase::SetMinSize(const wxSize& minSize)
{
m_minWidth = minSize.x;