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
This commit is contained in:
Vadim Zeitlin
2010-04-24 20:39:39 +00:00
parent 51fe41000c
commit 394cfde3cf
2 changed files with 9 additions and 14 deletions

View File

@@ -256,11 +256,11 @@ public:
wxEvtHandler *GetEventHandler() const { return m_eventHandler; } wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
// Invoking window: this is set by wxWindow::PopupMenu() before showing a // Invoking window: this is set by wxWindow::PopupMenu() before showing a
// popup menu and reset after it's hidden. Notice that GetInvokingWindow() // popup menu and reset after it's hidden. Notice that you probably want to
// recurses upwards and will return the invoking window for any submenu of // use GetWindow() below instead of GetInvokingWindow() as the latter only
// a popup menu as well as the menu itself. // returns non-NULL for the top level menus
void SetInvokingWindow(wxWindow *win); 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 // 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 // popup menus or the top level window to which the menu bar is attached

View File

@@ -514,23 +514,18 @@ void wxMenuBase::SetInvokingWindow(wxWindow *win)
m_invokingWindow = 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 // only the top level menus have non-NULL invoking window or a pointer to
// upwards until we find it // the menu bar so recurse upwards until we find it
const wxMenuBase *menu = this; const wxMenuBase *menu = this;
while ( menu->GetParent() ) while ( menu->GetParent() )
{ {
menu = menu->GetParent(); menu = menu->GetParent();
} }
// menu is a top level menu here return menu->GetMenuBar() ? menu->GetMenuBar()->GetFrame()
return menu->m_invokingWindow; : menu->GetInvokingWindow();
}
wxWindow *wxMenuBase::GetWindow() const
{
return GetMenuBar() ? GetMenuBar()->GetFrame() : GetInvokingWindow();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------