[SOLVED] Simulating menu bar blink in Cocoa
[SOLVED] Simulating menu bar blink in Cocoa
- Subject: [SOLVED] Simulating menu bar blink in Cocoa
- From: John Stiles <email@hidden>
- Date: Fri, 18 Apr 2008 14:25:15 -0700
The "fake temporary item" solution actually works pretty well. It's the
last thing I'd call elegant, but here's how you can blink a menu title
in Cocoa.
This assumes that you aren't actually assigning the command+F35 key
equivalent to any of your menu items... hopefully a safe assumption for
the time being :)
- (void) blink {
const unichar f35Key = NSF35FunctionKey;
NSString* f35String = [NSString stringWithCharacters:&f35Key
length:1];
int position = [myMenu numberOfItems];
NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:@"* blink *"
action:NULL
keyEquivalent:f35String]
autorelease];
[item setTarget:NULL];
[myMenu insertItem:item atIndex:position];
NSEvent * f35Event = [NSEvent keyEventWithType:NSKeyDown
location:NSZeroPoint
modifierFlags:NSCommandKeyMask
timestamp:0
windowNumber:0
context:[NSGraphicsContext
currentContext]
characters:f35String
charactersIgnoringModifiers:f35String
isARepeat:NO
keyCode:0];
[myMenu performKeyEquivalent:f35Event];
[myMenu removeItemAtIndex:position];
}
John Stiles wrote:
Reading the list archives a little more, it looks like there may be
two ways to do this:
- _NSHighlightCarbonMenu and _NSUnhighlightCarbonMenu are SPIs which
take an NSMenu* and do exactly what you'd expect
- You can add a fake temporary menu item to your menu, with a suitably
bizarre key equivalent and no target or action. Then use NSMenu
-performKeyEquivalent: to simulate its selection.
Wow, great choices here :| I'm going to try #2 first since it's not
SPI. I'll inform the list of the results.
John Stiles wrote:
John Stiles wrote:
Randall Meadows wrote:
On Apr 17, 2008, at 11:54 AM, John Stiles wrote:
As previously explained here, I'm handling hotkeys in my app via
custom code in order to work around some AppKit bugs.
How can I simulate the menu-title blink effect using Cocoa? In
Carbon, it's FlashMenuBar(menuID) but I don't see a Cocoa equivalent.
NSMenuView's -performActionWithHighlightingForItemAtIndex:?
(Never used it, just looked it up...)
This is at the top of the file:
Note: NSMenuView is deprecated and is no longer used to draw
menus. Calling its methods will not affect the appearance of your
menus.
I don't think this will work. Actually I don't think there is even
a way to get a valid NSMenuView* at all.
For the curious, I tried the next best thing—NSMenu's
-performActionForItemAtIndex: —and this API does not appear to
simulate the menu blink, although it arguably should.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden