]>
Commit | Line | Data |
---|---|---|
89c684ef | 1 | ///////////////////////////////////////////////////////////////////////////// |
40ff126a | 2 | // Name: src/common/valgen.cpp |
89c684ef JS |
3 | // Purpose: wxGenericValidator class |
4 | // Author: Kevin Smith | |
5 | // Modified by: | |
6 | // Created: Jan 22 1999 | |
7448de8d | 7 | // RCS-ID: $Id$ |
89c684ef | 8 | // Copyright: (c) 1999 Kevin Smith |
7448de8d | 9 | // Licence: wxWindows licence |
89c684ef JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
89c684ef JS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
8898456d | 16 | #pragma hdrstop |
ce4169a4 RR |
17 | #endif |
18 | ||
19 | #if wxUSE_VALIDATORS | |
20 | ||
21 | #ifndef WX_PRECOMP | |
ad9835c9 | 22 | #include "wx/dynarray.h" |
8898456d WS |
23 | #include "wx/utils.h" |
24 | #include "wx/intl.h" | |
8898456d WS |
25 | #include "wx/choice.h" |
26 | #include "wx/combobox.h" | |
27 | #include "wx/radiobox.h" | |
28 | #include "wx/radiobut.h" | |
29 | #include "wx/checkbox.h" | |
30 | #include "wx/scrolbar.h" | |
31 | #include "wx/gauge.h" | |
32 | #include "wx/stattext.h" | |
33 | #include "wx/textctrl.h" | |
34 | #include "wx/button.h" | |
35 | #include "wx/listbox.h" | |
36 | #include "wx/slider.h" | |
e6e83933 | 37 | #include "wx/checklst.h" |
89c684ef JS |
38 | #endif |
39 | ||
388aa6e2 | 40 | #include "wx/spinctrl.h" |
22de6a40 | 41 | #include "wx/datectrl.h" |
4ded51f2 | 42 | |
cab1a605 | 43 | #if wxUSE_SPINBTN |
ad9835c9 | 44 | #include "wx/spinbutt.h" |
750b78ba | 45 | #endif |
388aa6e2 | 46 | #if wxUSE_TOGGLEBTN |
ad9835c9 | 47 | #include "wx/tglbtn.h" |
388aa6e2 | 48 | #endif |
89c684ef JS |
49 | |
50 | #include "wx/valgen.h" | |
51 | ||
5cf69f76 JS |
52 | IMPLEMENT_CLASS(wxGenericValidator, wxValidator) |
53 | ||
89c684ef JS |
54 | wxGenericValidator::wxGenericValidator(bool *val) |
55 | { | |
ce4169a4 RR |
56 | Initialize(); |
57 | m_pBool = val; | |
89c684ef JS |
58 | } |
59 | ||
60 | wxGenericValidator::wxGenericValidator(int *val) | |
61 | { | |
ce4169a4 RR |
62 | Initialize(); |
63 | m_pInt = val; | |
89c684ef JS |
64 | } |
65 | ||
66 | wxGenericValidator::wxGenericValidator(wxString *val) | |
67 | { | |
ce4169a4 RR |
68 | Initialize(); |
69 | m_pString = val; | |
89c684ef JS |
70 | } |
71 | ||
72 | wxGenericValidator::wxGenericValidator(wxArrayInt *val) | |
73 | { | |
ce4169a4 RR |
74 | Initialize(); |
75 | m_pArrayInt = val; | |
89c684ef JS |
76 | } |
77 | ||
22de6a40 VZ |
78 | #if wxUSE_DATETIME |
79 | ||
80 | wxGenericValidator::wxGenericValidator(wxDateTime *val) | |
81 | { | |
82 | Initialize(); | |
83 | m_pDateTime = val; | |
84 | } | |
85 | ||
86 | #endif // wxUSE_DATETIME | |
87 | ||
89c684ef | 88 | wxGenericValidator::wxGenericValidator(const wxGenericValidator& val) |
d84afea9 | 89 | : wxValidator() |
89c684ef | 90 | { |
ce4169a4 | 91 | Copy(val); |
89c684ef JS |
92 | } |
93 | ||
94 | bool wxGenericValidator::Copy(const wxGenericValidator& val) | |
95 | { | |
e90196a5 | 96 | wxValidator::Copy(val); |
89c684ef | 97 | |
e90196a5 RR |
98 | m_pBool = val.m_pBool; |
99 | m_pInt = val.m_pInt; | |
100 | m_pString = val.m_pString; | |
101 | m_pArrayInt = val.m_pArrayInt; | |
22de6a40 VZ |
102 | #if wxUSE_DATETIME |
103 | m_pDateTime = val.m_pDateTime; | |
104 | #endif // wxUSE_DATETIME | |
89c684ef | 105 | |
cab1a605 | 106 | return true; |
89c684ef JS |
107 | } |
108 | ||
89c684ef JS |
109 | // Called to transfer data to the window |
110 | bool wxGenericValidator::TransferToWindow(void) | |
111 | { | |
e90196a5 | 112 | if ( !m_validatorWindow ) |
cab1a605 | 113 | return false; |
89c684ef | 114 | |
e90196a5 | 115 | // bool controls |
dcf924a3 | 116 | #if wxUSE_CHECKBOX |
e90196a5 | 117 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)) ) |
89c684ef | 118 | { |
e90196a5 RR |
119 | wxCheckBox* pControl = (wxCheckBox*) m_validatorWindow; |
120 | if (m_pBool) | |
3ca6a5f0 BP |
121 | { |
122 | pControl->SetValue(*m_pBool); | |
cab1a605 | 123 | return true; |
3ca6a5f0 | 124 | } |
e90196a5 | 125 | } else |
dcf924a3 RR |
126 | #endif |
127 | #if wxUSE_RADIOBTN | |
e90196a5 | 128 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioButton)) ) |
89c684ef | 129 | { |
e90196a5 | 130 | wxRadioButton* pControl = (wxRadioButton*) m_validatorWindow; |
3ca6a5f0 BP |
131 | if (m_pBool) |
132 | { | |
133 | pControl->SetValue(*m_pBool) ; | |
cab1a605 | 134 | return true; |
3ca6a5f0 | 135 | } |
e90196a5 | 136 | } else |
dcf924a3 | 137 | #endif |
10ff9c61 | 138 | |
388aa6e2 JS |
139 | #if wxUSE_TOGGLEBTN |
140 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxToggleButton)) ) | |
141 | { | |
142 | wxToggleButton * pControl = (wxToggleButton *) m_validatorWindow; | |
40ff126a WS |
143 | if (m_pBool) |
144 | { | |
145 | pControl->SetValue(*m_pBool); | |
146 | return true; | |
147 | } | |
388aa6e2 | 148 | } else |
10ff9c61 RR |
149 | #if defined(__WXMAC__) || defined(__WXGTK20__) |
150 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxBitmapToggleButton)) ) | |
151 | { | |
152 | wxBitmapToggleButton * pControl = (wxBitmapToggleButton *) m_validatorWindow; | |
153 | if (m_pBool) | |
154 | { | |
155 | pControl->SetValue(*m_pBool); | |
156 | return true; | |
157 | } | |
158 | } else | |
159 | #endif | |
388aa6e2 | 160 | #endif |
e90196a5 RR |
161 | |
162 | // int controls | |
dcf924a3 | 163 | #if wxUSE_GAUGE |
e90196a5 | 164 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxGauge)) ) |
89c684ef | 165 | { |
e90196a5 | 166 | wxGauge* pControl = (wxGauge*) m_validatorWindow; |
3ca6a5f0 BP |
167 | if (m_pInt) |
168 | { | |
169 | pControl->SetValue(*m_pInt); | |
cab1a605 | 170 | return true; |
3ca6a5f0 | 171 | } |
e90196a5 | 172 | } else |
dcf924a3 RR |
173 | #endif |
174 | #if wxUSE_RADIOBOX | |
e90196a5 | 175 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioBox)) ) |
89c684ef | 176 | { |
e90196a5 | 177 | wxRadioBox* pControl = (wxRadioBox*) m_validatorWindow; |
3ca6a5f0 BP |
178 | if (m_pInt) |
179 | { | |
180 | pControl->SetSelection(*m_pInt) ; | |
cab1a605 | 181 | return true; |
3ca6a5f0 | 182 | } |
e90196a5 | 183 | } else |
dcf924a3 RR |
184 | #endif |
185 | #if wxUSE_SCROLLBAR | |
e90196a5 | 186 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxScrollBar)) ) |
89c684ef | 187 | { |
e90196a5 | 188 | wxScrollBar* pControl = (wxScrollBar*) m_validatorWindow; |
3ca6a5f0 BP |
189 | if (m_pInt) |
190 | { | |
191 | pControl->SetThumbPosition(*m_pInt) ; | |
cab1a605 | 192 | return true; |
3ca6a5f0 | 193 | } |
e90196a5 | 194 | } else |
dcf924a3 | 195 | #endif |
3a5bcc4d | 196 | #if wxUSE_SPINCTRL && !defined(__WXMOTIF__) |
a55e0ebc JS |
197 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinCtrl)) ) |
198 | { | |
199 | wxSpinCtrl* pControl = (wxSpinCtrl*) m_validatorWindow; | |
200 | if (m_pInt) | |
201 | { | |
202 | pControl->SetValue(*m_pInt); | |
cab1a605 | 203 | return true; |
a55e0ebc JS |
204 | } |
205 | } else | |
206 | #endif | |
3a5bcc4d | 207 | #if wxUSE_SPINBTN |
e90196a5 | 208 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinButton)) ) |
89c684ef | 209 | { |
e90196a5 | 210 | wxSpinButton* pControl = (wxSpinButton*) m_validatorWindow; |
3ca6a5f0 BP |
211 | if (m_pInt) |
212 | { | |
213 | pControl->SetValue(*m_pInt) ; | |
cab1a605 | 214 | return true; |
3ca6a5f0 | 215 | } |
e90196a5 | 216 | } else |
dcf924a3 | 217 | #endif |
e90196a5 RR |
218 | #if wxUSE_SLIDER |
219 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSlider)) ) | |
220 | { | |
221 | wxSlider* pControl = (wxSlider*) m_validatorWindow; | |
222 | if (m_pInt) | |
223 | { | |
3ca6a5f0 | 224 | pControl->SetValue(*m_pInt) ; |
cab1a605 | 225 | return true; |
3ca6a5f0 | 226 | } |
e90196a5 RR |
227 | } else |
228 | #endif | |
229 | ||
22de6a40 | 230 | // date time controls |
3baef911 | 231 | #if 0 // wxUSE_DATEPICKCTRL -- temporary fix for shared build linking |
22de6a40 VZ |
232 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxDatePickerCtrl)) ) |
233 | { | |
234 | wxDatePickerCtrl* pControl = (wxDatePickerCtrl*) m_validatorWindow; | |
235 | if (m_pDateTime) | |
236 | { | |
237 | pControl->SetValue(*m_pDateTime) ; | |
238 | return true; | |
239 | } | |
240 | } else | |
241 | #endif | |
242 | ||
3ca6a5f0 | 243 | // string controls |
d7260478 | 244 | #if wxUSE_BUTTON |
e90196a5 | 245 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxButton)) ) |
89c684ef | 246 | { |
e90196a5 | 247 | wxButton* pControl = (wxButton*) m_validatorWindow; |
3ca6a5f0 BP |
248 | if (m_pString) |
249 | { | |
250 | pControl->SetLabel(*m_pString) ; | |
cab1a605 | 251 | return true; |
3ca6a5f0 | 252 | } |
e90196a5 | 253 | } else |
d7260478 | 254 | #endif |
e90196a5 RR |
255 | #if wxUSE_COMBOBOX |
256 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) ) | |
89c684ef | 257 | { |
e90196a5 | 258 | wxComboBox* pControl = (wxComboBox*) m_validatorWindow; |
f6bcfd97 BP |
259 | if (m_pInt) |
260 | { | |
261 | pControl->SetSelection(*m_pInt) ; | |
cab1a605 | 262 | return true; |
f6bcfd97 BP |
263 | } |
264 | else if (m_pString) | |
265 | { | |
cab1a605 | 266 | if (pControl->FindString(* m_pString) != wxNOT_FOUND) |
f6bcfd97 BP |
267 | { |
268 | pControl->SetStringSelection(* m_pString); | |
269 | } | |
780fb83c | 270 | if ((m_validatorWindow->GetWindowStyle() & wxCB_READONLY) == 0) |
7cc3cec9 JS |
271 | { |
272 | pControl->SetValue(* m_pString); | |
273 | } | |
cab1a605 | 274 | return true; |
f6bcfd97 | 275 | } |
e90196a5 | 276 | } else |
ce4169a4 | 277 | #endif |
a55e0ebc JS |
278 | #if wxUSE_CHOICE |
279 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxChoice)) ) | |
f6bcfd97 | 280 | { |
a55e0ebc | 281 | wxChoice* pControl = (wxChoice*) m_validatorWindow; |
f6bcfd97 BP |
282 | if (m_pInt) |
283 | { | |
284 | pControl->SetSelection(*m_pInt) ; | |
cab1a605 | 285 | return true; |
f6bcfd97 BP |
286 | } |
287 | else if (m_pString) | |
288 | { | |
cab1a605 | 289 | if (pControl->FindString(* m_pString) != wxNOT_FOUND) |
f6bcfd97 BP |
290 | { |
291 | pControl->SetStringSelection(* m_pString); | |
292 | } | |
cab1a605 | 293 | return true; |
f6bcfd97 BP |
294 | } |
295 | } else | |
a55e0ebc | 296 | #endif |
001e76a9 | 297 | #if wxUSE_STATTEXT |
e90196a5 | 298 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) ) |
89c684ef | 299 | { |
e90196a5 | 300 | wxStaticText* pControl = (wxStaticText*) m_validatorWindow; |
f6bcfd97 BP |
301 | if (m_pString) |
302 | { | |
303 | pControl->SetLabel(*m_pString) ; | |
cab1a605 | 304 | return true; |
f6bcfd97 | 305 | } |
3ca6a5f0 | 306 | } else |
001e76a9 | 307 | #endif |
d7260478 | 308 | #if wxUSE_TEXTCTRL |
e90196a5 | 309 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) |
89c684ef | 310 | { |
e90196a5 | 311 | wxTextCtrl* pControl = (wxTextCtrl*) m_validatorWindow; |
f6bcfd97 BP |
312 | if (m_pString) |
313 | { | |
314 | pControl->SetValue(*m_pString) ; | |
cab1a605 | 315 | return true; |
f6bcfd97 BP |
316 | } |
317 | else if (m_pInt) | |
318 | { | |
319 | wxString str; | |
66b3ec7f | 320 | str.Printf(wxT("%d"), *m_pInt); |
f6bcfd97 | 321 | pControl->SetValue(str); |
cab1a605 | 322 | return true; |
f6bcfd97 | 323 | } |
e90196a5 | 324 | } else |
d7260478 | 325 | #endif |
388aa6e2 | 326 | |
1e6feb95 | 327 | // array controls |
3a5bcc4d | 328 | #if wxUSE_CHECKLISTBOX |
1e6feb95 VZ |
329 | // NOTE: wxCheckListBox is a wxListBox, so wxCheckListBox MUST come first: |
330 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckListBox)) ) | |
89c684ef | 331 | { |
1e6feb95 VZ |
332 | wxCheckListBox* pControl = (wxCheckListBox*) m_validatorWindow; |
333 | if (m_pArrayInt) | |
334 | { | |
335 | // clear all selections | |
336 | size_t i, | |
337 | count = pControl->GetCount(); | |
338 | for ( i = 0 ; i < count; i++ ) | |
cab1a605 | 339 | pControl->Check(i, false); |
1e6feb95 VZ |
340 | |
341 | // select each item in our array | |
342 | count = m_pArrayInt->GetCount(); | |
343 | for ( i = 0 ; i < count; i++ ) | |
344 | pControl->Check(m_pArrayInt->Item(i)); | |
345 | ||
cab1a605 | 346 | return true; |
1e6feb95 | 347 | } |
3ca6a5f0 | 348 | else |
cab1a605 | 349 | return false; |
1e6feb95 | 350 | } else |
750b78ba | 351 | #endif |
dcf924a3 | 352 | #if wxUSE_LISTBOX |
e90196a5 | 353 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxListBox)) ) |
89c684ef | 354 | { |
e90196a5 | 355 | wxListBox* pControl = (wxListBox*) m_validatorWindow; |
3ca6a5f0 BP |
356 | if (m_pArrayInt) |
357 | { | |
358 | // clear all selections | |
1e6feb95 VZ |
359 | size_t i, |
360 | count = pControl->GetCount(); | |
361 | for ( i = 0 ; i < count; i++ ) | |
3ca6a5f0 | 362 | pControl->Deselect(i); |
1e6feb95 | 363 | |
3ca6a5f0 | 364 | // select each item in our array |
1e6feb95 VZ |
365 | count = m_pArrayInt->GetCount(); |
366 | for ( i = 0 ; i < count; i++ ) | |
367 | pControl->SetSelection(m_pArrayInt->Item(i)); | |
368 | ||
cab1a605 | 369 | return true; |
3ca6a5f0 | 370 | } |
e90196a5 | 371 | } else |
dcf924a3 | 372 | #endif |
3ca6a5f0 | 373 | ; // to match the last 'else' above |
89c684ef JS |
374 | |
375 | // unrecognized control, or bad pointer | |
cab1a605 | 376 | return false; |
89c684ef JS |
377 | } |
378 | ||
e90196a5 | 379 | // Called to transfer data from the window |
89c684ef JS |
380 | bool wxGenericValidator::TransferFromWindow(void) |
381 | { | |
7448de8d WS |
382 | if ( !m_validatorWindow ) |
383 | return false; | |
89c684ef | 384 | |
7448de8d | 385 | // BOOL CONTROLS ************************************** |
dcf924a3 | 386 | #if wxUSE_CHECKBOX |
7448de8d | 387 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)) ) |
89c684ef | 388 | { |
7448de8d WS |
389 | wxCheckBox* pControl = (wxCheckBox*) m_validatorWindow; |
390 | if (m_pBool) | |
391 | { | |
392 | *m_pBool = pControl->GetValue() ; | |
393 | return true; | |
394 | } | |
395 | } else | |
dcf924a3 RR |
396 | #endif |
397 | #if wxUSE_RADIOBTN | |
7448de8d | 398 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioButton)) ) |
89c684ef | 399 | { |
7448de8d WS |
400 | wxRadioButton* pControl = (wxRadioButton*) m_validatorWindow; |
401 | if (m_pBool) | |
402 | { | |
403 | *m_pBool = pControl->GetValue() ; | |
404 | return true; | |
405 | } | |
406 | } else | |
dcf924a3 | 407 | #endif |
388aa6e2 JS |
408 | #if wxUSE_TOGGLEBTN |
409 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxToggleButton)) ) | |
410 | { | |
40ff126a WS |
411 | wxToggleButton *pControl = (wxToggleButton *) m_validatorWindow; |
412 | if (m_pBool) | |
413 | { | |
414 | *m_pBool = pControl->GetValue() ; | |
415 | return true; | |
416 | } | |
388aa6e2 JS |
417 | } else |
418 | #endif | |
7448de8d WS |
419 | |
420 | // INT CONTROLS *************************************** | |
dcf924a3 | 421 | #if wxUSE_GAUGE |
7448de8d | 422 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxGauge)) ) |
89c684ef | 423 | { |
7448de8d WS |
424 | wxGauge* pControl = (wxGauge*) m_validatorWindow; |
425 | if (m_pInt) | |
426 | { | |
427 | *m_pInt = pControl->GetValue() ; | |
428 | return true; | |
429 | } | |
430 | } else | |
dcf924a3 RR |
431 | #endif |
432 | #if wxUSE_RADIOBOX | |
7448de8d | 433 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxRadioBox)) ) |
89c684ef | 434 | { |
7448de8d WS |
435 | wxRadioBox* pControl = (wxRadioBox*) m_validatorWindow; |
436 | if (m_pInt) | |
437 | { | |
438 | *m_pInt = pControl->GetSelection() ; | |
439 | return true; | |
440 | } | |
441 | } else | |
dcf924a3 RR |
442 | #endif |
443 | #if wxUSE_SCROLLBAR | |
7448de8d | 444 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxScrollBar)) ) |
89c684ef | 445 | { |
7448de8d WS |
446 | wxScrollBar* pControl = (wxScrollBar*) m_validatorWindow; |
447 | if (m_pInt) | |
448 | { | |
449 | *m_pInt = pControl->GetThumbPosition() ; | |
450 | return true; | |
451 | } | |
452 | } else | |
dcf924a3 | 453 | #endif |
3a5bcc4d | 454 | #if wxUSE_SPINCTRL && !defined(__WXMOTIF__) |
a55e0ebc JS |
455 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinCtrl)) ) |
456 | { | |
457 | wxSpinCtrl* pControl = (wxSpinCtrl*) m_validatorWindow; | |
458 | if (m_pInt) | |
459 | { | |
460 | *m_pInt=pControl->GetValue(); | |
cab1a605 | 461 | return true; |
a55e0ebc JS |
462 | } |
463 | } else | |
464 | #endif | |
3a5bcc4d | 465 | #if wxUSE_SPINBTN |
7448de8d | 466 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSpinButton)) ) |
89c684ef | 467 | { |
7448de8d WS |
468 | wxSpinButton* pControl = (wxSpinButton*) m_validatorWindow; |
469 | if (m_pInt) | |
470 | { | |
471 | *m_pInt = pControl->GetValue() ; | |
472 | return true; | |
473 | } | |
474 | } else | |
dcf924a3 | 475 | #endif |
e90196a5 | 476 | #if wxUSE_SLIDER |
7448de8d | 477 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxSlider)) ) |
e90196a5 | 478 | { |
7448de8d WS |
479 | wxSlider* pControl = (wxSlider*) m_validatorWindow; |
480 | if (m_pInt) | |
481 | { | |
482 | *m_pInt = pControl->GetValue() ; | |
483 | return true; | |
484 | } | |
485 | } else | |
750b78ba | 486 | #endif |
7448de8d | 487 | |
22de6a40 | 488 | // DATE TIME CONTROLS ************************************ |
3baef911 | 489 | #if 0 // wxUSE_DATEPICKCTRL -- temporary fix for shared build linking |
22de6a40 VZ |
490 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxDatePickerCtrl)) ) |
491 | { | |
492 | wxDatePickerCtrl* pControl = (wxDatePickerCtrl*) m_validatorWindow; | |
493 | if (m_pDateTime) | |
494 | { | |
495 | *m_pDateTime = pControl->GetValue() ; | |
496 | return true; | |
497 | } | |
498 | } else | |
499 | #endif | |
500 | ||
7448de8d | 501 | // STRING CONTROLS ************************************ |
d7260478 | 502 | #if wxUSE_BUTTON |
7448de8d | 503 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxButton)) ) |
89c684ef | 504 | { |
7448de8d WS |
505 | wxButton* pControl = (wxButton*) m_validatorWindow; |
506 | if (m_pString) | |
507 | { | |
508 | *m_pString = pControl->GetLabel() ; | |
509 | return true; | |
510 | } | |
511 | } else | |
d7260478 | 512 | #endif |
dcf924a3 | 513 | #if wxUSE_COMBOBOX |
7448de8d | 514 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) ) |
f6bcfd97 | 515 | { |
7448de8d WS |
516 | wxComboBox* pControl = (wxComboBox*) m_validatorWindow; |
517 | if (m_pInt) | |
518 | { | |
519 | *m_pInt = pControl->GetSelection() ; | |
520 | return true; | |
521 | } | |
522 | else if (m_pString) | |
523 | { | |
524 | if (m_validatorWindow->GetWindowStyle() & wxCB_READONLY) | |
525 | *m_pString = pControl->GetStringSelection(); | |
526 | else | |
527 | *m_pString = pControl->GetValue(); | |
528 | return true; | |
529 | } | |
530 | } else | |
dcf924a3 | 531 | #endif |
ce4169a4 | 532 | #if wxUSE_CHOICE |
7448de8d | 533 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxChoice)) ) |
f6bcfd97 | 534 | { |
7448de8d WS |
535 | wxChoice* pControl = (wxChoice*) m_validatorWindow; |
536 | if (m_pInt) | |
537 | { | |
538 | *m_pInt = pControl->GetSelection() ; | |
539 | return true; | |
540 | } | |
541 | else if (m_pString) | |
542 | { | |
543 | *m_pString = pControl->GetStringSelection(); | |
544 | return true; | |
545 | } | |
546 | } else | |
ce4169a4 | 547 | #endif |
001e76a9 | 548 | #if wxUSE_STATTEXT |
7448de8d | 549 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) ) |
89c684ef | 550 | { |
7448de8d WS |
551 | wxStaticText* pControl = (wxStaticText*) m_validatorWindow; |
552 | if (m_pString) | |
553 | { | |
554 | *m_pString = pControl->GetLabel() ; | |
555 | return true; | |
556 | } | |
557 | } else | |
001e76a9 | 558 | #endif |
d7260478 | 559 | #if wxUSE_TEXTCTRL |
7448de8d | 560 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) |
f6bcfd97 | 561 | { |
7448de8d WS |
562 | wxTextCtrl* pControl = (wxTextCtrl*) m_validatorWindow; |
563 | if (m_pString) | |
564 | { | |
565 | *m_pString = pControl->GetValue() ; | |
566 | return true; | |
567 | } | |
568 | else if (m_pInt) | |
569 | { | |
570 | *m_pInt = wxAtoi(pControl->GetValue()); | |
571 | return true; | |
572 | } | |
573 | } else | |
d7260478 | 574 | #endif |
7448de8d WS |
575 | |
576 | // ARRAY CONTROLS ************************************* | |
e90196a5 | 577 | #if wxUSE_CHECKLISTBOX |
7448de8d WS |
578 | // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox MUST come first: |
579 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxCheckListBox)) ) | |
89c684ef | 580 | { |
7448de8d WS |
581 | wxCheckListBox* pControl = (wxCheckListBox*) m_validatorWindow; |
582 | if (m_pArrayInt) | |
583 | { | |
584 | // clear our array | |
585 | m_pArrayInt->Clear(); | |
586 | ||
587 | // add each selected item to our array | |
588 | size_t i, | |
589 | count = pControl->GetCount(); | |
590 | for ( i = 0; i < count; i++ ) | |
591 | { | |
592 | if (pControl->IsChecked(i)) | |
593 | m_pArrayInt->Add(i); | |
594 | } | |
595 | ||
596 | return true; | |
597 | } | |
598 | else | |
599 | return false; | |
600 | } else | |
dcf924a3 | 601 | #endif |
dcf924a3 | 602 | #if wxUSE_LISTBOX |
7448de8d | 603 | if (m_validatorWindow->IsKindOf(CLASSINFO(wxListBox)) ) |
89c684ef | 604 | { |
7448de8d WS |
605 | wxListBox* pControl = (wxListBox*) m_validatorWindow; |
606 | if (m_pArrayInt) | |
607 | { | |
608 | // clear our array | |
609 | m_pArrayInt->Clear(); | |
1e6feb95 | 610 | |
7448de8d WS |
611 | // add each selected item to our array |
612 | size_t i, | |
613 | count = pControl->GetCount(); | |
614 | for ( i = 0; i < count; i++ ) | |
615 | { | |
40ff126a | 616 | if (pControl->IsSelected(i)) |
7448de8d WS |
617 | m_pArrayInt->Add(i); |
618 | } | |
1e6feb95 | 619 | |
7448de8d WS |
620 | return true; |
621 | } | |
622 | } else | |
dcf924a3 | 623 | #endif |
89c684ef | 624 | |
7448de8d WS |
625 | // unrecognized control, or bad pointer |
626 | return false; | |
627 | ||
cab1a605 | 628 | return false; |
89c684ef JS |
629 | } |
630 | ||
631 | /* | |
632 | Called by constructors to initialize ALL data members | |
633 | */ | |
634 | void wxGenericValidator::Initialize() | |
635 | { | |
ce4169a4 RR |
636 | m_pBool = 0; |
637 | m_pInt = 0; | |
638 | m_pString = 0; | |
639 | m_pArrayInt = 0; | |
22de6a40 VZ |
640 | #if wxUSE_DATETIME |
641 | m_pDateTime = 0; | |
642 | #endif // wxUSE_DATETIME | |
89c684ef JS |
643 | } |
644 | ||
22de6a40 | 645 | #endif // wxUSE_VALIDATORS |