X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e6edd2772fe266cb3160fe4fa5c10e8483088b7..5d7792236f7e4fcbb94cdc2a5213e0c5788e8c28:/src/common/sizer.cpp diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index e9e7ad1193..64ffc0877f 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -634,7 +634,7 @@ wxSizer::~wxSizer() WX_CLEAR_LIST(wxSizerItemList, m_children); } -wxSizerItem* wxSizer::Insert( size_t index, wxSizerItem *item ) +wxSizerItem* wxSizer::DoInsert( size_t index, wxSizerItem *item ) { m_children.Insert( index, item ); @@ -1317,39 +1317,39 @@ bool wxSizer::IsShown( size_t index ) const // wxGridSizer //--------------------------------------------------------------------------- -wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap ) - : m_rows( rows || cols ? rows : 1 ), +wxGridSizer::wxGridSizer( int cols, int vgap, int hgap ) + : m_rows( cols == 0 ? 1 : 0 ), m_cols( cols ), m_vgap( vgap ), m_hgap( hgap ) { } -wxGridSizer::wxGridSizer( int rows, int cols, const wxSize& gap ) - : m_rows( rows || cols ? rows : 1 ), +wxGridSizer::wxGridSizer( int cols, const wxSize& gap ) + : m_rows( cols == 0 ? 1 : 0 ), m_cols( cols ), m_vgap( gap.GetHeight() ), m_hgap( gap.GetWidth() ) { } -wxGridSizer::wxGridSizer( int cols, int vgap, int hgap ) - : m_rows( cols == 0 ? 1 : 0 ), +wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap ) + : m_rows( rows || cols ? rows : 1 ), m_cols( cols ), m_vgap( vgap ), m_hgap( hgap ) { } -wxGridSizer::wxGridSizer( int cols, const wxSize& gap ) - : m_rows( cols == 0 ? 1 : 0 ), +wxGridSizer::wxGridSizer( int rows, int cols, const wxSize& gap ) + : m_rows( rows || cols ? rows : 1 ), m_cols( cols ), m_vgap( gap.GetHeight() ), m_hgap( gap.GetWidth() ) { } -wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) +wxSizerItem *wxGridSizer::DoInsert(size_t index, wxSizerItem *item) { // if only the number of columns or the number of rows is specified for a // sizer, arbitrarily many items can be added to it but if both of them are @@ -1369,7 +1369,7 @@ wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) // additionally, continuing to use the specified number of columns // and rows is not a good idea as callers of CalcRowsCols() expect - // that all sizer items can fit into m_cols/m_rows-sized arrays + // that all sizer items can fit into m_cols-/m_rows-sized arrays // which is not the case if there are too many items and results in // crashes, so let it compute the number of rows automatically by // forgetting the (wrong) number of rows specified (this also has a @@ -1379,38 +1379,19 @@ wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) } } - return wxSizer::Insert(index, item); + return wxSizer::DoInsert(index, item); } int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const { const int nitems = m_children.GetCount(); - if ( m_cols && m_rows ) - { - ncols = m_cols; - nrows = m_rows; - // this should be impossible because the too high number of items - // should have been detected by Insert() above - wxASSERT_MSG( nitems <= ncols*nrows, "logic error in wxGridSizer" ); - } - else if ( m_cols ) - { - ncols = m_cols; - nrows = (nitems + m_cols - 1) / m_cols; - } - else if ( m_rows ) - { - ncols = (nitems + m_rows - 1) / m_rows; - nrows = m_rows; - } - else // 0 columns, 0 rows? - { - wxFAIL_MSG( wxT("grid sizer must have either rows or columns fixed") ); + ncols = GetEffectiveColsCount(); + nrows = GetEffectiveRowsCount(); - nrows = - ncols = 0; - } + // Since Insert() checks for overpopulation, the following + // should only assert if the grid was shrunk via SetRows() / SetCols() + wxASSERT_MSG( nitems <= ncols*nrows, "logic error in wxGridSizer" ); return nitems; } @@ -1541,6 +1522,20 @@ void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) // wxFlexGridSizer //--------------------------------------------------------------------------- +wxFlexGridSizer::wxFlexGridSizer( int cols, int vgap, int hgap ) + : wxGridSizer( cols, vgap, hgap ), + m_flexDirection(wxBOTH), + m_growMode(wxFLEX_GROWMODE_SPECIFIED) +{ +} + +wxFlexGridSizer::wxFlexGridSizer( int cols, const wxSize& gap ) + : wxGridSizer( cols, gap ), + m_flexDirection(wxBOTH), + m_growMode(wxFLEX_GROWMODE_SPECIFIED) +{ +} + wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, int vgap, int hgap ) : wxGridSizer( rows, cols, vgap, hgap ), m_flexDirection(wxBOTH), @@ -1548,8 +1543,8 @@ wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, int vgap, int hgap ) { } -wxFlexGridSizer::wxFlexGridSizer( int cols, int vgap, int hgap ) - : wxGridSizer( cols, vgap, hgap ), +wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, const wxSize& gap ) + : wxGridSizer( rows, cols, gap ), m_flexDirection(wxBOTH), m_growMode(wxFLEX_GROWMODE_SPECIFIED) { @@ -1836,11 +1831,10 @@ void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz) // comments in AddGrowableCol/Row()) if ( !m_rows || !m_cols ) { - int nrows, ncols; - CalcRowsCols(nrows, ncols); - if ( !m_rows ) { + int nrows = CalcRows(); + for ( size_t n = 0; n < m_growableRows.size(); n++ ) { wxASSERT_MSG( m_growableRows[n] < nrows, @@ -1850,6 +1844,8 @@ void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz) if ( !m_cols ) { + int ncols = CalcCols(); + for ( size_t n = 0; n < m_growableCols.size(); n++ ) { wxASSERT_MSG( m_growableCols[n] < ncols, @@ -1874,17 +1870,17 @@ void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz) // This gives nested objects that benefit from knowing one size // component in advance the chance to use that. bool didAdjustMinSize = false; - int nrows, ncols; - CalcRowsCols(nrows, ncols); // Iterate over all items and inform about column width - size_t n = 0; + const int ncols = GetEffectiveColsCount(); + int col = 0; for ( wxSizerItemList::iterator i = m_children.begin(); i != m_children.end(); - ++i, ++n ) + ++i ) { - const int col = n % ncols; didAdjustMinSize |= (*i)->InformFirstDirection(wxHORIZONTAL, m_colWidths[col], sz.y - m_calculatedMinSize.y); + if ( ++col == ncols ) + col = 0; } // Only redo if info was actually used @@ -1928,9 +1924,6 @@ bool wxFlexGridSizer::IsColGrowable( size_t idx ) void wxFlexGridSizer::AddGrowableRow( size_t idx, int proportion ) { - int nrows, ncols; - CalcRowsCols(nrows, ncols); - wxASSERT_MSG( !IsRowGrowable( idx ), "AddGrowableRow() called for growable row" ); @@ -1946,15 +1939,12 @@ void wxFlexGridSizer::AddGrowableRow( size_t idx, int proportion ) void wxFlexGridSizer::AddGrowableCol( size_t idx, int proportion ) { - int nrows, ncols; - CalcRowsCols(nrows, ncols); - wxASSERT_MSG( !IsColGrowable( idx ), "AddGrowableCol() called for growable column" ); // see comment in AddGrowableRow(): although it's less common to omit the // specification of the number of columns, it still can also happen - wxCHECK_RET( !m_cols || idx < (size_t)ncols, "invalid column index" ); + wxCHECK_RET( !m_cols || idx < (size_t)m_cols, "invalid column index" ); m_growableCols.Add( idx ); m_growableColsProportions.Add( proportion ); @@ -1992,6 +1982,11 @@ void wxFlexGridSizer::RemoveGrowableRow( size_t idx ) // wxBoxSizer //--------------------------------------------------------------------------- +wxSizerItem *wxBoxSizer::AddSpacer(int size) +{ + return IsVertical() ? Add(0, size) : Add(size, 0); +} + void wxBoxSizer::RecalcSizes() { if ( m_children.empty() ) @@ -2184,12 +2179,12 @@ void wxStaticBoxSizer::RecalcSizes() #if defined( __WXGTK20__ ) // if the wxStaticBox has created a wxPizza to contain its children // (see wxStaticBox::AddChild) then we need to place the items it contains - // in the wxBoxSizer::RecalcSizes() call below using coordinates relative + // in the wxBoxSizer::RecalcSizes() call below using coordinates relative // to the top-left corner of the staticbox: m_position.x = m_position.y = 0; #else // if the wxStaticBox has childrens, then these windows must be placed - // by the wxBoxSizer::RecalcSizes() call below using coordinates relative + // by the wxBoxSizer::RecalcSizes() call below using coordinates relative // to the top-left corner of the staticbox (but unlike wxGTK, we need // to keep in count the static borders here!): m_position.x = other_border;