views:

331

answers:

2

I would need something this owner drawn tab completition key equivalents in my own code. Like TextMate does in this example.

I heared that the menu drawing is Carbon based but I don't hope it is such a huge hack.

But whatever I tried and wherever I looked I couldn't find a clue.

EDIT: I'm willing to accept even a carbon based answer, just anything that runs on version >= 10.4

+1  A: 

One way to accomplish this is to draw the item yourself. I am not sure if there is a way to just override the drawing on the key equivalent. Take a look at the MenuItemView sample code.

Jon Steinmetz
Yes thanks i know about the embedding of a NSView in a menu bar item, but this is very expensive and does work only on 10.5TextMate can do the same on 10.4 so they found another way to do the drawing.
Lothar
Yes, TextMate is hacking. There's no supported way to do what it's doing on 10.4.
Ken
+2  A: 

The menubar, even in 10.6, is still based on Carbon. At the Carbon level, there is an API (see below) that lets you set whatever key equivalent you want on the menuitem regardless of whether the app actually maps that key equivalent to the menuitem. In other words, Carbon lets you adjust the display of the menuitem independently of the behavior. Using this API, you can set whatever keyboard shortcut you want the menuitem to display.

Unfortunately it seems the documentation for this API is no more. But you can still read the header file. I believe the API you want is in /System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/Menus.h. I know HIToolbox is not 64-bit, but I suspect the menu API must still be, given that the Cocoa menus are still based on the Carbon menus.

Kevin Ballard
Hmmm, i really don't want to do it just with the header file. Thats too much trial and error for me. I knew that there was some Carbon based example but i can't find it.
Lothar
The documentation for Carbon (and even Toolbox) hasn't perished; Apple moved it to the Legacy docset. Here's Menu Manager: http://developer.apple.com/legacy/mac/library/documentation/Carbon/Reference/Menu_Manager/
Peter Hosey
Hmm, I guess the legacy docset must not be part of Xcode's documentation download then.
Kevin Ballard