spinctrl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/spinctrl.h
  3. // Purpose: wxSpinCtrlBase class
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 22.07.99
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_SPINCTRL_H_
  11. #define _WX_SPINCTRL_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_SPINCTRL
  14. #include "wx/spinbutt.h" // should make wxSpinEvent visible to the app
  15. // Events
  16. class WXDLLIMPEXP_FWD_CORE wxSpinDoubleEvent;
  17. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SPINCTRL, wxSpinEvent);
  18. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SPINCTRLDOUBLE, wxSpinDoubleEvent);
  19. // ----------------------------------------------------------------------------
  20. // A spin ctrl is a text control with a spin button which is usually used to
  21. // prompt the user for a numeric input.
  22. // There are two kinds for number types T=integer or T=double.
  23. // ----------------------------------------------------------------------------
  24. class WXDLLIMPEXP_CORE wxSpinCtrlBase : public wxControl
  25. {
  26. public:
  27. wxSpinCtrlBase() {}
  28. // accessor functions that derived classes are expected to have
  29. // T GetValue() const
  30. // T GetMin() const
  31. // T GetMax() const
  32. // T GetIncrement() const
  33. virtual bool GetSnapToTicks() const = 0;
  34. // unsigned GetDigits() const - wxSpinCtrlDouble only
  35. // operation functions that derived classes are expected to have
  36. virtual void SetValue(const wxString& value) = 0;
  37. // void SetValue(T val)
  38. // void SetRange(T minVal, T maxVal)
  39. // void SetIncrement(T inc)
  40. virtual void SetSnapToTicks(bool snap_to_ticks) = 0;
  41. // void SetDigits(unsigned digits) - wxSpinCtrlDouble only
  42. // The base for numbers display, e.g. 10 or 16.
  43. virtual int GetBase() const = 0;
  44. virtual bool SetBase(int base) = 0;
  45. // Select text in the textctrl
  46. virtual void SetSelection(long from, long to) = 0;
  47. private:
  48. wxDECLARE_NO_COPY_CLASS(wxSpinCtrlBase);
  49. };
  50. // ----------------------------------------------------------------------------
  51. // wxSpinDoubleEvent - a wxSpinEvent for double valued controls
  52. // ----------------------------------------------------------------------------
  53. class WXDLLIMPEXP_CORE wxSpinDoubleEvent : public wxNotifyEvent
  54. {
  55. public:
  56. wxSpinDoubleEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
  57. double value = 0)
  58. : wxNotifyEvent(commandType, winid), m_value(value)
  59. {
  60. }
  61. wxSpinDoubleEvent(const wxSpinDoubleEvent& event)
  62. : wxNotifyEvent(event), m_value(event.GetValue())
  63. {
  64. }
  65. double GetValue() const { return m_value; }
  66. void SetValue(double value) { m_value = value; }
  67. virtual wxEvent *Clone() const { return new wxSpinDoubleEvent(*this); }
  68. protected:
  69. double m_value;
  70. private:
  71. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSpinDoubleEvent)
  72. };
  73. // ----------------------------------------------------------------------------
  74. // wxSpinDoubleEvent event type, see also wxSpinEvent in wx/spinbutt.h
  75. // ----------------------------------------------------------------------------
  76. typedef void (wxEvtHandler::*wxSpinDoubleEventFunction)(wxSpinDoubleEvent&);
  77. #define wxSpinDoubleEventHandler(func) \
  78. wxEVENT_HANDLER_CAST(wxSpinDoubleEventFunction, func)
  79. // macros for handling spinctrl events
  80. #define EVT_SPINCTRL(id, fn) \
  81. wx__DECLARE_EVT1(wxEVT_SPINCTRL, id, wxSpinEventHandler(fn))
  82. #define EVT_SPINCTRLDOUBLE(id, fn) \
  83. wx__DECLARE_EVT1(wxEVT_SPINCTRLDOUBLE, id, wxSpinDoubleEventHandler(fn))
  84. // ----------------------------------------------------------------------------
  85. // include the platform-dependent class implementation
  86. // ----------------------------------------------------------------------------
  87. // we may have a native wxSpinCtrl implementation, native wxSpinCtrl and
  88. // wxSpinCtrlDouble implementations or neither, define the appropriate symbols
  89. // and include the generic version if necessary to provide the missing class(es)
  90. #if defined(__WXUNIVERSAL__)
  91. // nothing, use generic controls
  92. #elif defined(__WXMSW__)
  93. #define wxHAS_NATIVE_SPINCTRL
  94. #include "wx/msw/spinctrl.h"
  95. #elif defined(__WXPM__)
  96. #define wxHAS_NATIVE_SPINCTRL
  97. #include "wx/os2/spinctrl.h"
  98. #elif defined(__WXGTK20__)
  99. #define wxHAS_NATIVE_SPINCTRL
  100. #define wxHAS_NATIVE_SPINCTRLDOUBLE
  101. #include "wx/gtk/spinctrl.h"
  102. #elif defined(__WXGTK__)
  103. #define wxHAS_NATIVE_SPINCTRL
  104. #include "wx/gtk1/spinctrl.h"
  105. #endif // platform
  106. #if !defined(wxHAS_NATIVE_SPINCTRL) || !defined(wxHAS_NATIVE_SPINCTRLDOUBLE)
  107. #include "wx/generic/spinctlg.h"
  108. #endif
  109. namespace wxPrivate
  110. {
  111. // This is an internal helper function currently used by all ports: return the
  112. // string containing hexadecimal representation of the given number.
  113. extern wxString wxSpinCtrlFormatAsHex(long val, long maxVal);
  114. } // namespace wxPrivate
  115. // old wxEVT_COMMAND_* constants
  116. #define wxEVT_COMMAND_SPINCTRL_UPDATED wxEVT_SPINCTRL
  117. #define wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED wxEVT_SPINCTRLDOUBLE
  118. #endif // wxUSE_SPINCTRL
  119. #endif // _WX_SPINCTRL_H_