clicking on an already selected object for move
authorClaus Gittinger <cg@exept.de>
Fri, 13 Jun 2008 10:22:29 +0200
changeset 2356 bb961692c387
parent 2355 72444ef06dcf
child 2357 48ed61c2825e
clicking on an already selected object for move may not search for clicked object again. Otherwise, overlapping widgets sometimes cannot be moved
UIObjectView.st
--- a/UIObjectView.st	Thu Jun 05 14:32:57 2008 +0200
+++ b/UIObjectView.st	Fri Jun 13 10:22:29 2008 +0200
@@ -859,61 +859,76 @@
 !
 
 startSelectOrMove:aPoint
-    "a button is pressed at a point; start moving or selection
-    "
-    |aView b v|
+    "a button is pressed at a point; start moving or selecting"
+
+    |selectedView containerOfSelectedView
+     clickedView viewOperatedUpon b pView|
 
     self enabled ifFalse:[^ self].
 
-    aView := self singleSelection.
-
-    aView notNil ifTrue:[
-	v := self findContainerOfView:aView.
-
-	v specClass canResizeSubComponents ifTrue:[
-	    b := self whichHandleOf:aView isHitBy:aPoint.
-
-	    (b notNil and:[b ~~ #view]) ifTrue:[
-		^ self startResizeBorder:b of:aView.
-	    ]
-	].
-
-	(self sensor ctrlDown and:[self canChangeLayoutOfView:aView]) ifFalse:[
-	    aView := nil
-	]
+    selectedView := self singleSelection.
+    clickedView := self findObjectAt:aPoint.
+
+    (clickedView isComponentOf:selectedView) ifTrue:[
+        self unselect.
+        selectedView := nil.    
     ].
 
-    aView isNil ifTrue:[
-	(aView := self findObjectAt:aPoint) isNil ifTrue:[
-	    ^ self select:nil
-	].
-
-	(self canChangeLayoutOfView:aView) ifFalse:[
-	    ^ self select:aView
-	]
+    selectedView notNil ifTrue:[
+        containerOfSelectedView := self findContainerOfView:selectedView.
+
+        containerOfSelectedView specClass canResizeSubComponents ifTrue:[
+            b := self whichHandleOf:selectedView isHitBy:aPoint.
+            (b notNil and:[b ~~ #view]) ifTrue:[
+                self startResizeBorder:b of:selectedView.
+                ^ self
+            ]
+        ].
+        viewOperatedUpon := selectedView.
+
+        pView := device translatePoint:aPoint fromView:self toView:selectedView superView.
+        (selectedView bounds containsPoint:pView) ifFalse:[
+            "/ clicked outside the selection
+            (self sensor ctrlDown and:[self canChangeLayoutOfView:selectedView]) ifFalse:[
+                viewOperatedUpon := nil
+            ]
+        ]
     ].
 
-    (self isSelected:aView) ifFalse:[
-	self select:aView.
+    viewOperatedUpon isNil ifTrue:[
+        clickedView isNil ifTrue:[
+            self select:nil.
+            ^ self.
+        ].
+
+        (self canChangeLayoutOfView:clickedView) ifFalse:[
+            self select:clickedView.
+            ^ self
+        ].
+        viewOperatedUpon := clickedView
+    ].
+
+    (self isSelected:viewOperatedUpon) ifFalse:[
+        self select:viewOperatedUpon.
     ].
 
     (self numberOfSelections ~~ 1) ifTrue:[
-	releaseAction := [
-	    self setDefaultActions.
-	    self select:aView
-	]
+        releaseAction := 
+            [
+                self setDefaultActions.
+                self select:viewOperatedUpon
+            ]
     ] ifFalse:[
-	releaseAction := [self setDefaultActions]
+        releaseAction := [self setDefaultActions]
     ].
 
-    "prepare move operation for an object
-    "
-
-    motionAction := [:movePoint|
-	(aPoint dist:movePoint) > 8.0 ifTrue:[
-	    self startObjectMoveAt:aPoint
-	]
-    ].
+    "prepare move operation for an object"
+    motionAction := 
+        [:movePoint|
+            (aPoint dist:movePoint) > 4.0 ifTrue:[
+                self startObjectMoveAt:aPoint
+            ]
+        ].
 ! !
 
 !UIObjectView methodsFor:'object resize'!
@@ -1187,8 +1202,6 @@
 !UIObjectView methodsFor:'searching'!
 
 findObjectAt:aPoint
-    "find the origin/corner of the currentWidget
-    "
     |view viewId lastId point|
 
     point  := aPoint + (device translatePoint:0@0 fromView:self toView:rootView).
@@ -1376,33 +1389,6 @@
 
 ! !
 
-!UIObjectView methodsFor:'selections basic'!
-
-setSelection:newSelection withRedraw:doRedraw
-    "set a new selection without change notifications"
-
-    | sel |
-
-    (sel := newSelection) == self ifTrue:[
-        sel := nil
-    ].
-
-    doRedraw ifTrue:[
-        self hideSelection.
-        selection := sel.
-
-        self forEach:selection do:[:aView |
-            |superView|
-
-            superView := aView superView. 
-            self recomputeShapeIfTransparentBox:superView.
-        ].
-        self showSelection.
-    ] ifFalse:[
-        selection := sel
-    ]
-! !
-
 !UIObjectView methodsFor:'selections-basic'!
 
 recursiveRepair:theDamages startIn:aView
@@ -1490,6 +1476,31 @@
 
 !
 
+setSelection:newSelection withRedraw:doRedraw
+    "set a new selection without change notifications"
+
+    | sel |
+
+    (sel := newSelection) == self ifTrue:[
+        sel := nil
+    ].
+
+    doRedraw ifTrue:[
+        self hideSelection.
+        selection := sel.
+
+        self forEach:selection do:[:aView |
+            |superView|
+
+            superView := aView superView. 
+            self recomputeShapeIfTransparentBox:superView.
+        ].
+        self showSelection.
+    ] ifFalse:[
+        selection := sel
+    ]
+!
+
 showUnselected:something
     "show a component ot list of components unselected
     "
@@ -1771,29 +1782,29 @@
     |sensor tm|
 
     self moveableSelection isNil ifTrue:[
-	^ self
+        ^ self
     ].
     sensor := self sensor.
 
     tm := 0.15.
 
     self withSelectionHiddenDo:[
-	self transaction:#move selectionDo:[:aView|self createUndoLayout:aView].
-
-	[
-	    self selectionDo:[:aView| aOneArgBlock value:aView ].
-	    Delay waitForSeconds:tm.
-	    tm := 0.02.
-	    self layoutChanged.
-	    sensor leftButtonPressed.
-	] whileTrue.
-
-	"/ handle any expose events (for subcomponents) before
-	"/ redrawing the handles.
-	Delay waitForSeconds:0.05.
-	[self sensor hasExposeEventFor:nil] whileTrue:[
-	    self windowGroup processExposeEvents
-	]
+        self transaction:#move selectionDo:[:aView|self createUndoLayout:aView].
+
+        [
+            self selectionDo:[:aView| aOneArgBlock value:aView ].
+            Delay waitForSeconds:tm.
+            tm := 0.02.
+            self layoutChanged.
+            sensor leftButtonPressed.
+        ] whileTrue.
+
+        "/ handle any expose events (for subcomponents) before
+        "/ redrawing the handles.
+        Delay waitForSeconds:0.1.
+        [self sensor hasExposeEventFor:nil] whileTrue:[
+            self windowGroup processExposeEvents
+        ]
     ].
 !
 
@@ -1858,15 +1869,14 @@
 !
 
 moveSelectionRight
-    "move selection right
-    "
+    "move the selection to the right"
+
     self moveSelectionRight:1
-
 !
 
 moveSelectionRight:howMany
-    "move selection right
-    "
+    "move selection to the right by howMany pixels"
+
     |gridX n|
 
     gridAlign notNil ifTrue:[gridX := gridAlign x]