--- a/DragAndDropManager.st Fri Jan 31 18:57:46 1997 +0100
+++ b/DragAndDropManager.st Fri Jan 31 18:59:54 1997 +0100
@@ -1,12 +1,19 @@
Object subclass:#DragAndDropManager
instanceVariableNames:'dragView motionAction releaseAction initialPoint previousPoint
rememberedDelegate dragBlock lineMode dropAction opaque saveUnder
- dragSize dragOffset dropObject saveCursor lastView'
+ dragSize dragOffset dropObjects saveCursor lastView'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
!
+View subclass:#DemoView
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:DragAndDropManager
+!
+
View subclass:#DemoView2
instanceVariableNames:''
classVariableNames:''
@@ -21,13 +28,6 @@
privateIn:DragAndDropManager
!
-View subclass:#DemoView
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:''
- privateIn:DragAndDropManager
-!
-
!DragAndDropManager class methodsFor:'documentation'!
documentation
@@ -46,10 +46,63 @@
"Modified: 26.10.1996 / 15:21:42 / cg"
! !
+!DragAndDropManager class methodsFor:'simple start'!
+
+startDrag:anObjectOrCollection from:aView
+ "start a drop at the current pointer position"
+
+ (self new) startDrag:anObjectOrCollection from:aView offset:0@0
+
+
+ "
+ |o v|
+
+ v := (Button label:'press me').
+ v pressAction:[
+ |o|
+ o := DropObject newFile:('.').
+ DragAndDropManager startDrag:o from:v.
+ v turnOff
+ ].
+ v openAt:100@100
+ "
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:offset
+ "start a drop at the current pointer position"
+
+ (self new) startDrag:anObjectOrCollection from:aView offset:offset
+
+
+ "
+ |o v|
+
+ v := (Button label:'press me').
+ v pressAction:[
+ |o|
+ o := DropObject newFile:('.').
+ DragAndDropManager startDrag:o from:v offset:10@10.
+ v turnOff
+ ].
+ v openAt:100@100
+ "
+
+! !
+
!DragAndDropManager methodsFor:'accessing'!
-dropObject:aDropObject
- dropObject := aDropObject
+dropObjects
+ ^ dropObjects
+!
+
+dropObjects:anObjectOrCollection
+
+ anObjectOrCollection isCollection ifTrue:[
+ dropObjects := anObjectOrCollection
+ ] ifFalse:[
+ dropObjects := Array with:anObjectOrCollection
+ ].
! !
!DragAndDropManager methodsFor:'dragging - generic'!
@@ -68,10 +121,16 @@
view := self destinationViewAt:previousPoint.
view ~~ lastView ifTrue:[
- (view notNil and:[view canDrop:dropObject]) ifTrue:[
- dragView cursor:(Cursor thumbsUp) now:true.
+ view isNil ifTrue:[
+ "/ alien view
+ dragView cursor:(Cursor questionMark) now:true
] ifFalse:[
- dragView cursor:(Cursor thumbsDown) now:true
+ "/ ST/X view
+ (view canDrop:dropObjects) ifTrue:[
+ dragView cursor:(Cursor thumbsUp) now:true.
+ ] ifFalse:[
+ dragView cursor:(Cursor thumbsDown) now:true
+ ]
].
lastView := view
].
@@ -373,6 +432,53 @@
! !
+!DragAndDropManager methodsFor:'drawing'!
+
+showDragging:items in:aView at:p
+ |offs|
+
+ items size > 1 ifTrue:[
+ offs := 0.
+ items do:[:item |
+ item displayOn:aView at:p + (0@offs).
+ offs := offs + (item heightOn:self)
+ ]
+ ] ifFalse:[
+ items first displayOn:aView at:p.
+ ]
+
+ "Created: 14.11.1996 / 15:31:31 / cg"
+ "Modified: 14.11.1996 / 16:32:00 / cg"
+
+
+! !
+
+!DragAndDropManager methodsFor:'easy drag & drop'!
+
+startDrag:anObjectOrCollection from:aView offset:offset
+ "start a drop at the current pointer position"
+
+ |pos displayObjects device width height|
+
+ self dropObjects:anObjectOrCollection.
+
+ device := aView device.
+ pos := device translatePoint:(device pointerPosition)
+ from:(device rootView id)
+ to:(aView id).
+
+ displayObjects := dropObjects collect:[:each | each displayObject on:device].
+ height := displayObjects inject:0 into:[:sum :each | sum + (each heightOn:aView)].
+ width := displayObjects inject:0 into:[:max :each | max max:(each widthOn:aView)].
+
+ self startOpaqueDrag:[:aPoint :aView|self showDragging:displayObjects in:aView at:(aPoint - offset)]
+ offset:offset
+ extent:(width @ height)
+ in:aView
+ at:pos
+ atEnd:nil.
+! !
+
!DragAndDropManager methodsFor:'event catching'!
buttonMotion:button x:x y:y view:aView
@@ -525,8 +631,9 @@
].
dropAction isNil ifTrue:[
- (destinationView notNil and:[destinationView canDrop:dropObject]) ifTrue:[
- destinationView drop:dropObject to:destinationPoint
+ "/ XXX add external clipboard mechanism via display
+ (destinationView notNil and:[destinationView canDrop:dropObjects]) ifTrue:[
+ destinationView drop:dropObjects to:destinationPoint
].
^ self
].
@@ -544,6 +651,32 @@
! !
+!DragAndDropManager::DemoView methodsFor:'events'!
+
+buttonPress:button x:x y:y
+ DragAndDropManager new
+ startLineDragIn:self at:(x@y)
+ atEnd:[:view
+ :viewID
+ :rootPoint
+ :viewPoint |
+
+ Transcript show:'dropped at ';
+ show:viewPoint;
+ show:' in '.
+ view notNil ifTrue:[
+ Transcript showCR:view
+ ] ifFalse:[
+ Transcript show:'alien view ';
+ showCR:viewID address
+ ]
+ ].
+
+ "
+ self new open
+ "
+! !
+
!DragAndDropManager::DemoView2 methodsFor:'events'!
buttonPress:button x:x y:y
@@ -580,34 +713,8 @@
"
! !
-!DragAndDropManager::DemoView methodsFor:'events'!
-
-buttonPress:button x:x y:y
- DragAndDropManager new
- startLineDragIn:self at:(x@y)
- atEnd:[:view
- :viewID
- :rootPoint
- :viewPoint |
-
- Transcript show:'dropped at ';
- show:viewPoint;
- show:' in '.
- view notNil ifTrue:[
- Transcript showCR:view
- ] ifFalse:[
- Transcript show:'alien view ';
- showCR:viewID address
- ]
- ].
-
- "
- self new open
- "
-! !
-
!DragAndDropManager class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.7 1997-01-31 16:01:33 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.8 1997-01-31 17:59:54 ca Exp $'
! !