From a99a3029c80e77aff7d4ec529c3347650bc494e4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 31 Mar 2011 09:28:38 +0000 Subject: [PATCH] Fix HMENU to wxMenu translation in wxMSW code. We didn't find the menus corresponding to the submenu handles. This resulted in incorrect processing of EVT_UPDATE_UI events for the submenus and probably other problems. Fix this by searching for the HMENU recursively in all menus. Closes #13080. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67355 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/menu.h | 6 ++++++ src/msw/frame.cpp | 10 +--------- src/msw/menu.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b1aac62be2..3d18793491 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -516,6 +516,7 @@ MSW: - Fix wxBitmapButton best size determination broken in 2.9.1. - Center task dialog-based wxProgressDialog on the parent (John Roberts). - wxAutomationObject::GetInstance() creates objects on demand (Kolya Kosenko). +- Fix EVT_UPDATE_UI generation for items in submenus (wsu). OSX: diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index 84c3631620..d80e85cca1 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -102,6 +102,9 @@ public: m_maxAccelWidth = -1; } + // get the menu with given handle (recursively) + wxMenu* MSWGetMenu(WXHMENU hMenu); + private: void CalculateMaxAccelWidth(); @@ -208,6 +211,9 @@ public: void Refresh( bool eraseBackground, const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); } + // get the menu with given handle (recursively) + wxMenu* MSWGetMenu(WXHMENU hMenu); + protected: // common part of all ctors void Init(); diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index c1c96bb1ce..25cfa7eb30 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -864,15 +864,7 @@ bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) wxMenu* menu = NULL; if (GetMenuBar()) { - int nCount = GetMenuBar()->GetMenuCount(); - for (int n = 0; n < nCount; n++) - { - if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) - { - menu = GetMenuBar()->GetMenu(n); - break; - } - } + menu = GetMenuBar()->MSWGetMenu(hMenu); } wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index afb0df14e9..4769e1b00b 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -885,6 +885,30 @@ bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_) return true; } +// get the menu with given handle (recursively) +wxMenu* wxMenu::MSWGetMenu(WXHMENU hMenu) +{ + // check self + if ( GetHMenu() == hMenu ) + return this; + + // recursively query submenus + for ( size_t n = 0 ; n < GetMenuItemCount(); ++n ) + { + wxMenuItem* item = FindItemByPosition(n); + wxMenu* submenu = item->GetSubMenu(); + if ( submenu ) + { + submenu = submenu->MSWGetMenu(hMenu); + if (submenu) + return submenu; + } + } + + // unknown hMenu + return NULL; +} + // --------------------------------------------------------------------------- // Menu Bar // --------------------------------------------------------------------------- @@ -1467,4 +1491,22 @@ void wxMenuBar::Detach() wxMenuBarBase::Detach(); } +// get the menu with given handle (recursively) +wxMenu* wxMenuBar::MSWGetMenu(WXHMENU hMenu) +{ + wxCHECK_MSG( GetHMenu() != hMenu, NULL, + wxT("wxMenuBar::MSWGetMenu(): menu handle is wxMenuBar, not wxMenu") ); + + // query all menus + for ( size_t n = 0 ; n < GetMenuCount(); ++n ) + { + wxMenu* menu = GetMenu(n)->MSWGetMenu(hMenu); + if ( menu ) + return menu; + } + + // unknown hMenu + return NULL; +} + #endif // wxUSE_MENUS -- 2.45.2