So my view is a NSControl subclass and after playing with this some it seems you have to do one more thing. If you're going to have a control handle multiple cells (in my case button cells) you have to call setCell: for the correct cell in mouseDown: and then let super handle the mouse event. This seems to work much better than trying to handle the event yourself.

Does this sound right to you Ken?

In any case I think there should really be more info on how to subclass NSControl and NSCell. The developer docs are really sparse on this. I filed a bug asking for a guide on this topic (rdar:// 5804311).

->Ben
--
Ben Lachman
Acacia Tree Software

http://acaciatreesoftware.com

[EMAIL PROTECTED]
740.590.0009

On Mar 17, 2008, at 4:25 PM, Ken Ferry wrote:

On Mon, Mar 17, 2008 at 8:49 AM, glenn andreas <[EMAIL PROTECTED]> wrote:

 On Mar 17, 2008, at 1:42 AM, Ben Lachman wrote:

I have a few NSButtonCells that I'm using in a custom view.  I need
them to track the mouse during clicks and do this by calling
NSCell's trackMouse:inRect:ofView:untilMouseUp:.  This works fine
except that the button cells never update their graphical state by
highlighting or whatever.  However if I call performClick: on them
the button updates as it should.  Is the only solution to this to
implement mouse tracking at the view instead of at the cell level?


 You need to set the control view of the cell to your view and then
 implement the appropriate [update|draw]cell[inside]: methods in your
 view.

Or, a bit more specifically, setControlView: will fail to store
anything if the passed view is not an NSControl.  You can use an
NSCell to purely stamp out drawing in an NSView, but more complicated
interaction requires the view to be an NSControl, so that the cell can
message the control in various ways.  It isn't just updateCell:.

Ken Ferry
Cocoa Frameworks

 Basically a cell expects to be inside a control and needs to be
 able to tell that control to draw itself (and thus redraw the cell).
One would think that the parameters to trackMouse would be sufficient to have the cell handle this by itself, but since a control could have a background behind the cell, it's really up to the control to decide
 how to redraw the cell.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to