]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/dynamic/dynamic.cpp
added GetAllEncodingNames(), use it to select the correct encoding name to pass to...
[wxWidgets.git] / samples / dynamic / dynamic.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: dynamic.cpp
3// Purpose: Dynamic events wxWidgets 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 license
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(__APPLE__)
13#pragma implementation
14#pragma interface
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#include "wx/clntdata.h"
29
30#ifndef __WXMSW__
31#include "mondrian.xpm"
32#endif
33
34// Define a new application type
35class MyApp: public wxApp
36{
37public:
38 bool OnInit(void);
39};
40
41// Define a new frame type
42class MyFrame: public wxFrame
43{
44public:
45 MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
46
47public:
48 void OnQuit(wxCommandEvent& event);
49 void OnTest(wxCommandEvent& event);
50 void OnAbout(wxCommandEvent& event);
51
52protected:
53 wxShadowObject m_shadow;
54};
55
56// Define another new frame type
57class MySecondFrame: public MyFrame
58{
59public:
60 MySecondFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
61};
62
63// ID for the menu commands
64#define DYNAMIC_QUIT wxID_EXIT
65#define DYNAMIC_TEST 101
66#define DYNAMIC_ABOUT wxID_ABOUT
67
68// Create a new application object
69IMPLEMENT_APP (MyApp)
70
71// `Main program' equivalent, creating windows and returning main app frame
72bool MyApp::OnInit(void)
73{
74 // Create the main frame window
75 MyFrame *frame = new MyFrame(NULL, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
76
77 // Show the frame
78 frame->Show(true);
79
80 // Create the main frame window
81 MySecondFrame *frame2 = new MySecondFrame(NULL, _T("Dynamic wxWidgets App"), 150, 150, 450, 340);
82
83 // Show the frame
84 frame2->Show(true);
85
86 SetTopWindow(frame);
87
88 return true;
89}
90
91// -------------------------------------
92// MyFrame
93// -------------------------------------
94
95// Callback from wxShadowObject
96
97int cb_MyFrame_InitStatusbar( void* window, void* WXUNUSED(param) )
98{
99 MyFrame *frame = (MyFrame*) window;
100 frame->SetStatusText( wxT("Hello from MyFrame"), 0 );
101 return 0;
102}
103
104// My frame constructor
105MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
106 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
107{
108 // Give it an icon
109#ifdef __WXMSW__
110 SetIcon(wxIcon(_T("mondrian")));
111#else
112 SetIcon(wxIcon(mondrian_xpm));
113#endif
114
115 // Make a menubar
116 wxMenu *file_menu = new wxMenu;
117
118 file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
119 file_menu->Append(DYNAMIC_TEST, _T("&Test"));
120 file_menu->Append(DYNAMIC_QUIT, _T("E&xit"));
121 wxMenuBar *menu_bar = new wxMenuBar;
122 menu_bar->Append(file_menu, _T("&File"));
123 SetMenuBar(menu_bar);
124
125 // Make a panel with a message
126 wxPanel *panel = new wxPanel(this, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
127
128 (void)new wxStaticText(panel, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize, 0);
129
130 // You used to have to do some casting for param 4, but now there are type-safe handlers
131 Connect( DYNAMIC_QUIT, wxID_ANY,
132 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );
133 Connect( DYNAMIC_TEST, wxID_ANY,
134 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnTest) );
135 Connect( DYNAMIC_ABOUT, wxID_ANY,
136 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) );
137
138 CreateStatusBar();
139 m_shadow.AddMethod( wxT("OnTest"), &cb_MyFrame_InitStatusbar );
140}
141
142void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
143{
144 Close(true);
145}
146
147void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event) )
148{
149 m_shadow.InvokeMethod( wxT("OnTest"), this, NULL, NULL );
150}
151
152void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
153{
154 wxMessageDialog dialog(this, _T("This demonstrates dynamic event handling"),
155 _T("About Dynamic"), wxYES_NO|wxCANCEL);
156
157 dialog.ShowModal();
158}
159
160
161// -------------------------------------
162// MySecondFrame
163// -------------------------------------
164
165// Callback from wxShadowObject
166
167int cb_MySecondFrame_InitStatusbar( void* window, void* WXUNUSED(param) )
168{
169 MySecondFrame *frame = (MySecondFrame*) window;
170 frame->SetStatusText( wxT("Hello from MySecondFrame"), 0 );
171 return 0;
172}
173
174// My frame constructor
175MySecondFrame::MySecondFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
176 MyFrame(frame, title, x, y, w, h )
177{
178 m_shadow.AddMethod( wxT("OnTest"), &cb_MySecondFrame_InitStatusbar );
179}