]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/sizer.cpp
reverted yet another accidental commit of testing code in r57505
[wxWidgets.git] / src / common / sizer.cpp
index 63a832d8ff9beb1f321595d47655360fa26e8b50..939150a121ff2dae7636abf5ea88941f7fc0db47 100644 (file)
@@ -1324,25 +1324,33 @@ wxGridSizer::wxGridSizer( int cols, int vgap, int hgap )
 
 int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const
 {
-    int nitems = m_children.GetCount();
-    if ( nitems)
+    const int nitems = m_children.GetCount();
+    if ( m_cols && m_rows )
     {
-        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( _T("grid sizer must have either rows or columns fixed") );
+        // if both rows and columns are specified by user, use the provided
+        // values even if we don't have enough items but check that we don't
+        // have too many of them as this is going to result in problems later
+        ncols = m_cols;
+        nrows = m_rows;
 
-            nrows = ncols = 0;
-        }
+        wxASSERT_MSG( ncols*nrows <= nitems, "too many items in grid sizer" );
+    }
+    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( _T("grid sizer must have either rows or columns fixed") );
+
+        nrows =
+        ncols = 0;
     }
 
     return nitems;
@@ -1830,7 +1838,10 @@ bool wxFlexGridSizer::IsColGrowable( size_t idx )
 
 void wxFlexGridSizer::AddGrowableRow( size_t idx, int proportion )
 {
-    wxCHECK_RET( idx < (size_t)GetRows(), "invalid row index" );
+    int nrows, ncols;
+    CalcRowsCols(nrows, ncols);
+    wxCHECK_RET( idx < (size_t)nrows, "invalid row index" );
+
     wxASSERT_MSG( !IsRowGrowable( idx ),
                   "AddGrowableRow() called for growable row" );
     m_growableRows.Add( idx );
@@ -1839,7 +1850,10 @@ void wxFlexGridSizer::AddGrowableRow( size_t idx, int proportion )
 
 void wxFlexGridSizer::AddGrowableCol( size_t idx, int proportion )
 {
-    wxCHECK_RET( idx < (size_t)GetCols(), "invalid column index" );
+    int nrows, ncols;
+    CalcRowsCols(nrows, ncols);
+    wxCHECK_RET( idx < (size_t)ncols, "invalid column index" );
+
     wxASSERT_MSG( !IsColGrowable( idx ),
                   "AddGrowableCol() called for growable column" );
     m_growableCols.Add( idx );