]>
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
)
89 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
91 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
94 pControl
->SetValue(*m_pBool
) ;
98 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
100 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
103 pControl
->SetValue(*m_pBool
) ;
108 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
110 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
113 pControl
->SetValue(*m_pInt
) ;
117 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
119 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
122 pControl
->SetSelection(*m_pInt
) ;
126 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
128 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
131 pControl
->SetThumbPosition(*m_pInt
) ;
136 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
138 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
141 pControl
->SetValue(*m_pInt
) ;
147 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
149 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
152 pControl
->SetLabel(*m_pString
) ;
156 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
158 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
161 pControl
->SetValue(*m_pString
) ;
165 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
167 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
170 pControl
->SetSelection(*m_pInt
) ;
174 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
176 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
179 pControl
->SetLabel(*m_pString
) ;
183 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
185 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
188 pControl
->SetValue(*m_pString
) ;
194 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
196 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
198 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
201 // clear all selections
203 for (i
= 0 ; i
< pControl
->Number(); ++i
)
204 pControl
->Check(i
, FALSE
);
205 // select each item in our array
207 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
208 pControl
->Check(m_pArrayInt
->Item(u
));
215 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
217 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
220 // clear all selections
222 for (i
= 0 ; i
< pControl
->Number(); ++i
)
223 pControl
->Deselect(i
);
224 // select each item in our array
226 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
227 pControl
->SetSelection(m_pArrayInt
->Item(u
));
232 // unrecognized control, or bad pointer
236 // Called to transfer data to the window
237 bool wxGenericValidator::TransferFromWindow(void)
239 if ( !m_validatorWindow
)
243 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
245 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
248 *m_pBool
= pControl
->GetValue() ;
252 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
254 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
257 *m_pBool
= pControl
->GetValue() ;
262 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
264 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
267 *m_pInt
= pControl
->GetValue() ;
271 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
273 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
276 *m_pInt
= pControl
->GetSelection() ;
280 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
282 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
285 *m_pInt
= pControl
->GetThumbPosition() ;
290 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
292 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
295 *m_pInt
= pControl
->GetValue() ;
301 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
303 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
306 *m_pString
= pControl
->GetLabel() ;
310 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
312 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
315 *m_pString
= pControl
->GetValue() ;
319 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
321 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
324 *m_pInt
= pControl
->GetSelection() ;
328 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
330 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
333 *m_pString
= pControl
->GetLabel() ;
337 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
339 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
342 *m_pString
= pControl
->GetValue() ;
348 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
350 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
352 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
356 m_pArrayInt
->Clear();
357 // add each selected item to our array
359 for (i
= 0 ; i
< pControl
->Number(); ++i
)
360 if (pControl
->IsChecked(i
))
368 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
370 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
374 m_pArrayInt
->Clear();
375 // add each selected item to our array
377 for (i
= 0 ; i
< pControl
->Number(); ++i
)
378 if (pControl
->Selected(i
))
384 // unrecognized control, or bad pointer
389 Called by constructors to initialize ALL data members
391 void wxGenericValidator::Initialize()