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