UIObjectView.st
changeset 175 0b0b4d99e3e7
parent 156 b332d7117c40
child 194 2b05bd327785
--- a/UIObjectView.st	Mon Jun 23 12:53:14 1997 +0200
+++ b/UIObjectView.st	Tue Jun 24 16:14:11 1997 +0200
@@ -14,8 +14,8 @@
 
 ObjectView subclass:#UIObjectView
 	instanceVariableNames:'saveSelection inputView enableChannel undoHistory copiedExtent
-		copiedLayout actionData createClass clipChildren
-		selectionHiddenLevel setOfSuperViewsSizeChanged'
+		copiedLayout resizeData clipChildren selectionHiddenLevel
+		setOfSuperViewsSizeChanged'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -167,8 +167,97 @@
 
 ! !
 
+!UIObjectView class methodsFor:'handles'!
+
+handlesOf:aView do:aBlock
+    |type v h|
+
+    type := self layoutType:aView.
+
+    (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
+        v := self isVerticalResizable:aView.
+        h := self isHorizontalResizable:aView.
+
+        h ifTrue:[  aBlock value:(aView leftCenter ) value:#left.
+                    aBlock value:(aView rightCenter) value:#right.
+                 ].
+        v ifTrue:[  aBlock value:(aView topCenter   ) value:#top.
+                    aBlock value:(aView bottomCenter) value:#bottom.
+                 ].
+
+        (h and:[v]) ifTrue:[
+            aBlock value:(aView origin    ) value:#origin.
+            aBlock value:(aView topRight  ) value:#topRight.
+            aBlock value:(aView bottomLeft) value:#bottomLeft.
+            aBlock value:(aView corner    ) value:#corner.
+          ^ self
+        ]
+    ].
+
+    aBlock value:(aView origin    ) value:#view.
+    aBlock value:(aView topRight  ) value:#view.
+    aBlock value:(aView bottomLeft) value:#view.
+
+    type == #Extent ifTrue:[
+        v := self isVerticalResizable:aView.
+        h := self isHorizontalResizable:aView.
+
+        v ifTrue:[aBlock value:(aView bottomCenter) value:#bottom].
+        h ifTrue:[aBlock value:(aView rightCenter ) value:#right ].
+
+        (h and:[v]) ifTrue:[
+            aBlock value:(aView corner) value:#corner.
+          ^ self
+        ]
+    ].
+    aBlock value:(aView corner) value:#view.
+
+
+! !
+
 !UIObjectView class methodsFor:'queries'!
 
+isHorizontalResizable:aComponent
+    "returns true if instance is horizontal resizeable
+    "
+    (aComponent isKindOf:ScrollBar) ifTrue:[
+        ^ aComponent orientation == #horizontal
+    ].
+    (aComponent isKindOf:Scroller) ifTrue:[
+        ^ aComponent orientation == #horizontal
+    ].
+    (aComponent isKindOf:Slider) ifTrue:[
+        ^ aComponent orientation == #horizontal
+    ].
+    ^ true
+
+!
+
+isVerticalResizable:aComponent
+    "returns true if instance is vertical resizeable
+    "
+    (aComponent isKindOf:EditField) ifTrue:[
+        ^ false
+    ].
+    (aComponent isKindOf:ComboBoxView) ifTrue:[
+        ^ false
+    ].
+    (aComponent isKindOf:CheckBox) ifTrue:[
+        ^ false
+    ].
+    (aComponent isKindOf:ScrollBar) ifTrue:[
+        ^ aComponent orientation == #vertical
+    ].
+    (aComponent isKindOf:Scroller) ifTrue:[
+        ^ aComponent orientation == #vertical
+    ].
+    (aComponent isKindOf:Slider) ifTrue:[
+        ^ aComponent orientation == #vertical
+    ].
+    ^ true
+
+!
+
 layoutType:aView
     "returns layout type of aView or nil
     "
@@ -329,6 +418,11 @@
     "
     self halt
 
+!
+
+startCreate:aPoint
+    self setDefaultActions.
+    self halt
 ! !
 
 !UIObjectView methodsFor:'event handling'!
@@ -347,24 +441,21 @@
 exposeX:x y:y width:w height:h
     "handle an expose event from device; redraw selection
     "
-    super exposeX:x y:y width:w height:h.
-
-"
-catch expose events for all subviews associated with
-a selected instance
-"
-
-    "/ handle any expose events (for subcomponents) before
-    "/ redrawing the handles.
-    (self sensor hasExposeEventFor:nil) ifTrue:[^ self].
-
-    self selectionDo:[:aComponent |
-        aComponent withAllSubViewsDo:[:v |
-            self sensor flushExposeEventsFor:v.
-            v exposeX:0 y:0 width:9999 height:9999.
-        ].
-
-        self showSelected:aComponent
+    resizeData isNil ifTrue:[
+        super exposeX:x y:y width:w height:h.
+
+        "/ handle any expose events (for subcomponents) before
+        "/ redrawing the handles.
+        (self sensor hasExposeEventFor:nil) ifTrue:[^ self].
+
+        self selectionDo:[:aComponent |
+            aComponent withAllSubViewsDo:[:v |
+                self sensor flushExposeEventsFor:v.
+                v exposeX:0 y:0 width:9999 height:9999.
+            ].
+
+            self showSelected:aComponent
+        ]
     ]
 
 !
@@ -455,27 +546,29 @@
 
 !
 
-invertOutlineOf:anObject
-    "invert outline of an object
+invertOutlineOf:something
+    "invert outline of an object or collection of objects
     "
-    |wasClipped delta|
+    |wasClipped p|
 
     (wasClipped := clipChildren) ifTrue:[
         self clippedByChildren:(clipChildren := false).
     ].
-    delta := (anObject originRelativeTo:self) - anObject origin.
-
-    self xoring:[
-        self displayRectangle:((anObject origin + delta) extent:anObject extent).
+
+    something isCollection ifTrue:[
+        something do:[:v|
+            p := v originRelativeTo:self.
+            self xoring:[self displayRectangle:(p extent:v extent)].
+        ]
+    ] ifFalse:[
+        p := something originRelativeTo:self.
+        self xoring:[self displayRectangle:(p extent:something extent)]
     ].
 
     wasClipped ifTrue:[
         self clippedByChildren:(clipChildren := true).
     ].
 
-    "Modified: 5.9.1995 / 12:25:25 / claus"
-
-
 !
 
 minSetOfSuperViews:setOfViews
@@ -502,177 +595,18 @@
 
 ! !
 
-!UIObjectView methodsFor:'object creation'!
-
-actionCreate:anObject frame:aFrame delta:aDelta
-    "create and initialize action data
-    "
-    |extent x y selectors values|
-
-"minimum extent
-"
-    (anObject specClass supportsSubComponents) ifTrue:[
-        extent := 25@25
-    ] ifFalse:[
-        extent := self extent.
-        x := extent x // 3.
-        y := extent y // 3.
-        extent := anObject preferredExtent.
-
-        (extent x > x) ifTrue:[extent x:x].
-        (extent y > y) ifTrue:[extent y:y].
-    ].
-
-"setup structure
-"
-    selectors := #( object frame delta vertical horizontal minExtent ).
-    values    := Array new:(selectors size).
-
-    values at:1 put:anObject.
-    values at:2 put:aFrame.
-    values at:3 put:aDelta.
-    values at:4 put:(self isVerticalResizable:anObject).
-    values at:5 put:(self isHorizontalResizable:anObject).
-    values at:6 put:extent.
-
-    actionData := Structure newWith:selectors values:values.
-
-
-"can change cursor dependent on vertical/horizontal resizing
-"
-    oldCursor := cursor.
-    self cursor:(Cursor leftHand).
-
-
-
-!
-
-createWidgetWithClass:aClass
-    "prepare to create new widgets
-    "
-    aClass notNil ifTrue:[
-        createClass := aClass.
-        pressAction := [:aPoint| self startCreate:aPoint].
-        self cursor:Cursor origin.
-    ]
-
-!
-
-doDragCreate:aPoint
-    "do a widget create drag
-    "
-    |frame object extent minimum|
-
-    frame   := actionData frame.
-    frame corner:((self alignToGrid:aPoint) - (actionData delta)).
-
-    object  := actionData object.
-    minimum := actionData minExtent.
-    extent  := frame extent.
-
-    ((extent x < minimum x) or:[actionData horizontal not]) ifTrue:[
-        extent x:(minimum x)
-    ].
-
-    ((extent y < minimum y) or:[actionData vertical not]) ifTrue:[
-        extent y:(minimum y)
-    ].
-
-    frame extent:extent.
-
-    self invertOutlineOf:object.
-    object origin:(frame origin) extent:(frame extent).
-    self invertOutlineOf:object.
-!
-
-endCreate
-    "end a widget create drag
-    "
-    |object specClass|
-
-    object := actionData object.
-    self invertOutlineOf:object.
-    inputView raise.
-
-    self setupInitialLayoutFor:object.
-    self select:object.
-    actionData := nil.
-
-    self setDefaultActions.
-
-!
-
-initializeCreatedObject:anObject
-    self subclassResponsibility
-!
-
-setupInitialLayoutFor:anObject
-    "setup initial layout for an object; !!!! some kludge !!!!
-    "
-    |spec topSpec|
-
-    topSpec := anObject superView specClass basicNew.
-
-    topSpec class isLayoutContainer ifFalse:[
-
-"/ ... KLUDGE ....
-
-        spec := anObject specClass.
-
-        (    spec == ViewSpec
-         or:[spec == SubCanvasSpec
-         or:[spec == TextEditorSpec
-         or:[spec == SequenceViewSpec]]]
-        ) ifTrue:[
-            anObject geometryLayout:(anObject bounds asLayout).
-          ^ self
-        ]
-    ].
-    topSpec setupInitialLayoutFor:anObject.
-
-!
-
-startCreate:aPoint
-    "start a widget create
-    "
-    |widget object start frame delta|
-
-    self select:nil.
-    widget := self findContainerViewAt:aPoint.
-
-    motionAction  := [:movePoint| self doDragCreate:movePoint].
-    releaseAction := [ self endCreate].
-
-    object := createClass new.
-    (widget isKindOf:ScrollableView) ifTrue:[
-        widget scrolledView:object
-    ] ifFalse:[
-        widget addSubView:object.
-    ].
-
-    start := self alignToGrid:aPoint.
-    delta := widget originRelativeTo:self.
-    frame := Rectangle origin:(start - delta) corner:start.
-
-    object origin:(frame origin).
-    self initializeCreatedObject:object.
-    self actionCreate:object frame:frame delta:delta.
-    object extent:(actionData minExtent).
-    object realize.
-    self invertOutlineOf:object.
-! !
-
 !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.
-        ]
+        self invertOutlineOf:movedObject.
+
+        movedObject keysAndValuesDo:[:i :v|
+            self moveObject:v to:(aPoint - (moveDelta at:i)).
+        ].
+        self invertOutlineOf:movedObject.
     ]
 
 !
@@ -681,12 +615,11 @@
     "cleanup after object(s) move
     "
     movedObject notNil ifTrue:[
-        movedObject do:[:aView|self invertOutlineOf:aView].
+        self invertOutlineOf:movedObject.
 
         movedObject size == 1 ifTrue:[
             movedObject := movedObject first
         ].
-
         self setSelection:movedObject withRedraw:true.
         movedObject := nil.
         self setDefaultActions.
@@ -728,12 +661,8 @@
     moveDelta := movedObject collect:[:aView|
         aPoint - aView computeOrigin
     ].
-
-    self transaction:#move objects:movedObject do:[:aView|
-        self invertOutlineOf:aView.
-        self createUndoLayout:aView
-    ].
-
+    self transaction:#move objects:movedObject do:[:v|self createUndoLayout:v].
+    self invertOutlineOf:movedObject.
 !
 
 startSelectMoreOrMove:aPoint
@@ -819,7 +748,7 @@
     delta    := anObject container originRelativeTo:self.
     selector := ('resize:', aSelector, ':') asSymbol.
 
-    actionData := Structure with:(#object->anObject)
+    resizeData := Structure with:(#object->anObject)
                             with:(#selector->selector)
                             with:(#delta->delta).
 
@@ -837,12 +766,12 @@
     "
     |p object|
 
-    object := actionData object.
+    object := resizeData object.
 
     self invertOutlineOf:object.
-    p := (self alignToGrid:aPoint) - (actionData delta).
-
-    self perform:(actionData selector) with:object with:p.
+    p := (self alignToGrid:aPoint) - (resizeData delta).
+
+    self perform:(resizeData selector) with:object with:p.
    "/ object geometryLayout:(object geometryLayout).
     self invertOutlineOf:object
 
@@ -853,8 +782,8 @@
     "
     |object|
 
-    object := actionData object.
-    actionData := nil.
+    object := resizeData object.
+    resizeData := nil.
 
     self invertOutlineOf:object.
     self setDefaultActions.
@@ -891,73 +820,41 @@
 
 !UIObjectView methodsFor:'private handles'!
 
-handlesOf:aView do:aBlock
-    |dlta type v h|
-
-    dlta := (aView originRelativeTo:self) - aView origin.
-    type := self class layoutType:aView.
-
-    (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
-        v := self isVerticalResizable:aView.
-        h := self isHorizontalResizable:aView.
-
-        h ifTrue:[  aBlock value:(aView leftCenter   + dlta) value:#left.
-                    aBlock value:(aView rightCenter  + dlta) value:#right.
-                 ].
-        v ifTrue:[  aBlock value:(aView topCenter    + dlta) value:#top.
-                    aBlock value:(aView bottomCenter + dlta) value:#bottom.
-                 ].
-
-        (h and:[v]) ifTrue:[
-            aBlock value:(aView origin     + dlta) value:#origin.
-            aBlock value:(aView topRight   + dlta) value:#topRight.
-            aBlock value:(aView bottomLeft + dlta) value:#bottomLeft.
-            aBlock value:(aView corner     + dlta) value:#corner.
-          ^ self
-        ]
-    ].
-
-    aBlock value:(aView origin     + dlta) value:#view.
-    aBlock value:(aView topRight   + dlta) value:#view.
-    aBlock value:(aView bottomLeft + dlta) value:#view.
-
-    type == #Extent ifTrue:[
-        v := self isVerticalResizable:aView.
-        h := self isHorizontalResizable:aView.
-
-        v ifTrue:[aBlock value:(aView bottomCenter + dlta) value:#bottom].
-        h ifTrue:[aBlock value:(aView rightCenter  + dlta) value:#right ].
-
-        (h and:[v]) ifTrue:[
-            aBlock value:(aView corner + dlta) value:#corner.
-          ^ self
-        ]
-    ].
-    aBlock value:(aView corner + dlta) value:#view.
+handlesOf:aComponent do:aTwoArgAction
+    "perform action on each handle of a component
+    "
+    |dlt ext|
+
+    dlt := (aComponent originRelativeTo:self) - aComponent origin.
+    dlt := dlt - (3@3).
+    ext := 6@6.
+
+    self class handlesOf:aComponent do:[:pnt :wht |
+        aTwoArgAction value:(pnt + dlt extent:ext) value:wht
+    ]
 !
 
 showSelected:aComponent
     "show object selected
     "
-    |wasClipped delta|
-
-    selectionHiddenLevel ~~ 0 ifTrue:[^ self].
-
-    self paint:Color black.
-
-    (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)]
-    ].
-
-    wasClipped ifTrue:[
-        self clippedByChildren:(clipChildren := true).
-    ].
-
+    |wasClipped|
+
+    selectionHiddenLevel == 0 ifTrue:[
+        self paint:Color black.
+
+        (wasClipped := clipChildren) ifTrue:[
+            self clippedByChildren:(clipChildren := false). 
+        ].
+
+        self handlesOf:aComponent do:[:rectangle :what|
+            what == #view ifTrue:[self displayRectangle:rectangle]
+                         ifFalse:[self fillRectangle:rectangle]
+        ].
+
+        wasClipped ifTrue:[
+            self clippedByChildren:(clipChildren := true).
+        ]
+    ]
 !
 
 showUnselected:aComponent
@@ -971,9 +868,7 @@
         self clippedByChildren:(clipChildren := false). 
     ].
 
-    self handlesOf:aComponent do:[:pnt :what |
-        self clearRectangle:(pnt - (4@4) extent:7@7).
-    ].
+    self handlesOf:aComponent do:[:rec :wht| self clearRectangle:rec ].
 
     wasClipped ifTrue:[
         self clippedByChildren:(clipChildren := true). 
@@ -981,8 +876,7 @@
 
     "/ must redraw all components which are affected b the handles
 
-    r := (aComponent originRelativeTo:self) - (4@4)
-             extent:(aComponent extent + (4@4)).
+    r := (aComponent originRelativeTo:self) - (3@3) extent:(aComponent extent + (6@6)).
 
     subViews do:[:anotherComponent |
         |absOrg absFrame|
@@ -1004,21 +898,13 @@
     "Modified: 8.4.1997 / 00:32:26 / cg"
 !
 
-whichHandleOf:aView isHitBy:aPoint
+whichHandleOf:aComponent isHitBy:aPoint
     "returns kind of handle or nil
     "
-    |bounds|
-
-    self handlesOf:aView do:[:pnt :what |
-        ((pnt - (4@4) extent:7@7) containsPoint:aPoint) ifTrue:[
-            ^ what
-        ].
+    self handlesOf:aComponent do:[:rectangle :what|
+        (rectangle containsPoint:aPoint) ifTrue:[^ what]
     ].
-
-    ^ nil
-
-    "Modified: 5.9.1995 / 14:39:34 / claus"
-
+  ^ nil
 ! !
 
 !UIObjectView methodsFor:'private resizing-subviews'!
@@ -1219,48 +1105,6 @@
     ^ nil
 
 
-!
-
-isPoint:aPoint containedIn:aView
-    "checks whether a point is covered by a view.
-    "
-    |p|
-
-    p := device translatePoint:aPoint from:inputView id to:aView id.
-
-    (p x >= 0 and:[p y >= 0]) ifTrue:[
-        p := aView extent - p.
-
-        (p x >= 0 and:[p y >= 0]) ifTrue:[
-            ^ true
-        ]
-    ].
-    ^ false
-!
-
-whichBorderOf:aView isHitBy:aPoint
-    |p r bw org|
-
-    bw := aView borderWidth.
-    p := aPoint - (aView superView originRelativeTo:self).
-
-    r := Rectangle origin:(aView origin)
-                   extent:(aView width @ bw).
-    (r containsPoint:p) ifTrue:[^ #top:].
-
-    r origin:(aView left @ (aView bottom + bw)) extent:(aView width @ bw).
-    (r containsPoint:p) ifTrue:[^ #bottom:].
-
-    r top:(aView top).
-    r extent:(bw @ aView height).
-    (r containsPoint:p) ifTrue:[^ #left:].
-
-    r origin:((aView right + bw) @ aView top).
-    (r containsPoint:p) ifTrue:[^ #right:].
-
-    ^ nil
-
-
 ! !
 
 !UIObjectView methodsFor:'selections'!
@@ -1533,14 +1377,6 @@
 
 !
 
-isHorizontalResizable:aComponent
-    "returns true if instance is horizontal resizeable
-    "
-    ^ self subclassResponsibility
-
-
-!
-
 isModified
     "returns true if painter is modified
     "
@@ -1555,22 +1391,6 @@
     ].
   ^ false
 
-!
-
-isVerticalResizable:aComponent
-    "returns true if instance is vertical resizeable
-    "
-    ^ self subclassResponsibility
-
-
-!
-
-supportsLabel:aComponent
-    "returns true if component supports label
-    "
-    ^ self subclassResponsibility
-
-
 ! !
 
 !UIObjectView methodsFor:'transaction'!