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