How drag and drop items are transported

To determine what you need to do to implement a drag source or a drop acceptor, you need to understand how drag and drop items are encapsulated and how the Drag and Drop framework handles the drag and drop interaction.

When the user selects an item to drag from a drag source, the drag source encapsulates the item in a TDragAndDropItem object and passes it to a drag and drop interactor, along with an MGraphic that defines what the item looks like as it is dragged.

A TDragAndDropItem object conceptually represents a collection of items, or TScrapItem instances, where each scrap item describes one possible representation of the data being dragged. This mechanism is necessary because an item might require different representations depending on what operation is performed on it. For example, a document needs to be dropped into a folder as a document, onto a spell checker as a stream of text, and onto a printer as a paginated graphical presentation. Because you don't know which operation will be performed until the item is actually dropped, the drag and drop item needs to be able to produce the data in all its possible representations.

TDragAndDropItem is, therefore, the class used to encapsulate a draggable entity; TScrapItem is the class used to encapsulate a specific representation of the data in that entity:


NOTE TDragAndDropItem and TScrapItem are abstract classes. You derive concrete classes to represent specific families or types of draggable items. You can also use the enabler class TScrapItemOn<AType> used in the Documented Samples. This template class builds a scrap item to hold any data representation you specify. For source code for this class, see the online directory
$TaligentRoot/TaligentSamples/Supported/Enablers/ScrapItem. TDragAndDropInteractor is also abstract; derived classes support specific pointing devices a user might use for a drag and drop interaction. The Drag and Drop framework provides the class TMouseDragAndDropInteractor for dragging and dropping items with a mouse.

When the user drops the drag and drop item on a potential destination, the TDragAndDropItem publishes a list of all the possible representations (or data types) of the encapsulated data and the interactor passes it to the drop acceptor. The drop acceptor chooses a preferred type from this list, and the interactor drops a TScrapItem containing that type of data. If the drop acceptor cannot accept any of the possible data types, the interaction ends.

Classes derived from TDragAndDropItem and TScrapItem also have to define how the actual data is transported. Generally, you don't want to physically carry all the data for each scrap item in the drag and drop item because only one representation will be required to complete the interaction (or none, if the user doesn't drop the item on a drop acceptor). Scrap item classes should be able to access the data and assemble the correct representation when they are actually dropped on the appropriate destination instead of when the drag and drop item is constructed.

For more information on the TDragAndDropItem and TScrapItem classes, see the section "Drag and Drop Framework" in Chapter 5, "GUI Application framework concepts," in Desktop Framework Concepts, and the online class and member function descriptions.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker