#pragma hdrstop
#endif
+#include "wx/display.h"
#include "wx/sizer.h"
#ifndef WX_PRECOMP
#include "wx/math.h"
#include "wx/utils.h"
#include "wx/settings.h"
+ #include "wx/button.h"
#include "wx/statbox.h"
+ #include "wx/toplevel.h"
#endif // WX_PRECOMP
#include "wx/listimpl.cpp"
{
// Since the size of the window may change during runtime, we
// should use the current minimal/best size.
- m_minSize = m_window->GetBestFittingSize();
+ m_minSize = m_window->GetEffectiveMinSize();
}
return GetMinSizeWithBorder();
size.y -= m_border;
}
+ if (size.x < 0)
+ size.x = 0;
+ if (size.y < 0)
+ size.y = 0;
+
m_rect = wxRect(pos, size);
switch ( m_kind )
return item;
}
+void wxSizer::SetContainingWindow(wxWindow *win)
+{
+ if ( win == m_containingWindow )
+ return;
+
+ m_containingWindow = win;
+
+ // set the same window for all nested sizers as well, they also are in the
+ // same window
+ for ( wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ wxSizerItem *const item = node->GetData();
+ wxSizer *const sizer = item->GetSizer();
+
+ if ( sizer )
+ {
+ sizer->SetContainingWindow(win);
+ }
+ }
+}
+
#if WXWIN_COMPATIBILITY_2_6
bool wxSizer::Remove( wxWindow *window )
{
if (item->GetSizer()->Replace( oldwin, newwin, true ))
return true;
}
-
+
node = node->GetNext();
}
{
if (item->GetSizer()->Replace( oldsz, newsz, true ))
return true;
- }
-
+ }
+
node = node->GetNext();
}
wxSizerItem *item = node->GetData();
node->SetData(newitem);
- delete item;
+ delete item;
return true;
}
wxSize wxSizer::Fit( wxWindow *window )
{
- wxSize size(window->IsTopLevel() ? FitSize(window)
- : GetMinWindowSize(window));
+ // take the min size by default and limit it by max size
+ wxSize size = GetMinWindowSize(window);
+ wxSize sizeMax = GetMaxWindowSize(window);
+
+ wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
+ if ( tlw )
+ {
+ // hack for small screen devices where TLWs are always full screen
+ if ( tlw->IsAlwaysMaximized() )
+ {
+ size = 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 )
+ {
+ // or, if we don't know which one it is, of the main one
+ disp = 0;
+ }
+
+ sizeMax = wxDisplay(disp).GetClientArea().GetSize();
+ }
+ }
+
+ if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x )
+ size.x = sizeMax.x;
+ if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y )
+ size.y = sizeMax.y;
+
window->SetSize( size );
// 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
-
-// Return a window size that will fit within the screens dimensions
-wxSize wxSizer::FitSize( wxWindow *window )
-{
- if ( window->IsTopLevel() )
- {
- wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow);
- if ( tlw && tlw->IsAlwaysMaximized() )
- {
- return tlw->GetClientSize();
- }
- }
-
- wxSize size = GetMinWindowSize( window );
- wxSize sizeMax = GetMaxWindowSize( window );
-
- // Limit the size if sizeMax != wxDefaultSize
-
- if ( size.x > sizeMax.x && sizeMax.x != wxDefaultCoord )
- size.x = sizeMax.x;
- if ( size.y > sizeMax.y && sizeMax.y != wxDefaultCoord )
- size.y = sizeMax.y;
-
- return size;
-}
-
wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const
{
wxSize maxSize( window->GetMaxSize() );
// wxALIGN_CENTER should be used in new code
child_pos.y += (m_size.y - size.y) / 2;
+ if ( m_containingWindow )
+ {
+ child_pos.x = m_containingWindow->AdjustForLayoutDirection
+ (
+ child_pos.x,
+ width,
+ m_size.x
+ );
+ }
+
item->SetDimension( child_pos, child_size );
pt.x += width;