I previously assumed I could simply draw my view a couple times with a delay
between, to simulate the quick flash that a menu item does when you choose it.
Of course, so many things have to be difficult in the world of Cocoa. I assume
drawing can't get flushed to the screen until control is returned to the
tracking event loop? What I came up with works, but seems ridiculously
inelegant. Is there some better way to give the current event loop time so I
can have the drawing and canceling done right in my mouseUp handler?
-(void) mouseUp:(NSEvent*)event
{
UNUSED_VAR(event);
NSMenuItem* item = [self enclosingMenuItem];
NSMenu* menu = [item menu];
// Flash the menu item off and back on just like real ones:
[self performSelector:@selector(flashOff:) withObject:menu
afterDelay:0.05 inModes:[NSArray arrayWithObject:NSEventTrackingRunLoopMode]];
}
-(void) flashOff:(NSMenu*)menu
{
isHilited = NO;
[self display];
[self performSelector:@selector(flashOn:) withObject:menu
afterDelay:0.05 inModes:[NSArray arrayWithObject:NSEventTrackingRunLoopMode]];
}
-(void) flashOn:(NSMenu*)menu
{
isHilited = YES;
[self display];
[self performSelector:@selector(cancelMenu:) withObject:menu
afterDelay:0.05 inModes:[NSArray arrayWithObject:NSEventTrackingRunLoopMode]];
}
-(void) cancelMenu:(NSMenu*)menu
{
[menu cancelTracking];
[self performSelector:@selector(delayedSendAction:) withObject:nil
afterDelay:0 inModes:[NSArray arrayWithObjects:NSEventTrackingRunLoopMode,
NSDefaultRunLoopMode, nil]];
}
-(void) delayedSendAction:(id)obj
{
UNUSED_VAR(obj);
// Then send the action to the target:
NSMenuItem* item = [self enclosingMenuItem];
SEL act = [item action];
id targ = [item target];
if(act != nil && targ != nil)
[NSApp sendAction:act to:targ from:item];
}
--
Steve Mills
office: 952-818-3871
home: 952-401-6255
cell: 612-803-6157
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]