Drag grid item to another grid

Utilities like DBU, Make, IDE written in HMG/ used to create HMG based applications

Moderator: Rathinagiri

User avatar
serge_girard
Posts: 2333
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 576 times
Been thanked: 124 times
Contact:

Re: Drag grid item to another grid

Post by serge_girard » 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

edk
Posts: 480
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 136 times
Been thanked: 387 times

Post by edk » Fri Jan 04, 2019 5:13 pm

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.

User avatar
serge_girard
Posts: 2333
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 576 times
Been thanked: 124 times
Contact:

Post by serge_girard » Fri Jan 04, 2019 5:58 pm

Great !

Serge

User avatar
mustafa
Posts: 829
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 117 times
Contact:

Post by mustafa » Fri Jan 04, 2019 6:24 pm

Edk
Very interesting
Congratulations
Mustafa

User avatar
mol
Posts: 3214
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 223 times
Been thanked: 123 times
Contact:

Post by mol » 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!

User avatar
Anand
Posts: 404
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 110 times
Been thanked: 60 times

Post by Anand » Sat Jan 05, 2019 10:33 am

Thanks Edward for such a useful enhancement !!

Regards,

Anand
Image

User avatar
quartz565
Posts: 561
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 173 times
Been thanked: 20 times
Contact:

Post by quartz565 » Sat Jan 05, 2019 11:22 am

Thank you Edward!
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

edk
Posts: 480
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 136 times
Been thanked: 387 times

Post by edk » Sat Jan 05, 2019 2:41 pm

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 37 times
Tree DragAndDrop.gif
Tree DragAndDrop.gif (77.57 KiB) Viewed 543 times

User avatar
mol
Posts: 3214
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 223 times
Been thanked: 123 times
Contact:

Post by mol » Sun Jan 06, 2019 10:00 am

Jesteś wielki!
Król Edward na 3 Króli! :-D

Ps. Jakim programem robisz te animowane gify?

edk
Posts: 480
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 136 times
Been thanked: 387 times

Post by edk » Sun Jan 06, 2019 3:11 pm

Dzięki, gify zrobilem oCam'em

Post Reply