Dragging Around A NSScrollView
Dragging Around A NSScrollView
- Subject: Dragging Around A NSScrollView
- From: Seth Willits <email@hidden>
- Date: Sat, 27 Mar 2004 17:50:43 -0800
I have a custom NSView embedded in a scroll view and I'd like to be
able to drag the scroll view around by clicking in the view and simply
dragging. The cursor would be an openHandCursor when the mouse is up
and then a closedHandCursor when dragging. There are also things I'd be
drawing in the view that would just the regular arrow pointer,
signaling that the user can select those.
Taking a look at this would make it clearer:
http://www.freaksw.com/WCInterface.jpg
When the mouse is over the background and not inside the whole
rectangle thing, it would be an openHandCursor and let you drag the
view around (by drag I mean dragging left and right would make the
bottom scrollbar scroll, dragging up and down would make the right
scrollbar scroll). When the mouse is inside any of the objects being
drawn on top of the background it would be an arrow cursor.
Here's the code I have so far:
- (void)mouseDown:(NSEvent *)theEvent
{
BOOL keepOn = YES;
BOOL isInside = YES;
NSPoint mouseLoc;
while (keepOn) {
theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask |
NSLeftMouseDraggedMask];
mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
isInside = [self mouse:mouseLoc inRect:[self bounds]];
switch ([theEvent type]) {
case NSLeftMouseDragged:
[mScrollView setDocumentCursor:[NSCursor closedHandCursor]];
break;
case NSLeftMouseUp:
[mScrollView setDocumentCursor:[NSCursor openHandCursor]];
keepOn = NO;
break;
default:
// Ignore any other kind of event
break;
}
}
return;
}
This is slightly modified code from Apple's reference:
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
BasicEventHandling/Tasks/HandlingMouseEvents.html#//apple_ref/doc/uid/
20000906>
I haven't begun to move the view around yet because I can't event get
the cursor to change. So the question is, how do I get the cursor to
change, and how would I make the scrollbars scroll?
Seth Willits
------------------------------------------------------------------------
---
President and Head Developer of Freak Software -
http://www.freaksw.com
REALbasic Guru at ResExcellence -
http://www.resexcellence.com/realbasic
Webmaster for REALbasic Game Central -
http://www.freaksw.com/rbgames
"Few are those who see with their own eyes and feel with their own
hearts."
-- Albert Einstein
------------------------------------------------------------------------
---
_______________________________________________
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.