Mac Developer Library

Developer

AppKit Framework Reference NSDraggingSource Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSDraggingSource

The NSDraggingSource protocol declares methods that are implemented by the source object in a dragging session. More...

Inheritance


Not Applicable

Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.7 and later.
  • Declares the types of operations the source allows to be performed. (required)

    Declaration

    Swift

    func draggingSession(_ session: NSDraggingSession, sourceOperationMaskForDraggingContext context: NSDraggingContext) -> NSDragOperation

    Objective-C

    - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context

    Parameters

    session

    The dragging session.

    context

    The dragging context. See NSDraggingContext for the supported values.

    Return Value

    The appropriate dragging operation as defined in

    Discussion

    In the future Apple may provide more specific "within" values in the future. To account for this, for unrecognized localities, return the operation mask for the most specific context that you are concerned with. The following code is an example of how to implement this functionality:

    • switch(context) {
    • case NSDraggingContextOutsideApplication:
    • return ...
    • break;
    • case NSDraggingContextWithinApplication:
    • default:
    • return ...
    • break;
    • }

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an integer bit mask indicating the types of dragging operations the source object will allow to be performed on the dragged image's data.

    Deprecation Statement

    This method is informally deprecated. It is only called if the source does not implement the NSDraggingSource protocol methods. This method will be formally deprecated in a future OS release.

    Declaration

    Objective-C

    - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal

    Parameters

    isLocal

    YEStrue indicates that the candidate destination object (the window or view over which the dragged image is currently poised) is in the same application as the source, while a NOfalse value indicates that the destination object is in a different application.

    Return Value

    A mask, created by combining the dragging operations listed in the NSDragOperation section of NSDraggingInfo protocol reference using the C bitwise OR operator.If the source does not permit any dragging operations, it should return NSDragOperationNone.

    Discussion

    If not implemented, the default value is NSDragOperationCopy | NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Returns the names of the files that the receiver promises to create at a specified location.

    Declaration

    Swift

    func namesOfPromisedFilesDroppedAtDestination(_ dropDestination: NSURL) -> [AnyObject]?

    Objective-C

    - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination

    Parameters

    dropDestination

    A URL object that identifies the location at which the promised files will be created.

    Return Value

    An array of the names of files (not full paths) that the receiver promises to create at dropDestination.

    Discussion

    This method is invoked when the drop has been accepted by the destination and the destination, in the case of another Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination:. For long operations, you can cache dropDestination and defer the creation of the files until the draggedImage:endedAt:operation: method to avoid blocking the destination application.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.2 and later.

    Deprecated in OS X v10.7.

  • Sets whether the use of modifier keys should have an effect on the type of operation performed.

    Deprecation Statement

    This method is informally deprecated. It is only called if the source does not implement the NSDraggingSource protocol methods. This method will be formally deprecated in a future OS release.

    Declaration

    Objective-C

    - (BOOL)ignoreModifierKeysWhileDragging

    Return Value

    Return NOfalse, if the user can tailor the drag operation by holding down a modifier key during the drag.

    Discussion

    If this method is not implemented the default behavior is equivalent to returning NOfalse

    The dragging option that corresponds to the modifier key is combined with the source’s mask (as set with the draggingSourceOperationMaskForLocal: method) using the C bitwise OR operator. See the description for the draggingSourceOperationMask method in the NSDraggingInfo protocol specification for more information about dragging masks and modifier keys.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Gives the source object an opportunity to respond to the initiation of a dragging session.

    Deprecation Statement

    This method is informally deprecated. It is only called if the source does not implement the NSDraggingSource protocol methods. This method will be formally deprecated in a future OS release.

    Declaration

    Objective-C

    - (void)draggedImage:(NSImage *)anImage beganAt:(NSPoint)aPoint

    Parameters

    anImage

    The image of the dragged item.

    aPoint

    The origin of the image in screen coordinates.

    Discussion

    This method is invoked when anImage is displayed but before it starts following the mouse. For example, you might choose to have the source give a visual indication to the user that data is being dragged from the source.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Informs the dragging source when a dragged image moves to a new screen coordinate.

    Deprecation Statement

    This method is informally deprecated. It is only called if the source does not implement the NSDraggingSource protocol methods. This method will be formally deprecated in a future OS release.

    Declaration

    Objective-C

    - (void)draggedImage:(NSImage *)draggedImage movedTo:(NSPoint)screenPoint

    Parameters

    draggedImage

    The dragged image.

    screenPoint

    The point specifying the new location of the image in screen coordinates.

    Discussion

    This message is similar to the dragging destination being sent draggingUpdated: messages.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Invoked after the dragging destination has been given a chance to operate on the data represented by the image. (required)

    Deprecation Statement

    Use draggedImage:endedAt:operation: instead.

    Declaration

    Objective-C

    - (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint deposited:(BOOL)flag

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.1.

  • Invoked after the dragging destination has been given a chance to operate on the data represented by the image.

    Deprecation Statement

    This method is informally deprecated. It is only called if the source does not implement the NSDraggingSource protocol methods. This method will be formally deprecated in a future OS release.

    Declaration

    Objective-C

    - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation

    Parameters

    anImage

    The dragged image.

    aPoint

    The point locating the image’s origin in the screen coordinate system when it was released.

    operation

    An integer constant that indicates the operation performed by the destination.

    Discussion

    This method is invoked after the dragged image (anImage) has been released and the dragging destination has been given a chance to operate on the data it represents. This method provides the source object with an opportunity to respond to either a successful or a failed dragging session. For example, if you are moving data from one location to another, you could use this method to make the source data disappear from its previous location, if the dragging session is successful, or reset itself to its previous state, in the event of a failure.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.