]> git.saurik.com Git - wxWidgets.git/blob - src/common/valgen.cpp
Added zillions of #if wxUSE_XXX
[wxWidgets.git] / src / common / valgen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: valgen.cpp
3 // Purpose: wxGenericValidator class
4 // Author: Kevin Smith
5 // Modified by:
6 // Created: Jan 22 1999
7 // RCS-ID:
8 // Copyright: (c) 1999 Kevin Smith
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "valgen.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/utils.h"
25 #include "wx/intl.h"
26 #include "wx/wx.h"
27 #include "wx/dynarray.h"
28 #endif
29
30 #ifndef __WIN16__
31 #include "wx/spinbutt.h"
32 #include "wx/checklst.h"
33 #endif
34
35 #include "wx/valgen.h"
36
37 wxGenericValidator::wxGenericValidator(bool *val)
38 {
39 Initialize();
40 m_pBool = val;
41 }
42
43 wxGenericValidator::wxGenericValidator(int *val)
44 {
45 Initialize();
46 m_pInt = val;
47 }
48
49 wxGenericValidator::wxGenericValidator(wxString *val)
50 {
51 Initialize();
52 m_pString = val;
53 }
54
55 wxGenericValidator::wxGenericValidator(wxArrayInt *val)
56 {
57 Initialize();
58 m_pArrayInt = val;
59 }
60
61 wxGenericValidator::wxGenericValidator(const wxGenericValidator& val)
62 {
63 Copy(val);
64 }
65
66 bool wxGenericValidator::Copy(const wxGenericValidator& val)
67 {
68 wxValidator::Copy(val);
69
70 m_pBool = val.m_pBool;
71 m_pInt = val.m_pInt;
72 m_pString = val.m_pString;
73 m_pArrayInt = val.m_pArrayInt;
74
75 return TRUE;
76 }
77
78 wxGenericValidator::~wxGenericValidator()
79 {
80 }
81
82 // Called to transfer data to the window
83 bool wxGenericValidator::TransferToWindow(void)
84 {
85 if ( !m_validatorWindow )
86 return FALSE;
87
88 // bool controls
89 #if wxUSE_CHECKBOX
90 if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)) )
91 {
92 wxCheckBox* pControl = (wxCheckBox*) m_validatorWindow;
93 if (m_pBool)
94 {
95 pControl->SetValue(*m_pBool) ;
96 return TRUE;
97 }
98 } else
99 #endif
100 #if wxUSE_RADIOBTN
101 if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioButton)) )
102 {
103 wxRadioButton* pControl = (wxRadioButton*) m_validatorWindow;
104 if (m_pBool)
105 {
106 pControl->SetValue(*m_pBool) ;
107 return TRUE;
108 }
109 } else
110 #endif
111 // int controls
112 #if wxUSE_GAUGE
113 if (m_validatorWindow->IsKindOf(CLASSINFO(wxGauge)) )
114 {
115 wxGauge* pControl = (wxGauge*) m_validatorWindow;
116 if (m_pInt)
117 {
118 pControl->SetValue(*m_pInt) ;
119 return TRUE;
120 }
121 }
122 else
123 #endif
124 #if wxUSE_RADIOBOX
125 if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioBox)) )
126 {
127 wxRadioBox* pControl = (wxRadioBox*) m_validatorWindow;
128 if (m_pInt)
129 {
130 pControl->SetSelection(*m_pInt) ;
131 return TRUE;
132 }
133 }
134 else
135 #endif
136 #if wxUSE_SCROLLBAR
137 if (m_validatorWindow->IsKindOf(CLASSINFO(wxScrollBar)) )
138 {
139 wxScrollBar* pControl = (wxScrollBar*) m_validatorWindow;
140 if (m_pInt)
141 {
142 pControl->SetThumbPosition(*m_pInt) ;
143 return TRUE;
144 }
145 } else
146 #endif
147 #if wxUSE_SPINBTN
148 #ifndef __WIN16__
149 if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinButton)) )
150 {
151 wxSpinButton* pControl = (wxSpinButton*) m_validatorWindow;
152 if (m_pInt)
153 {
154 pControl->SetValue(*m_pInt) ;
155 return TRUE;
156 }
157 } else
158 #endif
159 #endif
160 // string controls
161 if (m_validatorWindow->IsKindOf(CLASSINFO(wxButton)) )
162 {
163 wxButton* pControl = (wxButton*) m_validatorWindow;
164 if (m_pString)
165 {
166 pControl->SetLabel(*m_pString) ;
167 return TRUE;
168 }
169 } else
170 #if wxUSE_COMBOBOX
171 if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) )
172 {
173 wxComboBox* pControl = (wxComboBox*) m_validatorWindow;
174 if (m_pString)
175 {
176 pControl->SetValue(*m_pString) ;
177 return TRUE;
178 }
179 }
180 #endif
181 else if (m_validatorWindow->IsKindOf(CLASSINFO(wxChoice)) )
182 {
183 wxChoice* pControl = (wxChoice*) m_validatorWindow;
184 if (m_pInt)
185 {
186 pControl->SetSelection(*m_pInt) ;
187 return TRUE;
188 }
189 }
190 else if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) )
191 {
192 wxStaticText* pControl = (wxStaticText*) m_validatorWindow;
193 if (m_pString)
194 {
195 pControl->SetLabel(*m_pString) ;
196 return TRUE;
197 }
198 }
199 else if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
200 {
201 wxTextCtrl* pControl = (wxTextCtrl*) m_validatorWindow;
202 if (m_pString)
203 {
204 pControl->SetValue(*m_pString) ;
205 return TRUE;
206 }
207 } else
208 #if wxUSE_CHECKLISTBOX
209 #ifndef __WIN16__
210 // array controls
211 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
212 // MUST come first:
213 if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckListBox)) )
214 {
215 wxCheckListBox* pControl = (wxCheckListBox*) m_validatorWindow;
216 if (m_pArrayInt)
217 {
218 // clear all selections
219 int i;
220 for (i = 0 ; i < pControl->Number(); ++i)
221 pControl->Check(i, FALSE);
222 // select each item in our array
223 unsigned u;
224 for (u = 0; u < m_pArrayInt->Count(); ++u)
225 pControl->Check(m_pArrayInt->Item(u));
226 return TRUE;
227 }
228 else
229 return FALSE;
230 } else
231 #endif
232 #endif
233 #if wxUSE_LISTBOX
234 if (m_validatorWindow->IsKindOf(CLASSINFO(wxListBox)) )
235 {
236 wxListBox* pControl = (wxListBox*) m_validatorWindow;
237 if (m_pArrayInt)
238 {
239 // clear all selections
240 int i;
241 for (i = 0 ; i < pControl->Number(); ++i)
242 pControl->Deselect(i);
243 // select each item in our array
244 unsigned u;
245 for (u = 0; u < m_pArrayInt->Count(); ++u)
246 pControl->SetSelection(m_pArrayInt->Item(u));
247 return TRUE;
248 }
249 } else
250 #endif
251
252 // unrecognized control, or bad pointer
253 return FALSE;
254 return FALSE;
255 }
256
257 // Called to transfer data to the window
258 bool wxGenericValidator::TransferFromWindow(void)
259 {
260 if ( !m_validatorWindow )
261 return FALSE;
262
263 // bool controls
264 #if wxUSE_CHECKBOX
265 if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)) )
266 {
267 wxCheckBox* pControl = (wxCheckBox*) m_validatorWindow;
268 if (m_pBool)
269 {
270 *m_pBool = pControl->GetValue() ;
271 return TRUE;
272 }
273 } else
274 #endif
275 #if wxUSE_RADIOBTN
276 if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioButton)) )
277 {
278 wxRadioButton* pControl = (wxRadioButton*) m_validatorWindow;
279 if (m_pBool)
280 {
281 *m_pBool = pControl->GetValue() ;
282 return TRUE;
283 }
284 } else
285 #endif
286 // int controls
287 #if wxUSE_GAUGE
288 if (m_validatorWindow->IsKindOf(CLASSINFO(wxGauge)) )
289 {
290 wxGauge* pControl = (wxGauge*) m_validatorWindow;
291 if (m_pInt)
292 {
293 *m_pInt = pControl->GetValue() ;
294 return TRUE;
295 }
296 } else
297 #endif
298 #if wxUSE_RADIOBOX
299 if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioBox)) )
300 {
301 wxRadioBox* pControl = (wxRadioBox*) m_validatorWindow;
302 if (m_pInt)
303 {
304 *m_pInt = pControl->GetSelection() ;
305 return TRUE;
306 }
307 } else
308 #endif
309 #if wxUSE_SCROLLBAR
310 if (m_validatorWindow->IsKindOf(CLASSINFO(wxScrollBar)) )
311 {
312 wxScrollBar* pControl = (wxScrollBar*) m_validatorWindow;
313 if (m_pInt)
314 {
315 *m_pInt = pControl->GetThumbPosition() ;
316 return TRUE;
317 }
318 } else
319 #endif
320 #if wxUSE_SPINBTN
321 #ifndef __WIN16__
322 if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinButton)) )
323 {
324 wxSpinButton* pControl = (wxSpinButton*) m_validatorWindow;
325 if (m_pInt)
326 {
327 *m_pInt = pControl->GetValue() ;
328 return TRUE;
329 }
330 } else
331 #endif
332 #endif
333 // string controls
334 if (m_validatorWindow->IsKindOf(CLASSINFO(wxButton)) )
335 {
336 wxButton* pControl = (wxButton*) m_validatorWindow;
337 if (m_pString)
338 {
339 *m_pString = pControl->GetLabel() ;
340 return TRUE;
341 }
342 }
343 else
344 #if wxUSE_COMBOBOX
345 if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) )
346 {
347 wxComboBox* pControl = (wxComboBox*) m_validatorWindow;
348 if (m_pString)
349 {
350 *m_pString = pControl->GetValue() ;
351 return TRUE;
352 }
353 } else
354 #endif
355 if (m_validatorWindow->IsKindOf(CLASSINFO(wxChoice)) )
356 {
357 wxChoice* pControl = (wxChoice*) m_validatorWindow;
358 if (m_pInt)
359 {
360 *m_pInt = pControl->GetSelection() ;
361 return TRUE;
362 }
363 } else
364 if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) )
365 {
366 wxStaticText* pControl = (wxStaticText*) m_validatorWindow;
367 if (m_pString)
368 {
369 *m_pString = pControl->GetLabel() ;
370 return TRUE;
371 }
372 } else
373 if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) )
374 {
375 wxTextCtrl* pControl = (wxTextCtrl*) m_validatorWindow;
376 if (m_pString)
377 {
378 *m_pString = pControl->GetValue() ;
379 return TRUE;
380 }
381 } else
382 #if wxUSE_LISTBOX
383 #ifndef __WIN16__
384 // array controls
385 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
386 // MUST come first:
387 if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckListBox)) )
388 {
389 wxCheckListBox* pControl = (wxCheckListBox*) m_validatorWindow;
390 if (m_pArrayInt)
391 {
392 // clear our array
393 m_pArrayInt->Clear();
394 // add each selected item to our array
395 int i;
396 for (i = 0 ; i < pControl->Number(); ++i)
397 if (pControl->IsChecked(i))
398 m_pArrayInt->Add(i);
399 return TRUE;
400 }
401 else
402 return FALSE;
403 } else
404 #endif
405 #endif
406 #if wxUSE_LISTBOX
407 if (m_validatorWindow->IsKindOf(CLASSINFO(wxListBox)) )
408 {
409 wxListBox* pControl = (wxListBox*) m_validatorWindow;
410 if (m_pArrayInt)
411 {
412 // clear our array
413 m_pArrayInt->Clear();
414 // add each selected item to our array
415 int i;
416 for (i = 0 ; i < pControl->Number(); ++i)
417 if (pControl->Selected(i))
418 m_pArrayInt->Add(i);
419 return TRUE;
420 }
421 } else
422 #endif
423
424 // unrecognized control, or bad pointer
425 return FALSE;
426 return FALSE;
427 }
428
429 /*
430 Called by constructors to initialize ALL data members
431 */
432 void wxGenericValidator::Initialize()
433 {
434 m_pBool = 0;
435 m_pInt = 0;
436 m_pString = 0;
437 m_pArrayInt = 0;
438 }
439