views:

230

answers:

1

I'm working on a custom button component. I've been reading through the documentation for NSControl and NSCell, and the programming topics associated with it.

What I can't figure out is how to correctly use mouse events in NSCell's. I see that NSControl subclasses NSView, which implements NSResponder - so implementing mouse events in the control and forwarding to the cell is simple. But the documentation states that when a control needs to be placed in a Table, the Cell for the control is used, not the control.

The methods that are available in the cell are somewhat well documented, but confusing to understand how to implement. Ultimately what I'm trying to figure out is how to replicate a push button; a down image is shown while the mouse is down, until the mouse is up. I've already got the images and text etc working fine.

I've been experimenting and messing around with different combinations of the mouse methods for NSCell, but just can't get it right.

-Is using NSCell for mouse events in this respect even correct?

-Is using the mouse events from NSControl and forwarding to the cell the right way?

-If I use mouse events from the Control and forward to the cell, how does a Table know that I need certain mouse events forwarded to my cell?

-If the mouse events are needed from an NSControl, can a table use an NSControl?

Any takers?

+2  A: 

Ultimately what I'm trying to figure out is how to replicate a push button; a down image is shown while the mouse is down, until the mouse is up.

Why not use NSButtonCell?

Peter Hosey
Because my control has a bunch of custom drawing. It is a button - but yet I'm using scale 9 for the button image, and adding an optional label and icon, as well as allowing you to set the "over", and "down" states of each. So there's quite a bit more going on. NSButton supports some of that, but not exactly how I need it.
bl4th3rsk1t3
And a subclass of NSButtonCell wouldn't work?
Peter Hosey