From: Robin Dunn Date: Thu, 3 Feb 2005 22:11:43 +0000 (+0000) Subject: Include the size of any window borders (size vs. clientsize X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/08a19f640784b2b3e3ffb703f40d7203f7510201?ds=inline Include the size of any window borders (size vs. clientsize differences) in the window's bestsize git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 4b721d0da3..758ab40742 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -39,6 +39,11 @@ All: - wxGetPowerType() and wxGetBatteryState() addition - wxSystemSettings::GetSystem*() members deprecated and replaced with wxSystemSettings::Get*() +- wxWindowBase::DoGetBestSize now includes the difference (if any) between + the client size and total size of the window. Code that sets the + client size using the best size, or that added extra space to sizers + to compensate for this bug may need to be changed. + All (GUI): diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 1f67899546..29a9fa8402 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -508,7 +508,7 @@ void wxWindowBase::Fit() { if ( GetChildren().GetCount() > 0 ) { - SetClientSize(GetBestSize()); + SetSize(GetBestSize()); } //else: do nothing if we have no children } @@ -553,9 +553,11 @@ void wxWindowBase::InvalidateBestSize() // return the size best suited for the current window wxSize wxWindowBase::DoGetBestSize() const { + wxSize best; + if ( m_windowSizer ) { - return m_windowSizer->GetMinSize(); + best = m_windowSizer->GetMinSize(); } #if wxUSE_CONSTRAINTS else if ( m_constraints ) @@ -591,7 +593,7 @@ wxSize wxWindowBase::DoGetBestSize() const // will never return a size bigger than the current one :-( } - return wxSize(maxX, maxY); + best = wxSize(maxX, maxY); } #endif // wxUSE_CONSTRAINTS else if ( !GetChildren().empty() @@ -643,17 +645,25 @@ wxSize wxWindowBase::DoGetBestSize() const maxX += 7; maxY += 14; - return wxSize(maxX, maxY); + best = wxSize(maxX, maxY); } else // ! has children { - // for a generic window there is no natural best size - just use either the - // minimum size if there is one, or the current size + // For a generic window there is no natural best size - just use + // either the minimum size if there is one, or the current size. + // These are returned as-is, unadjusted by the client size difference. if ( GetMinSize().IsFullySpecified() ) return GetMinSize(); else return GetSize(); } + + // Add any difference between size and client size + wxSize diff = GetSize() - GetClientSize(); + best.x += wxMax(0, diff.x); + best.y += wxMax(0, diff.y); + + return best; }