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
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();
}
// ----------------------------------------------------------------------------