Set popup menu invoking window in wxWindowBase and not in all ports.

Don't duplicate the code for setting (and unsetting, which was forgotten by at
least wxGTK) the popup menu invoking window in all ports but do it in the base
class PopupMenu() itself.

Also add a helper wxMenuInvokingWindowSetter class which ensures that the
invoking window will be unset in any case.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64143 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-04-26 14:19:17 +00:00
parent 6de0a414a5
commit c59aa14a6c
10 changed files with 56 additions and 61 deletions

View File

@@ -259,6 +259,9 @@ public:
// 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
//
// NB: avoid calling SetInvokingWindow() directly if possible, use
// wxMenuInvokingWindowSetter class below instead
void SetInvokingWindow(wxWindow *win);
wxWindow *GetInvokingWindow() const { return m_invokingWindow; }
@@ -551,7 +554,35 @@ protected:
#endif
#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
// ----------------------------------------------------------------------------
// Helper class used in the implementation only: sets the invoking window of
// the given menu in its ctor and resets it in dtor.
// ----------------------------------------------------------------------------
class wxMenuInvokingWindowSetter
{
public:
// Ctor sets the invoking window for the given menu.
//
// The menu lifetime must be greater than that of this class.
wxMenuInvokingWindowSetter(wxMenu& menu, wxWindow *win)
: m_menu(menu)
{
menu.SetInvokingWindow(win);
}
// Dtor resets the invoking window.
~wxMenuInvokingWindowSetter()
{
m_menu.SetInvokingWindow(NULL);
}
private:
wxMenu& m_menu;
wxDECLARE_NO_COPY_CLASS(wxMenuInvokingWindowSetter);
};
#endif // wxUSE_MENUS
#endif
// _WX_MENU_H_BASE_
#endif // _WX_MENU_H_BASE_