From d19729d5284b9de3f8c6a6efcaade22b39226f57 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Aug 2000 13:30:47 +0000 Subject: [PATCH] fix (with a test) for wxMenu::UpdateUI bug (the handler defined in the menu class was never used) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@8046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/menu/menu.cpp | 26 +++++++++++++++++++++++++- src/common/menucmn.cpp | 17 +++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index cee944b197..bb86ad00c6 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -77,6 +77,7 @@ public: void OnRightDown(wxMouseEvent& event); void OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event); + void OnUpdatePopup(wxUpdateUIEvent& event) { event.Enable(FALSE); } private: wxMenu *CreateDummyMenu(wxString *title); @@ -109,6 +110,17 @@ private: DECLARE_EVENT_TABLE() }; +class MyPopupMenu : public wxMenu +{ +public: + MyPopupMenu(const wxString& title) : wxMenu(title) { } + + void OnUpdateUI(wxUpdateUIEvent& event) { event.Enable(FALSE); } + +private: + DECLARE_EVENT_TABLE() +}; + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -145,6 +157,8 @@ enum Menu_Popup_ToBeDeleted = 2000, Menu_Popup_ToBeGreyed, + Menu_Popup_ToBeGreyed2, + Menu_Popup_ToBeGreyed3, Menu_Popup_ToBeChecked, Menu_Popup_Submenu, @@ -182,6 +196,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_UPDATE_UI(Menu_Menu_Check, MyFrame::OnUpdateCheckMenuItemUI) + EVT_UPDATE_UI(Menu_Popup_ToBeGreyed3, MyFrame::OnUpdatePopup) + EVT_RIGHT_DOWN(MyFrame::OnRightDown) END_EVENT_TABLE() @@ -189,6 +205,10 @@ BEGIN_EVENT_TABLE(MyEvtHandler, wxEvtHandler) EVT_MENU(-1, MyEvtHandler::OnMenuEvent) END_EVENT_TABLE() +BEGIN_EVENT_TABLE(MyPopupMenu, wxMenu) + EVT_UPDATE_UI(Menu_Popup_ToBeGreyed2, MyPopupMenu::OnUpdateUI) +END_EVENT_TABLE() + // ============================================================================ // implementation // ============================================================================ @@ -618,7 +638,7 @@ void MyFrame::OnGetMenuItemInfo(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnRightDown(wxMouseEvent &event ) { - wxMenu menu("Test popup"); + MyPopupMenu menu("Test popup"); menu.Append(Menu_Help_About, "&About"); menu.Append(Menu_Popup_Submenu, "Submenu", CreateDummyMenu(NULL)); @@ -626,6 +646,10 @@ void MyFrame::OnRightDown(wxMouseEvent &event ) menu.Append(Menu_Popup_ToBeChecked, "To be checked", "", TRUE); menu.Append(Menu_Popup_ToBeGreyed, "To be greyed"); menu.AppendSeparator(); + // VZ: don't search for the word autogreyed in the dictionary... + menu.Append(Menu_Popup_ToBeGreyed2, "To be autogreyed"); + menu.Append(Menu_Popup_ToBeGreyed3, "This one too"); + menu.AppendSeparator(); menu.Append(Menu_File_Quit, "E&xit"); menu.Delete(Menu_Popup_ToBeDeleted); diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index fd1cc38a1e..9edfcbe609 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -346,10 +346,10 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) { if ( !source && GetInvokingWindow() ) source = GetInvokingWindow()->GetEventHandler(); + + wxEvtHandler *self = GetEventHandler(); if ( !source ) - source = GetEventHandler(); - if ( !source ) - source = this; + source = self; wxMenuItemList::Node* node = GetMenuItems().GetFirst(); while ( node ) @@ -361,7 +361,16 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) wxUpdateUIEvent event(id); event.SetEventObject( source ); - if ( source->ProcessEvent(event) ) + // let the invoking window process the event and fall back to the + // menu itself if it didn't + bool processed = source->ProcessEvent(event); + if ( !processed && source != self ) + { + event.SetEventObject( self ); + processed = self->ProcessEvent(event); + } + + if ( processed ) { // if anything changed, update the chanegd attribute if (event.GetSetText())