]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed DrawTextFormatted to work in O(n) instead of O(n^2) if the text doesn't fit...
authorVáclav Slavík <vslavik@fastmail.fm>
Thu, 27 Mar 2003 23:21:47 +0000 (23:21 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Thu, 27 Mar 2003 23:21:47 +0000 (23:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19842 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/listctrl.cpp

index b20d95fd8dd47325c06930a49b454d0a8a452f2c..02a2580a927714f543310e134f83ebd557765c11 100644 (file)
@@ -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