Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Drag and Drop Overview

Overview

Drag and drop in handled by the CP_DragDrop, CP_M_DragTarget and CP_M_DragSource classes in CPLAT, which are both mix-in classes.

CP_M_DragTarget provides methods to handle users dropping files.

CP_M_DragSource provides methods to handle supplying data when transferring information between CPLAT classes via drag and drop.

You can see drag and drop in operation by building and running the DragDrop demo in the demos folder.

Receiving Items

To enable one of your views to receive dropped items, you need to create the view with the view flag CPLAT::CP_E_ViewFlags_SupportsDragAndDrop set. This will install the event handlers to handle drag receive and tracking.

When the flag is set, and a user drops an item onto one of your view objects, the method OnDragReceive() will be called with the items that have been dropped. In order for a view to indicate that an item is acceptable, it needs to override the OnCanAcceptDrag() method, and return true if the item is acceptable.

OnDragReceive() will pass in a CP_DragDrop object that contains a CP_DataStream object for the dropped item. The CP_DataStream in turn contains a list of CP_DataStreamItems, one for each of the dropped items in the drag and drop. The CP_DataStreamItem then contains the type of flavor and data for each individual flavor in the dropped item.

Some items may contain only a single item flavor, while others may contain multiple item flavors.

Items Sending Items

To supply data for a drag and drop, you need to handle a clicked event in your view, and create a CP_DragDrop object that will handle the drag and drop. If you have created the view with the view flag CPLAT::CP_E_ViewFlags_SupportsDragAndDrop set, then your view has CP_M_DragSource methods, such as AddFlavor, and TrackDrag which you see used below.

        DragSourceView::HandleControlHitEvent( CPLAT::CP_Event_Base& inEvent )
        {
            CPLAT::CP_DragDrop              dragDrop;

            AddFlavor( dragDrop, kFlavorTypeColor, &swatchColor, sizeof(swatchColor) );

            TrackDrag( dragDrop, inEvent );
        }

The AddFlavor call is the method you use to supply data for the drag source item.


Generated on Sat Sep 17 20:02:36 2005 for CPLAT by  doxygen 1.4.0