can resize - allow resizing all;
authorClaus Gittinger <cg@exept.de>
Fri, 20 Jun 2008 11:38:50 +0200
changeset 2362 a6a7ef98fdc3
parent 2361 ae171f5bc002
child 2363 4c74ed85b3a4
can resize - allow resizing all; pasting: care for layout; paste ontop of original
UIPainterView.st
--- a/UIPainterView.st	Fri Jun 20 11:38:28 2008 +0200
+++ b/UIPainterView.st	Fri Jun 20 11:38:50 2008 +0200
@@ -254,15 +254,13 @@
 copySelection
     "copy the selection into the cut & paste-buffer"
 
-    |specs coll sel|
-
-    sel := treeView selection.
+    |specs coll|
 
     coll := self minClosedViewSetFor:(self selection).
 
     coll notNil ifTrue:[
 "/        self select:nil.
-        specs := coll collect:[:aView| self fullSpecFor:aView ].
+        specs := coll collect:[:eachView | self fullSpecWithAbsolutePositionFor:eachView].
         self setClipboardObject:specs.
 "/        treeView selection: sel
     ].
@@ -305,7 +303,7 @@
 
             self hideSelection.
             selection := nil.
-            specs := specsToRemove collect:[:aView| self fullSpecFor:aView ].
+            specs := specsToRemove collect:[:aView| self fullSpecWithAbsolutePositionFor:aView ].
 
             self withinTransaction:#cut objects:specsToRemove do:[
                 specsToRemove reverseDo:[:aView|
@@ -351,8 +349,13 @@
 
     |sel clipboard|
 
+    self enabled ifFalse:[
+        Dialog warn:'Operation currently disabled (In geometry test mode)'.
+        ^ self
+    ]. 
+
     clipboard := self getClipboardObject.
-    sel := self pasteSpecifications:clipboard keepLayout:(clipboard size > 1).
+    sel := self pasteSpecifications:clipboard keepLayout:true "(clipboard size > 1)".
     self changeSelectionAfterPasteOf:sel.
 !
 
@@ -378,6 +381,7 @@
     ^ self
         pasteSpecifications:aSpecificationOrList
         keepLayout:keepLayout
+        keepPosition:true
         at:nil
 
     "Modified: 11.8.1997 / 01:00:35 / cg"
@@ -389,18 +393,34 @@
     ^ self
         pasteSpecifications:aSpecificationOrList
         keepLayout:keepLayout
-        keepPosition:false
+        keepPosition:true
         at:aPointOrNil
 !
 
 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil
     "add the specs to the object view; returns list of pasted widgets"
 
-    |specsToPaste pasteOrigin pasteOffset builder newSel bounds containerToPasteInto|
+    |specsToPaste pasteOffset builder newSel 
+     bounds containerToPasteInto pastePoint|
 
     treeView askForSelectionChangeAllowed ifFalse:[^ nil].
 
-    containerToPasteInto := self singleSelection.
+    (self window sensor shiftDown
+    or:[ self window sensor ctrlDown ]) ifTrue:[
+        "/ paste into the selection
+        containerToPasteInto := self singleSelection.
+    ] ifFalse:[
+        "/ ignore the selection and paste where we drop!!
+        pastePoint := aPointOrNil.
+        pastePoint isNil ifTrue:[
+            pastePoint := device 
+                                translatePoint:(self sensor mousePoint)
+                                fromView:nil
+                                toView:self.
+        ].
+        containerToPasteInto := self findObjectAt:pastePoint
+    ].
+
     containerToPasteInto isNil ifTrue:[
         self selection size > 0 ifTrue:[
             containerToPasteInto := self commonContainerOf:self selection
@@ -410,17 +430,12 @@
 "/        self selection:containerToPasteInto.
     ].
 
-    (self canPasteInto:containerToPasteInto) ifFalse:[
-        containerToPasteInto notNil ifTrue:[
-            "/ search up parent list for something we can paste into
-            [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[
-                containerToPasteInto == self ifTrue:[
-                    containerToPasteInto := nil
-                ] ifFalse:[
-                    containerToPasteInto := containerToPasteInto container.
-                ].
-            ].
-"/            self selection:containerToPasteInto.
+    "/ search up parent list for something we can paste into
+    [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[
+        containerToPasteInto == self ifTrue:[
+            containerToPasteInto := nil
+        ] ifFalse:[
+            containerToPasteInto := containerToPasteInto container.
         ].
     ].
     containerToPasteInto isNil ifTrue:[
@@ -429,7 +444,11 @@
 
     (self canPaste:aSpecificationOrList into:containerToPasteInto)
     ifFalse:[
-        Dialog warn:'Cannot paste into selected component (not a container ?)'.
+        self enabled ifTrue:[
+            Dialog warn:'Cannot paste into selected component (not a container ?)'.
+        ] ifFalse:[
+            Dialog warn:'Operation currently disabled (In Geometry test mode)'.
+        ]. 
         ^ nil
     ].
 
@@ -446,46 +465,38 @@
     className notNil ifTrue:[
         builder applicationClass:(self resolveName:className)
     ].
-
-    (keepLayout not or:[keepPosition]) ifTrue:[
-        pasteOffset := 0@0.
-
-        keepPosition ifTrue:[
-            pasteOrigin := device translatePoint:0@0
-                                  fromView:self
-                                  toView:containerToPasteInto.
-        ] ifFalse:[
-            aPointOrNil isNil ifTrue:[
-                pasteOrigin := device translatePoint:(self sensor mousePoint)
-                                            fromView:nil
-                                              toView:containerToPasteInto.
-            ] ifFalse:[
-                pasteOrigin := device translatePoint:aPointOrNil
-                                            fromView:self
-                                              toView:containerToPasteInto.
-            ]
-        ].
-
-        bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent)
-    ].
+    bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent).
+
+    pasteOffset := 0.
 
     specsToPaste do:[:eachSpec|
-        |view newOrigin|
+        |view newOrigin uiPainterAttributes thisAbsOrigin|
+
+        uiPainterAttributes := eachSpec otherAttributeAt:#uiPainterAttributes.
+        eachSpec otherAttributeAt:#uiPainterAttributes put:nil.
 
         view := self addSpec:eachSpec builder:builder in:containerToPasteInto.
 
         keepPosition ifTrue:[
-            self moveObject:view to:(view origin + pasteOrigin).
+            thisAbsOrigin := uiPainterAttributes at:#absOrigin.
+            newOrigin := device 
+                                translatePoint:thisAbsOrigin
+                                fromView:self
+                                toView:containerToPasteInto.
         ] ifFalse:[
-            keepLayout ifFalse:[
-                (bounds containsPoint:pasteOrigin) ifFalse:[
-                    newOrigin := pasteOffset.
-                ] ifTrue:[
-                    newOrigin := pasteOrigin + pasteOffset.
-                ].
-                self moveObject:view to:newOrigin.
-                pasteOffset := pasteOffset + 4
-            ].
+            pastePoint isNil ifTrue:[ pastePoint := 0@0 ].
+            newOrigin := device 
+                                translatePoint:pastePoint
+                                fromView:self
+                                toView:containerToPasteInto.
+        ].
+
+        (bounds containsPoint:newOrigin) ifFalse:[
+            newOrigin := pasteOffset asPoint.
+            pasteOffset := pasteOffset + 4.
+        ].
+        newOrigin notNil ifTrue:[
+            self moveObject:view to:newOrigin.
         ].
         view realize.
         newSel add:view.
@@ -601,10 +612,11 @@
 canDropObjects:aCollectionOfDropObjects
     "returns true if something can be dropped"
 
-    ^ (aCollectionOfDropObjects size == 1 
+    ^ (true "aCollectionOfDropObjects size == 1" 
     and:[ self enabled 
-    and:[ self numberOfSelections <= 1
-    and:[ aCollectionOfDropObjects first theObject isKindOf:UISpecification ]]])
+    and:[ true "self numberOfSelections <= 1"
+    and:[ aCollectionOfDropObjects conform:[:each| each theObject isKindOf:UISpecification]
+              ]]])
 
     "Created: / 13-10-2006 / 16:09:24 / cg"
 !
@@ -674,7 +686,7 @@
     spec := (aCollectionOfDropObjects at:1) theObject.
     doit ifTrue:[
         dragOffset := DragAndDropManager dragOffsetQuerySignal query.
-        newSel := self pasteSpecifications:spec keepLayout:false at:aPoint - dragOffset.
+        newSel := self pasteSpecifications:spec keepLayout:false keepPosition:false at:aPoint - dragOffset.
 
         self select:(oldSel ? newSel)
     ].
@@ -2042,8 +2054,8 @@
     |view prop|
 
     view := super findObjectAt:aPoint.
+    "/ stupid check, if I know about this view
     prop := self propertyOfView:view.
-
     prop notNil ifTrue:[^ prop view].
     ^ nil
 !
@@ -2283,36 +2295,44 @@
     "Modified: 4.7.1997 / 23:48:55 / cg"
 !
 
-fullSpecFor:anObject
+fullSpecFor:aView
     "generate a full spec for an object
     "
     |mySpec subSpecs|
 
-    mySpec := self specFor:anObject.
+    mySpec := self specFor:aView.
 
     (mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[
-	(anObject subViews notNil) ifTrue:[
-	    anObject subViews do:[:aSubView||spec|
-		spec := self fullSpecFor:aSubView.
-		spec notNil ifTrue:[
-		    subSpecs isNil ifTrue:[
-			subSpecs := OrderedCollection new
-		    ].
-		    subSpecs add:spec.
-		].
-	    ].
-	    subSpecs notNil ifTrue:[
-		mySpec component:(SpecCollection new collection:subSpecs)
-	    ]
-	]
+        (aView subViews notNil) ifTrue:[
+            aView subViews do:[:aSubView||spec|
+                spec := self fullSpecFor:aSubView.
+                spec notNil ifTrue:[
+                    subSpecs isNil ifTrue:[
+                        subSpecs := OrderedCollection new
+                    ].
+                    subSpecs add:spec.
+                ].
+            ].
+            subSpecs notNil ifTrue:[
+                mySpec component:(SpecCollection new collection:subSpecs)
+            ]
+        ]
     ].
     ^ mySpec
-
-
-
-
-
-
+!
+
+fullSpecWithAbsolutePositionFor:aView
+    |spec|
+
+    spec := self fullSpecFor:aView.
+    spec 
+        otherAttributeAt:#uiPainterAttributes 
+        put:(Dictionary new
+                at:#origin put:aView origin;
+                at:#extent put:aView extent;
+                at:#absOrigin put:(aView originRelativeTo:self);
+                yourself).
+    ^ spec
 !
 
 rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil
@@ -2374,14 +2394,15 @@
     ].
 !
 
-specFor:anObject
-    "returns spec assigned to an object
-    "
+specFor:aView
+    "returns a copy of the spec assigned to an object"
+
     |prop spec|
 
-    (prop := self propertyOfView:anObject) isNil ifTrue:[^ nil].
+    (prop := self propertyOfView:aView) isNil ifTrue:[^ nil].
+
     spec := prop spec copy.
-    spec layoutFromView:anObject.
+    spec layoutFromView:aView.
     ^ spec
 !
 
@@ -2429,17 +2450,34 @@
 !UIPainterView methodsFor:'testing'!
 
 canChangeLayoutOfView:aView
-    "returns true if the view can change its layout which is dependant on
-     its parent view.
-    "
-    |item prnt|
-
-    (     (item := treeView itemOfView:aView) isNil
-      or:[(prnt := item parent) isNil]
-    ) ifTrue:[
-	^ false
+    "returns true if the view can change its layout.
+     This is dependent on its parent view."
+
+    |item parent granny|
+
+    item := treeView itemOfView:aView.
+    item isNil ifTrue:[
+        "/ I dont know anything about that view (cg: how can this happen ?)
+        "/ self breakPoint:#cg.
+        ^ false
     ].
-    ^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not])
+    parent := item parent.
+    parent isNil ifTrue:[
+        "/ that view has no parent (cg: does this mean its the canvas itself ?)
+        "/ self breakPoint:#cg.
+        ^ false
+    ].
+    granny := parent parent.
+    granny isNil ifTrue:[
+        "/ cg: why that ?
+        "/ self breakPoint:#cg.
+        ^ true
+    ].
+    parent contents spec class isLayoutContainer ifTrue:[
+        "/ self breakPoint:#cg.
+        ^ false
+    ].
+    ^ true
 !
 
 canExchangeSelectionLayouts
@@ -2467,10 +2505,10 @@
      something can change their layout ( move, align, ... operation ).
     "
     something notNil ifTrue:[
-	self forEach:something do:[:aView|
-	    (self canChangeLayoutOfView:aView) ifFalse:[^ false]
-	].
-	^ true
+        self forEach:something do:[:aView|
+            (self canChangeLayoutOfView:aView) ifFalse:[^ false]
+        ].
+        ^ true
     ].
     ^ false
 !
@@ -2479,8 +2517,7 @@
     "returns true if a selection exists and all elements in the selection
      can be moved or aligned
     "
-  ^ self canMove:(self selection)
-
+    ^ self canMove:(self selection)
 ! !
 
 !UIPainterView methodsFor:'transaction'!
@@ -2495,8 +2532,8 @@
 !
 
 withinTransaction:aType objects:objects do:aNoArgBlock
-    "evaluate a block with no arguments within a transaction
-    "
+    "evaluate a block within a transaction"
+
     |text size prop|
 
     objects isNil ifTrue:[ ^ self ].
@@ -2505,7 +2542,9 @@
 
     objects isCollection ifTrue:[
         size == 0 ifTrue:[ ^ self ].
-        size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ]
+        size == 1 ifTrue:[ 
+            prop := self propertyOfView:(objects first) 
+        ]
     ] ifFalse:[
         prop := self propertyOfView:objects
     ].