3

The LA Fox Developer Newsletter
September 1997
Drag and Drop (Con’t from page 1)

(default) and Automatic. There is less control over dragging when in Automatic mode so we’ll leave the DragMode property for all objects set to 0-Manual (the default).

There are three components for Drag-and-Drop:
1. Theform,
2.
The source list, and
3.
The target(s).
Each has methods or properties that need to be filled in to make Drag-and-Drop work, and with a short description for each property or method, it should be easy to apply these concepts to any application.

The Form holding Drag-and-Drop Objects

Use the New Property.. option from the Form menu to add the following PROPERTIES to the form:

Can Targetlcon (enter DRAGPAGE.CUR for this Property;

CanSourcelcon (enter DRAGYES.CUR for this Property;

NoDroplcon (enter NODROP.CUR for this Property

DragThreshold (enter 8 for this Property);

MouseX (don’t enter anything now);

MouseY (don’t enter anything now)

The first three properties give us a convenient place to store names of cursors; the DragThreshold number will tell us how far the left-clicked mouse needs to move before we know the user wants to Drag-and-Drop; and the MouseX and MouseY properties are just temporary places to put the mouse location information when we need it.

The following code goes into the INIT method of the form:
use reports public array aReports[reccount()] x1
scan
this.lstSource.Additem(trim(reports.desc))
aReports[x]=trim(reports.filename)\
x=x+1
endscan
use

This code reads REPORT. DBF and populates the source Listbox (lstSource) for us. It also populates the aReports array with the corresponding names of report files for each report description.

So that’s it for the form.. .six properties and some INIT code.

The Drag-and-Drop Source

The Drag-and-Drop source is the object “lstSource”, a ListBox
holding the descriptions of system reports. We need to modify
three methods in this object.

1.
The DragOver method should read:
LPARAMETERS oSource, nXCoord, nYCoord, nState
*
This sets cursor shape when leaving or entering..
do case
case nState = 0 && Entering list
oSource.Draglcon = this.parent.CanSourcelcon case nState = I && Leaving the list
oSource. Draglcon = this.parent.NoDroplcon
endcase

Remember creating the CanSourcelcon property for the form? This is where we use it. Same for NoDroplcon. This code here changes the cursor as the user moves it out of the ListBox, from an arrow with a box next to it to a cirle & slash cursor like those on No Smoking signs.. Impressive stuff for so little work.

2. The MouseDown method should read:

LPARAMETERS nButton, nShift, nXCoord, nYCoord this.parent.MouseX = nXcoord this.parent.MouseY = nYcoord

Remember creating the Mousex and MouseY properties for the form? We use those now to record the starting position of the mouse when the left mouse button is first pressed.

3. The MouseMove property should read:

LPARAMETERS nButton, nShift, nXCoord, nYCoord if nButton = I && Left Mouse Button
if abs(nXcoordthls.parent.MouseX)>this.parent.DragThreshold or;
abs(nYcoordthis.parent.MouseY)>this.parent.DragThreshold
this.drag() && start dragging
endif
endif

Remember adding DragThreshold as a property for the Form? Remember entering “8” in this property? This code enables Dragging of the selected item from the source ListBox if the user holds down the left mouse button and moves the pointer more than 8 pixels. This gives users a little leeway before the cursor changes, but you could set the DragThreshold property to and number you wish.
So that’s it for the Source.. .only three methods and very little

code!

The Drag-and-Drop Target(s)

Targets are even easier.. .there are only two methods in each target that need our attention.

1.
The DragOver method should look like this:
LPARAMETERS oSource, nXCoord, nYCoord, nState
*
This sets cursor shape when leaving or entering this
(Con't, page 4)
Page 3

3