]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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$ | |
e2a6f233 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
9fdf3c38 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
c801d85f | 19 | #ifdef __GNUG__ |
9fdf3c38 VZ |
20 | #pragma implementation "minimal.cpp" |
21 | #pragma interface "minimal.cpp" | |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx/wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
9fdf3c38 | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
9fdf3c38 VZ |
31 | // for all others, include the necessary headers (this file is usually all you |
32 | // need because it includes almost all "standard" wxWindows headers | |
c801d85f | 33 | #ifndef WX_PRECOMP |
9fdf3c38 | 34 | #include "wx/wx.h" |
c801d85f KB |
35 | #endif |
36 | ||
9fdf3c38 VZ |
37 | // ---------------------------------------------------------------------------- |
38 | // ressources | |
39 | // ---------------------------------------------------------------------------- | |
40 | // the application icon | |
3dd4e4e0 | 41 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
9fdf3c38 | 42 | #include "mondrian.xpm" |
d355d3fe RR |
43 | #endif |
44 | ||
9fdf3c38 VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // private classes | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | // Define a new application type, each program should derive a class from wxApp | |
50 | class MyApp : public wxApp | |
51 | { | |
52 | public: | |
53 | // override base class virtuals | |
54 | // ---------------------------- | |
55 | ||
56 | // this one is called on application startup and is a good place for the app | |
57 | // initialization (doing it here and not in the ctor allows to have an error | |
58 | // return: if OnInit() returns false, the application terminates) | |
59 | virtual bool OnInit(); | |
c801d85f KB |
60 | }; |
61 | ||
9fdf3c38 VZ |
62 | // Define a new frame type: this is going to be our main frame |
63 | class MyFrame : public wxFrame | |
64 | { | |
65 | public: | |
66 | // ctor(s) | |
67 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
68 | ||
69 | // event handlers (these functions should _not_ be virtual) | |
c801d85f KB |
70 | void OnQuit(wxCommandEvent& event); |
71 | void OnAbout(wxCommandEvent& event); | |
c50f1fb9 VZ |
72 | |
73 | void OnPaint(wxPaintEvent& event); | |
c801d85f | 74 | |
9fdf3c38 VZ |
75 | private: |
76 | // any class wishing to process wxWindows events must use this macro | |
77 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
78 | }; |
79 | ||
9fdf3c38 VZ |
80 | // ---------------------------------------------------------------------------- |
81 | // constants | |
82 | // ---------------------------------------------------------------------------- | |
c801d85f | 83 | |
9fdf3c38 VZ |
84 | // IDs for the controls and the menu commands |
85 | enum | |
86 | { | |
87 | // menu items | |
88 | Minimal_Quit = 1, | |
cf1f0870 | 89 | Minimal_About |
9fdf3c38 VZ |
90 | }; |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // event tables and other macros for wxWindows | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | // the event tables connect the wxWindows events with the functions (event | |
97 | // handlers) which process them. It can be also done at run-time, but for the | |
98 | // simple menu events like this the static method is much simpler. | |
c801d85f | 99 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
9fdf3c38 VZ |
100 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) |
101 | EVT_MENU(Minimal_About, MyFrame::OnAbout) | |
c801d85f KB |
102 | END_EVENT_TABLE() |
103 | ||
9fdf3c38 VZ |
104 | // Create a new application object: this macro will allow wxWindows to create |
105 | // the application object during program execution (it's better than using a | |
106 | // static object for many reasons) and also declares the accessor function | |
107 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
108 | // not wxApp) | |
109 | IMPLEMENT_APP(MyApp) | |
110 | ||
111 | // ============================================================================ | |
112 | // implementation | |
113 | // ============================================================================ | |
c801d85f | 114 | |
9fdf3c38 VZ |
115 | // ---------------------------------------------------------------------------- |
116 | // the application class | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
119 | // `Main program' equivalent: the program execution "starts" here | |
120 | bool MyApp::OnInit() | |
121 | { | |
122 | // Create the main application window | |
123 | MyFrame *frame = new MyFrame("Minimal wxWindows App", | |
124 | wxPoint(50, 50), wxSize(450, 340)); | |
125 | ||
126 | // Show it and tell the application that it's our main window | |
127 | // @@@ what does it do exactly, in fact? is it necessary here? | |
128 | frame->Show(TRUE); | |
129 | SetTopWindow(frame); | |
130 | ||
131 | // success: wxApp::OnRun() will be called which will enter the main message | |
132 | // loop and the application will run. If we returned FALSE here, the | |
133 | // application would exit immediately. | |
134 | return TRUE; | |
135 | } | |
136 | ||
137 | // ---------------------------------------------------------------------------- | |
138 | // main frame | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
141 | // frame constructor | |
142 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
143 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
c801d85f | 144 | { |
9fdf3c38 VZ |
145 | // set the frame icon |
146 | SetIcon(wxICON(mondrian)); | |
c801d85f | 147 | |
9fdf3c38 | 148 | // create a menu bar |
1ecffbff | 149 | wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF); |
c801d85f | 150 | |
ab46dc18 | 151 | menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); |
9fdf3c38 | 152 | menuFile->AppendSeparator(); |
ab46dc18 | 153 | menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); |
c801d85f | 154 | |
9fdf3c38 | 155 | // now append the freshly created menu to the menu bar... |
ae53c98c | 156 | wxMenuBar *menuBar = new wxMenuBar(); |
9fdf3c38 | 157 | menuBar->Append(menuFile, "&File"); |
c801d85f | 158 | |
9fdf3c38 VZ |
159 | // ... and attach this menu bar to the frame |
160 | SetMenuBar(menuBar); | |
c801d85f | 161 | |
c50f1fb9 | 162 | #if wxUSE_STATUSBAR |
9fdf3c38 | 163 | // create a status bar just for fun (by default with 1 pane only) |
47d67540 | 164 | CreateStatusBar(2); |
9fdf3c38 | 165 | SetStatusText("Welcome to wxWindows!"); |
c50f1fb9 | 166 | #endif // wxUSE_STATUSBAR |
c801d85f KB |
167 | } |
168 | ||
c801d85f | 169 | |
9fdf3c38 VZ |
170 | // event handlers |
171 | ||
172 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
c801d85f | 173 | { |
9fdf3c38 VZ |
174 | // TRUE is to force the frame to close |
175 | Close(TRUE); | |
c801d85f KB |
176 | } |
177 | ||
9fdf3c38 | 178 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
c801d85f | 179 | { |
2f877010 | 180 | wxString msg; |
9f06bcb3 RR |
181 | msg.Printf( _T("This is the about dialog of minimal sample.\n") |
182 | _T("Welcome to %s") | |
2f877010 | 183 | #ifdef wxBETA_NUMBER |
9f06bcb3 | 184 | _T(" (beta %d)!") |
2f877010 VZ |
185 | #endif // wxBETA_NUMBER |
186 | , wxVERSION_STRING | |
187 | #ifdef wxBETA_NUMBER | |
188 | , wxBETA_NUMBER | |
189 | #endif // wxBETA_NUMBER | |
190 | ); | |
191 | ||
192 | wxMessageBox(msg, "About Minimal", wxOK | wxICON_INFORMATION, this); | |
c801d85f | 193 | } |
c50f1fb9 | 194 |