]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/spinctrl.h
597009107364602d9c782e7443db5bc1199243b7
[wxWidgets.git] / include / wx / mac / carbon / spinctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/spinctlg.h
3 // Purpose: generic wxSpinCtrl class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 28.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MAC_SPINCTRL_H_
13 #define _WX_MAC_SPINCTRL_H_
14
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 // ----------------------------------------------------------------------------
22
23 #if wxUSE_SPINBTN
24
25 class WXDLLEXPORT wxSpinButton;
26 class WXDLLEXPORT wxTextCtrl;
27
28 // ----------------------------------------------------------------------------
29 // wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxSpinCtrl : public wxControl
33 {
34 public:
35 wxSpinCtrl() { Init(); }
36
37 wxSpinCtrl(wxWindow *parent,
38 wxWindowID id = -1,
39 const wxString& value = wxEmptyString,
40 const wxPoint& pos = wxDefaultPosition,
41 const wxSize& size = wxDefaultSize,
42 long style = wxSP_ARROW_KEYS,
43 int min = 0, int max = 100, int initial = 0,
44 const wxString& name = _T("wxSpinCtrl"))
45 {
46 Init();
47 Create(parent, id, value, pos, size, style, min, max, initial, name);
48 }
49
50 bool Create(wxWindow *parent,
51 wxWindowID id = -1,
52 const wxString& value = wxEmptyString,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = wxSP_ARROW_KEYS,
56 int min = 0, int max = 100, int initial = 0,
57 const wxString& name = _T("wxSpinCtrl"));
58
59 // wxTextCtrl-like method
60 void SetSelection(long from, long to);
61
62 virtual ~wxSpinCtrl();
63
64 // operations
65 void SetValue(int val);
66 void SetValue(const wxString& text);
67 void SetRange(int min, int max);
68
69 // accessors
70 int GetValue() const;
71 int GetMin() const;
72 int GetMax() const;
73
74 // implementation from now on
75
76 // forward these functions to all subcontrols
77 virtual bool Enable(bool enable = TRUE);
78 virtual bool Show(bool show = TRUE);
79
80 // get the subcontrols
81 wxTextCtrl *GetText() const { return m_text; }
82 wxSpinButton *GetSpinButton() const { return m_btn; }
83
84 // set the value of the text (only)
85 void SetTextValue(int val);
86
87 // put the numeric value of the string in the text ctrl into val and return
88 // TRUE or return FALSE if the text ctrl doesn't contain a number or if the
89 // number is out of range
90 bool GetTextValue(int *val) const;
91
92 WX_DECLARE_CONTROL_CONTAINER();
93
94 protected:
95 // override the base class virtuals involved into geometry calculations
96 virtual wxSize DoGetBestSize() const;
97 virtual void DoMoveWindow(int x, int y, int width, int height);
98
99 // common part of all ctors
100 void Init();
101
102 private:
103 // the subcontrols
104 wxTextCtrl *m_text;
105 wxSpinButton *m_btn;
106
107 private:
108 DECLARE_EVENT_TABLE()
109 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
110 };
111
112 #else // !wxUSE_SPINBTN
113
114 // ----------------------------------------------------------------------------
115 // wxSpinCtrl is just a text control
116 // ----------------------------------------------------------------------------
117
118 #include "wx/textctrl.h"
119
120 class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl
121 {
122 public:
123 wxSpinCtrl() { Init(); }
124
125 wxSpinCtrl(wxWindow *parent,
126 wxWindowID id = -1,
127 const wxString& value = wxEmptyString,
128 const wxPoint& pos = wxDefaultPosition,
129 const wxSize& size = wxDefaultSize,
130 long style = wxSP_ARROW_KEYS,
131 int min = 0, int max = 100, int initial = 0,
132 const wxString& name = _T("wxSpinCtrl"))
133 {
134 Create(parent, id, value, pos, size, style, min, max, initial, name);
135 }
136
137 bool Create(wxWindow *parent,
138 wxWindowID id = -1,
139 const wxString& value = wxEmptyString,
140 const wxPoint& pos = wxDefaultPosition,
141 const wxSize& size = wxDefaultSize,
142 long style = wxSP_ARROW_KEYS,
143 int min = 0, int max = 100, int initial = 0,
144 const wxString& name = _T("wxSpinCtrl"))
145 {
146 SetRange(min, max);
147
148 bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style,
149 wxDefaultValidator, name);
150 SetValue(initial);
151
152 return ok;
153 }
154
155 // accessors
156 int GetValue(int WXUNUSED(dummy) = 1) const
157 {
158 int n;
159 if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) )
160 n = INT_MIN;
161
162 return n;
163 }
164
165 int GetMin() const { return m_min; }
166 int GetMax() const { return m_max; }
167
168 // operations
169 void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); }
170 void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); }
171 void SetRange(int min, int max) { m_min = min; m_max = max; }
172
173 protected:
174 // initialize m_min/max with the default values
175 void Init() { SetRange(0, 100); }
176
177 int m_min;
178 int m_max;
179
180 private:
181 DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
182 };
183
184 #endif // wxUSE_SPINBTN/!wxUSE_SPINBTN
185
186 #endif // _WX_MAC_SPINCTRL_H_
187