]> git.saurik.com Git - wxWidgets.git/blame - samples/validate/validate.cpp
added wxMemoryOutputStream test
[wxWidgets.git] / samples / validate / validate.cpp
CommitLineData
457814b5
JS
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
a994f81b 9// Licence: wxWindows license
457814b5
JS
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
32BEGIN_EVENT_TABLE(MyFrame, wxFrame)
a994f81b
VZ
33 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
34 EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
35 EVT_MENU(VALIDATE_SILENT, MyFrame::OnSilent)
457814b5
JS
36END_EVENT_TABLE()
37
38IMPLEMENT_APP(MyApp)
39
a994f81b 40MyData g_data;
457814b5 41
a994f81b 42bool MyApp::OnInit()
457814b5
JS
43{
44 // Create the main frame window
a994f81b 45 MyFrame *frame = new MyFrame((wxFrame *) NULL, "Validation Test", 50, 50, 300, 250);
457814b5 46
a994f81b
VZ
47 // Show the frame
48 frame->Show(TRUE);
49
50 SetTopWindow(frame);
51
52 return TRUE;
53}
54
55// My frame constructor
56MyFrame::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))
58{
457814b5 59 // Give it an icon
2049ba38 60#ifdef __WXMSW__
a994f81b 61 SetIcon(wxIcon("mondrian"));
457814b5
JS
62#endif
63#ifdef __X__
a994f81b 64 SetIcon(wxIcon("aiai.xbm"));
457814b5
JS
65#endif
66
67 // Make a menubar
68 wxMenu *file_menu = new wxMenu;
69
a994f81b
VZ
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();
457814b5 73 file_menu->Append(wxID_EXIT, "E&xit");
457814b5 74
0a98aa1a 75 file_menu->Check(VALIDATE_SILENT, !wxValidator::IsSilent());
457814b5 76
a994f81b
VZ
77 wxMenuBar *menu_bar = new wxMenuBar;
78 menu_bar->Append(file_menu, "File");
79 SetMenuBar(menu_bar);
457814b5 80
a994f81b 81 CreateStatusBar(1);
457814b5
JS
82}
83
cb43b372 84void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 85{
a994f81b 86 Close(TRUE);
457814b5
JS
87}
88
cb43b372 89void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
457814b5 90{
a994f81b
VZ
91 MyDialog dialog(this, "Validation test dialog", wxPoint(100, 100), wxSize(340, 170));
92
93 dialog.ShowModal();
94}
95
96void MyFrame::OnSilent(wxCommandEvent& event)
97{
98 static bool s_silent = FALSE;
99
100 s_silent = !s_silent;
101 wxValidator::SetBellOnError(s_silent);
457814b5 102
a994f81b 103 event.Skip();
457814b5
JS
104}
105
a994f81b 106MyDialog::MyDialog( wxWindow *parent, const wxString& title,
cb43b372 107 const wxPoint& pos, const wxSize& size, const long WXUNUSED(style) ) :
a994f81b 108 wxDialog(parent, VALIDATE_DIALOG_ID, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
457814b5
JS
109{
110 wxButton *but1 = new wxButton(this, wxID_OK, "OK", wxPoint(250, 10), wxSize(80, 30));
cb43b372 111 (void)new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(250, 60), wxSize(80, 30));
457814b5 112
cb43b372 113 (void)new wxTextCtrl(this, VALIDATE_TEXT, "",
903f689b 114 wxPoint(10, 10), wxSize(120, -1), 0, wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
457814b5 115
cb43b372 116 SetBackgroundColour(wxColour(0,0,255));
457814b5
JS
117
118 but1->SetFocus();
119 but1->SetDefault();
120}
121