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