Fix wxGrid::AutoSizeColOrRow() logic for multicells.

This fixes the regression of r64885 and also tries to make the code more
clear by setting the variables explicitly to their correct values.

Closes #14611.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72489 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-15 23:17:34 +00:00
parent a349dc1085
commit bc7d2e9dd4

View File

@@ -8241,9 +8241,15 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ ) for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ )
{ {
if ( column ) if ( column )
{
row = rowOrCol; row = rowOrCol;
else col = colOrRow;
}
else
{
row = colOrRow;
col = rowOrCol; col = rowOrCol;
}
// we need to account for the cells spanning multiple columns/rows: // we need to account for the cells spanning multiple columns/rows:
// while they may need a lot of space, they don't need all of it in // while they may need a lot of space, they don't need all of it in
@@ -8261,6 +8267,7 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
GetCellSize(row, col, &numRows, &numCols); GetCellSize(row, col, &numRows, &numCols);
} }
// get cell ( main cell if CellSpan_Inside ) renderer best size
wxGridCellAttr *attr = GetCellAttr(row, col); wxGridCellAttr *attr = GetCellAttr(row, col);
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col); wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
if ( renderer ) if ( renderer )
@@ -8295,12 +8302,12 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
if ( column ) if ( column )
{ {
dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h ); dc.GetMultiLineTextExtent( GetColLabelValue(colOrRow), &w, &h );
if ( GetColLabelTextOrientation() == wxVERTICAL ) if ( GetColLabelTextOrientation() == wxVERTICAL )
w = h; w = h;
} }
else else
dc.GetMultiLineTextExtent( GetRowLabelValue(row), &w, &h ); dc.GetMultiLineTextExtent( GetRowLabelValue(colOrRow), &w, &h );
extent = column ? w : h; extent = column ? w : h;
if ( extent > extentMax ) if ( extent > extentMax )
@@ -8327,20 +8334,20 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
// comment in SetColSize() for explanation of why this isn't done // comment in SetColSize() for explanation of why this isn't done
// in SetColSize(). // in SetColSize().
if ( !setAsMin ) if ( !setAsMin )
extentMax = wxMax(extentMax, GetColMinimalWidth(col)); extentMax = wxMax(extentMax, GetColMinimalWidth(colOrRow));
SetColSize( col, extentMax ); SetColSize( colOrRow, extentMax );
if ( !GetBatchCount() ) if ( !GetBatchCount() )
{ {
if ( m_useNativeHeader ) if ( m_useNativeHeader )
{ {
GetGridColHeader()->UpdateColumn(col); GetGridColHeader()->UpdateColumn(colOrRow);
} }
else else
{ {
int cw, ch, dummy; int cw, ch, dummy;
m_gridWin->GetClientSize( &cw, &ch ); m_gridWin->GetClientSize( &cw, &ch );
wxRect rect ( CellToRect( 0, col ) ); wxRect rect ( CellToRect( 0, colOrRow ) );
rect.y = 0; rect.y = 0;
CalcScrolledPosition(rect.x, 0, &rect.x, &dummy); CalcScrolledPosition(rect.x, 0, &rect.x, &dummy);
rect.width = cw - rect.x; rect.width = cw - rect.x;
@@ -8355,14 +8362,14 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
// comment in SetColSize() for explanation of why this isn't done // comment in SetColSize() for explanation of why this isn't done
// in SetRowSize(). // in SetRowSize().
if ( !setAsMin ) if ( !setAsMin )
extentMax = wxMax(extentMax, GetRowMinimalHeight(row)); extentMax = wxMax(extentMax, GetRowMinimalHeight(colOrRow));
SetRowSize(row, extentMax); SetRowSize(colOrRow, extentMax);
if ( !GetBatchCount() ) if ( !GetBatchCount() )
{ {
int cw, ch, dummy; int cw, ch, dummy;
m_gridWin->GetClientSize( &cw, &ch ); m_gridWin->GetClientSize( &cw, &ch );
wxRect rect( CellToRect( row, 0 ) ); wxRect rect( CellToRect( colOrRow, 0 ) );
rect.x = 0; rect.x = 0;
CalcScrolledPosition(0, rect.y, &dummy, &rect.y); CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
rect.width = m_rowLabelWidth; rect.width = m_rowLabelWidth;
@@ -8374,9 +8381,9 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
if ( setAsMin ) if ( setAsMin )
{ {
if ( column ) if ( column )
SetColMinimalWidth(col, extentMax); SetColMinimalWidth(colOrRow, extentMax);
else else
SetRowMinimalHeight(row, extentMax); SetRowMinimalHeight(colOrRow, extentMax);
} }
} }