Account for cells spanning multiple grid cells better when autosizing.
The total size of a multi-span cell was accounted for each row/column it covered, resulting in too much space being allocated to them. Only take into account the average size of each row/column computed by dividing the total cell size by number of rows/columns it occupies to fix this. Closes #11498. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63001 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -7812,22 +7812,40 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
|
|||||||
HideCellEditControl();
|
HideCellEditControl();
|
||||||
SaveEditControlValue();
|
SaveEditControlValue();
|
||||||
|
|
||||||
// init both of them to avoid compiler warnings, even if we only need one
|
// initialize both of them just to avoid compiler warnings
|
||||||
int row = -1,
|
int row = -1,
|
||||||
col = -1;
|
col = -1;
|
||||||
if ( column )
|
|
||||||
col = colOrRow;
|
|
||||||
else
|
|
||||||
row = colOrRow;
|
|
||||||
|
|
||||||
wxCoord extent, extentMax = 0;
|
wxCoord extent, extentMax = 0;
|
||||||
int max = column ? m_numRows : m_numCols;
|
int max = column ? m_numRows : m_numCols;
|
||||||
for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ )
|
for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ )
|
||||||
{
|
{
|
||||||
if ( column )
|
if ( column )
|
||||||
|
{
|
||||||
row = rowOrCol;
|
row = rowOrCol;
|
||||||
|
col = colOrRow;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
row = colOrRow;
|
||||||
col = rowOrCol;
|
col = rowOrCol;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// this column/row
|
||||||
|
int numRows, numCols;
|
||||||
|
const CellSpan span = GetCellSize(row, col, &numRows, &numCols);
|
||||||
|
if ( span == CellSpan_Inside )
|
||||||
|
{
|
||||||
|
// we need to get the size of the main cell, not of a cell hidden
|
||||||
|
// by it
|
||||||
|
row += numRows;
|
||||||
|
col += numCols;
|
||||||
|
|
||||||
|
// get the size of the main cell too
|
||||||
|
GetCellSize(row, col, &numRows, &numCols);
|
||||||
|
}
|
||||||
|
|
||||||
wxGridCellAttr *attr = GetCellAttr(row, col);
|
wxGridCellAttr *attr = GetCellAttr(row, col);
|
||||||
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
|
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
|
||||||
@@ -7835,6 +7853,19 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
|
|||||||
{
|
{
|
||||||
wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
|
wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col);
|
||||||
extent = column ? size.x : size.y;
|
extent = column ? size.x : size.y;
|
||||||
|
|
||||||
|
if ( span != CellSpan_None )
|
||||||
|
{
|
||||||
|
// we spread the size of a spanning cell over all the cells it
|
||||||
|
// covers evenly -- this is probably not ideal but we can't
|
||||||
|
// really do much better here
|
||||||
|
//
|
||||||
|
// notice that numCols and numRows are never 0 as they
|
||||||
|
// correspond to the size of the main cell of the span and not
|
||||||
|
// of the cell inside it
|
||||||
|
extent /= column ? numCols : numRows;
|
||||||
|
}
|
||||||
|
|
||||||
if ( extent > extentMax )
|
if ( extent > extentMax )
|
||||||
extentMax = extent;
|
extentMax = extent;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user