oops, restored accidentally checked in testing code
[wxWidgets.git] / samples / minimal / minimal.cpp
1 Index: samples/minimal/minimal.cpp
2 ===================================================================
3 RCS file: /pack/cvsroots/wxwidgets/wxWidgets/samples/minimal/minimal.cpp,v
4 retrieving revision 1.71
5 diff -B -b -u -2 -p -r1.71 minimal.cpp
6 --- samples/minimal/minimal.cpp 2006/06/29 13:47:45 1.71
7 +++ samples/minimal/minimal.cpp 2006/11/04 20:50:29
8 @@ -1,199 +0,0 @@
9 -/////////////////////////////////////////////////////////////////////////////
10 -// Name: minimal.cpp
11 -// Purpose: Minimal wxWidgets sample
12 -// Author: Julian Smart
13 -// Modified by:
14 -// Created: 04/01/98
15 -// RCS-ID: $Id$
16 -// Copyright: (c) Julian Smart
17 -// Licence: wxWindows licence
18 -/////////////////////////////////////////////////////////////////////////////
19 -
20 -// ============================================================================
21 -// declarations
22 -// ============================================================================
23 -
24 -// ----------------------------------------------------------------------------
25 -// headers
26 -// ----------------------------------------------------------------------------
27 -
28 -// For compilers that support precompilation, includes "wx/wx.h".
29 -#include "wx/wxprec.h"
30 -
31 -#ifdef __BORLANDC__
32 - #pragma hdrstop
33 -#endif
34 -
35 -// for all others, include the necessary headers (this file is usually all you
36 -// need because it includes almost all "standard" wxWidgets headers)
37 -#ifndef WX_PRECOMP
38 - #include "wx/wx.h"
39 -#endif
40 -
41 -// ----------------------------------------------------------------------------
42 -// resources
43 -// ----------------------------------------------------------------------------
44 -
45 -// the application icon (under Windows and OS/2 it is in resources and even
46 -// though we could still include the XPM here it would be unused)
47 -#if !defined(__WXMSW__) && !defined(__WXPM__)
48 - #include "../sample.xpm"
49 -#endif
50 -
51 -// ----------------------------------------------------------------------------
52 -// private classes
53 -// ----------------------------------------------------------------------------
54 -
55 -// Define a new application type, each program should derive a class from wxApp
56 -class MyApp : public wxApp
57 -{
58 -public:
59 - // override base class virtuals
60 - // ----------------------------
61 -
62 - // this one is called on application startup and is a good place for the app
63 - // initialization (doing it here and not in the ctor allows to have an error
64 - // return: if OnInit() returns false, the application terminates)
65 - virtual bool OnInit();
66 -};
67 -
68 -// Define a new frame type: this is going to be our main frame
69 -class MyFrame : public wxFrame
70 -{
71 -public:
72 - // ctor(s)
73 - MyFrame(const wxString& title);
74 -
75 - // event handlers (these functions should _not_ be virtual)
76 - void OnQuit(wxCommandEvent& event);
77 - void OnAbout(wxCommandEvent& event);
78 -
79 -private:
80 - // any class wishing to process wxWidgets events must use this macro
81 - DECLARE_EVENT_TABLE()
82 -};
83 -
84 -// ----------------------------------------------------------------------------
85 -// constants
86 -// ----------------------------------------------------------------------------
87 -
88 -// IDs for the controls and the menu commands
89 -enum
90 -{
91 - // menu items
92 - Minimal_Quit = wxID_EXIT,
93 -
94 - // it is important for the id corresponding to the "About" command to have
95 - // this standard value as otherwise it won't be handled properly under Mac
96 - // (where it is special and put into the "Apple" menu)
97 - Minimal_About = wxID_ABOUT
98 -};
99 -
100 -// ----------------------------------------------------------------------------
101 -// event tables and other macros for wxWidgets
102 -// ----------------------------------------------------------------------------
103 -
104 -// the event tables connect the wxWidgets events with the functions (event
105 -// handlers) which process them. It can be also done at run-time, but for the
106 -// simple menu events like this the static method is much simpler.
107 -BEGIN_EVENT_TABLE(MyFrame, wxFrame)
108 - EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
109 - EVT_MENU(Minimal_About, MyFrame::OnAbout)
110 -END_EVENT_TABLE()
111 -
112 -// Create a new application object: this macro will allow wxWidgets to create
113 -// the application object during program execution (it's better than using a
114 -// static object for many reasons) and also implements the accessor function
115 -// wxGetApp() which will return the reference of the right type (i.e. MyApp and
116 -// not wxApp)
117 -IMPLEMENT_APP(MyApp)
118 -
119 -// ============================================================================
120 -// implementation
121 -// ============================================================================
122 -
123 -// ----------------------------------------------------------------------------
124 -// the application class
125 -// ----------------------------------------------------------------------------
126 -
127 -// 'Main program' equivalent: the program execution "starts" here
128 -bool MyApp::OnInit()
129 -{
130 - // call the base class initialization method, currently it only parses a
131 - // few common command-line options but it could be do more in the future
132 - if ( !wxApp::OnInit() )
133 - return false;
134 -
135 - // create the main application window
136 - MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
137 -
138 - // and show it (the frames, unlike simple controls, are not shown when
139 - // created initially)
140 - frame->Show(true);
141 -
142 - // success: wxApp::OnRun() will be called which will enter the main message
143 - // loop and the application will run. If we returned false here, the
144 - // application would exit immediately.
145 - return true;
146 -}
147 -
148 -// ----------------------------------------------------------------------------
149 -// main frame
150 -// ----------------------------------------------------------------------------
151 -
152 -// frame constructor
153 -MyFrame::MyFrame(const wxString& title)
154 - : wxFrame(NULL, wxID_ANY, title)
155 -{
156 - // set the frame icon
157 - SetIcon(wxICON(sample));
158 -
159 -#if wxUSE_MENUS
160 - // create a menu bar
161 - wxMenu *fileMenu = new wxMenu;
162 -
163 - // the "About" item should be in the help menu
164 - wxMenu *helpMenu = new wxMenu;
165 - helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
166 -
167 - fileMenu->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
168 -
169 - // now append the freshly created menu to the menu bar...
170 - wxMenuBar *menuBar = new wxMenuBar();
171 - menuBar->Append(fileMenu, _T("&File"));
172 - menuBar->Append(helpMenu, _T("&Help"));
173 -
174 - // ... and attach this menu bar to the frame
175 - SetMenuBar(menuBar);
176 -#endif // wxUSE_MENUS
177 -
178 -#if wxUSE_STATUSBAR
179 - // create a status bar just for fun (by default with 1 pane only)
180 - CreateStatusBar(2);
181 - SetStatusText(_T("Welcome to wxWidgets!"));
182 -#endif // wxUSE_STATUSBAR
183 -}
184 -
185 -
186 -// event handlers
187 -
188 -void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
189 -{
190 - // true is to force the frame to close
191 - Close(true);
192 -}
193 -
194 -void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
195 -{
196 - wxMessageBox(wxString::Format(
197 - _T("Welcome to %s!\n")
198 - _T("\n")
199 - _T("This is the minimal wxWidgets sample\n")
200 - _T("running under %s."),
201 - wxVERSION_STRING,
202 - wxGetOsDescription().c_str()
203 - ),
204 - _T("About wxWidgets minimal sample"),
205 - wxOK | wxICON_INFORMATION,
206 - this);
207 -}