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