wxSize TimeRenderer::GetBestSize(wxGrid &grid, wxGridCellAttr & WXUNUSED(attr), wxDC & WXUNUSED(dc), int row, int col) { wxGridTableBase *table = grid.GetTable(); TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col); wxSize sz; if (te) { double value; table->GetValue(row, col).ToDouble(&value); NumericTextCtrl tt(NumericConverter::TIME, &grid, wxID_ANY, te->GetFormat(), value, te->GetRate(), wxPoint(10000, 10000), // create offscreen wxDefaultSize, true); sz = tt.GetSize(); te->DecRef(); } return sz; }
wxSize TimeRenderer::GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) { wxGridTableBase *table = grid.GetTable(); TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col); wxSize sz; if (te) { double value; table->GetValue(row, col).ToDouble(&value); TimeTextCtrl tt(&grid, wxID_ANY, wxT(""), value, te->GetRate(), wxPoint(10000, 10000), // create offscreen wxDefaultSize, true); tt.SetFormatString(tt.GetBuiltinFormat(te->GetFormat())); sz = tt.GetSize(); te->DecRef(); } return sz; }
// Gets the name of the specified object. wxAccStatus GridAx::GetName(int childId, wxString *name) { int row; int col; if (GetRowCol(childId, row, col)) { wxString n = mGrid->GetColLabelValue(col); wxString v = mGrid->GetCellValue(row, col); if (v.IsEmpty()) { v = _("Empty"); } // Hack to provide a more intelligible response TimeEditor *d = (TimeEditor *)mGrid->GetDefaultEditorForType(GRID_VALUE_TIME); TimeEditor *c = (TimeEditor *)mGrid->GetCellEditor(row, col); if (c && d && c == d) { double value; v.ToDouble(&value); TimeTextCtrl tt(mGrid, wxID_ANY, wxT(""), value, c->GetRate(), wxPoint(10000, 10000), // create offscreen wxDefaultSize, true); tt.SetFormatString(tt.GetBuiltinFormat(c->GetFormat())); v = tt.GetTimeString(); } if (c) c->DecRef(); if (d) d->DecRef(); *name = n + wxT(" ") + v; } return wxACC_OK; }
void TimeRenderer::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); wxGridTableBase *table = grid.GetTable(); TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col); wxString tstr; if (te) { double value; table->GetValue(row, col).ToDouble(&value); NumericTextCtrl tt(NumericConverter::TIME, &grid, wxID_ANY, te->GetFormat(), value, te->GetRate(), wxPoint(10000, 10000), // create offscreen wxDefaultSize, true); tstr = tt.GetString(); te->DecRef(); } dc.SetBackgroundMode(wxTRANSPARENT); if (grid.IsEnabled()) { if (isSelected) { dc.SetTextBackground(grid.GetSelectionBackground()); dc.SetTextForeground(grid.GetSelectionForeground()); } else { dc.SetTextBackground(attr.GetBackgroundColour()); dc.SetTextForeground(attr.GetTextColour()); } } else { dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); } dc.SetFont(attr.GetFont()); int hAlign, vAlign; attr.GetAlignment(&hAlign, &vAlign); grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign); }