void OnGetLabelMenuItem(wxCommandEvent& event);
void OnSetLabelMenuItem(wxCommandEvent& event);
void OnGetMenuItemInfo(wxCommandEvent& event);
+ void OnFindMenuItem(wxCommandEvent& event);
void OnAppendMenu(wxCommandEvent& event);
void OnInsertMenu(wxCommandEvent& event);
void OnEnableMenu(wxCommandEvent& event);
void OnGetLabelMenu(wxCommandEvent& event);
void OnSetLabelMenu(wxCommandEvent& event);
+ void OnFindMenu(wxCommandEvent& event);
void OnTestNormal(wxCommandEvent& event);
void OnTestCheck(wxCommandEvent& event);
Menu_MenuBar_Enable,
Menu_MenuBar_GetLabel,
Menu_MenuBar_SetLabel,
+ Menu_MenuBar_FindMenu,
Menu_Menu_Append = 300,
Menu_Menu_AppendSub,
Menu_Menu_GetLabel,
Menu_Menu_SetLabel,
Menu_Menu_GetInfo,
+ Menu_Menu_FindItem,
Menu_Test_Normal = 400,
Menu_Test_Check,
EVT_MENU(Menu_MenuBar_Enable, MyFrame::OnEnableMenu)
EVT_MENU(Menu_MenuBar_GetLabel, MyFrame::OnGetLabelMenu)
EVT_MENU(Menu_MenuBar_SetLabel, MyFrame::OnSetLabelMenu)
+ EVT_MENU(Menu_MenuBar_FindMenu, MyFrame::OnFindMenu)
EVT_MENU(Menu_Menu_Append, MyFrame::OnAppendMenuItem)
EVT_MENU(Menu_Menu_AppendSub, MyFrame::OnAppendSubMenu)
EVT_MENU(Menu_Menu_GetLabel, MyFrame::OnGetLabelMenuItem)
EVT_MENU(Menu_Menu_SetLabel, MyFrame::OnSetLabelMenuItem)
EVT_MENU(Menu_Menu_GetInfo, MyFrame::OnGetMenuItemInfo)
+ EVT_MENU(Menu_Menu_FindItem, MyFrame::OnFindMenuItem)
EVT_MENU(Menu_Test_Normal, MyFrame::OnTestNormal)
EVT_MENU(Menu_Test_Check, MyFrame::OnTestCheck)
"Get the label of the last menu");
menubarMenu->Append(Menu_MenuBar_SetLabel, "&Set menu label\tCtrl-S",
"Change the label of the last menu");
+ menubarMenu->AppendSeparator();
+ menubarMenu->Append(Menu_MenuBar_FindMenu, "&Find menu from label\tCtrl-F",
+ "Find a menu by searching for its label");
wxMenu *menuMenu = new wxMenu;
menuMenu->Append(Menu_Menu_Append, "&Append menu item\tAlt-A",
menuMenu->AppendSeparator();
menuMenu->Append(Menu_Menu_GetInfo, "Get menu item in&fo\tAlt-F",
"Show the state of the last menu item");
+ menuMenu->AppendSeparator();
+ menuMenu->Append(Menu_Menu_FindItem, "Find menu item from label",
+ "Find a menu item by searching for its label");
wxMenu *testMenu = new wxMenu;
testMenu->Append(Menu_Test_Normal, "&Normal item");
}
}
+void MyFrame::OnFindMenu(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"),
+ "",
+ this
+ );
+
+ if ( !label.empty() )
+ {
+ int index = mbar->FindMenu(label);
+
+ if (index == wxNOT_FOUND)
+ {
+ wxLogWarning(wxT("No menu with label '%s'"), label.c_str());
+ }
+ else
+ {
+ wxLogMessage(wxT("Menu %d has label '%s'"), index, label.c_str());
+ }
+ }
+}
+
void MyFrame::OnDummy(wxCommandEvent& event)
{
wxLogMessage(wxT("Dummy item #%d"), event.GetId() - Menu_Dummy_First + 1);
}
}
+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"),
+ "",
+ 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("Test popup");