1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinCtrlBase class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SPINCTRL_H_
13 #define _WX_SPINCTRL_H_
19 #include "wx/spinbutt.h" // should make wxSpinEvent visible to the app
22 class WXDLLIMPEXP_FWD_CORE wxSpinDoubleEvent
;
24 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_SPINCTRL_UPDATED
, wxSpinEvent
);
25 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
, wxSpinDoubleEvent
);
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 // ----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxSpinCtrlBase
: public wxControl
38 // accessor functions that derived classes are expected to have
42 // T GetIncrement() const
43 virtual bool GetSnapToTicks() const = 0;
44 // unsigned GetDigits() const - wxSpinCtrlDouble only
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
54 // The base for numbers display, e.g. 10 or 16.
55 virtual int GetBase() const = 0;
56 virtual bool SetBase(int base
) = 0;
58 // Select text in the textctrl
59 virtual void SetSelection(long from
, long to
) = 0;
62 wxDECLARE_NO_COPY_CLASS(wxSpinCtrlBase
);
65 // ----------------------------------------------------------------------------
66 // wxSpinDoubleEvent - a wxSpinEvent for double valued controls
67 // ----------------------------------------------------------------------------
69 class WXDLLIMPEXP_CORE wxSpinDoubleEvent
: public wxNotifyEvent
72 wxSpinDoubleEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
74 : wxNotifyEvent(commandType
, winid
), m_value(value
)
78 wxSpinDoubleEvent(const wxSpinDoubleEvent
& event
)
79 : wxNotifyEvent(event
), m_value(event
.GetValue())
83 double GetValue() const { return m_value
; }
84 void SetValue(double value
) { m_value
= value
; }
86 virtual wxEvent
*Clone() const { return new wxSpinDoubleEvent(*this); }
92 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSpinDoubleEvent
)
95 // ----------------------------------------------------------------------------
96 // wxSpinDoubleEvent event type, see also wxSpinEvent in wx/spinbutt.h
97 // ----------------------------------------------------------------------------
99 typedef void (wxEvtHandler::*wxSpinDoubleEventFunction
)(wxSpinDoubleEvent
&);
101 #define wxSpinDoubleEventHandler(func) \
102 wxEVENT_HANDLER_CAST(wxSpinDoubleEventFunction, func)
104 // macros for handling spinctrl events
106 #define EVT_SPINCTRL(id, fn) \
107 wx__DECLARE_EVT1(wxEVT_COMMAND_SPINCTRL_UPDATED, id, wxSpinEventHandler(fn))
109 #define EVT_SPINCTRLDOUBLE(id, fn) \
110 wx__DECLARE_EVT1(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, id, wxSpinDoubleEventHandler(fn))
112 // ----------------------------------------------------------------------------
113 // include the platform-dependent class implementation
114 // ----------------------------------------------------------------------------
116 // we may have a native wxSpinCtrl implementation, native wxSpinCtrl and
117 // wxSpinCtrlDouble implementations or neither, define the appropriate symbols
118 // and include the generic version if necessary to provide the missing class(es)
120 #if defined(__WXUNIVERSAL__)
121 // nothing, use generic controls
122 #elif defined(__WXMSW__)
123 #define wxHAS_NATIVE_SPINCTRL
124 #include "wx/msw/spinctrl.h"
125 #elif defined(__WXPM__)
126 #define wxHAS_NATIVE_SPINCTRL
127 #include "wx/os2/spinctrl.h"
128 #elif defined(__WXGTK20__)
129 #define wxHAS_NATIVE_SPINCTRL
130 #define wxHAS_NATIVE_SPINCTRLDOUBLE
131 #include "wx/gtk/spinctrl.h"
132 #elif defined(__WXGTK__)
133 #define wxHAS_NATIVE_SPINCTRL
134 #include "wx/gtk1/spinctrl.h"
137 #if !defined(wxHAS_NATIVE_SPINCTRL) || !defined(wxHAS_NATIVE_SPINCTRLDOUBLE)
138 #include "wx/generic/spinctlg.h"
144 // This is an internal helper function currently used by all ports: return the
145 // string containing hexadecimal representation of the given number.
146 extern wxString
wxSpinCtrlFormatAsHex(long val
, long maxVal
);
148 } // namespace wxPrivate
150 #endif // wxUSE_SPINCTRL
152 #endif // _WX_SPINCTRL_H_