From bde56d09bb9915462039bcb8955c2f81e74cc953 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Dec 2011 17:47:21 +0000 Subject: [PATCH] Restore wxEVT_MENU_CLOSE generation under Windows 95 after r70151. WM_UNINITMENUPOPUP is "only" available since Windows 98/2000 so restore the old code using WM_EXITMENULOOP as fall back, just to avoid any regressions for people who might still be using these systems. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70156 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/frame.h | 9 +++++++++ src/msw/frame.cpp | 45 +++++++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index b7404bddc2..177bbb65b4 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -132,9 +132,18 @@ protected: // wxMDIChildFrame bool MSWDoTranslateMessage(wxFrame *frame, WXMSG *msg); +#if wxUSE_MENUS + // handle WM_EXITMENULOOP message for Win95 only + bool HandleExitMenuLoop(WXWORD isPopup); + // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu); + // Command part of HandleMenuPopup() and HandleExitMenuLoop(). + bool DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup); +#endif // wxUSE_MENUS + + virtual bool IsMDIChild() const { return false; } // get default (wxWidgets) icon for the frame diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index c9c90a78c7..31886a93ef 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -855,27 +855,38 @@ wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu)) return false; } -bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu) +bool +wxFrame::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup) +{ + wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu); + event.SetEventObject(this); + + return HandleWindowEvent(event); +} + +bool wxFrame::HandleExitMenuLoop(WXWORD isPopup) { - // we don't have the menu id here, so we use the id to specify if the event - // was from a popup menu or a normal one + return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE, + isPopup ? wxCurrentPopupMenu : NULL, + isPopup != 0); +} - int menuid = 0; +bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu) +{ + bool isPopup = false; wxMenu* menu = NULL; - if (GetMenuBar()) + if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu ) { - menu = GetMenuBar()->MSWGetMenu(hMenu); + menu = wxCurrentPopupMenu; + isPopup = true; } - else if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu ) + else if ( GetMenuBar() ) { - menu = wxCurrentPopupMenu; - menuid = wxID_ANY; + menu = GetMenuBar()->MSWGetMenu(hMenu); } - wxMenuEvent event(evtType, menuid, menu); - event.SetEventObject(this); - return HandleWindowEvent(event); + return DoSendMenuOpenCloseEvent(evtType, menu, isPopup); } #endif // wxUSE_MENUS @@ -935,6 +946,16 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara } break; + case WM_EXITMENULOOP: + // Under Windows 98 and 2000 and later we're going to get + // WM_UNINITMENUPOPUP which will be used to generate this event + // with more information (notably the menu that was closed) so we + // only need this one under old Windows systems where the newer + // event is never sent. + if ( wxGetWinVersion() < wxWinVersion_98 ) + processed = HandleExitMenuLoop(wParam); + break; + case WM_UNINITMENUPOPUP: processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam); break; -- 2.47.2