+void wxFlexGridSizer::RecalcSizes()
+{
+ int nitems, nrows, ncols;
+ if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 )
+ return;
+
+ wxSize sz( GetSize() );
+ wxSize minsz( CalcMin() );
+ wxPoint pt( GetPosition() );
+ int delta;
+ size_t idx,num;
+ wxArrayInt temp;
+
+ // Transfer only those rows into temp which exist in the sizer
+ // ignoring the superflouus ones. This prevents a segfault when
+ // calling AddGrowableRow( 3 ) if the sizer only has 2 rows.
+ for (idx = 0; idx < m_growableRows.GetCount(); idx++)
+ if (m_growableRows[idx] < nrows)
+ temp.Add( m_growableRows[idx] );
+ num = temp.GetCount();
+
+ if ((num > 0) && (sz.y > minsz.y))
+ {
+ delta = (sz.y - minsz.y) / num;
+ for (idx = 0; idx < num; idx++)
+ m_rowHeights[ temp[idx] ] += delta;
+ }
+
+ temp.Empty();
+ // See above
+ for (idx = 0; idx < m_growableCols.GetCount(); idx++)
+ if (m_growableCols[idx] < ncols)
+ temp.Add( m_growableCols[idx] );
+ num = temp.GetCount();
+
+ if ((num > 0) && (sz.x > minsz.x))
+ {
+ delta = (sz.x - minsz.x) / num;
+ for (idx = 0; idx < num; idx++)
+ m_colWidths[ temp[idx] ] += delta;
+ }
+
+ sz = wxSize( pt.x + sz.x, pt.y + sz.y );
+
+ int x = pt.x;
+ for (int c = 0; c < ncols; c++)
+ {
+ int y = pt.y;
+ for (int r = 0; r < nrows; r++)
+ {
+ int i = r * ncols + c;
+ if (i < nitems)
+ {
+ wxNode *node = m_children.Nth( i );
+ wxASSERT( node );
+
+ int w = wxMax( 0, wxMin( m_colWidths[c], sz.x - x ) );
+ int h = wxMax( 0, wxMin( m_rowHeights[r], sz.y - y ) );
+
+ SetItemBounds( (wxSizerItem*) node->Data(), x, y, w, h);
+ }
+ y = y + m_rowHeights[r] + m_vgap;
+ }
+ x = x + m_colWidths[c] + m_hgap;
+ }
+}
+
+wxSize wxFlexGridSizer::CalcMin()
+{
+ int nitems, nrows, ncols;
+ if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 )
+ return wxSize(10,10);
+
+ CreateArrays();
+
+ int i = 0;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxSizerItem *item = (wxSizerItem*)node->Data();
+ wxSize sz( item->CalcMin() );
+ int row = i / ncols;
+ int col = i % ncols;
+ m_rowHeights[ row ] = wxMax( sz.y, m_rowHeights[ row ] );
+ m_colWidths[ col ] = wxMax( sz.x, m_colWidths[ col ] );
+
+ node = node->Next();
+ i++;
+ }
+
+ int width = 0;
+ for (int col = 0; col < ncols; col++)
+ width += m_colWidths[ col ];
+
+ int height = 0;
+ for (int row = 0; row < nrows; row++)
+ height += m_rowHeights[ row ];
+
+ return wxSize( width + (ncols-1) * m_hgap,
+ height + (nrows-1) * m_vgap);
+}
+
+void wxFlexGridSizer::AddGrowableRow( size_t idx )
+{
+ m_growableRows.Add( idx );
+}
+
+void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx) )
+{
+}
+
+void wxFlexGridSizer::AddGrowableCol( size_t idx )
+{
+ m_growableCols.Add( idx );
+}
+
+void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx) )