]>
git.saurik.com Git - wxWidgets.git/blob - src/common/valgen.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericValidator class
6 // Created: Jan 22 1999
8 // Copyright: (c) 1999 Kevin Smith
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "valgen.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 #include "wx/dynarray.h"
33 #include "wx/choice.h"
34 #include "wx/combobox.h"
35 #include "wx/radiobox.h"
36 #include "wx/radiobut.h"
37 #include "wx/checkbox.h"
38 #include "wx/scrolbar.h"
40 #include "wx/stattext.h"
41 #include "wx/textctrl.h"
42 #include "wx/button.h"
43 #include "wx/listbox.h"
44 #include "wx/slider.h"
48 #include "wx/spinbutt.h"
49 #include "wx/checklst.h"
52 #include "wx/valgen.h"
54 wxGenericValidator::wxGenericValidator(bool *val
)
60 wxGenericValidator::wxGenericValidator(int *val
)
66 wxGenericValidator::wxGenericValidator(wxString
*val
)
72 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
78 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
83 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
85 wxValidator::Copy(val
);
87 m_pBool
= val
.m_pBool
;
89 m_pString
= val
.m_pString
;
90 m_pArrayInt
= val
.m_pArrayInt
;
95 wxGenericValidator::~wxGenericValidator()
99 // Called to transfer data to the window
100 bool wxGenericValidator::TransferToWindow(void)
102 if ( !m_validatorWindow
)
107 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
109 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
112 pControl
->SetValue(*m_pBool
);
118 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
120 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
123 pControl
->SetValue(*m_pBool
) ;
131 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
133 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
136 pControl
->SetValue(*m_pInt
);
142 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
144 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
147 pControl
->SetSelection(*m_pInt
) ;
153 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
155 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
158 pControl
->SetThumbPosition(*m_pInt
) ;
165 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
167 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
170 pControl
->SetValue(*m_pInt
) ;
177 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) )
179 wxSlider
* pControl
= (wxSlider
*) m_validatorWindow
;
182 pControl
->SetValue(*m_pInt
) ;
190 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
192 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
195 pControl
->SetLabel(*m_pString
) ;
201 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
203 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
206 pControl
->SetValue(*m_pString
) ;
212 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
214 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
217 pControl
->SetSelection(*m_pInt
) ;
222 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
224 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
227 pControl
->SetLabel(*m_pString
) ;
231 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
233 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
236 pControl
->SetValue(*m_pString
) ;
240 #if wxUSE_CHECKLISTBOX
243 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
245 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
247 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
250 // clear all selections
252 for (i
= 0 ; i
< pControl
->Number(); ++i
)
253 pControl
->Check(i
, FALSE
);
254 // select each item in our array
256 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
257 pControl
->Check(m_pArrayInt
->Item(u
));
266 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
268 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
271 // clear all selections
273 for (i
= 0 ; i
< pControl
->Number(); ++i
)
274 pControl
->Deselect(i
);
275 // select each item in our array
277 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
278 pControl
->SetSelection(m_pArrayInt
->Item(u
));
284 // unrecognized control, or bad pointer
289 // Called to transfer data from the window
290 bool wxGenericValidator::TransferFromWindow(void)
292 if ( !m_validatorWindow
)
297 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
299 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
302 *m_pBool
= pControl
->GetValue() ;
308 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
310 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
313 *m_pBool
= pControl
->GetValue() ;
320 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
322 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
325 *m_pInt
= pControl
->GetValue() ;
331 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
333 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
336 *m_pInt
= pControl
->GetSelection() ;
342 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
344 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
347 *m_pInt
= pControl
->GetThumbPosition() ;
354 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
356 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
359 *m_pInt
= pControl
->GetValue() ;
366 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) )
368 wxSlider
* pControl
= (wxSlider
*) m_validatorWindow
;
371 pControl
->SetValue(*m_pInt
) ;
377 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
379 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
382 *m_pString
= pControl
->GetLabel() ;
388 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
390 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
393 *m_pString
= pControl
->GetValue() ;
399 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
401 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
404 *m_pInt
= pControl
->GetSelection() ;
409 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
411 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
414 *m_pString
= pControl
->GetLabel() ;
418 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
420 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
423 *m_pString
= pControl
->GetValue() ;
427 #if wxUSE_CHECKLISTBOX
430 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
432 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
434 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
438 m_pArrayInt
->Clear();
439 // add each selected item to our array
441 for (i
= 0 ; i
< pControl
->Number(); ++i
)
442 if (pControl
->IsChecked(i
))
452 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
454 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
458 m_pArrayInt
->Clear();
459 // add each selected item to our array
461 for (i
= 0 ; i
< pControl
->Number(); ++i
)
462 if (pControl
->Selected(i
))
469 // unrecognized control, or bad pointer
475 Called by constructors to initialize ALL data members
477 void wxGenericValidator::Initialize()