]>
git.saurik.com Git - wxWidgets.git/blob - src/common/valgen.cpp
2c43f606481366d2445625cfb929ea022f3b7f2b
   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" 
  47 #if wxUSE_SPINCTRL && !defined(__WIN16__) 
  48   #include "wx/spinctrl.h" 
  50 #if wxUSE_SPINBTN && !defined(__WIN16__) 
  51   #include "wx/spinbutt.h" 
  53 #if wxUSE_CHECKLISTBOX && !defined(__WIN16__) 
  54   #include "wx/checklst.h" 
  57 #include "wx/valgen.h" 
  59 wxGenericValidator::wxGenericValidator(bool *val
) 
  65 wxGenericValidator::wxGenericValidator(int *val
) 
  71 wxGenericValidator::wxGenericValidator(wxString 
*val
) 
  77 wxGenericValidator::wxGenericValidator(wxArrayInt 
*val
) 
  83 wxGenericValidator::wxGenericValidator(const wxGenericValidator
& val
) 
  88 bool wxGenericValidator::Copy(const wxGenericValidator
& val
) 
  90     wxValidator::Copy(val
); 
  92     m_pBool 
= val
.m_pBool
; 
  94     m_pString 
= val
.m_pString
; 
  95     m_pArrayInt 
= val
.m_pArrayInt
; 
 100 wxGenericValidator::~wxGenericValidator() 
 104 // Called to transfer data to the window 
 105 bool wxGenericValidator::TransferToWindow(void) 
 107     if ( !m_validatorWindow 
) 
 112     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) ) 
 114         wxCheckBox
* pControl 
= (wxCheckBox
*) m_validatorWindow
; 
 117             pControl
->SetValue(*m_pBool
); 
 123     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) ) 
 125         wxRadioButton
* pControl 
= (wxRadioButton
*) m_validatorWindow
; 
 128             pControl
->SetValue(*m_pBool
) ; 
 136     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) ) 
 138         wxGauge
* pControl 
= (wxGauge
*) m_validatorWindow
; 
 141             pControl
->SetValue(*m_pInt
); 
 147     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) ) 
 149         wxRadioBox
* pControl 
= (wxRadioBox
*) m_validatorWindow
; 
 152             pControl
->SetSelection(*m_pInt
) ; 
 158     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) ) 
 160         wxScrollBar
* pControl 
= (wxScrollBar
*) m_validatorWindow
; 
 163             pControl
->SetThumbPosition(*m_pInt
) ; 
 168 #if wxUSE_SPINCTRL && !defined(__WIN16__) && !defined(__WXMOTIF__) 
 169     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinCtrl
)) ) 
 171         wxSpinCtrl
* pControl 
= (wxSpinCtrl
*) m_validatorWindow
; 
 174             pControl
->SetValue(*m_pInt
); 
 179 #if wxUSE_SPINBTN && !defined(__WIN16__) 
 180     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) ) 
 182         wxSpinButton
* pControl 
= (wxSpinButton
*) m_validatorWindow
; 
 185             pControl
->SetValue(*m_pInt
) ; 
 191     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) ) 
 193         wxSlider
* pControl 
= (wxSlider
*) m_validatorWindow
; 
 196             pControl
->SetValue(*m_pInt
) ; 
 203     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) ) 
 205         wxButton
* pControl 
= (wxButton
*) m_validatorWindow
; 
 208             pControl
->SetLabel(*m_pString
) ; 
 213     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) ) 
 215         wxComboBox
* pControl 
= (wxComboBox
*) m_validatorWindow
; 
 218             pControl
->SetSelection(*m_pInt
) ; 
 223             if (pControl
->FindString(* m_pString
) > -1) 
 225                 pControl
->SetStringSelection(* m_pString
); 
 232     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) ) 
 234         wxChoice
* pControl 
= (wxChoice
*) m_validatorWindow
; 
 237             pControl
->SetSelection(*m_pInt
) ; 
 242             if (pControl
->FindString(* m_pString
) > -1) 
 244                 pControl
->SetStringSelection(* m_pString
); 
 250     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) ) 
 252         wxStaticText
* pControl 
= (wxStaticText
*) m_validatorWindow
; 
 255             pControl
->SetLabel(*m_pString
) ; 
 259     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) ) 
 261         wxTextCtrl
* pControl 
= (wxTextCtrl
*) m_validatorWindow
; 
 264             pControl
->SetValue(*m_pString
) ; 
 270             str
.Printf(wxT("%d"), *m_pInt
); 
 271             pControl
->SetValue(str
); 
 275 #if wxUSE_CHECKLISTBOX 
 278   // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox 
 280   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) ) 
 282     wxCheckListBox
* pControl 
= (wxCheckListBox
*) m_validatorWindow
; 
 285       // clear all selections 
 287       for (i 
= 0 ; i 
< pControl
->Number(); ++i
) 
 288         pControl
->Check(i
, FALSE
); 
 289       // select each item in our array 
 291       for (u 
= 0; u 
< m_pArrayInt
->Count(); ++u
) 
 292         pControl
->Check(m_pArrayInt
->Item(u
)); 
 301     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) ) 
 303         wxListBox
* pControl 
= (wxListBox
*) m_validatorWindow
; 
 306             // clear all selections 
 308             for (i 
= 0 ; i 
< pControl
->Number(); ++i
) 
 309                 pControl
->Deselect(i
); 
 310             // select each item in our array 
 312             for (u 
= 0; u 
< m_pArrayInt
->Count(); ++u
) 
 313                 pControl
->SetSelection(m_pArrayInt
->Item(u
)); 
 319   // unrecognized control, or bad pointer 
 324 // Called to transfer data from the window 
 325 bool wxGenericValidator::TransferFromWindow(void) 
 327   if ( !m_validatorWindow 
) 
 332   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)) ) 
 334     wxCheckBox
* pControl 
= (wxCheckBox
*) m_validatorWindow
; 
 337       *m_pBool 
= pControl
->GetValue() ; 
 343   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioButton
)) ) 
 345     wxRadioButton
* pControl 
= (wxRadioButton
*) m_validatorWindow
; 
 348       *m_pBool 
= pControl
->GetValue() ; 
 355   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxGauge
)) ) 
 357     wxGauge
* pControl 
= (wxGauge
*) m_validatorWindow
; 
 360       *m_pInt 
= pControl
->GetValue() ; 
 366   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxRadioBox
)) ) 
 368     wxRadioBox
* pControl 
= (wxRadioBox
*) m_validatorWindow
; 
 371       *m_pInt 
= pControl
->GetSelection() ; 
 377   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxScrollBar
)) ) 
 379     wxScrollBar
* pControl 
= (wxScrollBar
*) m_validatorWindow
; 
 382       *m_pInt 
= pControl
->GetThumbPosition() ; 
 387 #if wxUSE_SPINCTRL && !defined(__WIN16__) && !defined(__WXMOTIF__) 
 388     if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinCtrl
)) ) 
 390         wxSpinCtrl
* pControl 
= (wxSpinCtrl
*) m_validatorWindow
; 
 393             *m_pInt
=pControl
->GetValue(); 
 398 #if wxUSE_SPINBTN && !defined(__WIN16__) 
 399   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSpinButton
)) ) 
 401     wxSpinButton
* pControl 
= (wxSpinButton
*) m_validatorWindow
; 
 404       *m_pInt 
= pControl
->GetValue() ; 
 410   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxSlider
)) ) 
 412     wxSlider
* pControl 
= (wxSlider
*) m_validatorWindow
; 
 415       pControl
->SetValue(*m_pInt
) ; 
 421   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxButton
)) ) 
 423     wxButton
* pControl 
= (wxButton
*) m_validatorWindow
; 
 426       *m_pString 
= pControl
->GetLabel() ; 
 432   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxComboBox
)) ) 
 434     wxComboBox
* pControl 
= (wxComboBox
*) m_validatorWindow
; 
 437       *m_pString 
= pControl
->GetValue() ; 
 442         *m_pString 
= pControl
->GetStringSelection(); 
 448  if (m_validatorWindow
->IsKindOf(CLASSINFO(wxChoice
)) ) 
 450     wxChoice
* pControl 
= (wxChoice
*) m_validatorWindow
; 
 453       *m_pInt 
= pControl
->GetSelection() ; 
 458         *m_pString 
= pControl
->GetStringSelection(); 
 463   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxStaticText
)) ) 
 465     wxStaticText
* pControl 
= (wxStaticText
*) m_validatorWindow
; 
 468       *m_pString 
= pControl
->GetLabel() ; 
 472   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)) ) 
 474     wxTextCtrl
* pControl 
= (wxTextCtrl
*) m_validatorWindow
; 
 477       *m_pString 
= pControl
->GetValue() ; 
 482         *m_pInt 
= wxAtoi(pControl
->GetValue()); 
 486 #if wxUSE_CHECKLISTBOX 
 489   // NOTE: wxCheckListBox isa wxListBox, so wxCheckListBox 
 491   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckListBox
)) ) 
 493     wxCheckListBox
* pControl 
= (wxCheckListBox
*) m_validatorWindow
; 
 497       m_pArrayInt
->Clear(); 
 498       // add each selected item to our array 
 500       for (i 
= 0 ; i 
< pControl
->Number(); ++i
) 
 501         if (pControl
->IsChecked(i
)) 
 511   if (m_validatorWindow
->IsKindOf(CLASSINFO(wxListBox
)) ) 
 513     wxListBox
* pControl 
= (wxListBox
*) m_validatorWindow
; 
 517       m_pArrayInt
->Clear(); 
 518       // add each selected item to our array 
 520       for (i 
= 0 ; i 
< pControl
->Number(); ++i
) 
 521         if (pControl
->Selected(i
)) 
 528   // unrecognized control, or bad pointer 
 534   Called by constructors to initialize ALL data members 
 535         Last change:  JAC  21 Jul 100    5:00 pm 
 537 void wxGenericValidator::Initialize()