+#if wxUSE_TEXTDLG
+void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event))
+{
+ wxMenuBar *mbar = GetMenuBar();
+ size_t count = mbar->GetMenuCount();
+
+ wxCHECK_RET( count, wxT("no last menu?") );
+
+ wxString label = wxGetTextFromUser
+ (
+ wxT("Enter label to search for: "),
+ wxT("Find menu item"),
+ wxEmptyString,
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ size_t menuindex;
+ int index = wxNOT_FOUND;
+
+ for (menuindex = 0; (menuindex < count) && (index == wxNOT_FOUND); ++menuindex)
+ {
+ index = mbar->FindMenuItem(mbar->GetMenu(menuindex)->GetTitle(), label);
+ }
+ if (index == wxNOT_FOUND)
+ {
+ wxLogWarning(wxT("No menu item with label '%s'"), label.c_str());
+ }
+ else
+ {
+ wxLogMessage(wxT("Menu item %d in menu %lu has label '%s'"),
+ index, (unsigned long)menuindex, label.c_str());
+ }
+ }
+}
+#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, wxT("&About"));
+ menu.Append(Menu_Popup_Submenu, wxT("&Submenu"), CreateDummyMenu(NULL));
+ menu.Append(Menu_Popup_ToBeDeleted, wxT("To be &deleted"));
+ menu.AppendCheckItem(Menu_Popup_ToBeChecked, wxT("To be &checked"));
+ menu.Append(Menu_Popup_ToBeGreyed, wxT("To be &greyed"),
+ wxT("This menu item should be initially greyed out"));
+ menu.AppendSeparator();
+ menu.Append(Menu_File_Quit, wxT("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(wxT("Normal item selected"));
+}
+
+void MyFrame::OnTestCheck(wxCommandEvent& event)
+{
+ wxLogMessage(wxT("Check item %schecked"),
+ event.IsChecked() ? wxT("") : wxT("un"));
+}
+
+void MyFrame::OnTestRadio(wxCommandEvent& event)
+{
+ wxLogMessage(wxT("Radio item %d selected"),
+ event.GetId() - Menu_Test_Radio1 + 1);
+}
+
+#if USE_LOG_WINDOW
+void MyFrame::LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what)
+{
+ wxString msg;
+ msg << wxT("A ")
+ << ( event.IsPopup() ? wxT("popup ") : wxT("") )
+ << wxT("menu has been ")
+ << what;
+
+ if ( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
+ {
+ msg << wxT(" (id=") << event.GetId() << wxT(")");
+ }
+
+ msg << wxT(".");
+
+ 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__
+}
+
+// ----------------------------------------------------------------------------
+// MyDialog
+// ----------------------------------------------------------------------------
+
+MyDialog::MyDialog(wxWindow* parent)
+ : wxDialog(parent, wxID_ANY, "Test Dialog")
+{
+#if USE_LOG_WINDOW
+ // create the log text window
+ m_textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE);
+ m_textctrl->SetEditable(false);
+
+ m_textctrl->AppendText(wxT("Dialogs do not have menus, but popup menus should function the same\n\n")
+ wxT("Right click this text ctrl to test popup menus.\n"));
+#endif
+#ifdef __POCKETPC__
+ EnableContextMenu();
+#endif
+}
+
+#if USE_LOG_WINDOW
+void MyDialog::LogMenuOpenCloseOrHighlight(const wxMenuEvent& event, const wxChar *what)
+{
+ wxString msg;
+ msg << wxT("A ")
+ << ( event.IsPopup() ? wxT("popup ") : wxT("") )
+ << wxT("menu has been ")
+ << what;
+ if ( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
+ {
+ msg << wxT(" (id=") << event.GetId() << wxT(")");
+ }
+ msg << wxT(".\n");
+
+ m_textctrl->AppendText(msg);
+}
+#endif // USE_LOG_WINDOW
+#if USE_CONTEXT_MENU
+void MyDialog::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 MyDialog::ShowContextMenu(const wxPoint& pos)