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