From 32013b47d64e648373eed7b522f2bf2880aa2f64 Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Wed, 13 Feb 2008 21:32:11 +0000
Subject: [PATCH] split wxSizer::Fit() into ComputeFittingWindow/ClientSize()
 that only does computations and Fit() that applies the result to the window

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/sizer.tex | 60 ++++++++++++++++++++++++++++++++++++++---
 include/wx/sizer.h      |  3 +++
 src/common/sizer.cpp    | 23 +++++++++++++---
 3 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/docs/latex/wx/sizer.tex b/docs/latex/wx/sizer.tex
index 8800335c25..a1e1ef5c64 100644
--- a/docs/latex/wx/sizer.tex
+++ b/docs/latex/wx/sizer.tex
@@ -197,6 +197,44 @@ Here, the sizer will do the actual calculation of its children's minimal sizes.
 Detaches all children from the sizer. If \arg{delete\_windows} is \true then child windows will also be deleted.
 
 
+\membersection{wxSizer::ComputeFittingClientSize}\label{wxsizercomputefittingclientsize}
+
+\func{wxSize}{ComputeFittingClientSize}{\param{wxWindow* }{window}}
+
+Computes client area size for \arg{window} so that it matches the 
+sizer's minimal size. Unlike \helpref{GetMinSize}{wxsizergetminsize}, this
+method accounts for other constraints imposed on \arg{window}, namely display's
+size (returned size will never be too large for the display) and maximum
+window size if previously set by
+\helpref{wxWindow::SetMaxSize}{wxwindowsetmaxsize}.
+
+The returned value is suitable for passing to
+\helpref{wxWindow::SetClientSize}{wxwindowsetclientsize} or
+\helpref{wxWindow::SetMinClientSize}{wxwindowsetminclientsize}.
+
+\wxheading{See also}
+
+\helpref{ComputeFittingWindowSize}{wxsizercomputefittingwindowsize},
+\helpref{Fit}{wxsizerfit}
+
+
+\membersection{wxSizer::ComputeFittintWindowSize}\label{wxsizercomputefittingwindowsize}
+
+\func{wxSize}{ComputeFittingWindowSize}{\param{wxWindow* }{window}}
+
+Like \helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize},
+but converts the result into \emph{window} size.
+
+The returned value is suitable for passing to
+\helpref{wxWindow::SetSize}{wxwindowsetsize} or
+\helpref{wxWindow::SetMinSize}{wxwindowsetminsize}.
+
+\wxheading{See also}
+
+\helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize},
+\helpref{Fit}{wxsizerfit}
+
+
 \membersection{wxSizer::Detach}\label{wxsizerdetach}
 
 \func{bool}{Detach}{\param{wxWindow* }{window}}
@@ -222,10 +260,19 @@ Returns true if the child item was found and detached, false otherwise.
 
 \func{wxSize}{Fit}{\param{wxWindow* }{window}}
 
-Tell the sizer to resize the \arg{window} so that its client area matchesthe 
-sizer's minimal size. This is commonly done in the constructor of the window
+Tell the sizer to resize the \arg{window} so that its client area matches the 
+sizer's minimal size
+(\helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize} is called
+to determine it).
+This is commonly done in the constructor of the window
 itself, see sample in the description
-of \helpref{wxBoxSizer}{wxboxsizer}. Returns the new size.
+of \helpref{wxBoxSizer}{wxboxsizer}. Returns the new \emph{window} size.
+
+\wxheading{See also}
+
+\helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize},
+\helpref{ComputeFittingWindowSize}{wxsizercomputefittingwindowsize}
+
 
 \membersection{wxSizer::FitInside}\label{wxsizerfitinside}
 
@@ -309,6 +356,13 @@ Returns the minimal size of the sizer. This is either the combined minimal
 size of all the children and their borders or the minimal size set by 
 \helpref{SetMinSize}{wxsizersetminsize}, depending on which is bigger.
 
+Note that the returned value is \emph{client} size, not window size.
+In particular, if you use the value to set toplevel window's minimal or
+actual size, use \helpref{wxWindow::SetMinClientSize}{wxwindowsetminclientsize}
+or \helpref{wxWindow::SetClientSize}{wxwindowsetclientsize}, \emph{not}
+\helpref{wxWindow::SetMinSize}{wxwindowsetminsize}
+or \helpref{wxWindow::SetSize}{wxwindowsetsize}.
+
 
 \membersection{wxSizer::Hide}\label{wxsizerhide}
 
diff --git a/include/wx/sizer.h b/include/wx/sizer.h
index 125dd55c7f..9ac8077b7d 100644
--- a/include/wx/sizer.h
+++ b/include/wx/sizer.h
@@ -601,6 +601,9 @@ public:
 
     virtual void Layout();
 
+    wxSize ComputeFittingClientSize(wxWindow *window);
+    wxSize ComputeFittingWindowSize(wxWindow *window);
+
     wxSize Fit( wxWindow *window );
     void FitInside( wxWindow *window );
     void SetSizeHints( wxWindow *window );
diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp
index 7c68b8a405..d080362274 100644
--- a/src/common/sizer.cpp
+++ b/src/common/sizer.cpp
@@ -834,8 +834,10 @@ void wxSizer::DeleteWindows()
     }
 }
 
-wxSize wxSizer::Fit( wxWindow *window )
+wxSize wxSizer::ComputeFittingClientSize(wxWindow *window)
 {
+    wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
+
     // take the min size by default and limit it by max size
     wxSize size = GetMinClientSize(window);
     wxSize sizeMax;
@@ -846,8 +848,7 @@ wxSize wxSizer::Fit( wxWindow *window )
         // hack for small screen devices where TLWs are always full screen
         if ( tlw->IsAlwaysMaximized() )
         {
-            // do nothing
-            return tlw->GetSize();
+            return tlw->GetClientSize();
         }
 
         // limit the window to the size of the display it is on
@@ -873,8 +874,22 @@ wxSize wxSizer::Fit( wxWindow *window )
     if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
             size.y = sizeMax.y;
 
+    return size;
+}
+
+wxSize wxSizer::ComputeFittingWindowSize(wxWindow *window)
+{
+    wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
+
+    return window->ClientToWindowSize(ComputeFittingClientSize(window));
+}
+
+wxSize wxSizer::Fit( wxWindow *window )
+{
+    wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
+
     // set client size
-    window->SetClientSize( size );
+    window->SetClientSize(ComputeFittingClientSize(window));
 
     // return entire size
     return window->GetSize();
-- 
2.45.2

