+void wxGridCellTextEditor::SetParameters(const wxString& params)
+{
+ if ( !params )
+ {
+ // reset to default
+ m_maxChars = 0;
+ }
+ else
+ {
+ long tmp;
+ if ( !params.ToLong(&tmp) )
+ {
+ wxLogDebug(_T("Invalid wxGridCellTextEditor parameter string "
+ "'%s' ignored"), params.c_str());
+ }
+ else
+ {
+ m_maxChars = (size_t)tmp;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+// 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(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
+ {
+ wxString sValue = table->GetValue(row, col);
+ if (! sValue.ToLong(&m_valueOld))
+ {
+ 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,
+ 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 )
+ {
+ if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
+ grid->GetTable()->SetValueAsLong(row, col, value);
+ else
+ grid->GetTable()->SetValue(row, col, wxString::Format("%ld", 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();
+}
+
+void wxGridCellNumberEditor::SetParameters(const wxString& params)
+{
+ if ( !params )
+ {
+ // reset to default
+ m_min =
+ m_max = -1;
+ }
+ else
+ {
+ long tmp;
+ if ( params.BeforeFirst(_T(',')).ToLong(&tmp) )
+ {
+ m_min = (int)tmp;
+
+ if ( params.AfterFirst(_T(',')).ToLong(&tmp) )
+ {
+ m_max = (int)tmp;
+
+ // skip the error message below
+ return;
+ }
+ }
+
+ wxLogDebug(_T("Invalid wxGridCellNumberEditor parameter string "
+ "'%s' ignored"), params.c_str());
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxGridCellFloatEditor
+// ----------------------------------------------------------------------------
+
+void wxGridCellFloatEditor::Create(wxWindow* parent,
+ wxWindowID id,
+ wxEvtHandler* evtHandler)
+{
+ wxGridCellTextEditor::Create(parent, id, evtHandler);
+
+#if wxUSE_VALIDATORS
+ Text()->SetValidator(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
+ {
+ wxString sValue = table->GetValue(row, col);
+ if (! sValue.ToDouble(&m_valueOld))
+ {
+ wxFAIL_MSG( _T("this cell doesn't have float value") );
+ return;
+ }
+ }
+
+ DoBeginEdit(GetString());
+}
+
+bool wxGridCellFloatEditor::EndEdit(int row, int col,
+ wxGrid* grid)
+{
+ double value;
+ if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) )
+ {
+ if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
+ grid->GetTable()->SetValueAsDouble(row, col, value);
+ else
+ grid->GetTable()->SetValue(row, col, wxString::Format("%f", 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();
+}
+