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