X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f8845289521c7f53e95b6dfd8275daab8b05639..b6a20a20d010d643e52914f51aa0700df0da925f:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index fb81a60daf..b171d66ae5 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -99,13 +99,16 @@ wxSizerItem::wxSizerItem( int width, int height, int proportion, int flag, int b wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) : m_window( window ) , m_sizer( NULL ) - , m_minSize( window->GetSize() ) // minimal size is the initial size , m_proportion( proportion ) , m_border( border ) , m_flag( flag ) , m_show( true ) , m_userData( userData ) { + if (flag & wxFIXED_MINSIZE) + window->SetMinSize(window->GetSize()); + m_minSize = window->GetSize(); + // aspect ratio calculated from initial size SetRatio( m_minSize ); @@ -177,27 +180,29 @@ wxSize wxSizerItem::GetSize() const wxSize wxSizerItem::CalcMin() { - wxSize ret; if (IsSizer()) { - ret = m_sizer->GetMinSize(); + m_minSize = m_sizer->GetMinSize(); // if we have to preserve aspect ratio _AND_ this is // the first-time calculation, consider ret to be initial size if ((m_flag & wxSHAPED) && !m_ratio) - SetRatio(ret); + SetRatio(m_minSize); } - else + else if ( IsWindow() ) { - if ( IsWindow() && !(m_flag & wxFIXED_MINSIZE) ) - { - // Since the size of the window may change during runtime, we - // should use the current minimal/best size. - m_minSize = m_window->GetBestFittingSize(); - } - ret = m_minSize; + // Since the size of the window may change during runtime, we + // should use the current minimal/best size. + m_minSize = m_window->GetBestFittingSize(); } + return GetMinSizeWithBorder(); +} + +wxSize wxSizerItem::GetMinSizeWithBorder() const +{ + wxSize ret = m_minSize; + if (m_flag & wxWEST) ret.x += m_border; if (m_flag & wxEAST) @@ -206,10 +211,11 @@ wxSize wxSizerItem::CalcMin() ret.y += m_border; if (m_flag & wxSOUTH) ret.y += m_border; - + return ret; } + void wxSizerItem::SetDimension( wxPoint pos, wxSize size ) { if (m_flag & wxSHAPED) @@ -360,6 +366,16 @@ void wxSizer::Add( wxSizerItem *item ) item->GetWindow()->SetContainingSizer( this ); } +void wxSizer::AddSpacer(int size) +{ + Add(size, size); +} + +void wxSizer::AddStretchSpacer(int prop) +{ + Add(0, 0, prop); +} + void wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) { m_children.Insert( new wxSizerItem( window, proportion, flag, border, userData ) ); @@ -384,6 +400,16 @@ void wxSizer::Prepend( wxSizerItem *item ) item->GetWindow()->SetContainingSizer( this ); } +void wxSizer::PrependSpacer(int size) +{ + Prepend(size, size); +} + +void wxSizer::PrependStretchSpacer(int prop) +{ + Prepend(0, 0, prop); +} + void wxSizer::Insert( size_t index, wxWindow *window, int proportion, @@ -427,6 +453,16 @@ void wxSizer::Insert( size_t index, wxSizerItem *item ) item->GetWindow()->SetContainingSizer( this ); } +void wxSizer::InsertSpacer(size_t index, int size) +{ + Insert(index, size, size); +} + +void wxSizer::InsertStretchSpacer(size_t index, int prop) +{ + Insert(index, 0, 0, prop); +} + bool wxSizer::Remove( wxWindow *window ) { return Detach( window ); @@ -596,7 +632,11 @@ void wxSizer::FitInside( wxWindow *window ) void wxSizer::Layout() { + // (re)calculates minimums needed for each item and other preparations + // for layout CalcMin(); + + // Applies the layout and repositions/resizes the items RecalcSizes(); } @@ -811,7 +851,7 @@ bool wxSizer::DoSetItemMinSize( size_t index, int width, int height ) } else { - // ... but the minimal size of spacers and windows in stored in them + // ... but the minimal size of spacers and windows is stored via the item item->SetMinSize( width, height ); } @@ -1032,7 +1072,7 @@ wxSize wxGridSizer::CalcMin() void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) { wxPoint pt( x,y ); - wxSize sz( item->CalcMin() ); + wxSize sz( item->GetMinSizeWithBorder() ); int flag = item->GetFlag(); if ((flag & wxEXPAND) || (flag & wxSHAPED)) @@ -1043,20 +1083,20 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) { if (flag & wxALIGN_CENTER_HORIZONTAL) { - pt.x = x + (w - sz.x - m_hgap) / 2; + pt.x = x + (w - sz.x) / 2; } else if (flag & wxALIGN_RIGHT) { - pt.x = x + (w - sz.x - m_hgap); + pt.x = x + (w - sz.x); } if (flag & wxALIGN_CENTER_VERTICAL) { - pt.y = y + (h - sz.y - m_vgap) / 2; + pt.y = y + (h - sz.y) / 2; } else if (flag & wxALIGN_BOTTOM) { - pt.y = y + (h - sz.y - m_vgap); + pt.y = y + (h - sz.y); } } @@ -1093,9 +1133,8 @@ void wxFlexGridSizer::RecalcSizes() wxPoint pt( GetPosition() ); wxSize sz( GetSize() ); - wxSize minsz( CalcMin() ); - AdjustForGrowables(sz, minsz, nrows, ncols); + AdjustForGrowables(sz, m_calculatedMinSize, nrows, ncols); sz = wxSize( pt.x + sz.x, pt.y + sz.y ); @@ -1180,7 +1219,8 @@ wxSize wxFlexGridSizer::CalcMin() if ( m_rowHeights[ row ] != -1 ) height += m_rowHeights[ row ] + ( row == nrows-1 ? 0 : m_vgap ); - return wxSize( width, height ); + m_calculatedMinSize = wxSize( width, height ); + return m_calculatedMinSize; } void wxFlexGridSizer::AdjustForFlexDirection() @@ -1375,7 +1415,7 @@ void wxBoxSizer::RecalcSizes() if (item->IsShown()) { - wxSize size( item->CalcMin() ); + wxSize size( item->GetMinSizeWithBorder() ); if (m_orient == wxVERTICAL) { @@ -1446,11 +1486,15 @@ wxSize wxBoxSizer::CalcMin() m_fixedWidth = 0; m_fixedHeight = 0; + // precalc item minsizes and count proportions wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); while (node) { wxSizerItem *item = node->GetData(); + if (item->IsShown()) + item->CalcMin(); // result is stored in the item + if (item->IsShown() && item->GetProportion() != 0) m_stretchable += item->GetProportion(); @@ -1468,7 +1512,7 @@ wxSize wxBoxSizer::CalcMin() if (item->IsShown() && item->GetProportion() != 0) { int stretch = item->GetProportion(); - wxSize size( item->CalcMin() ); + wxSize size( item->GetMinSizeWithBorder() ); int minSize; // Integer division rounded up is (a + b - 1) / b @@ -1493,7 +1537,7 @@ wxSize wxBoxSizer::CalcMin() if (item->IsShown()) { - wxSize size( item->CalcMin() ); + wxSize size( item->GetMinSizeWithBorder() ); if (item->GetProportion() != 0) { if (m_orient == wxHORIZONTAL)