From e32f4a9fa9de5c47574e5ee16c4d8afade3b0d34 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Jul 2003 01:20:52 +0000 Subject: [PATCH] preliminary implementation of wxEVT_MENU_OPEN/CLOSE for Mac git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21835 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/mac/app.cpp | 33 +++++++++++++++++++++++++++++++-- src/mac/carbon/app.cpp | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index db48d4e0e1..129b048916 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -147,6 +147,7 @@ wxGTK: wxMac: - generate wxEVT_SCROLL_THUMBRELEASE and wxEVT_SCROLLWIN_THUMBRELEASE events +- generate wxEVT_MENU_OPEN and wxEVT_MENU_CLOSE events wxMSW: diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 1af5aa871f..04f3eee3b5 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -288,6 +288,9 @@ void wxApp::MacNewFile() { kEventClassCommand, kEventProcessCommand } , { kEventClassCommand, kEventCommandUpdateStatus } , + { kEventClassMenu, kEventMenuOpening }, + { kEventClassMenu, kEventMenuClosed }, + { kEventClassApplication , kEventAppActivated } , { kEventClassApplication , kEventAppDeactivated } , // handling the quit event is not recommended by apple @@ -299,9 +302,35 @@ void wxApp::MacNewFile() { 'WXMC' , 'WXMC' } } ; -static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus +MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { - return eventNotHandledErr ; + // FIXME: this doesn't work for multiple windows + wxWindow *win = wxTheApp->GetTopWindow(); + if ( win ) + { + // VZ: we could find the menu from its handle here by examining all + // the menus in the menu bar recursively but knowing that neither + // wxMSW nor wxGTK do it why bother... +#if 0 + MenuRef menuRef; + + GetEventParameter(event, + kEventParamDirectObject, + typeMenuRef, NULL, + sizeof(menuRef), NULL, + &menuRef); +#endif // 0 + + wxMenuEvent event(GetEventKind(event) == kEventMenuOpening + ? wxEVT_MENU_OPEN + : wxEVT_MENU_CLOSE); + event.SetEventObject(win); + + (void)win->GetEventHandler()->ProcessEvent(event); + } + + return eventNotHandledErr; } // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 1af5aa871f..04f3eee3b5 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -288,6 +288,9 @@ void wxApp::MacNewFile() { kEventClassCommand, kEventProcessCommand } , { kEventClassCommand, kEventCommandUpdateStatus } , + { kEventClassMenu, kEventMenuOpening }, + { kEventClassMenu, kEventMenuClosed }, + { kEventClassApplication , kEventAppActivated } , { kEventClassApplication , kEventAppDeactivated } , // handling the quit event is not recommended by apple @@ -299,9 +302,35 @@ void wxApp::MacNewFile() { 'WXMC' , 'WXMC' } } ; -static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus +MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { - return eventNotHandledErr ; + // FIXME: this doesn't work for multiple windows + wxWindow *win = wxTheApp->GetTopWindow(); + if ( win ) + { + // VZ: we could find the menu from its handle here by examining all + // the menus in the menu bar recursively but knowing that neither + // wxMSW nor wxGTK do it why bother... +#if 0 + MenuRef menuRef; + + GetEventParameter(event, + kEventParamDirectObject, + typeMenuRef, NULL, + sizeof(menuRef), NULL, + &menuRef); +#endif // 0 + + wxMenuEvent event(GetEventKind(event) == kEventMenuOpening + ? wxEVT_MENU_OPEN + : wxEVT_MENU_CLOSE); + event.SetEventObject(win); + + (void)win->GetEventHandler()->ProcessEvent(event); + } + + return eventNotHandledErr; } // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop -- 2.45.2