1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinCtrlBase class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_SPINCTRL_H_
12 #define _WX_SPINCTRL_H_
18 #include "wx/spinbutt.h" // should make wxSpinEvent visible to the app
21 class WXDLLIMPEXP_FWD_CORE wxSpinDoubleEvent
;
23 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE
, wxEVT_SPINCTRL
, wxSpinEvent
);
24 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE
, wxEVT_SPINCTRLDOUBLE
, wxSpinDoubleEvent
);
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 // ----------------------------------------------------------------------------
32 class WXDLLIMPEXP_CORE wxSpinCtrlBase
: public wxControl
37 // accessor functions that derived classes are expected to have
41 // T GetIncrement() const
42 virtual bool GetSnapToTicks() const = 0;
43 // unsigned GetDigits() const - wxSpinCtrlDouble only
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
53 // The base for numbers display, e.g. 10 or 16.
54 virtual int GetBase() const = 0;
55 virtual bool SetBase(int base
) = 0;
57 // Select text in the textctrl
58 virtual void SetSelection(long from
, long to
) = 0;
61 wxDECLARE_NO_COPY_CLASS(wxSpinCtrlBase
);
64 // ----------------------------------------------------------------------------
65 // wxSpinDoubleEvent - a wxSpinEvent for double valued controls
66 // ----------------------------------------------------------------------------
68 class WXDLLIMPEXP_CORE wxSpinDoubleEvent
: public wxNotifyEvent
71 wxSpinDoubleEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
73 : wxNotifyEvent(commandType
, winid
), m_value(value
)
77 wxSpinDoubleEvent(const wxSpinDoubleEvent
& event
)
78 : wxNotifyEvent(event
), m_value(event
.GetValue())
82 double GetValue() const { return m_value
; }
83 void SetValue(double value
) { m_value
= value
; }
85 virtual wxEvent
*Clone() const { return new wxSpinDoubleEvent(*this); }
91 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSpinDoubleEvent
)
94 // ----------------------------------------------------------------------------
95 // wxSpinDoubleEvent event type, see also wxSpinEvent in wx/spinbutt.h
96 // ----------------------------------------------------------------------------
98 typedef void (wxEvtHandler::*wxSpinDoubleEventFunction
)(wxSpinDoubleEvent
&);
100 #define wxSpinDoubleEventHandler(func) \
101 wxEVENT_HANDLER_CAST(wxSpinDoubleEventFunction, func)
103 // macros for handling spinctrl events
105 #define EVT_SPINCTRL(id, fn) \
106 wx__DECLARE_EVT1(wxEVT_SPINCTRL, id, wxSpinEventHandler(fn))
108 #define EVT_SPINCTRLDOUBLE(id, fn) \
109 wx__DECLARE_EVT1(wxEVT_SPINCTRLDOUBLE, id, wxSpinDoubleEventHandler(fn))
111 // ----------------------------------------------------------------------------
112 // include the platform-dependent class implementation
113 // ----------------------------------------------------------------------------
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)
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"
136 #if !defined(wxHAS_NATIVE_SPINCTRL) || !defined(wxHAS_NATIVE_SPINCTRLDOUBLE)
137 #include "wx/generic/spinctlg.h"
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
);
147 } // namespace wxPrivate
149 // old wxEVT_COMMAND_* constants
150 #define wxEVT_COMMAND_SPINCTRL_UPDATED wxEVT_SPINCTRL
151 #define wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED wxEVT_SPINCTRLDOUBLE
153 #endif // wxUSE_SPINCTRL
155 #endif // _WX_SPINCTRL_H_