]> git.saurik.com Git - wxWidgets.git/commitdiff
Complete wxEVT_MENU_{OPEN,CLOSE} implementation in wxMSW and wxOSX.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 28 Dec 2011 13:51:17 +0000 (13:51 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 28 Dec 2011 13:51:17 +0000 (13:51 +0000)
Set the wxMenu correctly for wxEVT_MENU_CLOSE events in wxMSW.

Set the menu id correctly to allow wxMenuEvent::IsPopup() to work for both
wxEVT_MENU_OPEN and wxEVT_MENU_CLOSE in wxOSX.

Closes #11313.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70151 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/frame.h
include/wx/osx/menu.h
interface/wx/event.h
src/msw/frame.cpp
src/osx/menu_osx.cpp

index a4cc9f2f3ac2b41cad0ab0b64d3b6dacfb4e04c1..9d420c37504a91f1ebbca7daf57b70385423ce83 100644 (file)
@@ -468,6 +468,7 @@ MSW:
 
 - Fixed regression with initial focus in the dialogs in 2.9.3.
 - Added support for wxEXEC_MAKE_GROUP_LEADER to wxExecute (tteras).
+- Set wxMenu being closed in wxEVT_MENU_CLOSE events (Marcin Malich).
 
 OSX:
 
index d528a882dd9019346664575d0a306857f3cf6cd2..b7404bddc297c78c05220ae7b18d81e0b8f0b52e 100644 (file)
@@ -79,7 +79,6 @@ public:
     bool HandleSize(int x, int y, WXUINT flag);
     bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
     bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu);
-    bool HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup);
 
     // tooltip management
 #if wxUSE_TOOLTIPS
@@ -133,8 +132,8 @@ protected:
     // wxMDIChildFrame
     bool MSWDoTranslateMessage(wxFrame *frame, WXMSG *msg);
 
-    // handle WM_INITMENUPOPUP message to generate wxEVT_MENU_OPEN
-    bool HandleInitMenuPopup(WXHMENU hMenu);
+    // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE
+    bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu);
 
     virtual bool IsMDIChild() const { return false; }
 
index 55796749a14c4e87b59a78c56c5cd9aa3aebfc5e..b3d742defd86ba75511f333070f9460d11ed117d 100644 (file)
@@ -83,6 +83,10 @@ private:
     // terminate the current radio group, if any
     void EndRadioGroup();
 
+    // Common part of HandleMenu{Opened,Closed}().
+    void DoHandleMenuOpenedOrClosed(wxEventType evtType);
+
+
     // if TRUE, insert a breal before appending the next item
     bool m_doBreak;
 
index 5cb9c497aa53d11c9d1ae44e1c5b4019284c32ad..7cf8ec67f4d1008f0b1c8f3a75fd7020f3a81de2 100644 (file)
@@ -3870,9 +3870,12 @@ public:
     wxMenuEvent(wxEventType type = wxEVT_NULL, int id = 0, wxMenu* menu = NULL);
 
     /**
-        Returns the menu which is being opened or closed. This method should only be
-        used with the @c OPEN and @c CLOSE events and even for them the
-        returned pointer may be @NULL in some ports.
+        Returns the menu which is being opened or closed.
+
+        This method can only be used with the @c OPEN and @c CLOSE events.
+
+        The returned value is never @NULL in the ports implementing this
+        function, which currently includes all the major ones.
     */
     wxMenu* GetMenu() const;
 
index 9126afb4d9fd9dc69316177e898ae2c2e32a7338..ed3369c64cb713c85316aac6ec2186cbf7952c42 100644 (file)
@@ -61,9 +61,9 @@
 // globals
 // ----------------------------------------------------------------------------
 
-#if wxUSE_MENUS_NATIVE
+#if wxUSE_MENUS || wxUSE_MENUS_NATIVE
     extern wxMenu *wxCurrentPopupMenu;
-#endif // wxUSE_MENUS_NATIVE
+#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
 
 // ----------------------------------------------------------------------------
 // event tables
@@ -849,25 +849,24 @@ wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
     return false;
 }
 
-bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
+bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
 {
     // 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
-    wxMenuEvent event(evtType, isPopup ? -1 : 0);
-    event.SetEventObject(this);
 
-    return HandleWindowEvent(event);
-}
-
-bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
-{
+    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(wxEVT_MENU_OPEN, 0, menu);
+    wxMenuEvent event(evtType, menuid, menu);
     event.SetEventObject(this);
 
     return HandleWindowEvent(event);
@@ -917,7 +916,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
 #if wxUSE_MENUS
         case WM_INITMENUPOPUP:
-            processed = HandleInitMenuPopup((WXHMENU) wParam);
+            processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
             break;
 
         case WM_MENUSELECT:
@@ -930,8 +929,8 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
             }
             break;
 
-        case WM_EXITMENULOOP:
-            processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
+        case WM_UNINITMENUPOPUP:
+            processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
             break;
 #endif // wxUSE_MENUS
 
index ee18135ab7ada349c7d30aef092aa64968229708..da7d66545a7e11ca6b1ffaf57ea1c394624109ca 100644 (file)
@@ -452,16 +452,25 @@ void wxMenu::HandleMenuItemHighlighted( wxMenuItem* item )
     DoHandleMenuEvent( wxevent );
 }
 
-void wxMenu::HandleMenuOpened()
+void wxMenu::DoHandleMenuOpenedOrClosed(wxEventType evtType)
 {
-    wxMenuEvent wxevent(wxEVT_MENU_OPEN, 0, this);
+    // Popup menu being currently shown or NULL, defined in wincmn.cpp.
+    extern wxMenu *wxCurrentPopupMenu;
+
+    // Set the id to allow wxMenuEvent::IsPopup() to work correctly.
+    int menuid = this == wxCurrentPopupMenu ? wxID_ANY : 0;
+    wxMenuEvent wxevent(evtType, menuid, this);
     DoHandleMenuEvent( wxevent );
 }
 
+void wxMenu::HandleMenuOpened()
+{
+    DoHandleMenuOpenedOrClosed(wxEVT_MENU_OPEN);
+}
+
 void wxMenu::HandleMenuClosed()
 {
-    wxMenuEvent wxevent(wxEVT_MENU_CLOSE, 0, this);
-    DoHandleMenuEvent( wxevent );
+    DoHandleMenuOpenedOrClosed(wxEVT_MENU_CLOSE);
 }
 
 bool wxMenu::DoHandleMenuEvent(wxEvent& wxevent)