Creating a drop acceptor

To enable a Tiles document to be a drop acceptor for color items, you need to mix the class MDropAcceptor into TTilesView class. MDropAcceptor defines two important functions that your view class must override to define how it will handle dropped items:

NOTE MDropAcceptor also defines functions you can override if you want to provide specific visual feedback to the user to identify whether the drop acceptor can accept a particular item. For example, you might want to highlight the border of the view or change the color of an icon when the user drags an acceptable item over it. DragItemEntered, DragItemMoved, and DragItemExited are called by the Drag and Drop framework when the user drags the item into, around, and out of the view. If you don't override these, no explicit feedback is provided.

This figure shows the MDropAcceptor functions you need to override in TTilesView:


The Drag and Drop framework calls ChoosePreferredType when the user drops an item, passing it the list of data types in which the drag and drop item can issue the encapsulated data. ChoosePreferredType should iterate through the list until it finds its preferred data type, or, if the preferred type isn't in the list, any type that it can accept. The TTilesView class currently accepts only the type TColor, so it iterates through the list until it finds a TColor, and returns that as the chosen type. Types are represented using the class TTypeDescription, a simple class that encapsulates a single type (a TType object). If ChoosePreferredType cannot find an acceptable type, it should return False.

If ChoosePreferredType returns True, then the target can accept the item and the Drag and Drop framework calls AcceptDrop to complete the interaction. The AcceptDrop function is where you implement what you want the drop acceptor to do with the dropped item. For the TTilesView class, AcceptDrop does the following:

  1. Determines what tile, if any, the item was dropped on.
  2. If the drop was on a tile, it creates a selection on that tile. It also creates a TChangeColorCommand using the color encapsulated by the drop item, and issues the command against the selected tile.
  3. Returns True to indicate that the drop was completed successfully.
You could also add code to this function that would enable the user to drop a color anywhere in the window to change the color of the view background.


[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