+ BeginBatch();
+
+ wxSize size(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE));
+
+ // round up the size to a multiple of scroll step - this ensures that we
+ // won't get the scrollbars if we're sized exactly to this width
+ wxSize sizeFit(GetScrollX(size.x) * GRID_SCROLL_LINE_X,
+ GetScrollY(size.y) * GRID_SCROLL_LINE_Y);
+
+ // distribute the extra space between teh columns/rows to avoid having
+ // extra white space
+ wxCoord diff = sizeFit.x - size.x;
+ if ( diff )
+ {
+ // try to resize the columns uniformly
+ wxCoord diffPerCol = diff / m_numCols;
+ if ( diffPerCol )
+ {
+ for ( int col = 0; col < m_numCols; col++ )
+ {
+ SetColSize(col, GetColWidth(col) + diffPerCol);
+ }
+ }
+
+ // add remaining amount to the last columns
+ diff -= diffPerCol * m_numCols;
+ if ( diff )
+ {
+ for ( int col = m_numCols - 1; col >= m_numCols - diff; col-- )
+ {
+ SetColSize(col, GetColWidth(col) + 1);
+ }
+ }
+ }
+
+ // same for rows
+ diff = sizeFit.y - size.y;
+ if ( diff )
+ {
+ // try to resize the columns uniformly
+ wxCoord diffPerRow = diff / m_numRows;
+ if ( diffPerRow )
+ {
+ for ( int row = 0; row < m_numRows; row++ )
+ {
+ SetRowSize(row, GetRowHeight(row) + diffPerRow);
+ }
+ }
+
+ // add remaining amount to the last rows
+ diff -= diffPerRow * m_numRows;
+ if ( diff )
+ {
+ for ( int row = m_numRows - 1; row >= m_numRows - diff; row-- )
+ {
+ SetRowSize(row, GetRowHeight(row) + 1);
+ }
+ }
+ }
+
+ EndBatch();
+
+ SetClientSize(sizeFit);