X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c2d357716383cdfdbc8dd867c20d4551a2603f7..0d8b87ac8ae0ababd4c0d725142532f6d592fdb2:/samples/menu/menu.cpp diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index 9464e3e0f4..7ca53327c4 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -94,6 +94,10 @@ protected: void OnTestCheck(wxCommandEvent& event); void OnTestRadio(wxCommandEvent& event); + void OnUpdateSubMenuNormal(wxUpdateUIEvent& event); + void OnUpdateSubMenuCheck(wxUpdateUIEvent& event); + void OnUpdateSubMenuRadio(wxUpdateUIEvent& event); + #if defined( __WXMSW__ ) || defined( __WXMAC__ ) void OnContextMenu(wxContextMenuEvent& event) { ShowContextMenu(ScreenToClient(event.GetPosition())); } @@ -103,9 +107,9 @@ protected: #endif void OnMenuOpen(wxMenuEvent& event) - { LogMenuOpenOrClose(event, _T("opened")); } + { LogMenuOpenOrClose(event, _T("opened")); event.Skip(); } void OnMenuClose(wxMenuEvent& event) - { LogMenuOpenOrClose(event, _T("closed")); } + { LogMenuOpenOrClose(event, _T("closed")); event.Skip(); } void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event); @@ -188,6 +192,13 @@ enum Menu_Test_Radio2, Menu_Test_Radio3, + Menu_SubMenu = 450, + Menu_SubMenu_Normal, + Menu_SubMenu_Check, + Menu_SubMenu_Radio1, + Menu_SubMenu_Radio2, + Menu_SubMenu_Radio3, + Menu_Dummy_First = 500, Menu_Dummy_Second, Menu_Dummy_Third, @@ -240,6 +251,12 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Menu_Test_Radio2, MyFrame::OnTestRadio) EVT_MENU(Menu_Test_Radio3, MyFrame::OnTestRadio) + EVT_UPDATE_UI(Menu_SubMenu_Normal, MyFrame::OnUpdateSubMenuNormal) + EVT_UPDATE_UI(Menu_SubMenu_Check, MyFrame::OnUpdateSubMenuCheck) + EVT_UPDATE_UI(Menu_SubMenu_Radio1, MyFrame::OnUpdateSubMenuRadio) + EVT_UPDATE_UI(Menu_SubMenu_Radio2, MyFrame::OnUpdateSubMenuRadio) + EVT_UPDATE_UI(Menu_SubMenu_Radio3, MyFrame::OnUpdateSubMenuRadio) + EVT_MENU_RANGE(Menu_Dummy_First, Menu_Dummy_Last, MyFrame::OnDummy) EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI) @@ -337,6 +354,15 @@ MyFrame::MyFrame() menubarMenu->Append(Menu_MenuBar_FindMenu, _T("&Find menu from label\tCtrl-F"), _T("Find a menu by searching for its label")); + wxMenu* subMenu = new wxMenu; + subMenu->Append(Menu_SubMenu_Normal, _T("&Normal submenu item"), _T("Disabled submenu item")); + subMenu->AppendCheckItem(Menu_SubMenu_Check, _T("&Unchecked submenu item"), _T("Unchecked submenu item")); + subMenu->AppendRadioItem(Menu_SubMenu_Radio1, _T("&Radio item 1"), _T("Radio item")); + subMenu->AppendRadioItem(Menu_SubMenu_Radio2, _T("&Radio item 2"), _T("Radio item")); + subMenu->AppendRadioItem(Menu_SubMenu_Radio3, _T("&Radio item 3"), _T("Radio item")); + + menubarMenu->Append(Menu_SubMenu, _T("Submenu"), subMenu); + wxMenu *menuMenu = new wxMenu; menuMenu->Append(Menu_Menu_Append, _T("&Append menu item\tAlt-A"), _T("Append a menu item to the last menu")); @@ -437,7 +463,7 @@ wxMenuItem *MyFrame::GetLastMenuItem() const wxMenuBar *menubar = GetMenuBar(); wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); - wxMenuItemList::Node *node = menu->GetMenuItems().GetLast(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetLast(); if ( !node ) { wxLogWarning(wxT("No last item in the last menu!")); @@ -817,8 +843,8 @@ void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event)) } else { - wxLogMessage(wxT("Menu item %d in menu %d has label '%s'"), - index, menuindex, label.c_str()); + wxLogMessage(wxT("Menu item %d in menu %lu has label '%s'"), + index, (unsigned long)menuindex, label.c_str()); } } } @@ -831,7 +857,8 @@ void MyFrame::ShowContextMenu(const wxPoint& pos) 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")); + 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")); @@ -849,7 +876,7 @@ void MyFrame::ShowContextMenu(const wxPoint& pos) #endif // 0 } -void MyFrame::OnTestNormal(wxCommandEvent& event) +void MyFrame::OnTestNormal(wxCommandEvent& WXUNUSED(event)) { wxLogMessage(_T("Normal item selected")); } @@ -872,7 +899,27 @@ void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what) event.IsPopup() ? _T("popup ") : _T(""), what); } -void MyFrame::OnSize(wxSizeEvent& event) +void MyFrame::OnUpdateSubMenuNormal(wxUpdateUIEvent& event) +{ + event.Enable(FALSE); +} + +void MyFrame::OnUpdateSubMenuCheck(wxUpdateUIEvent& event) +{ + event.Enable(TRUE); + event.Check(TRUE); +} + +void MyFrame::OnUpdateSubMenuRadio(wxUpdateUIEvent& event) +{ + int which = (event.GetId() - Menu_SubMenu_Radio1 + 1); + if (which == 2) + event.Check(TRUE); + else + event.Check(FALSE); +} + +void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) { if ( !m_textctrl ) return;