X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42ed75321c19f7e77a62a451726c0c2131d8933a..f284605f65f6f957c90452b574f4131079819b53:/samples/menu/menu.cpp diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index ebe58946da..4d02ddac38 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -94,7 +94,11 @@ protected: void OnTestCheck(wxCommandEvent& event); void OnTestRadio(wxCommandEvent& event); -#ifdef __WXMSW__ + 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())); } #else @@ -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,11 +251,17 @@ 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) -#ifdef __WXMSW__ +#if defined( __WXMSW__ ) || defined( __WXMAC__ ) EVT_CONTEXT_MENU(MyFrame::OnContextMenu) #else EVT_RIGHT_UP(MyFrame::OnRightUp) @@ -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!")); @@ -584,7 +610,7 @@ void MyFrame::OnFindMenu(wxCommandEvent& WXUNUSED(event)) ( _T("Enter label to search for: "), _T("Find menu"), - "", + _T(""), this ); @@ -622,7 +648,7 @@ void MyFrame::OnAppendSubMenu(wxCommandEvent& WXUNUSED(event)) { wxMenuBar *menubar = GetMenuBar(); - wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 1); + wxMenu *menu = menubar->GetMenu(menubar->GetMenuCount() - 2); menu->Append(Menu_Dummy_Last, _T("&Dummy sub menu"), CreateDummyMenu(NULL), _T("Dummy sub menu help")); @@ -798,7 +824,7 @@ void MyFrame::OnFindMenuItem(wxCommandEvent& WXUNUSED(event)) ( _T("Enter label to search for: "), _T("Find menu item"), - "", + _T(""), this ); @@ -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")); @@ -872,6 +899,26 @@ void MyFrame::LogMenuOpenOrClose(const wxMenuEvent& event, const wxChar *what) event.IsPopup() ? _T("popup ") : _T(""), what); } +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& event) { if ( !m_textctrl )