From eeb0bee1d31939f8ff14a3c7dba6ff22fcdb6fff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Dec 2007 16:29:38 +0000 Subject: [PATCH] unset the window as invoking window of wxCurrentPopupMenu (which now exists in all ports and not just wxMSW-based ones) if it being destroyed before the menu itself (modified patch 1837214) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50903 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/window.h | 5 ++--- src/common/wincmn.cpp | 21 +++++++++++++++++++++ src/msw/window.cpp | 7 ------- src/os2/window.cpp | 2 -- src/palmos/window.cpp | 4 ---- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/wx/window.h b/include/wx/window.h index 17be18c237..6bc220b4d3 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1046,9 +1046,8 @@ public: // show popup menu at the given position, generate events for the items // selected in it bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition) - { return DoPopupMenu(menu, pos.x, pos.y); } - bool PopupMenu(wxMenu *menu, int x, int y) - { return DoPopupMenu(menu, x, y); } + { return PopupMenu(menu, pos.x, pos.y); } + bool PopupMenu(wxMenu *menu, int x, int y); // simply return the id of the selected item or wxID_NONE without // generating any events diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index dba13d8542..8d1432f8f1 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -85,6 +85,11 @@ // Windows List WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; +// globals +#if wxUSE_MENUS_NATIVE +wxMenu *wxCurrentPopupMenu = NULL; +#endif // wxUSE_MENUS_NATIVE + // ---------------------------------------------------------------------------- // static data // ---------------------------------------------------------------------------- @@ -317,6 +322,11 @@ wxWindowBase::~wxWindowBase() // we weren't a dialog class wxTopLevelWindows.DeleteObject((wxWindow*)this); + // The associated popup menu can still be alive, disassociate from it in + // this case + if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this ) + wxCurrentPopupMenu->SetInvokingWindow(NULL); + wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); // notify the parent about this window destruction @@ -2245,6 +2255,17 @@ void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) #if wxUSE_MENUS +bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y) +{ + wxCHECK_MSG( menu, false, "can't popup NULL menu" ); + + wxCurrentPopupMenu = menu; + const bool rc = DoPopupMenu(menu, x, y); + wxCurrentPopupMenu = NULL; + + return rc; +} + // this is used to pass the id of the selected item from the menu event handler // to the main function itself // diff --git a/src/msw/window.cpp b/src/msw/window.cpp index c4517a2a94..ebecabf2ab 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -179,10 +179,6 @@ // global variables // --------------------------------------------------------------------------- -#if wxUSE_MENUS_NATIVE -wxMenu *wxCurrentPopupMenu = NULL; -#endif // wxUSE_MENUS_NATIVE - #ifdef __WXWINCE__ extern wxChar *wxCanvasClassName; #else @@ -2219,7 +2215,6 @@ bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) point.x = x; point.y = y; ::ClientToScreen(hWnd, &point); - wxCurrentPopupMenu = menu; #if defined(__WXWINCE__) static const UINT flags = 0; #else // !__WXWINCE__ @@ -2248,8 +2243,6 @@ bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) // for example) and so we do need to process the event immediately wxYieldForCommandsOnly(); - wxCurrentPopupMenu = NULL; - menu->SetInvokingWindow(NULL); return true; diff --git a/src/os2/window.cpp b/src/os2/window.cpp index d8449e47a0..c1ec1c18f6 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -1804,7 +1804,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) DoGetSize(0,&nHeight); nY = nHeight - nY; } - wxCurrentPopupMenu = pMenu; ::WinPopupMenu( hWndParent ,hWndOwner @@ -1825,7 +1824,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg); } - wxCurrentPopupMenu = NULL; pMenu->SetInvokingWindow(NULL); return true; } // end of wxWindowOS2::DoPopupMenu diff --git a/src/palmos/window.cpp b/src/palmos/window.cpp index 3507888caf..75ddf0bc24 100644 --- a/src/palmos/window.cpp +++ b/src/palmos/window.cpp @@ -83,10 +83,6 @@ // global variables // --------------------------------------------------------------------------- -#if wxUSE_MENUS_NATIVE -wxMenu *wxCurrentPopupMenu = NULL; -#endif // wxUSE_MENUS_NATIVE - // --------------------------------------------------------------------------- // private functions // --------------------------------------------------------------------------- -- 2.45.2