- text.Printf(m_format, table->GetValueAsDouble(row, col));
- }
- else
- {
- text = table->GetValue(row, col);
- }
-
- return text;
-}
-
-void wxGridCellFloatRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rectCell,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
-
- SetTextColoursAndFont(grid, attr, dc, isSelected);
-
- // draw the text right aligned by default
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
- hAlign = wxRIGHT;
-
- wxRect rect = rectCell;
- rect.Inflate(-1);
-
- grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
-}
-
-wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, GetString(grid, row, col));
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolRenderer
-// ----------------------------------------------------------------------------
-
-wxSize wxGridCellBoolRenderer::ms_sizeCheckMark;
-
-// FIXME these checkbox size calculations are really ugly...
-
-// between checkmark and box
-#ifdef __WXGTK__
- static const wxCoord wxGRID_CHECKMARK_MARGIN = 4;
-#else
- static const wxCoord wxGRID_CHECKMARK_MARGIN = 2;
-#endif
-
-wxSize wxGridCellBoolRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& WXUNUSED(attr),
- wxDC& WXUNUSED(dc),
- int WXUNUSED(row),
- int WXUNUSED(col))
-{
- // compute it only once (no locks for MT safeness in GUI thread...)
- if ( !ms_sizeCheckMark.x )
- {
- // get checkbox size
- wxCoord checkSize = 0;
- wxCheckBox *checkbox = new wxCheckBox(&grid, -1, wxEmptyString);
- wxSize size = checkbox->GetBestSize();
- checkSize = size.y + wxGRID_CHECKMARK_MARGIN;
-
- // FIXME wxGTK::wxCheckBox::GetBestSize() gives "wrong" result
-#if defined(__WXGTK__) || defined(__WXMOTIF__)
- checkSize -= size.y / 2;
-#endif
-
- delete checkbox;
-
- ms_sizeCheckMark.x = ms_sizeCheckMark.y = checkSize;
- }
-
- return ms_sizeCheckMark;
-}
-
-void wxGridCellBoolRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int row, int col,
- bool isSelected)
-{
- wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
-
- // draw a check mark in the centre (ignoring alignment - TODO)
- wxSize size = GetBestSize(grid, attr, dc, row, col);
-
- // don't draw outside the cell
- wxCoord minSize = wxMin(rect.width, rect.height);
- if ( size.x >= minSize || size.y >= minSize )
- {
- // and even leave (at least) 1 pixel margin
- size.x = size.y = minSize - 2;
- }
-
- // draw a border around checkmark
- wxRect rectMark;
- rectMark.x = rect.x + rect.width/2 - size.x/2;
- rectMark.y = rect.y + rect.height/2 - size.y/2;
- rectMark.width = size.x;
- rectMark.height = size.y;
-
- dc.SetBrush(*wxTRANSPARENT_BRUSH);
- dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID));
- dc.DrawRectangle(rectMark);
-
- rectMark.Inflate(-wxGRID_CHECKMARK_MARGIN);
-
-#ifdef __WXMSW__
- // looks nicer under MSW
- rectMark.x++;
-#endif // MSW
-
- bool value;
- if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
- value = grid.GetTable()->GetValueAsBool(row, col);
- else
- value = !!grid.GetTable()->GetValue(row, col);
-
- if ( value )
- {
- dc.SetTextForeground(attr.GetTextColour());
- dc.DrawCheckMark(rectMark);
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttr
-// ----------------------------------------------------------------------------
-
-const wxColour& wxGridCellAttr::GetTextColour() const
-{
- if (HasTextColour())
- {
- return m_colText;
- }
- else if (m_defGridAttr != this)
- {
- return m_defGridAttr->GetTextColour();
- }
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-
-const wxColour& wxGridCellAttr::GetBackgroundColour() const
-{
- if (HasBackgroundColour())
- return m_colBack;
- else if (m_defGridAttr != this)
- return m_defGridAttr->GetBackgroundColour();
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullColour;
- }
-}
-
-
-const wxFont& wxGridCellAttr::GetFont() const
-{
- if (HasFont())
- return m_font;
- else if (m_defGridAttr != this)
- return m_defGridAttr->GetFont();
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return wxNullFont;
- }
-}
-
-
-void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const
-{
- if (HasAlignment())
- {
- if ( hAlign ) *hAlign = m_hAlign;
- if ( vAlign ) *vAlign = m_vAlign;
- }
- else if (m_defGridAttr != this)
- m_defGridAttr->GetAlignment(hAlign, vAlign);
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));