X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f0cbaaa4ab3037587fa796d38e7eaf16ed54933..ca77701441e39245dcbfce903049e76f166979e5:/include/wx/generic/spinctlg.h?ds=sidebyside diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index bdd0d4e55e..f5f52a56bb 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -22,6 +22,8 @@ #if wxUSE_SPINBTN +#include "wx/compositewin.h" + class WXDLLIMPEXP_FWD_CORE wxSpinButton; class WXDLLIMPEXP_FWD_CORE wxTextCtrl; @@ -40,7 +42,8 @@ class wxSpinCtrlTextGeneric; // wxTextCtrl used for the wxSpinCtrlGenericBase // function ambiguity. // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxSpinCtrlGenericBase : public wxSpinCtrlBase +class WXDLLIMPEXP_CORE wxSpinCtrlGenericBase + : public wxCompositeWindow { public: wxSpinCtrlGenericBase() { Init(); } @@ -50,9 +53,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(); @@ -80,7 +84,9 @@ public: // forward these functions to all subcontrols 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,36 +94,61 @@ 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: // override the base class virtuals involved into geometry calculations virtual wxSize DoGetBestSize() const; + virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const; virtual void DoMoveWindow(int x, int y, int width, int height); +#ifdef __WXMSW__ + // and, for MSW, enabling this window itself + virtual void DoEnable(bool enable); +#endif // __WXMSW__ + // generic double valued functions double DoGetValue() const { return m_value; } bool DoSetValue(double val); 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; + // 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); } + // 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; double m_increment; bool m_snap_to_ticks; - wxString m_format; int m_spin_value; @@ -128,6 +159,11 @@ protected: private: // common part of all ctors void Init(); + + // Implement pure virtual function inherited from wxCompositeWindow. + virtual wxWindowList GetCompositeWindowParts() const; + + DECLARE_EVENT_TABLE() }; #else // !wxUSE_SPINBTN @@ -152,9 +188,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 +218,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 +236,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; @@ -221,16 +267,18 @@ protected: class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGenericBase { public: - wxSpinCtrl() {} + wxSpinCtrl() { Init(); } wxSpinCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, 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")) { + Init(); + Create(parent, id, value, pos, size, style, min, max, initial, name); } @@ -239,29 +287,45 @@ 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); } + + virtual int GetBase() const { return m_base; } + virtual bool SetBase(int base); protected: virtual void DoSendEvent(); + virtual bool DoTextToValue(const wxString& text, double *val); + virtual wxString DoValueToText(double val); + private: + // Common part of all ctors. + void Init() + { + m_base = 10; + } + + int m_base; + DECLARE_DYNAMIC_CLASS(wxSpinCtrl) }; @@ -274,18 +338,21 @@ private: class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGenericBase { public: - wxSpinCtrlDouble() : m_digits(0) { } + wxSpinCtrlDouble() { Init(); } wxSpinCtrlDouble(wxWindow *parent, wxWindowID id = wxID_ANY, 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); + Init(); + + Create(parent, id, value, pos, size, style, + min, max, initial, inc, name); } bool Create(wxWindow *parent, @@ -293,11 +360,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,18 +378,36 @@ 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); } void SetDigits(unsigned digits); + // We don't implement bases support for floating point numbers, this is not + // very useful in practice. + virtual int GetBase() const { return 10; } + virtual bool SetBase(int WXUNUSED(base)) { return 0; } + 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) };