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