X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/36461f58114509ba43199bf81e4352f84e5573a1..d2ebf0b7303be387d2d5a55ea0cd672fdf0c4f25:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index f21543c120..475867e17b 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -47,41 +47,59 @@ IMPLEMENT_CLASS(wxStaticBoxSizer, wxBoxSizer) WX_DEFINE_EXPORTED_LIST( wxSizerItemList ); /* - TODO PROPERTIES - sizeritem - object - object_ref - minsize - option - flag - border + TODO PROPERTIES + sizeritem + object + object_ref + minsize + option + flag + border spacer - option - flag - borfder - boxsizer - orient + option + flag + borfder + boxsizer + orient staticboxsizer - orient - label - gridsizer - rows - cols - vgap - hgap - flexgridsizer - rows - cols - vgap - hgap - growablerows - growablecols + orient + label + gridsizer + rows + cols + vgap + hgap + flexgridsizer + rows + cols + vgap + hgap + growablerows + growablecols minsize */ + //--------------------------------------------------------------------------- // wxSizerItem //--------------------------------------------------------------------------- +void wxSizerItem::Init() +{ + m_window = NULL; + m_sizer = NULL; + m_show = true; + m_userData = NULL; +} + +void wxSizerItem::Init(const wxSizerFlags& flags) +{ + Init(); + + m_proportion = flags.GetProportion(); + m_flag = flags.GetFlags(); + m_border = flags.GetBorderInPixels(); +} + wxSizerItem::wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData ) : m_window( NULL ) , m_sizer( NULL ) @@ -108,7 +126,7 @@ wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border if (flag & wxFIXED_MINSIZE) window->SetMinSize(window->GetSize()); m_minSize = window->GetSize(); - + // aspect ratio calculated from initial size SetRatio( m_minSize ); @@ -130,15 +148,12 @@ wxSizerItem::wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, } wxSizerItem::wxSizerItem() - : m_window( NULL ) - , m_sizer( NULL ) - , m_proportion( 0 ) - , m_border( 0 ) - , m_flag( 0 ) - , m_show( true ) - , m_ratio( 0.0 ) - , m_userData( NULL ) { + Init(); + + m_proportion = 0; + m_border = 0; + m_flag = 0; } wxSizerItem::~wxSizerItem() @@ -211,7 +226,7 @@ wxSize wxSizerItem::GetMinSizeWithBorder() const ret.y += m_border; if (m_flag & wxSOUTH) ret.y += m_border; - + return ret; } @@ -342,89 +357,6 @@ wxSizer::~wxSizer() WX_CLEAR_LIST(wxSizerItemList, m_children); } -void wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Append( new wxSizerItem( window, proportion, flag, border, userData ) ); - window->SetContainingSizer( this ); -} - -void wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Append( new wxSizerItem( sizer, proportion, flag, border, userData ) ); -} - -void wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Append( new wxSizerItem( width, height, proportion, flag, border, userData ) ); -} - -void wxSizer::Add( wxSizerItem *item ) -{ - m_children.Append( item ); - - if( item->GetWindow() ) - item->GetWindow()->SetContainingSizer( this ); -} - -void wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Insert( new wxSizerItem( window, proportion, flag, border, userData ) ); - window->SetContainingSizer( this ); -} - -void wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Insert( new wxSizerItem( sizer, proportion, flag, border, userData ) ); -} - -void wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData ) -{ - m_children.Insert( new wxSizerItem( width, height, proportion, flag, border, userData ) ); -} - -void wxSizer::Prepend( wxSizerItem *item ) -{ - m_children.Insert( item ); - - if( item->GetWindow() ) - item->GetWindow()->SetContainingSizer( this ); -} - -void wxSizer::Insert( size_t index, - wxWindow *window, - int proportion, - int flag, - int border, - wxObject* userData ) -{ - m_children.Insert( index, - new wxSizerItem( window, proportion, flag, border, userData ) ); - window->SetContainingSizer( this ); -} - -void wxSizer::Insert( size_t index, - wxSizer *sizer, - int proportion, - int flag, - int border, - wxObject* userData ) -{ - m_children.Insert( index, - new wxSizerItem( sizer, proportion, flag, border, userData ) ); -} - -void wxSizer::Insert( size_t index, - int width, - int height, - int proportion, - int flag, - int border, - wxObject* userData ) -{ - m_children.Insert( index, - new wxSizerItem( width, height, proportion, flag, border, userData ) ); -} - void wxSizer::Insert( size_t index, wxSizerItem *item ) { m_children.Insert( index, item ); @@ -663,9 +595,9 @@ wxSize wxSizer::FitSize( wxWindow *window ) // Limit the size if sizeMax != wxDefaultSize - if ( size.x > sizeMax.x && sizeMax.x != -1 ) + if ( size.x > sizeMax.x && sizeMax.x != wxDefaultCoord ) size.x = sizeMax.x; - if ( size.y > sizeMax.y && sizeMax.y != -1 ) + if ( size.y > sizeMax.y && sizeMax.y != wxDefaultCoord ) size.y = sizeMax.y; return size; @@ -699,9 +631,9 @@ wxSize wxSizer::VirtualFitSize( wxWindow *window ) // Limit the size if sizeMax != wxDefaultSize - if ( size.x > sizeMax.x && sizeMax.x != -1 ) + if ( size.x > sizeMax.x && sizeMax.x != wxDefaultCoord ) size.x = sizeMax.x; - if ( size.y > sizeMax.y && sizeMax.y != -1 ) + if ( size.y > sizeMax.y && sizeMax.y != wxDefaultCoord ) size.y = sizeMax.y; return size; @@ -828,7 +760,7 @@ bool wxSizer::DoSetItemMinSize( size_t index, int width, int height ) return true; } -void wxSizer::Show( wxWindow *window, bool show ) +bool wxSizer::Show( wxWindow *window, bool show, bool recursive ) { wxASSERT_MSG( window, _T("Show for NULL window") ); @@ -840,13 +772,22 @@ void wxSizer::Show( wxWindow *window, bool show ) if (item->GetWindow() == window) { item->Show( show ); - break; + + return true; + } + else if (recursive && item->IsSizer()) + { + if (item->GetSizer()->Show(window, show, recursive)) + return true; } + node = node->GetNext(); } + + return false; } -void wxSizer::Show( wxSizer *sizer, bool show ) +bool wxSizer::Show( wxSizer *sizer, bool show, bool recursive ) { wxASSERT_MSG( sizer, _T("Show for NULL sizer") ); @@ -858,18 +799,30 @@ void wxSizer::Show( wxSizer *sizer, bool show ) if (item->GetSizer() == sizer) { item->Show( show ); - break; + + return true; + } + else if (recursive && item->IsSizer()) + { + if (item->GetSizer()->Show(sizer, show, recursive)) + return true; } + node = node->GetNext(); } + + return false; } -void wxSizer::Show( size_t index, bool show ) +bool wxSizer::Show( size_t index, bool show) { - wxCHECK_RET( index < m_children.GetCount(), + wxCHECK_MSG( index < m_children.GetCount(), + false, _T("Show index is out of range") ); m_children.Item( index )->GetData()->Show( show ); + + return true; } void wxSizer::ShowItems( bool show ) @@ -1042,7 +995,7 @@ wxSize wxGridSizer::CalcMin() void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) { wxPoint pt( x,y ); - wxSize sz( item->GetMinSizeWithBorder() ); + wxSize sz( item->GetMinSizeWithBorder() ); int flag = item->GetFlag(); if ((flag & wxEXPAND) || (flag & wxSHAPED)) @@ -1176,7 +1129,7 @@ wxSize wxFlexGridSizer::CalcMin() } AdjustForFlexDirection(); - + // Sum total minimum size, including gaps between rows/columns. // -1 is used as a magic number meaning empty column. int width = 0; @@ -1220,7 +1173,7 @@ void wxFlexGridSizer::AdjustForFlexDirection() array[n] = largest; } } -} +} void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz, const wxSize& minsz, @@ -1240,7 +1193,7 @@ void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz, const wxSize& minsz, // requested growable rows/columns are still valid. if (m_growableRows[idx] >= nrows) continue; - + // If all items in a row/column are hidden, that row/column will // have a dimension of -1. This causes the row/column to be // hidden completely. @@ -1292,7 +1245,7 @@ void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz, const wxSize& minsz, // requested growable rows/columns are still valid. if (m_growableCols[idx] >= ncols) continue; - + // If all items in a row/column are hidden, that row/column will // have a dimension of -1. This causes the column to be hidden // completely. @@ -1464,7 +1417,7 @@ wxSize wxBoxSizer::CalcMin() if (item->IsShown()) item->CalcMin(); // result is stored in the item - + if (item->IsShown() && item->GetProportion() != 0) m_stretchable += item->GetProportion(); @@ -1484,7 +1437,7 @@ wxSize wxBoxSizer::CalcMin() int stretch = item->GetProportion(); wxSize size( item->GetMinSizeWithBorder() ); int minSize; - + // Integer division rounded up is (a + b - 1) / b // Round up needed in order to guarantee that all // all items will have size not less then their min size @@ -1492,7 +1445,7 @@ wxSize wxBoxSizer::CalcMin() minSize = ( size.x*m_stretchable + stretch - 1)/stretch; else minSize = ( size.y*m_stretchable + stretch - 1)/stretch; - + if (minSize > maxMinSize) maxMinSize = minSize; } @@ -1584,7 +1537,7 @@ static void GetStaticBoxBorders( wxStaticBox *box, // pixels (otherwise overlapping occurs at the top). The "other" // border has to be 11. extraTop = 11; - other = 11; + other = 11; } }