X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f0cbaaa4ab3037587fa796d38e7eaf16ed54933..1f0acb435592470b421b80df854fbbb08cd2853f:/include/wx/generic/spinctlg.h?ds=sidebyside diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index bdd0d4e55e..338dd70234 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -50,9 +50,10 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - double min = 0, double max = 100, double initial = 0, double inc = 1, - const wxString& name = _T("wxSpinCtrl")); + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, + double min = 0, double max = 100, double initial = 0, + double inc = 1, + const wxString& name = wxT("wxSpinCtrl")); virtual ~wxSpinCtrlGenericBase(); @@ -81,6 +82,9 @@ public: virtual bool Enable(bool enable = true); virtual bool Show(bool show = true); virtual bool Reparent(wxWindowBase *newParent); +#if wxUSE_TOOLTIPS + virtual void DoSetToolTip(wxToolTip *tip); +#endif // wxUSE_TOOLTIPS // get the subcontrols wxTextCtrl *GetText() const { return m_textCtrl; } @@ -88,9 +92,15 @@ public: // forwarded events from children windows void OnSpinButton(wxSpinEvent& event); - void OnTextEnter(wxCommandEvent& event); + void OnTextLostFocus(wxFocusEvent& event); void OnTextChar(wxKeyEvent& event); + // this window itself is used only as a container for its sub windows so it + // shouldn't accept the focus at all and any attempts to explicitly set + // focus to it should give focus to its text constol part + virtual bool AcceptsFocus() const { return false; } + virtual void SetFocus(); + friend class wxSpinCtrlTextGeneric; protected: @@ -104,14 +114,24 @@ protected: void DoSetRange(double min_val, double max_val); void DoSetIncrement(double inc); - // Ensure that the textctrl shows correct value - void SyncSpinToText(); + // update our value to reflect the text control contents (if it has been + // modified by user, do nothing otherwise) + // + // can also change the text control if its value is invalid + // + // return true if our value has changed + bool SyncSpinToText(); // Send the correct event type virtual void DoSendEvent() = 0; + // check if the value is in range bool InRange(double n) const { return (n >= m_min) && (n <= m_max); } + // ensure that the value is in range wrapping it round if necessary + double AdjustToFitInRange(double value) const; + + double m_value; double m_min; double m_max; @@ -128,6 +148,8 @@ protected: private: // common part of all ctors void Init(); + + DECLARE_EVENT_TABLE() }; #else // !wxUSE_SPINBTN @@ -152,9 +174,10 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - double min = 0, double max = 100, double initial = 0, double inc = 1, - const wxString& name = _T("wxSpinCtrl")) + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, + double min = 0, double max = 100, double initial = 0, + double inc = 1, + const wxString& name = wxT("wxSpinCtrl")) { m_min = min; m_max = max; @@ -181,7 +204,8 @@ public: // void SetValue(T val) // void SetRange(T minVal, T maxVal) // void SetIncrement(T inc) - virtual void SetSnapToTicks(bool snap_to_ticks) { m_snap_to_ticks = snap_to_ticks; } + virtual void SetSnapToTicks(bool snap_to_ticks) + { m_snap_to_ticks = snap_to_ticks; } // void SetDigits(unsigned digits) - wxSpinCtrlDouble only // Select text in the textctrl @@ -198,8 +222,16 @@ protected: return n; } - bool DoSetValue(double val) { wxTextCtrl::SetValue(wxString::Format(m_format.c_str(), val)); return true; } - void DoSetRange(double min_val, double max_val) { m_min = min_val; m_max = max_val; } + bool DoSetValue(double val) + { + wxTextCtrl::SetValue(wxString::Format(m_format.c_str(), val)); + return true; + } + void DoSetRange(double min_val, double max_val) + { + m_min = min_val; + m_max = max_val; + } void DoSetIncrement(double inc) { m_increment = inc; } // Note: unused double m_value; @@ -227,9 +259,9 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, int min = 0, int max = 100, int initial = 0, - const wxString& name = _T("wxSpinCtrl")) + const wxString& name = wxT("wxSpinCtrl")) { Create(parent, id, value, pos, size, style, min, max, initial, name); } @@ -239,29 +271,30 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, int min = 0, int max = 100, int initial = 0, - const wxString& name = _T("wxSpinCtrl")) + const wxString& name = wxT("wxSpinCtrl")) { - return wxSpinCtrlGenericBase::Create(parent, id, value, pos, size, style, min, max, initial, 1, name); + return wxSpinCtrlGenericBase::Create(parent, id, value, pos, size, + style, min, max, initial, 1, name); } // accessors - int GetValue(wxSPINCTRL_GETVALUE_FIX) const { return int(DoGetValue() + 0.5); } - int GetMin() const { return int(m_min + 0.5); } - int GetMax() const { return int(m_max + 0.5); } - int GetIncrement() const { return int(m_increment + 0.5); } + int GetValue(wxSPINCTRL_GETVALUE_FIX) const { return int(DoGetValue()); } + int GetMin() const { return int(m_min); } + int GetMax() const { return int(m_max); } + int GetIncrement() const { return int(m_increment); } // operations - void SetValue(const wxString& value) { wxSpinCtrlGenericBase::SetValue(value); } // visibility problem w/ gcc + void SetValue(const wxString& value) + { wxSpinCtrlGenericBase::SetValue(value); } void SetValue( int value ) { DoSetValue(value); } void SetRange( int minVal, int maxVal ) { DoSetRange(minVal, maxVal); } - void SetIncrement( double inc ) { DoSetIncrement(inc); } + void SetIncrement(int inc) { DoSetIncrement(inc); } protected: virtual void DoSendEvent(); -private: DECLARE_DYNAMIC_CLASS(wxSpinCtrl) }; @@ -280,12 +313,14 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - double min = 0, double max = 100, double initial = 0, double inc = 1, - const wxString& name = _T("wxSpinCtrlDouble")) + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, + double min = 0, double max = 100, double initial = 0, + double inc = 1, + const wxString& name = wxT("wxSpinCtrlDouble")) { m_digits = 0; - Create(parent, id, value, pos, size, style, min, max, initial, inc, name); + Create(parent, id, value, pos, size, style, + min, max, initial, inc, name); } bool Create(wxWindow *parent, @@ -293,11 +328,14 @@ public: const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - double min = 0, double max = 100, double initial = 0, double inc = 1, - const wxString& name = _T("wxSpinCtrlDouble")) + long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT, + double min = 0, double max = 100, double initial = 0, + double inc = 1, + const wxString& name = wxT("wxSpinCtrlDouble")) { - return wxSpinCtrlGenericBase::Create(parent, id, value, pos, size, style, min, max, initial, inc, name); + return wxSpinCtrlGenericBase::Create(parent, id, value, pos, size, + style, min, max, initial, + inc, name); } // accessors @@ -308,7 +346,8 @@ public: unsigned GetDigits() const { return m_digits; } // operations - void SetValue(const wxString& value) { wxSpinCtrlGenericBase::SetValue(value); } // visibility problem w/ gcc + void SetValue(const wxString& value) + { wxSpinCtrlGenericBase::SetValue(value); } void SetValue(double value) { DoSetValue(value); } void SetRange(double minVal, double maxVal) { DoSetRange(minVal, maxVal); } void SetIncrement(double inc) { DoSetIncrement(inc); } @@ -319,7 +358,6 @@ protected: unsigned m_digits; -private: DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble) };