summaryrefslogtreecommitdiff
path: root/wxWidgets-Fix/grid.cpp.patch
blob: af9bd6845881560ad2e7d2d70a1718c78a202ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- old	2009-03-06 11:00:48.000000000 +0100
+++ src\generic\grid.cpp	2009-10-24 17:12:24.484375000 +0200
@@ -5605,6 +5605,59 @@
     }
 }
 
+
+void wxGrid::AutoSizeColFast(int col, bool doRefresh)
+{
+    if (col < 0)
+        return;
+
+    int rowMax = -1;
+    size_t lenMax = 0;
+    for (int row = 0; row < GetNumberRows(); ++row)
+        if (GetCellValue(row, col).size() > lenMax)
+        {
+            lenMax = GetCellValue(row, col).size();
+            rowMax = row;
+    }
+
+    wxCoord extentMax = 0;
+
+    //calculate width of (most likely) widest cell
+    wxClientDC dc(GetGridWindow());
+    if (rowMax > -1)
+    {
+        wxGridCellAttr* attr = GetCellAttr(rowMax, col);
+        if (attr)
+        {
+            wxGridCellRenderer* renderer = attr->GetRenderer(this, rowMax, col);
+            if (renderer)
+            {
+                const wxSize size = renderer->GetBestSize(*this, *attr, dc, rowMax, col);
+                extentMax = std::max(extentMax, size.x);
+                renderer->DecRef();
+            }
+            attr->DecRef();
+        }
+    }
+
+    //consider column label
+    dc.SetFont(GetLabelFont());
+    wxCoord w = 0;
+    wxCoord h = 0;
+    dc.GetMultiLineTextExtent(GetColLabelValue(col), &w, &h );
+    if (GetColLabelTextOrientation() == wxVERTICAL)
+        w = h;
+    extentMax = std::max(extentMax, w);
+
+    extentMax += 15; //leave some space around text
+
+    SetColSize(col, extentMax);
+
+    if (doRefresh)
+        Refresh();
+}
+
+
 void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
 {
     int x, y, col;
@@ -5829,7 +5882,7 @@
         else
         {
             // adjust column width depending on label text
-            AutoSizeColLabelSize( col );
+            AutoSizeColFast( col );
 
             ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
             m_dragLastPos = -1;
bgstack15