Summary:
See also: Classes and Objects, Drag & Drop.
The DragDrop class is used to control the events related to Drag & Drop.
ui.DragDrop
Object Methods | |
Name | Description |
addPossibleOperation( optype STRING ) |
Adds a Drag & Drop operation that is allowed. |
dropInternal() |
Performs built-in drop when the target is the source list or tree. |
getBuffer() |
Returns Drag & Drop data as selected by the hasMimeType() method. |
getLocationParent() |
Returns the parent node index of the child node the mouse is pointing to during Drag & Drop. |
getLocationRow() |
Returns the index of the row the mouse is pointing to during Drag & Drop. |
getOperation() |
Returns the current type of Drag & Drop operation or NULL if denied. |
getSelectedMimeType() |
Returns the previously selected MIME type. |
selectMimeType( mimetype STRING ) |
Selects the given MIME type if such a record is available in the Drag & Drop buffer. |
setFeedback( feedback STRING ) |
Defines the appearance of the target during Drag & Drop. |
setMimeType( mimetype STRING ) |
Defines the MIME type of the dragged object. |
setBuffer( data STRING ) |
Copies the text data of the dragged object into the Drag & Drop buffer. |
setOperation( optype STRING ) |
Defines the type of Drag & Drop operation or denies Drag & Drop. |
When implementing Drag & Drop in a dialog, the ON DRAG* / ON DROP dialog control blocks take a ui.DragDrop variable as a parameter to let you configure and control the Drag & Drop procedure. The ui.DragDrop variable must be declared in the scope of the dialog implementing Drag & Drop.
In the next example, the code defines a ui.DragDrop variable named dnd, and implements an ON DRAG_ENTER block taking dnd as the argument:
01
DEFINE dnd ui.DragDrop02
...03
DISPLAY ARRAY arr TO sr.* ...04
...05
ON DRAG_ENTER(dnd)06
IF ok_to_drop THEN07
CALL dnd.setOperation("move")08
ELSE09
CALL dnd.setOperation(NULL)10
END IF11
...12
END DISPLAY
Drag & Drop actions can be of different kinds; you can do a copy of the dragged object, or move the dragged object from the source to the destination. The default Drag & Drop operation is defined by a call to setOperation() in ON DRAG_START, you can then use the addPossibleOperation()
method to define additional operations that are allowed.
See setOperation() for possible values.
The getLocationRow()
method returns the index of the row in the drop target list pointed to by the mouse cursor. This method is typically used in the ON DROP block to get the index of the target row to be modified or replaced by the dragged object. The method can also be used in ON DRAG_OVER to deny the drop according to the current target row returned by getLocationRow()
.
When using a TreeView, a node can be dropped as a sibling or as a child node to another node. In order to distinguish between the cases, you must use the getLocationParent()
method, which returns the index of the parent node of the drop target node returned by getLocationRow(). If both methods return the same row index, you must append the dropped row as a child of the target node. Otherwise, getLocationParent()
identifies the parent node where the dropped row has to be added as a child, and getLocationRow()
is the index of a sibling node. In the last case the dropped node must be inserted before the node identified by getLocationRow()
. These methods are typically used in the ON DROP block, but can also be used in ON DRAG_OVER to deny the drop according to the indexes returned; for example, the program might only allow the drop of objects as new children for a given parent node.
The getOperation()
method returns the type of the current Drag & Drop operation (i.e. copy, move, none). According to the value returned by this method, the program can make the appropriate changes in the data model. For example, after a row has been dropped into another list, the source list can remove the original row if the operation was a "move", but keeps the original row if the operation was a "copy". The getOperation()
method is typically called in the ON DRAG_FINISHED block.
Use the setOperation()
method to define/force the type of Drag & Drop operation or to deny/cancel the Drag & Drop process.
setOperation() parameter | Description |
---|---|
NULL |
To deny/cancel the Drag & Drop process. |
copy |
To allow Drag & Drop as a copy of the source object. |
move |
To allow Drag & Drop as a move of the source object. |
The setOperation()
method can be called in different Drag & Drop triggers. The most common usage is to deny Drag & Drop by passing NULL in the ON DRAG_ENTER and/or ON DRAG_OVER blocks because the dragged object does not correspond to the type of objects the target can receive. It is also typically used in ON DRAG_START to force a specific type of Drag & Drop operation (copy or move), or to deny drag start if the context does not allow a Drag & Drop action. When called in the ON DRAG_ENTER block, the method forces a specific Drag & Drop operation.
See also addPossibleOperation().
The setFeedback()
method defines the appearance the target object must have during the Drag & Drop action. For example, in a table or treeview, when the mouse is flying over rows in the drop target, a different visual indicator will appear according to the value that was passed to setFeedback()
.
Possible values for the setFeedback()
method are:
setFeedback() parameter | Description |
---|---|
all |
Dragged object will be dropped somewhere on the target widget, the exact location does not matter. |
insert |
In lists, dragged object will be inserted in between existing rows. |
select |
In lists, dragged object will replace the current row under the mouse. |
Call the selectMimeType()
method to check that data is available in a format identified by the MIME type passed as parameter. If this type of data is available in the buffer, the method returns TRUE and you can later get the data with getBuffer()
.
The selectMimeType()
method is typically used in ON DRAG_ENTER, ON DRAG_OVER to deny the Drag & Drop operation if none of the supported MIME types is available in the buffer.
Before retrieving data from the Drag & Drop buffer with getBuffer(), you must first call the getSelectedMimeType()
method to identify the data format that was previously selected by a selectMimeType() call.
The getSelectedMimeType()
method is typically called in ON DROP to identity the format of the dropped object.
Once the MIME type of the dropped object was identified with getSelectedMimeType(), you can call the getBuffer()
method to get text data from the Drag & Drop buffer.
Drag & Drop data is only available at ON DROP time, thus the getBuffer()
method must be called in ON DROP only.
Objects dragged from a BDL application to an external application need to be identified with a MIME type and the program must provide the data. The MIME type can be specified with the setMimeType()
method.
The setMimeType()
method is typically used in an ON DRAG_START block in conjunction with setBuffer().
By default the source target will use the text/plain MIME type and copy the data of the selected rows into the Drag & Drop buffer.
In order to provide the text data of objects dragged from a BDL application to an external application, you must use the setBuffer()
method.
The setBuffer()
method is typically used in an ON DRAG_START block in conjunction with setMimeType().
By default, the dialog will serialize the data of the selected rows as a tab-separated list of values (text/plain MIME type is the default).
In order to simplify Drag & Drop programming in the same list, the ui.DragDrop
class provides the dropInternal()
utility method, to be called in the ON DROP block. This method will perform all the row changes in the array and move row selection as well as cell attributes.
When implementing Drag & Drop on a tree-view, dropping an element on the tree requires complex code in order to handle parent-child relationships. Nodes can be inserted under a parent between two children, appended at the end of the children list, and at different levels in the tree hierarchy. However, the dropInternal() method can also be used when the decoration is a regular table.
Note that a call to dropInternal() will silently be ignored, if the drag source is not the drop target, or if the method is called in a different context as ON DROP.
For more details about dropping elements in tree-views, see the usage of ON DROP in the Drag & Drop page.