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