DropSource.st
changeset 873 c5cd8f56dc6e
child 1679 cbff43d2fe2a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DropSource.st	Mon Mar 30 14:00:30 1998 +0200
@@ -0,0 +1,270 @@
+"
+ COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+Object subclass:#DropSource
+	instanceVariableNames:'receiver argument feedBackSelector dropObjectSelector
+		displayObjectSelector startDragSelector'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-DragAndDrop'
+!
+
+!DropSource class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+!
+
+documentation
+"
+    this class keeps the source from which the drag and drop operation is started.
+
+    receiver                <Object>    the receiver of the drop feedBack; a widget or
+                                        application or ....
+
+    argument                <Object>    user defined argument
+
+    startDragSelector       <Symbol>    send to the receiver to start a DragAndDropManager.
+                                        If no selector is specified, the default drag & drop
+                                        operation is performed. Thus the operator is able
+                                        to set the cursor, .... before starting the operation.
+
+    feedBackSelector        <Symbol>    send to the receiver to give a feedBack of the
+                                        finished drag & drop operation
+
+    dropObjectSelector      <Symbol>    used to get to get the list of draggable objects.
+
+    displayObjectSelector   <Symbol>    used to get to get the list of display objects.
+                                        In case of an empty or undefined list, the draggable
+                                        objects are used as display objects.
+
+    [see also:]
+        DragAndDropManager
+        DropObject
+        DropTarget
+        DropContext
+
+    [author:]
+        Claus Atzkern
+"
+! !
+
+!DropSource class methodsFor:'instance creation'!
+
+receiver:aReceiver
+    ^ self new receiver:aReceiver
+!
+
+receiver:aReceiver argument:anArgument
+    ^ self receiver:aReceiver argument:anArgument
+                    dropObjectSelector:nil
+                 displayObjectSelector:nil
+                      feedBackSelector:nil
+!
+
+receiver:aReceiver argument:anArgument dropObjectSelector:aSelector
+
+    ^ self new receiver:aReceiver argument:anArgument
+                        dropObjectSelector:aSelector
+                     displayObjectSelector:nil
+                          feedBackSelector:nil
+!
+
+receiver:aReceiver argument:anArgument dropObjectSelector:s1 displayObjectSelector:s2
+
+    ^ self new receiver:aReceiver argument:anArgument
+                        dropObjectSelector:s1
+                     displayObjectSelector:s2
+                          feedBackSelector:nil
+!
+
+receiver:aReceiver argument:anArgument dropObjectSelector:s1 displayObjectSelector:s2 feedBackSelector:s3
+
+    ^ self new receiver:aReceiver argument:anArgument
+                        dropObjectSelector:s1
+                     displayObjectSelector:s2
+                          feedBackSelector:s3
+! !
+
+!DropSource methodsFor:'accessing'!
+
+argument
+    "returns the user defined argument
+    "
+    ^ argument
+!
+
+argument:anArgument
+    "set the user defined argument
+    "
+    argument := anArgument
+!
+
+displayObjects
+    "returns a collection of display objects or nil
+    "
+    displayObjectSelector isNil ifTrue:[
+        ^ nil
+    ].
+    ^ displayObjectSelector numArgs == 0 ifTrue:[receiver perform:displayObjectSelector]
+                                        ifFalse:[receiver perform:displayObjectSelector with:self]
+!
+
+dropObjects
+    "returns a collection of objects to drop
+    "
+    dropObjectSelector isNil ifTrue:[
+        ^ nil
+    ].
+
+    ^ dropObjectSelector numArgs == 0 ifTrue:[receiver perform:dropObjectSelector]
+                                     ifFalse:[receiver perform:dropObjectSelector with:self]
+!
+
+receiver
+    "return the value of the instance variable 'receiver' (automatically generated)"
+
+    ^ receiver!
+
+receiver:something
+    "set the value of the instance variable 'receiver' (automatically generated)"
+
+    receiver := something.! !
+
+!DropSource methodsFor:'accessing selectors'!
+
+displayObjectSelector
+    "selector to access the displayObjects; a sequence of String, Text, Icon or Image,
+     LabelAndIcon ...
+     If an argument is required, the argument is the dropSource (self)
+    "
+    ^ displayObjectSelector
+!
+
+displayObjectSelector:aSelectorWithNoneOrOneArgs
+    "selector to access the displayObjects; a sequence of String, Text, Icon or Image,
+     LabelAndIcon ...
+     If an argument is required, the argument is the dropSource (self)
+    "
+    displayObjectSelector := aSelectorWithNoneOrOneArgs.
+!
+
+dropObjectSelector
+    "selector to access the draggable objects; a sequence of DropObject's
+     If an argument is required, the argument is the dropSource (self)
+    "
+    ^ dropObjectSelector
+!
+
+dropObjectSelector:aSelectorWithNoneOrOneArgs
+    "selector to access the draggable objects; a sequence of DropObject's
+     If an argument is required, the argument is the dropSource (self)
+    "
+    dropObjectSelector := aSelectorWithNoneOrOneArgs.
+!
+
+feedBackSelector
+    "selector called at end of a drop to give a feedback; the argument to
+     the selector is the dropContext
+    "
+    ^ feedBackSelector
+!
+
+feedBackSelector:aSelectorWithNoneOrOneArgs
+    "selector called at end of a drop to give a feedback; the argument to
+     the selector is the dropContext
+    "
+    feedBackSelector := aSelectorWithNoneOrOneArgs.
+!
+
+startDragSelector
+    "send to the receiver to start a DragAndDropManager. If no selector is specified,
+     the default drag & drop operation is performed.
+     Thus the operator is able to set the cursor, .... before starting the operation.
+
+     the arguments to the selector are:
+        2       aDropSource (self)      Widget
+        3       aDropSource (self)      Widget    Point
+    "
+    ^ startDragSelector
+!
+
+startDragSelector:aTwoOrThreeArgSelector
+    "send to the receiver to start a DragAndDropManager. If no selector is specified,
+     the default drag & drop operation is performed.
+     Thus the operator is able to set the cursor, .... before starting the operation.
+
+     the arguments to the selector are:
+        2       aDropSource (self)      Widget
+        3       aDropSource (self)      Widget    Point
+    "
+    startDragSelector := aTwoOrThreeArgSelector
+! !
+
+!DropSource methodsFor:'actions'!
+
+feedBack:aDropContext
+    "feedback to receiver
+    "
+    feedBackSelector isNil ifTrue:[
+        ^ self
+    ].
+
+    ^ feedBackSelector numArgs == 0 ifTrue:[receiver perform:feedBackSelector]
+                                   ifFalse:[receiver perform:feedBackSelector with:aDropContext]
+!
+
+startDragIn:aView at:aPoint
+    "start drag operation for a widget
+    "
+    |args|
+
+    startDragSelector notNil ifTrue:[
+        args := startDragSelector numArgs.
+        args == 2 ifTrue:[ ^ receiver perform:startDragSelector with:self with:aView ].
+        args == 3 ifTrue:[ ^ receiver perform:startDragSelector with:self with:aView with:aPoint ].
+    ].    
+    "/
+    "/ the default
+    "/
+    DragAndDropManager startDragFrom:aView dropSource:self
+
+! !
+
+!DropSource methodsFor:'instance creation'!
+
+receiver:aReceiver argument:anArgument dropObjectSelector:s1 displayObjectSelector:s2 feedBackSelector:s3
+
+    receiver              := aReceiver.
+    argument              := anArgument.
+    dropObjectSelector    := s1.
+    displayObjectSelector := s2.
+    feedBackSelector      := s3.
+! !
+
+!DropSource class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview2/DropSource.st,v 1.1 1998-03-30 11:59:53 ca Exp $'
+! !