-bool wxGridCellFloatEditor::EndEdit(int row, int col, bool saveValue,
- wxGrid* grid)
-{
- double value;
- if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) )
- {
- grid->GetTable()->SetValueAsDouble(row, col, value);
-
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-void wxGridCellFloatEditor::Reset()
-{
- DoReset(GetString());
-}
-
-void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
-{
- long keycode = event.KeyCode();
- if ( isdigit(keycode) ||
- keycode == '+' || keycode == '-' || keycode == '.' )
- {
- wxGridCellTextEditor::StartingKey(event);
-
- // skip Skip() below
- return;
- }
-
- event.Skip();
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellBoolEditor
-// ----------------------------------------------------------------------------
-
-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());
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellChoiceEditor
-// ----------------------------------------------------------------------------
-
-wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
- const wxChar* choices[],
- bool allowOthers)
- : m_allowOthers(allowOthers)
-{
- m_choices.Alloc(count);
- for ( size_t n = 0; n < count; n++ )
- {
- m_choices.Add(choices[n]);
- }
-}
-
-void wxGridCellChoiceEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- size_t count = m_choices.GetCount();
- wxString *choices = new wxString[count];
- for ( size_t n = 0; n < count; n++ )
- {
- choices[n] = m_choices[n];
- }
-
- m_control = new wxComboBox(parent, id, wxEmptyString,
- wxDefaultPosition, wxDefaultSize,
- count, choices,
- m_allowOthers ? 0 : wxCB_READONLY);
-
- delete [] choices;
-
- wxGridCellEditor::Create(parent, id, evtHandler);
-}
-
-void wxGridCellChoiceEditor::PaintBackground(const wxRect& WXUNUSED(rectCell),
- wxGridCellAttr * WXUNUSED(attr))
-{
- // as we fill the entire client area, don't do anything here to minimize
- // flicker
-}
-
-void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- wxASSERT_MSG(m_control,
- wxT("The wxGridCellEditor must be Created first!"));
-
- m_startValue = grid->GetTable()->GetValue(row, col);
-
- Combo()->SetValue(m_startValue);
- Combo()->SetInsertionPointEnd();
- Combo()->SetFocus();
-}
-
-bool wxGridCellChoiceEditor::EndEdit(int row, int col,
- bool saveValue,
- wxGrid* grid)
-{
- wxString value = Combo()->GetValue();
- bool changed = value != m_startValue;
-
- if ( changed )
- grid->GetTable()->SetValue(row, col, value);
-
- m_startValue = wxEmptyString;
- Combo()->SetValue(m_startValue);
-
- return changed;
-}
-
-void wxGridCellChoiceEditor::Reset()
-{
- Combo()->SetValue(m_startValue);
- Combo()->SetInsertionPointEnd();
-}
-
-// ----------------------------------------------------------------------------
-// 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);
-}
-
-wxGridCellRenderer::~wxGridCellRenderer()
-{
-}
-
-// ----------------------------------------------------------------------------
-// wxGridCellStringRenderer
-// ----------------------------------------------------------------------------
-
-void wxGridCellStringRenderer::SetTextColoursAndFont(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- bool isSelected)
-{
- 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() );
-}
-
-wxSize wxGridCellStringRenderer::DoGetBestSize(wxGridCellAttr& attr,
- wxDC& dc,
- const wxString& text)
-{
- wxCoord x, y;
- dc.SetFont(attr.GetFont());
- dc.GetTextExtent(text, &x, &y);
-
- return wxSize(x, y);
-}
-
-wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid,
- wxGridCellAttr& attr,
- wxDC& dc,
- int row, int col)
-{
- return DoGetBestSize(attr, dc, grid.GetCellValue(row, col));
-}