3

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

Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
Lothar
  • 12,537
  • 6
  • 72
  • 121

2 Answers2

3

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.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • 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 Sep 02 '09 at 10:13
  • 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 Sep 03 '09 at 09:33
  • Hmm, I guess the legacy docset must not be part of Xcode's documentation download then. – Lily Ballard Sep 04 '09 at 01:41
2

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
  • 4,104
  • 1
  • 23
  • 21
  • 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.5 TextMate can do the same on 10.4 so they found another way to do the drawing. – Lothar Aug 24 '09 at 05:56
  • Yes, TextMate is hacking. There's no supported way to do what it's doing on 10.4. – Ken Sep 03 '09 at 05:14