--- a/DragAndDropManager.st Sat Jan 18 15:28:36 2003 +0100
+++ b/DragAndDropManager.st Tue Jan 21 08:23:12 2003 +0100
@@ -684,6 +684,7 @@
"
|device trans point offset|
+ aView isRootView ifTrue:[^ aPoint].
device := aView device.
"/
"/ get device coordinates
@@ -697,7 +698,7 @@
"/ translate to screen
"/
offset := device translatePoint:0@0 fromView:aView toView:(device rootView).
- ^ offset + point
+ ^ offset + point
! !
!DragAndDropManager methodsFor:'accessing'!
@@ -1103,28 +1104,25 @@
!DragAndDropManager methodsFor:'event catching'!
-buttonMotion:buttonState x:x y:y view:aView
- "handle a button motion event
- "
- |oldPt oldTgt oldWg oldId newWg newId newTgt screenPoint cursor device isDroppable|
+buttonMotion:button x:x y:y view:aView
+ |device screenPoint oldWg oldId oldPt newId newWg oldTgt newTgt isDroppable cursor|
self removePassiveAction.
-
escapePressed == true ifTrue:[^ self].
device := dragView device.
- screenPoint := self class translatePointToScreen:(x @ y) from:dragView.
-"/ cursor := dragView cursor.
-"/ screenPoint := screenPoint + (cursor hotX @ cursor hotY).
-
oldWg := dropContext targetWidget.
oldId := dropContext targetId.
oldPt := dropContext rootPoint.
+ screenPoint := self class translatePointToScreen:(x @ y) from:aView.
+"/ screenPoint := device pointerPosition.
dropContext rootPoint:screenPoint.
newId := device viewIdFromPoint:screenPoint.
newWg := device viewFromId:newId.
+
+ dropContext rootPoint:screenPoint.
dropContext targetWidget:newWg id:newId.
handler isInterestedInDropTarget ifFalse:[
@@ -1134,51 +1132,38 @@
handler dragTo:screenPoint.
^ self
].
+ oldTgt := dropContext dropTarget.
+ newTgt := self doFindDropTargetIn:newWg at:screenPoint.
- true "oldWg ~~ newWg" ifTrue:[
- "/
- "/ widget has changed: drop target might change
+ newTgt ~= oldTgt ifTrue:[
"/
- oldTgt := dropContext dropTarget.
- newTgt := self doFindDropTargetIn:newWg at:screenPoint.
-
- newTgt ~= oldTgt ifTrue:[
- "/
- "/ drop target changed: handler might restore the screen
- "/
- handler dropTargetWillChange.
+ "/ 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:[
- (oldPt notNil and:[(oldPt dist:screenPoint) < 2 ]) ifTrue:[
- "/
- "/ ignore the button motion event; restore old rootPoint
- "/
- dropContext rootPoint:oldPt.
- ^ self
- ].
- newTgt := dropContext dropTarget
+ dropContext dropTarget:newTgt
].
+
"/
"/ update the cursor
"/
+
(isDroppable := dropContext canDrop) ifTrue:[
cursor := enabledCursor
] ifFalse:[
- cursor := dropContext isAlienView ifFalse:[disabledCursor]
- ifTrue:[alienCursor]
+ dropContext isAlienView ifFalse:[cursor := disabledCursor]
+ ifTrue:[cursor := alienCursor]
].
dragView cursor:cursor now:true.
"/
@@ -1196,55 +1181,32 @@
handler dragTo:screenPoint.
!
-buttonMultiPress:button x:x y:y view:aView
- "discard each buttonMultiPress event
- "
-!
+buttonRelease:button x:x y:y view:aView
-buttonPress:button x:x y:y view:aView
- "discard each buttonPress event
- "
-!
-
-buttonRelease:button x:x y:y view:aView
- "button released; do the drop
- "
-
- ((button == 2) or:[button == #menu]) ifTrue:[
+ ((button == 1) or:[button == #select]) ifFalse:[
^ self
].
+ self removePassiveAction.
- self removePassiveAction.
- "/
- "/ update the context
- "/
- self buttonMotion:button x:x y:y view:aView.
-
- "/
- "/ restore source view
- "/
- restoreBlock value.
- escapePressed == true ifTrue:[^ self].
+ restoreBlock value. "/ restore context before start drag
- "/
- "/ at least do the drop operation
- "/
- dropAction isNil ifTrue:[
- dropContext doDrop
- ] ifFalse:[
+ escapePressed ~~ true ifTrue:[
"/
- "/ initiator wants to do it himself, manually.
- "/ Thus, no feedBack operation invoked.
+ "/ at least do the drop operation
"/
- dropAction value:(dropContext targetWidget)
- value:(dropContext targetId)
- value:(dropContext rootPoint)
- value:(dropContext targetPoint).
- ]
-!
-
-delegatesTo:someone
- ^false
+ dropAction isNil ifTrue:[
+ dropContext doDrop
+ ] ifFalse:[
+ "/
+ "/ initiator wants to do it himself, manually.
+ "/ Thus, no feedBack operation invoked.
+ "/
+ dropAction value:(dropContext targetWidget)
+ value:(dropContext targetId)
+ value:(dropContext rootPoint)
+ value:(dropContext targetPoint).
+ ].
+ ].
!
escapePressed
@@ -1269,50 +1231,40 @@
].
!
-handlesButtonMotion:button inView:aView
- "query from event processor: am I interested in button-events ?
- yes I am (to activate the clicked-on field)."
-
- ^ dragView == aView
-!
-
-handlesButtonMultiPress:button inView:aView
- "query from event processor: am I interested in button-events ?
- yes I am (to activate the clicked-on field)."
-
- ^ dragView == aView
-!
-
-handlesButtonPress:button inView:aView
- "query from event processor: am I interested in button-events ?
- yes I am (to activate the clicked-on field)."
+keyPress:aKey x:x y:y view:aView
- ^ dragView == aView
-!
-
-handlesButtonRelease:button inView:aView
- "query from event processor: am I interested in button-events ?
- yes I am (to activate the clicked-on field)."
-
- ^ dragView == aView
-!
-
-handlesKeyPress:aKey inView:aView
- "query from event processor: am I interested in key-events ?
- yes I am (to activate the clicked-on field)."
-
- ^ dragView == aView
-!
-
-keyPress:aKey x:x y:y view:aView
- "any key is pressed:
- #Escape cancel drag & drop operation
- "
- escapePressed == true ifTrue:[^ self ]. "/ already canceled
+ escapePressed == true ifTrue:[ ^ self ]. "/ ignorred, escaped was pressed
aKey == #Escape ifTrue:[
self escapePressed.
].
+!
+
+processEvent:event
+ |evView|
+
+ restoreBlock isNil ifTrue:[^ false]. "/ should not happen
+
+ evView := event view.
+ evView isNil ifTrue:[^ false].
+
+ event isInputEvent ifFalse:[
+ ^ false
+ ].
+
+ event isKeyEvent ifTrue:[
+ self keyPress:(event key) x:(event x) y:(event y) view:evView.
+ ^ true
+ ].
+
+ event isButtonMotionEvent ifTrue:[
+ self buttonMotion:(event state) x:(event x) y:(event y) view:evView.
+ ] ifFalse:[
+ event isButtonReleaseEvent ifTrue:[
+ self buttonRelease:(event button) x:(event x) y:(event y) view:evView.
+ ]
+ ].
+ ^ true
! !
!DragAndDropManager methodsFor:'initialization'!
@@ -1399,7 +1351,7 @@
doStart:aHandler for:aView atEnd:aFourArgEndBlock
"setup a handler and a restore block
"
- |device savedCursor savedDelegate prevGrab prevKeyb sensor p lastActive|
+ |device sensor lastActive windowGroup saveContents screenPoint|
device := aView device.
lastActive := ActiveDragAndDropManagers at:device ifAbsent:nil.
@@ -1417,56 +1369,45 @@
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ].
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ].
- dragView := aView.
- dropAction := aFourArgEndBlock.
- savedCursor := aView cursor.
- savedDelegate := aView delegate.
+ dragView := aView.
+ dropAction := aFourArgEndBlock.
+ windowGroup := aView windowGroup.
handler := aHandler.
escapePressed := false.
- prevGrab := prevKeyb := nil.
dropContext dragHandler:aHandler.
+ saveContents := IdentityDictionary new.
+
+ saveContents at:#preEventHook put:(windowGroup preEventHook).
+ saveContents at:#postEventHook put:(windowGroup postEventHook).
+ saveContents at:#cursor put:(dragView cursor).
+ windowGroup preEventHook:self.
+ windowGroup postEventHook:self.
restoreBlock := [
+ restoreBlock := nil.
+
ActiveDragAndDropManagers removeKey:device ifAbsent:nil.
- escapePressed ifFalse:[
- aHandler postDragging
- ].
- aView delegate:savedDelegate.
- aView cursor:savedCursor now:true.
- prevGrab notNil ifTrue:[
- aView forceUngrabPointer.
- prevGrab grabPointer.
- ] ifFalse:[
- aView ungrabPointer.
- ].
- prevKeyb notNil ifTrue:[
- aView forceUngrabKeyboard.
- prevKeyb grabKeyboard.
- ] ifFalse:[
- aView ungrabKeyboard.
+ escapePressed ifFalse:[ aHandler postDragging ].
+
+ saveContents notNil ifTrue:[
+ windowGroup preEventHook:(saveContents at:#preEventHook).
+ windowGroup postEventHook:(saveContents at:#postEventHook).
+ dragView cursor:(saveContents at:#cursor).
+ saveContents := nil.
].
].
-
- aHandler preDraggingIn:aView.
- aView delegate:self.
- prevGrab := device activePointerGrab.
- prevKeyb := device activeKeyboardGrab.
- aView grabPointer.
- aView grabKeyboard.
+ aHandler preDraggingIn:dragView.
"/ must wait for all pending motion events to arrive, and ignore them
- (sensor := aView sensor) notNil ifTrue:[
+ (sensor := dragView sensor) notNil ifTrue:[
device sync.
sensor flushMotionEventsFor:nil.
].
"/ start with a first draw at the current mouse position
- p := device pointerPosition.
- p := device translatePoint:p fromView:nil toView:aView.
- self buttonMotion:1 x:p x y:p y view:aView
-
- "Modified: / 10.10.2001 / 14:45:22 / cg"
+ screenPoint := device pointerPosition.
+ self buttonMotion:1 x:(screenPoint x) y:(screenPoint y) view:(device rootView).
!
forceGiveUp
@@ -1487,22 +1428,12 @@
handler rereadSaveArea.
handler restoreFromSaveArea.
].
-!
-
-xx
-
- Transcript showCR:([-3] on:Error do:[0]).
- Transcript showCR:([5 printString. 7] on:Error do:[])
-
-"
-self new xx
-"
! !
!DragAndDropManager class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.46 2003-01-18 14:28:36 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.47 2003-01-21 07:23:12 ca Exp $'
! !
DragAndDropManager initialize!