1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamic events wxWidgets sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/clntdata.h"
31 #include "mondrian.xpm"
34 // Define a new application type
35 class MyApp
: public wxApp
41 // Define a new frame type
42 class MyFrame
: public wxFrame
45 MyFrame(wxFrame
*frame
, wxChar
*title
, int x
, int y
, int w
, int h
);
48 void OnQuit(wxCommandEvent
& event
);
49 void OnTest(wxCommandEvent
& event
);
50 void OnAbout(wxCommandEvent
& event
);
53 wxShadowObject m_shadow
;
56 // Define another new frame type
57 class MySecondFrame
: public MyFrame
60 MySecondFrame(wxFrame
*frame
, wxChar
*title
, int x
, int y
, int w
, int h
);
63 // ID for the menu commands
64 #define DYNAMIC_QUIT wxID_EXIT
65 #define DYNAMIC_TEST 101
66 #define DYNAMIC_ABOUT wxID_ABOUT
68 // Create a new application object
71 // `Main program' equivalent, creating windows and returning main app frame
72 bool MyApp::OnInit(void)
74 // Create the main frame window
75 MyFrame
*frame
= new MyFrame(NULL
, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
80 // Create the main frame window
81 MySecondFrame
*frame2
= new MySecondFrame(NULL
, _T("Dynamic wxWidgets App"), 150, 150, 450, 340);
91 // -------------------------------------
93 // -------------------------------------
95 // Callback from wxShadowObject
97 int cb_MyFrame_InitStatusbar( void* window
, void* WXUNUSED(param
) )
99 MyFrame
*frame
= (MyFrame
*) window
;
100 frame
->SetStatusText( wxT("Hello from MyFrame"), 0 );
104 // My frame constructor
105 MyFrame::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
))
110 SetIcon(wxIcon(_T("mondrian")));
112 SetIcon(wxIcon(mondrian_xpm
));
116 wxMenu
*file_menu
= new wxMenu
;
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
);
125 // Make a panel with a message
126 wxPanel
*panel
= new wxPanel(this, wxID_ANY
, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL
);
128 (void)new wxStaticText(panel
, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize
, 0);
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
) );
139 m_shadow
.AddMethod( wxT("OnTest"), &cb_MyFrame_InitStatusbar
);
142 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
147 void MyFrame::OnTest(wxCommandEvent
& WXUNUSED(event
) )
149 m_shadow
.InvokeMethod( wxT("OnTest"), this, NULL
, NULL
);
152 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
154 wxMessageDialog
dialog(this, _T("This demonstrates dynamic event handling"),
155 _T("About Dynamic"), wxYES_NO
|wxCANCEL
);
161 // -------------------------------------
163 // -------------------------------------
165 // Callback from wxShadowObject
167 int cb_MySecondFrame_InitStatusbar( void* window
, void* WXUNUSED(param
) )
169 MySecondFrame
*frame
= (MySecondFrame
*) window
;
170 frame
->SetStatusText( wxT("Hello from MySecondFrame"), 0 );
174 // My frame constructor
175 MySecondFrame::MySecondFrame(wxFrame
*frame
, wxChar
*title
, int x
, int y
, int w
, int h
):
176 MyFrame(frame
, title
, x
, y
, w
, h
)
178 m_shadow
.AddMethod( wxT("OnTest"), &cb_MySecondFrame_InitStatusbar
);