+
+ lines.push_back(word.substr(0, n));
+
+ // Check if the remainder of the string fits in one line.
+ //
+ // Unfortunately we can't use the existing partial text extents as the
+ // extent of the remainder may be different when it's rendered in a
+ // separate line instead of as part of the same one, so we have to
+ // recompute it.
+ const wxString rest = word.substr(n);
+ const wxCoord restWidth = dc.GetTextExtent(rest).x;
+ if ( restWidth <= maxWidth )
+ {
+ line = rest;
+ return restWidth;
+ }
+
+ // Break the rest of the word into lines.
+ //
+ // TODO: Perhaps avoid recursion? The code is simpler like this but using a
+ // loop in this function would probably be more efficient.
+ return BreakWord(dc, rest, maxWidth, lines, line);
+}
+
+wxSize
+wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid,
+ wxGridCellAttr& attr,
+ 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);
+
+ 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)) );
+
+
+ return wxSize(width,height);
+}
+
+
+// ----------------------------------------------------------------------------
+// wxGridCellStringRenderer
+// ----------------------------------------------------------------------------
+
+void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid,
+ const wxGridCellAttr& attr,
+ wxDC& dc,
+ bool isSelected)
+{
+ dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
+
+ // TODO some special colours for attr.IsReadOnly() case?
+
+ // different coloured text when the grid is disabled
+ if ( grid.IsThisEnabled() )