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