Creating a drag source

To drag an item from a view, your view class must mix in MMouseEventHandler and override the MouseDown function to do the following:

  1. Determine where the mouse-down event occurred and whether it is on a draggable entity. If it is on a draggable entity:
  2. Create a TDragAndDropItem object encapsulating the draggable entity.
  3. Create an MGraphic representing the drag appearance.
  4. Create and start a drag and drop interactor, passing it the drag and drop item, the drag appearance, and a handle to the view object. The Drag and Drop framework handles the interaction after the interactor is started.
In Step 6, the TTilesView MouseDown function was implemented to launch a TMoveInteractor whenever the user clicked on a tile. In this step, the MouseDown function first checks to see if the user is also holding down the Shift key. If the Shift key isn't pressed, the TMoveInteractor is created just as in Step 6. If the Shift key is pressed, MouseDown initiates a drag and drop interaction as follows:

  1. Determines whether the mouse-down event occurred on a tile or in the background of the view. If the user clicked on a tile:
  2. Gets the color of that tile.
  3. Creates a rectangle of that color to use as the drag appearance.
  4. Creates a scrap item containing the color of the tile, using the class template TScrapItemOn<TColor>.
  5. Creates a drag and drop item containing the color scrap item, using the class TGeneralDragAndDropItem. This is also an enabler class that can hold scrap items of any type.
  6. Creates a drag and drop interactor, TMouseDragAndDropInteractor, passing it the drag appearance, the drag and drop item, and a view handle.
  7. Starts the interactor.
The Drag and Drop framework is responsible for the interaction after this point. The framework destroys the interactor and the drag and drop item when the user drops the item.

You can now create a Tiles document and see the new functionality by compiling the project in the directory $TaligentRoot/TaligentSamples/Supported/Apps/TilesTutorial/08.DragAndDrop/Tiles and then calling TilesTutorialApp from the $TaligentSharedLibs directory. Make sure that a previous version of a Tiles document is not running when you compile the project. If you want to drag and drop colors between a Tiles document and ColorChooser, launch the ColorChooser application by going to the $TaligentSharedLibs directory and typing ColorChooser.

For another example, see the online directory
$TaligentRoot/TaligentSamples/Supported/Examples/DragAndDrop/01.BasicDragAndDrop. This directory contains examples of both a drag source and a drop acceptor.


[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