+// ----------------------------------------------------------------------------
+// wxGridCellNumberEditor
+// ----------------------------------------------------------------------------
+
+wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max)
+{
+ m_min = min;
+ m_max = max;
+}
+
+void wxGridCellNumberEditor::Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler)
+{
+ if ( HasRange() )
+ {
+ // create a spin ctrl
+ m_control = new wxSpinCtrl(parent, -1, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize,
+ wxSP_ARROW_KEYS,
+ m_min, m_max);
+
+ wxGridCellEditor::Create(parent, id, evtHandler);
+ }
+ else
+ {
+ // just a text control
+ wxGridCellTextEditor::Create(parent, id, evtHandler);
+
+#if wxUSE_VALIDATORS
+ Text()->SetValidator(new wxTextValidator(wxFILTER_NUMERIC));
+#endif // wxUSE_VALIDATORS
+ }
+}
+
+void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
+{
+ // first get the value
+ wxGridTableBase *table = grid->GetTable();
+ if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
+ {
+ m_valueOld = table->GetValueAsLong(row, col);
+ }
+ else
+ {
+ wxFAIL_MSG( _T("this cell doesn't have numeric value") );
+
+ return;
+ }
+
+ if ( HasRange() )
+ {
+ Spin()->SetValue(m_valueOld);
+ }
+ else
+ {
+ DoBeginEdit(GetString());
+ }
+}
+
+bool wxGridCellNumberEditor::EndEdit(int row, int col, bool saveValue,
+ wxGrid* grid)
+{
+ bool changed;
+ long value;
+
+ if ( HasRange() )
+ {
+ value = Spin()->GetValue();
+ changed = value != m_valueOld;
+ }
+ else
+ {
+ changed = Text()->GetValue().ToLong(&value) && (value != m_valueOld);
+ }
+
+ if ( changed )
+ {
+ grid->GetTable()->SetValueAsLong(row, col, value);
+ }
+
+ return changed;
+}
+
+void wxGridCellNumberEditor::Reset()
+{
+ if ( HasRange() )
+ {
+ Spin()->SetValue(m_valueOld);
+ }
+ else
+ {
+ DoReset(GetString());
+ }
+}
+
+void wxGridCellNumberEditor::StartingKey(wxKeyEvent& event)
+{
+ if ( !HasRange() )
+ {
+ long keycode = event.KeyCode();
+ if ( isdigit(keycode) || keycode == '+' || keycode == '-' )
+ {
+ wxGridCellTextEditor::StartingKey(event);
+
+ // skip Skip() below
+ return;
+ }
+ }
+
+ event.Skip();
+}
+// ----------------------------------------------------------------------------
+// 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();
+}
+