drag & drop offset
authorClaus Gittinger <cg@exept.de>
Mon, 11 Aug 1997 14:07:53 +0200
changeset 278 5b7dfe33b497
parent 277 935f9a055594
child 279 ef937b65a7f6
drag & drop offset
UIGalleryView.st
UIPainterView.st
--- a/UIGalleryView.st	Fri Aug 08 18:40:24 1997 +0200
+++ b/UIGalleryView.st	Mon Aug 11 14:07:53 1997 +0200
@@ -419,6 +419,37 @@
         DragAndDropManager startDrag:dragObj from:inputView.
     ]
 
+!
+
+startDragWithOffset:offs
+    "start drag of selection
+    "
+    |dragObj spec name o|
+
+    spec := self findSpecFor:selection.
+
+    spec notNil ifTrue:[
+        spec := self buildSpecFrom:spec.
+        name := spec className asString.
+        name := name copyFrom:1 to:(name size - ('Spec' size) + 1). 
+        name at:1 put:(name at:1) asLowercase.
+        name at:(name size) put:$1.
+        spec name:name.
+
+        self showUnselected.
+        dragObj := DropSpec for:selection specification:spec.
+        self showSelected.
+
+        o := lastClickPoint - selection origin.
+
+        DragAndDropManager 
+            startDrag:dragObj 
+            from:inputView
+            offset:o.
+    ]
+
+    "Created: 11.8.1997 / 00:44:17 / cg"
+    "Modified: 11.8.1997 / 00:48:35 / cg"
 ! !
 
 !UIGalleryView::Canvas methodsFor:'event handling'!
@@ -432,12 +463,12 @@
         sensor := self sensor.
         sensor anyButtonPressed ifTrue:[
             (lastClickPoint dist:(x@y)) > 10.0 ifTrue:[
-                ^ self startDrag
+                ^ self startDragWithOffset:(x@y) - lastClickPoint
             ]
         ]
     ]
 
-
+    "Modified: 11.8.1997 / 00:44:49 / cg"
 !
 
 buttonPress:button x:x y:y
--- a/UIPainterView.st	Fri Aug 08 18:40:24 1997 +0200
+++ b/UIPainterView.st	Mon Aug 11 14:07:53 1997 +0200
@@ -11,7 +11,8 @@
 "
 
 UIObjectView subclass:#UIPainterView
-	instanceVariableNames:'treeView listHolder superclassName className methodName categoryName'
+	instanceVariableNames:'treeView listHolder superclassName className methodName
+		categoryName'
 	classVariableNames:'HandCursor'
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -212,6 +213,18 @@
 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
     "add the specs to the object view; returns list of pasted components
     "
+
+    ^ self
+        pasteSpecifications:aSpecificationOrList 
+        keepLayout:keepLayout 
+        at:nil
+
+    "Modified: 11.8.1997 / 01:00:35 / cg"
+!
+
+pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil
+    "add the specs to the object view; returns list of pasted components
+    "
     |paste frame pasteOrigin pasteOffset builder newSel|
 
     (self canPaste:aSpecificationOrList) ifFalse:[
@@ -237,8 +250,12 @@
 
         keepLayout ifFalse:[
             pasteOffset := 0@0.
-            pasteOrigin := self sensor mousePoint.
-            pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
+            aPointOrNil isNil ifTrue:[
+                pasteOrigin := self sensor mousePoint.
+                pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
+            ] ifFalse:[
+                pasteOrigin := aPointOrNil
+            ].
         ].
 
         paste do:[:aSpec|
@@ -271,6 +288,9 @@
         self elementChangedSize:frame.
     ].
     ^ newSel
+
+    "Created: 11.8.1997 / 00:59:38 / cg"
+    "Modified: 11.8.1997 / 01:05:27 / cg"
 !
 
 pasteWithLayout
@@ -333,16 +353,21 @@
 !
 
 drop:anObjectOrCollection at:aPoint
-    |spec newSel oldSel|
+    |spec newSel oldSel dragOffset|
+
+Transcript showCR:aPoint.
 
     (oldSel := selection) isCollection ifTrue:[
         oldSel := selection copy
     ].
     spec := (anObjectOrCollection at:1) theObject.
-    newSel := self pasteSpecifications:spec keepLayout:false.
+    dragOffset := DragAndDropManager dragOffsetQuerySignal raise.
+    newSel := self pasteSpecifications:spec keepLayout:false at:aPoint - dragOffset.
 
     oldSel isNil ifTrue:[self select:newSel]
                 ifFalse:[self select:oldSel]
+
+    "Modified: 11.8.1997 / 01:07:09 / cg"
 ! !
 
 !UIPainterView methodsFor:'generating output'!