Refactor text to/from double conversion in wxSpinCtrlGenericBase.
The code always used ToDouble() and Format("%g") which was a bit strange for integer-valued wxSpinCtrl. Move the conversions to their own virtual functions for clarity, perhaps correctness and, especially, flexibility as they will be overridden in wxSpinCtrl soon. Also move wxSpinCtrlGenericBase::m_format to wxSpinCtrlDouble as the base class really doesn't need it at all. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72412 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -129,6 +129,10 @@ protected:
|
||||
// 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); }
|
||||
|
||||
@@ -141,7 +145,6 @@ protected:
|
||||
double m_max;
|
||||
double m_increment;
|
||||
bool m_snap_to_ticks;
|
||||
wxString m_format;
|
||||
|
||||
int m_spin_value;
|
||||
|
||||
@@ -299,6 +302,8 @@ public:
|
||||
protected:
|
||||
virtual void DoSendEvent();
|
||||
|
||||
virtual bool DoTextToValue(const wxString& text, double *val);
|
||||
virtual wxString DoValueToText(double val);
|
||||
DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
|
||||
};
|
||||
|
||||
@@ -311,7 +316,7 @@ protected:
|
||||
class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGenericBase
|
||||
{
|
||||
public:
|
||||
wxSpinCtrlDouble() : m_digits(0) { }
|
||||
wxSpinCtrlDouble() { Init(); }
|
||||
wxSpinCtrlDouble(wxWindow *parent,
|
||||
wxWindowID id = wxID_ANY,
|
||||
const wxString& value = wxEmptyString,
|
||||
@@ -322,7 +327,8 @@ public:
|
||||
double inc = 1,
|
||||
const wxString& name = wxT("wxSpinCtrlDouble"))
|
||||
{
|
||||
m_digits = 0;
|
||||
Init();
|
||||
|
||||
Create(parent, id, value, pos, size, style,
|
||||
min, max, initial, inc, name);
|
||||
}
|
||||
@@ -360,8 +366,21 @@ public:
|
||||
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)
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user