OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Fred Tomke on April 29, 2009, 02:47:11 AM

Title: DragDrop in Tree
Post by: Fred Tomke on April 29, 2009, 02:47:11 AM
Hello,

I have a tree with enabled EditLabel, DragDropAllowDrag and DragDropAllowDrop.
Please imagine 3 items:

A
B
C

I want to drag C to drop between A and B. If A is currently selected and I drag C without selecting C explicitly, I don't know which item was dragged.

To solve this the user has to select the item before he can drag and drop it. But that might cause unexpected results. How can I get the real dragged item? Unfortunately, there is also no HitPointTest for tree controls as it is in ListViews. If so I could use the current MouseCoords to get the dragged item.

Code (autolisp) Select

(defun c:layer_sc_ltm_tree_OnDragnDropBegin (/)
  (princ "\ntree_OnDragnDropBegin\r")
  (setq ***ltm_label_drag*** (dcl_Tree_GetSelectedItem layer_sc_ltm_tree))
); c:layer_sc_ltm_tree_OnDragnDropBegin

(defun c:layer_sc_ltm_tree_OnDragnDropFromControl (strProjectName strFormName strControlName uDropPoint /)
  (if (and strProjectName (= strProjectName "layer")
   strFormName (= strFormName "sc_ltm")
   strControlName (or (= strControlName "tree") (= strControlName "lst_prop"))
   uDropPoint (= (type uDropPoint) 'STR)
   ***ltm_label_drag***
   (/= ***ltm_label_drag*** uDropPoint))
    (princ (strcat "\ntree_OnDragnDropFromControl: " (dcl_Tree_GetItemText layer_sc_ltm_tree ***ltm_label_drag***)
   "->" (dcl_Tree_GetItemText layer_sc_ltm_tree uDropPoint) "\r"))
  ); if
  (setq ***ltm_label_drag*** nil)
); c:layer_sc_ltm_tree_OnDragnDropFromControl


Fred
Title: Re: DragDrop in Tree
Post by: owenwengerd on April 29, 2009, 06:48:23 PM
I tried to test this with the tree sample. It always selects the item before the drag operation begins, so it is obvious which item is being moved. Can you attach a small sample file that demonstrates the problem?
Title: Re: DragDrop in Tree
Post by: Fred Tomke on April 30, 2009, 12:38:43 AM
Hello Owen,

I attached an example, I hope this works for you. I removed all unneeded sourcecode but I left all the events active to show whats going on. Let me know if you need something more.

Fred
Title: Re: DragDrop in Tree
Post by: owenwengerd on May 01, 2009, 07:45:54 AM
I see the problem. Unfortunately, I don't see any easy way to solve it. The ideal solution would be to create a drag image of the item that is being dragged, but that requires much more sophisticated drag/drop code. I didn't try it, but perhaps it would help to temporarily change the item label of the item during OnDragDropBegin. In any case, you could add a feature request for creating and using a custom drag image.