Search
Drag and Drop

Each process that requires OLE drag-and-drop functionality must initialize OLE libraries via the OleInitialize API function. That is done implicitly in Visual Basic applications, but if your software is developed in other language (e.g. Delphi or C++) you might have to call OleInitialize explicitly. In order to receive drag and drop notifications, FlowChartX has to be registered with OLE through the RegisterDragDrop method. Once registered, the control can work in three modes, varying in level of complexity and control provided. The current mode is set through DragDropMode property. Detailed description of each mode follows:

drAutoAccept

Any text data that is dropped into a box, a table caption or a table cell, is automatically accepted and the respective object properties are set to the dropped text. In similar manner dropping an image over a box or a table automatically sets the object Picture property to that image. Additionally, dropping an image into an empty area sets the background image of FlowChartX.

Diagram elements can be dragged between two FlowChartX instances when the ExtrnDragDrop property is set to true. In drAutoAccept mode any dragged objects are automatically copied if dropped into an empty document area. If you want the object to be moved instead, then you should use one of the programmatic drag-and-drop modes and set the drop-effect flag as appropriate (DROPEFFECT_COPY / vbDropEffectMove).

One of the following events can be raised in drAutoAccept mode, depending on the drop destination: DropAcceptedByBox, DropAcceptedByTable, DropAcceptedByTableCell, DropAccepted. These events have as parameters the type of data dropped, and a reference to the object that received the data.

drRequestAccept

Here, as in the first mode, tables and boxes accept textual and graphic data, setting accordingly their properties. However validation events are raised while the drag occurs, through which drop operation can be rejected. Appropriate visual feedback is given to the user, depending on the result set through an event handler. The validation events that may be raised are RequestDropInBox, RequestDropInTable and RequestDrop, depending on the type of object under the mouse cursor. If the operation is validated and the user drops the dragged data, the same events as in drAutoAccept mode are raised.

drProgrControl

In this mode the entire responsibility on interpreting the dragged data and the results of dropping it is left to your program. Two sets of events can be raised. While dragging some data over the flowchart area the DragOverDoc, DragOverBox and DragOverTable are raised, depending on the object under the mouse cursor. They have as arguments the OLE IDataObject interface pointer, through which the dragged data can be queried and retrieved. In addition the mouse position in document coordinates is passed along with a key-state parameter and an output effect parameter.

Through the effect parameter you can validate the drop operation and give OLE clue on its outcome, and thus the kind of visual feedback that should be displayed to the user. If the drop effect is set to DROPEFFECT_NONE / vbDropEffectNone, then the operation is rejected and the user is prohibited from dropping. If the operation is confirmed, by setting the drop effect to copy or move, and the dragged data is dropped, then one of the following events will be raised: DropInBox, DropInTable and DropInDoc. They receive the same parameters as their Drag* counterparts. When working in this mode you could use ObjectFromPoint method to find out if there's an object under the mouse cursor.

The CreateObjsFromDragData method can be used in this mode to create diagram objects if the drag-and-drop operation is performed between two flowchart instances.

drProgrControVB

The only difference with the above mode is that events raised from this mode receive a IVBDataObject parameter. This interface is automation-compatible and can be used with Visual Basic. The events raised in this mode are DragOverDocVB, DragOverBoxVB, DragOverTableVB, DropInBoxVB, DropInTableVB and DropInDocVB.

Start dragging from table cells

The TableCellStartDrag event gives you a chance to start OLE drag-and-drop operation from a cell. That event is raised only if the respective bit in EventFlags is enabled.

Internal drag-and-drop

Independently of the OLE drag and drop events, FlowChartX supports its own internal drag and drop functionality. If a user drops diagram items over other items, an ObjectDroppedInBox or ObjectDroppedInTable event will be raised. The events get as parameter the type of dropped data - box, table or selection. Additionally if DragDropMode is set to drRequestAccept, the appropriate validation events will be raised.

Drag-and-drop feedback

When drag-and-drop operation is performed and the mouse is dragged over a box, if this box can accept the dragged data this can be indicated to the user by drawing feedback frame around the box. Use the FeedbackOnDragOver property to enable this feature. The color of the frame is specified using FeedbackColor. Style of the pen for drawing the feedback frame is defined by FeedbackPenStyle and FeedbackPenWidth properties.

Cleanup

At the end of execution of your software, if FlowChartX has been registered for OLE drag and drop notifications through RegisterDragDrop method, it should be unregistered using RevokeDragDrop.

If you intend to enable drag-and-drop between FlowChartX and other controls in a single form, we recommend that FlowChartX is instantiated windowed.