Re: detecting mouse movement when window is inactive
Re: detecting mouse movement when window is inactive
- Subject: Re: detecting mouse movement when window is inactive
- From: Mitchell Livingston <email@hidden>
- Date: Sun, 22 Jul 2007 15:58:57 -0700
This is what I want to do with an NSOutlineView, but it seems to get really complicated with the content constantly changing. I set it up with these tracking rects, but it seems to freeze. Here is my code if it's of any interest.
- (void) mouseEntered: (NSEvent *) event
{
NSNumber * rowNumber;
if ((rowNumber = [event userData]))
{
fHoverRow = [rowNumber intValue];
[self reloadItem: [self itemAtRow: fHoverRow]];
}
[super mouseEntered: event];
}
- (void) mouseExited: (NSEvent *) event
{
NSNumber * rowNumber;
if ((rowNumber = [event userData]))
{
int row = [rowNumber intValue];
if (fHoverRow == row)
fHoverRow = -1;
[self reloadItem: [self itemAtRow: row]];
}
[super mouseExited: event];
}
- (int) hoverRow
{
return fHoverRow;
}
- (void) reloadData
{
fHoverRow = -1;
NSNumber * tag;
NSEnumerator * enumerator = [fTrackingList objectEnumerator];
while ((tag = [enumerator nextObject]))
[self removeTrackingRect: [tag intValue]];
[fTrackingList removeAllObjects];
[super reloadData];
}
- (NSRect) frameOfCellAtColumn: (int) column row: (int) row
{
NSRect rect = [super frameOfCellAtColumn: column row: row];
if (column == [self columnWithIdentifier: @"Priority"])
{
NSNumber * cellKey = [NSNumber numberWithInt: row];
NSNumber * tag;
if ((tag = [fTrackingList objectForKey: cellKey]))
[self removeTrackingRect: [tag intValue]];
[fTrackingList setObject:
[NSNumber numberWithInt: [self addTrackingRect: rect owner: self userData: cellKey assumeInside: NO]] forKey: cellKey];
}
return rect;
}
Basically I'm setting fHoverCell as the moused-over cell, but with fast movement or a lot of cells it seems to crash.
Thanks,
Mitch
On Sunday, July 22, 2007, at 06:34PM, "Uli Kusterer" <email@hidden> wrote:
>On 22.07.2007, at 18:22, Mitchell Livingston wrote:
>> On Jul 22, 2007, at 9:52 AM, Uli Kusterer wrote:
>>
>>> On 22.07.2007, at 15:42, Mitchell Livingston wrote:
>>>> On Jul 22, 2007, at 9:30 AM, I. Savant wrote:
>>>>
>>>>> On Jul 22, 2007, at 12:23 AM, Mitchell Livingston wrote:
>>>>>> Is there no way to do this in cocoa? Tooltips can work when not
>>>>>> for the inactive window, so there must be some way. Any help
>>>>>> would really be appreciated.
>>>>>
>>>>> See -addTrackingRect:owner:userData:assumeInside: and -- (void)
>>>>> removeTrackingRect:(NSTrackingRectTag)aTag and search the docs
>>>>> and archives for examples.
>>>>>
>>>> It appears this is only for entering and exiting. I need to
>>>> detect movement, specifically to know when the mouse enters and
>>>> exits cells in a table view. Is this possible?
>>>>
>>>> Thanks,
>>>> Mitch
>>>
>>> Have you even read the description of that method? You pass it a
>>> rect. It does exactly what you want.
>>
>> Perhaps not as closed as I should have. :-/ In my rush it seemed to
>> be focusing on the enter and exit, but I see now.
>
> Maybe I'm misunderstanding something, but you said you wanted to
>detect enter and exit of table cells. This gives you enter and exit
>of arbitrary rects inside your view. Is there anything else you're
>trying to do?
>
>Cheers,
>-- M. Uli Kusterer
>http://www.zathras.de
>
>
>
>
>
_______________________________________________
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