1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets validation sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/combobox.h"
14 #include "wx/dialog.h"
15 #include "wx/dynarray.h"
17 #include "wx/listbox.h"
18 #include "wx/string.h"
20 // Define a new application type
21 class MyApp
: public wxApp
27 // Define a new frame type
28 class MyFrame
: public wxFrame
31 MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
);
33 void OnQuit(wxCommandEvent
& event
);
34 void OnTestDialog(wxCommandEvent
& event
);
35 void OnToggleBell(wxCommandEvent
& event
);
44 class MyDialog
: public wxDialog
47 MyDialog(wxWindow
*parent
, const wxString
& title
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
,
50 const long style
= wxDEFAULT_DIALOG_STYLE
);
52 bool TransferDataToWindow();
54 wxComboBox
*m_combobox
;
56 wxTextCtrl
*m_numericTextInt
;
57 wxTextCtrl
*m_numericTextDouble
;
65 // These data members are designed for transfer to and from
66 // controls, via validators. For instance, a text control's
67 // transferred value is a string:
68 wxString m_string
, m_string2
;
70 // Listboxes may permit multiple selections, so their state
71 // is transferred to an integer-array class.
72 wxArrayInt m_listbox_choices
;
74 // Comboboxes differ from listboxes--validators transfer
75 // the string entered in the combobox's text-edit field.
76 wxString m_combobox_choice
;
78 // variables handled by wxNumericTextValidator
82 bool m_checkbox_state
;
83 int m_radiobox_choice
;
86 class MyComboBoxValidator
: public wxValidator
89 MyComboBoxValidator(const MyComboBoxValidator
& tocopy
) { m_var
=tocopy
.m_var
; }
90 MyComboBoxValidator(wxString
* var
) { m_var
=var
; }
92 virtual bool Validate(wxWindow
* parent
);
93 virtual wxObject
* Clone() const { return new MyComboBoxValidator(*this); }
95 // Called to transfer data to the window
96 virtual bool TransferToWindow();
98 // Called to transfer data from the window
99 virtual bool TransferFromWindow();
107 VALIDATE_DIALOG_ID
= wxID_HIGHEST
,
109 VALIDATE_TEST_DIALOG
,
110 VALIDATE_TOGGLE_BELL
,