Re: Catching NSSlider -mouseUp: events (workaround)
Re: Catching NSSlider -mouseUp: events (workaround)
- Subject: Re: Catching NSSlider -mouseUp: events (workaround)
- From: Roland Torres <email@hidden>
- Date: Wed, 11 Apr 2007 10:30:27 -0700
On Apr 11, 2007, at 2:56 AM, Uli Kusterer wrote:
Am 11.04.2007 um 05:05 schrieb Roland Torres:
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event]; // eats the mouse-up event
NSEvent upEvent=[NSEvent mouseEventWithType:NSLeftMouseUp ...
[NSApp sendEvent:upEvent]; // dispatch mouse-up event
}
- (void)mouseUp:(NSEvent *)event
{
[super mouseUp:event];
// your code goes here ...
}
It might be safer (as in, not confusing anything in the event
system that might expect mouse events to be balanced), if you just
directly called whatever method you want to trigger instead of
synthesizing a mouse event. E.g.:
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event]; // eats the mouse-up event
if( [[self target] respondsToSelector: mouseUpSelector] )
[[self target] performSelector: mouseUpSelector withObject:
self];
}
where mouseUpSelector would be an instance variable of type SEL,
not unlike the action in target/action.
Your point about the mouseDown+mouseUp event pair is well taken.
Originally I had it the way you've shown, but I thought it might not
be a good idea to invoke my target action directly from within the
mouseDown event handler, which is why I issued my own mouseUp event
and let the system take it from there. Both ways do seem to work
without apparent side effects (which isn't all too reassuring!), but
the way you illustrate seems truer to the Cocoa model.
Thanks,
Roland
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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