void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) { wxASSERT_MSG(m_control, wxT("The wxGridCellEditor must be created first!")); if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) { m_value = grid->GetTable()->GetValueAsBool(row, col); } else { wxString cellval( grid->GetTable()->GetValue(row, col) ); if ( cellval == ms_stringValues[false] ) m_value = false; else if ( cellval == ms_stringValues[true] ) m_value = true; else { // do not try to be smart here and convert it to true or false // because we'll still overwrite it with something different and // this risks to be very surprising for the user code, let them // know about it wxFAIL_MSG( wxT("invalid value for a cell with bool editor!") ); } } CBox()->SetValue(m_value); CBox()->SetFocus(); }
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; } // draw a border around checkmark int vAlign, hAlign; attr.GetAlignment(&hAlign, &vAlign); wxRect rectBorder; if (hAlign == wxALIGN_CENTRE) { rectBorder.x = rect.x + rect.width / 2 - size.x / 2; rectBorder.y = rect.y + rect.height / 2 - size.y / 2; rectBorder.width = size.x; rectBorder.height = size.y; } else if (hAlign == wxALIGN_LEFT) { rectBorder.x = rect.x + 2; rectBorder.y = rect.y + rect.height / 2 - size.y / 2; rectBorder.width = size.x; rectBorder.height = size.y; } else if (hAlign == wxALIGN_RIGHT) { rectBorder.x = rect.x + rect.width - size.x - 2; rectBorder.y = rect.y + rect.height / 2 - size.y / 2; rectBorder.width = size.x; rectBorder.height = size.y; } bool value; if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) { value = grid.GetTable()->GetValueAsBool(row, col); } else { wxString cellval( grid.GetTable()->GetValue(row, col) ); value = wxGridCellBoolEditor::IsTrueValue(cellval); } int flags = 0; if (value) flags |= wxCONTROL_CHECKED; wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags ); }