]>
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"
30 #include "wx/spinbutt.h"
31 #include "wx/checklst.h"
34 #include "wx/valgen.h"
36 wxGenericValidator::wxGenericValidator(bool *val
)
42 wxGenericValidator::wxGenericValidator(int *val
)
48 wxGenericValidator::wxGenericValidator(wxString
*val
)
54 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
60 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
65 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
67 wxValidator::Copy(val
);
69 m_pBool
= val
.m_pBool
;
71 m_pString
= val
.m_pString
;
72 m_pArrayInt
= val
.m_pArrayInt
;
77 wxGenericValidator::~wxGenericValidator()
81 // Called to transfer data to the window
82 bool wxGenericValidator::TransferToWindow(void)
84 if ( !m_validatorWindow
)
88 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
90 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
93 pControl
->SetValue(*m_pBool
) ;
97 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
99 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
102 pControl
->SetValue(*m_pBool
) ;
107 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
109 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
112 pControl
->SetValue(*m_pInt
) ;
116 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
118 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
121 pControl
->SetSelection(*m_pInt
) ;
125 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
127 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
130 pControl
->SetThumbPosition(*m_pInt
) ;
135 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
137 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
140 pControl
->SetValue(*m_pInt
) ;
146 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
148 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
151 pControl
->SetLabel(*m_pString
) ;
155 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
157 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
160 pControl
->SetValue(*m_pString
) ;
164 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
166 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
169 pControl
->SetSelection(*m_pInt
) ;
173 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
175 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
178 pControl
->SetLabel(*m_pString
) ;
182 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
184 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
187 pControl
->SetValue(*m_pString
) ;
193 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
195 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
197 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
200 // clear all selections
202 for (i
= 0 ; i
< pControl
->Number(); ++i
)
203 pControl
->Check(i
, FALSE
);
204 // select each item in our array
206 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
207 pControl
->Check(m_pArrayInt
->Item(u
));
214 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
216 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
219 // clear all selections
221 for (i
= 0 ; i
< pControl
->Number(); ++i
)
222 pControl
->Deselect(i
);
223 // select each item in our array
225 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
226 pControl
->SetSelection(m_pArrayInt
->Item(u
));
231 // unrecognized control, or bad pointer
235 // Called to transfer data to the window
236 bool wxGenericValidator::TransferFromWindow(void)
238 if ( !m_validatorWindow
)
242 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
244 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
247 *m_pBool
= pControl
->GetValue() ;
251 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
253 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
256 *m_pBool
= pControl
->GetValue() ;
261 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
263 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
266 *m_pInt
= pControl
->GetValue() ;
270 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
272 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
275 *m_pInt
= pControl
->GetSelection() ;
279 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
281 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
284 *m_pInt
= pControl
->GetThumbPosition() ;
289 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
291 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
294 *m_pInt
= pControl
->GetValue() ;
300 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
302 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
305 *m_pString
= pControl
->GetLabel() ;
309 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
311 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
314 *m_pString
= pControl
->GetValue() ;
318 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
320 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
323 *m_pInt
= pControl
->GetSelection() ;
327 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
329 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
332 *m_pString
= pControl
->GetLabel() ;
336 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
338 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
341 *m_pString
= pControl
->GetValue() ;
347 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
349 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
351 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
355 m_pArrayInt
->Clear();
356 // add each selected item to our array
358 for (i
= 0 ; i
< pControl
->Number(); ++i
)
359 if (pControl
->IsChecked(i
))
367 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
369 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
373 m_pArrayInt
->Clear();
374 // add each selected item to our array
376 for (i
= 0 ; i
< pControl
->Number(); ++i
)
377 if (pControl
->Selected(i
))
383 // unrecognized control, or bad pointer
388 Called by constructors to initialize ALL data members
390 void wxGenericValidator::Initialize()