4D v13.4

DRAG AND DROP PROPERTIES

Home

 
4D v13.4
DRAG AND DROP PROPERTIES

DRAG AND DROP PROPERTIES 


 

DRAG AND DROP PROPERTIES ( srcObject ; srcElement ; srcProcess ) 
Parameter Type   Description
srcObject  Pointer in Pointer to drag-and-drop source object
srcElement  Longint in Dragged array element number, or Dragged list box row number, or Dragged hierarchical list item, or -1 if source object is neither an array nor a list box nor a hierarchical list
srcProcess  Longint in Source process number

Compatibility note: Since version 11 of 4D, it is recommended to manage drag and drop operations, especially interprocess ones, using the On Begin Drag Over event and the commands of the Pasteboard theme.

The DRAG AND DROP PROPERTIES command enables you to obtain information about the source object when an On Drag Over or On Drop event occurs for a “complex” object (array, list box or hierarchical list).

Typically, you use DRAG AND DROP PROPERTIES from within the object method of the object (or from one of the subroutines it calls) for which the On Drag Over or On Drop event occurs (the destination object).

Important: A form object accepts dropped data if its Droppable property has been selected. Also, its object method must be activated for On Drag Over and/or On Drop, in order to process these events.

After the call:

  • The srcObject parameter is a pointer to the source object (the object that has been dragged and dropped). Note that this object can be the destination object (the object for which the On Drag Over or On Drop event occurs) or a different object. Dragging and dropping data from and to the same object is useful for arrays and hierarchical lists—it is a simple way of allowing the user to sort an array or a list manually.
  • If the dragged and dropped data is an array element (the source object being an array), the srcElement parameter returns the number of this element. If the dragged and dropped data is a list box row, the srcElement parameter returns the number of this row. If the drag and dropped data is a list item (the source object being a hierarchical list), the srcElement parameter returns the position of this item. Otherwise, if the source object does not belong to any of these categories, srcElement is equal to -1.
  • Drag and drop operations can occur between processes. The srcProcess parameter is equal to the number process to which the source object belongs. It is important to test the value of this parameter. You can respond to a drag and drop within the same process by simply copying the source data to the destination object. On the other hand, when treating an interprocess drag and drop, you will use the GET PROCESS VARIABLE command to get the source data from the source process object instance. You will usually implement drag and drop in the user interface from source variables (i.e., arrays and lists) toward data entry areas (fields or variables).

If you call DRAG AND DROP PROPERTIES when there is no drag and drop event, srcObject returns a NIL pointer, srcElement returns -1 and srcProcess returns 0.

Tip: 4D automatically handles the graphical aspect of a drag and drop. You must then respond to the event in the appropriate way. In the following examples, the response is to copy the data that has been dragged. Alternatively, you can implement sophisticated user interfaces where, for example, dragging and dropping an array element from a floating window will fill in the destination window (the window where the destination object is located) with structured data (i.e., several fields coming from a record uniquely identified by the source array element).

You use DRAG AND DROP PROPERTIES during an On Drag Over event in order to decide whether the destination object accepts the drag and drop operation, depending on the type and/or the nature of the source object (or any other reason). If you accept the drag and drop, the object method must return $0:=0. If you do not accept the drag and drop, the object method must return $0:=-1. Accepting or refusing the drag and drop is reflected on the screen—the object is or is not highlighted as the potential destination of the drag-and-drop operation.

In several of your database forms, there are scrollable areas in which you want to manually reorder the elements by simple drag and drop from one part of the scrollable area into another within it. Rather than writing specific code for each case, you may implement a generic project method that will handle any one of these scrollable areas. You could write something like:

  ` Handle self array drag and drop project method
  ` Handle self array drag and drop ( Pointer ) -> Boolean
  ` Handle self array drag and drop ( -> Array ) -> Is a self array drag and drop
 
 Case of
    :(Form event=On Drag Over)
       DRAG AND DROP PROPERTIES($vpSrcObj;$vlSrcElem;$vlPID)
       If($vpSrcObj=$1)
  ` Accept the drag and drop if it is from the array to itself
          $0:=0
       Else
          $0:=-1
       End if
    :(Form event=On Drop)
  ` Get the information about the drag and drop source object
       DRAG AND DROP PROPERTIES($vpSrcObj;$vlSrcElem;$vlPID)
  ` Get the destination element number
       $vlDstElem:=Drop position
  ` If the element was not dropped over itself
       If($vlDstElem #$vlSrcElem)
  ` Save dragged element in element 0 of the array
          $1->{0}:=$1->{$vlSrcElem}
  ` Delete the dragged element
          DELETE FROM ARRAY($1->;$vlSrcElem)
  ` If the destination element was beyond the dragged element
          If($vlDstElem>$vlSrcElem)
  ` Decrement the destination element number
             $vlDstElem:=$vlDstElem-1
          End if
  ` If the drag and drop occurred beyond the last element
          If($vlDstElem=-1)
  ` Set the destination element number to a new element at the end of the array
             $vlDstElem:=Size of array($1->)+1
          End if
  ` Insert this new element
          INSERT IN ARRAY($1->;$vlDstElem)
  ` Set its value which was previously saved in the element zero of the array
          $1->{$vlDstElem}:=$1->{0}
  ` The element becomes the new selected element of the array
          $1->:=$vlDstElem
       End if
 End case

Once you have implemented this project method, you can use it in the following way:

  ` anArray Scrollable Area Object Method
 
 Case of
  `...
    :(Form event=On Drag Over)
       $0:=Handle self array drag and drop(Self)
    :(Form event=On Drop)
       Handle self array drag and drop(Self)
  ` ...
 End case

In several of your database forms, you have text enterable areas in which you want to drag and drop data from various sources. Rather than writing specific code for each case, you may implement a generic project method that will handle any one of these text enterable areas. You could write something like:

  ` Handle dropping to text area project method
  ` Handle dropping to text area ( Pointer )
  ` Handle dropping to text area ( -> Text or String variable )
 
 Case of
  ` Use this event for accepting or rejecting the drag and drop
    :(Form event=On Drag Over)
  ` Initialize $0 for rejecting
       $0:=-1
  ` Get the information about the drag and drop source object
       DRAG AND DROP PROPERTIES($vpSrcObj;$vlSrcElem;$vlPID)
  ` In this example, we do not allow drag and drop from an object to itself
       If($vpSrcObj #$1)
  ` Get the type of the data which is being dragged
          $vlSrcType:=Type($vpSrcObj->)
          Case of
             :($vlSrcType=Is Text)
  ` OK for text variables
                $0:=0
             :($vlSrcType=Is String Var)
  ` String Variable is OK
                $0:=0
             :(($vlSrcType=String array)|($vlSrcType=Text array))
  ` String and Text Arrays are OK
                $0:=0
             :(($vlSrcType=Is LongInt)|($vlSrcType=Is Real)
                If(Is a list($vpSrcObj->))
  ` Hierarchical list is OK
                   $0:=0
                End if
          End case
       End if
 
  ` Use this event for performing the actual drag and drop action
    :(Form event=On Drop)
       $vtDraggedData:=""
  ` Get the information about the drag and drop source object
       DRAG AND DROP PROPERTIES($vpSrcObj;$vlSrcElem;$vlPID)
  ` Get the type of the variable which has been dragged
       $vlSrcType:=Type($vpSrcObj->)
       Case of
  ` If it is an array
          :(($vlSrcType=String array)|($vlSrcType=Text array))
             If($vlPID #Current process)
  ` Read the element from the source process instance of the variable
                GET PROCESS VARIABLE($vlPID;$vpSrcObj->{$vlSrcElem};$vtDraggedData)
             Else
  ` Copy the array element
                $vtDraggedData:=$vpSrcObj->{$vlSrcElem}
             End if
  ` If it is a list
          :(($vlSrcType=Is Real)|($vlSrcType=Is LongInt))
  ` If it is a list from another process
             If($vlPID #Current process)
  `Get the List Reference from the other process
                GET PROCESS VARIABLE($vlPID;$vpSrcObj->;$vlList)
             Else
                $vlList:=$vpSrcObj->
             End if
  ` If the list exists
             If(Is a list($vpSrcObj->))
  `Get the text of the item whose position was obtained
                GET LIST ITEM($vlList;$vlSrcElem;$vlItemRef;$vsItemText)
                $vtDraggedData:=$vsItemText
             End if
          Else
  ` It is a string or a text variable
             If($vlPID #Current process)
                GET PROCESS VARIABLE($vlPID;$vpSrcObj->;$vtDraggedData)
             Else
                $vtDraggedData:=$vpSrcObj->
             End if
       End case
  ` If there is actually something to drop (the source object may be empty)
       If($vtDraggedData #"")
          $1->:=$1->+$vtDraggedData
       End if
 End case

Once you have implemented this project method, you can use it in the following way:

  ` [anyTable]aTextField Object Method
 
 Case of
  ` ...
    :(Form event=On Drag Over)
       $0:=Handle dropping to text area(Self)
 
    :(Form event=On Drop)
       Handle dropping to text area(Self)
  ` ...
 End case

We want to fill a text area (for example, a label) with data dragged from a list box.

Here is the label1 object method:

 Case of
    :(Form event=On Drag Over)
       DRAG AND DROP PROPERTIES($source;$arrayrow;$processnum)
       If($source=Get pointer("list box1"))
          $0:=0 `The drop is accepted
       Else
          $0:=-1 `The drag is refused
       End if
    :(Form event=On Drop)
       DRAG AND DROP PROPERTIES($source;$arrayrow;$processnum)
       QUERY([Members];[Members]LastName=arrNames{$arrayrow})
       If(Records in selection([Members])#0)
          label1:=[Members]FirstName+" "+[Members]LastName+Char(Carriage return)+[Members]Address
          +Char(Carriage return)+[Members]City+","+" "+[Members]State
          +" "+[Members]ZipCode
       End if
 End case

It then becomes possible to carry out the following action:

 
PROPERTIES 

Product: 4D
Theme: Drag and Drop
Number: 607

 
INDEX

Alphabetical list of commands

 
HISTORY 

Modified: 4D 2004.2

 
SEE ALSO 

Drag and Drop
Drop position
Form event
GET PROCESS VARIABLE
Is a list
RESOLVE POINTER