Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / samples / validate / validate.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: validate.h
3 // Purpose: wxWidgets validation sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/app.h"
12 #include "wx/combobox.h"
13 #include "wx/dialog.h"
14 #include "wx/dynarray.h"
15 #include "wx/frame.h"
16 #include "wx/listbox.h"
17 #include "wx/string.h"
18
19 // Define a new application type
20 class MyApp : public wxApp
21 {
22 public:
23 bool OnInit();
24 };
25
26 // Define a new frame type
27 class MyFrame : public wxFrame
28 {
29 public:
30 MyFrame(wxFrame *frame, const wxString&title, int x, int y, int w, int h);
31
32 void OnQuit(wxCommandEvent& event);
33 void OnTestDialog(wxCommandEvent& event);
34 void OnToggleBell(wxCommandEvent& event);
35
36 private:
37 wxListBox *m_listbox;
38 bool m_silent;
39
40 DECLARE_EVENT_TABLE()
41 };
42
43 class MyDialog : public wxDialog
44 {
45 public:
46 MyDialog(wxWindow *parent, const wxString& title,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
49 const long style = wxDEFAULT_DIALOG_STYLE);
50
51 bool TransferDataToWindow();
52 wxTextCtrl *m_text;
53 wxComboBox *m_combobox;
54
55 wxTextCtrl *m_numericTextInt;
56 wxTextCtrl *m_numericTextDouble;
57 };
58
59 class MyData
60 {
61 public:
62 MyData();
63
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;
68
69 // Listboxes may permit multiple selections, so their state
70 // is transferred to an integer-array class.
71 wxArrayInt m_listbox_choices;
72
73 // Comboboxes differ from listboxes--validators transfer
74 // the string entered in the combobox's text-edit field.
75 wxString m_combobox_choice;
76
77 // variables handled by wxNumericTextValidator
78 int m_intValue;
79 double m_doubleValue;
80
81 bool m_checkbox_state;
82 int m_radiobox_choice;
83 };
84
85 class MyComboBoxValidator : public wxValidator
86 {
87 public:
88 MyComboBoxValidator(const MyComboBoxValidator& tocopy) { m_var=tocopy.m_var; }
89 MyComboBoxValidator(wxString* var) { m_var=var; }
90
91 virtual bool Validate(wxWindow* parent);
92 virtual wxObject* Clone() const { return new MyComboBoxValidator(*this); }
93
94 // Called to transfer data to the window
95 virtual bool TransferToWindow();
96
97 // Called to transfer data from the window
98 virtual bool TransferFromWindow();
99
100 protected:
101 wxString* m_var;
102 };
103
104 enum
105 {
106 VALIDATE_DIALOG_ID = wxID_HIGHEST,
107
108 VALIDATE_TEST_DIALOG,
109 VALIDATE_TOGGLE_BELL,
110
111 VALIDATE_TEXT,
112 VALIDATE_TEXT2,
113 VALIDATE_LIST,
114 VALIDATE_CHECK,
115 VALIDATE_COMBO,
116 VALIDATE_RADIO
117 };