]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/toplevel.cpp
Simplify the version information resource definition a little.
[wxWidgets.git] / src / msw / toplevel.cpp
index 0d1a0735cdde9113e08dff1284c3b12b08a22715..93f05893b2f772d626ce87e8740ab9e90839a1ba 100644 (file)
     #define ICON_SMALL 0
 #endif
 
+// 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 || wxUSE_MENUS_NATIVE
+    extern wxMenu *wxCurrentPopupMenu;
+#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
+
+
 // ----------------------------------------------------------------------------
 // stubs for missing functions under MicroWindows
 // ----------------------------------------------------------------------------
@@ -414,6 +429,38 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX
 #endif // #ifndef __WXUNIVERSAL__
             }
             break;
+
+#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
+#if wxUSE_MENUS
+        case WM_INITMENUPOPUP:
+            processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
+            break;
+
+        case WM_MENUSELECT:
+            {
+                WXWORD item, flags;
+                WXHMENU hmenu;
+                UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
+
+                processed = HandleMenuSelect(item, flags, hmenu);
+            }
+            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;
+#endif // wxUSE_MENUS
+#endif // !__WXMICROWIN__
     }
 
     if ( !processed )
@@ -1428,6 +1475,80 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
     }
 }
 
+#if wxUSE_MENUS
+
+bool
+wxTopLevelWindowMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
+{
+    // sign extend to int from unsigned short we get from Windows
+    int item = (signed short)nItem;
+
+    // WM_MENUSELECT is generated for both normal items and menus, including
+    // the top level menus of the menu bar, which can't be represented using
+    // any valid identifier in wxMenuEvent so use an otherwise unused value for
+    // them
+    if ( flags & (MF_POPUP | MF_SEPARATOR) )
+        item = wxID_NONE;
+
+    wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
+    event.SetEventObject(this);
+
+    if ( HandleWindowEvent(event) )
+        return true;
+
+    // by default, i.e. if the event wasn't handled above, clear the status bar
+    // text when an item which can't have any associated help string in wx API
+    // is selected
+    if ( item == wxID_NONE )
+        DoGiveHelp(wxEmptyString, true);
+
+    return false;
+}
+
+bool
+wxTopLevelWindowMSW::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup)
+{
+    wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
+    event.SetEventObject(menu);
+
+    return HandleWindowEvent(event);
+}
+
+bool wxTopLevelWindowMSW::HandleExitMenuLoop(WXWORD isPopup)
+{
+    return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE,
+                                    isPopup ? wxCurrentPopupMenu : NULL,
+                                    isPopup != 0);
+}
+
+bool wxTopLevelWindowMSW::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
+{
+    bool isPopup = false;
+    wxMenu* menu = NULL;
+    if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
+    {
+        menu = wxCurrentPopupMenu;
+        isPopup = true;
+    }
+    else
+    {
+        menu = MSWFindMenuFromHMENU(hMenu);
+    }
+
+
+    return DoSendMenuOpenCloseEvent(evtType, menu, isPopup);
+}
+
+wxMenu* wxTopLevelWindowMSW::MSWFindMenuFromHMENU(WXHMENU WXUNUSED(hMenu))
+{
+    // We don't have any menus at this level.
+    return NULL;
+}
+
+#endif // wxUSE_MENUS
+
+
+
 // the DialogProc for all wxWidgets dialogs
 LONG APIENTRY _EXPORT
 wxDlgProc(HWND hDlg,