-// ----------------------------------------------------------------------------
-// wxGridCellFloatEditor
-// ----------------------------------------------------------------------------
-
-void wxGridCellFloatEditor::Create(wxWindow* parent,
- wxWindowID id,
- wxEvtHandler* evtHandler)
-{
- wxGridCellTextEditor::Create(parent, id, evtHandler);
-
-#if wxUSE_VALIDATORS
- Text()->SetValidator(new wxTextValidator(wxFILTER_NUMERIC));
-#endif // wxUSE_VALIDATORS
-}
-
-void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
-{
- // first get the value
- wxGridTableBase *table = grid->GetTable();
- if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
- {
- m_valueOld = table->GetValueAsDouble(row, col);
- }
- else
- {
- wxFAIL_MSG( _T("this cell doesn't have float value") );
-
- return;
- }
-
- DoBeginEdit(GetString());
-}
-
-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;