From 09ecfaec8fa06e2f7ebd7aa62c0c5a7dd4b5df16 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Jun 2020 22:57:17 +0200 Subject: [PATCH] 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. --- src/generic/gridctrl.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index baf5937796..f40acbf0fd 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -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,