Add wxGridCellRenderer::GetMaxBestSize()

This is another optimization, useful for the renderers that are used
with the values of a fixed form or part of a limited set, as it is much
faster to compute the best size for all values of the set rather than
computing them for all the cells in the column.
This commit is contained in:
Vadim Zeitlin
2020-06-13 15:51:20 +02:00
parent 249db04dd3
commit 71d42a8290
5 changed files with 102 additions and 2 deletions

View File

@@ -165,6 +165,24 @@ wxSize wxGridCellDateRenderer::GetBestSize(wxGrid& grid,
return DoGetBestSize(attr, dc, GetString(grid, row, col));
}
wxSize wxGridCellDateRenderer::GetMaxBestSize(wxGrid& WXUNUSED(grid),
wxGridCellAttr& attr,
wxDC& dc)
{
wxSize size;
// Try to produce the longest string in the current format: as we don't
// know which month is the longest, we need to try all of them.
for ( int m = wxDateTime::Jan; m <= wxDateTime::Dec; ++m )
{
const wxDateTime d(28, static_cast<wxDateTime::Month>(m), 9999);
size.IncTo(DoGetBestSize(attr, dc, d.Format(m_oformat, m_tz)));
}
return size;
}
void wxGridCellDateRenderer::SetParameters(const wxString& params)
{
if (!params.empty())
@@ -260,6 +278,20 @@ wxSize wxGridCellEnumRenderer::GetBestSize(wxGrid& grid,
return DoGetBestSize(attr, dc, GetString(grid, row, col));
}
wxSize wxGridCellEnumRenderer::GetMaxBestSize(wxGrid& WXUNUSED(grid),
wxGridCellAttr& attr,
wxDC& dc)
{
wxSize size;
for ( size_t n = 0; n < m_choices.size(); ++n )
{
size.IncTo(DoGetBestSize(attr, dc, m_choices[n]));
}
return size;
}
void wxGridCellEnumRenderer::SetParameters(const wxString& params)
{
if ( !params )
@@ -912,10 +944,17 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
// ----------------------------------------------------------------------------
wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
wxGridCellAttr& WXUNUSED(attr),
wxDC& WXUNUSED(dc),
wxGridCellAttr& attr,
wxDC& dc,
int WXUNUSED(row),
int WXUNUSED(col))
{
return GetMaxBestSize(grid, attr, dc);
}
wxSize wxGridCellBoolRenderer::GetMaxBestSize(wxGrid& grid,
wxGridCellAttr& WXUNUSED(attr),
wxDC& WXUNUSED(dc))
{
static wxPrivate::DpiDependentValue<wxSize> s_sizeCheckMark;