]>
git.saurik.com Git - wxWidgets.git/blob - src/common/valgen.cpp
ac9989bb615dfb8f15c07dc50ff1b4054e93fc74
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"
32 #include "wx/dynarray.h"
33 #include "wx/choice.h"
34 #include "wx/combobox.h"
35 #include "wx/radiobox.h"
36 #include "wx/radiobut.h"
37 #include "wx/checkbox.h"
38 #include "wx/scrolbar.h"
40 #include "wx/stattext.h"
41 #include "wx/textctrl.h"
42 #include "wx/button.h"
43 #include "wx/listbox.h"
44 #include "wx/slider.h"
48 #include "wx/spinbutt.h"
49 #if wxUSE_CHECKLISTBOX
50 #include "wx/checklst.h"
54 #include "wx/valgen.h"
56 wxGenericValidator::wxGenericValidator(bool *val
)
62 wxGenericValidator::wxGenericValidator(int *val
)
68 wxGenericValidator::wxGenericValidator(wxString
*val
)
74 wxGenericValidator::wxGenericValidator(wxArrayInt
*val
)
80 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
)
85 bool wxGenericValidator::Copy(const wxGenericValidator
& val
)
87 wxValidator::Copy(val
);
89 m_pBool
= val
.m_pBool
;
91 m_pString
= val
.m_pString
;
92 m_pArrayInt
= val
.m_pArrayInt
;
97 wxGenericValidator::~wxGenericValidator()
101 // Called to transfer data to the window
102 bool wxGenericValidator::TransferToWindow(void)
104 if ( !m_validatorWindow
)
109 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
111 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
114 pControl
->SetValue(*m_pBool
);
120 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
122 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
125 pControl
->SetValue(*m_pBool
) ;
133 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
135 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
138 pControl
->SetValue(*m_pInt
);
144 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
146 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
149 pControl
->SetSelection(*m_pInt
) ;
155 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
157 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
160 pControl
->SetThumbPosition(*m_pInt
) ;
167 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
169 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
172 pControl
->SetValue(*m_pInt
) ;
179 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) )
181 wxSlider
* pControl
= (wxSlider
*) m_validatorWindow
;
184 pControl
->SetValue(*m_pInt
) ;
192 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
194 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
197 pControl
->SetLabel(*m_pString
) ;
203 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
205 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
208 pControl
->SetValue(*m_pString
) ;
214 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
216 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
219 pControl
->SetSelection(*m_pInt
) ;
224 if (pControl
->FindString(* m_pString
) > -1)
226 pControl
->SetStringSelection(* m_pString
);
232 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
234 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
237 pControl
->SetSelection(*m_pInt
) ;
242 if (pControl
->FindString(* m_pString
) > -1)
244 pControl
->SetStringSelection(* m_pString
);
249 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
251 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
254 pControl
->SetLabel(*m_pString
) ;
258 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
260 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
263 pControl
->SetValue(*m_pString
) ;
269 str
.Printf(wxT("%d"), *m_pInt
);
270 pControl
->SetValue(str
);
274 #if wxUSE_CHECKLISTBOX
277 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
279 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
281 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
284 // clear all selections
286 for (i
= 0 ; i
< pControl
->Number(); ++i
)
287 pControl
->Check(i
, FALSE
);
288 // select each item in our array
290 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
291 pControl
->Check(m_pArrayInt
->Item(u
));
300 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
302 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
305 // clear all selections
307 for (i
= 0 ; i
< pControl
->Number(); ++i
)
308 pControl
->Deselect(i
);
309 // select each item in our array
311 for (u
= 0; u
< m_pArrayInt
->Count(); ++u
)
312 pControl
->SetSelection(m_pArrayInt
->Item(u
));
318 // unrecognized control, or bad pointer
323 // Called to transfer data from the window
324 bool wxGenericValidator::TransferFromWindow(void)
326 if ( !m_validatorWindow
)
331 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) )
333 wxCheckBox
* pControl
= (wxCheckBox
*) m_validatorWindow
;
336 *m_pBool
= pControl
->GetValue() ;
342 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) )
344 wxRadioButton
* pControl
= (wxRadioButton
*) m_validatorWindow
;
347 *m_pBool
= pControl
->GetValue() ;
354 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) )
356 wxGauge
* pControl
= (wxGauge
*) m_validatorWindow
;
359 *m_pInt
= pControl
->GetValue() ;
365 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) )
367 wxRadioBox
* pControl
= (wxRadioBox
*) m_validatorWindow
;
370 *m_pInt
= pControl
->GetSelection() ;
376 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) )
378 wxScrollBar
* pControl
= (wxScrollBar
*) m_validatorWindow
;
381 *m_pInt
= pControl
->GetThumbPosition() ;
388 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) )
390 wxSpinButton
* pControl
= (wxSpinButton
*) m_validatorWindow
;
393 *m_pInt
= pControl
->GetValue() ;
400 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) )
402 wxSlider
* pControl
= (wxSlider
*) m_validatorWindow
;
405 pControl
->SetValue(*m_pInt
) ;
411 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) )
413 wxButton
* pControl
= (wxButton
*) m_validatorWindow
;
416 *m_pString
= pControl
->GetLabel() ;
422 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
424 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
427 *m_pString
= pControl
->GetValue() ;
432 *m_pString
= pControl
->GetStringSelection();
438 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) )
440 wxChoice
* pControl
= (wxChoice
*) m_validatorWindow
;
443 *m_pInt
= pControl
->GetSelection() ;
448 *m_pString
= pControl
->GetStringSelection();
453 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) )
455 wxComboBox
* pControl
= (wxComboBox
*) m_validatorWindow
;
458 *m_pInt
= pControl
->GetSelection() ;
463 *m_pString
= pControl
->GetStringSelection();
467 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) )
469 wxStaticText
* pControl
= (wxStaticText
*) m_validatorWindow
;
472 *m_pString
= pControl
->GetLabel() ;
476 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
478 wxTextCtrl
* pControl
= (wxTextCtrl
*) m_validatorWindow
;
481 *m_pString
= pControl
->GetValue() ;
486 *m_pInt
= wxAtoi(pControl
->GetValue());
490 #if wxUSE_CHECKLISTBOX
493 // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox
495 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) )
497 wxCheckListBox
* pControl
= (wxCheckListBox
*) m_validatorWindow
;
501 m_pArrayInt
->Clear();
502 // add each selected item to our array
504 for (i
= 0 ; i
< pControl
->Number(); ++i
)
505 if (pControl
->IsChecked(i
))
515 if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) )
517 wxListBox
* pControl
= (wxListBox
*) m_validatorWindow
;
521 m_pArrayInt
->Clear();
522 // add each selected item to our array
524 for (i
= 0 ; i
< pControl
->Number(); ++i
)
525 if (pControl
->Selected(i
))
532 // unrecognized control, or bad pointer
538 Called by constructors to initialize ALL data members
540 void wxGenericValidator::Initialize()