- 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.x, pos.y);
-
- // test for destroying items in popup menus
+ 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