Re: Problems manually scrolling a view using mouseDown:
Re: Problems manually scrolling a view using mouseDown:
- Subject: Re: Problems manually scrolling a view using mouseDown:
- From: Matt Neuburg <email@hidden>
- Date: Mon, 24 Jan 2005 13:33:16 -0800
On Sun, 23 Jan 2005 21:28:46 -0800, mmalcolm crawford <email@hidden>
said:
>
>On Jan 23, 2005, at 9:15 PM, Matt Neuburg wrote:
>
>> (2) You exit the event loop prematurely, instead of generating your own
>> event loop during the drag, as explained in the helpful document
>> "Handling
>> Mouse Events in Views".
>> [...]
>> - (void) mouseDown: (NSEvent*) e {
>> NSScrollView* sv = [self enclosingScrollView];
>> NSClipView* cv = [sv contentView];
>> [[NSCursor openHandCursor] push];
>> clickPoint = [e locationInWindow];
>> originalOrigin = [cv bounds].origin;
>> {
>> BOOL keepOn = YES;
>> while (keepOn) {
>> NSEvent* theEvent = [[self window] nextEventMatchingMask:
>> NSLeftMouseUpMask | NSLeftMouseDraggedMask];
>>
>That document is, unfortunately, misleading (and a bug has been filed).
> You should not set up your own "mini event loop" in this way. You
>should instead capture the relevant information in mouseDown: and then
>deal with updates in mouseMoved: and mouseUp:.
Okay, I'm adaptable. Here's the Damn-The-Documentation, Full-Speed-Ahead
version:
- (void) mouseDown: (NSEvent*) e {
clickPoint = [e locationInWindow];
originalOrigin = [cv bounds].origin;
[cv setDocumentCursor: [NSCursor openHandCursor]];
}
- (void) mouseDragged: (NSEvent*) e {
NSPoint newPoint = [e locationInWindow];
NSPoint newOrigin = NSMakePoint(originalOrigin.x, originalOrigin.y +
(clickPoint.y - newPoint.y));
[cv scrollToPoint: [cv constrainScrollPoint: newOrigin]];
[sv reflectScrolledClipView: cv];
}
- (void) mouseUp: (NSEvent*) e {
[cv setDocumentCursor: nil];
}
cv, sv, clickPoint, and originalOrigin are all ivars; cv and sv were set to
the NSClipView and the NSScrollView at awakeFromNib-time. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden