Re: Capturing the mouse and working out the mouse position
Re: Capturing the mouse and working out the mouse position
- Subject: Re: Capturing the mouse and working out the mouse position
- From: Graham Cox <email@hidden>
- Date: Fri, 28 Nov 2008 14:23:12 +1100
On 28 Nov 2008, at 2:02 pm, Christian Graus wrote:
Hi guys. Although I've subscribed to this list for months, this is
my first
post. I'm in the process of migrating from Windows development, so my
questions may have a windows centric bent, in terms of my thinking
in terms
of how I'd do stuff under that platform.
Basically, I have an NSTableView in which each row contains an icon
and some
text. I have it so when I click on an item, a thumbnail animates up
of the
image that the item refers to. So far, so good. I need to achieve
two
things:
1 - I need to work out if the mouse is over the icon rather than the
text,
b/c I only want the popup to occur if it is. This means I need to
know the
mouse pos relative to the control. I can't find a way to work that
out. I
am using the shouldSelectRow event, which doesn't get passed a mouse
pos.
2 - right now, I hide my popup based on a timer, but what I want to
do, is
to 'capture' the mouse, so that no matter where the user clicks when
the
popup is visible, the program closes the popup window in response.
Any advice on how to find out the mouse position, how to translate
it to be
relative to a control and how to capture the mouse, would be
recieved with
much appreciation. Thank you
I'm assuming the icon and text are in different columns, otherwise
you'd have had to implement a custom cell, in which case your cell has
all the mouse tracking information passed to it.
So in the normal case, you can just use -clickedRow and -clickedColumn
to get the row/column that was clicked. Given the column index you can
get the column using [[table tableColumns] objectAtIndex:[table
clickedColumn]] but this is only valid in the action method of the
table's target.
Alternatively, you could implement the delegate method:
tableView:didClickTableColumn:
which passes you the column directly, which saves a lot of hassle.
Given the column, you can call methods on it to make sure it's the one
you expect, then do whatever. Bear in mind the user can drag columns
into any order, so you need to be ready to ask the column for more
info (such as its identifier, typically) to know whether it's the icon
or the text column. In other words don't test the mouse position to
tell columns apart, since columns move.
However, it also sounds like what you might really want is a custom
icon cell, since special behaviours that are part of the actual
content of a table row are usually handled that way. Cell subclassing
can be a bit of a chore though - see NSCell.
hth,
Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden