]> git.saurik.com Git - wxWidgets.git/blame - include/wx/spinctrl.h
Better name for wxXmlResource::GetDirection() argument.
[wxWidgets.git] / include / wx / spinctrl.h
CommitLineData
b782f2e0 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/spinctrl.h
b782f2e0
VZ
3// Purpose: wxSpinCtrlBase class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 22.07.99
b782f2e0 7// Copyright: (c) Vadim Zeitlin
65571936 8// Licence: wxWindows licence
b782f2e0
VZ
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_SPINCTRL_H_
12#define _WX_SPINCTRL_H_
13
2ecf902b
WS
14#include "wx/defs.h"
15
16#if wxUSE_SPINCTRL
17
9d9b7755 18#include "wx/spinbutt.h" // should make wxSpinEvent visible to the app
b782f2e0 19
3c778901
VZ
20// Events
21class WXDLLIMPEXP_FWD_CORE wxSpinDoubleEvent;
22
ce7fe42e
VZ
23wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SPINCTRL, wxSpinEvent);
24wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SPINCTRLDOUBLE, wxSpinDoubleEvent);
3c778901 25
b782f2e0 26// ----------------------------------------------------------------------------
8cd6a9ad
VZ
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.
b782f2e0
VZ
30// ----------------------------------------------------------------------------
31
53a2db12 32class WXDLLIMPEXP_CORE wxSpinCtrlBase : public wxControl
b782f2e0
VZ
33{
34public:
8cd6a9ad 35 wxSpinCtrlBase() {}
b782f2e0 36
8cd6a9ad
VZ
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
b782f2e0 44
8cd6a9ad 45 // operation functions that derived classes are expected to have
36f210c8 46 virtual void SetValue(const wxString& value) = 0;
8cd6a9ad
VZ
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
b782f2e0 52
9e565667
VZ
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
8cd6a9ad 57 // Select text in the textctrl
14bc59a2
VZ
58 virtual void SetSelection(long from, long to) = 0;
59
8cd6a9ad 60private:
c0c133e1 61 wxDECLARE_NO_COPY_CLASS(wxSpinCtrlBase);
8cd6a9ad
VZ
62};
63
64// ----------------------------------------------------------------------------
65// wxSpinDoubleEvent - a wxSpinEvent for double valued controls
66// ----------------------------------------------------------------------------
67
53a2db12 68class WXDLLIMPEXP_CORE wxSpinDoubleEvent : public wxNotifyEvent
8cd6a9ad
VZ
69{
70public:
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
b782f2e0 87protected:
8cd6a9ad 88 double m_value;
b782f2e0 89
8cd6a9ad
VZ
90private:
91 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSpinDoubleEvent)
b782f2e0 92};
8cd6a9ad
VZ
93
94// ----------------------------------------------------------------------------
95// wxSpinDoubleEvent event type, see also wxSpinEvent in wx/spinbutt.h
96// ----------------------------------------------------------------------------
97
98typedef void (wxEvtHandler::*wxSpinDoubleEventFunction)(wxSpinDoubleEvent&);
99
100#define wxSpinDoubleEventHandler(func) \
3c778901 101 wxEVENT_HANDLER_CAST(wxSpinDoubleEventFunction, func)
8cd6a9ad
VZ
102
103// macros for handling spinctrl events
104
105#define EVT_SPINCTRL(id, fn) \
ce7fe42e 106 wx__DECLARE_EVT1(wxEVT_SPINCTRL, id, wxSpinEventHandler(fn))
8cd6a9ad
VZ
107
108#define EVT_SPINCTRLDOUBLE(id, fn) \
ce7fe42e 109 wx__DECLARE_EVT1(wxEVT_SPINCTRLDOUBLE, id, wxSpinDoubleEventHandler(fn))
b782f2e0
VZ
110
111// ----------------------------------------------------------------------------
112// include the platform-dependent class implementation
113// ----------------------------------------------------------------------------
114
8cd6a9ad
VZ
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
36090ae5 119#if defined(__WXUNIVERSAL__)
8cd6a9ad 120 // nothing, use generic controls
3a5bcc4d 121#elif defined(__WXMSW__)
8cd6a9ad 122 #define wxHAS_NATIVE_SPINCTRL
b782f2e0 123 #include "wx/msw/spinctrl.h"
04701dd9 124#elif defined(__WXPM__)
8cd6a9ad 125 #define wxHAS_NATIVE_SPINCTRL
04701dd9 126 #include "wx/os2/spinctrl.h"
1be7a35c 127#elif defined(__WXGTK20__)
8cd6a9ad
VZ
128 #define wxHAS_NATIVE_SPINCTRL
129 #define wxHAS_NATIVE_SPINCTRLDOUBLE
738f9e5a 130 #include "wx/gtk/spinctrl.h"
1be7a35c 131#elif defined(__WXGTK__)
8cd6a9ad 132 #define wxHAS_NATIVE_SPINCTRL
1be7a35c 133 #include "wx/gtk1/spinctrl.h"
b782f2e0
VZ
134#endif // platform
135
8cd6a9ad
VZ
136#if !defined(wxHAS_NATIVE_SPINCTRL) || !defined(wxHAS_NATIVE_SPINCTRLDOUBLE)
137 #include "wx/generic/spinctlg.h"
138#endif
5dd26b08 139
9e565667
VZ
140namespace 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.
145extern wxString wxSpinCtrlFormatAsHex(long val, long maxVal);
146
147} // namespace wxPrivate
148
ce7fe42e
VZ
149// old wxEVT_COMMAND_* constants
150#define wxEVT_COMMAND_SPINCTRL_UPDATED wxEVT_SPINCTRL
151#define wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED wxEVT_SPINCTRLDOUBLE
152
2ecf902b 153#endif // wxUSE_SPINCTRL
b782f2e0 154
2ecf902b 155#endif // _WX_SPINCTRL_H_