home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / samples / validate / validate.cpp < prev    next >
C/C++ Source or Header  |  2002-12-16  |  3KB  |  122 lines

  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: validate.cpp,v 1.7.6.1 2002/12/14 14:23:10 MBN Exp $
  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.     EVT_MENU(VALIDATE_SILENT, MyFrame::OnSilent)
  36. END_EVENT_TABLE()
  37.  
  38. IMPLEMENT_APP(MyApp)
  39.  
  40. MyData g_data;
  41.  
  42. bool MyApp::OnInit()
  43. {
  44.   // Create the main frame window
  45.   MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("Validation Test"), 50, 50, 300, 250);
  46.  
  47.   // Show the frame
  48.   frame->Show(TRUE);
  49.  
  50.   SetTopWindow(frame);
  51.  
  52.   return TRUE;
  53. }
  54.  
  55. // My frame constructor
  56. MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h)
  57.        : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
  58. {
  59.   // Give it an icon
  60. #ifdef __WXMSW__
  61.   SetIcon(wxIcon(_T("mondrian")));
  62. #endif
  63. #ifdef __X__
  64.   SetIcon(wxIcon(_T("aiai.xbm")));
  65. #endif
  66.  
  67.   // Make a menubar
  68.   wxMenu *file_menu = new wxMenu;
  69.  
  70.   file_menu->Append(VALIDATE_TEST_DIALOG, _T("&Test dialog"), _T("Show example dialog"));
  71.   file_menu->Append(VALIDATE_SILENT, _T("&Bell on error"), _T("Toggle bell on error"), TRUE);
  72.   file_menu->AppendSeparator();
  73.   file_menu->Append(wxID_EXIT, _T("E&xit"));
  74.  
  75.   file_menu->Check(VALIDATE_SILENT, !wxValidator::IsSilent());
  76.  
  77.   wxMenuBar *menu_bar = new wxMenuBar;
  78.   menu_bar->Append(file_menu, _T("File"));
  79.   SetMenuBar(menu_bar);
  80.  
  81.   CreateStatusBar(1);
  82. }
  83.  
  84. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  85. {
  86.     Close(TRUE);
  87. }
  88.  
  89. void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
  90. {
  91.     MyDialog dialog(this, _T("Validation test dialog"), wxPoint(100, 100), wxSize(340, 170));
  92.  
  93.     dialog.ShowModal();
  94. }
  95.  
  96. void MyFrame::OnSilent(wxCommandEvent& event)
  97. {
  98.     static bool s_silent = FALSE;
  99.  
  100.     s_silent = !s_silent;
  101.     wxValidator::SetBellOnError(s_silent);
  102.  
  103.     event.Skip();
  104. }
  105.  
  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)
  109. {
  110.   wxButton *but1 = new wxButton(this, wxID_OK, _T("OK"), wxPoint(250, 10), wxSize(80, 30));
  111.   (void)new wxButton(this, wxID_CANCEL, _T("Cancel"), wxPoint(250, 60), wxSize(80, 30));
  112.  
  113.   (void)new wxTextCtrl(this, VALIDATE_TEXT, _T(""),
  114.     wxPoint(10, 10), wxSize(120, -1), 0, wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
  115.  
  116.   SetBackgroundColour(wxColour(0,0,255));
  117.  
  118.   but1->SetFocus();
  119.   but1->SetDefault();
  120. }
  121.  
  122.