Reuse wxDC::GetMultiLineTextExtent() in wxGridCellStringRenderer
There is no need to reimplement the same logic in wxGrid code when we already have a perfectly cromulent way to do it in wxDC itself (which hadn't existed when this code was originally written, explaining why it wasn't used here before). This makes the code shorter and also a bit faster, as we avoid using wxStringTokenizer unnecessarily. No changes in behaviour.
This commit is contained in:
@@ -557,18 +557,8 @@ wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
|
||||
wxDC& dc,
|
||||
const wxString& text)
|
||||
{
|
||||
wxCoord x = 0, y = 0, max_x = 0;
|
||||
dc.SetFont(attr.GetFont());
|
||||
wxStringTokenizer tk(text, wxT('\n'));
|
||||
while ( tk.HasMoreTokens() )
|
||||
{
|
||||
dc.GetTextExtent(tk.GetNextToken(), &x, &y);
|
||||
max_x = wxMax(max_x, x);
|
||||
}
|
||||
|
||||
y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines.
|
||||
|
||||
return wxSize(max_x, y);
|
||||
return dc.GetMultiLineTextExtent(text);
|
||||
}
|
||||
|
||||
wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid,
|
||||
|
Reference in New Issue
Block a user