]> git.saurik.com Git - wxWidgets.git/blob - samples/menu/menu.cpp
compilation fix
[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 #ifdef __WXUNIVERSAL__
435 // wxMessageBox not implemented yet
436 wxLogMessage("wxWindows menu sample\n© 1999-2001 Vadim Zeitlin");
437 #else
438 (void)wxMessageBox("wxWindows menu sample\n© 1999-2001 Vadim Zeitlin",
439 "About wxWindows menu sample",
440 wxICON_INFORMATION);
441 #endif
442 }
443
444 void MyFrame::OnDeleteMenu(wxCommandEvent& WXUNUSED(event))
445 {
446 wxMenuBar *mbar = GetMenuBar();
447
448 size_t count = mbar->GetMenuCount();
449 if ( count == 2 )
450 {
451 // don't let delete the first 2 menus
452 wxLogError("Can't delete any more menus");
453 }
454 else
455 {
456 delete mbar->Remove(count - 1);
457 }
458 }
459
460 void MyFrame::OnInsertMenu(wxCommandEvent& WXUNUSED(event))
461 {
462 wxString title;
463 wxMenu *menu = CreateDummyMenu(&title);
464 GetMenuBar()->Insert(0, menu, title);
465 }
466
467 void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
468 {
469 wxString title;
470 wxMenu *menu = CreateDummyMenu(&title);
471 GetMenuBar()->Append(menu, title);
472 }
473
474 void MyFrame::OnToggleMenu(wxCommandEvent& WXUNUSED(event))
475 {
476 wxMenuBar *mbar = GetMenuBar();
477 if ( !m_menu )
478 {
479 // hide the menu
480 m_menu = mbar->Remove(0);
481 }
482 else
483 {
484 // restore it
485 mbar->Insert(0, m_menu, "&File");
486 m_menu = NULL;
487 }
488 }
489
490 void MyFrame::OnEnableMenu(wxCommandEvent& event)
491 {
492 wxMenuBar *mbar = GetMenuBar();
493 size_t count = mbar->GetMenuCount();
494
495 mbar->EnableTop(count - 1, event.IsChecked());
496 }
497
498 void MyFrame::OnGetLabelMenu(wxCommandEvent& WXUNUSED(event))
499 {
500 wxMenuBar *mbar = GetMenuBar();
501 size_t count = mbar->GetMenuCount();
502
503 wxLogMessage("The label of the last menu item is '%s'",
504 mbar->GetLabelTop(count - 1).c_str());
505 }
506
507 void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
508 {
509 wxMenuBar *mbar = GetMenuBar();
510 size_t count = mbar->GetMenuCount();
511
512 mbar->SetLabelTop(count - 1, "Dummy label &0");
513 }
514
515 void MyFrame::OnDummy(wxCommandEvent& event)
516 {
517 wxLogMessage("Dummy item #%d", event.GetId() - Menu_Dummy_First + 1);
518 }
519
520 void MyFrame::OnAppendMenuItem(wxCommandEvent& WXUNUSED(event))
521 {
522 wxMenuBar *menubar = GetMenuBar();
523 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
524
525 menu->AppendSeparator();
526 menu->Append(Menu_Dummy_Third, "&Third dummy item\tCtrl-F3",
527 "Checkable item", TRUE);
528 }
529
530 void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event))
531 {
532 wxMenuBar *menubar = GetMenuBar();
533
534 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
535
536 menu->Append(Menu_Dummy_Last, "&Dummy sub menu",
537 CreateDummyMenu(NULL), "Dummy sub menu help");
538 }
539
540 void MyFrame::OnDeleteMenuItem(wxCommandEvent& WXUNUSED(event))
541 {
542 wxMenuBar *menubar = GetMenuBar();
543 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
544
545 size_t count = menu->GetMenuItemCount();
546 if ( !count )
547 {
548 wxLogWarning("No items to delete!");
549 }
550 else
551 {
552 menu->Destroy(menu->GetMenuItems().Item(count - 1)->GetData());
553 }
554 }
555
556 void MyFrame::OnInsertMenuItem(wxCommandEvent& WXUNUSED(event))
557 {
558 wxMenuBar *menubar = GetMenuBar();
559 wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1);
560
561 menu->Insert(0, wxMenuItem::New(menu, Menu_Dummy_Fourth,
562 "Fourth dummy item\tCtrl-F4"));
563 menu->Insert(1, wxMenuItem::New(menu, wxID_SEPARATOR, ""));
564 }
565
566 void MyFrame::OnEnableMenuItem(wxCommandEvent& WXUNUSED(event))
567 {
568 wxMenuItem *item = GetLastMenuItem();
569
570 if ( item )
571 {
572 item->Enable(!item->IsEnabled());
573 }
574 }
575
576 void MyFrame::OnCheckMenuItem(wxCommandEvent& WXUNUSED(event))
577 {
578 wxMenuItem *item = GetLastMenuItem();
579
580 item->Toggle();
581 }
582
583 void MyFrame::OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event)
584 {
585 wxLogNull nolog;
586
587 wxMenuItem *item = GetLastMenuItem();
588
589 event.Enable(item && item->IsCheckable());
590 }
591
592 void MyFrame::OnGetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
593 {
594 wxMenuItem *item = GetLastMenuItem();
595
596 if ( item )
597 {
598 wxLogMessage("The label of the last menu item is '%s'",
599 item->GetLabel().c_str());
600 }
601 }
602
603 void MyFrame::OnSetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
604 {
605 wxMenuItem *item = GetLastMenuItem();
606
607 if ( item )
608 {
609 item->SetText("Dummy menu item text");
610 }
611 }
612
613 void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event))
614 {
615 wxMenuItem *item = GetLastMenuItem();
616
617 if ( item )
618 {
619 wxString msg;
620 msg << "The item is " << (item->IsEnabled() ? "enabled"
621 : "disabled")
622 << '\n';
623
624 if ( item->IsCheckable() )
625 {
626 msg << "It is checkable and " << (item->IsChecked() ? "" : "un")
627 << "checked\n";
628 }
629
630 #if wxUSE_ACCEL
631 wxAcceleratorEntry *accel = item->GetAccel();
632 if ( accel )
633 {
634 msg << "Its accelerator is ";
635
636 int flags = accel->GetFlags();
637 if ( flags & wxACCEL_ALT )
638 msg << wxT("Alt-");
639 if ( flags & wxACCEL_CTRL )
640 msg << wxT("Ctrl-");
641 if ( flags & wxACCEL_SHIFT )
642 msg << wxT("Shift-");
643
644 int code = accel->GetKeyCode();
645 switch ( code )
646 {
647 case WXK_F1:
648 case WXK_F2:
649 case WXK_F3:
650 case WXK_F4:
651 case WXK_F5:
652 case WXK_F6:
653 case WXK_F7:
654 case WXK_F8:
655 case WXK_F9:
656 case WXK_F10:
657 case WXK_F11:
658 case WXK_F12:
659 msg << wxT('F') << code - WXK_F1 + 1;
660 break;
661
662 // if there are any other keys wxGetAccelFromString() may return,
663 // we should process them here
664
665 default:
666 if ( wxIsalnum(code) )
667 {
668 msg << (wxChar)code;
669
670 break;
671 }
672
673 wxFAIL_MSG( wxT("unknown keyboard accel") );
674 }
675
676 delete accel;
677 }
678 else
679 {
680 msg << "It doesn't have an accelerator";
681 }
682 #endif // wxUSE_ACCEL
683
684 wxLogMessage(msg);
685 }
686 }
687
688 void MyFrame::OnRightUp(wxMouseEvent &event)
689 {
690 wxMenu menu("Test popup");
691
692 menu.Append(Menu_Help_About, "&About");
693 menu.Append(Menu_Popup_Submenu, "&Submenu", CreateDummyMenu(NULL));
694 menu.Append(Menu_Popup_ToBeDeleted, "To be &deleted");
695 menu.Append(Menu_Popup_ToBeChecked, "To be &checked", "", TRUE);
696 menu.Append(Menu_Popup_ToBeGreyed, "To be &greyed");
697 menu.AppendSeparator();
698 menu.Append(Menu_File_Quit, "E&xit");
699
700 menu.Delete(Menu_Popup_ToBeDeleted);
701 menu.Check(Menu_Popup_ToBeChecked, TRUE);
702 menu.Enable(Menu_Popup_ToBeGreyed, FALSE);
703
704 PopupMenu(&menu, event.GetX(), event.GetY());
705
706 // test for destroying items in popup menus
707 #if 0 // doesn't work in wxGTK!
708 menu.Destroy(Menu_Popup_Submenu);
709
710 PopupMenu( &menu, event.GetX(), event.GetY() );
711 #endif // 0
712 }
713
714 void MyFrame::OnSize(wxSizeEvent& event)
715 {
716 // leave a band below for popup menu testing
717 wxSize size = GetClientSize();
718 m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4);
719
720 // this is really ugly but we have to do it as we can't just call
721 // event.Skip() because wxFrameBase would make the text control fill the
722 // entire frame then
723 #ifdef __WXUNIVERSAL__
724 PositionMenuBar();
725 #endif // __WXUNIVERSAL__
726 }
727