Re: Custom tracking in a NSTextFieldCell
Re: Custom tracking in a NSTextFieldCell
- Subject: Re: Custom tracking in a NSTextFieldCell
- From: Alastair Houghton <email@hidden>
- Date: Fri, 9 Jan 2009 10:59:07 +0000
On 8 Jan 2009, at 21:19, Eric Gorr wrote:
Well, I was finally able to spot the delegate method:
-outlineView:shouldTrackCell:forTableColumn:item:
and simply return YES.
This caused trackMouse & startTrackingAt to be called, but this
isn't useful until stopTracking is called. For some reason, it isn't.
I would be interested in learning why this might not be the case and
what I can do about it.
Mouse tracking can be a little frustrating sometimes, because whether
the NSCell methods work as advertised depends somewhat on the
implementation of the NSCell in question, and also on the NSView that
is hosting it.
For instance, sometimes people code cells with their own mouse
tracking loop in -trackMouse:inRect:ofView:untilMouseUp: --- something
like this, for instance:
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame
ofView:(NSView *)controlView untilMouseUp:
(BOOL)untilMouseUp
{
if ([theEvent type] == NSLeftMouseDown) {
NSWindow *window = [controlView window];
NSEvent *myEvent;
while ((myEvent = [window nextEventMatchingMask:
(NSLeftMouseDragged
|
NSLeftMouseUp)])) {
NSPoint pos = [controlView convertPoint:[theEvent
locationInWindow]
fromView:nil];
// Mouse is at location in "pos". Do whatever is needed.
if ([myEvent type] == NSLeftMouseUp) {
// Finished tracking
return YES;
}
}
}
return [super trackMouse:theEvent inRect:cellFrame
ofView:controlView
untilMouseUp:untilMouseUp];
}
in which case you won't see either -startTrackingAt:inView: or -
stopTracking:at:inView:mouseIsUp: if the user presses the left button
in that cell.
Also, similar things can happen in the view layer instead, so someone
might run a tracking loop not dissimilar to that above from -
mouseDown:, and in that case it may be that your cell won't see the
messages for that reason.
The most frustrating part, I've always found, is that some of the
framework's controls do these kinds of things, and exactly what they
do in each case doesn't appear to be documented anywhere.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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