diff --git a/docs/changes.txt b/docs/changes.txt index 4a9e3d9b9d..a274b25064 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -121,6 +121,7 @@ All (GUI): - Added wxSizerFlags::ReserveSpaceEvenIfHidden() and wxRESERVE_SPACE_EVEN_IF_HIDDEN sizer flag. - Added wxWindow::ClientToWindowSize() and WindowToClientSize() helpers. +- Added wxSizer::ComputeFittingClientSize() and ComputeFittingWindowSize(). All (Unix): diff --git a/docs/latex/wx/sizer.tex b/docs/latex/wx/sizer.tex index db206cb654..7d721b05fb 100644 --- a/docs/latex/wx/sizer.tex +++ b/docs/latex/wx/sizer.tex @@ -197,6 +197,48 @@ Here, the sizer will do the actual calculation of its children 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}. + +\since{2.8.8} + +\wxheading{See also} + +\helpref{ComputeFittingWindowSize}{wxsizercomputefittingwindowsize}, +\helpref{Fit}{wxsizerfit} + + +\membersection{wxSizer::ComputeFittingWindowSize}\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}. + +\since{2.8.8} + +\wxheading{See also} + +\helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize}, +\helpref{Fit}{wxsizerfit} + + \membersection{wxSizer::Detach}\label{wxsizerdetach} \func{bool}{Detach}{\param{wxWindow* }{window}} @@ -228,6 +270,11 @@ of \helpref{wxBoxSizer}{wxboxsizer}. Returns the new size. For a top level window this is the total window size, not client size. +\wxheading{See also} + +\helpref{ComputeFittingClientSize}{wxsizercomputefittingclientsize}, +\helpref{ComputeFittingWindowSize}{wxsizercomputefittingwindowsize} + \membersection{wxSizer::FitInside}\label{wxsizerfitinside} @@ -297,6 +344,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 94bae3bb6e..8cba219c6f 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -562,6 +562,11 @@ public: virtual void Layout(); +#if wxABI_VERSION >= 20808 + wxSize ComputeFittingClientSize(wxWindow *window); + wxSize ComputeFittingWindowSize(wxWindow *window); +#endif + 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 81ae4cabf6..de4b8c3bdb 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -809,7 +809,7 @@ void wxSizer::DeleteWindows() } } -wxSize wxSizer::Fit( wxWindow *window ) +wxSize wxSizer::ComputeFittingWindowSize(wxWindow *window) { // take the min size by default and limit it by max size wxSize size = GetMinWindowSize(window); @@ -842,9 +842,20 @@ wxSize wxSizer::Fit( wxWindow *window ) if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y ) size.y = sizeMax.y; + return size; +} - window->SetSize( size ); +wxSize wxSizer::ComputeFittingClientSize(wxWindow *window) +{ + wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" ); + return window->WindowToClientSize(ComputeFittingWindowSize(window)); +} + +wxSize wxSizer::Fit( wxWindow *window ) +{ + wxSize size = ComputeFittingWindowSize(window); + window->SetSize(size); return size; } diff --git a/version-script.in b/version-script.in index 6a250aa781..5948e7915c 100644 --- a/version-script.in +++ b/version-script.in @@ -37,6 +37,8 @@ *wxRichTextCtrl*SetTextCursor*; *wxRichTextCtrl*SetURLCursor*; *wxScrollHelper*HandleOnChildFocus*; + *wxSizer*ComputeFittingClientSize*; + *wxSizer*ComputeFittingWindowSize*; *wxSizerFlags*ReserveSpaceEvenIfHidden*; *wxSizerItem*ShouldAccountFor*; *wxWindowBase*ClientToWindowSize*;