Re: Getting a command key before it is interpreted by the menus
Re: Getting a command key before it is interpreted by the menus
- Subject: Re: Getting a command key before it is interpreted by the menus
- From: Gideon King <email@hidden>
- Date: Tue, 27 Apr 2004 20:35:38 +1000
Thanks Peter, this solves the problem.
For others who may read this, it does rely on you having a handle to
the specific MenuRef that you can get from each NSMenu by calling the
*undocumented* _NSGetCarbonMenu call and iterating through the NSMenus
rather than using the documented AcquireRootMenu call and iterating
through the MenuRefs using GetItemHeirarchicalMenu.
Gideon.
On Tuesday, April 27, 2004, at 06:16 PM, Peter Maurer wrote:
I have successfully hooked in to the Carbon events associated with
menus and that side of things seems to be working ok but when I
change things in the menus on the carbon side of things, although
they are displayed in the application, when I use the Cocoa NSMenu
class, it doesn't recognize that I have changed anything (when I list
my menus, it shows all the original items, but no added or changed
items).
I have tried all the methods I can find on the Cocoa and Carbon side
of things to get things in sync again, but haven't found a solution
yet.
For my particular problem, I believe I should be able to solve the
problem in either of 2 ways:
1. get the cocoa NSMenu to recognize that the underlying carbon menu
has changed (this would be my preferred option)
2. work out how I could access the menu tag values in carbon
You could pass your NSMenu to the event handler. In
<advertisement>Butler</advertisement>'s recent pasteboards menu, my
event handler looks like this...
static OSStatus handleMatchKey(EventHandlerCallRef nextHandler,
EventRef event, void *myself) {
int aTag = 100; // assume we're looking for this tag
int aCocoaMenuItemIndex = [(NSMenu*)myself indexOfItemWithTag: aTag];
// do something...
}
... and I install it this way, passing "self" as the "user data"
parameter (in the init... method of a NSMenu subclass)...
InstallMenuEventHandler(menuReference, handleMatchKeyUPP,
GetEventTypeCount(eventTypes), eventTypes, self, NULL);
HTH, Peter.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.