UIObjectView.st
changeset 50 fb4359c9bdc4
parent 49 7f58dd5fc836
child 51 01d0c9394944
equal deleted inserted replaced
49:7f58dd5fc836 50:fb4359c9bdc4
     1 ObjectView subclass:#UIObjectView
       
     2 	instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject
       
     3 		resizeSelector createInWidget createFrame createdObject
       
     4 		createClass clipChildren'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'Interface-UIPainter'
       
     8 !
       
     9 
       
    10 Object subclass:#UndoHistory
     1 Object subclass:#UndoHistory
    11 	instanceVariableNames:'history transaction enabled modifiedAction'
     2 	instanceVariableNames:'history transaction enabled modifiedAction'
    12 	classVariableNames:''
     3 	classVariableNames:''
    13 	poolDictionaries:''
     4 	poolDictionaries:''
    14 	privateIn:UIObjectView
     5 	privateIn:UIObjectView
    15 !
     6 !
    16 
     7 
    17 
     8 !UIObjectView::UndoHistory class methodsFor:'instance creation'!
    18 !UIObjectView class methodsFor:'defaults'!
     9 
    19 
    10 new
    20 defaultGrid
    11     ^ self basicNew initialize
    21     ^ 4 @ 4
    12 
    22 
       
    23 !
       
    24 
       
    25 gridShown
       
    26     ^ false
       
    27 
       
    28 !
       
    29 
       
    30 handleSize
       
    31     "size of blob drawn for handles"
       
    32     ^ 4
       
    33 
       
    34 !
       
    35 
       
    36 hitDelta
       
    37     ^ 4
       
    38 
       
    39 ! !
       
    40 
       
    41 !UIObjectView methodsFor:'accessing'!
       
    42 
       
    43 gridParameters
       
    44     "used by defineGrid, and in a separate method for
       
    45      easier redefinition in subclasses. 
       
    46      Returns the grid parameters in an array of 7 elements,
       
    47      which control the appearance of the grid-pattern.
       
    48      the elements are:
       
    49 
       
    50         bigStepH        number of pixels horizontally between 2 major steps
       
    51         bigStepV        number of pixels vertically between 2 major steps
       
    52         littleStepH     number of pixels horizontally between 2 minor steps
       
    53         littleStepV     number of pixels vertically between 2 minor steps
       
    54         gridAlignH      number of pixels for horizontal grid align (pointer snap)
       
    55         gridAlignV      number of pixels for vertical grid align (pointer snap)
       
    56         docBounds       true, if document boundary should be shown
       
    57 
       
    58      if littleStepH/V are nil, only bigSteps are drawn.
       
    59     "
       
    60 
       
    61     ^ #(10 10 nil nil 10 10 false)
       
    62 
       
    63 
       
    64 !
       
    65 
       
    66 hideGrid
       
    67     gridShown ifTrue:[
       
    68         self withSelectionHiddenDo:[
       
    69             super hideGrid
       
    70         ]
       
    71     ]
       
    72 
       
    73 
       
    74 !
       
    75 
       
    76 showGrid
       
    77     self withSelectionHiddenDo:[
       
    78         super showGrid
       
    79     ]
       
    80 
       
    81     "Modified: 5.9.1995 / 12:47:46 / claus"
       
    82 
       
    83 
       
    84 !
       
    85 
       
    86 testMode
       
    87     "returns testMode
       
    88     "
       
    89     ^ testMode
       
    90 
       
    91 
       
    92 !
       
    93 
       
    94 testMode:aBoolean
       
    95     "change testMode
       
    96     "
       
    97     (aBoolean == testMode) ifFalse:[
       
    98         testMode := aBoolean.
       
    99 
       
   100         testMode ifTrue:[
       
   101             self unselect.
       
   102             inputView unrealize
       
   103         ] ifFalse:[
       
   104             inputView raise.
       
   105             inputView realize
       
   106         ]
       
   107     ]
       
   108 
       
   109 
       
   110 ! !
       
   111 
       
   112 !UIObjectView methodsFor:'event handling'!
       
   113 
       
   114 doKeyInput:key
       
   115     ^ self
       
   116 
       
   117 
       
   118 !
       
   119 
       
   120 elementChanged:aView 
       
   121     "some element has been changed - kludge to force a resizing
       
   122      operation (for child layout recomputation) in its superView"
       
   123 
       
   124     aView superView sizeChanged:nil.
       
   125     self changed:#any.
       
   126 
       
   127 
       
   128 !
       
   129 
       
   130 elementChangedLayout:aView 
       
   131     "some element has been changed - kludge to force a resizing
       
   132      operation (for child layout recomputation) in its superView"
       
   133 
       
   134     aView superView sizeChanged:nil.
       
   135     self changed:#layout.
       
   136 
       
   137 
       
   138 !
       
   139 
       
   140 exposeX:x y:y width:w height:h
       
   141     "handle an expose event from device; redraw selection
       
   142     "
       
   143     super exposeX:x y:y width:w height:h.
       
   144 
       
   145     selection notNil ifTrue:[
       
   146         self selectionDo:[:v | self showSelected:v]
       
   147     ]
       
   148 
       
   149 
       
   150 !
       
   151 
       
   152 keyPress:key x:x y:y
       
   153 
       
   154     key == #InspectIt ifTrue:[
       
   155         ^ self inspectSelection
       
   156     ].
       
   157 
       
   158     (key == #Delete or:[key == #BackSpace]) ifTrue: [
       
   159         selection notNil ifTrue:[
       
   160             self deleteSelection
       
   161         ]
       
   162     ] ifFalse:[
       
   163         keyPressAction notNil ifTrue:[
       
   164             keyPressAction value:key
       
   165         ]
       
   166     ]
       
   167 
       
   168 
       
   169 !
       
   170 
       
   171 processEvent:anEvent
       
   172     "catch expose events for components, and redraw its handles after
       
   173      the redraw when this happens
       
   174     "
       
   175     |view|
       
   176 
       
   177     selection notNil ifTrue:[
       
   178         anEvent type == #damage ifTrue:[
       
   179             view := anEvent view.
       
   180             (selection == view
       
   181             or:[selection isCollection
       
   182                 and:[selection includes:view]]) ifTrue:[
       
   183                     self showSelected:view
       
   184             ]
       
   185         ]
       
   186     ].
       
   187     ^ false.
       
   188 
       
   189 
       
   190 !
       
   191 
       
   192 sizeChanged:how
       
   193     self withSelectionHiddenDo:[
       
   194         super sizeChanged:how
       
   195     ]
       
   196 
       
   197 
       
   198 ! !
       
   199 
       
   200 !UIObjectView methodsFor:'initialization'!
       
   201 
       
   202 initialize
       
   203     super initialize.
       
   204 
       
   205     "funny: since I do not want the created widgets to get pointer
       
   206      events, I put an InputView on top of them, which catches those events
       
   207      and passes them back to me - have to take care, that this inputView
       
   208      is always on top
       
   209     "
       
   210     inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self.
       
   211 
       
   212     inputView eventReceiver:self.
       
   213     inputView enableButtonEvents.
       
   214     inputView enableButtonMotionEvents.
       
   215 
       
   216     self setDefaultActions.
       
   217 
       
   218     undoHistory := UndoHistory new.
       
   219 
       
   220     undoHistory modifiedAction:[:what|
       
   221         self changed:#undoHistory with:what
       
   222     ].
       
   223 
       
   224     testMode := false.
       
   225     clipChildren := true.
       
   226 
       
   227     (self class gridShown) ifTrue:[
       
   228         super showGrid
       
   229     ].
       
   230 
       
   231 !
       
   232 
       
   233 realize
       
   234     super realize.
       
   235     self windowGroup postEventHook:self
       
   236 
       
   237 ! !
       
   238 
       
   239 !UIObjectView methodsFor:'misc'!
       
   240 
       
   241 cursor:aCursor
       
   242     inputView realized ifTrue:[
       
   243         inputView cursor:aCursor
       
   244     ].
       
   245     super cursor:aCursor
       
   246 
       
   247 
       
   248 !
       
   249 
       
   250 invertOutlineOf:anObject
       
   251     |wasClipped delta|
       
   252 
       
   253     (wasClipped := clipChildren) ifTrue:[
       
   254         self clippedByChildren:(clipChildren := false).
       
   255     ].
       
   256     delta := (anObject originRelativeTo:self) - anObject origin.
       
   257 
       
   258     self xoring:[
       
   259         self displayRectangle:((anObject origin + delta) extent:anObject extent).
       
   260     ].
       
   261 
       
   262     wasClipped ifTrue:[
       
   263         self clippedByChildren:(clipChildren := true).
       
   264     ].
       
   265 
       
   266     "Modified: 5.9.1995 / 12:25:25 / claus"
       
   267 
       
   268 
       
   269 !
       
   270 
       
   271 setDefaultActions
       
   272 
       
   273     pressAction      := [:pressPoint | self startSelectOrMove:pressPoint].
       
   274     shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint].
       
   275     motionAction     := [:movePoint  | nil].
       
   276     releaseAction    := [nil].
       
   277     keyPressAction   := [:key | self doKeyInput:key].
       
   278 
       
   279     self cursor:Cursor normal.
       
   280 
       
   281 !
       
   282 
       
   283 showDragging:something offset:anOffset
       
   284     "drag around a View"
       
   285 
       
   286     |top|
       
   287 
       
   288     self forEach:something do:[:anObject |
       
   289         self drawRectangle:((anObject origin + anOffset) extent:(anObject extent))
       
   290     ]
       
   291 
       
   292 ! !
       
   293 
       
   294 !UIObjectView methodsFor:'object creation'!
       
   295 
       
   296 doDragCreate:aPoint
       
   297     "do a widget create drag
       
   298     "
       
   299     |p|
       
   300 
       
   301     p := self alignToGrid:aPoint.
       
   302     createFrame corner:(p - (createInWidget originRelativeTo:self)).
       
   303 
       
   304     (createFrame extent x < 10) ifTrue:[
       
   305         createFrame extent x:10
       
   306     ].
       
   307 
       
   308     (createFrame extent y < 10) ifTrue:[
       
   309         createFrame extent y:10
       
   310     ].
       
   311 
       
   312     self invertOutlineOf:createdObject.
       
   313     createdObject origin:(createFrame origin) extent:(createFrame extent).
       
   314     self invertOutlineOf:createdObject.
       
   315 !
       
   316 
       
   317 endCreate
       
   318     "end a widget create drag
       
   319     "
       
   320     |layout x y|
       
   321 
       
   322     self invertOutlineOf:createdObject.
       
   323     inputView raise.
       
   324 
       
   325     layout := createdObject bounds asLayout.
       
   326     createdObject geometryLayout:layout.
       
   327 
       
   328     self changed:#tree.
       
   329     self select:createdObject.
       
   330     createdObject := nil.
       
   331 
       
   332     self setDefaultActions.
       
   333 
       
   334 !
       
   335 
       
   336 setupCreatedObject:anObject
       
   337     self subclassResponsibility
       
   338 !
       
   339 
       
   340 startCreate:aPoint
       
   341     "start a widget create
       
   342     "
       
   343     |startPoint|
       
   344 
       
   345     createClass isNil ifTrue:[
       
   346         ^ self setDefaultActions
       
   347     ].
       
   348     (selection isKindOf:Collection) ifTrue:[
       
   349         self unselect.
       
   350       ^ self setDefaultActions.
       
   351     ].
       
   352 
       
   353     startPoint    := self alignToGrid:aPoint.
       
   354     motionAction  := [:movePoint| self doDragCreate:movePoint].
       
   355     releaseAction := [ self endCreate].
       
   356 
       
   357     selection notNil ifTrue:[
       
   358         (    (self isPoint:aPoint containedIn:selection)
       
   359          and:[selection specClass basicNew supportsSubComponents]
       
   360         ) ifFalse:[
       
   361             self unselect
       
   362         ]
       
   363     ].
       
   364 
       
   365     oldCursor := cursor.
       
   366     self cursor:(Cursor leftHand).
       
   367 
       
   368     createInWidget := selection ? self.
       
   369     createdObject  := createClass new.
       
   370     createInWidget addSubView:createdObject.
       
   371 
       
   372     createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self))
       
   373                              corner:startPoint.
       
   374 
       
   375     createdObject origin:(createFrame origin).
       
   376 
       
   377     undoHistory transactionNamed:'create' do:[
       
   378         self setupCreatedObject:createdObject.
       
   379     ].
       
   380     createdObject realize.
       
   381     self invertOutlineOf:createdObject.
       
   382 ! !
       
   383 
       
   384 !UIObjectView methodsFor:'object moving'!
       
   385 
       
   386 doObjectMove:aPoint
       
   387     "move selection
       
   388     "
       
   389     movedObject notNil ifTrue:[
       
   390         movedObject keysAndValuesDo:[:nr :aView|
       
   391             self invertOutlineOf:aView.
       
   392             self moveObject:aView to:(aPoint - (moveDelta at:nr)).
       
   393             self invertOutlineOf:aView.
       
   394         ]
       
   395     ]
       
   396 
       
   397 !
       
   398 
       
   399 endObjectMove
       
   400     "cleanup after object move"
       
   401 
       
   402     movedObject notNil ifTrue:[
       
   403         movedObject do:[:aView|
       
   404             self invertOutlineOf:aView
       
   405         ].
       
   406 
       
   407         movedObject do:[:aView|
       
   408             self showSelected:aView
       
   409         ].
       
   410         movedObject size == 1 ifTrue:[
       
   411             selection := movedObject at:1
       
   412         ] ifFalse:[
       
   413             selection := movedObject
       
   414         ].
       
   415 
       
   416         movedObject := nil.
       
   417         self setDefaultActions.
       
   418         self changed:#layout.
       
   419     ].
       
   420 !
       
   421 
       
   422 startObjectMoveAt:aPoint
       
   423 
       
   424     self startObjectMove:selection at:aPoint.
       
   425 
       
   426     selection size == 0 ifTrue:[
       
   427         movedObject := Array with:selection
       
   428     ] ifFalse:[
       
   429         movedObject := selection
       
   430     ].
       
   431     super unselect.
       
   432 
       
   433     moveDelta := movedObject collect:[:aView|
       
   434         aPoint - aView computeOrigin
       
   435     ].
       
   436 
       
   437     undoHistory transactionNamed:'move' do:[
       
   438         movedObject do:[:aView|
       
   439             self invertOutlineOf:aView.
       
   440             self undoBlockPositionChanged:aView
       
   441         ]
       
   442     ]
       
   443 !
       
   444 
       
   445 startSelectMoreOrMove:aPoint
       
   446     "add/remove to/from selection"
       
   447 
       
   448     |anObject|
       
   449 
       
   450     testMode ifTrue:[^ self].
       
   451 
       
   452     anObject := self findObjectAt:aPoint.
       
   453     anObject notNil ifTrue:[
       
   454         (self isSelected:anObject) ifTrue:[
       
   455             self removeFromSelection:anObject
       
   456         ] ifFalse:[
       
   457             self addToSelection:anObject
       
   458         ]
       
   459     ]
       
   460 !
       
   461 
       
   462 startSelectOrMove:aPoint
       
   463     "a button is pressed at a point
       
   464     "
       
   465     |anObject b|
       
   466 
       
   467     testMode ifTrue:[^ self].
       
   468 
       
   469     "if there is one selection and point hits handle, start a resize
       
   470     "
       
   471     self singleSelection notNil ifTrue:[
       
   472         b := self whichHandleOf:selection isHitBy:aPoint.
       
   473 
       
   474         (b notNil and:[b ~~ #view]) ifTrue:[
       
   475             ^ self startResizeBorder:b of:selection at:aPoint.
       
   476         ]
       
   477     ].
       
   478 
       
   479     anObject := self findObjectAt:aPoint.
       
   480 
       
   481     "nothing is selected
       
   482     "
       
   483     anObject isNil ifTrue:[
       
   484         ^ self unselect
       
   485     ].
       
   486 
       
   487     (self isSelected:anObject) ifFalse:[
       
   488         super unselect.
       
   489         self select:anObject.
       
   490     ].
       
   491 
       
   492     selection isCollection ifTrue:[
       
   493         releaseAction := [
       
   494             self setDefaultActions.
       
   495             self select:anObject
       
   496         ]
       
   497     ] ifFalse:[
       
   498         releaseAction := [self setDefaultActions]
       
   499     ].
       
   500 
       
   501     "prepare move operation for an object
       
   502     "
       
   503     motionAction := [:movePoint|
       
   504         (aPoint dist:movePoint) > 2.0 ifTrue:[
       
   505             self startObjectMoveAt:aPoint
       
   506         ]
       
   507     ].
       
   508 ! !
       
   509 
       
   510 !UIObjectView methodsFor:'private handles'!
       
   511 
       
   512 handlesOf:aComponent do:aBlock
       
   513     |delta layout vertical horizontal|
       
   514 
       
   515     layout := aComponent geometryLayout.
       
   516     delta  := (aComponent originRelativeTo:self) - aComponent origin.
       
   517 
       
   518     (layout isLayout not or:[layout isLayoutFrame]) ifTrue:[
       
   519         vertical   := self isVerticalResizable:aComponent.
       
   520         horizontal := self isHorizontalResizable:aComponent.
       
   521     ] ifFalse:[
       
   522         vertical   := false.
       
   523         horizontal := false.
       
   524     ].
       
   525 
       
   526     horizontal ifTrue:[
       
   527         aBlock value:(aComponent leftCenter   + delta) value:#left.
       
   528         aBlock value:(aComponent rightCenter  + delta) value:#right.
       
   529     ].
       
   530 
       
   531     vertical ifTrue:[
       
   532         aBlock value:(aComponent topCenter    + delta) value:#top.
       
   533         aBlock value:(aComponent bottomCenter + delta) value:#bottom.
       
   534     ].
       
   535 
       
   536     (horizontal and:[vertical]) ifTrue:[
       
   537         aBlock value:(aComponent origin     + delta) value:#origin.
       
   538         aBlock value:(aComponent corner     + delta) value:#corner.
       
   539         aBlock value:(aComponent topRight   + delta) value:#topRight.
       
   540         aBlock value:(aComponent bottomLeft + delta) value:#bottomLeft.
       
   541     ] ifFalse:[
       
   542         aBlock value:(aComponent origin     + delta) value:#view.
       
   543         aBlock value:(aComponent corner     + delta) value:#view.
       
   544         aBlock value:(aComponent topRight   + delta) value:#view.
       
   545         aBlock value:(aComponent bottomLeft + delta) value:#view.
       
   546     ].
       
   547 
       
   548 
       
   549 !
       
   550 
       
   551 showSelected:aComponent
       
   552     |wasClipped delta oldPaint|
       
   553 
       
   554     self paint:Color black.
       
   555 
       
   556     (wasClipped := clipChildren) ifTrue:[
       
   557         self clippedByChildren:(clipChildren := false). 
       
   558     ].
       
   559 
       
   560     self handlesOf:aComponent do:[:pnt :what |
       
   561         what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)]
       
   562                      ifFalse:[self    fillRectangle:(pnt - (4@4) extent:7@7)]
       
   563     ].
       
   564 
       
   565     wasClipped ifTrue:[
       
   566         self clippedByChildren:(clipChildren := true).
       
   567     ].
       
   568     self paint:oldPaint.
       
   569 !
       
   570 
       
   571 showUnselected:aComponent
       
   572     |wasClipped delta r oldPaint|
       
   573 
       
   574     r := aComponent origin extent:8@8.
       
   575 
       
   576     (wasClipped := clipChildren) ifTrue:[
       
   577         self clippedByChildren:(clipChildren := false). 
       
   578     ].
       
   579 
       
   580     self handlesOf:aComponent do:[:pnt :what |
       
   581         self clearRectangle:(pnt - (4@4) extent:7@7).
       
   582     ].
       
   583 
       
   584     wasClipped ifTrue:[
       
   585         self clippedByChildren:(clipChildren := true). 
       
   586     ].
       
   587 
       
   588     "/ must redraw all components which are affected b the handles
       
   589 
       
   590     r := (aComponent originRelativeTo:self) - (4@4)
       
   591              extent:(aComponent extent + (4@4)).
       
   592 
       
   593     subViews do:[:anotherComponent |
       
   594         |absOrg absFrame|
       
   595 
       
   596         anotherComponent ~~ inputView ifTrue:[
       
   597             absOrg := anotherComponent originRelativeTo:self.
       
   598             absFrame := absOrg extent:(anotherComponent extent).
       
   599             (absFrame intersects:r) ifTrue:[
       
   600                 anotherComponent withAllSubViewsDo:[:v |
       
   601                     v clear.
       
   602                     v exposeX:0 y:0 width:9999 height:9999.
       
   603                 ]
       
   604             ]
       
   605         ]
       
   606     ]
       
   607 
       
   608 !
       
   609 
       
   610 whichHandleOf:aView isHitBy:aPoint
       
   611     |bounds|
       
   612 
       
   613     self handlesOf:aView do:[:pnt :what |
       
   614         ((pnt - (4@4) extent:7@7) containsPoint:aPoint) ifTrue:[
       
   615             ^ what
       
   616         ].
       
   617     ].
       
   618 
       
   619     ^ #view
       
   620 
       
   621     "Modified: 5.9.1995 / 14:39:34 / claus"
       
   622 
       
   623 ! !
       
   624 
       
   625 !UIObjectView methodsFor:'private resizing-subviews'!
       
   626 
       
   627 resize:aView bottom:aPoint
       
   628 
       
   629     undoHistory disabledTransitionDo:[
       
   630         self shifLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
       
   631     ]
       
   632 !
       
   633 
       
   634 resize:aView corner:aPoint
       
   635     |delta|
       
   636 
       
   637     delta := aPoint - aView computeCorner.
       
   638 
       
   639     undoHistory disabledTransitionDo:[
       
   640         self shifLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
       
   641     ]
       
   642 !
       
   643 
       
   644 resize:aView left:aPoint
       
   645 
       
   646     undoHistory disabledTransitionDo:[
       
   647         self shifLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
       
   648     ]
       
   649 
       
   650 !
       
   651 
       
   652 resize:aView right:aPoint
       
   653 
       
   654     undoHistory disabledTransitionDo:[
       
   655         self shifLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
       
   656     ]
       
   657 !
       
   658 
       
   659 resize:aView top:aPoint
       
   660 
       
   661     undoHistory disabledTransitionDo:[
       
   662         self shifLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
       
   663     ]
       
   664 ! !
       
   665 
       
   666 !UIObjectView methodsFor:'private shift-layout'!
       
   667 
       
   668 shifLayout:aView left:l right:r
       
   669     "shift layout for a view; in case of an open transaction, the
       
   670      undoAction will be defined
       
   671     "
       
   672     self shifLayout:aView top:0 bottom:0 left:l right:r
       
   673 
       
   674 !
       
   675 
       
   676 shifLayout:aView top:t bottom:b
       
   677     "shift layout for a view; in case of an open transaction, the
       
   678      undoAction will be defined
       
   679     "
       
   680     self shifLayout:aView top:t bottom:b left:0 right:0
       
   681 
       
   682 
       
   683 !
       
   684 
       
   685 shifLayout:aView top:t bottom:b left:l right:r
       
   686     "shift layout for a view; in case of an open transaction, the
       
   687      undoAction will be defined
       
   688     "
       
   689     |layout|
       
   690 
       
   691     self undoBlockPositionChanged:aView.
       
   692 
       
   693     layout := aView geometryLayout.
       
   694 
       
   695     layout leftOffset:(layout leftOffset + l)
       
   696             topOffset:(layout topOffset  + t).
       
   697 
       
   698     layout isLayoutFrame ifTrue:[
       
   699         layout bottomOffset:(layout bottomOffset + b).
       
   700         layout  rightOffset:(layout rightOffset  + r).
       
   701     ].
       
   702 
       
   703     aView geometryLayout:layout.
       
   704 
       
   705 
       
   706 
       
   707 ! !
       
   708 
       
   709 !UIObjectView methodsFor:'private undo-actions'!
       
   710 
       
   711 undoBlockDimensionChanged:aView
       
   712 
       
   713     undoHistory isTransactionOpen ifTrue:[
       
   714         |layout|
       
   715 
       
   716         layout := aView geometryLayout copy.
       
   717 
       
   718         undoHistory addUndoBlock:[
       
   719             aView geometryLayout:layout.
       
   720             aView superView sizeChanged:nil.
       
   721         ]
       
   722     ]
       
   723 
       
   724 !
       
   725 
       
   726 undoBlockPositionChanged:aView
       
   727 
       
   728     undoHistory isTransactionOpen ifTrue:[
       
   729         |layout|
       
   730 
       
   731         layout := aView geometryLayout copy.
       
   732         undoHistory addUndoBlock:[aView geometryLayout:layout]
       
   733     ]
       
   734 
       
   735 ! !
       
   736 
       
   737 !UIObjectView methodsFor:'searching'!
       
   738 
       
   739 findObjectAt:aPoint
       
   740     "find the origin/corner of the currentWidget
       
   741     "
       
   742     |view viewId lastId point|
       
   743 
       
   744     viewId := rootView id.
       
   745     point  := aPoint + (device translatePoint:0@0 from:(self id) to:viewId).
       
   746 
       
   747     inputView lower.
       
   748 
       
   749     [viewId notNil] whileTrue:[
       
   750         lastId := viewId.
       
   751         viewId := device viewIdFromPoint:point in:lastId
       
   752     ].
       
   753 
       
   754     inputView raise.
       
   755 
       
   756     view := device viewFromId:lastId.
       
   757 
       
   758     view ~~ inputView ifTrue:[^ view]
       
   759                      ifFalse:[^ nil]
       
   760 
       
   761 
       
   762 !
       
   763 
       
   764 isPoint:aPoint containedIn:aView
       
   765     "checks whether a point is covered by a view.
       
   766     "
       
   767     |org ext|
       
   768 
       
   769     org := aView computeOrigin.
       
   770     ext := aView computeExtent.
       
   771 
       
   772     ^ ((org extent:ext) containsPoint:aPoint)
       
   773 !
       
   774 
       
   775 whichBorderOf:aView isHitBy:aPoint
       
   776     |p r bw org|
       
   777 
       
   778     bw := aView borderWidth.
       
   779     p := aPoint - (aView superView originRelativeTo:self).
       
   780 
       
   781     r := Rectangle origin:(aView origin)
       
   782                    extent:(aView width @ bw).
       
   783     (r containsPoint:p) ifTrue:[^ #top:].
       
   784 
       
   785     r origin:(aView left @ (aView bottom + bw)) extent:(aView width @ bw).
       
   786     (r containsPoint:p) ifTrue:[^ #bottom:].
       
   787 
       
   788     r top:(aView top).
       
   789     r extent:(bw @ aView height).
       
   790     (r containsPoint:p) ifTrue:[^ #left:].
       
   791 
       
   792     r origin:((aView right + bw) @ aView top).
       
   793     (r containsPoint:p) ifTrue:[^ #right:].
       
   794 
       
   795     ^ nil
       
   796 
       
   797 
       
   798 ! !
       
   799 
       
   800 !UIObjectView methodsFor:'selections'!
       
   801 
       
   802 addToSelection:something
       
   803     (testMode or:[something == selection]) ifFalse:[
       
   804         super addToSelection:something.
       
   805         self changed:#selection.
       
   806     ]
       
   807 !
       
   808 
       
   809 inspectSelection
       
   810     self singleSelectionDo:[:aView |
       
   811         aView inspect
       
   812     ]
       
   813 !
       
   814 
       
   815 removeFromSelection:something
       
   816     super removeFromSelection:something.
       
   817     self changed:#selection
       
   818 
       
   819 !
       
   820 
       
   821 select:something
       
   822     (testMode or:[something == selection]) ifFalse:[
       
   823         super select:something.
       
   824         self changed:#selection
       
   825     ]
       
   826 
       
   827 !
       
   828 
       
   829 selection
       
   830     ^ selection
       
   831 
       
   832 
       
   833 !
       
   834 
       
   835 selectionFindMinimum:aOneArgBlock
       
   836     "returns the minimum value from the block evaluated on each view
       
   837      in the selection
       
   838     "
       
   839     |min val|
       
   840 
       
   841     self selectionDo:[:aView|
       
   842         val := aOneArgBlock value:aView.
       
   843 
       
   844         min isNil ifTrue:[min := val]
       
   845                  ifFalse:[min := min min:val]
       
   846     ].
       
   847     ^ min
       
   848 !
       
   849 
       
   850 selectionHiddenDo:aBlock
       
   851     "apply block to every object in selection"
       
   852 
       
   853     self selectionDo:[:aView |
       
   854         self showUnselected:aView.
       
   855     ].
       
   856     device flush.
       
   857     aBlock value.
       
   858     self selectionDo:[:aView |
       
   859         self showSelected:aView
       
   860     ]
       
   861 
       
   862 
       
   863 !
       
   864 
       
   865 singleSelection
       
   866     "returns single selection or nil
       
   867     "
       
   868     (selection isKindOf:SimpleView) ifTrue:[^ selection]
       
   869                                    ifFalse:[^ nil]
       
   870 !
       
   871 
       
   872 singleSelectionDo:aBlock
       
   873 
       
   874     self singleSelection notNil ifTrue:[
       
   875         aBlock value:selection
       
   876     ]
       
   877 !
       
   878 
       
   879 unselect
       
   880     selection notNil ifTrue:[
       
   881         super unselect.
       
   882         self changed:#selection
       
   883     ]
       
   884 
       
   885 !
       
   886 
       
   887 withSelectionHiddenDo:aBlock
       
   888     "evaluate aBlock while selection is hidden"
       
   889 
       
   890     |sel|
       
   891 
       
   892     selection isNil ifTrue:[
       
   893         aBlock value
       
   894     ] ifFalse:[
       
   895         sel := selection.
       
   896         super unselect.
       
   897         aBlock value.
       
   898         super select:sel
       
   899     ]
       
   900 
       
   901     "Modified: 6.9.1995 / 01:46:16 / claus"
       
   902 
       
   903 
       
   904 ! !
       
   905 
       
   906 !UIObjectView methodsFor:'testing'!
       
   907 
       
   908 canMove:something
       
   909     ^ true
       
   910 
       
   911 
       
   912 !
       
   913 
       
   914 isHorizontalResizable:aComponent
       
   915     ^ self subclassResponsibility
       
   916 
       
   917 
       
   918 !
       
   919 
       
   920 isVerticalResizable:aComponent
       
   921     ^ self subclassResponsibility
       
   922 
       
   923 
       
   924 ! !
       
   925 
       
   926 !UIObjectView methodsFor:'user actions'!
       
   927 
       
   928 createWidgetWithClass:aClass
       
   929     "prepare to create new widgets
       
   930     "
       
   931     createClass := aClass.
       
   932     pressAction := [:pressPoint | self startCreate:pressPoint].
       
   933     self cursor:Cursor origin.
       
   934 
       
   935 
       
   936 !
       
   937 
       
   938 undoAction
       
   939     undoHistory notEmpty ifTrue:[
       
   940         self unselect.
       
   941         undoHistory undoLast
       
   942     ]
       
   943 
       
   944 
       
   945 ! !
       
   946 
       
   947 !UIObjectView methodsFor:'user actions - dimension'!
       
   948 
       
   949 copyExtent
       
   950     (selection isNil or:[selection isKindOf:Collection]) ifTrue:[
       
   951         ^ self warn:'exactly one element must be selected'.
       
   952     ].
       
   953     copiedExtent := selection computeExtent
       
   954 
       
   955 
       
   956 
       
   957 !
       
   958 
       
   959 pasteExtent
       
   960     copiedExtent notNil ifTrue:[
       
   961         self transition:'paste extent' dimensionDo:[:v|
       
   962             self resize:v corner:(v computeOrigin + copiedExtent)
       
   963         ]    
       
   964     ]    
       
   965 !
       
   966 
       
   967 pasteHeight
       
   968     copiedExtent notNil ifTrue:[
       
   969         self transition:'paste height' dimensionDo:[:v|
       
   970             self resize:v bottom:(v computeOrigin + copiedExtent)
       
   971         ]    
       
   972     ]    
       
   973 
       
   974 !
       
   975 
       
   976 pasteWidth
       
   977     copiedExtent notNil ifTrue:[
       
   978         self transition:'paste width' dimensionDo:[:v|
       
   979             self resize:v right:(v computeOrigin + copiedExtent)
       
   980         ]    
       
   981     ]    
       
   982 
       
   983 !
       
   984 
       
   985 setDimension:aLayout
       
   986     |undoText|
       
   987 
       
   988     undoText := 'change layout'.
       
   989     aLayout isLayout ifTrue:[
       
   990         undoText := 'change to layout frame'.
       
   991         aLayout isAlignmentOrigin ifTrue:[
       
   992             undoText := 'change to layout alignOrigin'.
       
   993         ] ifFalse:[
       
   994             aLayout isAlignmentOrigin ifTrue:[
       
   995                 undoText := 'change to layout origin'.
       
   996             ]
       
   997         ]
       
   998     ].
       
   999 
       
  1000     self transition:undoText dimensionDo:[:v| v geometryLayout:(aLayout copy)]    
       
  1001 
       
  1002 !
       
  1003 
       
  1004 setToDefaultExtent
       
  1005     self transition:'default extent' dimensionDo:[:v|
       
  1006         self resize:v corner:(v computeOrigin + (v preferredExtent))
       
  1007     ]    
       
  1008 
       
  1009 !
       
  1010 
       
  1011 setToDefaultHeight
       
  1012     self transition:'default height' dimensionDo:[:v|
       
  1013         self resize:v bottom:(v computeOrigin + (v preferredExtent))
       
  1014     ]    
       
  1015 
       
  1016 !
       
  1017 
       
  1018 setToDefaultWidth
       
  1019     self transition:'default width' dimensionDo:[:v|
       
  1020         self resize:v right:(v computeOrigin + (v preferredExtent))
       
  1021     ]    
       
  1022 
       
  1023 !
       
  1024 
       
  1025 transition:what dimensionDo:aOneArgBlock
       
  1026     "change dimension within a transaction for the selected elements by evaluating
       
  1027      the block with the argument a view.
       
  1028     "
       
  1029     self selectionHiddenDo:[
       
  1030         undoHistory transactionNamed:what do:[
       
  1031             self selectionDo:[:aView|
       
  1032                 self undoBlockDimensionChanged:aView.
       
  1033                 aOneArgBlock value:aView.
       
  1034                 self elementChangedLayout:aView.
       
  1035             ]
       
  1036         ]
       
  1037     ]
       
  1038 ! !
       
  1039 
       
  1040 !UIObjectView methodsFor:'user actions - move'!
       
  1041 
       
  1042 basicMoveSelectionHorizontal:n
       
  1043     "move left:  n < 0
       
  1044      move right: n > 0
       
  1045     "
       
  1046     self selectionHiddenDo:[
       
  1047         undoHistory transactionNamed:'move' do:[
       
  1048             self selectionDo:[:aView|self shifLayout:aView left:n right:n]
       
  1049         ].
       
  1050         self changed:#layout
       
  1051     ]
       
  1052 
       
  1053 
       
  1054 !
       
  1055 
       
  1056 basicMoveSelectionVertical:n
       
  1057     "move up:   n < 0
       
  1058      move down: n > 0
       
  1059     "
       
  1060     self selectionHiddenDo:[
       
  1061         undoHistory transactionNamed:'move' do:[
       
  1062             self selectionDo:[:aView| self shifLayout:aView top:n bottom:n ]
       
  1063         ].
       
  1064         self changed:#layout
       
  1065     ]
       
  1066 
       
  1067 
       
  1068 
       
  1069 !
       
  1070 
       
  1071 moveObject:anObject to:aPoint
       
  1072     "move anObject to newOrigin, aPoint
       
  1073     "
       
  1074     |dX dY org delta|
       
  1075 
       
  1076     anObject notNil ifTrue:[
       
  1077         org := anObject computeOrigin.
       
  1078 
       
  1079         delta := aPoint - org.
       
  1080         delta := (self alignToGrid:aPoint) - org.
       
  1081         dX := delta x.
       
  1082         dY := delta y.
       
  1083 
       
  1084         undoHistory disabledTransitionDo:[
       
  1085             self shifLayout:anObject top:dY bottom:dY left:dX right:dX
       
  1086         ].
       
  1087         self elementChangedLayout:anObject.
       
  1088     ]
       
  1089 
       
  1090 !
       
  1091 
       
  1092 moveSelectionDown
       
  1093     self moveSelectionDown:1
       
  1094 
       
  1095 
       
  1096 !
       
  1097 
       
  1098 moveSelectionDown10
       
  1099     self moveSelectionDown:10
       
  1100 
       
  1101 
       
  1102 !
       
  1103 
       
  1104 moveSelectionDown:n
       
  1105     self basicMoveSelectionVertical:n
       
  1106 
       
  1107 
       
  1108 !
       
  1109 
       
  1110 moveSelectionLeft
       
  1111     self moveSelectionLeft:1
       
  1112 
       
  1113 
       
  1114 !
       
  1115 
       
  1116 moveSelectionLeft10
       
  1117     self moveSelectionLeft:10
       
  1118 
       
  1119 
       
  1120 !
       
  1121 
       
  1122 moveSelectionLeft:n
       
  1123     self basicMoveSelectionHorizontal:(n negated)
       
  1124 
       
  1125 
       
  1126 !
       
  1127 
       
  1128 moveSelectionRight
       
  1129     self moveSelectionRight:1
       
  1130 
       
  1131 
       
  1132 !
       
  1133 
       
  1134 moveSelectionRight10
       
  1135     self moveSelectionRight:10
       
  1136 
       
  1137 
       
  1138 !
       
  1139 
       
  1140 moveSelectionRight:n
       
  1141     self basicMoveSelectionHorizontal:n
       
  1142 
       
  1143 
       
  1144 !
       
  1145 
       
  1146 moveSelectionUp
       
  1147     self moveSelectionUp:1
       
  1148 
       
  1149 
       
  1150 !
       
  1151 
       
  1152 moveSelectionUp10
       
  1153     self moveSelectionUp:10
       
  1154 
       
  1155 
       
  1156 !
       
  1157 
       
  1158 moveSelectionUp:n
       
  1159     self basicMoveSelectionVertical:(n negated)
       
  1160 
       
  1161 
       
  1162 ! !
       
  1163 
       
  1164 !UIObjectView methodsFor:'user actions - position'!
       
  1165 
       
  1166 alignSelectionBottom
       
  1167     |bmost delta|
       
  1168 
       
  1169     self selectionHiddenDo:[
       
  1170         bmost := 0.
       
  1171         self selectionDo:[:v| bmost := bmost max:(v computeCorner y)].
       
  1172 
       
  1173         undoHistory transactionNamed:'align' do:[
       
  1174             self selectionDo:[:v|
       
  1175                 (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[
       
  1176                     self shifLayout:v top:delta bottom:delta
       
  1177                 ]
       
  1178             ]
       
  1179         ].
       
  1180         self changed:#layout
       
  1181     ]
       
  1182 
       
  1183 
       
  1184 
       
  1185 !
       
  1186 
       
  1187 alignSelectionCenterHor
       
  1188     |counter centerX|
       
  1189 
       
  1190     self selectionHiddenDo:[
       
  1191         counter := 0.
       
  1192         centerX := 0.
       
  1193 
       
  1194         self selectionDo:[:v |
       
  1195             centerX := centerX + (v computeCorner x + v computeOrigin x).
       
  1196             counter := counter + 1.
       
  1197         ].
       
  1198         centerX := centerX // (counter * 2).
       
  1199 
       
  1200         undoHistory transactionNamed:'align' do:[
       
  1201             |newX oldX delta|
       
  1202 
       
  1203             self selectionDo:[:v|
       
  1204                 oldX  := v computeOrigin x.
       
  1205                 newX  := centerX - ((v computeCorner x - oldX) // 2).
       
  1206                 delta := newX - oldX.
       
  1207 
       
  1208                 self shifLayout:v left:delta right:delta
       
  1209             ]
       
  1210         ].
       
  1211         self changed:#layout
       
  1212     ]
       
  1213 
       
  1214 
       
  1215 
       
  1216 !
       
  1217 
       
  1218 alignSelectionCenterVer
       
  1219     |counter centerY|
       
  1220 
       
  1221     self selectionHiddenDo:[
       
  1222         counter := 0.
       
  1223         centerY := 0.
       
  1224 
       
  1225         self selectionDo:[:v |
       
  1226             centerY := centerY + (v computeCorner y + v computeOrigin y).
       
  1227             counter := counter + 1.
       
  1228         ].
       
  1229         centerY := centerY // (counter * 2).
       
  1230 
       
  1231         undoHistory transactionNamed:'align' do:[
       
  1232             |newY oldY delta|
       
  1233 
       
  1234             self selectionDo:[:v|
       
  1235                 oldY  := v computeOrigin y.
       
  1236                 newY  := centerY - ((v computeCorner y - oldY) // 2).
       
  1237                 delta := newY - oldY.
       
  1238 
       
  1239                 self shifLayout:v top:delta bottom:delta
       
  1240             ]
       
  1241         ].
       
  1242         self changed:#layout
       
  1243     ]
       
  1244 !
       
  1245 
       
  1246 alignSelectionLeft
       
  1247     |lmost delta|
       
  1248 
       
  1249     self selectionHiddenDo:[
       
  1250         lmost := self selectionFindMinimum:[:v| v computeOrigin x].
       
  1251 
       
  1252         undoHistory transactionNamed:'align' do:[
       
  1253             self selectionDo:[:v|
       
  1254                 (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[
       
  1255                     self shifLayout:v left:delta right:delta
       
  1256                 ]
       
  1257             ]
       
  1258         ].
       
  1259         self changed:#layout
       
  1260     ]
       
  1261 
       
  1262 !
       
  1263 
       
  1264 alignSelectionLeftAndRight
       
  1265     |lmost rmost|
       
  1266 
       
  1267     self selectionHiddenDo:[
       
  1268         lmost := self selectionFindMinimum:[:v| v computeOrigin x].
       
  1269         rmost := 0.
       
  1270         self selectionDo:[:v | rmost := rmost max:(v computeCorner x)].
       
  1271 
       
  1272         undoHistory transactionNamed:'align' do:[
       
  1273             self selectionDo:[:v|
       
  1274                 self shifLayout:v left:(lmost - (v computeOrigin x))
       
  1275                                  right:(rmost - (v computeCorner x))
       
  1276             ]
       
  1277         ].
       
  1278         self changed:#layout
       
  1279     ]
       
  1280 !
       
  1281 
       
  1282 alignSelectionRight
       
  1283     |rmost delta|
       
  1284 
       
  1285     self selectionHiddenDo:[
       
  1286         rmost := 0.
       
  1287         self selectionDo:[:v| rmost := rmost max:(v computeCorner x)].
       
  1288 
       
  1289         undoHistory transactionNamed:'align' do:[
       
  1290             self selectionDo:[:v|
       
  1291                 (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[
       
  1292                     self shifLayout:v left:delta right:delta
       
  1293                 ]
       
  1294             ]
       
  1295         ].
       
  1296         self changed:#layout
       
  1297     ]
       
  1298 
       
  1299 !
       
  1300 
       
  1301 alignSelectionTop
       
  1302     |tmost delta|
       
  1303 
       
  1304     self selectionHiddenDo:[
       
  1305         tmost := self selectionFindMinimum:[:v| v computeOrigin y].
       
  1306 
       
  1307         undoHistory transactionNamed:'align' do:[
       
  1308             self selectionDo:[:v||delta|
       
  1309                 (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[
       
  1310                     self shifLayout:v top:delta bottom:delta
       
  1311                 ]
       
  1312             ]
       
  1313         ].
       
  1314         self changed:#layout
       
  1315     ]
       
  1316 
       
  1317 !
       
  1318 
       
  1319 alignSelectionTopAndBottom
       
  1320     |tmost bmost|
       
  1321 
       
  1322     self selectionHiddenDo:[
       
  1323         tmost := self selectionFindMinimum:[:v| v computeOrigin y].
       
  1324         bmost := 0.
       
  1325         self selectionDo:[:v| bmost := bmost max:(v computeCorner y)].
       
  1326 
       
  1327         undoHistory transactionNamed:'align' do:[
       
  1328             self selectionDo:[:v|
       
  1329                 self shifLayout:v top:(tmost - (v computeOrigin y))
       
  1330                                bottom:(bmost - (v computeCorner y))
       
  1331             ]
       
  1332         ].
       
  1333         self changed:#layout
       
  1334     ]
       
  1335 !
       
  1336 
       
  1337 centerSelection:aOneArgBlockXorY
       
  1338     "center selection horizontal or vertical dependant on the block result( x or y).
       
  1339      The argument to the block is the point.
       
  1340     "
       
  1341     |superview min max delta val|
       
  1342 
       
  1343     self selectionHiddenDo:[
       
  1344         max := 0.
       
  1345 
       
  1346         self selectionDo:[:aView |
       
  1347             superview isNil ifTrue:[
       
  1348                 superview := aView superView
       
  1349             ] ifFalse:[
       
  1350                 (aView superView == superview) ifFalse:[
       
  1351                     ^ self notify:'views must have same superview'.
       
  1352                 ]
       
  1353             ].
       
  1354             val := aOneArgBlockXorY value:(aView computeOrigin).    
       
  1355 
       
  1356             min isNil ifTrue:[min := val]
       
  1357                      ifFalse:[min := min min:val].
       
  1358 
       
  1359             val := aOneArgBlockXorY value:(aView computeCorner).
       
  1360             max := max max:val.
       
  1361         ].
       
  1362 
       
  1363         val := aOneArgBlockXorY value:(superview computeExtent).
       
  1364         max := (min + val - max) // 2.
       
  1365 
       
  1366         max == min ifFalse:[
       
  1367             delta := max - min.
       
  1368 
       
  1369             undoHistory transactionNamed:'center' do:[
       
  1370                 self selectionDo:[:aView|
       
  1371                     self shifLayout:aView top:delta bottom:delta]
       
  1372             ]
       
  1373         ].
       
  1374         self changed:#layout
       
  1375     ]
       
  1376 
       
  1377 
       
  1378 !
       
  1379 
       
  1380 centerSelectionHor
       
  1381     "center selection horizontal
       
  1382     "
       
  1383     self centerSelection:[:aPoint| aPoint x]
       
  1384 
       
  1385 
       
  1386 !
       
  1387 
       
  1388 centerSelectionVer
       
  1389     "center selection vertical
       
  1390     "
       
  1391     self centerSelection:[:aPoint| aPoint y]
       
  1392 !
       
  1393 
       
  1394 spreadSelectionHor
       
  1395     |sumWidths min max viewsInOrder topsInOrder count space|
       
  1396 
       
  1397     (selection isKindOf:Collection) ifFalse:[^ self].
       
  1398 
       
  1399     self selectionHiddenDo:[
       
  1400         count := 0.
       
  1401         sumWidths := 0.
       
  1402         max := 0.
       
  1403 
       
  1404         self selectionDo:[:aView |
       
  1405             sumWidths := sumWidths + aView width.
       
  1406 
       
  1407             min isNil ifTrue:[min := aView left]
       
  1408                      ifFalse:[min := min min:(aView left)].
       
  1409 
       
  1410             max := max max:(aView right).
       
  1411             count := count + 1
       
  1412         ].
       
  1413         viewsInOrder := Array withAll:selection.
       
  1414         topsInOrder  := viewsInOrder collect:[:aView | aView left].
       
  1415         topsInOrder sortWith:viewsInOrder.
       
  1416 
       
  1417         space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger.
       
  1418 
       
  1419         undoHistory transactionNamed:'spread' do:[
       
  1420             viewsInOrder do:[:aView | 
       
  1421                 |delta|
       
  1422 
       
  1423                 delta := min - aView computeOrigin x.
       
  1424                 self shifLayout:aView left:delta right:delta.
       
  1425                 min := min + aView computeExtent x + space
       
  1426             ]
       
  1427         ].
       
  1428         self changed:#layout
       
  1429     ]
       
  1430 
       
  1431 !
       
  1432 
       
  1433 spreadSelectionVer
       
  1434     |sumHeights min max viewsInOrder topsInOrder count space|
       
  1435 
       
  1436     (selection isKindOf:Collection) ifFalse:[^ self].
       
  1437 
       
  1438     self selectionHiddenDo:[
       
  1439         count := 0.
       
  1440         sumHeights := 0.
       
  1441         max := 0.
       
  1442 
       
  1443         self selectionDo:[:aView |
       
  1444             sumHeights := sumHeights + aView height.
       
  1445 
       
  1446             min isNil ifTrue:[min := aView top]
       
  1447                      ifFalse:[min := min min:(aView top)].
       
  1448 
       
  1449             max   := max max:(aView bottom).
       
  1450             count := count + 1
       
  1451         ].
       
  1452         viewsInOrder := Array withAll:selection.
       
  1453         topsInOrder  := viewsInOrder collect:[:aView|aView top].
       
  1454         topsInOrder sortWith:viewsInOrder.
       
  1455 
       
  1456         space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger.
       
  1457 
       
  1458         undoHistory transactionNamed:'spread' do:[
       
  1459             viewsInOrder do:[:aView||delta|
       
  1460                 delta := min - aView computeOrigin y.
       
  1461                 self shifLayout:aView top:delta bottom:delta.
       
  1462                 min := min + aView height + space
       
  1463             ]
       
  1464         ].
       
  1465         self changed:#layout
       
  1466     ]
       
  1467 ! !
       
  1468 
       
  1469 !UIObjectView methodsFor:'user actions - resize'!
       
  1470 
       
  1471 doDragResize:aPoint
       
  1472     "do a widget resize drag"
       
  1473 
       
  1474     |p|
       
  1475 
       
  1476     self invertOutlineOf:resizedObject.
       
  1477     p := (self alignToGrid:aPoint) - (resizedObject container originRelativeTo:self).
       
  1478     self perform:('x' , resizeSelector , ':') asSymbol with:p.
       
  1479     resizedObject geometryLayout:(resizedObject geometryLayout).
       
  1480     self invertOutlineOf:resizedObject
       
  1481 
       
  1482     "Modified: 5.9.1995 / 17:11:46 / claus"
       
  1483 
       
  1484 !
       
  1485 
       
  1486 endResize
       
  1487     "cleanup after object resize"
       
  1488 
       
  1489     self invertOutlineOf:resizedObject.
       
  1490     self setDefaultActions.
       
  1491     self select:resizedObject.
       
  1492     resizedObject := nil
       
  1493 
       
  1494     "Modified: 5.9.1995 / 17:11:17 / claus"
       
  1495 
       
  1496 !
       
  1497 
       
  1498 startResizeBorder:b of:selection at:aPoint
       
  1499     "resize selected view
       
  1500     "
       
  1501     resizedObject := self singleSelection.
       
  1502 
       
  1503     resizedObject notNil ifTrue:[
       
  1504         resizeSelector := b.
       
  1505         super unselect.
       
  1506 
       
  1507         undoHistory transactionNamed:'extent' do:[
       
  1508             self undoBlockDimensionChanged:resizedObject.
       
  1509         ].
       
  1510 
       
  1511         motionAction := [:movePoint | self doDragResize:movePoint].
       
  1512         releaseAction := [self endResize].
       
  1513         self invertOutlineOf:resizedObject
       
  1514     ]
       
  1515 !
       
  1516 
       
  1517 xbottom:aPoint
       
  1518     self resize:resizedObject bottom:aPoint
       
  1519 
       
  1520 !
       
  1521 
       
  1522 xbottomLeft:aPoint
       
  1523     self resize:resizedObject   left:aPoint.
       
  1524     self resize:resizedObject bottom:aPoint.
       
  1525 
       
  1526 !
       
  1527 
       
  1528 xcorner:aPoint
       
  1529     self resize:resizedObject corner:aPoint.
       
  1530 
       
  1531 !
       
  1532 
       
  1533 xleft:aPoint
       
  1534     self resize:resizedObject left:aPoint
       
  1535 
       
  1536 !
       
  1537 
       
  1538 xorigin:aPoint
       
  1539     self resize:resizedObject left:aPoint.
       
  1540     self resize:resizedObject  top:aPoint.
       
  1541 
       
  1542 !
       
  1543 
       
  1544 xright:aPoint
       
  1545     self resize:resizedObject right:aPoint
       
  1546 
       
  1547 !
       
  1548 
       
  1549 xtop:aPoint
       
  1550     self resize:resizedObject top:aPoint
       
  1551 
       
  1552 !
       
  1553 
       
  1554 xtopRight:aPoint
       
  1555     self resize:resizedObject right:aPoint.
       
  1556     self resize:resizedObject   top:aPoint.
       
  1557 
    13 
  1558 ! !
    14 ! !
  1559 
    15 
  1560 !UIObjectView::UndoHistory class methodsFor:'constants'!
    16 !UIObjectView::UndoHistory class methodsFor:'constants'!
  1561 
    17 
  1562 maxHistorySize
    18 maxHistorySize
  1563     "returns maximum size of history before removing oldest
    19     "returns maximum size of history before removing oldest
  1564      record
    20      record
  1565     "
    21     "
  1566     ^ 50
    22     ^ 50
  1567 
       
  1568 
       
  1569 ! !
       
  1570 
       
  1571 !UIObjectView::UndoHistory class methodsFor:'instance creation'!
       
  1572 
       
  1573 new
       
  1574     ^ self basicNew initialize
       
  1575 
    23 
  1576 
    24 
  1577 ! !
    25 ! !
  1578 
    26 
  1579 !UIObjectView::UndoHistory methodsFor:'accessing'!
    27 !UIObjectView::UndoHistory methodsFor:'accessing'!
  1758     ]
   206     ]
  1759 
   207 
  1760 
   208 
  1761 ! !
   209 ! !
  1762 
   210 
  1763 !UIObjectView class methodsFor:'documentation'!
       
  1764 
       
  1765 version
       
  1766     ^ '$Header$'
       
  1767 ! !