From 65ba4113c63f5ad60aa6bb49a70cf893d1d175a3 Mon Sep 17 00:00:00 2001 From: George Tasker Date: Wed, 25 Apr 2001 16:08:22 +0000 Subject: [PATCH] Fixes ::Fit() and ::SetSizeHints() to keep the dialog sized so that it will not grow outside the display area of the screen. NEcessary to fix the problems seen in wxAnyChoiceDialog() derived classes where the dialog grows too big to see the top or bottom of the dialog git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9876 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/sizer.h | 4 +++- src/common/sizer.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) 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;