From 394cfde3cf78553b1356167bbf917e21767eb546 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Apr 2010 20:39:39 +0000 Subject: [PATCH] Recurse upwards the menu hierarchy in wxMenu::GetWindow(). Only the top level menus have non-NULL wxMenuBar pointer too, so recurse upwards the menu hierarchy in GetWindow() and not (just) GetInvokingWindow(). This fixes event processing for submenus broken by the recent changes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/menu.h | 8 ++++---- src/common/menucmn.cpp | 15 +++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/wx/menu.h b/include/wx/menu.h index 8914432b71..5e318efac6 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -256,11 +256,11 @@ public: wxEvtHandler *GetEventHandler() const { return m_eventHandler; } // Invoking window: this is set by wxWindow::PopupMenu() before showing a - // popup menu and reset after it's hidden. Notice that GetInvokingWindow() - // recurses upwards and will return the invoking window for any submenu of - // a popup menu as well as the menu itself. + // popup menu and reset after it's hidden. Notice that you probably want to + // use GetWindow() below instead of GetInvokingWindow() as the latter only + // returns non-NULL for the top level menus void SetInvokingWindow(wxWindow *win); - wxWindow *GetInvokingWindow() const; + wxWindow *GetInvokingWindow() const { return m_invokingWindow; } // the window associated with this menu: this is the invoking window for // popup menus or the top level window to which the menu bar is attached diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 883870a714..af96b1116d 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -514,23 +514,18 @@ void wxMenuBase::SetInvokingWindow(wxWindow *win) m_invokingWindow = win; } -wxWindow *wxMenuBase::GetInvokingWindow() const +wxWindow *wxMenuBase::GetWindow() const { - // only the popup menu itself has a non-NULL invoking window so recurse - // upwards until we find it + // only the top level menus have non-NULL invoking window or a pointer to + // the menu bar so recurse upwards until we find it const wxMenuBase *menu = this; while ( menu->GetParent() ) { menu = menu->GetParent(); } - // menu is a top level menu here - return menu->m_invokingWindow; -} - -wxWindow *wxMenuBase::GetWindow() const -{ - return GetMenuBar() ? GetMenuBar()->GetFrame() : GetInvokingWindow(); + return menu->GetMenuBar() ? menu->GetMenuBar()->GetFrame() + : menu->GetInvokingWindow(); } // ---------------------------------------------------------------------------- -- 2.47.2