DragAndDropManager.st
changeset 1289 0f7688ddff2c
parent 1166 4892defb2ab6
child 1397 47ac1d3e1df1
--- a/DragAndDropManager.st	Wed Dec 08 20:56:31 1999 +0100
+++ b/DragAndDropManager.st	Wed Dec 08 21:36:52 1999 +0100
@@ -882,22 +882,22 @@
     numArgs    := aDragBlock numArgs.
 
     numArgs == 3 ifTrue:[
-	dobjs := self dropObjects.
-	dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ]
+        dobjs := self dropObjects.
+        dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ]
     ] ifFalse:[
-	numArgs == 1 ifTrue:[
-	    dragBlock := [:p :v| aDragBlock value:p ]
-	] ifFalse:[
-	    dragBlock := aDragBlock
-	]
+        numArgs == 1 ifTrue:[
+            dragBlock := [:p :v| aDragBlock value:p ]
+        ] ifFalse:[
+            dragBlock := aDragBlock
+        ]
     ].
 
     anExtent isNil ifTrue:[
-	handler := DragHandler startGenericDrag:dragBlock.
+        handler := DragHandler startGenericDrag:dragBlock.
     ] ifFalse:[
-	handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset.
+        handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset.
     ].
-    self doStart:handler for:aView atEnd:aFourArgEndBlock
+    self doStart:handler for:aView atEnd:aFourArgEndBlock.
 
 ! !
 
@@ -1019,75 +1019,75 @@
     "/ search view the drop is in
     "/
     [   newId := rootId.
-	(rootId := device viewIdFromPoint:point in:newId) notNil
+        (rootId := device viewIdFromPoint:point in:newId) notNil
     ] whileTrue.
 
     newWg := device viewFromId:newId.
     dropContext targetWidget:newWg id:newId.
 
     handler isInterestedInDropTarget ifFalse:[
-	"/
-	"/ line or arrow handler
-	"/
-	handler dragTo:point.
-	^ self
+        "/
+        "/ line or arrow handler
+        "/
+        handler dragTo:point.
+        ^ self
     ].
 
     oldWg ~~ newWg ifTrue:[
-	"/
-	"/ widget has changed: drop target might change
-	"/
-	oldTgt := dropContext dropTarget.
-	newTgt := self doFindDropTargetIn:newWg at:point.
+        "/
+        "/ widget has changed: drop target might change
+        "/
+        oldTgt := dropContext dropTarget.
+        newTgt := self doFindDropTargetIn:newWg at:point.
 
-	newTgt ~= oldTgt ifTrue:[
-	    "/
-	    "/ drop target changed: handler might restore the screen
-	    "/
-	    handler dropTargetWillChange.
+        newTgt ~= oldTgt ifTrue:[
+            "/
+            "/ drop target changed: handler might restore the screen
+            "/
+            handler dropTargetWillChange.
 
-	    oldTgt notNil ifTrue:[
-		"/
-		"/ setup old context
-		"/
-		dropContext targetWidget:oldWg id:oldId.
-		oldTgt leave:dropContext.
-		dropContext targetWidget:newWg id:newId.
-	    ].
-	    dropContext dropTarget:newTgt.
-	    newTgt notNil ifTrue:[ newTgt enter:dropContext ]
-	] ifFalse:[
-	    dropContext dropTarget:newTgt
-	]
+            oldTgt notNil ifTrue:[
+                "/
+                "/ setup old context
+                "/
+                dropContext targetWidget:oldWg id:oldId.
+                oldTgt leave:dropContext.
+                dropContext targetWidget:newWg id:newId.
+            ].
+            dropContext dropTarget:newTgt.
+            newTgt notNil ifTrue:[ newTgt enter:dropContext ]
+        ] ifFalse:[
+            dropContext dropTarget:newTgt
+        ]
     ] ifFalse:[
-	(oldPt notNil and:[(oldPt dist:point) < 2 ]) ifTrue:[
-	    "/
-	    "/ ignorre the button motion event; restore old rootPoint
-	    "/
-	    dropContext rootPoint:oldPt.
-	    ^ self
-	].
-	newTgt := dropContext dropTarget
+        (oldPt notNil and:[(oldPt dist:point) < 2 ]) ifTrue:[
+            "/
+            "/ ignore the button motion event; restore old rootPoint
+            "/
+            dropContext rootPoint:oldPt.
+            ^ self
+        ].
+        newTgt := dropContext dropTarget
     ].
     "/
     "/ update the cursor
     "/
     (isDroppable := dropContext canDrop) ifTrue:[
-	cursor := enabledCursor
+        cursor := enabledCursor
     ] ifFalse:[
-	cursor := dropContext isAlienView ifFalse:[disabledCursor]
-					   ifTrue:[alienCursor]
+        cursor := dropContext isAlienView ifFalse:[disabledCursor]
+                                           ifTrue:[alienCursor]
     ].
     dragView cursor:cursor now:true.
     "/
     "/ test if droppable state changed
     "/
     canDrop == isDroppable ifFalse:[
-	"/
-	"/ droppable state changed: handler might restore the screen
-	"/
-	canDrop := isDroppable.
-	handler dropTargetWillChange
+        "/
+        "/ droppable state changed: handler might restore the screen
+        "/
+        canDrop := isDroppable.
+        handler dropTargetWillChange
     ].
 
     newTgt notNil ifTrue:[ newTgt over:dropContext ].
@@ -1137,6 +1137,10 @@
     ]
 !
 
+delegatesTo:someone
+    ^false
+!
+
 handlesButtonMotion:button inView:aView
     "query from event processor: am I interested in button-events ?
      yes I am (to activate the clicked-on field)."
@@ -1163,10 +1167,6 @@
      yes I am (to activate the clicked-on field)."
 
     ^ dragView == aView
-!
-
-delegatesTo:someone
-    ^false
 ! !
 
 !DragAndDropManager methodsFor:'initialization'!
@@ -1244,7 +1244,7 @@
 doStart:aHandler for:aView atEnd:aFourArgEndBlock
     "setup a handler and a restore block
     "
-    |cursor delegate|
+    |savedCursor savedDelegate prevGrab sensor p|
 
     dropContext sourceWidget:aView.
 
@@ -1253,22 +1253,39 @@
 
     dragView   := aView.
     dropAction := aFourArgEndBlock.
-    cursor     := aView cursor.
-    delegate   := aView delegate.
+    savedCursor     := aView cursor.
+    savedDelegate   := aView delegate.
     handler    := aHandler.
 
     dropContext dragHandler:aHandler.
 
     restoreBlock := [
-	aHandler postDragging.
-	aView delegate:delegate.
-	aView cursor:cursor now:true.
-	aView device ungrabPointer
+        aHandler postDragging.
+        aView delegate:savedDelegate.
+        aView cursor:savedCursor now:true.
+        prevGrab notNil ifTrue:[
+            aView forceUngrabPointer.
+            prevGrab grabPointer.
+        ] ifFalse:[
+            aView ungrabPointer.
+        ].
     ].
 
     aHandler preDraggingIn:aView.
     aView delegate:self.
-    aView device grabPointerInView:aView.
+    prevGrab := aView device activePointerGrab.
+    aView grabPointer.
+
+    "/ must wait for all pending motion events to arrive, and ignore them
+    (sensor := aView sensor) notNil ifTrue:[
+        aView device sync.        
+        sensor flushMotionEventsFor:nil.
+    ].
+
+    "/ start with a first draw at the current mouse position
+    p := aView device pointerPosition.
+    p := aView device translatePoint:p from:(aView device rootView id) to:(aView id).
+    self buttonMotion:1 x:p x y:p y view:aView
 
 ! !
 
@@ -1299,6 +1316,6 @@
 !DragAndDropManager class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.23 1999-05-06 21:17:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.24 1999-12-08 20:36:52 ca Exp $'
 ! !
 DragAndDropManager initialize!