From 5175dbbd9f20e7fd39e0820ea510c1c6ea349584 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 27 Mar 2003 23:21:47 +0000 Subject: [PATCH] fixed DrawTextFormatted to work in O(n) instead of O(n^2) if the text doesn't fit into the column git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19842 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index b20d95fd8d..02a2580a92 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -1808,13 +1808,17 @@ void wxListLineData::DrawTextFormatted(wxDC *dc, dc->GetTextExtent(ellipsis, &base_w, &h); // continue until we have enough space or only one character left - drawntext = text.Left(text.Length() - 1); - while (drawntext.Length() > 1) + wxCoord w_c, h_c; + size_t len = text.Length(); + drawntext = text.Left(len); + while (len > 1) { - dc->GetTextExtent(drawntext, &w, &h); + dc->GetTextExtent(drawntext.Last(), &w_c, &h_c); + drawntext.RemoveLast(); + len--; + w -= w_c; if (w + base_w <= width) break; - drawntext = drawntext.Left(drawntext.Length() - 1); } // if still not enough space, remove ellipsis characters -- 2.47.2