UIObjectView.st
changeset 49 7f58dd5fc836
parent 47 5e4319953a0b
child 50 fb4359c9bdc4
--- a/UIObjectView.st	Fri Feb 14 18:20:05 1997 +0100
+++ b/UIObjectView.st	Sat Feb 15 19:14:01 1997 +0100
@@ -1,7 +1,7 @@
 ObjectView subclass:#UIObjectView
 	instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject
 		resizeSelector createInWidget createFrame createdObject
-		createClass'
+		createClass clipChildren'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -109,139 +109,6 @@
 
 ! !
 
-!UIObjectView methodsFor:'cut & paste'!
-
-convertForPaste:something
-    Transcript showCR:'convertForPaste'.
-    ^ nil
-
-
-!
-
-deleteSelection
-    "delete the selection
-    "
-    undoHistory transactionNamed:'delete' do:[
-        super deleteSelection
-    ].
-
-! !
-
-!UIObjectView methodsFor:'dragging object move'!
-
-doObjectMove:aPoint
-    "move selection
-    "
-
-    selection isCollection ifTrue:[^ self].
-
-    movedObject isNil ifTrue:[
-        (movedObject := selection) isNil ifTrue:[
-            ^ self
-        ].
-        super unselect.
-        moveDelta := aPoint - movedObject computeOrigin.
-        self invertOutlineOf:movedObject
-    ].
-
-    self moveObject:movedObject to:(aPoint - moveDelta)
-
-
-!
-
-endObjectMove
-    "cleanup after object move"
-
-    movedObject notNil ifTrue:[
-        self invertOutlineOf:movedObject.
-        self setDefaultActions.
-        self select:movedObject.
-        movedObject := nil
-    ].
-
-    "Modified: 5.9.1995 / 12:20:31 / claus"
-
-
-!
-
-startObjectMove:aView at:aPoint
-
-    super startObjectMove:aView at:aPoint.
-
-    aView notNil ifTrue:[
-        undoHistory transactionNamed:'move' do:[
-            self undoBlockPositionChanged:aView
-        ]
-    ]
-
-
-!
-
-startSelectMoreOrMove:aPoint
-    "add/remove to/from selection"
-
-    |anObject|
-
-    testMode ifTrue:[^ self].
-
-    anObject := self findObjectAtVisible:aPoint.
-    anObject notNil ifTrue:[
-        (self isSelected:anObject) ifTrue:[
-            self removeFromSelection:anObject
-        ] ifFalse:[
-            self addToSelection:anObject
-        ]
-    ]
-!
-
-startSelectOrMove:aPoint
-    "a button is pressed at a point
-    "
-    |anObject b|
-
-    testMode ifTrue:[^ self].
-
-    "if there is one selection and point hits handle, start a resize
-    "
-    self singleSelection notNil ifTrue:[
-        b := self whichHandleOf:selection isHitBy:aPoint.
-
-        (b notNil and:[b ~~ #view]) ifTrue:[
-            ^ self startResizeBorder:b of:selection at:aPoint.
-        ]
-    ].
-
-    anObject := self findObjectAtVisible:aPoint.
-
-    "nothing is selected
-    "
-    anObject isNil ifTrue:[
-        ^ self unselect
-    ].
-
-    "object not in selection; clear selection and add anObject to selection
-    "
-    (self isSelected:anObject) ifFalse:[
-        super unselect.
-        self select:anObject.
-    ] ifTrue:[
-        selection isCollection ifTrue:[
-            ^ self removeFromSelection:anObject.
-        ]
-    ].
-
-    "prepare move operation for an object
-    "
-    motionAction := [:movePoint|
-        (aPoint dist:movePoint) > 2.0 ifTrue:[
-            self startObjectMove:anObject at:aPoint
-        ]
-    ].
-    releaseAction := [self setDefaultActions].
-
-
-! !
-
 !UIObjectView methodsFor:'event handling'!
 
 doKeyInput:key
@@ -346,6 +213,8 @@
     inputView enableButtonEvents.
     inputView enableButtonMotionEvents.
 
+    self setDefaultActions.
+
     undoHistory := UndoHistory new.
 
     undoHistory modifiedAction:[:what|
@@ -353,6 +222,7 @@
     ].
 
     testMode := false.
+    clipChildren := true.
 
     (self class gridShown) ifTrue:[
         super showGrid
@@ -378,20 +248,38 @@
 !
 
 invertOutlineOf:anObject
-    |delta|
+    |wasClipped delta|
 
-    self clippedByChildren:false.
+    (wasClipped := clipChildren) ifTrue:[
+        self clippedByChildren:(clipChildren := false).
+    ].
     delta := (anObject originRelativeTo:self) - anObject origin.
+
     self xoring:[
         self displayRectangle:((anObject origin + delta) extent:anObject extent).
     ].
-    self clippedByChildren:true.
+
+    wasClipped ifTrue:[
+        self clippedByChildren:(clipChildren := true).
+    ].
 
     "Modified: 5.9.1995 / 12:25:25 / claus"
 
 
 !
 
+setDefaultActions
+
+    pressAction      := [:pressPoint | self startSelectOrMove:pressPoint].
+    shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint].
+    motionAction     := [:movePoint  | nil].
+    releaseAction    := [nil].
+    keyPressAction   := [:key | self doKeyInput:key].
+
+    self cursor:Cursor normal.
+
+!
+
 showDragging:something offset:anOffset
     "drag around a View"
 
@@ -429,60 +317,57 @@
 endCreate
     "end a widget create drag
     "
+    |layout x y|
+
     self invertOutlineOf:createdObject.
-    self cursor:oldCursor.
     inputView raise.
 
-    createdObject geometryLayout:(createdObject bounds asLayout).
+    layout := createdObject bounds asLayout.
+    createdObject geometryLayout:layout.
 
     self changed:#tree.
     self select:createdObject.
     createdObject := nil.
 
-    pressAction   := [:pressPoint | self startSelectOrMove:pressPoint].
-    motionAction  := [:movePoint | true].
-    releaseAction := [ true ].
-
-    self cursor:Cursor normal.
-
+    self setDefaultActions.
 
 !
 
-initializeCreatedObject:anObject
+setupCreatedObject:anObject
     self subclassResponsibility
 !
 
 startCreate:aPoint
     "start a widget create
     "
-    |props index startPoint|
+    |startPoint|
 
     createClass isNil ifTrue:[
-        ^ self
+        ^ self setDefaultActions
+    ].
+    (selection isKindOf:Collection) ifTrue:[
+        self unselect.
+      ^ self setDefaultActions.
     ].
 
     startPoint    := self alignToGrid:aPoint.
-    motionAction  := [:movePoint | self doDragCreate:movePoint].
-    releaseAction := [self endCreate].
+    motionAction  := [:movePoint| self doDragCreate:movePoint].
+    releaseAction := [ self endCreate].
 
-    (selection isNil or:[selection isKindOf:Collection]) ifTrue:[
-        createInWidget := self findObjectIn:self at:aPoint
-    ] ifFalse:[
-        createInWidget := self findObjectIn:selection at:aPoint
+    selection notNil ifTrue:[
+        (    (self isPoint:aPoint containedIn:selection)
+         and:[selection specClass basicNew supportsSubComponents]
+        ) ifFalse:[
+            self unselect
+        ]
     ].
-    super unselect.
-    self select:createInWidget.
 
     oldCursor := cursor.
     self cursor:(Cursor leftHand).
 
-    createInWidget isNil ifTrue:[
-        createdObject  := createClass in:self.
-        createInWidget := self.
-    ] ifFalse:[
-        createdObject := createClass new.
-        createInWidget addSubView:createdObject.
-    ].
+    createInWidget := selection ? self.
+    createdObject  := createClass new.
+    createInWidget addSubView:createdObject.
 
     createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self))
                              corner:startPoint.
@@ -490,12 +375,138 @@
     createdObject origin:(createFrame origin).
 
     undoHistory transactionNamed:'create' do:[
-        self initializeCreatedObject:createdObject.
+        self setupCreatedObject:createdObject.
     ].
     createdObject realize.
     self invertOutlineOf:createdObject.
 ! !
 
+!UIObjectView methodsFor:'object moving'!
+
+doObjectMove:aPoint
+    "move selection
+    "
+    movedObject notNil ifTrue:[
+        movedObject keysAndValuesDo:[:nr :aView|
+            self invertOutlineOf:aView.
+            self moveObject:aView to:(aPoint - (moveDelta at:nr)).
+            self invertOutlineOf:aView.
+        ]
+    ]
+
+!
+
+endObjectMove
+    "cleanup after object move"
+
+    movedObject notNil ifTrue:[
+        movedObject do:[:aView|
+            self invertOutlineOf:aView
+        ].
+
+        movedObject do:[:aView|
+            self showSelected:aView
+        ].
+        movedObject size == 1 ifTrue:[
+            selection := movedObject at:1
+        ] ifFalse:[
+            selection := movedObject
+        ].
+
+        movedObject := nil.
+        self setDefaultActions.
+        self changed:#layout.
+    ].
+!
+
+startObjectMoveAt:aPoint
+
+    self startObjectMove:selection at:aPoint.
+
+    selection size == 0 ifTrue:[
+        movedObject := Array with:selection
+    ] ifFalse:[
+        movedObject := selection
+    ].
+    super unselect.
+
+    moveDelta := movedObject collect:[:aView|
+        aPoint - aView computeOrigin
+    ].
+
+    undoHistory transactionNamed:'move' do:[
+        movedObject do:[:aView|
+            self invertOutlineOf:aView.
+            self undoBlockPositionChanged:aView
+        ]
+    ]
+!
+
+startSelectMoreOrMove:aPoint
+    "add/remove to/from selection"
+
+    |anObject|
+
+    testMode ifTrue:[^ self].
+
+    anObject := self findObjectAt:aPoint.
+    anObject notNil ifTrue:[
+        (self isSelected:anObject) ifTrue:[
+            self removeFromSelection:anObject
+        ] ifFalse:[
+            self addToSelection:anObject
+        ]
+    ]
+!
+
+startSelectOrMove:aPoint
+    "a button is pressed at a point
+    "
+    |anObject b|
+
+    testMode ifTrue:[^ self].
+
+    "if there is one selection and point hits handle, start a resize
+    "
+    self singleSelection notNil ifTrue:[
+        b := self whichHandleOf:selection isHitBy:aPoint.
+
+        (b notNil and:[b ~~ #view]) ifTrue:[
+            ^ self startResizeBorder:b of:selection at:aPoint.
+        ]
+    ].
+
+    anObject := self findObjectAt:aPoint.
+
+    "nothing is selected
+    "
+    anObject isNil ifTrue:[
+        ^ self unselect
+    ].
+
+    (self isSelected:anObject) ifFalse:[
+        super unselect.
+        self select:anObject.
+    ].
+
+    selection isCollection ifTrue:[
+        releaseAction := [
+            self setDefaultActions.
+            self select:anObject
+        ]
+    ] ifFalse:[
+        releaseAction := [self setDefaultActions]
+    ].
+
+    "prepare move operation for an object
+    "
+    motionAction := [:movePoint|
+        (aPoint dist:movePoint) > 2.0 ifTrue:[
+            self startObjectMoveAt:aPoint
+        ]
+    ].
+! !
+
 !UIObjectView methodsFor:'private handles'!
 
 handlesOf:aComponent do:aBlock
@@ -538,32 +549,41 @@
 !
 
 showSelected:aComponent
-    |delta oldPaint|
+    |wasClipped delta oldPaint|
+
+    self paint:Color black.
 
-    self paint:Color black. 
-    self clippedByChildren:false. 
+    (wasClipped := clipChildren) ifTrue:[
+        self clippedByChildren:(clipChildren := false). 
+    ].
 
     self handlesOf:aComponent do:[:pnt :what |
         what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)]
                      ifFalse:[self    fillRectangle:(pnt - (4@4) extent:7@7)]
     ].
 
-    self clippedByChildren:true.
+    wasClipped ifTrue:[
+        self clippedByChildren:(clipChildren := true).
+    ].
     self paint:oldPaint.
 !
 
 showUnselected:aComponent
-    |delta r oldPaint|
+    |wasClipped delta r oldPaint|
 
     r := aComponent origin extent:8@8.
 
-    self clippedByChildren:false. 
+    (wasClipped := clipChildren) ifTrue:[
+        self clippedByChildren:(clipChildren := false). 
+    ].
 
     self handlesOf:aComponent do:[:pnt :what |
         self clearRectangle:(pnt - (4@4) extent:7@7).
     ].
 
-    self clippedByChildren:true. 
+    wasClipped ifTrue:[
+        self clippedByChildren:(clipChildren := true). 
+    ].
 
     "/ must redraw all components which are affected b the handles
 
@@ -717,43 +737,39 @@
 !UIObjectView methodsFor:'searching'!
 
 findObjectAt:aPoint
-    "find the origin/corner of the currentWidget"
+    "find the origin/corner of the currentWidget
+    "
+    |view viewId lastId point|
+
+    viewId := rootView id.
+    point  := aPoint + (device translatePoint:0@0 from:(self id) to:viewId).
+
+    inputView lower.
 
-     selection notNil ifTrue:[
-        (selection isKindOf:Collection) ifTrue:[
-            ^ self findObjectIn:(selection first) at:aPoint
-        ].
-        ^ self findObjectIn:selection at:aPoint
-     ].
-     ^ self findObjectIn:self at:aPoint
+    [viewId notNil] whileTrue:[
+        lastId := viewId.
+        viewId := device viewIdFromPoint:point in:lastId
+    ].
 
+    inputView raise.
+
+    view := device viewFromId:lastId.
+
+    view ~~ inputView ifTrue:[^ view]
+                     ifFalse:[^ nil]
 
 
 !
 
-findObjectIn:aView at:aPoint
-    "find the origin/corner of the currentWidget
+isPoint:aPoint containedIn:aView
+    "checks whether a point is covered by a view.
     "
-    |relPoint|
-
-    aView isNil ifTrue:[^ nil].
-    aView subViews notNil ifTrue:[
-        relPoint := aPoint - (aView originRelativeTo:self).
-        self subviewsOf:aView do:[:aView |
-            |org ext|
+    |org ext|
 
-            (aView isKindOf:InputView) ifFalse:[
-                org := aView computeOrigin.
-                ext := aView computeExtent.
-                ((org extent:ext) containsPoint:relPoint) ifTrue:[
-                    ^ aView
-                ]
-            ]
-        ]
-    ].
-    (aView == self) ifTrue:[^ nil].
+    org := aView computeOrigin.
+    ext := aView computeExtent.
 
-    ^ self findObjectIn:(aView superView) at:aPoint
+    ^ ((org extent:ext) containsPoint:aPoint)
 !
 
 whichBorderOf:aView isHitBy:aPoint
@@ -785,10 +801,8 @@
 
 addToSelection:something
     (testMode or:[something == selection]) ifFalse:[
-        selection ~~ something ifTrue:[
-            super addToSelection:something.
-            self changed:#selection.
-        ]
+        super addToSelection:something.
+        self changed:#selection.
     ]
 !
 
@@ -1060,8 +1074,6 @@
     |dX dY org delta|
 
     anObject notNil ifTrue:[
-        self invertOutlineOf:anObject.
-
         org := anObject computeOrigin.
 
         delta := aPoint - org.
@@ -1073,7 +1085,6 @@
             self shifLayout:anObject top:dY bottom:dY left:dX right:dX
         ].
         self elementChangedLayout:anObject.
-        self invertOutlineOf:anObject.
     ]
 
 !