How do I draw my own key equivalents in NSMenuItem?

I will need something that this owner has drawn in the key keyword equivalents in my own code. Like TextMate in this example .

I've heard that the menu drawing is carbon based, but I don't hope it's such a huge hack.

But no matter what I tried and wherever I looked, I couldn't find a clue.

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

+2


source to share


2 answers


The menu bar, even at 10.6, is still carbon based. At the Carbon level, there is an API (see below) that allows you to set whatever key equivalent you want on the menu, regardless of whether the application actually maps that key to the menuitem equivalent. In other words, Carbon allows you to customize the display of a menu item regardless of behavior. Using this API, you can set whatever keyboard shortcut you want the menuitem to display.



Unfortunately, it looks like the documentation for this API no longer exists. But you can still read the header file. I believe the required API 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 should still be, given that Cocoa's menu is still based on Carbon menu.

+3


source


One way to do this is to make the item itself. I'm not sure if there is a way to simply override the drawing with the key equivalent. Take a look at sample MenuItemView .



+2


source







All Articles