X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e7bc14b51c0f4441f31be92c214bc93bce0a11d..d230488b29e48d130a8883215db18fbd92daf48c:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 6030fd9f20..cc81970cb5 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 @@ -861,10 +862,7 @@ wxSize wxSizer::Fit( wxWindow *window ) 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; + sizeMax = tlw->WindowToClientSize(sizeMax); } else { @@ -876,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(); @@ -909,12 +921,16 @@ void wxSizer::SetSizeHints( wxWindow *window ) // Preserve the window's max size hints, but set the // lower bound according to the sizer calculations. - wxSize size = Fit( window ); + // This is equivalent to calling Fit(), except that we need to set + // the size hints _in between_ the two steps performed by Fit + // (1. ComputeFittingClientSize, 2. SetClientSize). That's because + // otherwise SetClientSize() could have no effect if there already are + // size hints in effect that forbid requested client size. + + const wxSize clientSize = ComputeFittingClientSize(window); - window->SetSizeHints( size.x, - size.y, - window->GetMaxWidth(), - window->GetMaxHeight() ); + window->SetMinClientSize(clientSize); + window->SetClientSize(clientSize); } #if WXWIN_COMPATIBILITY_2_8 @@ -924,38 +940,12 @@ void wxSizer::SetVirtualSizeHints( wxWindow *window ) } #endif // WXWIN_COMPATIBILITY_2_8 -wxSize wxSizer::GetMaxWindowSize( wxWindow *window ) const -{ - return window->GetMaxSize(); -} - -wxSize wxSizer::GetMinWindowSize( wxWindow *window ) -{ - wxSize minSize( GetMinSize() ); - wxSize size( window->GetSize() ); - wxSize client_size( window->GetClientSize() ); - - return wxSize( minSize.x+size.x-client_size.x, - minSize.y+size.y-client_size.y ); -} - // TODO on mac we need a function that determines how much free space this // min size contains, in order to make sure that we have 20 pixels of free // space around the controls wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const { - wxSize maxSize( window->GetMaxSize() ); - - if ( maxSize != wxDefaultSize ) - { - wxSize size( window->GetSize() ); - wxSize client_size( window->GetClientSize() ); - - return wxSize( maxSize.x + client_size.x - size.x, - maxSize.y + client_size.y - size.y ); - } - else - return wxDefaultSize; + return window->WindowToClientSize(window->GetMaxSize()); } wxSize wxSizer::GetMinClientSize( wxWindow *WXUNUSED(window) )