X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0ec98fd6c98c9605cbe7f5cf3c31230ff7f236b7..931d6a47c32a5b4c283243cb553ce71ee2b535d5:/src/generic/gridctrl.cpp diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index 734775d15c..25c3359d3b 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -4,7 +4,6 @@ // Author: Paul Gammans, Roger Gammans // Modified by: // Created: 11/04/2001 -// RCS-ID: $Id$ // Copyright: (c) The Computer Surgery (paul@compsurg.co.uk) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -302,6 +301,11 @@ wxGridCellAutoWrapStringRenderer::GetTextLines(wxGrid& grid, const wxArrayString logicalLines = wxSplit(grid.GetCellValue(row, col), '\n', '\0'); + // Trying to do anything if the column is hidden anyhow doesn't make sense + // and we run into problems in BreakLine() in this case. + if ( maxWidth <= 0 ) + return logicalLines; + wxArrayString physicalLines; for ( wxArrayString::const_iterator it = logicalLines.begin(); it != logicalLines.end(); @@ -432,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.. - - wxRect rect(0,0,width,10); - - // M is a nice large character 'y' gives descender!. - dc.GetTextExtent(wxT("My"), &x, &y); + const int lineHeight = dc.GetCharHeight(); - 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 // ----------------------------------------------------------------------------