]>
git.saurik.com Git - wxWidgets.git/blob - src/common/valgen.cpp
d90f90f6f066cf150c73df67e7b369b621e1e3b0
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"
28 #include "wx/spinbutt.h"
29 #include "wx/checklst.h"
31 #include "wx/valgen.h"
33 wxGenericValidator::wxGenericValidator(bool *val
)
39 wxGenericValidator::wxGenericValidator(int *val
)
45 wxGenericValidator::wxGenericValidator(wxString
*val
)
51 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
57 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
62 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
64 wxValidator::Copy(val
);
66 m_pBool
= val
.m_pBool
;
68 m_pString
= val
.m_pString
;
69 m_pArrayInt
= val
.m_pArrayInt
;
74 wxGenericValidator::~wxGenericValidator()
78 // Called to transfer data to the window
79 bool wxGenericValidator::TransferToWindow(void)
81 if ( !m_validatorWindow
)
85 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
87 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
90 pControl
->SetValue(*m_pBool
) ;
94 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
96 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
99 pControl
->SetValue(*m_pBool
) ;
104 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
106 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
109 pControl
->SetValue(*m_pInt
) ;
113 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
115 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
118 pControl
->SetSelection(*m_pInt
) ;
122 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
124 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
127 pControl
->SetThumbPosition(*m_pInt
) ;
131 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
133 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
136 pControl
->SetValue(*m_pInt
) ;
141 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
143 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
146 pControl
->SetLabel(*m_pString
) ;
150 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
152 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
155 pControl
->SetValue(*m_pString
) ;
159 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
161 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
164 pControl
->SetSelection(*m_pInt
) ;
168 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
170 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
173 pControl
->SetLabel(*m_pString
) ;
177 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
179 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
182 pControl
->SetValue(*m_pString
) ;
187 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
189 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
191 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
194 // clear all selections
196 for (i
= 0 ; i
< pControl
->Number(); ++i
)
197 pControl
->Check(i
, FALSE
);
198 // select each item in our array
200 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
201 pControl
->Check(m_pArrayInt
->Item(u
));
207 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
209 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
212 // clear all selections
214 for (i
= 0 ; i
< pControl
->Number(); ++i
)
215 pControl
->Deselect(i
);
216 // select each item in our array
218 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
219 pControl
->SetSelection(m_pArrayInt
->Item(u
));
224 // unrecognized control, or bad pointer
228 // Called to transfer data to the window
229 bool wxGenericValidator::TransferFromWindow(void)
231 if ( !m_validatorWindow
)
235 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
237 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
240 *m_pBool
= pControl
->GetValue() ;
244 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
246 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
249 *m_pBool
= pControl
->GetValue() ;
254 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
256 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
259 *m_pInt
= pControl
->GetValue() ;
263 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
265 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
268 *m_pInt
= pControl
->GetSelection() ;
272 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
274 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
277 *m_pInt
= pControl
->GetThumbPosition() ;
281 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
283 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
286 *m_pInt
= pControl
->GetValue() ;
291 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
293 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
296 *m_pString
= pControl
->GetLabel() ;
300 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
302 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
305 *m_pString
= pControl
->GetValue() ;
309 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
311 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
314 *m_pInt
= pControl
->GetSelection() ;
318 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
320 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
323 *m_pString
= pControl
->GetLabel() ;
327 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
329 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
332 *m_pString
= pControl
->GetValue() ;
337 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
339 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
341 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
345 m_pArrayInt
->Clear();
346 // add each selected item to our array
348 for (i
= 0 ; i
< pControl
->Number(); ++i
)
349 if (pControl
->IsChecked(i
))
356 else if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
358 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
362 m_pArrayInt
->Clear();
363 // add each selected item to our array
365 for (i
= 0 ; i
< pControl
->Number(); ++i
)
366 if (pControl
->Selected(i
))
372 // unrecognized control, or bad pointer
377 Called by constructors to initialize ALL data members
379 void wxGenericValidator::Initialize()