]>
Commit | Line | Data |
---|---|---|
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 | #if defined(__GNUG__) && !defined(__APPLE__) | |
26 | #pragma interface "spinctlg.h" | |
27 | #endif | |
28 | ||
29 | class WXDLLEXPORT wxSpinButton; | |
30 | class WXDLLEXPORT wxTextCtrl; | |
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // wxSpinCtrl is a combination of wxTextCtrl and wxSpinButton | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | class WXDLLEXPORT wxSpinCtrl : public wxControl | |
37 | { | |
38 | public: | |
39 | wxSpinCtrl() { Init(); } | |
40 | ||
41 | wxSpinCtrl(wxWindow *parent, | |
42 | wxWindowID id = -1, | |
43 | const wxString& value = wxEmptyString, | |
44 | const wxPoint& pos = wxDefaultPosition, | |
45 | const wxSize& size = wxDefaultSize, | |
46 | long style = wxSP_ARROW_KEYS, | |
47 | int min = 0, int max = 100, int initial = 0, | |
48 | const wxString& name = _T("wxSpinCtrl")) | |
49 | { | |
50 | Init(); | |
51 | Create(parent, id, value, pos, size, style, min, max, initial, name); | |
52 | } | |
53 | ||
54 | bool Create(wxWindow *parent, | |
55 | wxWindowID id = -1, | |
56 | const wxString& value = wxEmptyString, | |
57 | const wxPoint& pos = wxDefaultPosition, | |
58 | const wxSize& size = wxDefaultSize, | |
59 | long style = wxSP_ARROW_KEYS, | |
60 | int min = 0, int max = 100, int initial = 0, | |
61 | const wxString& name = _T("wxSpinCtrl")); | |
62 | ||
63 | // wxTextCtrl-like method | |
64 | void SetSelection(long from, long to); | |
65 | ||
66 | virtual ~wxSpinCtrl(); | |
67 | ||
68 | // operations | |
69 | void SetValue(int val); | |
70 | void SetValue(const wxString& text); | |
71 | void SetRange(int min, int max); | |
72 | ||
73 | // accessors | |
74 | int GetValue() const; | |
75 | int GetMin() const; | |
76 | int GetMax() const; | |
77 | ||
78 | // implementation from now on | |
79 | ||
80 | // forward these functions to all subcontrols | |
81 | virtual bool Enable(bool enable = TRUE); | |
82 | virtual bool Show(bool show = TRUE); | |
83 | ||
84 | // get the subcontrols | |
85 | wxTextCtrl *GetText() const { return m_text; } | |
86 | wxSpinButton *GetSpinButton() const { return m_btn; } | |
87 | ||
88 | // set the value of the text (only) | |
89 | void SetTextValue(int val); | |
90 | ||
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; | |
95 | ||
96 | protected: | |
97 | // override the base class virtuals involved into geometry calculations | |
98 | virtual wxSize DoGetBestSize() const; | |
99 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
100 | ||
101 | // common part of all ctors | |
102 | void Init(); | |
103 | ||
104 | private: | |
105 | // the subcontrols | |
106 | wxTextCtrl *m_text; | |
107 | wxSpinButton *m_btn; | |
108 | ||
109 | private: | |
110 | DECLARE_DYNAMIC_CLASS(wxSpinCtrl) | |
111 | }; | |
112 | ||
113 | #else // !wxUSE_SPINBTN | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // wxSpinCtrl is just a text control | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
119 | #include "wx/textctrl.h" | |
120 | ||
121 | class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl | |
122 | { | |
123 | public: | |
124 | wxSpinCtrl() { Init(); } | |
125 | ||
126 | wxSpinCtrl(wxWindow *parent, | |
127 | wxWindowID id = -1, | |
128 | const wxString& value = wxEmptyString, | |
129 | const wxPoint& pos = wxDefaultPosition, | |
130 | const wxSize& size = wxDefaultSize, | |
131 | long style = wxSP_ARROW_KEYS, | |
132 | int min = 0, int max = 100, int initial = 0, | |
133 | const wxString& name = _T("wxSpinCtrl")) | |
134 | { | |
135 | Create(parent, id, value, pos, size, style, min, max, initial, name); | |
136 | } | |
137 | ||
138 | bool Create(wxWindow *parent, | |
139 | wxWindowID id = -1, | |
140 | const wxString& value = wxEmptyString, | |
141 | const wxPoint& pos = wxDefaultPosition, | |
142 | const wxSize& size = wxDefaultSize, | |
143 | long style = wxSP_ARROW_KEYS, | |
144 | int min = 0, int max = 100, int initial = 0, | |
145 | const wxString& name = _T("wxSpinCtrl")) | |
146 | { | |
147 | SetRange(min, max); | |
148 | ||
149 | bool ok = wxTextCtrl::Create(parent, id, value, pos, size, style, | |
150 | wxDefaultValidator, name); | |
151 | SetValue(initial); | |
152 | ||
153 | return ok; | |
154 | } | |
155 | ||
156 | // accessors | |
157 | int GetValue(int WXUNUSED(dummy) = 1) const | |
158 | { | |
159 | int n; | |
160 | if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) ) | |
161 | n = INT_MIN; | |
162 | ||
163 | return n; | |
164 | } | |
165 | ||
166 | int GetMin() const { return m_min; } | |
167 | int GetMax() const { return m_max; } | |
168 | ||
169 | // operations | |
170 | void SetValue(const wxString& value) { wxTextCtrl::SetValue(value); } | |
171 | void SetValue(int val) { wxString s; s << val; wxTextCtrl::SetValue(s); } | |
172 | void SetRange(int min, int max) { m_min = min; m_max = max; } | |
173 | ||
174 | protected: | |
175 | // initialize m_min/max with the default values | |
176 | void Init() { SetRange(0, 100); } | |
177 | ||
178 | int m_min; | |
179 | int m_max; | |
180 | ||
181 | private: | |
182 | DECLARE_DYNAMIC_CLASS(wxSpinCtrl) | |
183 | }; | |
184 | ||
185 | #endif // wxUSE_SPINBTN/!wxUSE_SPINBTN | |
186 | ||
187 | #endif // _WX_MAC_SPINCTRL_H_ | |
188 |