- menu.Append(Menu_Help_About, "&About");
- menu.Append(Menu_Popup_Submenu, "Submenu", CreateDummyMenu());
- menu.Append(Menu_Popup_ToBeDeleted, "To be deleted");
- menu.Append(Menu_Popup_ToBeChecked, "To be checked", "", TRUE);
- menu.Append(Menu_Popup_ToBeGreyed, "To be greyed");
+ if ( item )
+ {
+ wxString msg;
+ msg << _T("The item is ") << (item->IsEnabled() ? _T("enabled")
+ : _T("disabled"))
+ << '\n';
+
+ if ( item->IsCheckable() )
+ {
+ msg << _T("It is checkable and ") << (item->IsChecked() ? _T("") : _T("un"))
+ << _T("checked\n");
+ }
+
+#if wxUSE_ACCEL
+ wxAcceleratorEntry *accel = item->GetAccel();
+ if ( accel )
+ {
+ msg << _T("Its accelerator is ");
+
+ int flags = accel->GetFlags();
+ if ( flags & wxACCEL_ALT )
+ msg << wxT("Alt-");
+ if ( flags & wxACCEL_CTRL )
+ msg << wxT("Ctrl-");
+ if ( flags & wxACCEL_SHIFT )
+ msg << wxT("Shift-");
+
+ int code = accel->GetKeyCode();
+ switch ( code )
+ {
+ case WXK_F1:
+ case WXK_F2:
+ case WXK_F3:
+ case WXK_F4:
+ case WXK_F5:
+ case WXK_F6:
+ case WXK_F7:
+ case WXK_F8:
+ case WXK_F9:
+ case WXK_F10:
+ case WXK_F11:
+ case WXK_F12:
+ msg << wxT('F') << code - WXK_F1 + 1;
+ break;
+
+ // if there are any other keys wxGetAccelFromString() may return,
+ // we should process them here
+
+ default:
+ if ( wxIsalnum(code) )
+ {
+ msg << (wxChar)code;
+
+ break;
+ }
+
+ wxFAIL_MSG( wxT("unknown keyboard accel") );
+ }
+
+ delete accel;
+ }
+ else
+ {
+ msg << _T("It doesn't have an accelerator");
+ }
+#endif // wxUSE_ACCEL
+
+ wxLogMessage(msg);
+ }
+}
+
+void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event))
+{
+ wxMenuBar *mbar = GetMenuBar();
+ size_t count = mbar->GetMenuCount();
+
+ wxCHECK_RET( count, _T("no last menu?") );
+
+ wxString label = wxGetTextFromUser
+ (
+ _T("Enter label to search for: "),
+ _T("Find menu item"),
+ _T(""),
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ size_t menuindex = 0;
+ 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 %d has label '%s'"),
+ index, menuindex, label.c_str());
+ }
+ }
+}
+
+void MyFrame::ShowContextMenu(const wxPoint& pos)
+{
+ wxMenu menu(_T("Test popup"));
+
+ 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.Append(Menu_Popup_ToBeChecked, _T("To be &checked"), _T(""), TRUE);
+ menu.Append(Menu_Popup_ToBeGreyed, _T("To be &greyed"));