]> git.saurik.com Git - wxWidgets.git/blob - samples/validate/validate.cpp
wxConfig changes to be more logical.
[wxWidgets.git] / samples / validate / validate.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: validate.cpp
3 // Purpose: wxWindows validation sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 // #pragma implementation
14 // #pragma interface
15 #endif
16
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 #include "wx/valtext.h"
29
30 #include "validate.h"
31
32 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
33 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
34 EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
35 END_EVENT_TABLE()
36
37 IMPLEMENT_APP(MyApp)
38
39 MyData g_data;
40
41 bool MyApp::OnInit(void)
42 {
43 // Create the main frame window
44 MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "Validation Test", 50, 50, 300, 250);
45
46 // Give it an icon
47 #ifdef __WXMSW__
48 frame->SetIcon(wxIcon("mondrian"));
49 #endif
50 #ifdef __X__
51 frame->SetIcon(wxIcon("aiai.xbm"));
52 #endif
53
54 // Make a menubar
55 wxMenu *file_menu = new wxMenu;
56
57 file_menu->Append(VALIDATE_TEST_DIALOG, "&Test dialog");
58 file_menu->Append(wxID_EXIT, "E&xit");
59 wxMenuBar *menu_bar = new wxMenuBar;
60 menu_bar->Append(file_menu, "File");
61 frame->SetMenuBar(menu_bar);
62
63 frame->CreateStatusBar(1);
64
65 // Show the frame
66 frame->Show(TRUE);
67
68 SetTopWindow(frame);
69
70 return TRUE;
71 }
72
73 // My frame constructor
74 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
75 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
76 {}
77
78 void MyFrame::OnQuit(wxCommandEvent& event)
79 {
80 Close(TRUE);
81 }
82
83 void MyFrame::OnTestDialog(wxCommandEvent& event)
84 {
85 MyDialog dialog(this, "Validation test dialog", wxPoint(100, 100), wxSize(340, 170));
86
87 dialog.ShowModal();
88 }
89
90 MyDialog::MyDialog(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
91 const long style):
92 wxDialog(parent, VALIDATE_DIALOG_ID, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
93 {
94 wxButton *but1 = new wxButton(this, wxID_OK, "OK", wxPoint(250, 10), wxSize(80, 30));
95 wxButton *but2 = new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(250, 60), wxSize(80, 30));
96
97 wxTextCtrl *txt1 = new wxTextCtrl(this, VALIDATE_TEXT, "",
98 wxPoint(10, 10), wxSize(120, -1), 0, wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
99
100 // SetBackgroundColour(wxColour(0,0,255));
101
102 but1->SetFocus();
103 but1->SetDefault();
104 }
105