diff --git a/include/wx/sizer.h b/include/wx/sizer.h index 32cff00a7c..9e378b73f6 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -197,8 +197,10 @@ protected: wxPoint m_position; wxList m_children; + wxSize GetMaxWindowSize( wxWindow *window ); wxSize GetMinWindowSize( wxWindow *window ); - + wxSize FitSize( wxWindow *window ); + virtual void DoSetMinSize( int width, int height ); virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index c49530577e..fd78077c09 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -355,7 +355,8 @@ bool wxSizer::Remove( int pos ) void wxSizer::Fit( wxWindow *window ) { - window->SetSize( GetMinWindowSize( window ) ); + wxSize size = FitSize( window ); + window->SetSize( size ); } void wxSizer::Layout() @@ -366,10 +367,24 @@ void wxSizer::Layout() void wxSizer::SetSizeHints( wxWindow *window ) { - wxSize size( GetMinWindowSize( window ) ); + wxSize size = FitSize( window ); window->SetSizeHints( size.x, size.y ); } +wxSize wxSizer::GetMaxWindowSize( wxWindow *window ) +{ + wxSize sizeMax = wxGetDisplaySize(); + // make the max size a bit smaller than the screen, a window which takes + // the entire screen doesn't look very nice neither + sizeMax.x *= 9; + sizeMax.x /= 10; + + sizeMax.y *= 9; + sizeMax.y /= 10; + + return sizeMax; +} + wxSize wxSizer::GetMinWindowSize( wxWindow *window ) { wxSize minSize( GetMinSize() ); @@ -379,6 +394,20 @@ wxSize wxSizer::GetMinWindowSize( wxWindow *window ) minSize.y+size.y-client_size.y ); } +// Return a window size that will fit within the screens dimensions +wxSize wxSizer::FitSize( wxWindow *window ) +{ + wxSize size = GetMinWindowSize( window ); + wxSize sizeMax = GetMaxWindowSize( window ); + + if ( size.x > sizeMax.x ) + size.x = sizeMax.x; + if ( size.y > sizeMax.y ) + size.y = sizeMax.y; + + return size; +} + void wxSizer::SetDimension( int x, int y, int width, int height ) { m_position.x = x;