Contents

dragImage:at:offset:event:pasteboard:source:slideBack:

Initiates a dragging operation from the view, allowing the user to drag arbitrary data with a specified icon into any application that has window or view objects that accept dragged data.

Declaration

- (void) dragImage:(NSImage *) image at:(NSPoint) viewLocation offset:(NSSize) initialOffset event:(NSEvent *) event pasteboard:(NSPasteboard *) pboard source:(id) sourceObj slideBack:(BOOL) slideFlag;

Parameters

  • image:

    The Nsimage object to be dragged.

  • viewLocation:

    The location of the image’s lower-left corner, in the view’s coordinate system. It determines the placement of the dragged image under the cursor. When determining the image location you should use the mouse down coordinate, provided in theEvent, rather than the current mouse location.

  • initialOffset:

    This parameter is ignored.

  • event:

    The left mouse-down event that triggered the dragging operation (see discussion below).

  • pboard:

    The pasteboard that holds the data to be transferred to the destination (see discussion below).

  • sourceObj:

    An object that serves as the controller of the dragging operation. It must conform to the Nsdraggingsource protocol and is typically the view itself or its Nswindow object.

  • slideFlag:

    A Boolean that determines whether the drag image should slide back if it’s rejected. The image slides back to imageLoc if slideBack is True and the image isn’t accepted by the dragging destination. If False the image doesn’t slide back.

Discussion

This method must be invoked only within an implementation of the mouseDown(with:) or mouseDragged(with:) methods.

Before invoking this method, you must place the data to be transferred on pboard. To do this, get the drag pasteboard object (NSDragPboard), declare the types of the data, and then put the data on the pasteboard. This code fragment initiates a dragging operation on an image itself (that is, the image is the data to be transferred):

- (void)mouseDown:(NSEvent *)theEvent
{
    NSSize dragOffset = NSMakeSize(0.0, 0.0);
    NSPasteboard *pboard;
 
    pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]  owner:self];
    [pboard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
 
    [self dragImage:[self image] at:[self imageLocation] offset:dragOffset
        event:theEvent pasteboard:pboard source:self slideBack:YES];
 
    return;
}

See the NSDraggingSource, NSDraggingInfo, and NSDraggingDestination protocol specifications for more information on dragging operations.

See Also

Related Documentation

Methods