1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets validation sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
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
;
62 // These data members are designed for transfer to and from
63 // controls, via validators. For instance, a text control's
64 // transferred value is a string:
65 wxString m_string
, m_string2
;
67 // Listboxes may permit multiple selections, so their state
68 // is transferred to an integer-array class.
69 wxArrayInt m_listbox_choices
;
71 // Comboboxes differ from listboxes--validators transfer
72 // the string entered in the combobox's text-edit field.
73 wxString m_combobox_choice
;
75 bool m_checkbox_state
;
76 int m_radiobox_choice
;
79 class MyComboBoxValidator
: public wxValidator
82 MyComboBoxValidator(const MyComboBoxValidator
& tocopy
) { m_var
=tocopy
.m_var
; }
83 MyComboBoxValidator(wxString
* var
) { m_var
=var
; }
85 virtual bool Validate(wxWindow
* parent
);
86 virtual wxObject
* Clone() const { return new MyComboBoxValidator(*this); }
88 // Called to transfer data to the window
89 virtual bool TransferToWindow();
91 // Called to transfer data from the window
92 virtual bool TransferFromWindow();
100 VALIDATE_DIALOG_ID
= wxID_HIGHEST
,
102 VALIDATE_TEST_DIALOG
,
103 VALIDATE_TOGGLE_BELL
,