NSDraggingSession Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.7 and later. |
| Declared in | NSDragging.h NSDraggingSession.h |
Overview
The NSDraggingSession class encompases a drag and drop action and allows modification of the drag while in progress.
You start a new dragging session by calling the NSView method beginDraggingSessionWithItems:event:source: method. This method immediately returns and you can further modify the properties of the dragging session. The actual drag begins at the next turn of the run loop.
Tasks
Dragging Pasteboard
-
draggingPasteboardproperty
Dragging Visual Representation
-
animatesToStartingPositionsOnCancelOrFailproperty -
draggingFormationproperty
Identifying the Dragging Session
-
draggingSequenceNumberproperty
Enumerating Dragging Items
Dragging Session Location
-
draggingLocationproperty
Dragging Item Location
-
draggingLeaderIndexproperty
Properties
animatesToStartingPositionsOnCancelOrFail
Controls whether the dragging image animates back to its starting point on a cancelled or failed drag.
Discussion
This property should be set immediately after creating the dragging session.
The default value is YES.
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hdraggingFormation
Controls the dragging formation when the drag is not over the source or a valid destination.
Discussion
Setting this value causes the dragging formation to change immediately, provided a valid destination has not overriden the behavior. If the dragging session hasn't started yet, the dragging items will animate into formation immediately upon start. It is highly recommended to never change the formation when starting a drag.
The default value is NSDraggingFormationNone.
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hdraggingLeaderIndex
The index of the dragging item under the cursor.
Discussion
The index is to an element in the array passed as the first parameter to the NSView method beginDraggingSessionWithItems:event:source:.
The default is the NSDraggingItem closest to the location field in the event parameter that was passed to the beginDraggingSessionWithItems:event:source: method.
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hdraggingLocation
The current cursor location of the drag in screen coordinates. (read-only)
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hdraggingPasteboard
Returns the pasteboard object that contains the data being dragged. (read-only)
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hdraggingSequenceNumber
Returns a number that uniquely identifies the dragging session. (read-only)
Availability
- Available in OS X v10.7 and later.
Declared In
NSDraggingSession.hInstance Methods
enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock:
Enumerates through each dragging item.
Parameters
- enumOpts
The enumeration options. See “NSDraggingItemEnumerationOptions” for the supported values.
- view
The view used as the base coordinate system for the
NSDraggingIteminstances.- classArray
An array of class objects.
The classes should appear in the array in the order the preferred order of representation. Classes in the array must conform to the
NSPasteboardReadingProtocol Reference.- searchOptions
A dictionary that specifies options to refine the search for pasteboard items, for example to restrict the search to file URLs with particular content types. For valid dictionary keys, see
Pasteboard_Reading_Options.- block
The block executed for the enumeration.
The block takes three arguments:
- draggingItem
A reference to the dragging item. The
draggingFrameof the dragging item is in the coordinate space of the view specified in by view. A view value ofnilmeans the screen coordinate space.Note: The draggingItem object is only valid for this iteration of the enumeration block. Never store this draggingItem or try to change it outside of Block iteration. It is very easy to reference draggingItem inside an
imageComponentsProviderblock. This is bad for two reasons: by the time theimageComponentsProviderBlock is called, the enumeration Block is out of scope and the draggingItem is no longer valid and it creates a retain cycledraggingItemretainsimageComponentsProviderwhich retainsdraggingItemcausing a memory leak. Instead, assigndraggingItem.itemto an object pointer outside of theimageComponentsProviderBlock definition and use the object pointer inside theimageComponentsProviderblock definition.- idx
The index of the element in the classes.
- stop
A reference to a Boolean value that the block can use to stop the enumeration by setting *stop to
YES; it should not touch *stop otherwise.
Discussion
Classes in the provided array must implement the NSPasteboardReading protocol. Cocoa classes that implement this protocol include NSImage, NSString, NSURL, NSColor, NSAttributedString, and NSPasteboardItem. For every item on the pasteboard, each class in the provided array will be queried for the types it can read using readableTypesForPasteboard:. An instance is created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. Any instances that could be created from pasteboard item data is returned to the caller. Additional options, such as restricting the search to file URLs with particular content types, can be specified with the options dictionary. Only objects of the requested classes are returned. You can always ensure to receive one object per item on the pasteboard by including the NSPasteboardItem class in the array of classes.
This method enumerates the items on the dragging pasteboard associated with this dragging info, as well as all the additional data the dragging info knows about. The pasteboard data and the additional data is represented as one logical unit, an NSDraggingItem instance.
For every item on the pasteboard, each class in classArray will be queried for the types it can read using readableTypesForPasteboard:. An instance will be created of the first class found in the provided array whose readable types match a conforming type contained in that pasteboard item. If an instance is created from the pasteboard item data, it is placed into an NSDraggingItem along with the dragging properties of that item such as the dragging image. The NSDraggingItem instance is then passed as a parameter to the provided block.
Availability
- Available in OS X v10.7 and later.
See Also
-
– readObjectsForClasses:options:(NSPasteboard Class)
Declared In
NSDraggingSession.hConstants
Dragging Enumeration Options
The following constants specify the enumeration options used in the enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock: method.
enum {
NSDraggingItemEnumerationConcurrent = NSEnumerationConcurrent,
NSDraggingItemEnumerationClearNonenumeratedImages = (1UL << 16),
};
typedef NSUInteger NSDraggingItemEnumerationOptions;
Constants
NSDraggingItemEnumerationConcurrentSpecifies that the Block enumeration should be concurrent.
The order of invocation is nondeterministic and undefined; this flag is a hint and may be ignored by the implementation under some circumstances; the code of the Block must be safe against concurrent invocation.
Available in OS X v10.7 and later.
Declared in
NSDragging.h.NSDraggingItemEnumerationClearNonenumeratedImagesWhen the following option is set, the Application Kit will automatically set the
imageComponentProvidertonilfor all dragging items that do not meet theclasses/searchOptionscriteria of the method. Effectively, this hides the drag image for invalid items for this destination.Available in OS X v10.7 and later.
Declared in
NSDragging.h.
© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-06-06)