void wxSheetCellStringRendererRefData::SetTextColoursAndFont(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, bool isSelected) { dc.SetBackgroundMode( wxTRANSPARENT ); // TODO some special colours for attr.IsReadOnly() case? // different coloured text when the sheet is disabled if ( sheet.IsEnabled() ) { if ( isSelected ) { dc.SetTextBackground( sheet.GetSelectionBackground() ); dc.SetTextForeground( sheet.GetSelectionForeground() ); } else { dc.SetTextBackground( attr.GetBackgroundColour() ); dc.SetTextForeground( attr.GetForegroundColour() ); } } else { dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); } dc.SetFont( attr.GetFont() ); }
wxSize wxSheetCellStringRendererRefData::DoGetBestSize(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, const wxString& text) { wxArrayString lines; long w=0, h=0; if (sheet.StringToLines(text, lines) > 0) { dc.SetFont(attr.GetFont()); sheet.GetTextBoxSize(dc, lines, &w, &h); } return (attr.GetOrientation() == wxHORIZONTAL) ? wxSize(w, h) : wxSize(h, w); }
wxArrayString wxSheetCellAutoWrapStringRendererRefData::GetTextLines(wxSheet& sheet, wxDC& dc, const wxSheetCellAttr& attr, const wxRect& rect, const wxSheetCoords& coords) { wxString data( sheet.GetCellValue(coords) ); wxArrayString lines; dc.SetFont(attr.GetFont()); //Taken from wxSheet again! wxCoord x = 0, y = 0, curr_x = 0; wxCoord max_x = rect.GetWidth(); wxStringTokenizer tk(data, _T(" \n\t\r")); wxString thisline; while ( tk.HasMoreTokens() ) { wxString tok( tk.GetNextToken() ); //FIXME: this causes us to print an extra unnecesary // space at the end of the line. But it // is invisible , simplifies the size calculation // and ensures tokens are separated in the display tok += _T(" "); dc.GetTextExtent(tok, &x, &y); if ( curr_x + x > max_x) { lines.Add( thisline ); thisline = tok; curr_x = x; } else { thisline += tok; curr_x += x; } } lines.Add( thisline ); //Add last line return lines; }
bool wxSheetCellAttr::MergeWith(const wxSheetCellAttr &other) { wxCHECK_MSG(Ok() && other.Ok(), false, wxT("this or Attr to MergeWith from is not created")); if ( !HasForegoundColour() && other.HasForegoundColour() ) SetForegroundColour(other.GetForegroundColour()); if ( !HasBackgroundColour() && other.HasBackgroundColour() ) SetBackgroundColour(other.GetBackgroundColour()); if ( !HasFont() && other.HasFont() ) SetFont(other.GetFont()); if ( !HasAlignment() && other.HasAlignment() ) SetAlignment(other.GetAlignment()); if ( !HasOrientation() && other.HasOrientation() ) SetOrientation(other.GetOrientation()); if ( !HasLevel() && other.HasLevel() ) SetLevel(other.GetLevel()); if ( !HasReadWriteMode() && other.HasReadWriteMode() ) SetReadOnly(other.GetReadOnly()); if ( !HasOverflowMode() && other.HasOverflowMode() ) SetOverflow(other.GetOverflow()); if ( !HasOverflowMarkerMode() && other.HasOverflowMarkerMode() ) SetOverflowMarker(other.GetOverflowMarker()); if ( !HasShowEditorMode() && other.HasShowEditorMode() ) SetShowEditor(other.GetShowEditor()); // Directly access m_renderer/m_editor as GetRender/Editor may return different one // Maybe add support for merge of Render and Editor? if ( !HasRenderer() && other.HasRenderer() ) SetRenderer(((wxSheetCellAttrRefData*)other.m_refData)->m_renderer->Clone()); if ( !HasEditor() && other.HasEditor() ) SetEditor(((wxSheetCellAttrRefData*)other.m_refData)->m_editor->Clone()); if ( !HasDefaultAttr() && other.HasDefaultAttr() ) SetDefaultAttr(other.GetDefaultAttr()); return true; }
wxSize wxSheetCellAutoWrapStringRendererRefData::GetBestSize(wxSheet& sheet, const wxSheetCellAttr& attr, wxDC& dc, const wxSheetCoords& coords) { wxCoord x, y, height, width = sheet.GetColWidth(coords.GetCol()) -10; int count = 250; //Limit iterations.. wxRect rect(0, 0, width, 10); // M is a nice large character 'y' gives descender!. dc.SetFont(attr.GetFont()); dc.GetTextExtent(wxT("My"), &x, &y); do // Search for a shape no taller than the golden ratio. { width += 10; rect.SetWidth(width); height = y * GetTextLines(sheet,dc,attr,rect,coords).GetCount(); count--; } while (count && (width < (height*1.68)) ); return wxSize(width, height); }