Hi all.
If you have no need (or interest) in my replacement for 4D’s Drag and Drop 
command, stop reading now :-).

I have (like many others no doubt) developed alternative method calls to 
replace the obsolete 4D command _O_DRAG AND DROP PROPERTIES, and include the 
calls/code below in case someone else has problems coming up with a solution.
I was able to simply drop the new calls into the draggable list boxes on many 
forms quite easily.
I have simplified some bits in this email and, hopefully, didn’t mess it up.

Some sub-calls re objects use Cannon Smith’s Object Module calls (OBJ_xxx) but 
all can be replaced with native 4D code easily (I use them out of habit).

If you can see something I’ve screwed up or missed, please let me know.
Cheers, Keith

==========================
Form object call sequence
-----------------------------------
Given 2 listboxes side by side (A and B), that are able to drag/drop in either 
direction:
Both have events enabled for
- On Begin Drag Over
- On Drag Over
- On Drop

==========================
Listbox A method:

C_LONGINT($0)
C_LONGINT($Source_Element_l)
Case of 
        // 
********************************************************************************
        : (Form event code=On Begin Drag Over)
                OnDrag_Begin 
                
                  
//********************************************************************************
        : (Form event code=On Drag Over)  //this object has been dragged
                $0:=OnDrag_DragOver (->LSTBX_B_ab)  //pointer to allowed target 
listbox variable
                
                  
//********************************************************************************
        : (Form event code=On Drop)  //Trap drop from Export Fields (removing 
an Export field)
                $Source_Element_l:=OnDrag_Drop (->LSTBX_B_ab)  //pointer to 
allowed target listbox variable
                If ($Source_Element_l>0)
                        //Do something
                End if 
End case

==========================
Listbox B method:

C_LONGINT($0)
C_LONGINT($Source_Element_l)
Case of 
        // 
********************************************************************************
        : (Form event code=On Begin Drag Over)
                OnDrag_Begin 
                
                  
//********************************************************************************
        : (Form event code=On Drag Over)  //this object has been dragged
                $0:=OnDrag_DragOver (->LSTBX_A_ab)  //pointer to allowed target 
listbox variable
                
                  
//********************************************************************************
        : (Form event code=On Drop)  //Trap drop from Export Fields (removing 
an Export field)
                $Source_Element_l:=OnDrag_Drop (->LSTBX_A_ab)  //pointer to 
allowed target listbox variable
                If ($Source_Element_l>0)
                        //Do something
                End if 
End case

==========================
  // OnDrag_Begin  

  // Action: Centralised On Begin Drag Over handling for array based listboxes.
  // Created for 4D v18 upgrade
  // Created by Keith Goebel on 17/09/2020

If (False)  //Example calls for On Drag events to/from array based listboxes.
        OnDrag_Begin 
        
          //$0:=OnDrag_DragOver (->LSTBX_MBR_Select_2_ab)  //pointer to allowed 
target listbox variable
        
        C_LONGINT($Source_Element_l)
        $Source_Element_l:=OnDrag_Drop (->LSTBX_MBR_Select_2_ab)  //pointer to 
allowed target listbox variable
        If ($Source_Element_l>0)
                  //do something
        End if 
End if 

  // 
********************************************************************************
  // Declare local vars
C_TEXT($DragSourceName_t)
C_LONGINT($Column_Nb_l)
C_LONGINT($Row_Nb_l)
C_POINTER($Source_Object_p)
C_OBJECT($OBJ_o)

  
//********************************************************************************
CLEAR PASTEBOARD  //clear special Drag and Drop 4D pasteboard
  // --------------------------------------------------------------------
  //Store name of current listbox variable and dragged row number
$Source_Object_p:=OBJECT Get pointer(Object current)
LISTBOX GET CELL POSITION($Source_Object_p->;$Column_Nb_l;$Row_Nb_l)
If ($Row_Nb_l>0)
        $OBJ_o:=OBJ_Create 
                //subcall creates the object using Cannon Smith’s Object Module
        $DragSourceName_t:=OBJ_Get_Object_Name ($Source_Object_p;0)
                //subcall returns the pointed-to variable's name
        OBJ_Set_Text ($OBJ_o;"Source_Object";$DragSourceName_t) 
                //subcall stores the text in the object using Cannon Smith’s 
Object Module
        OBJ_Set_Long ($OBJ_o;"Source_Element";$Row_Nb_l)
                //subcall stores the longint in the object using Cannon Smith’s 
Object Module
        SET TEXT TO PASTEBOARD(JSON Stringify($OBJ_o))
Else 
          //do nothing
End if 
  // EOM


==========================
  // OnDrag_DragOver  

  // $1   Pointer     Pointer to the required source listbox variable.
  // $0   Longint    Returns
  //                       0 = drag can continue
  //                      -1 = drag rejected

  // Action: Centralised On Drag Over handling for array based listboxes.
  // Created for 4D v18 upgrade
  // Created by Keith Goebel on 17/09/2020

If (False)  //Example calls for On Drag events to/from array based listboxes.
        OnDrag_Begin 
        
          //$0:=OnDrag_DragOver (->LSTBX_MBR_Select_2_ab)  //pointer to allowed 
target listbox variable
        
        C_LONGINT($Source_Element_l)
        $Source_Element_l:=OnDrag_Drop (->LSTBX_MBR_Select_2_ab)  //pointer to 
allowed target listbox variable
        If ($Source_Element_l>0)
                  //do something
        End if 
End if 

  // 
********************************************************************************
  // Declare and Init parameters
C_POINTER($1;$Source_Check_p)
C_LONGINT($0)
$Source_Check_p:=$1
  // ------------------------------------------------------------------
  // Declare local vars
C_TEXT($PasteBoard_t)
C_TEXT($DragSourceName_t)
C_POINTER($Source_Object_p)
C_OBJECT($OBJ_o)

  
//********************************************************************************
$PasteBoard_t:=Get text from pasteboard  //get special Drag and Drop 4D 
pasteboard contents
If (Length($PasteBoard_t)>0)  //for protection against empty pastboard for some 
reason (prevents 4D crash)
        $OBJ_o:=JSON Parse(Get text from pasteboard)
        $DragSourceName_t:=OBJ_Get_Text ($OBJ_o;"Source_Object”)
                //subcall gets the text from the object using Cannon Smith’s 
Object Module
        $Source_Object_p:=Get pointer($DragSourceName_t)
        If (Not(Is nil pointer($Source_Object_p))) 
                If ($Source_Object_p=($Source_Check_p))
                        $0:=0
                Else 
                        $0:=-1
                End if 
        Else 
                  //how did we get here?
                $0:=-1  //error
        End if 
End if 
  // EOM


==========================
  // OnDrag_Drop  

  // $1   Pointer     Pointer to the required source listbox variable.
  // $0   Longint    Returns the dragged row niumber.

  // Action: Centralised On Drop handling for array based listboxes.
  // Created for 4D v18 upgrade
  // Created by Keith Goebel on 17/09/2020

If (False)  //Example calls for On Drag events to/from array based listboxes.
        OnDrag_Begin 
        
          //$0:=OnDrag_DragOver (->LSTBX_MBR_Select_2_ab)  //pointer to allowed 
target listbox variable
        
        C_LONGINT($Source_Element_l)
        $Source_Element_l:=OnDrag_Drop (->LSTBX_MBR_Select_2_ab)  //pointer to 
allowed target listbox variable
        If ($Source_Element_l>0)
                  //do something
        End if 
End if 

  
//********************************************************************************
  // Declare and Init parameters
C_POINTER($1;$Source_Check_p)
C_LONGINT($0;$Source_Element_l)
$Source_Check_p:=$1
  // ------------------------------------------------------------------
  // Declare local vars
C_TEXT($PasteBoard_t)
C_TEXT($DragSourceName_t)  //All added for 4D v18 upgrade
C_POINTER($Source_Object_p)
C_OBJECT($OBJ_o)

  
//********************************************************************************
$PasteBoard_t:=Get text from pasteboard  //get special Drag and Drop 4D 
pasteboard contents
If (Length($PasteBoard_t)>0)  //for protection against empty pastboard for some 
reason
        $OBJ_o:=JSON Parse($PasteBoard_t)
        $DragSourceName_t:=OBJ_Get_Text ($OBJ_o;"Source_Object")
                //subcall gets the text from the object using Cannon Smith’s 
Object Module
        $Source_Object_p:=Get pointer($DragSourceName_t)
        If (Not(Is nil pointer($Source_Object_p))) 
                If ($Source_Object_p=($Source_Check_p))
                        $Source_Element_l:=OBJ_Get_Long 
($OBJ_o;"Source_Element”)
                                //subcall gets the longint from the object 
using Cannon Smith’s Object Module
                End if 
        End if 
End if 
$0:=$Source_Element_l
  // EOM


**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to