+#endif
+
+void MyFrame::ShowContextMenu(const wxPoint& pos)
+{
+ wxMenu menu;
+
+ if ( wxGetKeyState(WXK_SHIFT) )
+ {
+ // when Shift is pressed, demonstrate the use of a simple function
+ // returning the id of the item selected in the popup menu
+ menu.SetTitle("Choose one of:");
+ static const char *choices[] = { "Apple", "Banana", "Cherry" };
+ for ( size_t n = 0; n < WXSIZEOF(choices); n++ )
+ menu.Append(Menu_PopupChoice + n, choices[n]);
+
+ const int rc = GetPopupMenuSelectionFromUser(menu, pos);
+ if ( rc == wxID_NONE )
+ {
+ wxLogMessage("No selection");
+ }
+ else
+ {
+ wxLogMessage("You have selected \"%s\"",
+ choices[rc - Menu_PopupChoice]);
+ }
+ }
+ else // normal case, shift not pressed
+ {
+ menu.Append(Menu_Help_About, _T("&About"));
+ menu.Append(Menu_Popup_Submenu, _T("&Submenu"), CreateDummyMenu(NULL));
+ menu.Append(Menu_Popup_ToBeDeleted, _T("To be &deleted"));
+ menu.AppendCheckItem(Menu_Popup_ToBeChecked, _T("To be &checked"));
+ menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"),
+ _T("This menu item should be initially greyed out"));
+ menu.AppendSeparator();
+ menu.Append(Menu_File_Quit, _T("E&xit"));
+
+ menu.Delete(Menu_Popup_ToBeDeleted);
+ menu.Check(Menu_Popup_ToBeChecked, true);
+ menu.Enable(Menu_Popup_ToBeGreyed, false);
+
+ PopupMenu(&menu, pos);
+
+ // test for destroying items in popup menus
+#if 0 // doesn't work in wxGTK!
+ menu.Destroy(Menu_Popup_Submenu);
+
+ PopupMenu( &menu, event.GetX(), event.GetY() );
+#endif // 0
+ }
+}
+
+void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event))
+{
+ wxLogMessage(_T("Normal item selected"));
+}
+
+void MyFrame::OnTestCheck(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Check item %schecked"),
+ event.IsChecked() ? _T("") : _T("un"));
+}
+
+void MyFrame::OnTestRadio(wxCommandEvent& event)
+{
+ wxLogMessage(_T("Radio item %d selected"),
+ event.GetId() - Menu_Test_Radio1 + 1);
+}
+
+#if USE_LOG_WINDOW
+void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what)
+{
+ wxString msg;
+ msg << _T("A ")
+ << ( event.IsPopup() ? _T("popup ") : _T("") )
+ << _T("menu has been ")
+ << what
+ << _T(".");
+
+ wxLogStatus(this, msg.c_str());
+}
+#endif
+
+void MyFrame::OnUpdateSubMenuNormal(wxUpdateUIEvent& event)
+{
+ event.Enable(false);
+}
+
+void MyFrame::OnUpdateSubMenuCheck(wxUpdateUIEvent& event)
+{
+ event.Enable(true);
+}
+
+void MyFrame::OnUpdateSubMenuRadio(wxUpdateUIEvent& event)
+{
+ int which = (event.GetId() - Menu_SubMenu_Radio1 + 1);
+ if (which == 2)
+ event.Check(true);
+ else
+ event.Check(false);
+}
+
+#if USE_CONTEXT_MENU
+void MyFrame::OnContextMenu(wxContextMenuEvent& event)
+{
+ wxPoint point = event.GetPosition();
+ // If from keyboard
+ if (point.x == -1 && point.y == -1) {
+ wxSize size = GetSize();
+ point.x = size.x / 2;
+ point.y = size.y / 2;
+ } else {
+ point = ScreenToClient(point);
+ }
+ ShowContextMenu(point);
+}
+#endif
+
+void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
+{
+#if USE_LOG_WINDOW
+ if ( !m_textctrl )
+ return;
+
+ // leave a band below for popup menu testing
+ wxSize size = GetClientSize();
+ m_textctrl->SetSize(0, 0, size.x, (3*size.y)/4);
+#endif
+
+ // this is really ugly but we have to do it as we can't just call
+ // event.Skip() because wxFrameBase would make the text control fill the
+ // entire frame then
+#ifdef __WXUNIVERSAL__
+ PositionMenuBar();
+#endif // __WXUNIVERSAL__
+}
+