]>
git.saurik.com Git - wxWidgets.git/blob - samples/validate/validate.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows validation sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/valtext.h"
32 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
33 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
34 EVT_MENU(VALIDATE_TEST_DIALOG
, MyFrame::OnTestDialog
)
35 EVT_MENU(VALIDATE_SILENT
, MyFrame::OnSilent
)
44 // Create the main frame window
45 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, "Validation Test", 50, 50, 300, 250);
55 // My frame constructor
56 MyFrame::MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
)
57 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
61 SetIcon(wxIcon("mondrian"));
64 SetIcon(wxIcon("aiai.xbm"));
68 wxMenu
*file_menu
= new wxMenu
;
70 file_menu
->Append(VALIDATE_TEST_DIALOG
, "&Test dialog", "Show example dialog");
71 file_menu
->Append(VALIDATE_SILENT
, "&Bell on error", "Toggle bell on error", TRUE
);
72 file_menu
->AppendSeparator();
73 file_menu
->Append(wxID_EXIT
, "E&xit");
75 file_menu
->Check(VALIDATE_SILENT
, wxValidator::IsSilent());
77 wxMenuBar
*menu_bar
= new wxMenuBar
;
78 menu_bar
->Append(file_menu
, "File");
84 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
89 void MyFrame::OnTestDialog(wxCommandEvent
& WXUNUSED(event
))
91 MyDialog
dialog(this, "Validation test dialog", wxPoint(100, 100), wxSize(340, 170));
96 void MyFrame::OnSilent(wxCommandEvent
& event
)
98 static bool s_silent
= FALSE
;
100 s_silent
= !s_silent
;
101 wxValidator::SetBellOnError(s_silent
);
106 MyDialog::MyDialog( wxWindow
*parent
, const wxString
& title
,
107 const wxPoint
& pos
, const wxSize
& size
, const long WXUNUSED(style
) ) :
108 wxDialog(parent
, VALIDATE_DIALOG_ID
, title
, pos
, size
, wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
)
110 wxButton
*but1
= new wxButton(this, wxID_OK
, "OK", wxPoint(250, 10), wxSize(80, 30));
111 (void)new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(250, 60), wxSize(80, 30));
113 (void)new wxTextCtrl(this, VALIDATE_TEXT
, "",
114 wxPoint(10, 10), wxSize(120, -1), 0, wxTextValidator(wxFILTER_ALPHA
, &g_data
.m_string
));
116 SetBackgroundColour(wxColour(0,0,255));