Hit-testing in custom NSCell in NSTableview

  • I have a custom NSCell that draws a list of small images. This cell
    is being used in an NSTableview. I need to know when the user clicks
    on one of the images, both left and right click. I know when a click
    happens and in which column and row, but I need to know which image
    in the cell was hit. Ideas?

    Thanks,
    Glen Simmons
  • I'd have thought your best bet is to place this kind of logic inside
    the NSCell itself.  It should be easy to tell from there.

    Mike.

    On 6 Oct 2006, at 14:54, Glen Simmons wrote:

    > I have a custom NSCell that draws a list of small images. This cell
    > is being used in an NSTableview. I need to know when the user
    > clicks on one of the images, both left and right click. I know when
    > a click happens and in which column and row, but I need to know
    > which image in the cell was hit. Ideas?
    >
    > Thanks,
    > Glen Simmons
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/mike.abdullah%
    > 40gmail.com
    >
    > This email sent to <mike.abdullah...>
  • Yes, except for getting that information out to the world. When an
    NSActionCell sends its action message, there's no extra information,
    just the control that contains it. Also, the cell isn't involved at
    all for a right-click.

    On Oct 6, 2006, at 11:16 AM, Mike Abdullah wrote:

    > I'd have thought your best bet is to place this kind of logic
    > inside the NSCell itself.  It should be easy to tell from there.
    >
    > Mike.
    >
    > On 6 Oct 2006, at 14:54, Glen Simmons wrote:
    >
    >> I have a custom NSCell that draws a list of small images. This
    >> cell is being used in an NSTableview. I need to know when the user
    >> clicks on one of the images, both left and right click. I know
    >> when a click happens and in which column and row, but I need to
    >> know which image in the cell was hit. Ideas?
    >>
    >> Thanks,
    >> Glen Simmons
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/mike.abdullah%
    >> 40gmail.com
    >>
    >> This email sent to <mike.abdullah...>
    >
  • On Friday, October 06, 2006, at 11:47AM, Glen Simmons <glen.simmons...> wrote:

    > Yes, except for getting that information out to the world. When an
    > NSActionCell sends its action message, there's no extra information,
    > just the control that contains it. Also, the cell isn't involved at
    > all for a right-click.

    You could always do something like this...

    * add a 'clickedImageIndex' ivar to your cell; also expose at least a getter in your control to obtain that ivar.
    * when a mouse click is received by your control (you'll need to override mouseDown if not already), 'clear' the cell's clickedImageIndex (maybe set to -1)
    * in your code that determines which image in the cell was actually hit, set that as the clickedImageIndex.
    * In your action handler (where you have the control), ask the control for the clickedImageIndex.

    I did something similar to this for a multi-cell control.

    --
    Rick Sharp
    Instant Interactive(tm)
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today