]> git.saurik.com Git - wxWidgets.git/blob - samples/menu/menu.cpp
applied doc patch for wxPostEvent().
[wxWidgets.git] / samples / menu / menu.cpp
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 #include "copy.xpm"
43
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
61 virtual ~MyFrame();
62
63 void LogMenuEvent(const wxCommandEvent& event);
64
65 protected:
66 void OnQuit(wxCommandEvent& event);
67 void OnClearLog(wxCommandEvent& event);
68
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);
81 void OnGetMenuItemInfo(wxCommandEvent& event);
82
83 void OnAppendMenu(wxCommandEvent& event);
84 void OnInsertMenu(wxCommandEvent& event);
85 void OnDeleteMenu(wxCommandEvent& event);
86 void OnToggleMenu(wxCommandEvent& event);
87 void OnEnableMenu(wxCommandEvent& event);
88 void OnGetLabelMenu(wxCommandEvent& event);
89 void OnSetLabelMenu(wxCommandEvent& event);
90
91 void OnRightUp(wxMouseEvent& event);
92
93 void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event);
94
95 void OnSize(wxSizeEvent& event);
96
97 private:
98 wxMenu *CreateDummyMenu(wxString *title);
99
100 wxMenuItem *GetLastMenuItem() const;
101
102 // the menu previously detached from the menubar (may be NULL)
103 wxMenu *m_menu;
104
105 // the count of dummy menus already created
106 size_t m_countDummy;
107
108 // the control used for logging
109 wxTextCtrl *m_textctrl;
110
111 // the previous log target
112 wxLog *m_logOld;
113
114 DECLARE_EVENT_TABLE()
115 };
116
117 // A small helper class which intercepts all menu events and logs them
118 class MyEvtHandler : public wxEvtHandler
119 {
120 public:
121 MyEvtHandler(MyFrame *frame) { m_frame = frame; }
122
123 void OnMenuEvent(wxCommandEvent& event)
124 {
125 m_frame->LogMenuEvent(event);
126
127 event.Skip();
128 }
129
130 private:
131 MyFrame *m_frame;
132
133 DECLARE_EVENT_TABLE()
134 };
135
136 // ----------------------------------------------------------------------------
137 // constants
138 // ----------------------------------------------------------------------------
139
140 enum
141 {
142 Menu_File_Quit = 100,
143 Menu_File_ClearLog,
144
145 Menu_MenuBar_Toggle = 200,
146 Menu_MenuBar_Append,
147 Menu_MenuBar_Insert,
148 Menu_MenuBar_Delete,
149 Menu_MenuBar_Enable,
150 Menu_MenuBar_GetLabel,
151 Menu_MenuBar_SetLabel,
152
153 Menu_Menu_Append = 300,
154 Menu_Menu_AppendSub,
155 Menu_Menu_Insert,
156 Menu_Menu_Delete,
157 Menu_Menu_Enable,
158 Menu_Menu_Check,
159 Menu_Menu_GetLabel,
160 Menu_Menu_SetLabel,
161 Menu_Menu_GetInfo,
162
163 Menu_Dummy_First = 400,
164 Menu_Dummy_Second,
165 Menu_Dummy_Third,
166 Menu_Dummy_Fourth,
167 Menu_Dummy_Last,
168
169 Menu_Help_About = 1000,
170
171 Menu_Popup_ToBeDeleted = 2000,
172 Menu_Popup_ToBeGreyed,
173 Menu_Popup_ToBeChecked,
174 Menu_Popup_Submenu,
175
176 Menu_Max
177 };
178
179 // ----------------------------------------------------------------------------
180 // event tables
181 // ----------------------------------------------------------------------------
182
183 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
184 EVT_MENU(Menu_File_Quit, MyFrame::OnQuit)
185 EVT_MENU(Menu_File_ClearLog, MyFrame::OnClearLog)
186
187 EVT_MENU(Menu_Help_About, MyFrame::OnAbout)
188
189 EVT_MENU(Menu_MenuBar_Toggle, MyFrame::OnToggleMenu)
190 EVT_MENU(Menu_MenuBar_Append, MyFrame::OnAppendMenu)
191 EVT_MENU(Menu_MenuBar_Insert, MyFrame::OnInsertMenu)
192 EVT_MENU(Menu_MenuBar_Delete, MyFrame::OnDeleteMenu)
193 EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu)
194 EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu)
195 EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu)
196
197 EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem)
198 EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu)
199 EVT_MENU(Menu_Menu_Insert, MyFrame::OnInsertMenuItem)
200 EVT_MENU(Menu_Menu_Delete, MyFrame::OnDeleteMenuItem)
201 EVT_MENU(Menu_Menu_Enable, MyFrame::OnEnableMenuItem)
202 EVT_MENU(Menu_Menu_Check, MyFrame::OnCheckMenuItem)
203 EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem)
204 EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem)
205 EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo)
206
207 EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy)
208
209 EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI)
210
211 EVT_RIGHT_UP(MyFrame::OnRightUp)
212
213 EVT_SIZE(MyFrame::OnSize)
214 END_EVENT_TABLE()
215
216 BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler)
217 EVT_MENU(-1, MyEvtHandler::OnMenuEvent)
218 END_EVENT_TABLE()
219
220 // ============================================================================
221 // implementation
222 // ============================================================================
223
224 // ----------------------------------------------------------------------------
225 // MyApp
226 // ----------------------------------------------------------------------------
227
228 IMPLEMENT_APP(MyApp)
229
230 // The `main program' equivalent, creating the windows and returning the
231 // main frame
232 bool MyApp::OnInit()
233 {
234 // Create the main frame window
235 MyFrame* frame = new MyFrame;
236
237 frame->Show(TRUE);
238
239 #if wxUSE_STATUSBAR
240 frame->SetStatusText("Welcome to wxWindows menu sample");
241 #endif // wxUSE_STATUSBAR
242
243 SetTopWindow(frame);
244
245 return TRUE;
246 }
247
248 // ----------------------------------------------------------------------------
249 // MyFrame
250 // ----------------------------------------------------------------------------
251
252 // Define my frame constructor
253 MyFrame::MyFrame()
254 : wxFrame((wxFrame *)NULL, -1, "wxWindows menu sample",
255 wxDefaultPosition, wxSize(400, 250))
256 {
257 m_textctrl = NULL;
258 m_menu = NULL;
259 m_countDummy = 0;
260 m_logOld = NULL;
261
262 #if wxUSE_STATUSBAR
263 CreateStatusBar();
264 #endif // wxUSE_STATUSBAR
265
266 // create the menubar
267 wxMenu *fileMenu = new wxMenu;
268
269 wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog,
270 "Clear &log\tCtrl-L");
271 item->SetBitmap(copy_xpm);
272 fileMenu->Append(item);
273 fileMenu->AppendSeparator();
274 fileMenu->Append(Menu_File_Quit, "E&xit\tAlt-X", "Quit menu sample");
275
276 wxMenu *menubarMenu = new wxMenu;
277 menubarMenu->Append(Menu_MenuBar_Append, "&Append menu\tCtrl-A",
278 "Append a menu to the menubar");
279 menubarMenu->Append(Menu_MenuBar_Insert, "&Insert menu\tCtrl-I",
280 "Insert a menu into the menubar");
281 menubarMenu->Append(Menu_MenuBar_Delete, "&Delete menu\tCtrl-D",
282 "Delete the last menu from the menubar");
283 menubarMenu->Append(Menu_MenuBar_Toggle, "&Toggle menu\tCtrl-T",
284 "Toggle the first menu in the menubar", TRUE);
285 menubarMenu->AppendSeparator();
286 menubarMenu->Append(Menu_MenuBar_Enable, "&Enable menu\tCtrl-E",
287 "Enable or disable the last menu", TRUE);
288 menubarMenu->AppendSeparator();
289 menubarMenu->Append(Menu_MenuBar_GetLabel, "&Get menu label\tCtrl-G",
290 "Get the label of the last menu");
291 menubarMenu->Append(Menu_MenuBar_SetLabel, "&Set menu label\tCtrl-S",
292 "Change the label of the last menu");
293
294 wxMenu *menuMenu = new wxMenu;
295 menuMenu->Append(Menu_Menu_Append, "&Append menu item\tAlt-A",
296 "Append a menu item to the last menu");
297 menuMenu->Append(Menu_Menu_AppendSub, "&Append sub menu\tAlt-S",
298 "Append a sub menu to the last menu");
299 menuMenu->Append(Menu_Menu_Insert, "&Insert menu item\tAlt-I",
300 "Insert a menu item in head of the last menu");
301 menuMenu->Append(Menu_Menu_Delete, "&Delete menu item\tAlt-D",
302 "Delete the last menu item from the last menu");
303 menuMenu->AppendSeparator();
304 menuMenu->Append(Menu_Menu_Enable, "&Enable menu item\tAlt-E",
305 "Enable or disable the last menu item", TRUE);
306 menuMenu->Append(Menu_Menu_Check, "&Check menu item\tAlt-C",
307 "Check or uncheck the last menu item", TRUE);
308 menuMenu->AppendSeparator();
309 menuMenu->Append(Menu_Menu_GetLabel, "&Get menu item label\tAlt-G",
310 "Get the label of the last menu item");
311 menuMenu->Append(Menu_Menu_SetLabel, "&Set menu item label\tAlt-S",
312 "Change the label of the last menu item");
313 menuMenu->AppendSeparator();
314 menuMenu->Append(Menu_Menu_GetInfo, "Get menu item in&fo\tAlt-F",
315 "Show the state of the last menu item");
316
317 wxMenu *helpMenu = new wxMenu;
318 helpMenu->Append(Menu_Help_About, "&About\tF1", "About menu sample");
319
320 wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
321
322 menuBar->Append(fileMenu, "&File");
323 menuBar->Append(menubarMenu, "Menu&bar");
324 menuBar->Append(menuMenu, "&Menu");
325 menuBar->Append(helpMenu, "&Help");
326
327 // these items should be initially checked
328 menuBar->Check(Menu_MenuBar_Toggle, TRUE);
329 menuBar->Check(Menu_MenuBar_Enable, TRUE);
330 menuBar->Check(Menu_Menu_Enable, TRUE);
331 menuBar->Check(Menu_Menu_Check, FALSE);
332
333 // associate the menu bar with the frame
334 SetMenuBar(menuBar);
335
336 // intercept all menu events and log them in this custom event handler
337 PushEventHandler(new MyEvtHandler(this));
338
339 // create the log text window
340 m_textctrl = new wxTextCtrl(this, -1, _T(""),
341 wxDefaultPosition, wxDefaultSize,
342 wxTE_MULTILINE);
343 m_textctrl->SetEditable(FALSE);
344
345 wxLog::SetTimestamp(NULL);
346 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_textctrl));
347
348 wxLogMessage(_T("Brief explanations: the commands or the \"Menu\" menu ")
349 _T("append/insert/delete items to/from the last menu.\n")
350 _T("The commands from \"Menubar\" menu work with the ")
351 _T("menubar itself.\n\n")
352 _T("Right click the band below to test popup menus.\n"));
353 }
354
355 MyFrame::~MyFrame()
356 {
357 delete m_menu;
358
359 // delete the event handler installed in ctor
360 PopEventHandler(TRUE);
361
362 // restore old logger
363 delete wxLog::SetActiveTarget(m_logOld);
364 }
365
366 wxMenu *MyFrame::CreateDummyMenu(wxString *title)
367 {
368 wxMenu *menu = new wxMenu;
369 menu->Append(Menu_Dummy_First, "&First item\tCtrl-F1");
370 menu->AppendSeparator();
371 menu->Append(Menu_Dummy_Second, "&Second item\tCtrl-F2", "", TRUE);
372
373 if ( title )
374 {
375 title->Printf(wxT("Dummy menu &%d"), ++m_countDummy);
376 }
377
378 return menu;
379 }
380
381 wxMenuItem *MyFrame::GetLastMenuItem() const
382 {
383 wxMenuBar *menubar = GetMenuBar();
384 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
385
386 wxMenuItemList::Node *node = menu->GetMenuItems().GetLast();
387 if ( !node )
388 {
389 wxLogWarning(wxT("No last item in the last menu!"));
390
391 return NULL;
392 }
393 else
394 {
395 return node->GetData();
396 }
397 }
398
399 void MyFrame::LogMenuEvent(const wxCommandEvent& event)
400 {
401 int id = event.GetId();
402 if ( !GetMenuBar()->FindItem(id) )
403 return;
404
405 wxString msg = wxString::Format(wxT("Menu command %d"), id);
406 if ( GetMenuBar()->FindItem(id)->IsCheckable() )
407 {
408 msg += wxString::Format(wxT(" (the item is currently %schecked)"),
409 event.IsChecked() ? "" : "not ");
410 }
411
412 wxLogMessage(msg);
413 }
414
415 // ----------------------------------------------------------------------------
416 // menu callbacks
417 // ----------------------------------------------------------------------------
418
419 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
420 {
421 Close(TRUE);
422 }
423
424 void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
425 {
426 m_textctrl->Clear();
427 }
428
429 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
430 {
431 (void)wxMessageBox("wxWindows menu sample\n© 1999-2001 Vadim Zeitlin",
432 "About wxWindows menu sample",
433 wxICON_INFORMATION);
434 }
435
436 void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
437 {
438 wxMenuBar *mbar = GetMenuBar();
439
440 size_t count = mbar->GetMenuCount();
441 if ( count == 2 )
442 {
443 // don't let delete the first 2 menus
444 wxLogError(wxT("Can't delete any more menus"));
445 }
446 else
447 {
448 delete mbar->Remove(count - 1);
449 }
450 }
451
452 void MyFrame::OnInsertMenu(wxCommandEvent& WXUNUSED(event))
453 {
454 wxString title;
455 wxMenu *menu = CreateDummyMenu(&title);
456 GetMenuBar()->Insert(0, menu, title);
457 }
458
459 void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
460 {
461 wxString title;
462 wxMenu *menu = CreateDummyMenu(&title);
463 GetMenuBar()->Append(menu, title);
464 }
465
466 void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event))
467 {
468 wxMenuBar *mbar = GetMenuBar();
469 if ( !m_menu )
470 {
471 // hide the menu
472 m_menu = mbar->Remove(0);
473 }
474 else
475 {
476 // restore it
477 mbar->Insert(0, m_menu, "&File");
478 m_menu = NULL;
479 }
480 }
481
482 void MyFrame::OnEnableMenu(wxCommandEvent& event)
483 {
484 wxMenuBar *mbar = GetMenuBar();
485 size_t count = mbar->GetMenuCount();
486
487 mbar->EnableTop(count - 1, event.IsChecked());
488 }
489
490 void MyFrame::OnGetLabelMenu(wxCommandEvent& WXUNUSED(event))
491 {
492 wxMenuBar *mbar = GetMenuBar();
493 size_t count = mbar->GetMenuCount();
494
495 wxCHECK_RET( count, _T("no last menu?") );
496
497 wxLogMessage(wxT("The label of the last menu item is '%s'"),
498 mbar->GetLabelTop(count - 1).c_str());
499 }
500
501 void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
502 {
503 wxMenuBar *mbar = GetMenuBar();
504 size_t count = mbar->GetMenuCount();
505
506 wxCHECK_RET( count, _T("no last menu?") );
507
508 wxString label = wxGetTextFromUser
509 (
510 _T("Enter new label: "),
511 _T("Change last menu text"),
512 mbar->GetLabelTop(count - 1),
513 this
514 );
515
516 if ( !label.empty() )
517 {
518 mbar->SetLabelTop(count - 1, label);
519 }
520 }
521
522 void MyFrame::OnDummy(wxCommandEvent& event)
523 {
524 wxLogMessage(wxT("Dummy item #%d"), event.GetId() - Menu_Dummy_First + 1);
525 }
526
527 void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event))
528 {
529 wxMenuBar *menubar = GetMenuBar();
530 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
531
532 menu->AppendSeparator();
533 menu->Append(Menu_Dummy_Third, "&Third dummy item\tCtrl-F3",
534 "Checkable item", TRUE);
535 }
536
537 void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event))
538 {
539 wxMenuBar *menubar = GetMenuBar();
540
541 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
542
543 menu->Append(Menu_Dummy_Last, "&Dummy sub menu",
544 CreateDummyMenu(NULL), "Dummy sub menu help");
545 }
546
547 void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event))
548 {
549 wxMenuBar *menubar = GetMenuBar();
550 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
551
552 size_t count = menu->GetMenuItemCount();
553 if ( !count )
554 {
555 wxLogWarning(wxT("No items to delete!"));
556 }
557 else
558 {
559 menu->Destroy(menu->GetMenuItems().Item(count - 1)->GetData());
560 }
561 }
562
563 void MyFrame::OnInsertMenuItem(wxCommandEvent& WXUNUSED(event))
564 {
565 wxMenuBar *menubar = GetMenuBar();
566 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
567
568 menu->Insert(0, wxMenuItem::New(menu, Menu_Dummy_Fourth,
569 "Fourth dummy item\tCtrl-F4"));
570 menu->Insert(1, wxMenuItem::New(menu, wxID_SEPARATOR, ""));
571 }
572
573 void MyFrame::OnEnableMenuItem(wxCommandEvent& WXUNUSED(event))
574 {
575 wxMenuItem *item = GetLastMenuItem();
576
577 if ( item )
578 {
579 item->Enable(!item->IsEnabled());
580 }
581 }
582
583 void MyFrame::OnCheckMenuItem(wxCommandEvent& WXUNUSED(event))
584 {
585 wxMenuItem *item = GetLastMenuItem();
586
587 item->Toggle();
588 }
589
590 void MyFrame::OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event)
591 {
592 wxLogNull nolog;
593
594 wxMenuItem *item = GetLastMenuItem();
595
596 event.Enable(item && item->IsCheckable());
597 }
598
599 void MyFrame::OnGetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
600 {
601 wxMenuItem *item = GetLastMenuItem();
602
603 if ( item )
604 {
605 wxLogMessage(wxT("The label of the last menu item is '%s'"),
606 item->GetLabel().c_str());
607 }
608 }
609
610 void MyFrame::OnSetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
611 {
612 wxMenuItem *item = GetLastMenuItem();
613
614 if ( item )
615 {
616 wxString label = wxGetTextFromUser
617 (
618 _T("Enter new label: "),
619 _T("Change last menu item text"),
620 item->GetLabel(),
621 this
622 );
623
624 if ( !label.empty() )
625 {
626 item->SetText(label);
627 }
628 }
629 }
630
631 void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
632 {
633 wxMenuItem *item = GetLastMenuItem();
634
635 if ( item )
636 {
637 wxString msg;
638 msg << "The item is " << (item->IsEnabled() ? "enabled"
639 : "disabled")
640 << '\n';
641
642 if ( item->IsCheckable() )
643 {
644 msg << "It is checkable and " << (item->IsChecked() ? "" : "un")
645 << "checked\n";
646 }
647
648 #if wxUSE_ACCEL
649 wxAcceleratorEntry *accel = item->GetAccel();
650 if ( accel )
651 {
652 msg << "Its accelerator is ";
653
654 int flags = accel->GetFlags();
655 if ( flags & wxACCEL_ALT )
656 msg << wxT("Alt-");
657 if ( flags & wxACCEL_CTRL )
658 msg << wxT("Ctrl-");
659 if ( flags & wxACCEL_SHIFT )
660 msg << wxT("Shift-");
661
662 int code = accel->GetKeyCode();
663 switch ( code )
664 {
665 case WXK_F1:
666 case WXK_F2:
667 case WXK_F3:
668 case WXK_F4:
669 case WXK_F5:
670 case WXK_F6:
671 case WXK_F7:
672 case WXK_F8:
673 case WXK_F9:
674 case WXK_F10:
675 case WXK_F11:
676 case WXK_F12:
677 msg << wxT('F') << code - WXK_F1 + 1;
678 break;
679
680 // if there are any other keys wxGetAccelFromString() may return,
681 // we should process them here
682
683 default:
684 if ( wxIsalnum(code) )
685 {
686 msg << (wxChar)code;
687
688 break;
689 }
690
691 wxFAIL_MSG( wxT("unknown keyboard accel") );
692 }
693
694 delete accel;
695 }
696 else
697 {
698 msg << "It doesn't have an accelerator";
699 }
700 #endif // wxUSE_ACCEL
701
702 wxLogMessage(msg);
703 }
704 }
705
706 void MyFrame::OnRightUp(wxMouseEvent &event)
707 {
708 wxMenu menu("Test popup");
709
710 menu.Append(Menu_Help_About, "&About");
711 menu.Append(Menu_Popup_Submenu, "&Submenu", CreateDummyMenu(NULL));
712 menu.Append(Menu_Popup_ToBeDeleted, "To be &deleted");
713 menu.Append(Menu_Popup_ToBeChecked, "To be &checked", "", TRUE);
714 menu.Append(Menu_Popup_ToBeGreyed, "To be &greyed");
715 menu.AppendSeparator();
716 menu.Append(Menu_File_Quit, "E&xit");
717
718 menu.Delete(Menu_Popup_ToBeDeleted);
719 menu.Check(Menu_Popup_ToBeChecked, TRUE);
720 menu.Enable(Menu_Popup_ToBeGreyed, FALSE);
721
722 PopupMenu(&menu, event.GetX(), event.GetY());
723
724 // test for destroying items in popup menus
725 #if 0 // doesn't work in wxGTK!
726 menu.Destroy(Menu_Popup_Submenu);
727
728 PopupMenu( &menu, event.GetX(), event.GetY() );
729 #endif // 0
730 }
731
732 void MyFrame::OnSize(wxSizeEvent& event)
733 {
734 if ( !m_textctrl )
735 return;
736
737 // leave a band below for popup menu testing
738 wxSize size = GetClientSize();
739 m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4);
740
741 // this is really ugly but we have to do it as we can't just call
742 // event.Skip() because wxFrameBase would make the text control fill the
743 // entire frame then
744 #ifdef __WXUNIVERSAL__
745 PositionMenuBar();
746 #endif // __WXUNIVERSAL__
747 }
748