Draggable buttons
Draggable buttons
- Subject: Draggable buttons
- From: Ben Chess <email@hidden>
- Date: Sat, 2 Feb 2002 12:52:15 -0500
Hi folks,
It's common behavior in some instances to not start dragging an image
until the user has moved the cursor a few pixels away from the original
point. This is usually used to discriminate between intention to click
vs. intention to drag the item. The Dock exhibits this sort of
behavior. The icon in the title bars of Project Builder windows does
the same thing.
Does anyone know how to do this sort of thing?
The only way to start a non-TableView drag that I know of is
dragImage:at:offset:event:pasteboard:source:slideBack. The docs state
clearly that this is to only be called from a mouseDown event. Throwing
caution into the wind, I tried saving the mouseDown event and then not
making a call to dragImage until a move occurs, but it doesn't work
correctly. It seems to be capturing mouse movements, but the image
dragged is never drawn.
I'm doing something like this in an NSResponder subclass:
-(void)mouseDown:(NSEvent *)theEvent
{
_mouseDownEvent = [theEvent retain];
_originalPoint = [theEvent locationInWindow];
}
-(void)mouseMoved:(NSEvent *)theEvent
{
if (_mouseDownEvent)
{
if (abs(originalPoint.x - [theEvent locationInWindow].x)>8 ||
abs(originalPoint.y - [theEvent locationInWindow].y)>8)
{
[[theEvent window] dragImage: ...
at: ...
offset: ...
event: _mouseDownEvent
pasteboard:... source:... slideBack:YES];
}
}
}
The object I'm trying to drag is a NSButtonCell.
Thanks for any help you can provide
Ben