ON DRAG_ENTER block

When the ON DROP control block is defined, the ON DRAG_ENTER block will be executed when the mouse cursor enters the visual boundaries of the drop target dialog. Entering the target dialog is accepted by default if no ON DRAG_ENTER block is defined. However, when ON DROP is defined, you should also define ON DRAG_ENTER to deny the drop of objects with an unsupported MIME type that come from other applications.

The program can decide to deny or allow a specific drop operation with a call to ui.DragDrop.setOperation(); passing a NULL to the method will deny drop.

To check what MIME type is available in the drag & drop buffer, the program uses the ui.DragDrop.selectMimeType() method. This method takes the MIME type as a parameter and returns TRUE if the passed MIME type is used. You can call this method several times to check the availability of different MIME types.

You may also define the visual effect when flying over the target list with ui.DragDrop.setFeedback().

DEFINE dnd ui.DragDrop 
...
DISPLAY ARRAY arr TO sr.* ...
  ...
  ON DRAG_ENTER (dnd)
    IF dnd.selectMimeType("text/plain") THEN
      CALL dnd.setOperation("copy")
      CALL dnd.setFeedback("all")
    ELSE
      CALL dnd.setOperation(NULL)
    END IF
  ON DROP (dnd)
    ...
END DISPLAY

Once the mouse has entered the target area, subsequent mouse cursor moves can be detected with the ON DRAG_OVER trigger.

When using a table or tree-view as drop target, you can control the visual effect when the mouse flies over the rows, according to the type of drag & drop you want to achieve.

Basically, a dragged object can be:

  1. Inserted in between two rows (visual effect must show where the object will be inserted)
  2. Copied/merged to the current row (visual effect must show the row under the mouse)
  3. Dropped somewhere on the target widget (the exact location inside the widget does not matter)

The visual effect can be defined with the ui.DragDrop.setFeedback() method, typically called in the ON DRAG_ENTER block.

The values to pass to the setFeedback() method to get the desired visual effects described are respectively:

  1. insert (default)
  2. select
  3. all
DEFINE dnd ui.DragDrop 
...
DISPLAY ARRAY arr TO sr.* ...
  ...
  ON DRAG_ENTER (dnd)
    IF canDrop() THEN
      CALL dnd.setOperation(NULL)
    ELSE
      CALL dnd.setFeedback("select")
    END IF
    ...
END DISPLAY