wxSizer::Fit() now sets client size

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2008-01-13 13:08:30 +00:00
parent 1fd012c366
commit c30199bfdd
2 changed files with 43 additions and 25 deletions

View File

@@ -222,13 +222,11 @@ Returns true if the child item was found and detached, false otherwise.
\func{wxSize}{Fit}{\param{wxWindow* }{window}} \func{wxSize}{Fit}{\param{wxWindow* }{window}}
Tell the sizer to resize the \arg{window} to match the sizer's minimal size. This Tell the sizer to resize the \arg{window} so that its client area matchesthe
is commonly done in the constructor of the window itself, see sample in the description sizer's minimal size. 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 size.
For a top level window this is the total window size, not client size.
\membersection{wxSizer::FitInside}\label{wxsizerfitinside} \membersection{wxSizer::FitInside}\label{wxsizerfitinside}
\func{void}{FitInside}{\param{wxWindow* }{window}} \func{void}{FitInside}{\param{wxWindow* }{window}}

View File

@@ -838,7 +838,6 @@ wxSize wxSizer::Fit( wxWindow *window )
{ {
// take the min size by default and limit it by max size // take the min size by default and limit it by max size
wxSize size = GetMinWindowSize(window); wxSize size = GetMinWindowSize(window);
wxSize sizeMax = GetMaxWindowSize(window);
wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow); wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
if ( tlw ) if ( tlw )
@@ -846,31 +845,52 @@ wxSize wxSizer::Fit( wxWindow *window )
// hack for small screen devices where TLWs are always full screen // hack for small screen devices where TLWs are always full screen
if ( tlw->IsAlwaysMaximized() ) if ( tlw->IsAlwaysMaximized() )
{ {
size = tlw->GetSize(); // do nothing
return tlw->GetSize();
} }
else // normal situation
// limit the window to the size of the display it is on
int disp = wxDisplay::GetFromWindow(window);
if ( disp == wxNOT_FOUND )
{ {
// limit the window to the size of the display it is on // or, if we don't know which one it is, of the main one
int disp = wxDisplay::GetFromWindow(window); disp = 0;
if ( disp == wxNOT_FOUND )
{
// or, if we don't know which one it is, of the main one
disp = 0;
}
sizeMax = wxDisplay(disp).GetClientArea().GetSize();
} }
wxSize sizeMax = wxDisplay(disp).GetClientArea().GetSize();
// space for decorations and toolbars etc.
wxSize tlw_client_size = tlw->GetClientSize();
wxSize tlw_size = tlw->GetSize();
sizeMax.x -= tlw_size.x - tlw_client_size.x;
sizeMax.y -= tlw_size.y - tlw_client_size.y;
if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x )
size.x = sizeMax.x;
if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
size.y = sizeMax.y;
// set client size
tlw->SetClientSize( size );
// return entire size
return tlw->GetSize();
} }
else
{
wxSize sizeMax = GetMaxWindowSize(window);
if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x )
size.x = sizeMax.x;
if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
size.y = sizeMax.y;
if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x ) // set client size
size.x = sizeMax.x; window->SetClientSize( size );
if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
size.y = sizeMax.y;
// return entire size
window->SetSize( size ); return window->GetSize();
}
return size;
} }
void wxSizer::FitInside( wxWindow *window ) void wxSizer::FitInside( wxWindow *window )