]>
Commit | Line | Data |
---|---|---|
3e0f9228 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dynamic.cpp | |
be5a51fb | 3 | // Purpose: Dynamic events wxWidgets sample |
3e0f9228 JS |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
f5d01a1c | 9 | // Licence: wxWindows license |
3e0f9228 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
788233da | 12 | #if defined(__GNUG__) && !defined(__APPLE__) |
3e0f9228 JS |
13 | #pragma implementation "dynamic.cpp" |
14 | #pragma interface "dynamic.cpp" | |
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 | ||
116a877a | 28 | #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXCOCOA__) |
3e0f9228 JS |
29 | #include "mondrian.xpm" |
30 | #endif | |
31 | ||
32 | // Define a new application type | |
33 | class MyApp: public wxApp | |
34 | { public: | |
35 | bool OnInit(void); | |
36 | }; | |
37 | ||
38 | // Define a new frame type | |
39 | class MyFrame: public wxFrame | |
40 | { public: | |
ab1ca7b3 | 41 | MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h); |
f5d01a1c | 42 | |
3e0f9228 JS |
43 | public: |
44 | void OnQuit(wxCommandEvent& event); | |
45 | void OnAbout(wxCommandEvent& event); | |
3e0f9228 JS |
46 | }; |
47 | ||
48 | // ID for the menu commands | |
f5d01a1c VZ |
49 | #define DYNAMIC_QUIT 1 |
50 | #define DYNAMIC_TEXT 101 | |
51 | #define DYNAMIC_ABOUT 102 | |
3e0f9228 JS |
52 | |
53 | // Create a new application object | |
f5d01a1c | 54 | IMPLEMENT_APP (MyApp) |
3e0f9228 JS |
55 | |
56 | // `Main program' equivalent, creating windows and returning main app frame | |
57 | bool MyApp::OnInit(void) | |
58 | { | |
59 | // Create the main frame window | |
be5a51fb | 60 | MyFrame *frame = new MyFrame(NULL, _T("Dynamic wxWidgets App"), 50, 50, 450, 340); |
3e0f9228 | 61 | |
566e85f6 RN |
62 | // You used to have to do some casting for param 4, but now there are type-safe handlers |
63 | frame->Connect( DYNAMIC_QUIT, wxID_ANY, | |
64 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) ); | |
65 | frame->Connect( DYNAMIC_ABOUT, wxID_ANY, | |
66 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) ); | |
3e0f9228 JS |
67 | |
68 | // Give it an icon | |
69 | #ifdef __WXMSW__ | |
ab1ca7b3 | 70 | frame->SetIcon(wxIcon(_T("mondrian"))); |
3e0f9228 JS |
71 | #else |
72 | frame->SetIcon(wxIcon(mondrian_xpm)); | |
73 | #endif | |
74 | ||
75 | // Make a menubar | |
76 | wxMenu *file_menu = new wxMenu; | |
77 | ||
ab1ca7b3 MB |
78 | file_menu->Append(DYNAMIC_ABOUT, _T("&About")); |
79 | file_menu->Append(DYNAMIC_QUIT, _T("E&xit")); | |
3e0f9228 | 80 | wxMenuBar *menu_bar = new wxMenuBar; |
ab1ca7b3 | 81 | menu_bar->Append(file_menu, _T("&File")); |
3e0f9228 JS |
82 | frame->SetMenuBar(menu_bar); |
83 | ||
84 | // Make a panel with a message | |
07850a49 | 85 | wxPanel *panel = new wxPanel(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL); |
3e0f9228 | 86 | |
07850a49 | 87 | (void)new wxStaticText(panel, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize, 0); |
3e0f9228 JS |
88 | |
89 | // Show the frame | |
07850a49 | 90 | frame->Show(true); |
f5d01a1c | 91 | |
3e0f9228 JS |
92 | SetTopWindow(frame); |
93 | ||
07850a49 | 94 | return true; |
3e0f9228 JS |
95 | } |
96 | ||
97 | // My frame constructor | |
ab1ca7b3 | 98 | MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): |
07850a49 | 99 | wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) |
3e0f9228 JS |
100 | {} |
101 | ||
102 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) | |
103 | { | |
07850a49 | 104 | Close(true); |
3e0f9228 JS |
105 | } |
106 | ||
107 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) | |
108 | { | |
ab1ca7b3 MB |
109 | wxMessageDialog dialog(this, _T("This demonstrates dynamic event handling"), |
110 | _T("About Dynamic"), wxYES_NO|wxCANCEL); | |
3e0f9228 JS |
111 | |
112 | dialog.ShowModal(); | |
113 | } | |
114 | ||
115 |