Re: NSCell mouse tracking best practices.
Re: NSCell mouse tracking best practices.
- Subject: Re: NSCell mouse tracking best practices.
- From: Matt Neuburg <email@hidden>
- Date: Wed, 05 Jul 2006 17:30:08 -0700
- Thread-topic: NSCell mouse tracking best practices.
On Wed, 5 Jul 2006 16:17:18 -0400, ?scar Morales Viv? <email@hidden>
said:
>I'm trying to implement a custom subclass of NSCell. As part of the
>work I need to implement mouse event tracking (down, drag & up as
>usual). The problem is that the methods in NSCell don't pass around
>the cell's frame and the information is needed to figure out the
>behavior while dragging. From what I've been reading in the docs,
>there's two possible solutions:
>
>- Keep around an instance variable for the tracking rectangle. Fill
>it up in trackMouse:inRect:ofView:untilMouseUp: right before calling
>super, and then override startTrackingAt:inView:,
>continueTracking:at:inView and stopTracking:at:inView:mouseIsUp:
>(NSSliderCell seems to do this).
>- Just override the whole trackMouse:inRect:ofView:untilMouseUp:
>taking care of the event loop there and ignoring the other three
>mouse tracking methods (That's what the clock control sample code does).
My app (NotLight) uses an NSImageCell subclass. What I do is:
(1) I implement trackMouse:, as you say. (I don't use any instance variable
for the tracking rectangle - I don't have to, because I'm not creating a
draggable image - but I do set some state switches telling me whether the
mouse is in a certain region.)
(2) In the NSMatrix subclass, I implement mouseUp and notify the relevant
cells that the mouse went up. This sort of cooperation between the NSMatrix
and the NSCells makes things very complicated, but for some purposes that's
just the way you have to do it. My NSCell didn't get any startTracking:...
(etc.) messages, and I assume that this is because it's an NSImageCell.
That's why I had to resort to the matrix's mouseUp instead. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden