1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/spinctlg.h
3 // Purpose: generic wxSpinCtrl class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MAC_SPINCTRL_H_
13 #define _WX_MAC_SPINCTRL_H_
15 // ----------------------------------------------------------------------------
16 // wxSpinCtrl is a combination of wxSpinButton and wxTextCtrl, so if
17 // wxSpinButton is available, this is what we do - but if it isn't, we still
18 // define wxSpinCtrl class which then has the same appearance as wxTextCtrl but
19 // the different interface. This allows to write programs using wxSpinCtrl
20 // without tons of #ifdefs.
21 // ----------------------------------------------------------------------------
25 #include "wx/containr.h"
27 class WXDLLIMPEXP_FWD_CORE wxSpinButton
;
28 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
29 class WXDLLIMPEXP_FWD_CORE wxSpinCtrlText
;
30 class WXDLLIMPEXP_FWD_CORE wxSpinCtrlButton
;
32 // ----------------------------------------------------------------------------
33 // wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
34 // ----------------------------------------------------------------------------
36 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxControl
39 wxSpinCtrl() { Init(); }
41 wxSpinCtrl(wxWindow
*parent
,
43 const wxString
& value
= wxEmptyString
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
46 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
47 int min
= 0, int max
= 100, int initial
= 0,
48 const wxString
& name
= wxT("wxSpinCtrl"))
51 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
54 bool Create(wxWindow
*parent
,
56 const wxString
& value
= wxEmptyString
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
59 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
60 int min
= 0, int max
= 100, int initial
= 0,
61 const wxString
& name
= wxT("wxSpinCtrl"));
63 // wxTextCtrl-like method
64 void SetSelection(long from
, long to
);
66 virtual ~wxSpinCtrl();
69 void SetValue(int val
);
70 void SetValue(const wxString
& text
);
71 void SetRange(int min
, int max
);
78 // implementation from now on
80 // forward these functions to all subcontrols
81 virtual bool Enable(bool enable
= true);
82 virtual bool Show(bool show
= true);
84 // get the subcontrols
85 wxTextCtrl
*GetText() const { return m_text
; }
86 wxSpinButton
*GetSpinButton() const { return m_btn
; }
88 // set the value of the text (only)
89 void SetTextValue(int val
);
91 // put the numeric value of the string in the text ctrl into val and return
92 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
93 // number is out of range
94 bool GetTextValue(int *val
) const;
96 WX_DECLARE_CONTROL_CONTAINER();
99 // override the base class virtuals involved into geometry calculations
100 virtual wxSize
DoGetBestSize() const;
101 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
103 // common part of all ctors
111 friend class wxSpinCtrlText
;
112 friend class wxSpinCtrlButton
;
116 DECLARE_EVENT_TABLE()
117 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
120 #else // !wxUSE_SPINBTN
122 // ----------------------------------------------------------------------------
123 // wxSpinCtrl is just a text control
124 // ----------------------------------------------------------------------------
126 #include "wx/textctrl.h"
128 class WXDLLIMPEXP_CORE wxSpinCtrl
: public wxTextCtrl
131 wxSpinCtrl() { Init(); }
133 wxSpinCtrl(wxWindow
*parent
,
135 const wxString
& value
= wxEmptyString
,
136 const wxPoint
& pos
= wxDefaultPosition
,
137 const wxSize
& size
= wxDefaultSize
,
138 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
139 int min
= 0, int max
= 100, int initial
= 0,
140 const wxString
& name
= wxT("wxSpinCtrl"))
142 Create(parent
, id
, value
, pos
, size
, style
, min
, max
, initial
, name
);
145 bool Create(wxWindow
*parent
,
147 const wxString
& value
= wxEmptyString
,
148 const wxPoint
& pos
= wxDefaultPosition
,
149 const wxSize
& size
= wxDefaultSize
,
150 long style
= wxSP_ARROW_KEYS
| wxALIGN_RIGHT
,
151 int min
= 0, int max
= 100, int initial
= 0,
152 const wxString
& name
= wxT("wxSpinCtrl"))
156 bool ok
= wxTextCtrl::Create(parent
, id
, value
, pos
, size
, style
,
157 wxDefaultValidator
, name
);
164 int GetValue(int WXUNUSED(dummy
) = 1) const
167 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n
) != 1) )
173 int GetMin() const { return m_min
; }
174 int GetMax() const { return m_max
; }
177 void SetValue(const wxString
& value
) { wxTextCtrl::SetValue(value
); }
178 void SetValue(int val
) { wxString s
; s
<< val
; wxTextCtrl::SetValue(s
); }
179 void SetRange(int min
, int max
) { m_min
= min
; m_max
= max
; }
182 // initialize m_min/max with the default values
183 void Init() { SetRange(0, 100); }
189 DECLARE_DYNAMIC_CLASS(wxSpinCtrl
)
192 #endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
194 #endif // _WX_MAC_SPINCTRL_H_