Dragging Destinations

To receive drag operations, you must register the pasteboard types that your window or view will accept by sending the object a registerForDraggedTypes: message, defined in both NSWindow and NSView, and implement several methods from the NSDraggingDestination protocol. During a dragging session, a candidate destination receives NSDraggingDestination messages only if the destination is registered for a pasteboard type that matches the type of the pasteboard data being dragged. The destination receives these messages as an image enters, moves around inside, and then exits or is released within the destination’s boundaries.

Although NSDraggingDestination is declared as an informal protocol, the NSWindow and NSView subclasses you create to adopt the protocol need only implement those methods that are pertinent. (The NSWindow and NSView classes provide private implementations for all of the methods.) Either a window object or its delegate may implement these methods; however, the delegate’s implementation takes precedence if there are implementations in both places.

The Sender of Destination Messages

Each of the NSDraggingDestination methods sports a single argument: sender, the object that invoked the method. Within its implementations of the NSDraggingDestination methods, the destination can send NSDraggingInfo protocol messages to sender to get more information on the current dragging session, such as querying for the dragging pasteboard or the source’s operations mask. In Java, sender is an NSDragDestination object, which implements the NSDraggingInfo interface.

The Dragging Pasteboard

Although a standard dragging pasteboard (obtained using [NSPasteboard pasteboardWithName:NSDragPboard]) is provided as a convenience in getting the pasteboard for dragging data, there is NO guarantee that this will be the pasteboard used in a cross-process drag. Thus, to guarantee getting the correct pasteboard, your code should use [sender draggingPasteboard].

The Order of Destination Messages

The six NSDraggingDestination methods are invoked in a distinct order: