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
This commit is contained in:
Vadim Zeitlin
2011-12-28 17:47:21 +00:00
parent abb8764e32
commit bde56d09bb
2 changed files with 47 additions and 17 deletions

View File

@@ -132,9 +132,18 @@ protected:
// wxMDIChildFrame // wxMDIChildFrame
bool MSWDoTranslateMessage(wxFrame *frame, WXMSG *msg); 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 // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE
bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu); 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; } virtual bool IsMDIChild() const { return false; }
// get default (wxWidgets) icon for the frame // get default (wxWidgets) icon for the frame

View File

@@ -855,29 +855,40 @@ wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
return false; return false;
} }
bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu) bool
wxFrame::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup)
{ {
// we don't have the menu id here, so we use the id to specify if the event wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
// was from a popup menu or a normal one
int menuid = 0;
wxMenu* menu = NULL;
if (GetMenuBar())
{
menu = GetMenuBar()->MSWGetMenu(hMenu);
}
else if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
{
menu = wxCurrentPopupMenu;
menuid = wxID_ANY;
}
wxMenuEvent event(evtType, menuid, menu);
event.SetEventObject(this); event.SetEventObject(this);
return HandleWindowEvent(event); return HandleWindowEvent(event);
} }
bool wxFrame::HandleExitMenuLoop(WXWORD isPopup)
{
return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE,
isPopup ? wxCurrentPopupMenu : NULL,
isPopup != 0);
}
bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
{
bool isPopup = false;
wxMenu* menu = NULL;
if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
{
menu = wxCurrentPopupMenu;
isPopup = true;
}
else if ( GetMenuBar() )
{
menu = GetMenuBar()->MSWGetMenu(hMenu);
}
return DoSendMenuOpenCloseEvent(evtType, menu, isPopup);
}
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -935,6 +946,16 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
} }
break; 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: case WM_UNINITMENUPOPUP:
processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam); processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
break; break;