]>
Commit | Line | Data |
---|---|---|
717a57c2 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: samples/menu.cpp | |
3 | // Purpose: wxMenu/wxMenuBar sample | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 01.11.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1999 Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx/wx.h". | |
92a19c2e | 21 | #include "wx/wxprec.h" |
717a57c2 VZ |
22 | |
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
f91bf72f GD |
28 | #include "wx/app.h" |
29 | #include "wx/frame.h" | |
30 | #include "wx/menu.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/log.h" | |
33 | #include "wx/textctrl.h" | |
5c7766de | 34 | #include "wx/textdlg.h" |
717a57c2 VZ |
35 | #endif |
36 | ||
6d5b2a57 VZ |
37 | #if !wxUSE_MENUS |
38 | // nice try... | |
39 | #error "menu sample requires wxUSE_MENUS=1" | |
40 | #endif // wxUSE_MENUS | |
41 | ||
fcaf9e70 RR |
42 | #include "copy.xpm" |
43 | ||
717a57c2 VZ |
44 | // ---------------------------------------------------------------------------- |
45 | // classes | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | // Define a new application | |
49 | class MyApp: public wxApp | |
50 | { | |
51 | public: | |
52 | bool OnInit(); | |
53 | }; | |
54 | ||
55 | // Define a new frame | |
56 | class MyFrame: public wxFrame | |
57 | { | |
58 | public: | |
59 | MyFrame(); | |
60 | ||
3ca6a5f0 BP |
61 | virtual ~MyFrame(); |
62 | ||
63 | void LogMenuEvent(const wxCommandEvent& event); | |
717a57c2 | 64 | |
e421922f | 65 | protected: |
717a57c2 | 66 | void OnQuit(wxCommandEvent& event); |
e421922f VZ |
67 | void OnClearLog(wxCommandEvent& event); |
68 | ||
717a57c2 VZ |
69 | void OnAbout(wxCommandEvent& event); |
70 | ||
71 | void OnDummy(wxCommandEvent& event); | |
72 | ||
73 | void OnAppendMenuItem(wxCommandEvent& event); | |
74 | void OnAppendSubMenu(wxCommandEvent& event); | |
75 | void OnDeleteMenuItem(wxCommandEvent& event); | |
76 | void OnInsertMenuItem(wxCommandEvent& event); | |
77 | void OnCheckMenuItem(wxCommandEvent& event); | |
78 | void OnEnableMenuItem(wxCommandEvent& event); | |
79 | void OnGetLabelMenuItem(wxCommandEvent& event); | |
80 | void OnSetLabelMenuItem(wxCommandEvent& event); | |
a80c322c | 81 | void OnGetMenuItemInfo(wxCommandEvent& event); |
f6d90fb9 | 82 | void OnFindMenuItem(wxCommandEvent& event); |
717a57c2 VZ |
83 | |
84 | void OnAppendMenu(wxCommandEvent& event); | |
f03ec224 | 85 | void OnInsertMenu(wxCommandEvent& event); |
717a57c2 VZ |
86 | void OnDeleteMenu(wxCommandEvent& event); |
87 | void OnToggleMenu(wxCommandEvent& event); | |
88 | void OnEnableMenu(wxCommandEvent& event); | |
89 | void OnGetLabelMenu(wxCommandEvent& event); | |
90 | void OnSetLabelMenu(wxCommandEvent& event); | |
f6d90fb9 | 91 | void OnFindMenu(wxCommandEvent& event); |
717a57c2 | 92 | |
d65c269b VZ |
93 | void OnTestNormal(wxCommandEvent& event); |
94 | void OnTestCheck(wxCommandEvent& event); | |
95 | void OnTestRadio(wxCommandEvent& event); | |
96 | ||
c377f1be JS |
97 | void OnUpdateSubMenuNormal(wxUpdateUIEvent& event); |
98 | void OnUpdateSubMenuCheck(wxUpdateUIEvent& event); | |
99 | void OnUpdateSubMenuRadio(wxUpdateUIEvent& event); | |
100 | ||
0c2d3577 | 101 | #if defined( __WXMSW__ ) || defined( __WXMAC__ ) |
ccef86c7 VZ |
102 | void OnContextMenu(wxContextMenuEvent& event) |
103 | { ShowContextMenu(ScreenToClient(event.GetPosition())); } | |
104 | #else | |
105 | void OnRightUp(wxMouseEvent& event) | |
106 | { ShowContextMenu(event.GetPosition()); } | |
107 | #endif | |
108 | ||
109 | void OnMenuOpen(wxMenuEvent& event) | |
deadb443 | 110 | { LogMenuOpenOrClose(event, _T("opened")); event.Skip(); } |
ccef86c7 | 111 | void OnMenuClose(wxMenuEvent& event) |
deadb443 | 112 | { LogMenuOpenOrClose(event, _T("closed")); event.Skip(); } |
717a57c2 VZ |
113 | |
114 | void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event); | |
115 | ||
e421922f VZ |
116 | void OnSize(wxSizeEvent& event); |
117 | ||
717a57c2 | 118 | private: |
ccef86c7 VZ |
119 | void LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what); |
120 | void ShowContextMenu(const wxPoint& pos); | |
121 | ||
f03ec224 | 122 | wxMenu *CreateDummyMenu(wxString *title); |
717a57c2 VZ |
123 | |
124 | wxMenuItem *GetLastMenuItem() const; | |
125 | ||
e421922f VZ |
126 | // the menu previously detached from the menubar (may be NULL) |
127 | wxMenu *m_menu; | |
717a57c2 | 128 | |
e421922f | 129 | // the count of dummy menus already created |
f03ec224 VZ |
130 | size_t m_countDummy; |
131 | ||
e421922f VZ |
132 | // the control used for logging |
133 | wxTextCtrl *m_textctrl; | |
134 | ||
135 | // the previous log target | |
136 | wxLog *m_logOld; | |
137 | ||
717a57c2 VZ |
138 | DECLARE_EVENT_TABLE() |
139 | }; | |
140 | ||
3ca6a5f0 BP |
141 | // A small helper class which intercepts all menu events and logs them |
142 | class MyEvtHandler : public wxEvtHandler | |
143 | { | |
144 | public: | |
145 | MyEvtHandler(MyFrame *frame) { m_frame = frame; } | |
146 | ||
147 | void OnMenuEvent(wxCommandEvent& event) | |
148 | { | |
149 | m_frame->LogMenuEvent(event); | |
150 | ||
151 | event.Skip(); | |
152 | } | |
153 | ||
154 | private: | |
155 | MyFrame *m_frame; | |
156 | ||
157 | DECLARE_EVENT_TABLE() | |
158 | }; | |
159 | ||
717a57c2 VZ |
160 | // ---------------------------------------------------------------------------- |
161 | // constants | |
162 | // ---------------------------------------------------------------------------- | |
163 | ||
164 | enum | |
165 | { | |
166 | Menu_File_Quit = 100, | |
e421922f | 167 | Menu_File_ClearLog, |
717a57c2 VZ |
168 | |
169 | Menu_MenuBar_Toggle = 200, | |
170 | Menu_MenuBar_Append, | |
f03ec224 | 171 | Menu_MenuBar_Insert, |
717a57c2 VZ |
172 | Menu_MenuBar_Delete, |
173 | Menu_MenuBar_Enable, | |
174 | Menu_MenuBar_GetLabel, | |
175 | Menu_MenuBar_SetLabel, | |
f6d90fb9 | 176 | Menu_MenuBar_FindMenu, |
717a57c2 VZ |
177 | |
178 | Menu_Menu_Append = 300, | |
179 | Menu_Menu_AppendSub, | |
180 | Menu_Menu_Insert, | |
181 | Menu_Menu_Delete, | |
182 | Menu_Menu_Enable, | |
183 | Menu_Menu_Check, | |
184 | Menu_Menu_GetLabel, | |
185 | Menu_Menu_SetLabel, | |
a80c322c | 186 | Menu_Menu_GetInfo, |
f6d90fb9 | 187 | Menu_Menu_FindItem, |
717a57c2 | 188 | |
d65c269b VZ |
189 | Menu_Test_Normal = 400, |
190 | Menu_Test_Check, | |
191 | Menu_Test_Radio1, | |
192 | Menu_Test_Radio2, | |
193 | Menu_Test_Radio3, | |
194 | ||
c377f1be JS |
195 | Menu_SubMenu = 450, |
196 | Menu_SubMenu_Normal, | |
197 | Menu_SubMenu_Check, | |
198 | Menu_SubMenu_Radio1, | |
199 | Menu_SubMenu_Radio2, | |
200 | Menu_SubMenu_Radio3, | |
201 | ||
d65c269b | 202 | Menu_Dummy_First = 500, |
717a57c2 VZ |
203 | Menu_Dummy_Second, |
204 | Menu_Dummy_Third, | |
205 | Menu_Dummy_Fourth, | |
206 | Menu_Dummy_Last, | |
207 | ||
208 | Menu_Help_About = 1000, | |
209 | ||
210 | Menu_Popup_ToBeDeleted = 2000, | |
211 | Menu_Popup_ToBeGreyed, | |
212 | Menu_Popup_ToBeChecked, | |
213 | Menu_Popup_Submenu, | |
214 | ||
215 | Menu_Max | |
216 | }; | |
217 | ||
218 | // ---------------------------------------------------------------------------- | |
219 | // event tables | |
220 | // ---------------------------------------------------------------------------- | |
221 | ||
222 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
e421922f VZ |
223 | EVT_MENU(Menu_File_Quit, MyFrame::OnQuit) |
224 | EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog) | |
717a57c2 VZ |
225 | |
226 | EVT_MENU(Menu_Help_About, MyFrame::OnAbout) | |
227 | ||
228 | EVT_MENU(Menu_MenuBar_Toggle, MyFrame::OnToggleMenu) | |
229 | EVT_MENU(Menu_MenuBar_Append, MyFrame::OnAppendMenu) | |
f03ec224 | 230 | EVT_MENU(Menu_MenuBar_Insert, MyFrame::OnInsertMenu) |
717a57c2 VZ |
231 | EVT_MENU(Menu_MenuBar_Delete, MyFrame::OnDeleteMenu) |
232 | EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu) | |
233 | EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu) | |
234 | EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu) | |
f6d90fb9 | 235 | EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu) |
717a57c2 VZ |
236 | |
237 | EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem) | |
238 | EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu) | |
239 | EVT_MENU(Menu_Menu_Insert, MyFrame::OnInsertMenuItem) | |
240 | EVT_MENU(Menu_Menu_Delete, MyFrame::OnDeleteMenuItem) | |
241 | EVT_MENU(Menu_Menu_Enable, MyFrame::OnEnableMenuItem) | |
a80c322c | 242 | EVT_MENU(Menu_Menu_Check, MyFrame::OnCheckMenuItem) |
717a57c2 VZ |
243 | EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem) |
244 | EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem) | |
a80c322c | 245 | EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo) |
f6d90fb9 | 246 | EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem) |
717a57c2 | 247 | |
d65c269b VZ |
248 | EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal) |
249 | EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck) | |
250 | EVT_MENU(Menu_Test_Radio1, MyFrame::OnTestRadio) | |
251 | EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio) | |
252 | EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio) | |
253 | ||
c377f1be JS |
254 | EVT_UPDATE_UI(Menu_SubMenu_Normal, MyFrame::OnUpdateSubMenuNormal) |
255 | EVT_UPDATE_UI(Menu_SubMenu_Check, MyFrame::OnUpdateSubMenuCheck) | |
256 | EVT_UPDATE_UI(Menu_SubMenu_Radio1, MyFrame::OnUpdateSubMenuRadio) | |
257 | EVT_UPDATE_UI(Menu_SubMenu_Radio2, MyFrame::OnUpdateSubMenuRadio) | |
258 | EVT_UPDATE_UI(Menu_SubMenu_Radio3, MyFrame::OnUpdateSubMenuRadio) | |
259 | ||
717a57c2 VZ |
260 | EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy) |
261 | ||
262 | EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI) | |
263 | ||
0c2d3577 | 264 | #if defined( __WXMSW__ ) || defined( __WXMAC__ ) |
ccef86c7 VZ |
265 | EVT_CONTEXT_MENU(MyFrame::OnContextMenu) |
266 | #else | |
e421922f | 267 | EVT_RIGHT_UP(MyFrame::OnRightUp) |
ccef86c7 VZ |
268 | #endif |
269 | ||
270 | EVT_MENU_OPEN(MyFrame::OnMenuOpen) | |
271 | EVT_MENU_CLOSE(MyFrame::OnMenuClose) | |
e421922f VZ |
272 | |
273 | EVT_SIZE(MyFrame::OnSize) | |
717a57c2 VZ |
274 | END_EVENT_TABLE() |
275 | ||
3ca6a5f0 BP |
276 | BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler) |
277 | EVT_MENU(-1, MyEvtHandler::OnMenuEvent) | |
278 | END_EVENT_TABLE() | |
279 | ||
717a57c2 VZ |
280 | // ============================================================================ |
281 | // implementation | |
282 | // ============================================================================ | |
283 | ||
284 | // ---------------------------------------------------------------------------- | |
285 | // MyApp | |
286 | // ---------------------------------------------------------------------------- | |
287 | ||
288 | IMPLEMENT_APP(MyApp) | |
289 | ||
290 | // The `main program' equivalent, creating the windows and returning the | |
291 | // main frame | |
292 | bool MyApp::OnInit() | |
293 | { | |
294 | // Create the main frame window | |
295 | MyFrame* frame = new MyFrame; | |
296 | ||
297 | frame->Show(TRUE); | |
298 | ||
6d5b2a57 | 299 | #if wxUSE_STATUSBAR |
42ed7532 | 300 | frame->SetStatusText(_T("Welcome to wxWindows menu sample")); |
6d5b2a57 | 301 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
302 | |
303 | SetTopWindow(frame); | |
304 | ||
305 | return TRUE; | |
306 | } | |
307 | ||
308 | // ---------------------------------------------------------------------------- | |
309 | // MyFrame | |
310 | // ---------------------------------------------------------------------------- | |
311 | ||
312 | // Define my frame constructor | |
313 | MyFrame::MyFrame() | |
42ed7532 | 314 | : wxFrame((wxFrame *)NULL, -1, _T("wxWindows menu sample"), |
5c7766de | 315 | wxDefaultPosition, wxSize(400, 250)) |
717a57c2 | 316 | { |
268766dd | 317 | m_textctrl = NULL; |
717a57c2 | 318 | m_menu = NULL; |
f03ec224 | 319 | m_countDummy = 0; |
e421922f | 320 | m_logOld = NULL; |
717a57c2 | 321 | |
6d5b2a57 | 322 | #if wxUSE_STATUSBAR |
e421922f | 323 | CreateStatusBar(); |
6d5b2a57 | 324 | #endif // wxUSE_STATUSBAR |
717a57c2 VZ |
325 | |
326 | // create the menubar | |
327 | wxMenu *fileMenu = new wxMenu; | |
6d5b2a57 | 328 | |
e421922f | 329 | wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog, |
42ed7532 | 330 | _T("Clear &log\tCtrl-L")); |
e421922f VZ |
331 | item->SetBitmap(copy_xpm); |
332 | fileMenu->Append(item); | |
333 | fileMenu->AppendSeparator(); | |
42ed7532 | 334 | fileMenu->Append(Menu_File_Quit, _T("E&xit\tAlt-X"), _T("Quit menu sample")); |
717a57c2 VZ |
335 | |
336 | wxMenu *menubarMenu = new wxMenu; | |
42ed7532 MB |
337 | menubarMenu->Append(Menu_MenuBar_Append, _T("&Append menu\tCtrl-A"), |
338 | _T("Append a menu to the menubar")); | |
339 | menubarMenu->Append(Menu_MenuBar_Insert, _T("&Insert menu\tCtrl-I"), | |
340 | _T("Insert a menu into the menubar")); | |
341 | menubarMenu->Append(Menu_MenuBar_Delete, _T("&Delete menu\tCtrl-D"), | |
342 | _T("Delete the last menu from the menubar")); | |
343 | menubarMenu->Append(Menu_MenuBar_Toggle, _T("&Toggle menu\tCtrl-T"), | |
344 | _T("Toggle the first menu in the menubar"), TRUE); | |
717a57c2 | 345 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
346 | menubarMenu->Append(Menu_MenuBar_Enable, _T("&Enable menu\tCtrl-E"), |
347 | _T("Enable or disable the last menu"), TRUE); | |
717a57c2 | 348 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
349 | menubarMenu->Append(Menu_MenuBar_GetLabel, _T("&Get menu label\tCtrl-G"), |
350 | _T("Get the label of the last menu")); | |
351 | menubarMenu->Append(Menu_MenuBar_SetLabel, _T("&Set menu label\tCtrl-S"), | |
352 | _T("Change the label of the last menu")); | |
f6d90fb9 | 353 | menubarMenu->AppendSeparator(); |
42ed7532 MB |
354 | menubarMenu->Append(Menu_MenuBar_FindMenu, _T("&Find menu from label\tCtrl-F"), |
355 | _T("Find a menu by searching for its label")); | |
717a57c2 | 356 | |
c377f1be JS |
357 | wxMenu* subMenu = new wxMenu; |
358 | subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item")); | |
359 | subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Unchecked submenu item"), _T("Unchecked submenu item")); | |
360 | subMenu->AppendRadioItem(Menu_SubMenu_Radio1, _T("&Radio item 1"), _T("Radio item")); | |
361 | subMenu->AppendRadioItem(Menu_SubMenu_Radio2, _T("&Radio item 2"), _T("Radio item")); | |
362 | subMenu->AppendRadioItem(Menu_SubMenu_Radio3, _T("&Radio item 3"), _T("Radio item")); | |
363 | ||
364 | menubarMenu->Append(Menu_SubMenu, _T("Submenu"), subMenu); | |
365 | ||
717a57c2 | 366 | wxMenu *menuMenu = new wxMenu; |
42ed7532 MB |
367 | menuMenu->Append(Menu_Menu_Append, _T("&Append menu item\tAlt-A"), |
368 | _T("Append a menu item to the last menu")); | |
369 | menuMenu->Append(Menu_Menu_AppendSub, _T("&Append sub menu\tAlt-S"), | |
370 | _T("Append a sub menu to the last menu")); | |
371 | menuMenu->Append(Menu_Menu_Insert, _T("&Insert menu item\tAlt-I"), | |
372 | _T("Insert a menu item in head of the last menu")); | |
373 | menuMenu->Append(Menu_Menu_Delete, _T("&Delete menu item\tAlt-D"), | |
374 | _T("Delete the last menu item from the last menu")); | |
717a57c2 | 375 | menuMenu->AppendSeparator(); |
42ed7532 MB |
376 | menuMenu->Append(Menu_Menu_Enable, _T("&Enable menu item\tAlt-E"), |
377 | _T("Enable or disable the last menu item"), TRUE); | |
378 | menuMenu->Append(Menu_Menu_Check, _T("&Check menu item\tAlt-C"), | |
379 | _T("Check or uncheck the last menu item"), TRUE); | |
717a57c2 | 380 | menuMenu->AppendSeparator(); |
42ed7532 MB |
381 | menuMenu->Append(Menu_Menu_GetInfo, _T("Get menu item in&fo\tAlt-F"), |
382 | _T("Show the state of the last menu item")); | |
a80c322c | 383 | menuMenu->AppendSeparator(); |
42ed7532 MB |
384 | menuMenu->Append(Menu_Menu_FindItem, _T("Find menu item from label"), |
385 | _T("Find a menu item by searching for its label")); | |
717a57c2 | 386 | |
d65c269b | 387 | wxMenu *testMenu = new wxMenu; |
42ed7532 | 388 | testMenu->Append(Menu_Test_Normal, _T("&Normal item")); |
d65c269b | 389 | testMenu->AppendSeparator(); |
42ed7532 | 390 | testMenu->AppendCheckItem(Menu_Test_Check, _T("&Check item")); |
d65c269b | 391 | testMenu->AppendSeparator(); |
42ed7532 MB |
392 | testMenu->AppendRadioItem(Menu_Test_Radio1, _T("Radio item &1")); |
393 | testMenu->AppendRadioItem(Menu_Test_Radio2, _T("Radio item &2")); | |
394 | testMenu->AppendRadioItem(Menu_Test_Radio3, _T("Radio item &3")); | |
d65c269b | 395 | |
717a57c2 | 396 | wxMenu *helpMenu = new wxMenu; |
42ed7532 | 397 | helpMenu->Append(Menu_Help_About, _T("&About\tF1"), _T("About menu sample")); |
717a57c2 VZ |
398 | |
399 | wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE ); | |
400 | ||
42ed7532 MB |
401 | menuBar->Append(fileMenu, _T("&File")); |
402 | menuBar->Append(menubarMenu, _T("Menu&bar")); | |
403 | menuBar->Append(menuMenu, _T("&Menu")); | |
404 | menuBar->Append(testMenu, _T("&Test")); | |
405 | menuBar->Append(helpMenu, _T("&Help")); | |
717a57c2 VZ |
406 | |
407 | // these items should be initially checked | |
408 | menuBar->Check(Menu_MenuBar_Toggle, TRUE); | |
409 | menuBar->Check(Menu_MenuBar_Enable, TRUE); | |
410 | menuBar->Check(Menu_Menu_Enable, TRUE); | |
411 | menuBar->Check(Menu_Menu_Check, FALSE); | |
412 | ||
413 | // associate the menu bar with the frame | |
414 | SetMenuBar(menuBar); | |
3ca6a5f0 BP |
415 | |
416 | // intercept all menu events and log them in this custom event handler | |
417 | PushEventHandler(new MyEvtHandler(this)); | |
e421922f VZ |
418 | |
419 | // create the log text window | |
420 | m_textctrl = new wxTextCtrl(this, -1, _T(""), | |
421 | wxDefaultPosition, wxDefaultSize, | |
422 | wxTE_MULTILINE); | |
423 | m_textctrl->SetEditable(FALSE); | |
5c7766de VZ |
424 | |
425 | wxLog::SetTimestamp(NULL); | |
e421922f VZ |
426 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl)); |
427 | ||
5c7766de | 428 | wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ") |
e421922f | 429 | _T("append/insert/delete items to/from the last menu.\n") |
5c7766de VZ |
430 | _T("The commands from \"Menubar\" menu work with the ") |
431 | _T("menubar itself.\n\n") | |
e421922f | 432 | _T("Right click the band below to test popup menus.\n")); |
3ca6a5f0 BP |
433 | } |
434 | ||
435 | MyFrame::~MyFrame() | |
436 | { | |
437 | delete m_menu; | |
438 | ||
439 | // delete the event handler installed in ctor | |
440 | PopEventHandler(TRUE); | |
e421922f VZ |
441 | |
442 | // restore old logger | |
443 | delete wxLog::SetActiveTarget(m_logOld); | |
717a57c2 VZ |
444 | } |
445 | ||
f03ec224 | 446 | wxMenu *MyFrame::CreateDummyMenu(wxString *title) |
717a57c2 VZ |
447 | { |
448 | wxMenu *menu = new wxMenu; | |
42ed7532 | 449 | menu->Append(Menu_Dummy_First, _T("&First item\tCtrl-F1")); |
717a57c2 | 450 | menu->AppendSeparator(); |
42ed7532 | 451 | menu->Append(Menu_Dummy_Second, _T("&Second item\tCtrl-F2"), _T(""), TRUE); |
717a57c2 | 452 | |
f03ec224 VZ |
453 | if ( title ) |
454 | { | |
eb1ab6f9 | 455 | title->Printf(wxT("Dummy menu &%u"), (unsigned)++m_countDummy); |
f03ec224 VZ |
456 | } |
457 | ||
717a57c2 VZ |
458 | return menu; |
459 | } | |
460 | ||
461 | wxMenuItem *MyFrame::GetLastMenuItem() const | |
462 | { | |
463 | wxMenuBar *menubar = GetMenuBar(); | |
464 | wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); | |
465 | ||
65c0217e | 466 | wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetLast(); |
717a57c2 VZ |
467 | if ( !node ) |
468 | { | |
4693b20c | 469 | wxLogWarning(wxT("No last item in the last menu!")); |
717a57c2 VZ |
470 | |
471 | return NULL; | |
472 | } | |
473 | else | |
474 | { | |
475 | return node->GetData(); | |
476 | } | |
477 | } | |
478 | ||
3ca6a5f0 BP |
479 | void MyFrame::LogMenuEvent(const wxCommandEvent& event) |
480 | { | |
481 | int id = event.GetId(); | |
e421922f | 482 | if ( !GetMenuBar()->FindItem(id) ) |
d3d69314 | 483 | return; |
e421922f | 484 | |
4693b20c | 485 | wxString msg = wxString::Format(wxT("Menu command %d"), id); |
3ca6a5f0 BP |
486 | if ( GetMenuBar()->FindItem(id)->IsCheckable() ) |
487 | { | |
4693b20c | 488 | msg += wxString::Format(wxT(" (the item is currently %schecked)"), |
3ca6a5f0 BP |
489 | event.IsChecked() ? "" : "not "); |
490 | } | |
491 | ||
e421922f | 492 | wxLogMessage(msg); |
3ca6a5f0 BP |
493 | } |
494 | ||
495 | // ---------------------------------------------------------------------------- | |
496 | // menu callbacks | |
497 | // ---------------------------------------------------------------------------- | |
498 | ||
717a57c2 VZ |
499 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
500 | { | |
501 | Close(TRUE); | |
502 | } | |
503 | ||
e421922f VZ |
504 | void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) |
505 | { | |
506 | m_textctrl->Clear(); | |
507 | } | |
508 | ||
717a57c2 VZ |
509 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
510 | { | |
42ed7532 MB |
511 |