Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Irreverent behavior of the ImageList Control
Message
From
09/09/1997 21:57:05
Renato De Giovanni
Via Fractal Information Systems
São Paulo, Brazil
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00048496
Message ID:
00049250
Views:
92
>>Hello All,
>>
>>I have been trying to tame the ImageList control and the Treeview control with a view to creating an Explorer Like interface in VFP5.0. Being real tough. Have a lot of questions and would be really grateful if any one could help me out.
>>
>>1. How do I reference an node in an TreeView control, like from a Drag operation ? How can I use the HitTest Method ?
>>2. The Tree view control does not allow me to assign a character type reference from a variable as an image. When the same is allowed withh an constant. ? For example.
>>Thisform.trvMain.Nodes.Add( ,, cChildKey, cChildText, cChildImage), fails where the cChildKey, cChildText & cChildImage are all character fields from an table. But if cChildImage were to be an numeric field. It works just fine.
>>
>>Well that's it for now.
>>
>>Dilip,
>>Bahrain
>
>Hello Dilip,
>
>I have already implemented those features, and here are some tips:
>
>First for the HitTest you need the conversion factor.
>Add the following properties for the form:
>
>nTreeFactorX (default value 0) && used in HitTest
>nTreeFactorY (default value 0) && used in HitTest
>nMouseX (default value 0) && used in MouseDown
>nMouseY (default value 0) && used in MouseDown
>nDragThreshold (default value 4)
>cDraggedNodeKey (default value "")
>cDraggedNodeText (default value "")
>
>You may not use nDragTreshold if you don't want to.
>
>This should be in your form.Init()
>
>**************************************************************
>*myForm.Init()
>*this method code comes from Doug Hennig's article in June's 97 FoxTalk
>
>* Calculate the conversion factor between VFP window units (in pixels) and
>* TreeView window units (in twips).
>
>LOCAL liHWnd, ;
>	liHDC, ;
>	liPixelsPerInchX, ;
>	liPixelsPerInchY
>
>* Define some constants.
>
>#DEFINE cnLOG_PIXELS_X      88
>* From WINGDI.H
>#DEFINE cnLOG_PIXELS_Y      90
>* From WINGDI.H
>#DEFINE cnTWIPS_PER_INCH  1440
>* 1440 twips per inch
>
>* Declare some Windows API functions.
>
>DECLARE integer GetActiveWindow in WIN32API
>DECLARE integer GetDC           in WIN32API ;
>	integer iHDC
>DECLARE integer GetDeviceCaps   in WIN32API ;
>	integer iHDC, integer iIndex
>
>* Get a device context for VFP.
>
>liHWnd = GetActiveWindow()
>liHDC  = GetDC(liHWnd)
>
>* Get the pixels per inch.
>
>liPixelsPerInchX = GetDeviceCaps(liHDC, cnLOG_PIXELS_X)
>liPixelsPerInchY = GetDeviceCaps(liHDC, cnLOG_PIXELS_Y)
>
>* Get the twips per pixel.
>
>WITH This
>	.nTreeFactorX = cnTWIPS_PER_INCH/liPixelsPerInchX
>	.nTreeFactorY = cnTWIPS_PER_INCH/liPixelsPerInchY
>ENDWITH
>DoDefault()
>***************************
>
>What about images in the ListView - by default TreeView references them by numbers, but just give the names for images in ImageList in the Key property and you will be able to reference them by that name or numeric index.
>
>I took some sample code from my form which represents user groups and group members in the TreeView and supports DragDrop  from listbox lstUser and within the treeview.
>
>I have to say that in the latest MS TreeView versions HitTest doesn't work properly, returning always empty string instead of .NULL. or node reference. I didn't figure out yet what is wrong.
>Version of the MS TreeView shipped with VFP 5.0 works properly.
>
>
>**********************************************************//
>Sample of TreeView.MouseDown :
>
>*** OLE Control Event ***
>LPARAMETERS button, shift, x, y
>local loNode
>if Button = 1
>	loNode = This.HitTest(X * Thisform.nTreeFactorX, Y * Thisform.nTreeFactorX)
>	if not isnull(loNode) && and loNode.Key <> This.SelectedItem.Key
>		loNode.Selected = .T.
>		thisform.cDraggedNodeKey = loNode.Key
>		thisform.cDraggedNodeText = loNode.Text
>	else
>		thisform.cDraggedNodeKey = ""
>		thisform.cDraggedNodeText = ""
>	endif not isnull(loNode)
>
>* The user pressed the mouse button, so record the current mouse position so
>* we can later determine if the mouse moved enough to start a drag operation.
>
>endif Button = 1
>Thisform.nMouseX = X
>Thisform.nMouseY = Y
>
>
>**********************************************************************
>Sample of TreeView.MouseMove:
>
>*******************************************
>*** OLE Control Event ***
>LPARAMETERS button, shift, x, y
>
>* If the left mouse button is pressed and the user has moved the mouse (since
>* the button was first pressed) by more than our defined threshold, start the
>* drag operation.
>
>with Thisform
>	if Button = 1 and (abs(X - .nMouseX) > .nDragThreshold or ;
>		abs(Y - .nMouseY) > .nDragThreshold)
>		* we need to trap the selected node, because
>		* MouseDown and MouseMove happen when we click on + sign to open node
>		IF !EMPTY(thisform.cDraggedNodeKey)
>			This.Drag()
>		ENDIF
>	endif Button = 1 ...
>endwith
>
>***************************************************
>
>Sample of  TreeView.DragDrop:
>
>***************************
>
>LPARAMETERS oSource, nXCoord, nYCoord
>SELECT rv_us_groups
>LOCAL loNode, oNewNode
>oNewNode=.NULL.
>IF oSource.Name == lstUser'
>	loNode = This.HitTest(nXCoord * .nTreeFactorX, nYCoord * .nTreeFactorX)
>	IF not isnull(loNode)
>		loNode.Selected = .T.
>		*
>		*your code here
>		*
>	ENDIF
>ENDIF oSource.Name == 'lstUser'
>
>
>IF oSource.Name == 'TreeView'
>	loNode = This.HitTest(nXCoord * .nTreeFactorX, nYCoord * .nTreeFactorX)
>	IF not isnull(loNode)
>	loNode.Selected = .T.
>
>	**************************
>	IF not isnull(loNode)  and loNode.Key <> thisform.cDraggedNodeKey
>	*with this part you can move nodes within the treeview
>		loNode.Selected = .T.
>		IF isnull(loNode.parent) AND loNode.Image="group" && add moved *node only to first node level and only if it is a group
>			this.Nodes.Remove(thisform.cDraggedNodeKey)
>			oNewNode=this.Nodes.add(loNode,4,thisform.cDraggedNodeKey, thisform.cDraggedNodeText,"user")
>
>			oNewNode.EnsureVisible()
>			oNewNode.Selected = .t.
>		ENDIF
>
>	ENDIF
>	ENDIF
>ENDIF oSource.Name == 'TreeView'
>thisform.cDraggedNodeKey = ""
>thisform.cDraggedNodeText = ""
>
>**********************************************************************
>
>Sample of TreeView.DragOver:
>
>******************************
>LPARAMETERS oSource, nXCoord, nYCoord, nState
>LOCAL loNode
>IF oSource.Name == "lstUser"
>	WITH Thisform
>		loNode = This.HitTest(nXCoord * .nTreeFactorX, nYCoord * .nTreeFactorX)
>		IF !isnull(loNode)
>			loNode.Selected = .T.
>			* NoDrop cursor when mouse is over group member
>			oSource.DragIcon = IIF(loNode.Image = "user","no_l.cur","dragmove.cur")
>		ELSE
>			oSource.DragIcon = "dragmove.cur" && if cursor is outside nodes
>		ENDIF !isnull(loNode) ...
>	ENDWITH
>ENDIF
>
>IF oSource.Name == "TreeView"
>	WITH Thisform
>		loNode = This.HitTest(nXCoord * .nTreeFactorX, nYCoord * .nTreeFactorX)
>			loNode.Selected = .T.
>			this.DragIcon = IIF(loNode.Image  ==  "group" ,"dragmove.cur","no_l.cur")
>		ELSE
>			this.DragIcon = "dragmove.cur"
>		ENDIF !isnull(loNode) ...
>	ENDWITH
>ENDIF
>************************************************************************************
>
>HTH,
>
>Nick

Hi Nick!

Thank you for sharing all this code!

When I have more time I'll give a good look at it and also check about the HitTest problem (I didn't know about that).

One more thing I'll think about in the future is how to automatically scroll the Treeview during a Drag&Drop operation when the target node is not visible...

Renato
Previous
Reply
Map
View

Click here to load this message in the networking platform