]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/frame.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / msw / frame.cpp
index 9126afb4d9fd9dc69316177e898ae2c2e32a7338..f61c8f5f0cbda0cd63003e6027e284d205da5072 100644 (file)
     #include "wx/univ/colschem.h"
 #endif // __WXUNIVERSAL__
 
+// FIXME-VC6: Only VC6 doesn't have this in its standard headers so this
+//            could be removed once support for it is dropped.
+#ifndef WM_UNINITMENUPOPUP
+    #define WM_UNINITMENUPOPUP 0x0125
+#endif
+
 // ----------------------------------------------------------------------------
 // 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
@@ -233,11 +239,6 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
 // wxFrame: various geometry-related functions
 // ----------------------------------------------------------------------------
 
-void wxFrame::Raise()
-{
-    ::SetForegroundWindow(GetHwnd());
-}
-
 // generate an artificial resize event
 void wxFrame::SendSizeEvent(int flags)
 {
@@ -379,7 +380,7 @@ void wxFrame::AttachMenuBar(wxMenuBar *menubar)
         // adjust for menu / titlebar height
         rc.bottom -= (2*menuHeight-1);
 
-        ::MoveWindow(Gethwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
+        ::MoveWindow(GetHwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
     }
 #endif
 
@@ -849,28 +850,38 @@ wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
     return false;
 }
 
-bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
+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
-    wxMenuEvent event(evtType, isPopup ? -1 : 0);
-    event.SetEventObject(this);
+    wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
+    event.SetEventObject(menu);
 
     return HandleWindowEvent(event);
 }
 
-bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
+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 (GetMenuBar())
+    if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
+    {
+        menu = wxCurrentPopupMenu;
+        isPopup = true;
+    }
+    else if ( GetMenuBar() )
     {
         menu = GetMenuBar()->MSWGetMenu(hMenu);
     }
 
-    wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
-    event.SetEventObject(this);
 
-    return HandleWindowEvent(event);
+    return DoSendMenuOpenCloseEvent(evtType, menu, isPopup);
 }
 
 #endif // wxUSE_MENUS
@@ -917,7 +928,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:
@@ -931,7 +942,17 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
             break;
 
         case WM_EXITMENULOOP:
-            processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
+            // 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;
 #endif // wxUSE_MENUS