Page 4 of 7

Re: Drag grid item to another grid

Posted: Fri Jan 04, 2019 3:14 pm
by serge_girard
Great Work Edward !

One question : would it also be possible to COPY to grid2 with CTRL-key (now it is always MOVEd)?

Serge

Re: Drag grid item to another grid

Posted: Fri Jan 04, 2019 5:13 pm
by edk
serge_girard wrote: Fri Jan 04, 2019 3:14 pm Great Work Edward !

One question : would it also be possible to COPY to grid2 with CTRL-key (now it is always MOVEd)?

Serge
What to do during the DragAndDrop operation depends on how you program this event.
You have the following functions:
HMG_DaD_Drag_Window () -> returns the name of the form from which the drag started.
HMG_DaD_Drag_Control () -> returns the name of the control from which the drag started.
HMG_DaD_Drop_Window () -> returns the name of the form on which it was dropped.
HMG_DaD_Drop_Control () -> returns the name of the control on which it was dropped.
HMG_DaD_DragTreeValue () -> returns the value of the position of the tree from which the drag began.
HMG_DaD_DropTreeValue () -> returns the value of the tree position on which it was dropped.
HMG_Is_RButtonDaD () -> returns .T. if dragging was with the right mouse button.

Replace this function to copy from tree # 1 to tree # 2 with the right mouse button or with the ALT key.

Code: Select all

Function Drag_Tree2()
Local cDragFName := HMG_DaD_Drag_Window()
Local cDragCName := HMG_DaD_Drag_Control()
Local cDropFName := HMG_DaD_Drop_Window()
Local cDropCName := HMG_DaD_Drop_Control()
Local nDragTreeValue := HMG_DaD_DragTreeValue()
Local nDropTreeValue := HMG_DaD_DropTreeValue()
Local lIsDraggedWithRightButton := HMG_Is_RButtonDaD()
Local lCopy, aDragItems, nAddPos

IF HMG_Is_DaD()
	HMG_Release_DaD()
	DO CASE
		CASE cDropCName == 'Tree_2' 
			//Move nodes/items
			lCopy := HMG_VirtualKeyIsPressed (VK_LCONTROL) .OR. HMG_VirtualKeyIsPressed (VK_RCONTROL) .OR. HMG_VirtualKeyIsPressed (VK_ALT) .OR. lIsDraggedWithRightButton
			aDragItems := _GetTreeItemStru( cDragFName, cDragCName, nDragTreeValue )
			IF !EMPTY ( aDragItems )
				IF !lCopy .AND. nDropTreeValue < nDragTreeValue		//dropped above the drag
					DoMethod (cDragFName, cDragCName, "DeleteItem", nDragTreeValue)
				ENDIF
				
				nAddPos := nDropTreeValue
				AEVAL ( aDragItems, { |x| ( DoMethod (cDropFName, cDropCName, "AddItem", x[2] , nAddPos + x[3] ),  IF( x[3]=0 /* 1-st item added as last nodes item */, nAddPos := nAddPos + LEN( _GetTreeItemStru( cDropFName, cDropCName, nDropTreeValue ) ) - 1 - x [1] , Nil) ) } )
				
				IF !lCopy .AND. nDropTreeValue > nDragTreeValue		//dropped below the drag
					DoMethod (cDragFName, cDragCName, "DeleteItem", nDragTreeValue)
				ENDIF

				DoMethod (cDropFName, cDropCName, "Redraw")
				DoMethod (cDragFName, cDragCName, "Redraw")		
		
			ENDIF
			
		ENDCASE
ENDIF

RETURN
Control and Shift key disrupt the action of DragAndDrop (they trigger a separate event while dragging) but you can read their value when dropped. So just before dropping, press and hold Control and then drop.

Re: Drag grid item to another grid

Posted: Fri Jan 04, 2019 5:58 pm
by serge_girard
Great !

Serge

Re: Drag grid item to another grid

Posted: Fri Jan 04, 2019 6:24 pm
by mustafa
Edk
Very interesting
Congratulations
Mustafa

Re: Drag grid item to another grid

Posted: Sat Jan 05, 2019 7:10 am
by mol
Great work!
It would be excellent to have colorized new parent element in the tree while dragging child.

Thank you very much, Edward!

Re: Drag grid item to another grid

Posted: Sat Jan 05, 2019 10:33 am
by Anand
Thanks Edward for such a useful enhancement !!

Regards,

Anand

Re: Drag grid item to another grid

Posted: Sat Jan 05, 2019 11:22 am
by quartz565
Thank you Edward!

Re: Drag grid item to another grid

Posted: Sat Jan 05, 2019 2:41 pm
by edk
mol wrote: Sat Jan 05, 2019 7:10 am Great work!
It would be excellent to have colorized new parent element in the tree while dragging child.

Thank you very much, Edward!
Marku, mówisz i masz :D
Marek. You say, and you have. :D
DragAndDrop_0.005.zip
(11.84 KiB) Downloaded 232 times
Tree DragAndDrop.gif
Tree DragAndDrop.gif (77.57 KiB) Viewed 10307 times

Re: Drag grid item to another grid

Posted: Sun Jan 06, 2019 10:00 am
by mol
Jesteś wielki!
Król Edward na 3 Króli! :-D

Ps. Jakim programem robisz te animowane gify?

Re: Drag grid item to another grid

Posted: Sun Jan 06, 2019 3:11 pm
by edk
Dzięki, gify zrobilem oCam'em