Refactor wxGrid::SetOrCalcColumnSizes() and SetOrCalcRowSizes()

Get rid of the unnecessarily complicated functions doing two quite
different things depending on whether their first boolean parameter was
true of false.

Instead, split their body between AutoSize{Columns,Rows}() (which used
to call them) and DoGetBestSize(), keeping just the part needed in each
case.

This is much simpler and even more efficient, as it avoids a completely
unnecessary call to CalcDimensions() and Refresh() from DoGetBestSize(),
which doesn't change the current size at all and so doesn't need to
refresh anything, but previously did it and not only once, but twice,
because both of SetOrCalc{Column,Row}Sizes() did it.
This commit is contained in:
Vadim Zeitlin
2020-05-31 17:46:32 +02:00
parent eac58e7f87
commit 123e21c181
2 changed files with 18 additions and 45 deletions

View File

@@ -10206,50 +10206,28 @@ wxCoord wxGrid::CalcColOrRowLabelAreaMinSize(wxGridDirection direction)
return extentMax;
}
int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
void wxGrid::AutoSizeColumns(bool setAsMin)
{
int width = m_rowLabelWidth;
wxGridUpdateLocker locker;
if(!calcOnly)
locker.Create(this);
wxGridUpdateLocker locker(this);
for ( int col = 0; col < m_numCols; col++ )
{
if ( !calcOnly )
AutoSizeColumn(col, setAsMin);
width += GetColWidth(col);
}
return width;
AutoSizeColumn(col, setAsMin);
}
int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
void wxGrid::AutoSizeRows(bool setAsMin)
{
int height = m_colLabelHeight;
wxGridUpdateLocker locker;
if(!calcOnly)
locker.Create(this);
wxGridUpdateLocker locker(this);
for ( int row = 0; row < m_numRows; row++ )
{
if ( !calcOnly )
AutoSizeRow(row, setAsMin);
height += GetRowHeight(row);
}
return height;
AutoSizeRow(row, setAsMin);
}
void wxGrid::AutoSize()
{
wxGridUpdateLocker locker(this);
wxSize size(SetOrCalcColumnSizes(false) + m_extraWidth,
SetOrCalcRowSizes(false) + m_extraHeight);
AutoSizeColumns();
AutoSizeRows();
// we know that we're not going to have scrollbars so disable them now to
// avoid trouble in SetClientSize() which can otherwise set the correct
@@ -10257,7 +10235,7 @@ void wxGrid::AutoSize()
SetScrollbars(m_xScrollPixelsPerLine, m_yScrollPixelsPerLine,
0, 0, 0, 0, true);
SetClientSize(size);
SetSize(DoGetBestSize());
}
void wxGrid::AutoSizeRowLabelSize( int row )
@@ -10294,12 +10272,14 @@ void wxGrid::AutoSizeColLabelSize( int col )
wxSize wxGrid::DoGetBestSize() const
{
wxGrid * const self = const_cast<wxGrid *>(this);
wxSize size(m_rowLabelWidth + m_extraWidth,
m_colLabelHeight + m_extraHeight);
// we do the same as in AutoSize() here with the exception that we don't
// change the column/row sizes, only calculate them
wxSize size(self->SetOrCalcColumnSizes(true) + m_extraWidth,
self->SetOrCalcRowSizes(true) + m_extraHeight);
for ( int col = 0; col < m_numCols; col++ )
size.x += GetColWidth(col);
for ( int row = 0; row < m_numRows; row++ )
size.y += GetRowHeight(row);
return size + GetWindowBorderSize();
}