]>
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"
29 #include "wx/spinbutt.h"
30 #include "wx/checklst.h"
32 #include "wx/valgen.h"
34 wxGenericValidator::wxGenericValidator(bool *val
)
40 wxGenericValidator::wxGenericValidator(int *val
)
46 wxGenericValidator::wxGenericValidator(wxString
*val
)
52 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
58 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
63 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
65 wxValidator::Copy(val
);
67 m_pBool
= val
.m_pBool
;
69 m_pString
= val
.m_pString
;
70 m_pArrayInt
= val
.m_pArrayInt
;
75 wxGenericValidator::~wxGenericValidator()
79 // Called to transfer data to the window
80 bool wxGenericValidator::TransferToWindow(void)
82 if ( !m_validatorWindow
)
86 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
88 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
91 pControl
->SetValue(*m_pBool
) ;
95 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
97 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
100 pControl
->SetValue(*m_pBool
) ;
105 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
107 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
110 pControl
->SetValue(*m_pInt
) ;
114 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
116 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
119 pControl
->SetSelection(*m_pInt
) ;
123 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
125 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
128 pControl
->SetThumbPosition(*m_pInt
) ;
132 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
134 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
137 pControl
->SetValue(*m_pInt
) ;
142 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
144 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
147 pControl
->SetLabel(*m_pString
) ;
151 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
153 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
156 pControl
->SetValue(*m_pString
) ;
160 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
162 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
165 pControl
->SetSelection(*m_pInt
) ;
169 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
171 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
174 pControl
->SetLabel(*m_pString
) ;
178 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
180 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
183 pControl
->SetValue(*m_pString
) ;
188 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
190 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
192 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
195 // clear all selections
197 for (i
= 0 ; i
< pControl
->Number(); ++i
)
198 pControl
->Check(i
, FALSE
);
199 // select each item in our array
201 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
202 pControl
->Check(m_pArrayInt
->Item(u
));
208 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
210 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
213 // clear all selections
215 for (i
= 0 ; i
< pControl
->Number(); ++i
)
216 pControl
->Deselect(i
);
217 // select each item in our array
219 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
220 pControl
->SetSelection(m_pArrayInt
->Item(u
));
225 // unrecognized control, or bad pointer
229 // Called to transfer data to the window
230 bool wxGenericValidator::TransferFromWindow(void)
232 if ( !m_validatorWindow
)
236 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
238 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
241 *m_pBool
= pControl
->GetValue() ;
245 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
247 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
250 *m_pBool
= pControl
->GetValue() ;
255 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
257 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
260 *m_pInt
= pControl
->GetValue() ;
264 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
266 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
269 *m_pInt
= pControl
->GetSelection() ;
273 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
275 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
278 *m_pInt
= pControl
->GetThumbPosition() ;
282 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
284 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
287 *m_pInt
= pControl
->GetValue() ;
292 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
294 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
297 *m_pString
= pControl
->GetLabel() ;
301 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
303 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
306 *m_pString
= pControl
->GetValue() ;
310 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
312 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
315 *m_pInt
= pControl
->GetSelection() ;
319 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
321 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
324 *m_pString
= pControl
->GetLabel() ;
328 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
330 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
333 *m_pString
= pControl
->GetValue() ;
338 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
340 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
342 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
346 m_pArrayInt
->Clear();
347 // add each selected item to our array
349 for (i
= 0 ; i
< pControl
->Number(); ++i
)
350 if (pControl
->IsChecked(i
))
357 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
359 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
363 m_pArrayInt
->Clear();
364 // add each selected item to our array
366 for (i
= 0 ; i
< pControl
->Number(); ++i
)
367 if (pControl
->Selected(i
))
373 // unrecognized control, or bad pointer
378 Called by constructors to initialize ALL data members
380 void wxGenericValidator::Initialize()