The Label WidgetTable of the WidgetsThe Text Editor Wigdet
 

Implementing Drag & Drop

This section describes how to add an object of the widget to the Drag & Drop Control and how to get information about the current dragged object(s).


The Source Section:

Start Optional Message

This 'Two Arguments Message' can be used by setup your own Drag & Drop handler, an instance of class DragAndDropManager. This allows you to setup your own cursors and cursor position used during the Drag & Drop operation is active:
    #disabledCursor: (an instance of Cursor)
	cursor shown if the underlaying widget cannot drop the context.
    #enabledCursor: (an instance of Cursor)
	cursor shown if the underlaying widget can drop the context.
    #alienCursor: (an instance of Cursor)
	cursor shown if the underlaying widget is not a STX-Widget.
Example:
    doStartDrag:aDropSource in:aTheWidget
	|dragAndDropHandler|

	dragAndDropHandler = DragAndDropManager new.

	"/ setting the cursors shown during Drag & Drop

	dragAndDropHandler disabledCursor:(Cursor down).
	dragAndDropHandler  enabledCursor:(Cursor up).

	"/ now we Start The Drag & Drop Operation;
	"/ setting the cursor to the top left edge of your display
	"/ objects shown during the drag is active (#topLeft).

	dragAndDropHandler startDragFrom:aTheWidget
			      dropSource:aDropSource
				  offset:#topLeft.
The DropSource contains information about the widget the Drag Operation is instantiated from and the mouse position...
Argument Optional Argument

This optional argument is stored in the DropSource instance and can be used as an identifier or...
Feed Back Optional Message

This 'One Argument Message' is used to inform you that the Drag & Drop operation is finished. The argument to the message is an instance of class DropContext which contains the DropTarget of the last widget and you can ask the context whether the dragged objects are dropped.
    #hasDropped
	returns true if the dragged objects are dropped.
    #dropSource
	returns an instance of class DropSource which contains
	information about the widget which starts the operation.
    #dropTarget
	returns an instance of class DropTarget which contains
	information about the widget which drops (if accepted)
	the objects.
For more information see the classes:
          - DropContext
          - DropSource
          - DropTarget

Objects Required Message

This 'One Argument Message' is invoked by the Drag & Drop handler to access the list of dragged objects, which are kind of class DropObject.

To create a specific DropObect there exists creation methods:
    #newClass:(aClass)
	returns a DropObject, which returns true if asked for isClassObject.
    #newColor:(an instance of Color)
	returns a DropObject, which returns true if asked for isColorObject.
    #newFile:(an instance of Filename)
	returns a DropObject, which returns true if asked for isFileObject.
    #newFileInArchive:(an instance of Filename)
	returns a DropObject, which returns true if asked for isFileInArchive.
    #newImage:(an instance of Image or Icon)
	returns a DropObject, which returns true if asked for isImageObject.
    #newText:(an instance of String)
	returns a DropObject, which returns true if asked for isTextObject.
    #newMethod:(an instance of Method)
	returns a DropObject, which returns true if asked for isMethodObject.

    #new:(something)
	returns a DropObject dependent on something.

    To access the real instance of the DropObject, there exists the
    message #theObject which you can ask for example:

	#isColor
	    returns true if the receiver is a Color
	#isKindOf:
	    returns true, if the receiver is an instance of aClass or one
	    of its subclasses.
	.......
For more information see the class: DropObject
Display
Objects
Optional Message

This 'One Argument Message' is invoked by the Drag & Drop handler to access the list of display objects used during the drag operation is active. Returns a list of String(s), LabelAndIcon(s) or Image(s).

On default the DropObject's are asked for.
 
 

The Target Section:

Drop Required Message

This 'One or Two Argument(s) Message' is invoked by the Drag & Drop handler to perform the drop. The argument to the message is the DropContext and optional the argument.

Example:
    doDrop:aDropContext
	|dropObjects|

	dropObjects := aDropContext dropObjects.

	dropObjects do:[:aDropObject|
	    realObject := aDropObject theObject.
	    "/ do something with the real object
	].
Argument Optional Argument

This optional argument is stored in the DropContext instance and can be used as an identifier or...
The optional argument to the #drop message described above.
Can Drop Required Message

This 'One Argument Message' is invoked by the Drag & Drop handler to ask the receiver whether the DropContext is dropable or not. The argument to the message is an instance of DropContext.

Example:
    canDrop:aDropContext
	|dropObjects|

	dropObjects := aDropContext dropObjects.

	dropObjects do:[:aDropObject| |fileName|
	    "/ onnly file objects are dropable
	    aDropObject isFileObject ifFalse:[ ^ false ].

	    "/ and only directories are allowed.
	    fileName := aDropObject theObject.
	    fileName isDirectory ifFalse:[ ^ false ].
	].
	^ true   "/ ok, can drop the context
Enter Optinal Message

This 'One Argument Message' is invoked by the Drag & Drop handler to inform the receiver that the mouse is entered the underlaying widget. The argument to the message is an instance of DropContext.

Example:
    dropEnterWith:aDropContext
	|targetWidget targetPoint|

	"/ the widget under the mouse
	targetWidget := aDropContext targetWidget.

	"/ mouse position within the target
	targetPoint  := aDropContext targetPoint.

	"/ perform some operations ect.
	"/ if the widget changes the background color or something
	"/ you are obligated to inform the context that the drawable
	"/ will change.
	aDropContext contentsWillChange.

	"/ now you can change the background color or something else.
Over Optinal Message

This 'One Argument Message' is invoked by the Drag & Drop handler to inform the receiver that the mouse moves over the underlaying widget. The argument to the message is an instance of DropContext.

Example:
    dropOverWith:aDropContext
	"/ see the example under #enter.
	"/ perform some operations on the widget
Leave Optinal Message

This 'One Argument Message' is invoked by the Drag & Drop handler to inform the receiver that the mouse leaves the underlaying widget. The argument to the message is an instance of DropContext.

Example:
    dropLeaveWith:aDropContext
	"/ see the example under #enter.
	"/ perform some operations on the widget
	"/ maybe you have to restore the background color or ...

[stx-logo]
Copyright © 1998 eXept Software AG, all rights reserved