]> git.saurik.com Git - wxWidgets.git/blob - samples/dynamic/dynamic.cpp
removed assert which could be provoked by correct code
[wxWidgets.git] / samples / dynamic / dynamic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dynamic.cpp
3 // Purpose: Dynamic events wxWindows sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
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
28 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
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:
41 MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
42
43 public:
44 void OnQuit(wxCommandEvent& event);
45 void OnAbout(wxCommandEvent& event);
46 };
47
48 // ID for the menu commands
49 #define DYNAMIC_QUIT 1
50 #define DYNAMIC_TEXT 101
51 #define DYNAMIC_ABOUT 102
52
53 // Create a new application object
54 IMPLEMENT_APP (MyApp)
55
56 // `Main program' equivalent, creating windows and returning main app frame
57 bool MyApp::OnInit(void)
58 {
59 // Create the main frame window
60 MyFrame *frame = new MyFrame(NULL, "Dynamic wxWindows App", 50, 50, 450, 340);
61
62 frame->Connect( DYNAMIC_QUIT, -1, wxEVT_COMMAND_MENU_SELECTED,
63 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
64 &MyFrame::OnQuit );
65 frame->Connect( DYNAMIC_ABOUT, -1, wxEVT_COMMAND_MENU_SELECTED,
66 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
67 &MyFrame::OnAbout );
68
69 // Give it an icon
70 #ifdef __WXMSW__
71 frame->SetIcon(wxIcon("mondrian"));
72 #else
73 frame->SetIcon(wxIcon(mondrian_xpm));
74 #endif
75
76 // Make a menubar
77 wxMenu *file_menu = new wxMenu;
78
79 file_menu->Append(DYNAMIC_ABOUT, "&About");
80 file_menu->Append(DYNAMIC_QUIT, "E&xit");
81 wxMenuBar *menu_bar = new wxMenuBar;
82 menu_bar->Append(file_menu, "&File");
83 frame->SetMenuBar(menu_bar);
84
85 // Make a panel with a message
86 wxPanel *panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
87
88 (void)new wxStaticText(panel, 311, "Hello!", wxPoint(10, 10), wxSize(-1, -1), 0);
89
90 // Show the frame
91 frame->Show(TRUE);
92
93 SetTopWindow(frame);
94
95 return TRUE;
96 }
97
98 // My frame constructor
99 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
100 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
101 {}
102
103 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
104 {
105 Close(TRUE);
106 }
107
108 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
109 {
110 wxMessageDialog dialog(this, "This demonstrates dynamic event handling",
111 "About Dynamic", wxYES_NO|wxCANCEL);
112
113 dialog.ShowModal();
114 }
115
116