+ wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
+ extent = column ? size.x : size.y;
+ if ( extent > extentMax )
+ extentMax = extent;
+
+ renderer->DecRef();
+ }
+
+ attr->DecRef();
+ }
+
+ // now also compare with the column label extent
+ wxCoord w, h;
+ dc.SetFont( GetLabelFont() );
+
+ if ( column )
+ {
+ dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h );
+ if ( GetColLabelTextOrientation() == wxVERTICAL )
+ w = h;
+ }
+ else
+ dc.GetMultiLineTextExtent( GetRowLabelValue(row), &w, &h );
+
+ extent = column ? w : h;
+ if ( extent > extentMax )
+ extentMax = extent;
+
+ if ( !extentMax )
+ {
+ // empty column - give default extent (notice that if extentMax is less
+ // than default extent but != 0, it's OK)
+ extentMax = column ? m_defaultColWidth : m_defaultRowHeight;
+ }
+ else
+ {
+ if ( column )
+ // leave some space around text
+ extentMax += 10;
+ else
+ extentMax += 6;
+ }
+
+ if ( column )
+ {
+ SetColSize( col, extentMax );
+ if ( !GetBatchCount() )
+ {
+ int cw, ch, dummy;
+ m_gridWin->GetClientSize( &cw, &ch );
+ wxRect rect ( CellToRect( 0, col ) );
+ rect.y = 0;
+ CalcScrolledPosition(rect.x, 0, &rect.x, &dummy);
+ rect.width = cw - rect.x;
+ rect.height = m_colLabelHeight;
+ m_colLabelWin->Refresh( true, &rect );
+ }
+ }
+ else
+ {
+ SetRowSize(row, extentMax);
+ if ( !GetBatchCount() )
+ {
+ int cw, ch, dummy;
+ m_gridWin->GetClientSize( &cw, &ch );
+ wxRect rect( CellToRect( row, 0 ) );
+ rect.x = 0;
+ CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
+ rect.width = m_rowLabelWidth;
+ rect.height = ch - rect.y;
+ m_rowLabelWin->Refresh( true, &rect );
+ }
+ }
+
+ if ( setAsMin )
+ {
+ if ( column )
+ SetColMinimalWidth(col, extentMax);
+ else
+ SetRowMinimalHeight(row, extentMax);
+ }
+}
+
+int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
+{
+ int width = m_rowLabelWidth;
+
+ if ( !calcOnly )
+ BeginBatch();
+
+ for ( int col = 0; col < m_numCols; col++ )
+ {
+ if ( !calcOnly )
+ AutoSizeColumn(col, setAsMin);
+
+ width += GetColWidth(col);
+ }
+
+ if ( !calcOnly )
+ EndBatch();
+
+ return width;
+}
+
+int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
+{
+ int height = m_colLabelHeight;
+
+ if ( !calcOnly )
+ BeginBatch();
+
+ for ( int row = 0; row < m_numRows; row++ )
+ {
+ if ( !calcOnly )
+ AutoSizeRow(row, setAsMin);
+
+ height += GetRowHeight(row);
+ }
+
+ if ( !calcOnly )
+ EndBatch();
+
+ return height;
+}
+
+void wxGrid::AutoSize()
+{
+ BeginBatch();
+
+ // we need to round up the size of the scrollable area to a multiple of
+ // scroll step to ensure that we don't get the scrollbars when we're sized
+ // exactly to fit our contents
+ wxSize size(SetOrCalcColumnSizes(false) - m_rowLabelWidth + m_extraWidth,
+ SetOrCalcRowSizes(false) - m_colLabelHeight + m_extraHeight);
+ wxSize sizeFit(GetScrollX(size.x) * GetScrollLineX(),
+ GetScrollY(size.y) * GetScrollLineY());
+
+ // distribute the extra space between the columns/rows to avoid having
+ // extra white space
+ wxCoord diff = sizeFit.x - size.x;
+ if ( diff && m_numCols )
+ {
+ // 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 && m_numRows )
+ {
+ // 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-- )