menu events handling more closely to the menu instance itself, removing menubar wherever possible
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27464 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -337,60 +337,56 @@ static const EventTypeSpec eventList[] =
|
|||||||
static pascal OSStatus
|
static pascal OSStatus
|
||||||
wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
|
wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
|
||||||
{
|
{
|
||||||
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
|
EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
|
||||||
|
EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
|
||||||
|
wxTheApp->MacSetCurrentEvent( event , handler ) ;
|
||||||
|
|
||||||
if ( mbar )
|
wxMacCarbonEvent cEvent( event ) ;
|
||||||
|
MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
|
||||||
|
wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
|
||||||
|
|
||||||
|
if ( menu )
|
||||||
{
|
{
|
||||||
wxFrame* win = mbar->GetFrame();
|
wxEventType type=0;
|
||||||
if ( win )
|
MenuCommand cmd=0;
|
||||||
|
switch (GetEventKind(event))
|
||||||
{
|
{
|
||||||
EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
|
case kEventMenuOpening:
|
||||||
EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
|
type = wxEVT_MENU_OPEN;
|
||||||
wxTheApp->MacSetCurrentEvent( event , handler ) ;
|
break;
|
||||||
|
case kEventMenuClosed:
|
||||||
// VZ: we could find the menu from its handle here by examining all
|
type = wxEVT_MENU_CLOSE;
|
||||||
// the menus in the menu bar recursively but knowing that neither
|
break;
|
||||||
// wxMSW nor wxGTK do it why bother...
|
case kEventMenuTargetItem:
|
||||||
#if 0
|
cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
|
||||||
MenuRef menuRef;
|
if (cmd != 0)
|
||||||
|
|
||||||
GetEventParameter(event,
|
|
||||||
kEventParamDirectObject,
|
|
||||||
typeMenuRef, NULL,
|
|
||||||
sizeof(menuRef), NULL,
|
|
||||||
&menuRef);
|
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
wxEventType type=0;
|
|
||||||
MenuCommand cmd=0;
|
|
||||||
switch (GetEventKind(event))
|
|
||||||
{
|
|
||||||
case kEventMenuOpening:
|
|
||||||
type = wxEVT_MENU_OPEN;
|
|
||||||
break;
|
|
||||||
case kEventMenuClosed:
|
|
||||||
type = wxEVT_MENU_CLOSE;
|
|
||||||
break;
|
|
||||||
case kEventMenuTargetItem:
|
|
||||||
type = wxEVT_MENU_HIGHLIGHT;
|
type = wxEVT_MENU_HIGHLIGHT;
|
||||||
GetEventParameter(event, kEventParamMenuCommand,
|
break;
|
||||||
typeMenuCommand, NULL,
|
default:
|
||||||
sizeof(cmd), NULL, &cmd);
|
wxFAIL_MSG(wxT("Unexpected menu event kind"));
|
||||||
if (cmd == 0) return eventNotHandledErr;
|
break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG(wxT("Unexpected menu event kind"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMenuEvent wxevent(type, cmd);
|
|
||||||
wxevent.SetEventObject(win);
|
|
||||||
|
|
||||||
(void)win->GetEventHandler()->ProcessEvent(wxevent);
|
|
||||||
|
|
||||||
wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( type )
|
||||||
|
{
|
||||||
|
wxMenuEvent wxevent(type, cmd);
|
||||||
|
wxevent.SetEventObject(menu);
|
||||||
|
|
||||||
|
wxEvtHandler* handler = menu->GetEventHandler();
|
||||||
|
if (handler && handler->ProcessEvent(wxevent))
|
||||||
|
{
|
||||||
|
// handled
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxWindow *win = menu->GetInvokingWindow();
|
||||||
|
if (win)
|
||||||
|
win->GetEventHandler()->ProcessEvent(wxevent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
|
||||||
|
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
}
|
||||||
@@ -401,32 +397,31 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
|
|||||||
|
|
||||||
HICommand command ;
|
HICommand command ;
|
||||||
|
|
||||||
GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,
|
wxMacCarbonEvent cEvent( event ) ;
|
||||||
sizeof( HICommand ), NULL, &command );
|
cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
|
||||||
|
|
||||||
MenuCommand id = command.commandID ;
|
|
||||||
if ( id == kHICommandPreferences )
|
|
||||||
id = wxApp::s_macPreferencesMenuItemId ;
|
|
||||||
|
|
||||||
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
|
|
||||||
wxMenu* menu = NULL ;
|
|
||||||
wxMenuItem* item = NULL ;
|
wxMenuItem* item = NULL ;
|
||||||
|
MenuCommand id = command.commandID ;
|
||||||
if ( mbar )
|
// for items we don't really control
|
||||||
|
if ( id == kHICommandPreferences )
|
||||||
{
|
{
|
||||||
item = mbar->FindItem( id , &menu ) ;
|
id = wxApp::s_macPreferencesMenuItemId ;
|
||||||
// it is not 100 % sure that an menu of id 0 is really ours, safety check
|
|
||||||
if ( id == 0 && menu != NULL && menu->GetHMenu() != command.menu.menuRef )
|
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
|
||||||
|
if ( mbar )
|
||||||
{
|
{
|
||||||
item = NULL ;
|
wxMenu* menu = NULL ;
|
||||||
menu = NULL ;
|
item = mbar->FindItem( id , &menu ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( id != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )
|
||||||
if ( item == NULL || menu == NULL || mbar == NULL )
|
{
|
||||||
return result ;
|
GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , (UInt32*) &item ) ;
|
||||||
|
}
|
||||||
switch( GetEventKind( event ) )
|
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
switch( cEvent.GetKind() )
|
||||||
{
|
{
|
||||||
case kEventProcessCommand :
|
case kEventProcessCommand :
|
||||||
{
|
{
|
||||||
@@ -435,18 +430,18 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
|
|||||||
item->Check( !item->IsChecked() ) ;
|
item->Check( !item->IsChecked() ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
|
item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
|
||||||
result = noErr ;
|
result = noErr ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
case kEventCommandUpdateStatus:
|
case kEventCommandUpdateStatus:
|
||||||
// eventually trigger an updateui round
|
// eventually trigger an updateui round
|
||||||
result = noErr ;
|
result = noErr ;
|
||||||
break ;
|
break ;
|
||||||
default :
|
default :
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user