• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Draggable buttons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Draggable buttons
      • From: "Erik M. Buck" <email@hidden>
  • Prev by Date: Re: Overiding NSButton initWithFrame: (doesn't work)
  • Next by Date: Re: Draggable buttons
  • Previous by thread: Re: Objective-C++ or C bridge?
  • Next by thread: Re: Draggable buttons
  • Index(es):
    • Date
    • Thread