-void wxGridCellBoolEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- m_control = new wxCheckBox(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- wxNO_BORDER);
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellBoolEditor::SetSize(const wxRect& r)
-{
- // position it in the centre of the rectangle (TODO: support alignment?)
- wxCoord w, h;
- m_control->GetSize(&w, &h);
-
- // the checkbox without label still has some space to the right in wxGTK,
- // so shift it to the right
-#ifdef __WXGTK__
- w -= 8;
-#endif // GTK
-
- m_control->Move(r.x + r.width/2 - w/2, r.y + r.height/2 - h/2);
-}
-
-void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr)
-{
- m_control->Show(show);
-
- if ( show )
- {
- wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
- CBox()->SetBackgroundColour(colBg);
- }
-}
-
-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, wxT("bool")))
- m_startValue = grid->GetTable()->GetValueAsBool(row, col);
- else
- m_startValue = !!grid->GetTable()->GetValue(row, col);
- CBox()->SetValue(m_startValue);
- CBox()->SetFocus();
-}
-
-bool wxGridCellBoolEditor::EndEdit(int row, int col,
- bool saveValue,
- wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be Created first!"));
-
- bool changed = FALSE;
- bool value = CBox()->GetValue();
- if ( value != m_startValue )
- changed = TRUE;
-
- if ( changed )
- {
- if (grid->GetTable()->CanGetValueAs(row, col, wxT("bool")))
- grid->GetTable()->SetValueAsBool(row, col, value);
- else
- grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString);
- }
-
- return changed;
-}
-
-void wxGridCellBoolEditor::Reset()
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be Created first!"));
-
- CBox()->SetValue(m_startValue);
-}
-
-void wxGridCellBoolEditor::StartingClick()
-{
- CBox()->SetValue(!CBox()->GetValue());
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellEditorEvtHandler
-// ----------------------------------------------------------------------------
-
-void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
-{
- switch ( event.KeyCode() )
- {
- case WXK_ESCAPE:
- m_editor->Reset();
- m_grid->DisableCellEditControl();
- break;
-
- case WXK_TAB:
- event.Skip( m_grid->ProcessEvent( event ) );
- break;
-
- case WXK_RETURN:
- if (!m_grid->ProcessEvent(event))
- m_editor->HandleReturn(event);
- break;
-
-
- default:
- event.Skip();
- }
-}
-
-void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
-{
- switch ( event.KeyCode() )
- {
- case WXK_ESCAPE:
- case WXK_TAB:
- case WXK_RETURN:
- break;
-
- default:
- event.Skip();
- }
-}
-
-// ============================================================================
-// renderer classes
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// wxGridCellRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellRenderer::Draw(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- const wxRect& rect,
- int row, int col,
- bool isSelected)
-{
- dc.SetBackgroundMode( wxSOLID );
-
- if ( isSelected )
- {
- dc.SetBrush( wxBrush(grid.GetSelectionBackground(), wxSOLID) );
- }
- else
- {
- dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) );
- }
-
- dc.SetPen( *wxTRANSPARENT_PEN );
- dc.DrawRectangle(rect);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellStringRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellStringRenderer::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);
-
- // now we only have to draw the text
- dc.SetBackgroundMode( wxTRANSPARENT );
-
- // TODO some special colours for attr.IsReadOnly() case?
-
- if ( isSelected )
- {
- dc.SetTextBackground( grid.GetSelectionBackground() );
- dc.SetTextForeground( grid.GetSelectionForeground() );
- }
- else
- {
- dc.SetTextBackground( attr.GetBackgroundColour() );
- dc.SetTextForeground( attr.GetTextColour() );
- }
- dc.SetFont( attr.GetFont() );
-
- int hAlign, vAlign;
- attr.GetAlignment(&hAlign, &vAlign);
-
- wxRect rect = rectCell;
- rect.x++;
- rect.y++;
- rect.width -= 2;
- rect.height -= 2;
-
- grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
- rect, hAlign, vAlign);
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolRenderer
-// ----------------------------------------------------------------------------
-
-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);
-
- // between checkmark and box
- static const wxCoord margin = 4;
-
- // get checkbox size
- static wxCoord s_checkSize = 0;
- if ( s_checkSize == 0 )
- {
- // compute it only once (no locks for MT safeness in GUI thread...)
- wxCheckBox *checkbox = new wxCheckBox(&grid, -1, wxEmptyString);
- wxSize size = checkbox->GetBestSize();
- s_checkSize = size.y + margin;
-
- // FIXME wxGTK::wxCheckBox::GetBestSize() is really weird...
-#ifdef __WXGTK__
- s_checkSize -= size.y / 2;
-#endif
-
- delete checkbox;
- }
-
- // draw a check mark in the centre (ignoring alignment - TODO)
- wxRect rectMark;
- rectMark.x = rect.x + rect.width/2 - s_checkSize/2;
- rectMark.y = rect.y + rect.height/2 - s_checkSize/2;
- rectMark.width = rectMark.height = s_checkSize;
-
- dc.SetBrush(*wxTRANSPARENT_BRUSH);
- dc.SetPen(wxPen(attr.GetTextColour(), 1, wxSOLID));
- dc.DrawRectangle(rectMark);
-
- rectMark.Inflate(-margin);
-
- bool value;
- if (grid.GetTable()->CanGetValueAs(row, col, wxT("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"));
- }
-}
-
-
-// GetRenderer and GetEditor use a slightly different decision path about
-// which to use. If a non-default attr object has one then it is used,
-// otherwise the default editor or renderer passed in is used. It should be
-// the default for the data type of the cell. If it is NULL (because the
-// table has a type that the grid does not have in its registry,) then the
-// grid's default editor or renderer is used.
-
-wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGridCellRenderer* def) const
-{
- if ((m_defGridAttr != this || def == NULL) && HasRenderer())
- return m_renderer;
- else if (def)
- return def;
- else if (m_defGridAttr != this)
- return m_defGridAttr->GetRenderer(NULL);
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return NULL;
- }
-}
-
-wxGridCellEditor* wxGridCellAttr::GetEditor(wxGridCellEditor* def) const
-{
- if ((m_defGridAttr != this || def == NULL) && HasEditor())
- return m_editor;
- else if (def)
- return def;
- else if (m_defGridAttr != this)
- return m_defGridAttr->GetEditor(NULL);
- else
- {
- wxFAIL_MSG(wxT("Missing default cell attribute"));
- return NULL;
- }
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellAttrData
-// ----------------------------------------------------------------------------
-
-void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col)