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