add more simple drag & drop functionality:
authorca
Mon, 09 Mar 1998 17:06:35 +0100
changeset 861 10bbb13fcb05
parent 860 99aac8d0e899
child 862 812e53d6c482
add more simple drag & drop functionality: support one icon for a set of drag objects
DragAndDropManager.st
--- a/DragAndDropManager.st	Mon Mar 09 17:05:51 1998 +0100
+++ b/DragAndDropManager.st	Mon Mar 09 17:06:35 1998 +0100
@@ -286,7 +286,7 @@
 startDrag:anObjectOrCollection from:aView
     "start a drop at the current pointer position"
 
-    (self new) startDrag:anObjectOrCollection from:aView offset:0@0
+    self startDrag:anObjectOrCollection from:aView offset:0@0 atEnd:nil
 
     "
      |o v|
@@ -302,12 +302,33 @@
     "
 
     "Modified: 19.4.1997 / 11:42:40 / cg"
+
+!
+
+startDrag:anObjectOrCollection from:aView atEnd:aFourArgEndBlock
+    "start a drop at the current pointer position
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+    self startDrag:anObjectOrCollection from:aView offset:0@0 atEnd:aFourArgEndBlock
+
+!
+
+startDrag:anObjectOrCollection from:aView atEnd:aFourArgEndBlock useIcon:anIcon
+    "start a drop at the current pointer position
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+    self startDrag:anObjectOrCollection from:aView offset:0@0 atEnd:aFourArgEndBlock useIcon:anIcon
+
 !
 
 startDrag:anObjectOrCollection from:aView offset:offset
     "start a drop at the current pointer position"
 
-    (self new) startDrag:anObjectOrCollection from:aView offset:offset
+    self startDrag:anObjectOrCollection from:aView offset:offset atEnd:nil
 
     "
      |o v|
@@ -323,6 +344,54 @@
     "
 
     "Modified: 19.4.1997 / 11:42:45 / cg"
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:offset atEnd:aFourArgEndBlock
+    "start a drop at the current pointer position
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+
+    (self new) startDrag:anObjectOrCollection from:aView offset:offset atEnd:aFourArgEndBlock
+
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:anOffset atEnd:aFourArgEndBlock useIcon:anIcon
+
+    (self new) startDrag:anObjectOrCollection
+                    from:aView
+                  offset:anOffset
+                   atEnd:aFourArgEndBlock
+                 useIcon:anIcon
+
+
+!
+
+startDrag:anObjectOrCollection from:aView useIcon:anIcon
+    "start a drop at the current pointer position"
+
+    self startDrag:anObjectOrCollection from:aView offset:0@0 atEnd:nil useIcon:anIcon
+
+    "
+     |o v|
+
+     v := (Button label:'press me').
+     v pressAction:[
+                |o|
+                o := DropObject newFile:('.').
+                DragAndDropManager startDrag:o from:v useIcon:(
+                    Image fromFile:('xpmBitmaps/cursors/hand_with_document.xpm')
+                ).
+                v turnOff
+              ].
+     v openAt:100@100
+    "
+
+    "Modified: 19.4.1997 / 11:42:40 / cg"
+
 !
 
 startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock
@@ -363,6 +432,14 @@
 
 !DragAndDropManager methodsFor:'accessing'!
 
+device
+    "returns the device of the source view
+    "
+    ^ dragView device
+
+
+!
+
 dropObjects
     "return the current dropObject collection"
 
@@ -381,6 +458,14 @@
     ].
 
     "Modified: 19.4.1997 / 10:19:33 / cg"
+!
+
+font
+    "returns the font of the source view
+    "
+    ^ dragView font
+
+
 ! !
 
 !DragAndDropManager methodsFor:'dragging - generic'!
@@ -788,10 +873,21 @@
 
 !DragAndDropManager methodsFor:'easy drag & drop'!
 
-startDrag:anObjectOrCollection from:aView offset:offset
+startDrag:anObjectOrCollection from:aView offset:anOffset
     "start a drop at the current pointer position"
 
-    |pos displayObjects device width height|
+    self startDrag:anObjectOrCollection from:aView offset:anOffset atEnd:nil
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:anOffset atEnd:aFourArgEndBlock
+    "start a drop at the current pointer position.
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+
+    |x y pos displayObjects device width height|
 
     self dropObjects:anObjectOrCollection.
 
@@ -804,12 +900,57 @@
     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
+    x := anOffset x.
+    y := anOffset y.
+
+    (displayObjects at:1) class == LabelAndIcon ifTrue:[
+        y := y + aView font ascent.
+        width := width * 2.
+    ].
+
+    self startOpaqueDrag:[:aPoint :aView|self showDragging:displayObjects in:aView at:(aPoint - anOffset)]
+                  offset:(x @ y)
                   extent:(width @ height)
                       in:aView
                       at:pos
-                   atEnd:nil.
+                   atEnd:aFourArgEndBlock.
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:anOffset atEnd:aFourArgEndBlock useIcon:anIcon
+    "start a drop at the current pointer position.
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+
+    |pos displayObjects device|
+
+    self dropObjects:anObjectOrCollection.
+
+    device := aView device.
+    pos    := device translatePoint:(device pointerPosition)
+                               from:(device rootView id) 
+                                 to:(aView id).
+
+    displayObjects := Array with:(anIcon on:device).
+
+    self startOpaqueDrag:[:aPoint :aView|self showDragging:displayObjects in:aView at:(aPoint - anOffset)]
+                  offset:anOffset
+                  extent:(anIcon extent)
+                      in:aView
+                      at:pos
+                   atEnd:aFourArgEndBlock.
+
+!
+
+startDrag:anObjectOrCollection from:aView offset:anOffset useIcon:anIcon
+    "start a drop at the current pointer position.
+     When finished, the endAction is called with four args:
+     the targetView, the targetViews windowID (useful, if its an alien view),
+     the dropPoint in root-coordinates and the dropPoint within the targetView"
+
+    self startDrag:anObjectOrCollection from:aView offset:anOffset atEnd:nil useIcon:anIcon
 ! !
 
 !DragAndDropManager methodsFor:'event catching'!
@@ -1192,6 +1333,6 @@
 !DragAndDropManager class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.17 1997-08-11 12:03:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.18 1998-03-09 16:06:35 ca Exp $'
 ! !
 DragAndDropManager initialize!