// Send the correct event type
virtual void DoSendEvent() = 0;
+ // Convert the text to/from the corresponding value.
+ virtual bool DoTextToValue(const wxString& text, double *val) = 0;
+ virtual wxString DoValueToText(double val) = 0;
+
// check if the value is in range
bool InRange(double n) const { return (n >= m_min) && (n <= m_max); }
double m_max;
double m_increment;
bool m_snap_to_ticks;
- wxString m_format;
int m_spin_value;
protected:
virtual void DoSendEvent();
+ virtual bool DoTextToValue(const wxString& text, double *val);
+ virtual wxString DoValueToText(double val);
DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
};
class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGenericBase
{
public:
- wxSpinCtrlDouble() : m_digits(0) { }
+ wxSpinCtrlDouble() { Init(); }
wxSpinCtrlDouble(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxString& value = wxEmptyString,
double inc = 1,
const wxString& name = wxT("wxSpinCtrlDouble"))
{
- m_digits = 0;
+ Init();
+
Create(parent, id, value, pos, size, style,
min, max, initial, inc, name);
}
protected:
virtual void DoSendEvent();
+ virtual bool DoTextToValue(const wxString& text, double *val);
+ virtual wxString DoValueToText(double val);
+
unsigned m_digits;
+private:
+ // Common part of all ctors.
+ void Init()
+ {
+ m_digits = 0;
+ m_format = wxS("%g");
+ }
+
+ wxString m_format;
+
DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble)
};
m_max = 100;
m_increment = 1;
m_snap_to_ticks = false;
- m_format = wxS("%g");
m_spin_value = 0;
if ( !value.empty() )
{
double d;
- if ( value.ToDouble(&d) )
+ if ( DoTextToValue(value, &d) )
{
m_value = d;
- m_textCtrl->SetValue(wxString::Format(m_format, m_value));
+ m_textCtrl->SetValue(DoValueToText(m_value));
}
}
return false;
double textValue;
- if ( m_textCtrl->GetValue().ToDouble(&textValue) )
+ if ( DoTextToValue(m_textCtrl->GetValue(), &textValue) )
{
if (textValue > m_max)
textValue = m_max;
wxCHECK_RET( m_textCtrl, wxT("invalid call to wxSpinCtrl::SetValue") );
double val;
- if ( text.ToDouble(&val) && InRange(val) )
+ if ( DoTextToValue(text, &val) && InRange(val) )
{
DoSetValue(val);
}
}
}
- wxString str(wxString::Format(m_format.c_str(), val));
+ wxString str(DoValueToText(val));
if ((val != m_value) || (str != m_textCtrl->GetValue()))
{
- m_value = val;
- str.ToDouble( &m_value ); // wysiwyg for textctrl
+ if ( !DoTextToValue(str, &m_value ) ) // wysiwyg for textctrl
+ m_value = val;
m_textCtrl->SetValue( str );
m_textCtrl->SetInsertionPointEnd();
m_textCtrl->DiscardEdits();
GetEventHandler()->ProcessEvent( event );
}
+bool wxSpinCtrl::DoTextToValue(const wxString& text, double *val)
+{
+ long lval;
+ if ( !text.ToLong(&lval) )
+ return false;
+
+ *val = static_cast<double>(lval);
+
+ return true;
+}
+
+wxString wxSpinCtrl::DoValueToText(double val)
+{
+ return wxString::Format("%ld", static_cast<long>(val));
+}
+
#endif // !wxHAS_NATIVE_SPINCTRL
//-----------------------------------------------------------------------------
GetEventHandler()->ProcessEvent( event );
}
+bool wxSpinCtrlDouble::DoTextToValue(const wxString& text, double *val)
+{
+ return text.ToDouble(val);
+}
+
+wxString wxSpinCtrlDouble::DoValueToText(double val)
+{
+ return wxString::Format(m_format, val);
+}
+
void wxSpinCtrlDouble::SetDigits(unsigned digits)
{
wxCHECK_RET( digits <= 20, "too many digits for wxSpinCtrlDouble" );