]>
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"
27 #include "wx/dynarray.h"
31 #include "wx/spinbutt.h"
32 #include "wx/checklst.h"
35 #include "wx/valgen.h"
37 wxGenericValidator::wxGenericValidator(bool *val
)
43 wxGenericValidator::wxGenericValidator(int *val
)
49 wxGenericValidator::wxGenericValidator(wxString
*val
)
55 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
61 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
66 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
68 wxValidator::Copy(val
);
70 m_pBool
= val
.m_pBool
;
72 m_pString
= val
.m_pString
;
73 m_pArrayInt
= val
.m_pArrayInt
;
78 wxGenericValidator::~wxGenericValidator()
82 // Called to transfer data to the window
83 bool wxGenericValidator::TransferToWindow(void)
85 if ( !m_validatorWindow
)
90 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
92 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
95 pControl
->SetValue(*m_pBool
) ;
101 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
103 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
106 pControl
->SetValue(*m_pBool
) ;
113 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
115 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
118 pControl
->SetValue(*m_pInt
) ;
125 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
127 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
130 pControl
->SetSelection(*m_pInt
) ;
137 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
139 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
142 pControl
->SetThumbPosition(*m_pInt
) ;
149 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
151 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
154 pControl
->SetValue(*m_pInt
) ;
161 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
163 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
166 pControl
->SetLabel(*m_pString
) ;
171 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
173 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
176 pControl
->SetValue(*m_pString
) ;
181 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
183 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
186 pControl
->SetSelection(*m_pInt
) ;
190 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
192 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
195 pControl
->SetLabel(*m_pString
) ;
199 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
201 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
204 pControl
->SetValue(*m_pString
) ;
208 #if wxUSE_CHECKLISTBOX
211 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
213 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
215 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
218 // clear all selections
220 for (i
= 0 ; i
< pControl
->Number(); ++i
)
221 pControl
->Check(i
, FALSE
);
222 // select each item in our array
224 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
225 pControl
->Check(m_pArrayInt
->Item(u
));
234 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
236 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
239 // clear all selections
241 for (i
= 0 ; i
< pControl
->Number(); ++i
)
242 pControl
->Deselect(i
);
243 // select each item in our array
245 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
246 pControl
->SetSelection(m_pArrayInt
->Item(u
));
252 // unrecognized control, or bad pointer
257 // Called to transfer data to the window
258 bool wxGenericValidator::TransferFromWindow(void)
260 if ( !m_validatorWindow
)
265 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
267 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
270 *m_pBool
= pControl
->GetValue() ;
276 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
278 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
281 *m_pBool
= pControl
->GetValue() ;
288 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
290 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
293 *m_pInt
= pControl
->GetValue() ;
299 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
301 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
304 *m_pInt
= pControl
->GetSelection() ;
310 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
312 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
315 *m_pInt
= pControl
->GetThumbPosition() ;
322 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
324 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
327 *m_pInt
= pControl
->GetValue() ;
334 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
336 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
339 *m_pString
= pControl
->GetLabel() ;
345 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
347 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
350 *m_pString
= pControl
->GetValue() ;
355 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
357 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
360 *m_pInt
= pControl
->GetSelection() ;
364 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
366 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
369 *m_pString
= pControl
->GetLabel() ;
373 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
375 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
378 *m_pString
= pControl
->GetValue() ;
385 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
387 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
389 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
393 m_pArrayInt
->Clear();
394 // add each selected item to our array
396 for (i
= 0 ; i
< pControl
->Number(); ++i
)
397 if (pControl
->IsChecked(i
))
407 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
409 wxListBox
* pControl
= (wxListBox
*) 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
->Selected(i
))
424 // unrecognized control, or bad pointer
430 Called by constructors to initialize ALL data members
432 void wxGenericValidator::Initialize()