]> git.saurik.com Git - wxWidgets.git/commitdiff
Simplify wxGridCellAutoWrapStringRenderer::GetBestSize().
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 4 Sep 2013 00:14:10 +0000 (00:14 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 4 Sep 2013 00:14:10 +0000 (00:14 +0000)
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.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/gridctrl.cpp

index beeea9d250ba26c72ca5e5271959e40f0f0b5690..25c3359d3b493c722326e03b0e9356c337e4d9d3 100644 (file)
@@ -436,31 +436,22 @@ wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid,
                                               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
 // ----------------------------------------------------------------------------