1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets validation sample
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/combobox.h"
13 #include "wx/dialog.h"
14 #include "wx/dynarray.h"
16 #include "wx/listbox.h"
17 #include "wx/string.h"
19 // Define a new application type
20 class MyApp
: public wxApp
26 // Define a new frame type
27 class MyFrame
: public wxFrame
30 MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
);
32 void OnQuit(wxCommandEvent
& event
);
33 void OnTestDialog(wxCommandEvent
& event
);
34 void OnToggleBell(wxCommandEvent
& event
);
43 class MyDialog
: public wxDialog
46 MyDialog(wxWindow
*parent
, const wxString
& title
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
49 const long style
= wxDEFAULT_DIALOG_STYLE
);
51 bool TransferDataToWindow();
53 wxComboBox
*m_combobox
;
55 wxTextCtrl
*m_numericTextInt
;
56 wxTextCtrl
*m_numericTextDouble
;
64 // These data members are designed for transfer to and from
65 // controls, via validators. For instance, a text control's
66 // transferred value is a string:
67 wxString m_string
, m_string2
;
69 // Listboxes may permit multiple selections, so their state
70 // is transferred to an integer-array class.
71 wxArrayInt m_listbox_choices
;
73 // Comboboxes differ from listboxes--validators transfer
74 // the string entered in the combobox's text-edit field.
75 wxString m_combobox_choice
;
77 // variables handled by wxNumericTextValidator
81 bool m_checkbox_state
;
82 int m_radiobox_choice
;
85 class MyComboBoxValidator
: public wxValidator
88 MyComboBoxValidator(const MyComboBoxValidator
& tocopy
) { m_var
=tocopy
.m_var
; }
89 MyComboBoxValidator(wxString
* var
) { m_var
=var
; }
91 virtual bool Validate(wxWindow
* parent
);
92 virtual wxObject
* Clone() const { return new MyComboBoxValidator(*this); }
94 // Called to transfer data to the window
95 virtual bool TransferToWindow();
97 // Called to transfer data from the window
98 virtual bool TransferFromWindow();
106 VALIDATE_DIALOG_ID
= wxID_HIGHEST
,
108 VALIDATE_TEST_DIALOG
,
109 VALIDATE_TOGGLE_BELL
,