spinbutt.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/spinbutt.h
  3. // Purpose: wxSpinButtonBase class
  4. // Author: Julian Smart, Vadim Zeitlin
  5. // Modified by:
  6. // Created: 23.07.99
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_SPINBUTT_H_BASE_
  11. #define _WX_SPINBUTT_H_BASE_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/defs.h"
  16. #if wxUSE_SPINBTN
  17. #include "wx/control.h"
  18. #include "wx/event.h"
  19. #include "wx/range.h"
  20. #define wxSPIN_BUTTON_NAME wxT("wxSpinButton")
  21. // ----------------------------------------------------------------------------
  22. // The wxSpinButton is like a small scrollbar than is often placed next
  23. // to a text control.
  24. //
  25. // Styles:
  26. // wxSP_HORIZONTAL: horizontal spin button
  27. // wxSP_VERTICAL: vertical spin button (the default)
  28. // wxSP_ARROW_KEYS: arrow keys increment/decrement value
  29. // wxSP_WRAP: value wraps at either end
  30. // ----------------------------------------------------------------------------
  31. class WXDLLIMPEXP_CORE wxSpinButtonBase : public wxControl
  32. {
  33. public:
  34. // ctor initializes the range with the default (0..100) values
  35. wxSpinButtonBase() { m_min = 0; m_max = 100; }
  36. // accessors
  37. virtual int GetValue() const = 0;
  38. virtual int GetMin() const { return m_min; }
  39. virtual int GetMax() const { return m_max; }
  40. wxRange GetRange() const { return wxRange( GetMin(), GetMax() );}
  41. // operations
  42. virtual void SetValue(int val) = 0;
  43. virtual void SetMin(int minVal) { SetRange ( minVal , m_max ) ; }
  44. virtual void SetMax(int maxVal) { SetRange ( m_min , maxVal ) ; }
  45. virtual void SetRange(int minVal, int maxVal)
  46. {
  47. m_min = minVal;
  48. m_max = maxVal;
  49. }
  50. void SetRange( const wxRange& range) { SetRange( range.GetMin(), range.GetMax()); }
  51. // is this spin button vertically oriented?
  52. bool IsVertical() const { return (m_windowStyle & wxSP_VERTICAL) != 0; }
  53. protected:
  54. // the range value
  55. int m_min;
  56. int m_max;
  57. wxDECLARE_NO_COPY_CLASS(wxSpinButtonBase);
  58. };
  59. // ----------------------------------------------------------------------------
  60. // include the declaration of the real class
  61. // ----------------------------------------------------------------------------
  62. #if defined(__WXUNIVERSAL__)
  63. #include "wx/univ/spinbutt.h"
  64. #elif defined(__WXMSW__)
  65. #include "wx/msw/spinbutt.h"
  66. #elif defined(__WXMOTIF__)
  67. #include "wx/motif/spinbutt.h"
  68. #elif defined(__WXGTK20__)
  69. #include "wx/gtk/spinbutt.h"
  70. #elif defined(__WXGTK__)
  71. #include "wx/gtk1/spinbutt.h"
  72. #elif defined(__WXMAC__)
  73. #include "wx/osx/spinbutt.h"
  74. #elif defined(__WXCOCOA__)
  75. #include "wx/cocoa/spinbutt.h"
  76. #elif defined(__WXPM__)
  77. #include "wx/os2/spinbutt.h"
  78. #endif
  79. // ----------------------------------------------------------------------------
  80. // the wxSpinButton event
  81. // ----------------------------------------------------------------------------
  82. class WXDLLIMPEXP_CORE wxSpinEvent : public wxNotifyEvent
  83. {
  84. public:
  85. wxSpinEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
  86. : wxNotifyEvent(commandType, winid)
  87. {
  88. }
  89. wxSpinEvent(const wxSpinEvent& event) : wxNotifyEvent(event) {}
  90. // get the current value of the control
  91. int GetValue() const { return m_commandInt; }
  92. void SetValue(int value) { m_commandInt = value; }
  93. int GetPosition() const { return m_commandInt; }
  94. void SetPosition(int pos) { m_commandInt = pos; }
  95. virtual wxEvent *Clone() const { return new wxSpinEvent(*this); }
  96. private:
  97. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSpinEvent)
  98. };
  99. typedef void (wxEvtHandler::*wxSpinEventFunction)(wxSpinEvent&);
  100. #define wxSpinEventHandler(func) \
  101. wxEVENT_HANDLER_CAST(wxSpinEventFunction, func)
  102. // macros for handling spin events: notice that we must use the real values of
  103. // the event type constants and not their references (wxEVT_SPIN[_UP/DOWN])
  104. // here as otherwise the event tables could end up with non-initialized
  105. // (because of undefined initialization order of the globals defined in
  106. // different translation units) references in them
  107. #define EVT_SPIN_UP(winid, func) \
  108. wx__DECLARE_EVT1(wxEVT_SPIN_UP, winid, wxSpinEventHandler(func))
  109. #define EVT_SPIN_DOWN(winid, func) \
  110. wx__DECLARE_EVT1(wxEVT_SPIN_DOWN, winid, wxSpinEventHandler(func))
  111. #define EVT_SPIN(winid, func) \
  112. wx__DECLARE_EVT1(wxEVT_SPIN, winid, wxSpinEventHandler(func))
  113. #endif // wxUSE_SPINBTN
  114. #endif
  115. // _WX_SPINBUTT_H_BASE_