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,29 +855,40 @@ 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) { - // 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 - - 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); + wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu); event.SetEventObject(this); 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 // --------------------------------------------------------------------------- @@ -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;