FROM : John Stiles
DATE : Fri Apr 18 23:25:15 2008
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_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Fri Apr 18 23:25:15 2008
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_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| John Stiles | Apr 17, 19:54 | |
| Randall Meadows | Apr 17, 20:01 | |
| John Stiles | Apr 17, 20:05 | |
| John Stiles | Apr 17, 20:14 | |
| Randall Meadows | Apr 17, 20:16 | |
| John Stiles | Apr 18, 20:44 | |
| John Stiles | Apr 18, 23:25 | |
| Martin Wierschin | Apr 19, 04:20 | |
| Martin Wierschin | Apr 19, 04:22 | |
| Benjamin Stiglitz | Apr 19, 06:36 | |
| Jean-Daniel Dupas | Apr 19, 14:05 | |
| Benjamin Stiglitz | Apr 19, 23:42 | |
| John Stiles | Apr 20, 02:36 | |
| John Stiles | Apr 20, 02:37 |






Cocoa mail archive

