SVN:(VZ)[74751] Simplify wxGridCellAutoWrapStringRenderer::GetBestSize().

0 views
Skip to first unread message

nor...@wxsite.net

unread,
Sep 3, 2013, 8:14:10 PM9/3/13
to wx-commi...@googlegroups.com
Revision
74751
Author
VZ
Date
2013-09-03 17:14:10 -0700 (Tue, 03 Sep 2013)

Log Message

Simplify wxGridCellAutoWrapStringRenderer::GetBestSize().

The code there was pretty wild, making clearly wrong assumptions (column size doesn't, and AFAICS never did, include 20 pixel margin) and also was clearly uncertain about what it was doing by trying to limit the number of iterations to some arbitrary cutoff when it is pretty clear that the loop increasing the width and decreasing the height on each iteration will reach the condition of "width >= height*1.68" sooner or later.

Modified Paths

Diff

Modified: wxWidgets/trunk/src/generic/gridctrl.cpp (74750 => 74751)


--- wxWidgets/trunk/src/generic/gridctrl.cpp	2013-09-04 00:14:05 UTC (rev 74750)
+++ wxWidgets/trunk/src/generic/gridctrl.cpp	2013-09-04 00:14:10 UTC (rev 74751)
@@ -436,31 +436,22 @@
                                               wxDC& dc,
                                               int row, int col)
 {
-    wxCoord x,y, height , width = grid.GetColSize(col) -20;
-    // for width, subtract 20 because ColSize includes a magin of 10 pixels
-    // that we do not want here and because we always start with an increment
-    // by 10 in the loop below.
-    int count = 250; //Limit iterations..
+    const int lineHeight = dc.GetCharHeight();
 
-    wxRect rect(0,0,width,10);
-
-    // M is a nice large character 'y' gives descender!.
-    dc.GetTextExtent(wxT("My"), &x, &y);
-
-    do
-    {
-        width+=10;
-        rect.SetWidth(width);
-        height = y * (wx_truncate_cast(wxCoord, GetTextLines(grid,dc,attr,rect,row,col).GetCount()));
-        count--;
     // Search for a shape no taller than the golden ratio.
-    } while (count && (width  < (height*1.68)) );
+    wxSize size;
+    for ( size.x = 10; ; size.x += 10 )
+    {
+        const size_t
+            numLines = GetTextLines(grid, dc, attr, size, row, col).size();
+        size.y = numLines * lineHeight;
+        if ( size.x >= size.y*1.68 )
+            break;
+    }
 
-
-    return wxSize(width,height);
+    return size;
 }
 
-
 // ----------------------------------------------------------------------------
 // wxGridCellStringRenderer
 // ----------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages