X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/85d2dec9f022748a678a3534851b8dcf76c56fa8..afab8b85c4bdeb11a248c57d13e9bcfa14149ef8:/src/generic/gridctrl.cpp diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index beeea9d250..25c3359d3b 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -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 // ----------------------------------------------------------------------------