Next Page > Hide TOC

NSDraggingDestination Protocol Reference

(informal protocol)

Framework
/System/Library/Frameworks/AppKit.framework
Companion guide
Declared in
NSDragging.h

Overview

The NSDraggingDestination informal protocol declares methods that the destination object (or recipient) of a dragged image must implement. The destination automatically receives NSDraggingDestination messages for pasteboard data types it has registered for as an image enters, moves around inside, and then exits or is released within the destination’s boundaries.

Tasks

Managing a Dragging Session Before an Image Is Released

Managing a Dragging Session After an Image Is Released

Instance Methods

concludeDragOperation:

Invoked when the dragging operation is complete, signaling the receiver to perform any necessary clean-up.

- (void)concludeDragOperation:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Discussion

For this method to be invoked, the previous performDragOperation: must have returned YES. The destination implements this method to perform any tidying up that it needs to do, such as updating its visual representation now that it has incorporated the dragged data. This message is the last message sent from sender to the destination during a dragging session.

Availability
Declared In
NSDragging.h

draggingEnded:

Implement this method to be notified when a drag operation ends in some other destination.

- (void)draggingEnded:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Discussion

This method might be used by a destination doing auto-expansion in order to collapse any auto-expands. This method has not yet been implemented.

Availability
Declared In
NSDragging.h

draggingEntered:

Invoked when the dragged image enters destination bounds or frame; delegate returns dragging operation to perform.

- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Return Value

One (and only one) of the dragging operation constants described in “Constants” in the NSDraggingInfo reference. The default return value (if this method is not implemented by the destination) is the value returned by the previous draggingEntered: message.

Discussion

Invoked when a dragged image enters the destination but only if the destination has registered for the pasteboard data type involved in the drag operation. Specifically, this method is invoked when the mouse pointer enters the destination’s bounds rectangle (if it is a view object) or its frame rectangle (if it is a window object).

This method must return a value that indicates which dragging operation the destination will perform when the image is released. In deciding which dragging operation to return, the method should evaluate the overlap between both the dragging operations allowed by the source (obtained from sender with the draggingSourceOperationMask method) and the dragging operations and pasteboard data types the destination itself supports.

If none of the operations is appropriate, this method should return NSDragOperationNone (this is the default response if the method is not implemented by the destination). A destination will still receive draggingUpdated: and draggingExited: even if NSDragOperationNone is returned by this method.

Availability
See Also
Declared In
NSDragging.h

draggingExited:

Invoked when the dragged image exits the destination’s bounds rectangle (in the case of a view object) or its frame rectangle (in the case of a window object).

- (void)draggingExited:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Availability
Declared In
NSDragging.h

draggingUpdated:

Invoked periodically as the image is held within the destination area, allowing modification of the dragging operation or mouse-pointer position.

- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Return Value

One (and only one) of the dragging operation constants described in “Constants” in the NSDraggingInfo reference. The default return value (if this method is not implemented by the destination) is the value returned by the previous draggingEntered: message.

Discussion

For this to be invoked, the destination must have registered for the pasteboard data type involved in the drag operation. The messages continue until the image is either released or dragged out of the window or view.

This method provides the destination with an opportunity to modify the dragging operation depending on the position of the mouse pointer inside of the destination view or window object. For example, you may have several graphics or areas of text contained within the same view and wish to tailor the dragging operation, or to ignore the drag event completely, depending upon which object is underneath the mouse pointer at the time when the user releases the dragged image and the performDragOperation: method is invoked.

You typically examine the contents of the pasteboard in the draggingEntered: method, where this examination is performed only once, rather than in the draggingUpdated: method, which is invoked multiple times.

Only one destination at a time receives a sequence of draggingUpdated: messages. If the mouse pointer is within the bounds of two overlapping views that are both valid destinations, the uppermost view receives these messages until the image is either released or dragged out.

Availability
See Also
Declared In
NSDragging.h

performDragOperation:

Invoked after the released image has been removed from the screen, signaling the receiver to import the pasteboard data.

- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Return Value

If the destination accepts the data, it returns YES; otherwise it returns NO. The default is to return NO.

Discussion

For this method to be invoked, the previous prepareForDragOperation: message must have returned YES. The destination should implement this method to do the real work of importing the pasteboard data represented by the image.

Availability
See Also
Declared In
NSDragging.h

prepareForDragOperation:

Invoked when the image is released, allowing the receiver to agree to or refuse drag operation.

- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender

Parameters
sender

The object sending the message; use it to get details about the dragging operation.

Return Value

YES if the receiver agrees to perform the drag operation and NO if not.

Discussion

This method is invoked only if the most recent draggingEntered: or draggingUpdated: message returned an acceptable drag-operation value.

Availability
See Also
Declared In
NSDragging.h

wantsPeriodicDraggingUpdates

Asks the destination object whether it wants to receive periodic draggingUpdated: messages.

- (BOOL)wantsPeriodicDraggingUpdates

Return Value

YES if the destination wants to receive periodic draggingUpdated: messages, NO otherwise.

Discussion

If the destination returns NO, these messages are sent only when the mouse moves or a modifier flag changes. Otherwise the destination gets the default behavior, where it receives periodic dragging-updated messages even if nothing changes.

Availability
Declared In
NSDragging.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.