Instance Method

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

anImage

The NSImage object to be dragged.

imageLoc

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.

mouseOffset

This parameter is ignored.

theEvent

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).

sourceObject

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.

slideBack

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

Discussion

This method must be invoked only within an implementation of the mouseDown: or mouseDragged: 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

Deprecated Methods

- convertPointToBase:

Converts the point from the view’s coordinate system to the base coordinate system.

Deprecated
- convertPointFromBase:

Converts the point from the base coordinate system to the view’s coordinate system.

Deprecated
- convertSizeToBase:

Converts the size from the view’s coordinate system to the base coordinate system.

Deprecated
- convertSizeFromBase:

Converts the size from the base coordinate system to the view’s coordinate system.

Deprecated
- convertRectToBase:

Converts the rectangle from the view’s coordinate system to the base coordinate system.

Deprecated
- convertRectFromBase:

Converts the rectangle from the base coordinate system to the view’s coordinate system.

Deprecated
- performMnemonic:

Implemented by subclasses to respond to mnemonics.

Deprecated
- shouldDrawColor

Returns a Boolean value indicating whether the view is being drawn to an environment that supports color.

Deprecated
- allocateGState

Causes the view to maintain a private graphics state object, which encapsulates all parameters of the graphics environment.

Deprecated
- gState

Returns the identifier for the view’s graphics state object, or 0 if the view doesn’t have a graphics state object.

Deprecated
- setUpGState

Overridden by subclasses to (re)initialize the view’s graphics state object.

Deprecated
- renewGState

Invalidates the view’s graphics state object, if it has one.

Deprecated
- releaseGState

Frees the view’s graphics state object, if it has one.

Deprecated