I am writing a custom NSControl with custom NSCells. It is a control, so it has to respond to the mouse. I created an NSTrackingArea over my control, implemented -mouseEntered:
, -mouseExited:
and -mouseMoved:
. (And I will have to implement -mouseUp/Down:
, but I have no idea what to do in there, so for now I haven't overridden those methods yet.) In these methods I successfully determine on which cell the mouse currently is. Now I have two questions:
- Is this a good approach for tracking the mouse? If not, what should I do instead?
- What method should I call on my NSCell on a mouse click, when the mouse enters the cell, when the mouse leaves the cell etc? Apple's docs are not very clear about this.
So, basically: When should I call what method on my NSCell to let it respond to mouse events?
EDIT:
Rereading the docs, I think I should call NSCell's -trackMouse:inRect:ofView:untilMouseUp:
and override -startTrackingAt:inView:
, -continueTracking:at:inView:
and -stopTracking:at:inView:mouseIsUp:
. Again two questions: 1) the docs give the impression these are only called when the mouse is down. Is that correct? Then what should I do instead? 2) Where/when should I call NSCell's -trackMouse:inRect:ofView:untilMouseUp:
?
I ended up implementing my own mouse tracking mechanism:
And of course, in
MyCell.h
:With an empty implementation for those methods (so the compiler doesn't complain and I can leave the implementation of the mouse handling methods to subclasses).