* Implemented BestSize cache

* Added calls to InvalidateBestSize where things affecting BestSize
  are modified.  There are probably several other places where this
  still needs to be done...

* Added wxWindowBase::GetBestFittingSize that will merge the BestSize
  into the MinSize, (if any) and return the result.

* SetBestFittingSize will now only set the MinSize to the value that
  was passed to it, without merging in the BestSize


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-06-24 20:09:45 +00:00
parent cf82b73a0a
commit 9f88452895
55 changed files with 260 additions and 105 deletions

View File

@@ -125,6 +125,9 @@ wxWindowBase::wxWindowBase()
m_minHeight =
m_maxHeight = wxDefaultSize.y;
// invalidiated cache value
m_bestSizeCache = wxDefaultSize;
// window are created enabled and visible by default
m_isShown =
m_isEnabled = true;
@@ -482,7 +485,7 @@ void wxWindowBase::Fit()
{
if ( GetChildren().GetCount() > 0 )
{
SetClientSize(DoGetBestSize());
SetClientSize(GetBestSize());
}
//else: do nothing if we have no children
}
@@ -620,32 +623,36 @@ wxSize wxWindowBase::DoGetBestSize() const
}
}
wxSize wxWindowBase::GetBestFittingSize() const
{
// merge the best size with the min size, giving priority to the min size
wxSize min = GetMinSize();
if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
{
wxSize best = GetBestSize();
if (min.x == wxDefaultCoord) min.x = best.x;
if (min.y == wxDefaultCoord) min.y = best.y;
}
return min;
}
void wxWindowBase::SetBestFittingSize(const wxSize& size)
{
// If the given size is incomplete then merge with the best size.
wxSize sizeBest;
if ( size.x == wxDefaultSize.x || size.y == wxDefaultSize.y )
{
sizeBest = DoGetBestSize();
if ( size.x != wxDefaultSize.x )
sizeBest.x = size.x;
if ( size.y != wxDefaultSize.y )
sizeBest.y = size.y;
}
else // have complete explicit size
{
sizeBest = size;
}
// Set the min size to the size passed in. This will usually either be
// wxDefaultSize or the size passed to this window's ctor/Create function.
SetMinSize(size);
// Change the size if needed
if (GetSize() != sizeBest)
SetSize(sizeBest);
// don't shrink the control below its best size
m_minWidth = sizeBest.x;
m_minHeight = sizeBest.y;
// Merge the size with the best size if needed
wxSize best = GetBestFittingSize();
// If the current size doesn't match then change it
if (GetSize() != best)
SetSize(best);
}
// by default the origin is not shifted
wxPoint wxWindowBase::GetClientAreaOrigin() const
{