- HICommand command ;
- OSErr err;
-
- err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand,
- NULL, sizeof(HICommand), NULL, &command);
- wxASSERT(err == noErr);
-
- MenuItemIndex menuItemIndex;
- err = GetIndMenuItemWithCommandID(hMenu, command.commandID, 1, NULL, &menuItemIndex);
- wxASSERT(err == noErr);
-
-
- MenuCommand id = command.commandID ;
- wxMenuItem* item = NULL;
- // for items we don't really control
- if ( id == kHICommandPreferences )
+ // get the HICommand from the event
+ HICommand command;
+ if (GetEventParameter(inEvent, kEventParamDirectObject,
+ typeHICommand, NULL,sizeof(HICommand), NULL, &command ) == noErr)
+ {
+ // Obtain the REAL menuRef and the menuItemIndex in the real menuRef
+ //
+ // NOTE: menuRef is generally used here for submenus, as
+ // GetMenuItemRefCon could give an incorrect wxMenuItem if we pass
+ // just the top level wxTaskBar menu
+ MenuItemIndex menuItemIndex;
+ MenuRef menuRef;
+ MenuRef taskbarMenuRef = MAC_WXHMENU(pTB->m_pMenu->GetHMenu());
+
+ // the next command is only successful if it was a command from the taskbar menu
+ // otherwise we pass it on
+ if (GetIndMenuItemWithCommandID(taskbarMenuRef,command.commandID,
+ 1, &menuRef, &menuItemIndex ) == noErr)
+ {
+ wxMenu* itemMenu = wxFindMenuFromMacMenu( menuRef ) ;
+ int id = wxMacCommandToId( command.commandID ) ;
+ wxMenuItem *item = NULL;
+
+ if (id != 0) // get the wxMenuItem reference from the MenuRef
+ GetMenuItemRefCon( menuRef, menuItemIndex, (URefCon*) &item );
+
+ if (item && itemMenu )
+ {
+ if ( eventKind == kEventCommandProcess )
+ err = itemMenu->MacHandleCommandProcess( item, id );
+ else if ( eventKind == kEventCommandUpdateStatus )
+ err = itemMenu->MacHandleCommandUpdateStatus( item, id );
+ }
+ }
+ }
+ } //end if noErr on getting HICommand from event
+ }
+ else if ((eventClass == kEventClassApplication) && (eventKind == kEventAppGetDockTileMenu ))