Re: NSMatrix hangs in mouse tracking?
Re: NSMatrix hangs in mouse tracking?
- Subject: Re: NSMatrix hangs in mouse tracking?
- From: Daniel Jalkut <email@hidden>
- Date: Thu, 29 May 2003 10:25:48 -0700
For the record, the following workaround does the trick. I fake a
mouse dragged event whenever my cell gets a stopTracking call. This
ensures that NSMatrix will have another event to consume, prompting it
to send startTracking to the new cell.
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint
inView:(NSView *)controlView mouseIsUp:(BOOL)flag
{
NSEvent* fakeMouseEvent;
NSWindow* viewWindow = [controlView window];
NSEvent* lastEvent = [viewWindow currentEvent];
[super stopTracking:lastPoint at:stopPoint inView:controlView
mouseIsUp:flag];
// Post a fake mouse dragged event to the exact same location we're
at, to stimulate
// continued tracking by NSMatrix if the mouse stopped dead upon
leaving the cell.
fakeMouseEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged
location:[lastEvent locationInWindow] modifierFlags:[lastEvent
modifierFlags] timestamp:[lastEvent timestamp] windowNumber:[lastEvent
windowNumber] context:[lastEvent context] eventNumber:[lastEvent
eventNumber] clickCount:1 pressure:1.0];
[viewWindow postEvent:fakeMouseEvent atStart:YES];
}
On Thursday, May 29, 2003, at 09:03 AM, Daniel Jalkut wrote:
>
I am implementing a custom control as a subclass of NSMatrix with a
>
single row of cells that are implemented as subclasses of
>
NSActionCell. When one of my cells gets clicked, and for the duration
>
of it being tracked, it draws a graphic in its portion of the view.
>
When the tracking moves to another cell, that cell draws a graphic,
>
and the old cell relinquishes the graphic, etc.
>
>
I handle tracking by implementing startTrackingAt, continueTracking,
>
and stopTracking.
>
>
I have found in testing that as I move the mouse from one cell to the
>
next, the cell that's being departed gets a stopTracking, and the cell
>
that's being arrived at gets a startTracking. Great! But I've also
>
found a problem scenario in which the tracking appears to hang:
>
>
It seems that if I move the mouse quickly enough from one cell to the
>
next, and stop dead at the destination, I can get NSMatrix's tracking
>
loop to "hang." If the mouse is flicked fast enough and the timing is
>
right, then NSMatrix seems to get only one mouse event, and it uses it
>
up telling the old cell to stopTracking. At this point, the new cell
>
hasn't gotten a startTracking, even though I'm hovering over its
>
contents. As soon as I move the mouse again, it "unlocks" the tracking
>
loop and the new cell becomes selected.
>
>
While the "hang" is happening, the old cell doesn't update, even
>
though it's been told to stopTracking (so I've redrawn its contents).
>
I assume this means the NSMatrix tracking loop is stuck in event
>
blocking, probably waiting for any mouse event to occur.
>
>
I actually just reproduced it in Interface Builder using a 3x10 matrix
>
of simple pushbuttons, so if you want to see it for yourself you can
>
try in IB. Rush your mouse around the matrix frantically, stopping
>
abruptly from time to time (with the mouse still down). You'll find
>
that sometimes you end up hovering over a button but it's not
>
selected. When you move the mouse slightly again, that button finally
>
becomes selected.
>
>
Is this a problem other people have run into? Any way to workaround
>
it, short of writing my own tracking loop and implementing trackMouse?
>
Maybe I could post a fake mouse movement event everytime I get a
>
stopTracking?
>
>
And yes, I'll write up a bug...
>
>
Daniel
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.