deal correctly with having too few items in wxFlexGridSizer (this is not an error...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 May 2007 01:19:17 +0000 (01:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 May 2007 01:19:17 +0000 (01:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46205 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/sizer.cpp

index 1258062d21ceb2c67881fdfa2acf0cf7eee3e528..c8965d7295d0ff10480e912aa3f2450c6c940206 100644 (file)
@@ -1352,6 +1352,8 @@ void wxFlexGridSizer::RecalcSizes()
     AdjustForGrowables(sz);
 
     wxSizerItemList::const_iterator i = m_children.begin();
+    const wxSizerItemList::const_iterator end = m_children.end();
+
     int y = 0;
     for ( int r = 0; r < nrows; r++ )
     {
@@ -1359,7 +1361,12 @@ void wxFlexGridSizer::RecalcSizes()
         {
             // this row is entirely hidden, skip it
             for ( int c = 0; c < ncols; c++ )
+            {
+                if ( i == end )
+                    return;
+
                 ++i;
+            }
 
             continue;
         }
@@ -1370,22 +1377,13 @@ void wxFlexGridSizer::RecalcSizes()
             h = hrow;
 
         int x = 0;
-        for ( int c = 0; c < ncols; c++, ++i )
+        for ( int c = 0; c < ncols && i != end; c++, ++i )
         {
             const int wcol = m_colWidths[c];
 
             if ( wcol == -1 )
                 continue;
 
-            // check if there are any remaining children: it may happen that
-            // the last row is incomplete
-            if ( i == m_children.end() )
-            {
-                wxASSERT_MSG( r == nrows - 1, _T("too few items") );
-
-                return;
-            }
-
             int w = sz.x - x; // max possible value, ensure we don't overflow
             if ( wcol < w )
                 w = wcol;
@@ -1395,6 +1393,9 @@ void wxFlexGridSizer::RecalcSizes()
             x += wcol + m_hgap;
         }
 
+        if ( i == end )
+            return;
+
         y += hrow + m_vgap;
     }
 }