]>
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"
47 #include "wx/spinbutt.h"
48 #include "wx/checklst.h"
51 #include "wx/valgen.h"
53 wxGenericValidator::wxGenericValidator(bool *val
)
59 wxGenericValidator::wxGenericValidator(int *val
)
65 wxGenericValidator::wxGenericValidator(wxString
*val
)
71 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
77 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
82 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
84 wxValidator::Copy(val
);
86 m_pBool
= val
.m_pBool
;
88 m_pString
= val
.m_pString
;
89 m_pArrayInt
= val
.m_pArrayInt
;
94 wxGenericValidator::~wxGenericValidator()
98 // Called to transfer data to the window
99 bool wxGenericValidator::TransferToWindow(void)
101 if ( !m_validatorWindow
)
106 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
108 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
111 pControl
->SetValue(*m_pBool
) ;
117 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
119 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
122 pControl
->SetValue(*m_pBool
) ;
129 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
131 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
134 pControl
->SetValue(*m_pInt
) ;
141 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
143 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
146 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(wxButton
)) )
179 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
182 pControl
->SetLabel(*m_pString
) ;
187 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
189 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
192 pControl
->SetValue(*m_pString
) ;
198 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
200 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
203 pControl
->SetSelection(*m_pInt
) ;
208 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
210 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
213 pControl
->SetLabel(*m_pString
) ;
217 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
219 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
222 pControl
->SetValue(*m_pString
) ;
226 #if wxUSE_CHECKLISTBOX
229 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
231 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
233 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
236 // clear all selections
238 for (i
= 0 ; i
< pControl
->Number(); ++i
)
239 pControl
->Check(i
, FALSE
);
240 // select each item in our array
242 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
243 pControl
->Check(m_pArrayInt
->Item(u
));
252 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
254 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
257 // clear all selections
259 for (i
= 0 ; i
< pControl
->Number(); ++i
)
260 pControl
->Deselect(i
);
261 // select each item in our array
263 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
264 pControl
->SetSelection(m_pArrayInt
->Item(u
));
270 // unrecognized control, or bad pointer
275 // Called to transfer data to the window
276 bool wxGenericValidator::TransferFromWindow(void)
278 if ( !m_validatorWindow
)
283 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
285 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
288 *m_pBool
= pControl
->GetValue() ;
294 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
296 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
299 *m_pBool
= pControl
->GetValue() ;
306 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
308 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
311 *m_pInt
= pControl
->GetValue() ;
317 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
319 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
322 *m_pInt
= pControl
->GetSelection() ;
328 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
330 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
333 *m_pInt
= pControl
->GetThumbPosition() ;
340 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
342 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
345 *m_pInt
= pControl
->GetValue() ;
352 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
354 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
357 *m_pString
= pControl
->GetLabel() ;
363 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
365 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
368 *m_pString
= pControl
->GetValue() ;
374 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
376 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
379 *m_pInt
= pControl
->GetSelection() ;
384 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
386 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
389 *m_pString
= pControl
->GetLabel() ;
393 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
395 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
398 *m_pString
= pControl
->GetValue() ;
405 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
407 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
409 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
413 m_pArrayInt
->Clear();
414 // add each selected item to our array
416 for (i
= 0 ; i
< pControl
->Number(); ++i
)
417 if (pControl
->IsChecked(i
))
427 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
429 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
433 m_pArrayInt
->Clear();
434 // add each selected item to our array
436 for (i
= 0 ; i
< pControl
->Number(); ++i
)
437 if (pControl
->Selected(i
))
444 // unrecognized control, or bad pointer
450 Called by constructors to initialize ALL data members
452 void wxGenericValidator::Initialize()