DropTarget.st
changeset 873 c5cd8f56dc6e
child 1550 b58979898957
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DropTarget.st	Mon Mar 30 14:00:30 1998 +0200
@@ -0,0 +1,326 @@
+"
+ 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:#DropTarget
+	instanceVariableNames:'receiver enterSelector leaveSelector overSelector dropSelector
+		canDropSelector argument'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-DragAndDrop'
+!
+
+!DropTarget 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 current target of the drop operation; the object respoonsible
+    for the widget under the current mouse position.
+
+    receiver        <Object>        receiver to which the requests are sent. the
+                                    widget or an application.
+
+    argument        <Object>        user defined argument
+
+    enterSelector   <Symbol>        send the first time to the drop target when entering
+                                    the widget.
+
+    leaveSelector   <Symbol>        send the last time to the drop target when leaving
+                                    the widget.
+
+    overSelector    <Symbol>        send all the time to the drop target when moveing the
+                                    mouse over the widget.
+
+    dropSelector    <Symbol>        send to the drop target to drop the collection of
+                                    objects.
+
+    canDropSelector <Symbol>        send to the drop target to ask if the context could
+                                    be dropped.
+
+    [see also:]
+        DragAndDropManager
+        DropSource
+        DropContext
+
+    [author:]
+        Claus Atzkern
+"
+
+! !
+
+!DropTarget class methodsFor:'instance creation'!
+
+receiver:aReceiver
+    ^ self new receiver:aReceiver
+!
+
+receiver:aReceiver argument:anArgument
+
+    ^ self new receiver:aReceiver
+               argument:anArgument.
+!
+
+receiver:aReceiver argument:anArgument dropSelector:aSelector
+
+    ^ self new receiver:aReceiver
+               argument:anArgument
+           dropSelector:aSelector
+        canDropSelector:nil
+!
+
+receiver:aReceiver argument:anArgument dropSelector:s1 canDropSelector:s2
+
+    ^ self new receiver:aReceiver
+               argument:anArgument
+           dropSelector:s1
+        canDropSelector:s2
+! !
+
+!DropTarget methodsFor:'accessing'!
+
+argument
+    "returns the user defined argument; this argument is used for a drop action
+     with two arguments, the context and the argument
+    "
+    ^ argument
+!
+
+argument:something
+    "set the user defined argument; this argument is used for a drop action
+     with two arguments, the context and the argument
+    "
+    ^ something
+!
+
+canDropSelector
+    "selector called to get a feedback if context is droppable.
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    ^ canDropSelector
+!
+
+canDropSelector:something
+    "selector called to get a feedback if context is droppable.
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    canDropSelector := something.
+!
+
+dropSelector
+    "selector called to drop a collection of draggable objects.
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    ^ dropSelector
+!
+
+dropSelector:something
+    "selector called to drop a collection of draggable objects.
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    dropSelector := something.
+!
+
+enterSelector
+    "send the first time to the drop target when entering the widget.
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    ^ enterSelector
+!
+
+enterSelector:something
+    "send the first time to the drop target when entering the widget.
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    enterSelector := something.
+!
+
+leaveSelector
+    "send the last time to the drop target when leaving the widget.
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    ^ leaveSelector
+!
+
+leaveSelector:something
+    "send the last time to the drop target when leaving the widget.
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    leaveSelector := something.
+!
+
+overSelector
+    "send all the time to the drop target when moveing the mouse over the widget
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    ^ overSelector
+!
+
+overSelector:something
+    "send all the time to the drop target when moveing the mouse over the widget
+
+     the arguments to the selector are:
+        0       nothing
+        1       aDropContext
+        2       aDropContext and the argument
+    "
+    overSelector := something.
+!
+
+receiver
+    "receiver to which the requests are sent. a widget or an application ...
+    "
+    ^ receiver
+!
+
+receiver:something
+    "receiver to which the requests are sent. a widget or an application ...
+    "
+    receiver := something.
+! !
+
+!DropTarget methodsFor:'actions'!
+
+drop:aContext
+    "send when the mouse button is released within the current widget.
+    "
+    self perform:dropSelector withContext:aContext
+!
+
+enter:aContext
+    "send the first time, when entering the widget
+    "
+    self perform:enterSelector withContext:aContext
+!
+
+leave:aContext
+    "send the last time, when leaving the widget
+    "
+    self perform:leaveSelector withContext:aContext
+!
+
+over:aContext
+    "send all the time, when moveing the mouse over the widget
+    "
+    self perform:overSelector withContext:aContext
+
+! !
+
+!DropTarget methodsFor:'instance creation'!
+
+receiver:aReceiver argument:anArgument
+    "set the receiver and an user defined argument
+    "
+    receiver := aReceiver.
+    argument := anArgument.
+!
+
+receiver:aReceiver argument:anArgument dropSelector:s1 canDropSelector:s2
+    "set the receiver and an user defined argument
+    "
+    receiver        := aReceiver.
+    argument        := anArgument.
+    dropSelector    := s1.
+    canDropSelector := s2.
+! !
+
+!DropTarget methodsFor:'private'!
+
+perform:aSelector withContext:aContext
+    "perform the selector
+    "
+    |numArgs|
+
+    aSelector notNil ifTrue:[
+        (numArgs := aSelector numArgs) == 0 ifTrue:[
+            receiver perform:aSelector
+        ] ifFalse:[
+            numArgs == 1 ifTrue:[
+                receiver perform:aSelector with:aContext
+            ] ifFalse:[
+                receiver perform:aSelector with:aContext with:argument
+            ]
+        ]
+    ]
+! !
+
+!DropTarget methodsFor:'queries'!
+
+canDrop:aContext
+    "send to the receiver to ask if the context is droppable
+    "
+    |numArgs|
+
+    canDropSelector notNil ifTrue:[
+        (numArgs := canDropSelector numArgs) == 0 ifTrue:[
+            ^ receiver perform:canDropSelector
+        ].
+        numArgs == 1 ifTrue:[
+            ^ receiver perform:canDropSelector with:aContext
+        ].
+        ^ receiver perform:canDropSelector with:aContext with:argument
+    ].
+    ^ true
+! !
+
+!DropTarget class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview2/DropTarget.st,v 1.1 1998-03-30 11:59:33 ca Exp $'
+! !