dropContextQuery signal
authormartin
Thu, 27 Sep 2001 15:58:38 +0200
changeset 1511 99ab0dc04de4
parent 1510 4e0133eec046
child 1512 1361c4cdf08e
dropContextQuery signal
DragAndDropManager.st
--- a/DragAndDropManager.st	Fri Sep 21 10:02:41 2001 +0200
+++ b/DragAndDropManager.st	Thu Sep 27 15:58:38 2001 +0200
@@ -16,8 +16,8 @@
 Object subclass:#DragAndDropManager
 	instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock
 		alienCursor enabledCursor disabledCursor canDrop'
-	classVariableNames:'DragOriginatorQuerySignal DragOffsetQuerySignal
-		ActiveDragAndDropManagers'
+	classVariableNames:'DragContextQuerySignal DragOriginatorQuerySignal
+		DragOffsetQuerySignal ActiveDragAndDropManagers'
 	poolDictionaries:''
 	category:'Interface-DragAndDrop'
 !
@@ -236,6 +236,7 @@
 initialize
     DragOriginatorQuerySignal := QuerySignal new.
     DragOffsetQuerySignal := QuerySignal new.
+    DragContextQuerySignal := QuerySignal new.
     ActiveDragAndDropManagers := IdentityDictionary new.
 
     "
@@ -253,6 +254,10 @@
 
 !DragAndDropManager class methodsFor:'Signal constants'!
 
+dragContextQuerySignal
+    ^ DragContextQuerySignal
+!
+
 dragOffsetQuerySignal
     ^ DragOffsetQuerySignal
 
@@ -649,6 +654,51 @@
 "
 ! !
 
+!DragAndDropManager class methodsFor:'translation'!
+
+translatePointFromScreen:aPoint toView:aView
+    "translate a point to screen
+    "
+    |device trans point offset|
+
+    device := aView device.
+
+    "/
+    "/ translate to view
+    "/
+    offset := device translatePoint:0@0 from:(device rootWindowId) to:(aView id).
+    point := aPoint + offset.
+
+    "/
+    "/ get device coordinates
+    "/
+    (trans := aView transformation) notNil ifTrue:[
+        point := trans applyInverseTo:point
+    ].
+    ^ point
+!
+
+translatePointToScreen:aPoint from:aView
+    "translate a point to screen
+    "
+    |device trans point offset|
+
+    device := aView device.
+    "/
+    "/ get device coordinates
+    "/
+    (trans := aView transformation) notNil ifTrue:[
+        point := trans applyTo:aPoint
+    ] ifFalse:[
+        point := aPoint
+    ].
+    "/
+    "/ translate to screen
+    "/
+    offset := device translatePoint:0@0 from:(aView id) to:(device rootWindowId).
+  ^ offset + point
+! !
+
 !DragAndDropManager methodsFor:'accessing'!
 
 device
@@ -947,11 +997,11 @@
     "
     |p|
 
-    p := self translatePointToScreen:aStartPoint from:aView.
+    p := self class translatePointToScreen:aStartPoint from:aView.
 
     self doStart:(DragHandler startArrowDragAt:p)
-	     for:aView
-	   atEnd:aFourArgEndBlock
+             for:aView
+           atEnd:aFourArgEndBlock
 !
 
 startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock
@@ -963,11 +1013,11 @@
     "
     |p|
 
-    p := self translatePointToScreen:aStartPoint from:aView.
+    p := self class translatePointToScreen:aStartPoint from:aView.
 
     self doStart:(DragHandler startLineDragAt:p)
-	     for:aView
-	   atEnd:aFourArgEndBlock
+             for:aView
+           atEnd:aFourArgEndBlock
 ! !
 
 !DragAndDropManager methodsFor:'drawing'!
@@ -1039,20 +1089,20 @@
 buttonMotion:buttonState x:x y:y view:aView
     "handle a button motion event
     "
-    |oldPt oldTgt oldWg oldId newWg newId newTgt point cursor device isDroppable|
+    |oldPt oldTgt oldWg oldId newWg newId newTgt screenPoint cursor device isDroppable|
 
     device := dragView device.
-    point  := self translatePointToScreen:(x @ y) from:dragView.
+    screenPoint  := self class translatePointToScreen:(x @ y) from:dragView.
 "/    cursor := dragView cursor.
-"/    point := point + (cursor hotX @ cursor hotY).
+"/    screenPoint := screenPoint + (cursor hotX @ cursor hotY).
 
     oldWg  := dropContext targetWidget.
     oldId  := dropContext targetId.
     oldPt  := dropContext rootPoint.
 
-    dropContext rootPoint:point.
+    dropContext rootPoint:screenPoint.
 
-    newId := device viewIdFromPoint:point.
+    newId := device viewIdFromPoint:screenPoint.
     newWg := device viewFromId:newId.
     dropContext targetWidget:newWg id:newId.
 
@@ -1060,16 +1110,16 @@
         "/
         "/ line or arrow handler
         "/
-        handler dragTo:point.
+        handler dragTo:screenPoint.
         ^ self
     ].
 
-    oldWg ~~ newWg ifTrue:[
+    true "oldWg ~~ newWg" ifTrue:[
         "/
         "/ widget has changed: drop target might change
         "/
         oldTgt := dropContext dropTarget.
-        newTgt := self doFindDropTargetIn:newWg at:point.
+        newTgt := self doFindDropTargetIn:newWg at:screenPoint.
 
         newTgt ~= oldTgt ifTrue:[
             "/
@@ -1091,7 +1141,7 @@
             dropContext dropTarget:newTgt
         ]
     ] ifFalse:[
-        (oldPt notNil and:[(oldPt dist:point) < 2 ]) ifTrue:[
+        (oldPt notNil and:[(oldPt dist:screenPoint) < 2 ]) ifTrue:[
             "/
             "/ ignore the button motion event; restore old rootPoint
             "/
@@ -1122,7 +1172,7 @@
     ].
 
     newTgt notNil ifTrue:[ newTgt over:dropContext ].
-    handler dragTo:point.
+    handler dragTo:screenPoint.
 !
 
 buttonMultiPress:button x:x y:y view:aView
@@ -1220,19 +1270,21 @@
     "
     |point|
 
-    DragOriginatorQuerySignal answer:dragView do:[
-	DragOffsetQuerySignal answer:dragOffset do:[
-	    aContext targetWidget == aWidget ifTrue:[
-		point := aContext targetPoint
-	    ] ifFalse:[
-		point := 0@0. "/ nil.
-		"/
-		"/ FeedBack: set the widget which handles the drop
-		"/
-		aContext targetWidget:aWidget id:(aWidget id).
-	    ].
-	    aWidget drop:(aContext dropObjects) at:point
-	]
+    DragContextQuerySignal answer:aContext do:[
+        DragOriginatorQuerySignal answer:dragView do:[
+            DragOffsetQuerySignal answer:dragOffset do:[
+                aContext targetWidget == aWidget ifTrue:[
+                    point := aContext targetPoint
+                ] ifFalse:[
+                    point := 0@0. "/ nil.
+                    "/
+                    "/ FeedBack: set the widget which handles the drop
+                    "/
+                    aContext targetWidget:aWidget id:(aWidget id).
+                ].
+                aWidget drop:(aContext dropObjects) at:point
+            ]
+        ].
     ].
 
     "Modified: / 11.9.1998 / 00:53:22 / cg"
@@ -1248,9 +1300,9 @@
     "/ new mechanism to get a dropTarget
     "/
     aView messageNotUnderstoodSignal handle:[:ex|
-	target := nil.
+        target := nil.
     ] do:[
-	target := aView dropTarget
+        target := aView dropTarget
     ].
     target notNil ifTrue:[ ^ target ].
     "/
@@ -1259,15 +1311,17 @@
     view := aView.
     dobj := dropContext dropObjects.
 
-    DragOriginatorQuerySignal answer:dragView do:[
-	DragOffsetQuerySignal answer:dragOffset do:[
-	    [   (view canDrop:dobj) ifTrue:[
-		    ^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:.
-		].
-		(view := view superView) notNil
+    DragContextQuerySignal answer:dropContext do:[
+        DragOriginatorQuerySignal answer:dragView do:[
+            DragOffsetQuerySignal answer:dragOffset do:[
+                [   (view canDrop:dobj) ifTrue:[
+                        ^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:.
+                    ].
+                    (view := view superView) notNil
 
-	    ] whileTrue.
-	]
+                ] whileTrue.
+            ]
+        ].
     ].
     ^ nil
 !
@@ -1297,7 +1351,7 @@
     dropContext dragHandler:aHandler.
 
     restoreBlock := [
-        ActiveDragAndDropManagers removeKey:aView device.
+        ActiveDragAndDropManagers removeKey:aView device ifAbsent:nil.
         aHandler postDragging.
         aView delegate:savedDelegate.
         aView cursor:savedCursor now:true.
@@ -1333,32 +1387,9 @@
     handler restoreFromSaveArea.
 ! !
 
-!DragAndDropManager methodsFor:'translation'!
-
-translatePointToScreen:aPoint from:aView
-    "translate a point to screen
-    "
-    |device trans point offset|
-
-    device := aView device.
-    "/
-    "/ get device coordinates
-    "/
-    (trans := aView transformation) notNil ifTrue:[
-        point := trans applyTo:aPoint
-    ] ifFalse:[
-        point := aPoint
-    ].
-    "/
-    "/ translate to screen
-    "/
-    offset := device translatePoint:0@0 from:(aView id) to:(device rootWindowId).
-  ^ offset + point
-! !
-
 !DragAndDropManager class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.32 2001-08-23 11:19:16 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.33 2001-09-27 13:58:38 martin Exp $'
 ! !
 DragAndDropManager initialize!