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