UIObjectView.st
author Claus Gittinger <cg@exept.de>
Wed, 29 Jul 2009 20:02:02 +0200
changeset 2570 4e663bc64364
parent 2555 322f0de7da00
child 2688 98d48fa622b4
permissions -rw-r--r--
changed #requestPackage
cg@156
     1
"
cg@156
     2
 COPYRIGHT (c) 1995 by eXept Software AG
cg@1120
     3
	      All Rights Reserved
cg@156
     4
cg@156
     5
 This software is furnished under a license and may be used
cg@156
     6
 only in accordance with the terms of that license and with the
cg@156
     7
 inclusion of the above copyright notice.   This software may not
cg@156
     8
 be provided or otherwise made available to, or used by, any
cg@156
     9
 other person.  No title to or ownership of the software is
cg@156
    10
 hereby transferred.
cg@156
    11
"
cg@1399
    12
"{ Package: 'stx:libtool2' }"
cg@1399
    13
cg@60
    14
ObjectView subclass:#UIObjectView
ca@1672
    15
	instanceVariableNames:'saveSelection undoHistory copiedExtent copiedLayout resizeData
ca@1672
    16
		clipChildren selectionHiddenLevel gridParameters
cg@1954
    17
		setOfSuperViewsSizeChanged hasUndoHistoryHolder'
cg@2364
    18
	classVariableNames:'CopiedLayout CopiedExtent'
cg@60
    19
	poolDictionaries:''
cg@60
    20
	category:'Interface-UIPainter'
cg@60
    21
!
cg@60
    22
ca@1672
    23
Object subclass:#PostEventHandler
ca@1672
    24
	instanceVariableNames:'onView'
ca@1672
    25
	classVariableNames:''
ca@1672
    26
	poolDictionaries:''
ca@1672
    27
	privateIn:UIObjectView
ca@1672
    28
!
ca@1672
    29
ca@1437
    30
Object subclass:#ResizeData
cg@2536
    31
	instanceVariableNames:'object selector checkForChangeSelector delta'
ca@1437
    32
	classVariableNames:''
ca@1437
    33
	poolDictionaries:''
ca@1437
    34
	privateIn:UIObjectView
ca@1437
    35
!
ca@1437
    36
cg@60
    37
Object subclass:#UndoHistory
ca@134
    38
	instanceVariableNames:'startIdentifier identifier painter history transaction enabled'
cg@60
    39
	classVariableNames:''
cg@60
    40
	poolDictionaries:''
cg@60
    41
	privateIn:UIObjectView
cg@60
    42
!
cg@60
    43
ca@54
    44
Object subclass:#Transaction
ca@134
    45
	instanceVariableNames:'identifier type text actions'
ca@54
    46
	classVariableNames:''
ca@54
    47
	poolDictionaries:''
ca@54
    48
	privateIn:UIObjectView::UndoHistory
ca@54
    49
!
ca@54
    50
ca@128
    51
!UIObjectView class methodsFor:'documentation'!
ca@128
    52
cg@156
    53
copyright
cg@156
    54
"
cg@156
    55
 COPYRIGHT (c) 1995 by eXept Software AG
cg@1120
    56
	      All Rights Reserved
cg@156
    57
cg@156
    58
 This software is furnished under a license and may be used
cg@156
    59
 only in accordance with the terms of that license and with the
cg@156
    60
 inclusion of the above copyright notice.   This software may not
cg@156
    61
 be provided or otherwise made available to, or used by, any
cg@156
    62
 other person.  No title to or ownership of the software is
cg@156
    63
 hereby transferred.
cg@156
    64
"
cg@156
    65
cg@156
    66
cg@156
    67
!
cg@156
    68
ca@128
    69
documentation
ca@128
    70
"
ca@131
    71
    buildIn view used by the UIPainter; it provides all services for creating, deleting
ca@131
    72
    moving and changing layouts of painted components on a canvas.
ca@128
    73
ca@128
    74
    [see also:]
cg@1120
    75
	UIBuilder
cg@1120
    76
	UIPainterView
cg@156
    77
cg@156
    78
    [author:]
cg@1120
    79
	Claus Atzkern
ca@128
    80
"
ca@128
    81
ca@128
    82
! !
cg@60
    83
ca@63
    84
!UIObjectView class methodsFor:'conversion'!
ca@63
    85
ca@63
    86
asLayoutFrameFromView:aView
ca@63
    87
    "convert layout from aView to a frameLayout. On success the frameLayout is
ca@63
    88
     returned otherwise nil
ca@63
    89
    "
ca@68
    90
    |lF lO rF rO tF tO bF bO type layout newLyt|
ca@68
    91
ca@68
    92
    type   := self layoutType:aView.
ca@68
    93
    layout := aView geometryLayout.
ca@68
    94
cg@91
    95
    layout isNil ifTrue:[
cg@1581
    96
        type == #Extent ifTrue:[
cg@1581
    97
            layout := aView bounds asLayout
cg@1581
    98
        ]
cg@91
    99
    ].
cg@91
   100
ca@68
   101
    (type isNil or:[layout isNil]) ifTrue:[
cg@1581
   102
        ^ nil
ca@63
   103
    ].
ca@63
   104
ca@68
   105
    type == #LayoutFrame ifTrue:[
cg@1581
   106
        ^ layout copy
ca@68
   107
    ].
ca@68
   108
ca@68
   109
    layout isLayout ifFalse:[
cg@1581
   110
        type == #Rectangle ifTrue:[
cg@1581
   111
            lO := layout left.
cg@1581
   112
            tO := layout top.
cg@1581
   113
            rO := layout right.
cg@1581
   114
            bO := layout bottom.
cg@1581
   115
        ] ifFalse:[
cg@1581
   116
            lO := layout x.
cg@1581
   117
            tO := layout y.
cg@1581
   118
            rO := lO + aView extent x.
cg@1581
   119
            bO := tO + aView extent y.
cg@1581
   120
        ].
cg@1581
   121
cg@1581
   122
        ^ LayoutFrame 
cg@1581
   123
                leftFraction:0 offset:lO  
cg@1581
   124
                rightFraction:0 offset:rO
cg@1581
   125
                topFraction:0 offset:tO 
cg@1581
   126
                bottomFraction:0 offset:bO
ca@63
   127
    ].
ca@63
   128
ca@68
   129
    lF := layout leftFraction.
ca@68
   130
    lO := layout leftOffset.
ca@68
   131
    tF := layout topFraction.
ca@68
   132
    tO := layout topOffset.
ca@68
   133
    bF := tF.
ca@68
   134
    bO := tO + aView extent y.
ca@68
   135
    rF := lF.
ca@68
   136
    rO := lO + aView extent x.
ca@68
   137
cg@1581
   138
    newLyt := LayoutFrame 
cg@1581
   139
                leftFraction:lF offset:lO  
cg@1581
   140
                rightFraction:rF offset:rO
cg@1581
   141
                topFraction:tF offset:tO 
cg@1581
   142
                bottomFraction:bF offset:bO.
ca@68
   143
ca@68
   144
    (    (type == #AlignmentOrigin)
ca@68
   145
     and:[layout leftAlignmentFraction ~~ 0
ca@68
   146
      or:[layout topAlignmentFraction  ~~ 0]]
ca@68
   147
    ) ifTrue:[
cg@1581
   148
        |svRc prBd dlta|
cg@1581
   149
cg@1581
   150
        svRc := aView superView viewRectangle.
cg@1581
   151
        prBd := aView preferredBounds.
cg@1581
   152
        dlta := (  ((layout rectangleRelativeTo:svRc preferred:prBd) corner)
cg@1581
   153
                 - ((newLyt rectangleRelativeTo:svRc preferred:prBd) corner)
cg@1581
   154
                ) rounded.
cg@1581
   155
cg@1581
   156
        newLyt 
cg@1581
   157
            leftOffset:(lO + dlta x)
cg@1581
   158
            rightOffset:(rO + dlta x)
cg@1581
   159
            topOffset:(tO + dlta y)
cg@1581
   160
            bottomOffset:(bO + dlta y).
ca@68
   161
    ].
ca@68
   162
  ^ newLyt.
cg@91
   163
cg@91
   164
    "Modified: 28.3.1997 / 19:52:48 / cg"
ca@63
   165
! !
ca@63
   166
cg@60
   167
!UIObjectView class methodsFor:'defaults'!
cg@60
   168
cg@60
   169
defaultGrid
cg@60
   170
    ^ 4 @ 4
cg@60
   171
cg@60
   172
!
cg@60
   173
cg@60
   174
gridShown
cg@60
   175
    ^ false
cg@60
   176
cg@60
   177
!
cg@60
   178
cg@60
   179
handleSize
cg@60
   180
    "size of blob drawn for handles"
cg@60
   181
    ^ 4
cg@60
   182
cg@60
   183
!
cg@60
   184
cg@60
   185
hitDelta
cg@60
   186
    ^ 4
cg@60
   187
cg@60
   188
! !
cg@60
   189
ca@175
   190
!UIObjectView class methodsFor:'handles'!
ca@175
   191
cg@2510
   192
handlesOf:aViewOrComponent do:aBlock
ca@175
   193
    |type v h|
ca@175
   194
cg@2510
   195
    (aViewOrComponent isKindOf:LineSegmentMorph) ifTrue:[
cg@2510
   196
        aBlock value:(aViewOrComponent startPoint) value:#startPoint.
cg@2510
   197
        aBlock value:(aViewOrComponent endPoint) value:#endPoint.
cg@2510
   198
        ^ self.
cg@2510
   199
    ].
cg@2510
   200
cg@2510
   201
    type := self layoutType:aViewOrComponent.
ca@175
   202
ca@175
   203
    (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
cg@2510
   204
        v := self isVerticalResizable:aViewOrComponent.
cg@2510
   205
        h := self isHorizontalResizable:aViewOrComponent.
cg@2501
   206
cg@2501
   207
        h ifTrue:[  
cg@2510
   208
            aBlock value:(aViewOrComponent leftCenter rounded ) value:#left.
cg@2510
   209
            aBlock value:(aViewOrComponent rightCenter rounded) value:#right
cg@2501
   210
        ].
cg@2501
   211
        v ifTrue:[  
cg@2510
   212
            aBlock value:(aViewOrComponent topCenter rounded   ) value:#top.
cg@2510
   213
            aBlock value:(aViewOrComponent bottomCenter rounded) value:#bottom.
cg@2501
   214
        ].
cg@2501
   215
cg@2501
   216
        (h and:[v]) ifTrue:[
cg@2510
   217
            aBlock value:(aViewOrComponent origin    ) value:#origin.
cg@2510
   218
            aBlock value:(aViewOrComponent topRight  ) value:#topRight.
cg@2510
   219
            aBlock value:(aViewOrComponent bottomLeft) value:#bottomLeft.
cg@2510
   220
            aBlock value:(aViewOrComponent corner    ) value:#corner.
cg@2501
   221
            ^ self
cg@2501
   222
        ]
ca@175
   223
    ].
ca@175
   224
cg@2510
   225
    aBlock value:(aViewOrComponent origin    ) value:#view.
cg@2510
   226
    aBlock value:(aViewOrComponent topRight  ) value:#view.
cg@2510
   227
    aBlock value:(aViewOrComponent bottomLeft) value:#view.
ca@175
   228
ca@175
   229
    type == #Extent ifTrue:[
cg@2510
   230
        v := self isVerticalResizable:aViewOrComponent.
cg@2510
   231
        h := self isHorizontalResizable:aViewOrComponent.
cg@2510
   232
cg@2510
   233
        v ifTrue:[ aBlock value:(aViewOrComponent bottomCenter rounded) value:#bottom ].
cg@2510
   234
        h ifTrue:[ aBlock value:(aViewOrComponent rightCenter rounded ) value:#right ].
cg@2501
   235
cg@2501
   236
        (h and:[v]) ifTrue:[
cg@2510
   237
            aBlock value:(aViewOrComponent corner) value:#corner.
cg@2501
   238
            ^ self
cg@2501
   239
        ]
ca@175
   240
    ].
cg@2510
   241
    aBlock value:(aViewOrComponent corner) value:#view.
ca@175
   242
! !
ca@175
   243
ca@61
   244
!UIObjectView class methodsFor:'queries'!
ca@61
   245
ca@175
   246
isHorizontalResizable:aComponent
cg@2510
   247
    "returns true if aComponent is horizontal resizeable
ca@175
   248
    "
ca@175
   249
    (aComponent isKindOf:ScrollBar) ifTrue:[
cg@2510
   250
        ^ aComponent orientation == #horizontal
ca@175
   251
    ].
ca@175
   252
    (aComponent isKindOf:Scroller) ifTrue:[
cg@2510
   253
        ^ aComponent orientation == #horizontal
ca@175
   254
    ].
ca@175
   255
    (aComponent isKindOf:Slider) ifTrue:[
cg@2510
   256
        ^ aComponent orientation == #horizontal
cg@2510
   257
    ].
cg@2510
   258
    (aComponent isKindOf:LineSegmentMorph) ifTrue:[
cg@2510
   259
        ^ false
ca@175
   260
    ].
ca@175
   261
    ^ true
ca@175
   262
!
ca@175
   263
ca@175
   264
isVerticalResizable:aComponent
cg@2510
   265
    "returns true if aComponent is vertical resizeable
ca@175
   266
    "
cg@2364
   267
"/    (aComponent isKindOf:EditField) ifTrue:[
cg@2364
   268
"/        ^ false
cg@2364
   269
"/    ].
cg@2364
   270
"/    (aComponent isKindOf:ComboBoxView) ifTrue:[
cg@2364
   271
"/        ^ false
cg@2364
   272
"/    ].
cg@2364
   273
"/    (aComponent isKindOf:CheckBox) ifTrue:[
cg@2364
   274
"/        ^ false
cg@2364
   275
"/    ].
cg@2364
   276
"/    (aComponent isKindOf:ScrollBar) ifTrue:[
cg@2364
   277
"/        ^ aComponent orientation == #vertical
cg@2364
   278
"/    ].
cg@2364
   279
"/    (aComponent isKindOf:Scroller) ifTrue:[
cg@2364
   280
"/        ^ aComponent orientation == #vertical
cg@2364
   281
"/    ].
cg@2364
   282
"/    (aComponent isKindOf:Slider) ifTrue:[
cg@2364
   283
"/        ^ aComponent orientation == #vertical
cg@2364
   284
"/    ].
cg@2510
   285
    (aComponent isKindOf:LineSegmentMorph) ifTrue:[
cg@2510
   286
        ^ false
cg@2510
   287
    ].
ca@175
   288
    ^ true
ca@175
   289
!
ca@175
   290
cg@2510
   291
layoutType:aViewOrComponent
cg@2510
   292
    "returns layout type of aView or nil"
cg@2510
   293
ca@113
   294
    |layout spec superView|
ca@113
   295
cg@2510
   296
    aViewOrComponent isNil ifTrue:[ ^ nil ].
cg@2510
   297
    (aViewOrComponent isKindOf:LineSegmentMorph) ifTrue:[
cg@2510
   298
        ^ nil
cg@2510
   299
    ].
cg@2510
   300
cg@2510
   301
    layout := aViewOrComponent geometryLayout.
cg@2510
   302
    layout notNil ifTrue:[
cg@2510
   303
        layout isLayout ifTrue:[
cg@2510
   304
            layout isLayoutFrame        ifTrue:[ ^ #LayoutFrame ].
cg@2510
   305
            layout isAlignmentOrigin    ifTrue:[ ^ #AlignmentOrigin ].
cg@2510
   306
            layout isLayoutOrigin       ifTrue:[ ^ #LayoutOrigin ].
cg@2510
   307
        ] ifFalse:[
cg@2510
   308
            layout isRectangle          ifTrue:[ ^ #Rectangle ].
cg@2510
   309
            layout isPoint              ifTrue:[ ^ #Point ].
cg@2510
   310
        ].
cg@2510
   311
    ] ifFalse:[
cg@2510
   312
        (superView := aViewOrComponent superView) notNil ifTrue:[
cg@2510
   313
            spec := superView specClass.
cg@2510
   314
            spec canResizeSubComponents ifTrue:[
cg@2510
   315
                ^ #Extent
cg@2510
   316
            ]
cg@2510
   317
        ]
ca@61
   318
    ].
ca@61
   319
    ^ nil
ca@61
   320
cg@67
   321
    "Modified: 28.2.1997 / 13:02:16 / cg"
ca@61
   322
! !
ca@61
   323
cg@60
   324
!UIObjectView methodsFor:'accessing'!
cg@60
   325
cg@60
   326
gridAlign
ca@61
   327
    "returns state of aligning to grid
ca@61
   328
    "
cg@60
   329
    ^ aligning
cg@60
   330
cg@60
   331
!
cg@60
   332
cg@60
   333
gridAlign:aBool
ca@61
   334
    "change state of aligning to grid
ca@61
   335
    "
cg@60
   336
    aBool ifTrue:[self alignOn]
cg@1120
   337
	 ifFalse:[self alignOff]
cg@60
   338
cg@60
   339
!
cg@60
   340
cg@60
   341
gridParameters
cg@60
   342
    "used by defineGrid, and in a separate method for
cg@60
   343
     easier redefinition in subclasses. 
cg@60
   344
     Returns the grid parameters in an array of 7 elements,
cg@60
   345
     which control the appearance of the grid-pattern.
cg@60
   346
     the elements are:
cg@60
   347
cg@1120
   348
	bigStepH        number of pixels horizontally between 2 major steps
cg@1120
   349
	bigStepV        number of pixels vertically between 2 major steps
cg@1120
   350
	littleStepH     number of pixels horizontally between 2 minor steps
cg@1120
   351
	littleStepV     number of pixels vertically between 2 minor steps
cg@1120
   352
	gridAlignH      number of pixels for horizontal grid align (pointer snap)
cg@1120
   353
	gridAlignV      number of pixels for vertical grid align (pointer snap)
cg@1120
   354
	docBounds       true, if document boundary should be shown
cg@60
   355
cg@60
   356
     if littleStepH/V are nil, only bigSteps are drawn.
cg@60
   357
    "
ca@360
   358
    gridParameters isNil ifTrue:[
cg@1120
   359
	gridParameters := #(10 10 nil nil 10 10 false)
ca@360
   360
    ].
ca@360
   361
    ^ gridParameters
ca@360
   362
ca@360
   363
ca@360
   364
!
ca@360
   365
ca@360
   366
gridParameters:newGridParameters
ca@360
   367
    "used by defineGrid, and in a separate method for
ca@360
   368
     easier redefinition in subclasses. 
ca@360
   369
     Returns the grid parameters in an array of 7 elements,
ca@360
   370
     which control the appearance of the grid-pattern.
ca@360
   371
     the elements are:
ca@360
   372
cg@1120
   373
	bigStepH        number of pixels horizontally between 2 major steps
cg@1120
   374
	bigStepV        number of pixels vertically between 2 major steps
cg@1120
   375
	littleStepH     number of pixels horizontally between 2 minor steps
cg@1120
   376
	littleStepV     number of pixels vertically between 2 minor steps
cg@1120
   377
	gridAlignH      number of pixels for horizontal grid align (pointer snap)
cg@1120
   378
	gridAlignV      number of pixels for vertical grid align (pointer snap)
cg@1120
   379
	docBounds       true, if document boundary should be shown
ca@360
   380
ca@360
   381
     if littleStepH/V are nil, only bigSteps are drawn.
ca@360
   382
    "
ca@360
   383
    newGridParameters size == 7 ifTrue:[
cg@1120
   384
	gridParameters := newGridParameters
ca@360
   385
    ].
cg@60
   386
cg@60
   387
cg@60
   388
!
cg@60
   389
cg@60
   390
gridShown:aBool
ca@61
   391
    "change visibility of grid
ca@61
   392
    "
cg@60
   393
    aBool ifTrue:[self showGrid]
cg@1120
   394
	 ifFalse:[self hideGrid]
cg@60
   395
!
cg@60
   396
cg@60
   397
hideGrid
ca@61
   398
    "hide grid
ca@61
   399
    "
cg@60
   400
    gridShown ifTrue:[
cg@1120
   401
	self withSelectionHiddenDo:[super hideGrid]
cg@60
   402
    ]
cg@60
   403
cg@60
   404
cg@60
   405
!
cg@60
   406
cg@60
   407
showGrid
ca@61
   408
    "show grid
ca@61
   409
    "
ca@61
   410
    self withSelectionHiddenDo:[super showGrid]
ca@119
   411
! !
ca@119
   412
cg@1399
   413
!UIObjectView methodsFor:'accessing-behavior'!
ca@119
   414
sv@1100
   415
enableStateChanged
cg@2364
   416
    "toggle the test mode
ca@119
   417
    "
cg@1102
   418
    self shown ifTrue:[
ca@1672
   419
        enableChannel value ifFalse:[
ca@1672
   420
            saveSelection := selection.
ca@1672
   421
            self hideSelection.
ca@1672
   422
            selection := nil.
ca@1672
   423
        ] ifTrue:[
ca@1672
   424
            selection := saveSelection.
ca@1672
   425
            self showSelection
ca@1672
   426
        ]
ca@119
   427
    ]
ca@119
   428
sv@1100
   429
    "Created: / 30.3.1999 / 16:17:24 / stefan"
sv@1100
   430
!
sv@1100
   431
sv@1100
   432
enabled
sv@1100
   433
    ^ enableChannel value
sv@1100
   434
!
sv@1100
   435
sv@1100
   436
enabled:aState
sv@1100
   437
    "set the modification / test mode
sv@1100
   438
    "
sv@1100
   439
sv@1100
   440
    enableChannel value:aState
sv@1100
   441
sv@1100
   442
    "Modified: / 30.3.1999 / 16:18:12 / stefan"
cg@60
   443
!
cg@60
   444
ca@134
   445
resetModification
cg@1918
   446
    "set modification state to false"
cg@1918
   447
cg@1954
   448
    undoHistory resetModification.
cg@1954
   449
    self undoHistoryChanged.
ca@134
   450
!
ca@134
   451
cg@60
   452
testMode
ca@61
   453
    "returns true if running test
cg@60
   454
    "
ca@119
   455
    ^ enableChannel value not
cg@60
   456
cg@60
   457
cg@60
   458
!
cg@60
   459
cg@60
   460
testMode:aBoolean
ca@61
   461
    "change test mode
cg@60
   462
    "
cg@1102
   463
    enableChannel value:(aBoolean not)
cg@60
   464
! !
cg@60
   465
cg@1954
   466
!UIObjectView methodsFor:'aspects'!
cg@1954
   467
cg@1954
   468
hasUndoHistoryHolder
cg@1954
   469
    hasUndoHistoryHolder isNil ifTrue:[
cg@1954
   470
        hasUndoHistoryHolder := false asValue
cg@1954
   471
    ].
cg@1954
   472
    ^ hasUndoHistoryHolder
cg@1954
   473
! !
cg@1954
   474
cg@60
   475
!UIObjectView methodsFor:'blocked'!
cg@60
   476
cg@60
   477
addObject:anObject
sv@1746
   478
    "add the argument, anObject to the contents - with redraw"
sv@1746
   479
sv@1746
   480
    self shouldNotImplement
cg@60
   481
!
cg@60
   482
cg@60
   483
addObjectWithoutRedraw:anObject
sv@1746
   484
    "add the argument, anObject to the contents - with redraw"
sv@1746
   485
sv@1746
   486
    self shouldNotImplement
cg@60
   487
! !
cg@60
   488
cg@2538
   489
!UIObjectView methodsFor:'enumerating'!
cg@2538
   490
cg@2538
   491
contentsDo:aBlock
cg@2538
   492
    self subViews do:aBlock.
cg@2538
   493
    self components do:aBlock.
cg@2538
   494
! !
cg@2538
   495
cg@60
   496
!UIObjectView methodsFor:'event handling'!
cg@60
   497
werner@1833
   498
doublePressed:pressPoint
werner@1833
   499
!
werner@1833
   500
ca@61
   501
elementChangedSize:aView
cg@2501
   502
    "some element has changed its size; collect them while selectionHiddenLevel is on"
cg@2501
   503
ca@284
   504
    |spv|
ca@284
   505
ca@284
   506
    spv := self findContainerOfView:aView.
ca@284
   507
cg@2501
   508
    aView isView ifFalse:[
cg@2503
   509
"/        spv invalidate.
cg@2501
   510
    ].
cg@2501
   511
cg@2503
   512
"/    spv := self findContainerOfView:aView.
cg@2501
   513
cg@2501
   514
    selectionHiddenLevel ~~ 0 ifTrue:[
cg@2501
   515
        setOfSuperViewsSizeChanged add:spv
cg@2501
   516
    ] ifFalse:[
cg@2501
   517
        spv sizeChanged:nil
cg@2501
   518
    ]
cg@60
   519
!
cg@60
   520
cg@60
   521
keyPress:key x:x y:y
ca@61
   522
    "any key pressed
ca@61
   523
    "
cg@1048
   524
    <resource: #keyboard ( #CursorUp #CursorDown #CursorLeft #CursorRight
werner@1827
   525
                           #Delete #BackSpace #Cut #Copy #Paste #Cmdu #Again) >
cg@1222
   526
cg@1222
   527
    |n sensor|
cg@60
   528
cg@60
   529
    (key == #Cut or:[key == #Delete or:[key == #BackSpace]]) ifTrue: [
cg@1222
   530
        ^ self deleteSelection
cg@60
   531
    ].
werner@1827
   532
    (key = #PreviousPage) ifTrue:[
werner@1827
   533
        self selectNextUpInHierarchy.
werner@1827
   534
    ].
ca@78
   535
    key == #Copy  ifTrue:[ ^ self copySelection].
ca@78
   536
    key == #Paste ifTrue:[ ^ self pasteBuffer].
ca@360
   537
    key == #Cmdu  ifTrue:[ ^ self undoLast ].           "/ #Undo
ca@360
   538
werner@1827
   539
    ( #(CursorUp CursorDown CursorRight CursorLeft)
werner@1827
   540
    includes:key) ifTrue:[
werner@1827
   541
        (sensor := self sensor) isNil ifTrue:[
werner@1827
   542
            n := 1
werner@1827
   543
        ] ifFalse:[
werner@1827
   544
            n := 1 + (sensor compressKeyPressEventsWithKey:key).
werner@1827
   545
            sensor shiftDown ifTrue:[
werner@1827
   546
                n := n * 10.
werner@1827
   547
            ].
cg@1222
   548
        ].
cg@1222
   549
cg@1222
   550
        key == #CursorUp ifTrue:[
cg@1222
   551
            ^ self moveSelectionUp:n
cg@1222
   552
        ].
cg@1222
   553
        key == #CursorDown ifTrue:[
cg@1222
   554
            ^ self moveSelectionDown:n
cg@1222
   555
        ].
cg@1222
   556
        key == #CursorRight ifTrue:[
cg@1222
   557
            ^ self moveSelectionRight:n
cg@1222
   558
        ].
cg@1222
   559
        key == #CursorLeft ifTrue:[
cg@1222
   560
            ^ self moveSelectionLeft:n
cg@1222
   561
        ].
cg@1222
   562
    ].
cg@374
   563
    super keyPress:key x:x y:y
cg@374
   564
cg@1048
   565
    "Modified: / 6.3.1999 / 22:47:48 / cg"
cg@60
   566
!
cg@60
   567
cg@60
   568
processEvent:anEvent
cg@60
   569
    "catch expose events for components, and redraw its handles after
cg@1895
   570
     the redraw when this happens.
cg@1895
   571
     Return true, if I have eaten the event"
cg@1895
   572
cg@2501
   573
    |evView widget p|
ca@1672
   574
ca@1672
   575
    self testMode ifTrue:[^ false].
ca@1672
   576
cg@2555
   577
    anEvent isInputEvent ifFalse:[^ false].
cg@2555
   578
ca@1672
   579
    evView := anEvent view.
cg@2548
   580
    evView isNil ifTrue:[ ^ false].
cg@2548
   581
cg@2501
   582
    (evView == self) ifTrue:[
cg@2501
   583
        "/ new: check for a component to be hit by the event
cg@2554
   584
cg@2501
   585
        components notEmptyOrNil ifTrue:[
cg@2554
   586
            anEvent x notNil ifTrue:[
cg@2554
   587
                p := (anEvent x @ anEvent y).        
cg@2554
   588
                widget := components detect:[:c | c bounds containsPoint:p ] ifNone:nil.
cg@2554
   589
            ].
cg@2501
   590
        ].
cg@2501
   591
        widget isNil ifTrue:[
cg@2501
   592
            ^ false
cg@2501
   593
        ].
cg@2501
   594
    ] ifFalse:[
cg@2501
   595
        widget := evView.
cg@2501
   596
    ].
cg@2501
   597
cg@2501
   598
    (widget isComponentOf:self) ifFalse:[
ca@1672
   599
        ^ false
ca@1672
   600
    ].
cg@2550
   601
cg@2548
   602
    "/ eat most of my events
cg@2548
   603
    anEvent isPointerEnterLeaveEvent ifTrue:[^ true. ^ false].
cg@2548
   604
    anEvent isKeyboardFocusEvent ifTrue:[^ true. ^ false].
cg@2548
   605
cg@2548
   606
    (anEvent isButtonEvent or:[anEvent isKeyEvent]) ifFalse:[ ^ true ].
ca@1672
   607
ca@2203
   608
    anEvent isButtonMotionEvent ifTrue:[
ca@2203
   609
        "/ use current point - layout of underlaying view might change
ca@2203
   610
        "/ and computation dependent on origin is wrong
ca@2203
   611
        p := self sensor mousePoint.
ca@2203
   612
        p := device translatePoint:p fromView:nil toView:self.
ca@2203
   613
    ] ifFalse:[
cg@2501
   614
        p := (anEvent x) @ (anEvent y).
ca@2203
   615
        p := device translatePoint:p fromView:evView toView:self.
ca@2203
   616
    ].
ca@1672
   617
ca@1672
   618
    "/ patch the event
ca@1672
   619
    anEvent x:p x.
ca@1672
   620
    anEvent y:p y.
ca@1672
   621
    anEvent view:self.
cg@60
   622
    ^ false.
cg@60
   623
!
cg@60
   624
cg@624
   625
redrawX:nx y:ny width:nw height:nh
cg@1911
   626
    |redrawFrame|
cg@1911
   627
cg@1911
   628
    redrawFrame := Rectangle left:nx top:ny width:nw height:nh.
cg@2501
   629
    "/ self clearRectangle:redrawFrame.
cg@2501
   630
    super redrawX:nx y:ny width:nw height:nh.
cg@1911
   631
cg@1911
   632
    self selectionDo:[:aComponent |
cg@1911
   633
        |anyHandleToRedraw|
cg@1911
   634
cg@1911
   635
        anyHandleToRedraw := false.
cg@1911
   636
        self handlesOf:aComponent do:[:hRect :typeOfHandle |
cg@1911
   637
            (hRect intersects:redrawFrame) ifTrue:[        
cg@1911
   638
                anyHandleToRedraw := true.
cg@1911
   639
            ].
cg@1911
   640
        ].
cg@1911
   641
        anyHandleToRedraw ifTrue:[
cg@1911
   642
            self showSelected:aComponent
cg@1911
   643
        ]
cg@1911
   644
    ]
cg@2246
   645
cg@2246
   646
    "Modified: / 16-01-2008 / 17:57:09 / cg"
cg@624
   647
!
cg@624
   648
cg@60
   649
sizeChanged:how
ca@61
   650
    "size of a view(s) changed
ca@61
   651
    "
cg@60
   652
    self withSelectionHiddenDo:[
ca@1672
   653
        super sizeChanged:how.
ca@1672
   654
    ].
cg@60
   655
! !
cg@60
   656
cg@60
   657
!UIObjectView methodsFor:'initialization'!
cg@60
   658
cg@60
   659
initialize
ca@61
   660
    "setup attributes
ca@61
   661
    "
cg@60
   662
    super initialize.
cg@60
   663
ca@61
   664
    setOfSuperViewsSizeChanged := IdentitySet new.
cg@60
   665
    self setDefaultActions.
cg@60
   666
cg@1954
   667
    undoHistory := UndoHistory on:self.
cg@1954
   668
sv@1100
   669
    self enableChannel:(true asValue).
ca@119
   670
    clipChildren         := true.
ca@61
   671
    selectionHiddenLevel := 0.
cg@60
   672
cg@60
   673
    (self class gridShown) ifTrue:[
ca@1672
   674
        super showGrid
cg@60
   675
    ].
cg@60
   676
cg@897
   677
    "Modified: / 20.7.1998 / 18:14:51 / cg"
sv@1100
   678
    "Modified: / 30.3.1999 / 16:19:15 / stefan"
cg@60
   679
!
cg@60
   680
ca@284
   681
map
ca@284
   682
    "make the view visible on the screen and in case of a none empty
ca@284
   683
     selection the selection will be shown.
ca@284
   684
    "
ca@284
   685
    super map.
ca@284
   686
    self showSelection.
ca@284
   687
!
ca@284
   688
cg@60
   689
realize
ca@1672
   690
    |windowGroup|
ca@1672
   691
cg@60
   692
    super realize.
ca@1672
   693
    windowGroup := self windowGroup.
ca@1672
   694
    windowGroup  addPreEventHook:self.
ca@1672
   695
    windowGroup addPostEventHook:(PostEventHandler new onView:self).
cg@897
   696
!
cg@897
   697
cg@897
   698
remap
cg@897
   699
    "make the view visible on the screen and in case of a none empty
sv@1746
   700
     selection the selection will be shown"
sv@1746
   701
sv@1746
   702
    self shouldNotImplement
cg@60
   703
! !
cg@60
   704
cg@60
   705
!UIObjectView methodsFor:'misc'!
cg@60
   706
ca@175
   707
invertOutlineOf:something
cg@2501
   708
    "invert outline of an object or collection of objects"
cg@2501
   709
cg@2536
   710
    ^ self.
cg@2536
   711
cg@2536
   712
"/ cg: nope - all done via handles now.
cg@2536
   713
cg@2536
   714
"/    |wasClipped|
cg@2536
   715
"/
cg@2536
   716
"/    (wasClipped := clipChildren) ifTrue:[
cg@2536
   717
"/        self clippedByChildren:(clipChildren := false).
cg@2536
   718
"/    ].
cg@2536
   719
"/
cg@2536
   720
"/    self xoring:[
cg@2536
   721
"/        |p|
cg@2536
   722
"/
cg@2536
   723
"/        something isCollection ifTrue:[
cg@2536
   724
"/            something do:[:v |
cg@2536
   725
"/                p := v originRelativeTo:self.
cg@2536
   726
"/                self displayRectangle:(p extent:v extent).
cg@2536
   727
"/            ].
cg@2536
   728
"/        ] ifFalse:[
cg@2536
   729
"/            p := something originRelativeTo:self.
cg@2536
   730
"/            self displayRectangle:(p extent:something extent).
cg@2536
   731
"/        ]
cg@2536
   732
"/    ].
cg@2536
   733
"/
cg@2536
   734
"/    wasClipped ifTrue:[
cg@2536
   735
"/        self clippedByChildren:(clipChildren := true).
cg@2536
   736
"/    ].
cg@60
   737
!
cg@60
   738
cg@2255
   739
minClosedViewSetFor:setOfViews
cg@2255
   740
    "return the minimum closure for a given set of view;
cg@2255
   741
     That is the minimum set of views which contains the given set of views.
cg@2255
   742
     Concrete: all subviews from setOfViews of which any superView is already in the set
cg@2255
   743
               is excluded from the result"
cg@2255
   744
ca@78
   745
    setOfViews isCollection ifFalse:[
cg@1903
   746
        setOfViews notNil ifTrue:[^ Array with:setOfViews].
cg@1903
   747
        ^ nil
ca@72
   748
    ].
cg@1903
   749
    ^ setOfViews 
cg@1903
   750
        select:[:aView|
cg@1903
   751
            (setOfViews contains:[:v | aView isComponentOf:v]) not
cg@1903
   752
        ]
ca@72
   753
!
ca@72
   754
cg@624
   755
redrawObjectsInVisible:redrawFrame
cg@2501
   756
    "my objects are views - they redraw themself.
cg@2501
   757
     - no longer - all non-views MUST be redrawn."
cg@2501
   758
cg@2501
   759
    super redrawObjectsInVisible:redrawFrame.
cg@624
   760
    ^ self
cg@624
   761
!
cg@624
   762
cg@60
   763
setDefaultActions
ca@61
   764
    "set default actions
ca@61
   765
    "
cg@60
   766
    pressAction      := [:pressPoint | self startSelectOrMove:pressPoint].
cg@60
   767
    shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint].
ca@1861
   768
    ctrlPressAction  := [:pressPoint | self startSelectMoreOrMove:pressPoint].
cg@60
   769
    motionAction     := [:movePoint  | nil].
cg@60
   770
    releaseAction    := [nil].
cg@60
   771
    keyPressAction   := nil.
werner@1827
   772
    doublePressAction   := [:pressPoint | self doublePressed: pressPoint].
cg@60
   773
cg@60
   774
    self cursor:Cursor normal.
cg@60
   775
! !
cg@60
   776
cg@60
   777
!UIObjectView methodsFor:'object moving'!
cg@60
   778
cg@60
   779
doObjectMove:aPoint
cg@2536
   780
    "move movedOject (which is a misnomer - it's actually a collection of objects to move)"
cg@2536
   781
cg@2536
   782
    |anyMove|
cg@2536
   783
cg@2536
   784
    movedObject isEmptyOrNil ifTrue:[^ self].
cg@2536
   785
cg@2536
   786
    anyMove := false.
cg@2536
   787
    "/ to avoid flicker, check if this really involves a move (due to align)
cg@2536
   788
    movedObject keysAndValuesDo:[:i :obj|
cg@2536
   789
        |newOrigin delta|
cg@2536
   790
cg@2536
   791
        newOrigin := (aPoint - (moveDelta at:i)).
cg@2536
   792
        delta := (self alignToGrid:newOrigin) - obj computeOrigin.
cg@2536
   793
        delta ~= (0@0) ifTrue:[ anyMove := true ].
cg@2536
   794
    ].
cg@2536
   795
    anyMove ifFalse:[^ self ].
cg@2536
   796
cg@2536
   797
    self hideSelection.
cg@2536
   798
    self invertOutlineOf:movedObject.
cg@2536
   799
cg@2536
   800
    movedObject keysAndValuesDo:[:i :v|
cg@2536
   801
        self moveObject:v to:(aPoint - (moveDelta at:i)).
cg@2536
   802
    ].
cg@2536
   803
cg@2536
   804
    self invertOutlineOf:movedObject.
cg@2536
   805
    self showSelection.
cg@60
   806
!
cg@60
   807
cg@60
   808
endObjectMove
ca@61
   809
    "cleanup after object(s) move
ca@2205
   810
     send expose to each view - workaround....
ca@61
   811
    "
ca@2205
   812
    |newSel|
ca@2205
   813
ca@2205
   814
    movedObject isNil ifTrue:[^ self].
ca@2205
   815
ca@2205
   816
    movedObject size == 1 ifTrue:[ newSel := movedObject first ]
ca@2205
   817
                         ifFalse:[ newSel := movedObject ].
ca@2205
   818
    movedObject := nil.
ca@2205
   819
cg@2536
   820
"/    self withSelectionHiddenDo:[
cg@2536
   821
"/        self setSelection:newSel withRedraw:false.
cg@2536
   822
"/
cg@2536
   823
"/        components notEmptyOrNil ifTrue:[
cg@2536
   824
"/            self invalidate.
cg@2536
   825
"/        ].
cg@2536
   826
"/        self allSubViewsDo:[:v|
cg@2536
   827
"/            v shown ifTrue:[
cg@2536
   828
"/                v fill:v viewBackground.
cg@2536
   829
"/                v exposeX:0 y:0 width:v width height:v height.
cg@2536
   830
"/            ].
cg@2536
   831
"/        ].
cg@2536
   832
"/    ].
cg@2536
   833
cg@2536
   834
    self setDefaultActions.
cg@2536
   835
    self layoutChanged.
cg@60
   836
!
cg@60
   837
cg@60
   838
moveObject:anObject to:aPoint
cg@2514
   839
    "move anObject to newOrigin, aPoint"
cg@2514
   840
cg@60
   841
    |dX dY org delta|
cg@60
   842
cg@60
   843
    anObject notNil ifTrue:[
cg@1954
   844
        org := anObject computeOrigin.
cg@1954
   845
cg@1954
   846
        delta := aPoint - org.
cg@1954
   847
        delta := (self alignToGrid:aPoint) - org.
cg@1954
   848
        dX := delta x.
cg@1954
   849
        dY := delta y.
cg@1954
   850
cg@1954
   851
        undoHistory withoutTransactionDo:[
cg@2514
   852
            self shiftLayout:anObject horizontal:dX vertical:dY
cg@1954
   853
        ]
cg@60
   854
    ]
cg@60
   855
!
cg@60
   856
cg@60
   857
startObjectMoveAt:aPoint
cg@2501
   858
    "start object(s) move at a point"
cg@2501
   859
ca@128
   860
    self startObjectMove:(self selection) at:aPoint.
ca@128
   861
    movedObject := self selection.
ca@128
   862
ca@128
   863
    movedObject isCollection ifFalse:[
ca@1451
   864
        movedObject := Array with:movedObject
cg@60
   865
    ].
cg@2501
   866
"/    self setSelection:nil withRedraw:true.
cg@2501
   867
cg@2501
   868
    moveDelta := movedObject collect:[:aView | aPoint - aView computeOrigin].
cg@2501
   869
ca@175
   870
    self transaction:#move objects:movedObject do:[:v|self createUndoLayout:v].
ca@175
   871
    self invertOutlineOf:movedObject.
cg@60
   872
!
cg@60
   873
cg@60
   874
startSelectMoreOrMove:aPoint
cg@60
   875
    "add/remove to/from selection"
cg@60
   876
cg@60
   877
    |anObject|
cg@60
   878
ca@119
   879
    self enabled ifFalse:[^ self].
cg@60
   880
cg@60
   881
    anObject := self findObjectAt:aPoint.
cg@60
   882
    anObject notNil ifTrue:[
cg@1120
   883
	(self isSelected:anObject) ifTrue:[
cg@1120
   884
	    self removeFromSelection:anObject
cg@1120
   885
	] ifFalse:[
cg@1120
   886
	    self addToSelection:anObject
cg@1120
   887
	]
cg@60
   888
    ]
cg@60
   889
!
cg@60
   890
cg@60
   891
startSelectOrMove:aPoint
cg@2356
   892
    "a button is pressed at a point; start moving or selecting"
cg@2356
   893
cg@2356
   894
    |selectedView containerOfSelectedView
cg@2501
   895
     clickedView viewOperatedUpon borderHandleSelector pView|
cg@60
   896
ca@119
   897
    self enabled ifFalse:[^ self].
cg@60
   898
cg@2356
   899
    selectedView := self singleSelection.
cg@2364
   900
cg@2364
   901
"/    clickedView := self findObjectAt:aPoint.
cg@2364
   902
"/    (clickedView notNil 
cg@2364
   903
"/    and:[clickedView isComponentOf:selectedView]) ifTrue:[
cg@2364
   904
"/        self unselect.
cg@2364
   905
"/        selectedView := nil.    
cg@2364
   906
"/    ].
cg@60
   907
cg@2501
   908
    "/ if there is already a selection, see if user clicked onto a handle
cg@2501
   909
    "/ then, this may be the start of a resize operation.
cg@2356
   910
    selectedView notNil ifTrue:[
cg@2356
   911
        containerOfSelectedView := self findContainerOfView:selectedView.
cg@2356
   912
cg@2356
   913
        containerOfSelectedView specClass canResizeSubComponents ifTrue:[
cg@2501
   914
            borderHandleSelector := self whichHandleOf:selectedView isHitBy:aPoint.
cg@2501
   915
            (borderHandleSelector notNil and:[borderHandleSelector ~~ #view]) ifTrue:[
cg@2501
   916
                self startResizeBorder:borderHandleSelector.
cg@2356
   917
                ^ self
cg@2356
   918
            ]
cg@2356
   919
        ].
cg@2356
   920
        viewOperatedUpon := selectedView.
cg@2356
   921
cg@2356
   922
        pView := device translatePoint:aPoint fromView:self toView:selectedView superView.
cg@2356
   923
        (selectedView bounds containsPoint:pView) ifFalse:[
cg@2356
   924
            "/ clicked outside the selection
cg@2356
   925
            (self sensor ctrlDown and:[self canChangeLayoutOfView:selectedView]) ifFalse:[
cg@2356
   926
                viewOperatedUpon := nil
cg@2356
   927
            ]
cg@2356
   928
        ]
ca@61
   929
    ].
ca@61
   930
cg@2364
   931
    clickedView := self findObjectAt:aPoint.
cg@2368
   932
    clickedView notNil ifTrue:[
cg@2368
   933
        (clickedView isComponentOf:selectedView) ifTrue:[
cg@2530
   934
            "/ self unselect.
cg@2368
   935
            selectedView := nil.    
cg@2368
   936
            viewOperatedUpon := nil
cg@2368
   937
        ] ifFalse:[
cg@2530
   938
            "/ self unselect.
cg@2368
   939
            selectedView := nil.    
cg@2368
   940
            viewOperatedUpon := clickedView
cg@2368
   941
        ].
cg@2364
   942
    ].
cg@2364
   943
cg@2356
   944
    viewOperatedUpon isNil ifTrue:[
cg@2356
   945
        clickedView isNil ifTrue:[
cg@2538
   946
            "/ clicked outside - start a rectangle drag.
cg@2356
   947
            self select:nil.
cg@2538
   948
            self startRectangleDrag:aPoint.
cg@2356
   949
            ^ self.
cg@2356
   950
        ].
cg@2356
   951
cg@2356
   952
        (self canChangeLayoutOfView:clickedView) ifFalse:[
cg@2356
   953
            self select:clickedView.
cg@2356
   954
            ^ self
cg@2356
   955
        ].
cg@2356
   956
        viewOperatedUpon := clickedView
cg@60
   957
    ].
cg@60
   958
cg@2356
   959
    (self isSelected:viewOperatedUpon) ifFalse:[
cg@2356
   960
        self select:viewOperatedUpon.
cg@2356
   961
    ].
cg@2356
   962
cg@60
   963
    (self numberOfSelections ~~ 1) ifTrue:[
cg@2356
   964
        releaseAction := 
cg@2356
   965
            [
cg@2356
   966
                self setDefaultActions.
cg@2356
   967
                self select:viewOperatedUpon
cg@2356
   968
            ]
cg@60
   969
    ] ifFalse:[
cg@2356
   970
        releaseAction := [self setDefaultActions]
cg@60
   971
    ].
cg@60
   972
cg@2356
   973
    "prepare move operation for an object"
cg@2356
   974
    motionAction := 
cg@2356
   975
        [:movePoint|
cg@2356
   976
            (aPoint dist:movePoint) > 4.0 ifTrue:[
cg@2356
   977
                self startObjectMoveAt:aPoint
cg@2356
   978
            ]
cg@2356
   979
        ].
cg@60
   980
! !
cg@60
   981
cg@60
   982
!UIObjectView methodsFor:'object resize'!
cg@60
   983
cg@60
   984
actionResize:anObject selector:aSelector
cg@2536
   985
    "create and initialize action for resize"
cg@2536
   986
cg@2536
   987
    |delta|
cg@60
   988
cg@60
   989
    delta    := anObject container originRelativeTo:self.
cg@543
   990
    resizeData := ResizeData new
cg@2536
   991
                        object:anObject 
cg@2536
   992
                        selector:aSelector
cg@2536
   993
                        delta:delta.
cg@60
   994
cg@60
   995
"can change cursor dependent on vertical/horizontal resizing
cg@60
   996
"
cg@60
   997
    oldCursor := cursor.
cg@60
   998
    self cursor:(Cursor leftHand).
cg@60
   999
cg@543
  1000
    "Modified: / 2.2.1998 / 13:40:55 / cg"
cg@60
  1001
!
cg@60
  1002
cg@60
  1003
doDragResize:aPoint
cg@2536
  1004
    "do a widget resize drag"
cg@2536
  1005
cg@60
  1006
    |p object|
cg@60
  1007
ca@175
  1008
    object := resizeData object.
cg@2536
  1009
    p := (self alignToGrid:aPoint) - (resizeData delta).
cg@2536
  1010
cg@2536
  1011
    (self resize:object handle:(resizeData selector) to:p check:true) ifFalse:[
cg@2536
  1012
        ^ self  "/ no real change (due to align)
cg@2536
  1013
    ].
cg@60
  1014
cg@2514
  1015
    self hideSelection.
cg@2514
  1016
cg@60
  1017
    self invertOutlineOf:object.
cg@2536
  1018
cg@2536
  1019
    self resize:object handle:(resizeData selector) to:p check:false.
cg@2536
  1020
ca@1451
  1021
    Delay waitForSeconds:0.05.
ca@1451
  1022
    [self sensor hasExposeEventFor:nil] whileTrue:[
ca@1451
  1023
        self windowGroup processExposeEvents
ca@1451
  1024
    ].
ca@1451
  1025
ca@79
  1026
   "/ object geometryLayout:(object geometryLayout).
cg@2501
  1027
    self invertOutlineOf:object.
cg@2501
  1028
cg@2514
  1029
    self showSelection.
cg@60
  1030
!
cg@60
  1031
cg@60
  1032
endResize
cg@2536
  1033
    "cleanup after object resize"
cg@2536
  1034
cg@2536
  1035
    |object savedSelection anyLayoutWrapper anyTransparentBox|
ca@61
  1036
ca@175
  1037
    object := resizeData object.
ca@175
  1038
    resizeData := nil.
ca@61
  1039
cg@2536
  1040
    "/ container objects might want to rearrange their elements after a size change;
cg@2536
  1041
    "/ therefore, we hide the handles while this is possibly done.
cg@2536
  1042
    "/ however, to avoid flicker, we check for containers first.
cg@2536
  1043
    anyLayoutWrapper := anyTransparentBox := false.
cg@2536
  1044
    self forEach:object do:[:aViewOrComponent | 
cg@2536
  1045
        aViewOrComponent isLayoutWrapper ifTrue:[ anyLayoutWrapper := true ].
cg@2536
  1046
        aViewOrComponent isTransparentBox ifTrue:[ anyTransparentBox := true ].
cg@2536
  1047
    ].
cg@2536
  1048
cg@2536
  1049
    (anyLayoutWrapper or:[anyTransparentBox]) ifTrue:[
cg@2536
  1050
cg@2536
  1051
        self invertOutlineOf:object.
cg@2536
  1052
cg@2536
  1053
        "/ temporarily hide the selection, in order to allow the container to move the
cg@2536
  1054
        "/ element around...
cg@2536
  1055
        savedSelection := selection.
cg@2536
  1056
        self setSelection:nil withRedraw:true.
cg@2536
  1057
cg@2536
  1058
        "/ handle any expose events (for subcomponents) before
cg@2536
  1059
        "/ redrawing the handles.
cg@2536
  1060
        self windowGroup processExposeEvents.
cg@2536
  1061
cg@2536
  1062
        self elementChangedSize:object.
cg@2536
  1063
cg@2536
  1064
        "/ handle any expose events (for subcomponents) before
cg@2536
  1065
        "/ redrawing the handles.
cg@2536
  1066
        Delay waitForSeconds:0.05.
cg@2536
  1067
        [self sensor hasExposeEventFor:nil] whileTrue:[
cg@2536
  1068
            self windowGroup processExposeEvents
cg@2536
  1069
        ].
cg@2536
  1070
cg@2536
  1071
        self forEach:savedSelection do:[:aView |
cg@2536
  1072
            self recomputeShapeIfTransparentBox:aView.
cg@2536
  1073
        ].
cg@2536
  1074
cg@2536
  1075
        self setSelection:object withRedraw:true.
cg@2536
  1076
    ].
cg@2536
  1077
cg@2536
  1078
    self layoutChanged.
cg@60
  1079
    self setDefaultActions.
cg@2536
  1080
!
cg@2536
  1081
cg@2536
  1082
layoutChanged
cg@2536
  1083
!
cg@2536
  1084
cg@2536
  1085
resize:aView bottom:aPoint
cg@2536
  1086
    "obsolete: resize a views bottom"
cg@2536
  1087
cg@2536
  1088
    self resize:aView handle:#bottom to:aPoint check:false.
cg@2536
  1089
"/    undoHistory withoutTransactionDo:[
cg@2536
  1090
"/        self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
cg@2536
  1091
"/    ].
cg@2536
  1092
!
cg@2536
  1093
cg@2536
  1094
resize:aView bottomLeft:aPoint
cg@2536
  1095
    "obsolete: resize a views bottom and left"
cg@2536
  1096
cg@2536
  1097
    self resize:aView handle:#bottomLeft to:aPoint check:false.
cg@2536
  1098
"/    undoHistory withoutTransactionDo:[
cg@2536
  1099
"/        self shiftLayout:aView top:0
cg@2536
  1100
"/                            bottom:((aPoint y) - (aView computeCorner y))
cg@2536
  1101
"/                              left:((aPoint x) - (aView computeOrigin x))
cg@2536
  1102
"/                             right:0
cg@2536
  1103
"/
cg@2536
  1104
"/    ]
cg@2536
  1105
!
cg@2536
  1106
cg@2536
  1107
resize:aView corner:aPoint
cg@2536
  1108
    "obsolete: resize a views corner"
cg@2536
  1109
cg@2536
  1110
    self resize:aView handle:#corner to:aPoint check:false.
cg@2536
  1111
"/    |delta|
cg@2536
  1112
"/
cg@2536
  1113
"/    delta := aPoint - aView computeCorner.
cg@2536
  1114
"/    undoHistory withoutTransactionDo:[
cg@2536
  1115
"/        self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
cg@2536
  1116
"/    ]
cg@2536
  1117
!
cg@2536
  1118
cg@2536
  1119
resize:aComponent endPoint:newEndPoint
cg@2536
  1120
    "obsolete: move a component's endPoint"
cg@2536
  1121
cg@2536
  1122
    self resize:aComponent handle:#endPoint to:newEndPoint check:false
cg@2536
  1123
cg@2536
  1124
"/    undoHistory 
cg@2536
  1125
"/        withoutTransactionDo:[
cg@2536
  1126
"/            self shiftLayout:aComponent startPoint:0 endPoint:(newEndPoint - (aComponent endPoint))
cg@2536
  1127
"/        ]
cg@2536
  1128
!
cg@2536
  1129
cg@2536
  1130
resize:aComponent handle:aSymbol to:aPoint check:doCheck
cg@2536
  1131
    "resize a views handle - if doCheck is true, only check if the handle would change
cg@2536
  1132
     (used to avoid flicker, when an aligned move would actually not move anything)"
cg@2536
  1133
cg@2536
  1134
    |newX newY oldBottom oldTop oldLeft oldRight 
cg@2536
  1135
     oldOrigin oldCorner shiftTop shiftBottom shiftLeft shiftRight|
cg@2536
  1136
cg@2536
  1137
    aSymbol == #startPoint ifTrue:[
cg@2536
  1138
        doCheck ifTrue:[
cg@2536
  1139
            ^ aPoint ~= (aComponent startPoint)
cg@2536
  1140
        ].
cg@2536
  1141
        self 
cg@2536
  1142
            shiftLayout:aComponent 
cg@2536
  1143
            startPoint:(aPoint - (aComponent startPoint)) endPoint:0.
cg@2536
  1144
        ^ self.
ca@138
  1145
    ].
cg@2536
  1146
    aSymbol == #endPoint ifTrue:[
cg@2536
  1147
        doCheck ifTrue:[
cg@2536
  1148
            ^ aPoint ~= (aComponent endPoint)
cg@2536
  1149
        ].
cg@2536
  1150
        self 
cg@2536
  1151
            shiftLayout:aComponent 
cg@2536
  1152
            startPoint:0 endPoint:(aPoint - (aComponent endPoint)).
cg@2536
  1153
        ^ self.
werner@1827
  1154
    ].
cg@2536
  1155
cg@2536
  1156
    newX := aPoint x.
cg@2536
  1157
    newY := aPoint y.
cg@2536
  1158
    shiftTop := shiftBottom := shiftLeft := shiftRight := 0.
cg@2536
  1159
cg@2536
  1160
    oldOrigin := aComponent computeOrigin.
cg@2536
  1161
    oldCorner := aComponent computeCorner.
cg@2536
  1162
cg@2536
  1163
    oldTop := oldOrigin y.
cg@2536
  1164
    oldBottom := oldCorner y.
cg@2536
  1165
    oldLeft := oldOrigin x.
cg@2536
  1166
    oldRight := oldCorner x.
cg@2536
  1167
cg@2536
  1168
    aSymbol == #bottom ifTrue:[
cg@2536
  1169
        shiftBottom := newY - oldBottom.
cg@2536
  1170
    ]. 
cg@2536
  1171
    aSymbol == #top ifTrue:[     
cg@2536
  1172
        shiftTop := newY - oldTop.
cg@2536
  1173
    ].
cg@2536
  1174
    aSymbol == #left ifTrue:[
cg@2536
  1175
        shiftLeft := newX - oldLeft.
cg@2536
  1176
    ].
cg@2536
  1177
    aSymbol == #right ifTrue:[
cg@2536
  1178
        shiftRight := newX - oldRight.
cg@2536
  1179
    ].
cg@2536
  1180
    aSymbol == #origin ifTrue:[
cg@2536
  1181
        shiftLeft := newX - oldLeft.
cg@2536
  1182
        shiftTop := newY - oldTop.
cg@2536
  1183
    ].
cg@2536
  1184
    aSymbol == #topRight ifTrue:[
cg@2536
  1185
        shiftRight := newX - oldRight.
cg@2536
  1186
        shiftTop := newY - oldTop.
cg@2536
  1187
    ].
cg@2536
  1188
    aSymbol == #corner ifTrue:[
cg@2536
  1189
        shiftRight := newX - oldRight.
cg@2536
  1190
        shiftBottom := newY - oldBottom.
cg@2536
  1191
    ].
cg@2536
  1192
    aSymbol == #bottomLeft ifTrue:[
cg@2536
  1193
        shiftLeft := newX - oldLeft.
cg@2536
  1194
        shiftBottom := newY - oldBottom.
cg@2536
  1195
    ].
cg@2536
  1196
cg@2536
  1197
    doCheck ifTrue:[
cg@2536
  1198
        ^ (shiftTop ~= 0) or:[ shiftBottom ~= 0 or:[ shiftLeft ~= 0 or:[ shiftRight ~= 0 ]]]
cg@2536
  1199
    ].
cg@2536
  1200
cg@2536
  1201
    undoHistory withoutTransactionDo:[
cg@2536
  1202
        self 
cg@2536
  1203
            shiftLayout:aComponent 
cg@2536
  1204
            top:shiftTop bottom:shiftBottom 
cg@2536
  1205
            left:shiftLeft right:shiftRight
cg@2536
  1206
    ].
cg@60
  1207
!
cg@60
  1208
cg@2536
  1209
resize:aView left:aPoint
cg@2536
  1210
    "obsolete: resize a views left"
cg@2536
  1211
cg@2536
  1212
    self resize:aView handle:#left to:aPoint check:false.
cg@2536
  1213
"/    undoHistory withoutTransactionDo:[
cg@2536
  1214
"/        self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
cg@2536
  1215
"/    ]
cg@2536
  1216
!
cg@2536
  1217
cg@2536
  1218
resize:aView origin:aPoint
cg@2536
  1219
    "obsolete: resize a views origin"
cg@2536
  1220
cg@2536
  1221
    self resize:aView handle:#origin to:aPoint check:false.
cg@2536
  1222
"/    |delta|
cg@2536
  1223
"/
cg@2536
  1224
"/    delta := aPoint - aView computeOrigin.
cg@2536
  1225
"/    undoHistory withoutTransactionDo:[
cg@2536
  1226
"/        self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
cg@2536
  1227
"/    ]
cg@2536
  1228
!
cg@2536
  1229
cg@2536
  1230
resize:aView right:aPoint
cg@2536
  1231
    "obsolete: resize a views right"
cg@2536
  1232
cg@2536
  1233
    self resize:aView handle:#right to:aPoint check:false.
cg@2536
  1234
"/    undoHistory withoutTransactionDo:[
cg@2536
  1235
"/        self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
cg@2536
  1236
"/    ]
cg@2536
  1237
!
cg@2536
  1238
cg@2536
  1239
resize:aComponent startPoint:newStartPoint
cg@2536
  1240
    "obsolete: move a component's startPoint"
cg@2536
  1241
cg@2536
  1242
    self resize:aComponent handle:#startPoint to:newStartPoint check:false
cg@2536
  1243
"/    undoHistory 
cg@2536
  1244
"/        withoutTransactionDo:[
cg@2536
  1245
"/            self shiftLayout:aComponent startPoint:(newStartPoint - (aComponent startPoint)) endPoint:0
cg@2536
  1246
"/        ]
cg@2536
  1247
!
cg@2536
  1248
cg@2536
  1249
resize:aView top:aPoint
cg@2536
  1250
    "obsolete: resize a views top"
cg@2536
  1251
cg@2536
  1252
    self resize:aView handle:#top to:aPoint check:false.
cg@2536
  1253
"/    undoHistory withoutTransactionDo:[
cg@2536
  1254
"/        self shiftLayout:aView 
cg@2536
  1255
"/                top:((aPoint y) - (aView computeOrigin y)) 
cg@2536
  1256
"/                bottom:0
cg@2536
  1257
"/    ]
cg@2536
  1258
!
cg@2536
  1259
cg@2536
  1260
resize:aView topRight:aPoint
cg@2536
  1261
    "obsolete: resize a views top and right"
cg@2536
  1262
cg@2536
  1263
    self resize:aView handle:#topRight to:aPoint check:false.
cg@2536
  1264
"/    undoHistory withoutTransactionDo:[
cg@2536
  1265
"/        self shiftLayout:aView 
cg@2536
  1266
"/                top:((aPoint y) - (aView computeOrigin y))
cg@2536
  1267
"/                bottom:0
cg@2536
  1268
"/                left:0
cg@2536
  1269
"/                right:((aPoint x) - (aView computeCorner x))
cg@2536
  1270
"/    ]
werner@1827
  1271
!
werner@1827
  1272
cg@2501
  1273
startResizeBorder:borderHandleSelector
cg@2501
  1274
    "start resizing the selected view at the given borderHandle"
cg@2501
  1275
cg@60
  1276
    |object|
cg@60
  1277
cg@60
  1278
    object := self singleSelection.
cg@2501
  1279
    self actionResize:object selector:borderHandleSelector.
cg@2501
  1280
cg@2501
  1281
    self 
cg@2501
  1282
        transaction:#resize 
cg@2501
  1283
        selectionDo:[:aView|
cg@2501
  1284
            self createUndoLayout:aView
cg@2501
  1285
        ].
cg@2501
  1286
    "/ self setSelection:nil withRedraw:true.
cg@60
  1287
cg@60
  1288
    motionAction  := [:movePoint | self doDragResize:movePoint].
cg@60
  1289
    releaseAction := [self endResize].
cg@2501
  1290
cg@60
  1291
    self invertOutlineOf:object
cg@60
  1292
! !
cg@60
  1293
cg@1954
  1294
!UIObjectView methodsFor:'private'!
cg@1954
  1295
cg@1954
  1296
undoHistoryChanged
cg@1954
  1297
    self hasUndoHistoryHolder value:(self hasUndoHistory).
cg@1954
  1298
! !
cg@1954
  1299
cg@1714
  1300
!UIObjectView methodsFor:'private-handles'!
cg@60
  1301
ca@175
  1302
handlesOf:aComponent do:aTwoArgAction
cg@2510
  1303
    "perform aTwoArgAction on each handle of a component"
cg@2510
  1304
ca@175
  1305
    |dlt ext|
ca@175
  1306
ca@175
  1307
    dlt := (aComponent originRelativeTo:self) - aComponent origin.
ca@1451
  1308
    dlt := dlt - (4@4).
ca@1451
  1309
    ext := 8@8.
ca@175
  1310
cg@2510
  1311
    self class 
cg@2510
  1312
        handlesOf:aComponent 
cg@2510
  1313
        do:[:pnt :wht |
cg@2510
  1314
            aTwoArgAction value:(pnt + dlt extent:ext) value:wht
cg@2510
  1315
        ]
cg@60
  1316
!
cg@60
  1317
ca@175
  1318
whichHandleOf:aComponent isHitBy:aPoint
cg@2501
  1319
    "returns kind of handle or nil"
cg@2501
  1320
ca@175
  1321
    self handlesOf:aComponent do:[:rectangle :what|
cg@2501
  1322
        (rectangle containsPoint:aPoint) ifTrue:[^ what]
cg@60
  1323
    ].
cg@2501
  1324
    ^ nil
cg@60
  1325
! !
cg@60
  1326
cg@1714
  1327
!UIObjectView methodsFor:'private-resizing subviews'!
cg@60
  1328
werner@1827
  1329
recomputeShapeIfTransparentBox:aView
werner@1829
  1330
    (aView notNil and:[aView isTransparentBox]) ifTrue:[
werner@1827
  1331
        aView computeShape.
werner@1827
  1332
        aView clear; redraw
werner@1827
  1333
    ].
cg@60
  1334
! !
cg@60
  1335
cg@1714
  1336
!UIObjectView methodsFor:'private-shift layout'!
cg@60
  1337
cg@2510
  1338
shiftLayout:aViewOrComponent horizontal:n
cg@2510
  1339
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1340
cg@2514
  1341
    self shiftLayout:aViewOrComponent horizontal:n vertical:0
cg@2514
  1342
!
cg@2514
  1343
cg@2514
  1344
shiftLayout:aViewOrComponent horizontal:h vertical:v
cg@2514
  1345
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2514
  1346
cg@2514
  1347
    (self specFor:aViewOrComponent) hasLayout ifTrue:[
cg@2514
  1348
        self shiftLayout:aViewOrComponent top:v bottom:v left:h right:h
cg@2510
  1349
    ] ifFalse:[
cg@2514
  1350
        self shiftLayout:aViewOrComponent startPoint:(h @ v) endPoint:(h @ v)
cg@2514
  1351
    ].
cg@2510
  1352
!
cg@2510
  1353
cg@60
  1354
shiftLayout:aView left:l right:r
cg@2510
  1355
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1356
cg@60
  1357
    self shiftLayout:aView top:0 bottom:0 left:l right:r
cg@60
  1358
!
cg@60
  1359
cg@2510
  1360
shiftLayout:aComponent startPoint:deltaS endPoint:deltaE
cg@2510
  1361
    "shift coordinates; in case of an open transaction, the undo action is registered"
cg@2510
  1362
cg@2510
  1363
    self createUndoStartPointEndPoint:aComponent.
cg@2510
  1364
    aComponent 
cg@2510
  1365
        startPoint:(aComponent startPoint + deltaS)
cg@2510
  1366
        endPoint:(aComponent endPoint + deltaE).
cg@2510
  1367
!
cg@2510
  1368
cg@60
  1369
shiftLayout:aView top:t bottom:b
cg@2510
  1370
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1371
cg@60
  1372
    self shiftLayout:aView top:t bottom:b left:0 right:0
cg@60
  1373
!
cg@60
  1374
cg@60
  1375
shiftLayout:aView top:t bottom:b left:l right:r
cg@2510
  1376
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1377
cg@2536
  1378
    |type layout oldExt dX dY|
ca@61
  1379
ca@61
  1380
    type := self class layoutType:aView.
cg@2536
  1381
    type isNil ifTrue:[ ^ self ].
cg@2536
  1382
cg@2536
  1383
    self createUndoLayout:aView.
cg@2536
  1384
cg@2536
  1385
    type == #Extent ifTrue:[
cg@2536
  1386
        oldExt := aView extent.
cg@2536
  1387
        dX := r-l.
cg@2536
  1388
        dY := b-t.
cg@2536
  1389
        aView extent:(oldExt + (dX @ dY)).
cg@2536
  1390
        ^ self 
cg@2536
  1391
    ].
cg@2536
  1392
cg@2536
  1393
    layout := aView geometryLayout copy.
cg@2536
  1394
    layout isLayout ifTrue:[
cg@2536
  1395
        layout leftOffset:(layout leftOffset + l)
cg@2536
  1396
                topOffset:(layout topOffset  + t).
cg@2536
  1397
                
cg@2536
  1398
        type == #LayoutFrame ifTrue:[
cg@2536
  1399
            layout bottomOffset:(layout bottomOffset + b).
cg@2536
  1400
            layout rightOffset:(layout rightOffset  + r).
cg@2536
  1401
        ]
cg@2536
  1402
    ] ifFalse:[
cg@2536
  1403
        type == #Rectangle ifTrue:[
cg@2536
  1404
            layout left:(layout left   + l)
cg@2536
  1405
                  right:(layout right  + r)
cg@2536
  1406
                    top:(layout top    + t)
cg@2536
  1407
                 bottom:(layout bottom + b).
cg@2536
  1408
        ] ifFalse:[     "POINT"
cg@2536
  1409
            layout x:(layout x + l) y:(layout y + t).
cg@2536
  1410
        ]
cg@2536
  1411
    ].
cg@2536
  1412
    aView geometryLayout:layout
cg@2510
  1413
!
cg@2510
  1414
cg@2510
  1415
shiftLayout:aViewOrComponent vertical:n
cg@2510
  1416
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1417
cg@2514
  1418
    self shiftLayout:aViewOrComponent horizontal:0 vertical:n
cg@60
  1419
! !
cg@60
  1420
cg@60
  1421
!UIObjectView methodsFor:'searching'!
cg@60
  1422
cg@60
  1423
findObjectAt:aPoint
cg@2501
  1424
    |view viewId lastId point component componentOrView|
cg@2501
  1425
cg@2501
  1426
    componentOrView := self findObjectAt:aPoint in:self.
cg@2501
  1427
cg@2501
  1428
    componentOrView == self ifTrue:[^ nil].
cg@2501
  1429
    ^ componentOrView.
cg@2501
  1430
cg@2501
  1431
"/ cg: old code, which I do not understand
cg@2501
  1432
"/    point := device translatePoint:aPoint fromView:self toView:rootView.
ca@1672
  1433
"/
cg@2501
  1434
"/    viewId := rootView id.
cg@2501
  1435
"/    [viewId notNil] whileTrue:[
cg@2501
  1436
"/        lastId := viewId.
cg@2501
  1437
"/        viewId := device viewIdFromPoint:point in:lastId. "/ must be rootView coordinate
ca@1672
  1438
"/    ].
ca@1672
  1439
"/
cg@2501
  1440
"/    view := device viewFromId:lastId.
cg@2501
  1441
"/    (view isNil or:[view == self]) ifTrue:[ 
cg@2501
  1442
"/        "/ used to return nil here;
cg@2501
  1443
"/        "/ now support a mix of views and components...
cg@2501
  1444
"/        components notEmptyOrNil ifTrue:[
cg@2501
  1445
"/            component := components detect:[:c | c bounds containsPoint:aPoint] ifNone:nil.
cg@2501
  1446
"/            ^ component
cg@2501
  1447
"/        ].
cg@2501
  1448
"/        ^ nil
ca@1672
  1449
"/    ].
cg@2501
  1450
"/    ^ view
cg@2501
  1451
!
cg@2501
  1452
cg@2501
  1453
findObjectAt:aPoint in:aView
cg@2501
  1454
    |lastHit lastRelPoint view point|
cg@2501
  1455
cg@2501
  1456
    "/ reverse search, to find covering ones first.
cg@2501
  1457
    aView subViews reverseDo:[:aSubView |
cg@2501
  1458
        |innerObject relPoint|
cg@2501
  1459
cg@2501
  1460
        ((aSubView origin extent:aSubView extent) containsPoint:aPoint) ifTrue:[
cg@2501
  1461
            relPoint := device translatePoint:aPoint fromView:aView toView:aSubView.
cg@2501
  1462
            innerObject := self findObjectAt:relPoint in:aSubView.
cg@2501
  1463
            innerObject notNil ifTrue:[ ^ innerObject ].
cg@2501
  1464
            lastHit := aSubView.
cg@2501
  1465
            lastRelPoint := relPoint.
cg@2501
  1466
        ]
cg@2501
  1467
    ].
cg@2501
  1468
    view := lastHit ? aView.
cg@2501
  1469
    point := lastRelPoint ? aPoint.
cg@2501
  1470
cg@2501
  1471
    view components notEmptyOrNil ifTrue:[
cg@2501
  1472
        view components reverseDo:[:eachComponent |
cg@2501
  1473
            (eachComponent frame containsPoint:point) ifTrue:[
cg@2501
  1474
                ^ eachComponent
cg@2501
  1475
            ].
cg@2501
  1476
        ].
cg@2501
  1477
    ].
cg@2501
  1478
    ^ view
cg@60
  1479
! !
cg@60
  1480
cg@60
  1481
!UIObjectView methodsFor:'selections'!
cg@60
  1482
ca@768
  1483
hideSelection
ca@1427
  1484
    "hide the selection - undraw hilights - whatever that is
ca@1427
  1485
    "
cg@2514
  1486
cg@2514
  1487
    super hideSelection.
cg@2514
  1488
    self repairDamage.   
cg@2501
  1489
"/    self showUnselected:selection.
ca@768
  1490
!
ca@768
  1491
ca@128
  1492
moveableSelection
ca@131
  1493
    "checks whether the selection is not empty and all selected instances
ca@131
  1494
     can be moved. If true the selection is returned otherwise nil
ca@128
  1495
    "
ca@128
  1496
    |coll|
ca@128
  1497
ca@128
  1498
    self hasSelection ifTrue:[
cg@2364
  1499
        (self canMove:(coll := self selection)) ifTrue:[
cg@2364
  1500
            ^ coll
cg@2364
  1501
        ]
ca@128
  1502
    ].
cg@2364
  1503
    ^ nil
ca@128
  1504
!
ca@128
  1505
cg@60
  1506
numberOfSelections
ca@131
  1507
    "return the number of selected instances
ca@61
  1508
    "
ca@128
  1509
    |coll size|
ca@128
  1510
ca@128
  1511
    coll := self selection.
ca@128
  1512
    size := coll size.
ca@128
  1513
ca@128
  1514
    (size ~~ 0 or:[coll isNil]) ifTrue:[^ size].
ca@128
  1515
  ^ 1
cg@60
  1516
!
cg@60
  1517
sv@2481
  1518
resizableSelection
sv@2481
  1519
    "checks whether the selection is not empty and all selected instances
sv@2481
  1520
     can be resized. If true the selection is returned otherwise nil
sv@2481
  1521
    "
sv@2481
  1522
    |coll|
sv@2481
  1523
sv@2481
  1524
    self hasSelection ifTrue:[
sv@2481
  1525
        coll := self selection.        
sv@2481
  1526
        (self canResize:coll) ifTrue:[
sv@2481
  1527
            ^ coll
sv@2481
  1528
        ]
sv@2481
  1529
    ].
sv@2481
  1530
    ^ nil
sv@2481
  1531
!
sv@2481
  1532
werner@1827
  1533
selectNextUpInHierarchy
cg@2422
  1534
    self halt:#ca.
werner@1827
  1535
!
werner@1827
  1536
cg@2215
  1537
selection:newSelection
cg@2215
  1538
    "change selection to newSelection"
cg@2215
  1539
cg@2215
  1540
    self select:newSelection
ca@149
  1541
!
ca@149
  1542
ca@128
  1543
selectionDo:aBlock
ca@128
  1544
    "apply block to every selected object
ca@128
  1545
    "
ca@128
  1546
    self forEach:(self selection) do:aBlock
ca@128
  1547
ca@128
  1548
ca@128
  1549
!
ca@128
  1550
ca@61
  1551
showSelection
cg@2501
  1552
    "show the selection - draw handles"
cg@2501
  1553
ca@61
  1554
    selectionHiddenLevel == 0 ifTrue:[
cg@2514
  1555
        super showSelection.
cg@2514
  1556
        self repairDamage.   
cg@60
  1557
    ].
cg@60
  1558
!
cg@60
  1559
cg@60
  1560
singleSelection
sv@2267
  1561
    "checks whether a single element is selected; in this case the element is
sv@2267
  1562
     returned otherwise nil"
sv@2267
  1563
sv@2267
  1564
    |sel|
sv@2267
  1565
sv@2267
  1566
    sel := self selection.
sv@2267
  1567
    sel isCollection ifTrue:[
sv@2267
  1568
        sel := sel size == 1 ifTrue:[sel first] ifFalse:[nil].
cg@60
  1569
    ].
sv@2267
  1570
    ^ sel
cg@60
  1571
!
cg@60
  1572
cg@60
  1573
singleSelectionDo:aBlock
ca@131
  1574
    "checks whether one element is selected; in this case the block
ca@131
  1575
     with argument the selected instance will be processed
ca@61
  1576
    "
cg@60
  1577
    |view|
cg@60
  1578
cg@60
  1579
    (view := self singleSelection) notNil ifTrue:[
cg@1120
  1580
	aBlock value:view
cg@60
  1581
    ]
cg@60
  1582
!
cg@60
  1583
cg@1230
  1584
twoElementSelection
cg@1230
  1585
    "checks whether exactly two elements are selected; 
cg@1230
  1586
     in this case, return the selection collection.
cg@1230
  1587
     otherwise return nil
cg@1230
  1588
    "
cg@1230
  1589
    |coll|
cg@1230
  1590
cg@1230
  1591
    (coll := self selection) isCollection ifFalse:[
cg@1230
  1592
        ^ nil "/ single
cg@1230
  1593
    ].
cg@1230
  1594
cg@1230
  1595
    coll size == 2 ifTrue:[ ^ coll].
cg@1230
  1596
    ^ nil
cg@1230
  1597
!
cg@1230
  1598
cg@60
  1599
unselect
ca@61
  1600
    "clear selection
ca@61
  1601
    "
ca@128
  1602
    self select:nil
cg@60
  1603
!
cg@60
  1604
cg@60
  1605
withSelectionHiddenDo:aBlock
cg@1959
  1606
    "apply block with selection hidden (no handles)"
cg@1959
  1607
ca@78
  1608
    |coll|
ca@78
  1609
ca@138
  1610
    selectionHiddenLevel == 0 ifTrue:[
cg@1555
  1611
        self hideSelection.
cg@1555
  1612
        device flush.
ca@61
  1613
    ].
ca@138
  1614
    selectionHiddenLevel := selectionHiddenLevel + 1.
ca@61
  1615
cg@2516
  1616
    aBlock 
cg@2516
  1617
        ensure:[
cg@2516
  1618
            selectionHiddenLevel == 1 ifTrue:[
cg@2516
  1619
                "/ careful to decrement selectionHiddenLevel AFTER the sizeChanged;
cg@2516
  1620
                "/ otherwise, we get endless recursion here.
cg@2516
  1621
                setOfSuperViewsSizeChanged notEmpty ifTrue:[
cg@2516
  1622
                    coll := self minClosedViewSetFor:setOfSuperViewsSizeChanged.
cg@2516
  1623
                    coll do:[:aView| aView sizeChanged:nil].
cg@2516
  1624
                    setOfSuperViewsSizeChanged := IdentitySet new
cg@2516
  1625
                ].
cg@2516
  1626
                selectionHiddenLevel := selectionHiddenLevel - 1.
cg@2516
  1627
                self showSelection.
cg@2516
  1628
            ] ifFalse:[
cg@2516
  1629
                selectionHiddenLevel := selectionHiddenLevel - 1.
cg@1555
  1630
            ].
cg@1555
  1631
        ]
ca@61
  1632
!
ca@61
  1633
ca@61
  1634
withoutSelectionDo:aBlock
ca@61
  1635
    "evaluate aBlock while selection is nilled
ca@61
  1636
    "
cg@60
  1637
    |sel|
cg@60
  1638
ca@128
  1639
    self hasSelection ifFalse:[
cg@1120
  1640
	aBlock value
ca@128
  1641
    ] ifTrue:[
cg@1120
  1642
	sel := self selection.
cg@1120
  1643
	self setSelection:nil withRedraw:true.
cg@1120
  1644
	aBlock value.
cg@1120
  1645
	self setSelection:sel withRedraw:true.
cg@60
  1646
    ]
cg@60
  1647
cg@60
  1648
cg@60
  1649
! !
cg@60
  1650
cg@1717
  1651
!UIObjectView methodsFor:'selections-basic'!
ca@131
  1652
ca@1427
  1653
recursiveRepair:theDamages startIn:aView
ca@1427
  1654
    "repair all views and contained views, which intersects the damage.
ca@1427
  1655
     !!!! all damages repaired are removed from the list of damages !!!!
ca@1427
  1656
    "
ca@1427
  1657
    |color isRepaired relOrg damage
ca@1427
  1658
     bwWidth    "{ Class:SmallInteger }"
ca@1427
  1659
     x          "{ Class:SmallInteger }"
ca@1427
  1660
     y          "{ Class:SmallInteger }"
ca@1427
  1661
     w          "{ Class:SmallInteger }"
ca@1427
  1662
     h          "{ Class:SmallInteger }"
ca@1427
  1663
     relOrgX    "{ Class:SmallInteger }"
ca@1427
  1664
     relOrgY    "{ Class:SmallInteger }"
ca@1427
  1665
     width      "{ Class:SmallInteger }"
ca@1427
  1666
     height     "{ Class:SmallInteger }"
ca@1427
  1667
     size       "{ Class:SmallInteger }"
ca@1427
  1668
    |
ca@1438
  1669
    aView isInputOnly ifTrue:[^ self ].
ca@1427
  1670
ca@1437
  1671
    (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ self ].
ca@1427
  1672
cg@2513
  1673
    aView components notEmptyOrNil ifTrue:[ 
cg@2513
  1674
        aView invalidate 
cg@2513
  1675
    ].
ca@1427
  1676
    aView subViews notNil ifTrue:[
ca@1427
  1677
        aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
ca@1427
  1678
        theDamages isEmpty ifTrue:[ ^ self ].
ca@1427
  1679
    ].
ca@1427
  1680
ca@1427
  1681
    relOrg  := aView originRelativeTo:self.
ca@1427
  1682
    bwWidth := aView borderWidth.
ca@1427
  1683
    size    := theDamages size.
ca@1427
  1684
ca@1427
  1685
    "/ compute relative origin starting from border left@top
ca@1427
  1686
    relOrgX := relOrg x - bwWidth.
ca@1427
  1687
    relOrgY := relOrg y - bwWidth.
ca@1427
  1688
    width   := aView width  + bwWidth + bwWidth.
sv@2482
  1689
    height  := aView height + bwWidth + bwWidth.
sv@2482
  1690
sv@2482
  1691
    size to:1 by:-1 do:[:anIndex|
sv@2482
  1692
        damage := theDamages at:anIndex.
sv@2482
  1693
sv@2482
  1694
        "/ compute the rectangle into the view
sv@2482
  1695
        y := damage top  - relOrgY.
sv@2482
  1696
        x := damage left - relOrgX.
sv@2482
  1697
        w := damage width.
sv@2482
  1698
        h := damage height.
sv@2482
  1699
sv@2482
  1700
        isRepaired := true.
sv@2482
  1701
sv@2482
  1702
        x     < 0      ifTrue:[ w := w + x. x := 0. isRepaired := false ].
sv@2482
  1703
        y     < 0      ifTrue:[ h := h + y. y := 0. isRepaired := false ].
sv@2482
  1704
        x + w > width  ifTrue:[ w := width  - x.    isRepaired := false ].
sv@2482
  1705
        y + h > height ifTrue:[ h := height - y.    isRepaired := false ].
sv@2482
  1706
sv@2482
  1707
        (w > 0 and:[h > 0]) ifTrue:[
sv@2482
  1708
            bwWidth ~~ 0 ifTrue:[
sv@2482
  1709
                color isNil ifTrue:[
sv@2482
  1710
                    "/ must force redraw of border
sv@2482
  1711
                    color := aView borderColor.
sv@2482
  1712
                    aView borderColor:(Color colorId:1).
sv@2482
  1713
                    aView borderColor:color.
sv@2482
  1714
                ].
sv@2482
  1715
                w := w - bwWidth.
sv@2482
  1716
                h := h - bwWidth.
sv@2482
  1717
sv@2482
  1718
                (x := x - bwWidth) < 0 ifTrue:[w := w + x. x := 0].
sv@2482
  1719
                (y := y - bwWidth) < 0 ifTrue:[h := h + y. y := 0].
sv@2482
  1720
sv@2482
  1721
                (w > 0 and:[h > 0])  ifFalse:[w := 0].
sv@2482
  1722
            ].
sv@2482
  1723
sv@2482
  1724
            w > 0 ifTrue:[
sv@2482
  1725
                aView clearRectangleX:x y:y width:w height:h.
sv@2482
  1726
                aView exposeX:x y:y width:w height:h
sv@2482
  1727
            ].
sv@2482
  1728
            isRepaired ifTrue:[ theDamages removeIndex:anIndex ].
sv@2482
  1729
        ]
sv@2482
  1730
    ].
ca@1427
  1731
!
ca@1427
  1732
ca@131
  1733
selection
ca@131
  1734
    "returns the current selection
ca@131
  1735
    "
cg@2528
  1736
cg@2528
  1737
    "/ Q to ca: why redefine the collection building???
cg@2528
  1738
    ^ super selection.
cg@2528
  1739
ca@131
  1740
    ^ selection
ca@131
  1741
!
ca@131
  1742
cg@2356
  1743
setSelection:newSelection withRedraw:doRedraw
cg@2356
  1744
    "set a new selection without change notifications"
cg@2356
  1745
cg@2356
  1746
    | sel |
cg@2356
  1747
cg@2356
  1748
    (sel := newSelection) == self ifTrue:[
cg@2356
  1749
        sel := nil
cg@2356
  1750
    ].
cg@2356
  1751
cg@2356
  1752
    doRedraw ifTrue:[
cg@2356
  1753
        self hideSelection.
cg@2356
  1754
        selection := sel.
cg@2356
  1755
cg@2356
  1756
        self forEach:selection do:[:aView |
cg@2356
  1757
            |superView|
cg@2356
  1758
cg@2356
  1759
            superView := aView superView. 
cg@2356
  1760
            self recomputeShapeIfTransparentBox:superView.
cg@2356
  1761
        ].
cg@2356
  1762
        self showSelection.
cg@2356
  1763
    ] ifFalse:[
cg@2356
  1764
        selection := sel
cg@2356
  1765
    ]
cg@2356
  1766
!
cg@2356
  1767
ca@1427
  1768
showUnselected:something
cg@2501
  1769
    "show a component or list of components unselected"
cg@2501
  1770
cg@2501
  1771
    |damages oldClipped savedSelection|
ca@1427
  1772
ca@1427
  1773
    (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
ca@1427
  1774
        ^ self
ca@1427
  1775
    ].
ca@1438
  1776
ca@1427
  1777
    damages := OrderedCollection new.
ca@1427
  1778
ca@1427
  1779
    self forEach:something do:[:v|
ca@1437
  1780
        self handlesOf:v do:[:aDamage :wht|
ca@1437
  1781
            damages reverseDo:[:el|
ca@1437
  1782
                (el intersects:aDamage) ifTrue:[
ca@1437
  1783
                    damages removeIdentical:el.
ca@1437
  1784
cg@2503
  1785
                    aDamage left:(aDamage left   min:el left) floor
cg@2503
  1786
                           right:(aDamage right  max:el right) ceiling
cg@2503
  1787
                             top:(aDamage top    min:el top) floor
cg@2503
  1788
                          bottom:(aDamage bottom max:el bottom) ceiling
ca@1437
  1789
                ]
ca@1437
  1790
            ].                        
ca@1437
  1791
            damages add:aDamage
ca@1427
  1792
        ]
ca@1427
  1793
    ].
ca@1438
  1794
cg@2501
  1795
    damages do:[:el| self clearRectangle:el. ].
ca@1438
  1796
ca@1438
  1797
    (oldClipped := clipChildren) ifFalse:[
ca@1438
  1798
        self clippedByChildren:(clipChildren := true)
ca@1438
  1799
    ].
ca@1451
  1800
    self subViews reverseDo:[:v| self recursiveRepair:damages startIn:v].
ca@1437
  1801
ca@1427
  1802
    oldClipped ~~ clipChildren ifTrue:[
ca@1427
  1803
        self clippedByChildren:(clipChildren := oldClipped).
ca@1427
  1804
    ].
cg@2501
  1805
cg@2501
  1806
    device flush.
cg@2501
  1807
cg@2501
  1808
    savedSelection := selection.
cg@2501
  1809
    [
cg@2501
  1810
        selection := nil.
cg@2501
  1811
        damages do:[:el| self invalidate:el ].
cg@2501
  1812
        self repairDamage.
cg@2501
  1813
    ] ensure:[
cg@2501
  1814
        selection := savedSelection
cg@2501
  1815
    ].
ca@131
  1816
! !
ca@131
  1817
cg@60
  1818
!UIObjectView methodsFor:'testing'!
cg@60
  1819
ca@128
  1820
hasSelection
ca@284
  1821
    "returns true if any widget is selected
ca@61
  1822
    "
ca@128
  1823
    ^ self numberOfSelections ~~ 0
cg@60
  1824
cg@60
  1825
!
cg@60
  1826
ca@284
  1827
hasSingleSelection
ca@284
  1828
    "returns true if one widget is selected
ca@284
  1829
    "
ca@284
  1830
    ^ self numberOfSelections == 1
ca@284
  1831
ca@284
  1832
!
ca@284
  1833
ca@284
  1834
hasUndoHistory
cg@1918
  1835
    "returns true if undos exists"
cg@1918
  1836
ca@284
  1837
    ^ undoHistory isEmpty not
ca@284
  1838
!
ca@284
  1839
ca@134
  1840
isModified
cg@1918
  1841
    "returns true if painter is modified"
cg@1918
  1842
cg@1918
  1843
    ^ undoHistory isModified
ca@134
  1844
!
ca@134
  1845
ca@128
  1846
isSelected:anObject
ca@128
  1847
    "return true, if the argument, anObject is selected
ca@128
  1848
    "
ca@128
  1849
    anObject notNil ifTrue:[
cg@1120
  1850
	self selectionDo:[:el| el == anObject ifTrue:[^ true]]
ca@128
  1851
    ].
ca@128
  1852
  ^ false
ca@128
  1853
cg@2538
  1854
!
cg@2538
  1855
cg@2538
  1856
object:anObject isContainedIn:aRectangle
cg@2538
  1857
    ^ anObject bounds isContainedIn:aRectangle
cg@60
  1858
! !
cg@60
  1859
cg@60
  1860
!UIObjectView methodsFor:'transaction'!
cg@60
  1861
ca@134
  1862
createUndoLayout:aView
ca@134
  1863
    "prepare undo action for a view changing its layout
ca@134
  1864
    "
ca@134
  1865
    self subclassResponsibility
ca@134
  1866
ca@134
  1867
!
ca@134
  1868
cg@60
  1869
transaction:aType objects:something do:aOneArgBlock
cg@60
  1870
    "opens a transaction and evaluates a block within the transaction; the
cg@60
  1871
     argument to the block is a view from derived from something
cg@60
  1872
    "
cg@60
  1873
    self subclassResponsibility
cg@60
  1874
cg@60
  1875
cg@60
  1876
!
cg@60
  1877
cg@60
  1878
transaction:aType selectionDo:aOneArgBlock
cg@60
  1879
    "opens a transaction and evaluates a block within the transaction; the
cg@60
  1880
     argument to the block is a view from the selection
cg@60
  1881
    "
ca@128
  1882
    self transaction:aType objects:(self selection) do:aOneArgBlock
cg@60
  1883
cg@60
  1884
cg@60
  1885
! !
cg@60
  1886
cg@1715
  1887
!UIObjectView methodsFor:'user actions-dimension'!
cg@60
  1888
cg@60
  1889
copyExtent
cg@2364
  1890
    "copy the extent from the selected object"
cg@2364
  1891
cg@60
  1892
    |object|
cg@60
  1893
cg@60
  1894
    object := self singleSelection.
cg@60
  1895
    object notNil ifTrue:[
cg@2364
  1896
        CopiedExtent := object computeExtent
cg@60
  1897
    ] ifFalse:[
cg@2364
  1898
        self warn:'Exactly one element must be selected!!'.
cg@60
  1899
    ]
cg@60
  1900
!
cg@60
  1901
ca@89
  1902
copyLayout
cg@2364
  1903
    "copy the layout from the selected object"
cg@2364
  1904
ca@89
  1905
    |object|
ca@89
  1906
ca@89
  1907
    object := self singleSelection.
ca@89
  1908
    object notNil ifTrue:[
cg@2364
  1909
        CopiedLayout := object geometryLayout copy
ca@89
  1910
    ] ifFalse:[
cg@2364
  1911
        self warn:'Exactly one element must be selected!!'.
ca@89
  1912
    ]
ca@89
  1913
!
ca@89
  1914
cg@1230
  1915
exchangeLayouts
cg@1230
  1916
    "exchange the layout of two elements 
cg@1230
  1917
     (useful to change the order of radiobuttons or checkBoxes)
cg@1230
  1918
    "
cg@1230
  1919
    |objects l1 l2|
cg@1230
  1920
cg@1230
  1921
    objects := self twoElementSelection.
cg@1230
  1922
cg@1230
  1923
    objects notNil ifTrue:[
cg@1230
  1924
        l1 := (objects at:1) geometryLayout copy.
cg@1230
  1925
        l2 := (objects at:2) geometryLayout copy.
cg@1230
  1926
        self transaction:#exchangeLayout dimensionDo:[:v|
cg@1230
  1927
            v == (objects at:1) ifTrue:[
cg@1230
  1928
                v geometryLayout:(l2 copy)
cg@1230
  1929
            ] ifFalse:[
cg@1230
  1930
                v geometryLayout:(l1 copy).
cg@1230
  1931
            ]
cg@1230
  1932
        ]    
cg@1230
  1933
    ] ifFalse:[    
cg@1230
  1934
        self warn:'exactly two elements must be selected'.
cg@1230
  1935
    ]
cg@1230
  1936
cg@1230
  1937
cg@1230
  1938
cg@1230
  1939
!
cg@1230
  1940
cg@60
  1941
pasteExtent
cg@2364
  1942
    "paste the copied extent to all objects in the selection"
cg@2364
  1943
cg@2398
  1944
    |heightToPaste widthToPaste|
cg@2398
  1945
cg@2364
  1946
    CopiedExtent notNil ifTrue:[
cg@2398
  1947
        widthToPaste := CopiedExtent x.
cg@2398
  1948
        heightToPaste := CopiedExtent y.
cg@2398
  1949
    ] ifFalse:[
cg@2398
  1950
        CopiedLayout notNil ifTrue:[
cg@2398
  1951
            CopiedLayout leftFraction = CopiedLayout rightFraction ifTrue:[
cg@2398
  1952
                CopiedLayout topFraction = CopiedLayout bottomFraction ifTrue:[
cg@2398
  1953
                    widthToPaste := (CopiedLayout rightOffset - CopiedLayout leftOffset). 
cg@2398
  1954
                    heightToPaste := (CopiedLayout bottomOffset - CopiedLayout topOffset). 
cg@2398
  1955
                ]
cg@2398
  1956
            ]
cg@2398
  1957
        ].
cg@2398
  1958
    ].
cg@2398
  1959
cg@2398
  1960
    widthToPaste notNil ifTrue:[
cg@2398
  1961
        heightToPaste notNil ifTrue:[
cg@2398
  1962
            self transaction:#pasteExtent dimensionDo:[:v|
cg@2398
  1963
                self resize:v corner:(v computeOrigin + (widthToPaste@heightToPaste))
cg@2398
  1964
            ]    
cg@2364
  1965
        ]    
cg@60
  1966
    ]    
cg@60
  1967
!
cg@60
  1968
cg@60
  1969
pasteHeight
cg@2364
  1970
    "paste the copied extent's height to all objects in the selection"
cg@2364
  1971
cg@2398
  1972
    |heightToPaste|
cg@2398
  1973
cg@2364
  1974
    CopiedExtent notNil ifTrue:[
cg@2398
  1975
        heightToPaste := CopiedExtent y.
cg@2398
  1976
    ] ifFalse:[
cg@2398
  1977
        CopiedLayout notNil ifTrue:[
cg@2398
  1978
            CopiedLayout topFraction = CopiedLayout bottomFraction ifTrue:[
cg@2398
  1979
                heightToPaste := (CopiedLayout bottomOffset - CopiedLayout topOffset) 
cg@2398
  1980
            ]
cg@2398
  1981
        ].
cg@2398
  1982
    ].
cg@2398
  1983
cg@2398
  1984
    heightToPaste notNil ifTrue:[
cg@2364
  1985
        self transaction:#pasteHeight dimensionDo:[:v|
cg@2398
  1986
            self resize:v bottom:(v computeOrigin + heightToPaste)
cg@2398
  1987
        ].
cg@2398
  1988
    ].    
ca@89
  1989
!
ca@89
  1990
cg@2364
  1991
pasteLayout
cg@2364
  1992
    "paste the layout to all objects in the selection"
cg@2364
  1993
cg@2364
  1994
    CopiedLayout notNil ifTrue:[
cg@2364
  1995
        self transaction:#pasteLayout dimensionDo:[:v|
cg@2364
  1996
            v geometryLayout:(CopiedLayout copy)
cg@2364
  1997
        ]    
cg@2364
  1998
    ]    
cg@2364
  1999
!
cg@2364
  2000
cg@60
  2001
pasteWidth
cg@2364
  2002
    "paste the copied extent's width to all objects in the selection"
cg@2364
  2003
cg@2398
  2004
    |widthToPaste|
cg@2398
  2005
cg@2364
  2006
    CopiedExtent notNil ifTrue:[
cg@2398
  2007
        widthToPaste := CopiedExtent x.
cg@2398
  2008
    ] ifFalse:[
cg@2398
  2009
        CopiedLayout notNil ifTrue:[
cg@2398
  2010
            CopiedLayout leftFraction = CopiedLayout rightFraction ifTrue:[
cg@2398
  2011
                widthToPaste := (CopiedLayout rightOffset - CopiedLayout leftOffset) 
cg@2398
  2012
            ]
cg@2398
  2013
        ].
cg@2398
  2014
    ].
cg@2398
  2015
cg@2398
  2016
    widthToPaste notNil ifTrue:[
cg@2364
  2017
        self transaction:#pasteWidth dimensionDo:[:v|
cg@2398
  2018
            self resize:v right:(v computeOrigin + widthToPaste)
cg@2364
  2019
        ]    
cg@60
  2020
    ]    
cg@60
  2021
!
cg@60
  2022
ca@61
  2023
setExtent:anExtent
ca@61
  2024
    "change extent for all selected objects
ca@61
  2025
    "
ca@134
  2026
    self transaction:#extent dimensionDo:[:v|
cg@1120
  2027
	v geometryLayout:nil.
cg@1120
  2028
	v extent:anExtent.
cg@67
  2029
    ].
cg@67
  2030
cg@67
  2031
    "Modified: 28.2.1997 / 12:49:00 / cg"
ca@61
  2032
!
ca@61
  2033
ca@149
  2034
setLayout:aLayout
ca@149
  2035
    "change layout for all selected objects
ca@149
  2036
    "
ca@149
  2037
    self transaction:#layout dimensionDo:[:v|
cg@2501
  2038
        v geometryLayout:(aLayout copy)
ca@149
  2039
    ].    
ca@149
  2040
!
ca@149
  2041
cg@60
  2042
setToDefaultExtent
ca@61
  2043
    "change extent of all selected views to their default extent
ca@61
  2044
    "
ca@134
  2045
    self transaction:#defaultExtent dimensionDo:[:v|
cg@1120
  2046
	self resize:v corner:(v computeOrigin + (v preferredExtent)).
cg@60
  2047
    ]    
cg@60
  2048
cg@60
  2049
!
cg@60
  2050
cg@60
  2051
setToDefaultHeight
ca@61
  2052
    "change height of all selected views to their default height
ca@61
  2053
    "
ca@134
  2054
    self transaction:#defaultHeight dimensionDo:[:v|
cg@1120
  2055
	self resize:v bottom:(v computeOrigin + (v preferredExtent))
cg@60
  2056
    ]    
cg@60
  2057
cg@60
  2058
!
cg@60
  2059
cg@60
  2060
setToDefaultWidth
ca@61
  2061
    "change width of all selected views to their default width
ca@61
  2062
    "
ca@134
  2063
    self transaction:#defaultWidth dimensionDo:[:v|
cg@1120
  2064
	self resize:v right:(v computeOrigin + (v preferredExtent))
cg@60
  2065
    ]    
cg@60
  2066
cg@60
  2067
!
cg@60
  2068
ca@134
  2069
transaction:aType dimensionDo:aOneArgBlock
cg@60
  2070
    "change dimension within a transaction for the selected elements by evaluating
cg@60
  2071
     the block with the argument a view.
cg@60
  2072
    "
ca@61
  2073
    self withSelectionHiddenDo:[
cg@1120
  2074
	self transaction:aType selectionDo:[:aView|
cg@1120
  2075
	    (self class layoutType:aView) notNil ifTrue:[
cg@1120
  2076
		self createUndoLayout:aView.
cg@1120
  2077
		aOneArgBlock value:aView.
cg@1120
  2078
		self elementChangedSize:aView.
cg@1120
  2079
	    ]
cg@1120
  2080
	]
ca@61
  2081
    ].
ca@225
  2082
    self layoutChanged
ca@61
  2083
ca@61
  2084
! !
ca@61
  2085
cg@1715
  2086
!UIObjectView methodsFor:'user actions-move'!
ca@61
  2087
cg@2394
  2088
moveDo:aOneArgBlock 
cg@2394
  2089
    "perform a move operation (with auto repeat)"
cg@2394
  2090
ca@138
  2091
    |sensor tm|
ca@138
  2092
ca@138
  2093
    self moveableSelection isNil ifTrue:[
cg@2356
  2094
        ^ self
ca@138
  2095
    ].
ca@138
  2096
    sensor := self sensor.
ca@138
  2097
cg@2394
  2098
    tm := ButtonController defaultInitialDelay.
ca@138
  2099
ca@138
  2100
    self withSelectionHiddenDo:[
cg@2356
  2101
        self transaction:#move selectionDo:[:aView|self createUndoLayout:aView].
cg@2356
  2102
cg@2356
  2103
        [
cg@2356
  2104
            self selectionDo:[:aView| aOneArgBlock value:aView ].
cg@2510
  2105
cg@2394
  2106
            sensor leftButtonPressed ifTrue:[
cg@2394
  2107
                self windowGroup processExposeEvents.
cg@2394
  2108
                Delay waitForSeconds:tm.
cg@2394
  2109
                self windowGroup processExposeEvents.
cg@2394
  2110
                tm := ButtonController defaultRepeatDelay.
cg@2394
  2111
                self layoutChanged.
cg@2394
  2112
            ].
cg@2356
  2113
            sensor leftButtonPressed.
cg@2356
  2114
        ] whileTrue.
cg@2356
  2115
cg@2356
  2116
        "/ handle any expose events (for subcomponents) before
cg@2356
  2117
        "/ redrawing the handles.
cg@2356
  2118
        Delay waitForSeconds:0.1.
cg@2394
  2119
        self windowGroup processExposeEvents
ca@138
  2120
    ].
ca@138
  2121
!
ca@138
  2122
ca@113
  2123
moveSelectionDown
ca@61
  2124
    "move selection down
ca@61
  2125
    "
cg@1222
  2126
    self moveSelectionDown:1
cg@1222
  2127
cg@1222
  2128
!
cg@1222
  2129
cg@1222
  2130
moveSelectionDown:howMany
cg@2510
  2131
    "move selection down (pixelwise or aligned-grid wise)"
cg@2510
  2132
ca@138
  2133
    |gridY n|
ca@138
  2134
ca@138
  2135
    gridAlign notNil ifTrue:[gridY := gridAlign y]
cg@1222
  2136
                    ifFalse:[gridY := 1].
ca@138
  2137
ca@138
  2138
    self moveDo:[:aView|
cg@1222
  2139
        aligning ifTrue:[
cg@1222
  2140
            n := ((aView computeCorner y) \\ gridY).
cg@1222
  2141
cg@1222
  2142
            n ~~ 0 ifTrue:[
cg@1222
  2143
                n := gridY - n + 1.
cg@1222
  2144
            ] ifFalse:[
cg@1222
  2145
                n := gridY
cg@1222
  2146
            ]
cg@1222
  2147
        ] ifFalse:[
cg@2510
  2148
            n := 1.
cg@2510
  2149
            self sensor shiftDown ifTrue:[
cg@2510
  2150
                n := 8.    
cg@2510
  2151
            ].
cg@1222
  2152
        ].
cg@1222
  2153
        n := n * howMany.
cg@2510
  2154
        self shiftLayout:aView vertical:n
cg@60
  2155
    ]
cg@60
  2156
!
cg@60
  2157
ca@113
  2158
moveSelectionLeft
cg@60
  2159
    "move selection left
cg@60
  2160
    "
cg@1222
  2161
    self moveSelectionLeft:1
cg@1222
  2162
cg@1222
  2163
!
cg@1222
  2164
cg@1222
  2165
moveSelectionLeft:howMany
cg@2510
  2166
    "move selection to the left (pixelwise or aligned-grid wise)"
cg@2510
  2167
ca@113
  2168
    |gridX n|
cg@60
  2169
ca@138
  2170
    gridAlign notNil ifTrue:[gridX := gridAlign x]
cg@1222
  2171
                    ifFalse:[gridX := 1].
ca@138
  2172
ca@138
  2173
    self moveDo:[:aView|
cg@1222
  2174
        aligning ifTrue:[
cg@1222
  2175
            n := ((aView computeOrigin x) \\ gridX).
cg@1222
  2176
            n == 0 ifTrue:[n := gridX].
cg@1222
  2177
        ] ifFalse:[
cg@2538
  2178
            n := 1.
cg@2510
  2179
            self sensor shiftDown ifTrue:[
cg@2538
  2180
                n := 8.    
cg@2510
  2181
            ].
cg@1222
  2182
        ].
cg@1222
  2183
        n := n * howMany.
cg@2538
  2184
        self shiftLayout:aView horizontal:n negated
cg@60
  2185
    ]
cg@60
  2186
!
cg@60
  2187
ca@113
  2188
moveSelectionRight
cg@2356
  2189
    "move the selection to the right"
cg@2356
  2190
cg@1222
  2191
    self moveSelectionRight:1
cg@1222
  2192
!
cg@1222
  2193
cg@1222
  2194
moveSelectionRight:howMany
cg@2510
  2195
    "move selection to the right (pixelwise or aligned-grid wise)"
cg@2356
  2196
ca@113
  2197
    |gridX n|
ca@113
  2198
ca@138
  2199
    gridAlign notNil ifTrue:[gridX := gridAlign x]
cg@1222
  2200
                    ifFalse:[gridX := 1].
ca@138
  2201
ca@138
  2202
    self moveDo:[:aView|
cg@1222
  2203
        aligning ifTrue:[
cg@1222
  2204
            n := ((aView computeCorner x) \\ gridX).
cg@2538
  2205
            n == 0 ifTrue:[n := gridX].
cg@1222
  2206
        ] ifFalse:[
cg@2510
  2207
            n := 1.
cg@2510
  2208
            self sensor shiftDown ifTrue:[
cg@2510
  2209
                n := 8.    
cg@2510
  2210
            ].
cg@1222
  2211
        ].
cg@1222
  2212
        n := n * howMany.
cg@2510
  2213
        self shiftLayout:aView horizontal:n
ca@113
  2214
    ]
ca@113
  2215
!
ca@113
  2216
ca@113
  2217
moveSelectionUp
cg@60
  2218
    "move selection up
cg@60
  2219
    "
cg@1222
  2220
    self moveSelectionUp:1
cg@1222
  2221
!
cg@1222
  2222
cg@1222
  2223
moveSelectionUp:howMany
cg@2510
  2224
    "move selection up (pixelwise or aligned-grid wise)"
cg@2510
  2225
ca@113
  2226
    |gridY n|
cg@60
  2227
ca@138
  2228
    gridAlign notNil ifTrue:[gridY := gridAlign y]
cg@1222
  2229
                    ifFalse:[gridY := 1].
ca@138
  2230
ca@138
  2231
    self moveDo:[:aView|
cg@1222
  2232
        aligning ifTrue:[
sv@2485
  2233
            n := ((aView computeOrigin y) \\ gridY).
cg@1222
  2234
            n == 0 ifTrue:[n := gridY].
cg@1222
  2235
            n := n negated.
cg@1222
  2236
        ] ifFalse:[
cg@2510
  2237
            n := -1.
cg@2510
  2238
            self sensor shiftDown ifTrue:[
cg@2510
  2239
                n := -8.    
cg@2510
  2240
            ].
cg@1222
  2241
        ].
cg@1222
  2242
        n := n * howMany.
cg@2510
  2243
        self shiftLayout:aView vertical:n
cg@60
  2244
    ]
cg@60
  2245
! !
cg@60
  2246
cg@1715
  2247
!UIObjectView methodsFor:'user actions-position'!
cg@60
  2248
cg@2364
  2249
alignResizeSelectionLeft
cg@2364
  2250
    "resize the selection on the left to align their left edge with the 
cg@2364
  2251
     of the first object in the selection; 
cg@2364
  2252
     in case of a single object selection, the objects left edge is aligned with the left of its superview"
cg@2364
  2253
cg@2364
  2254
    |lmost delta sel|
cg@2364
  2255
cg@2364
  2256
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2257
        self withSelectionHiddenDo:[
cg@2364
  2258
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2259
                lmost := (sel first) computeOrigin x.
cg@2364
  2260
cg@2364
  2261
                self transaction:#alignResizeLeft selectionDo:[:v|
cg@2364
  2262
                    (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[
cg@2364
  2263
                        self shiftLayout:v left:delta right:0
cg@2364
  2264
                    ]
cg@2364
  2265
                ]
cg@2364
  2266
            ] ifFalse:[
cg@2364
  2267
                self extentToFrame:#Left do:[:aLayout|
cg@2364
  2268
                    aLayout leftFraction:0.0 offset:0.
cg@2364
  2269
                ]
cg@2364
  2270
            ]
cg@2364
  2271
        ].
cg@2364
  2272
        self layoutChanged
cg@2364
  2273
    ]
cg@2364
  2274
!
cg@2364
  2275
cg@2364
  2276
alignResizeSelectionRight
cg@2364
  2277
    "align selection to the right of the first object in the selection; 
cg@2364
  2278
     in case of one selection the object is aligned to the right of its superview"
cg@2364
  2279
cg@2364
  2280
    |rmost delta sel|
cg@2364
  2281
cg@2364
  2282
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2283
        self withSelectionHiddenDo:[
cg@2364
  2284
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2285
                rmost := (sel first) computeCorner x.
cg@2364
  2286
cg@2364
  2287
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2288
                    (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[
cg@2364
  2289
                        self shiftLayout:v left:0 right:delta
cg@2364
  2290
                    ]
cg@2364
  2291
                ]
cg@2364
  2292
            ] ifFalse:[
cg@2364
  2293
                self extentToFrame:#Right do:[:aLayout|
cg@2364
  2294
                    aLayout rightOffset:0.
cg@2364
  2295
                    aLayout rightFraction:1.0.
cg@2364
  2296
                ]
cg@2364
  2297
            ]
cg@2364
  2298
        ].
cg@2364
  2299
        self layoutChanged
cg@2364
  2300
    ]
cg@2364
  2301
!
cg@2364
  2302
cg@60
  2303
alignSelectionBottom
ca@61
  2304
    "align selection to the bottom of the first object in the selection; in case
ca@61
  2305
     of one selection the object is aligned to the bottom of its superview
ca@61
  2306
    "
ca@128
  2307
    |bmost delta sel|
ca@128
  2308
ca@128
  2309
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2310
	self withSelectionHiddenDo:[
cg@1120
  2311
	    self numberOfSelections > 1 ifTrue:[
cg@1120
  2312
		bmost := (sel first) computeCorner y.
cg@1120
  2313
cg@1120
  2314
		self transaction:#alignBottom selectionDo:[:v|
cg@1120
  2315
		    (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[
cg@1120
  2316
			self shiftLayout:v top:delta bottom:delta.
cg@1120
  2317
		    ]
cg@1120
  2318
		]
cg@1120
  2319
	    ] ifFalse:[
cg@1120
  2320
		self extentToFrame:#Bottom do:[:aLayout|
cg@1120
  2321
		    aLayout bottomOffset:0.
cg@1120
  2322
		    aLayout bottomFraction:1.0
cg@1120
  2323
		]
cg@1120
  2324
	    ]
cg@1120
  2325
	].
cg@1120
  2326
	self layoutChanged
cg@60
  2327
    ]
cg@60
  2328
cg@60
  2329
cg@60
  2330
cg@60
  2331
!
cg@60
  2332
cg@60
  2333
alignSelectionCenterHor
ca@61
  2334
    "align selection to the center/horizontal of the first object in the selection; in case
ca@61
  2335
     of one selection the object is aligned to the center/horizontal of its superview
ca@61
  2336
    "
ca@128
  2337
    |view center sel|
ca@128
  2338
ca@128
  2339
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2340
	self withSelectionHiddenDo:[
cg@1120
  2341
	    view := self singleSelection.
cg@1120
  2342
cg@1120
  2343
	    view notNil ifTrue:[
ca@284
  2344
                
cg@1120
  2345
		view   := self findContainerOfView:view.
cg@1120
  2346
		center := view computeExtent
cg@1120
  2347
	    ] ifFalse:[
cg@1120
  2348
		view   := sel first.
cg@1120
  2349
		center := view computeCorner + view computeOrigin.
cg@1120
  2350
	    ].
cg@1120
  2351
	    center := center x // 2.
cg@1120
  2352
cg@1120
  2353
	    self transaction:#alignCenterHorizontal selectionDo:[:v|
cg@1120
  2354
		|newX oldX delta|
cg@1120
  2355
cg@1120
  2356
		oldX  := v computeOrigin x.
cg@1120
  2357
		newX  := center - ((v computeCorner x - oldX) // 2).
cg@1120
  2358
		delta := newX - oldX.
cg@1120
  2359
cg@1120
  2360
		self shiftLayout:v left:delta right:delta
cg@1120
  2361
	    ]
cg@1120
  2362
	].
cg@1120
  2363
	self layoutChanged
cg@60
  2364
    ]
cg@60
  2365
cg@60
  2366
cg@60
  2367
cg@60
  2368
!
cg@60
  2369
cg@60
  2370
alignSelectionCenterVer
ca@61
  2371
    "align selection to the center/vertical of the first object in the selection; in case
ca@61
  2372
     of one selection the object is aligned to the center/vertical of its superview
ca@61
  2373
    "
ca@128
  2374
    |view center sel|
ca@128
  2375
ca@128
  2376
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2377
	self withSelectionHiddenDo:[
cg@1120
  2378
	    view := self singleSelection.
cg@1120
  2379
cg@1120
  2380
	    view notNil ifTrue:[
cg@1120
  2381
		view   := self findContainerOfView:view.
cg@1120
  2382
		center := view computeExtent
cg@1120
  2383
	    ] ifFalse:[
cg@1120
  2384
		view   := sel first.
cg@1120
  2385
		center := view computeCorner + view computeOrigin.
cg@1120
  2386
	    ].
cg@1120
  2387
	    center := center y // 2.
cg@1120
  2388
cg@1120
  2389
	    self transaction:#alignCenterVertical selectionDo:[:v|
cg@1120
  2390
		|newY oldY delta|
cg@1120
  2391
cg@1120
  2392
		oldY  := v computeOrigin y.
cg@1120
  2393
		newY  := center - ((v computeCorner y - oldY) // 2).
cg@1120
  2394
		delta := newY - oldY.
cg@1120
  2395
cg@1120
  2396
		self shiftLayout:v top:delta bottom:delta
cg@1120
  2397
	    ]
cg@1120
  2398
	].
cg@1120
  2399
	self layoutChanged
cg@60
  2400
    ]
cg@60
  2401
!
cg@60
  2402
cg@60
  2403
alignSelectionLeft
cg@2364
  2404
    "align the selection with the left edge of the first object in the selection.
cg@2364
  2405
     in case of a single object selection, the object is moved to the left of its superview"
cg@2364
  2406
cg@2364
  2407
    |dominantLeft delta sel|
ca@128
  2408
ca@128
  2409
    (sel := self moveableSelection) notNil ifTrue:[
cg@1581
  2410
        self withSelectionHiddenDo:[
cg@2364
  2411
            dominantLeft := (sel first) computeOrigin x.
cg@1581
  2412
            self numberOfSelections > 1 ifTrue:[
cg@1581
  2413
                self transaction:#alignLeft selectionDo:[:v|
cg@2364
  2414
                    (delta := dominantLeft - (v computeOrigin x)) ~~ 0 ifTrue:[
cg@1581
  2415
                        self shiftLayout:v left:delta right:delta
cg@1581
  2416
                    ]
cg@1581
  2417
                ]
cg@1581
  2418
            ] ifFalse:[
cg@2364
  2419
                self transaction:#alignLeft selectionDo:[:v|
cg@2364
  2420
                    self shiftLayout:v left:dominantLeft negated right:dominantLeft negated
cg@2364
  2421
                ].
cg@1581
  2422
            ]
cg@1581
  2423
        ].
cg@1581
  2424
        self layoutChanged
cg@60
  2425
    ]
cg@60
  2426
!
cg@60
  2427
cg@60
  2428
alignSelectionLeftAndRight
ca@61
  2429
    "align selection to the left/right of the first object in the selection; in case
ca@61
  2430
     of one selection the object is aligned to the left/right of its superview
ca@61
  2431
    "
ca@128
  2432
    |lmost rmost sel|
ca@128
  2433
sv@2481
  2434
    (sel := self resizableSelection) notNil ifTrue:[
cg@1581
  2435
        self withSelectionHiddenDo:[
cg@1581
  2436
            self numberOfSelections > 1 ifTrue:[
cg@1581
  2437
                lmost := (sel first) computeOrigin x.
cg@1581
  2438
                rmost := (sel first) computeCorner x.
cg@1581
  2439
cg@1581
  2440
                self transaction:#alignLeftRight selectionDo:[:aView|
cg@1581
  2441
                    |layout|
sv@2481
  2442
sv@2481
  2443
                    aView superView isLayoutWrapper ifTrue:[
sv@2481
  2444
                        "change size only"
cg@1581
  2445
                        self createUndoLayout:aView.
sv@2481
  2446
                        aView width:sel first width.
sv@2481
  2447
                        self elementChangedSize:aView
sv@2481
  2448
                    ] ifFalse:[
sv@2481
  2449
                        layout := self class asLayoutFrameFromView:aView.
sv@2481
  2450
sv@2481
  2451
                        layout notNil ifTrue:[
sv@2481
  2452
                            self createUndoLayout:aView.
sv@2481
  2453
                            aView geometryLayout:layout.
sv@2481
  2454
sv@2481
  2455
                            undoHistory withoutTransactionDo:[
sv@2481
  2456
                                self shiftLayout:aView left:(lmost - (aView computeOrigin x))
sv@2481
  2457
                                                      right:(rmost - (aView computeCorner x)).
sv@2481
  2458
                            ].
sv@2481
  2459
                            self elementChangedSize:aView
cg@1581
  2460
                        ].
sv@2481
  2461
                    ].
cg@1581
  2462
                ]
cg@1581
  2463
            ] ifFalse:[
cg@1581
  2464
                self extentToFrame:#LeftRight do:[:aLayout|
cg@1581
  2465
                    aLayout leftFraction:0.0 offset:0.
cg@1581
  2466
                    aLayout rightFraction:1.0 offset:0.
cg@1581
  2467
                ]
cg@1581
  2468
            ]
cg@1581
  2469
        ].
cg@1581
  2470
        self layoutChanged
ca@61
  2471
    ].
ca@61
  2472
!
ca@61
  2473
ca@61
  2474
alignSelectionRight
ca@61
  2475
    "align selection to the right of the first object in the selection; in case
ca@61
  2476
     of one selection the object is aligned to the right of its superview
ca@61
  2477
    "
cg@2364
  2478
    |dominantRight delta sel|
ca@128
  2479
ca@128
  2480
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2481
        self withSelectionHiddenDo:[
cg@2364
  2482
            dominantRight := (sel first) computeCorner x.
cg@2364
  2483
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2484
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2485
                    (delta := dominantRight - (v computeCorner x)) ~~ 0 ifTrue:[
cg@2364
  2486
                        self shiftLayout:v left:delta right:delta
cg@2364
  2487
                    ]
cg@2364
  2488
                ]
cg@2364
  2489
            ] ifFalse:[
cg@2364
  2490
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2491
                    delta := v superView width - dominantRight.
cg@2364
  2492
                    self shiftLayout:v left:delta right:delta
cg@2364
  2493
                ]
cg@2364
  2494
"/                self extentToFrame:#Right do:[:aLayout|
cg@2364
  2495
"/                    aLayout rightOffset:0.
cg@2364
  2496
"/                    aLayout rightFraction:1.0.
cg@2364
  2497
"/                ]
cg@2364
  2498
            ]
cg@2364
  2499
        ].
cg@2364
  2500
        self layoutChanged
cg@60
  2501
    ]
cg@60
  2502
!
cg@60
  2503
cg@60
  2504
alignSelectionTop
ca@61
  2505
    "align selection to the top of the first object in the selection; in case
ca@61
  2506
     of one selection the object is aligned to the top of its superview
ca@61
  2507
    "
ca@128
  2508
    |tmost delta sel|
ca@128
  2509
ca@128
  2510
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2511
	self withSelectionHiddenDo:[
cg@1120
  2512
	    self numberOfSelections > 1 ifTrue:[
cg@1120
  2513
		tmost := (sel first) computeOrigin y.
cg@1120
  2514
cg@1120
  2515
		self transaction:#alignTop selectionDo:[:v|
cg@1120
  2516
		    (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[
cg@1120
  2517
			self shiftLayout:v top:delta bottom:delta
cg@1120
  2518
		    ]
cg@1120
  2519
		]
cg@1120
  2520
	    ] ifFalse:[
cg@1120
  2521
		self extentToFrame:#Top do:[:aLayout|
cg@1120
  2522
		    aLayout topOffset:0.
cg@1120
  2523
		    aLayout topFraction:0.0.
cg@1120
  2524
		]
cg@1120
  2525
	    ]
cg@1120
  2526
	].
cg@1120
  2527
	self layoutChanged
cg@60
  2528
    ]
cg@60
  2529
cg@60
  2530
!
cg@60
  2531
cg@60
  2532
alignSelectionTopAndBottom
ca@61
  2533
    "align selection to the top/bottom of the first object in the selection; in case
ca@61
  2534
     of one selection the object is aligned to the top/bottom of its superview
ca@61
  2535
    "
ca@128
  2536
    |tmost bmost sel|
ca@128
  2537
sv@2481
  2538
    (sel := self resizableSelection) notNil ifTrue:[
cg@1954
  2539
        self withSelectionHiddenDo:[
cg@1954
  2540
            self numberOfSelections > 1 ifTrue:[
cg@1954
  2541
                tmost := (sel first) computeOrigin y.
cg@1954
  2542
                bmost := (sel first) computeCorner y.
cg@1954
  2543
cg@1954
  2544
                self transaction:#alignTopBottom selectionDo:[:aView|
cg@1954
  2545
                    |layout|
sv@2481
  2546
                    aView superView isLayoutWrapper ifTrue:[
sv@2481
  2547
                        "change size only"
cg@1954
  2548
                        self createUndoLayout:aView.
sv@2481
  2549
                        aView height:sel first height.
sv@2481
  2550
                        self elementChangedSize:aView
sv@2481
  2551
                    ] ifFalse:[
sv@2481
  2552
                        layout := self class asLayoutFrameFromView:aView.
sv@2481
  2553
sv@2481
  2554
                        layout notNil ifTrue:[
sv@2481
  2555
                            self createUndoLayout:aView.
sv@2481
  2556
                            aView geometryLayout:layout.
sv@2481
  2557
sv@2481
  2558
                            undoHistory withoutTransactionDo:[
sv@2481
  2559
                                self shiftLayout:aView top:(tmost - (aView computeOrigin y))
sv@2481
  2560
                                                    bottom:(bmost - (aView computeCorner y)).
sv@2481
  2561
                            ].
sv@2481
  2562
                            self elementChangedSize:aView
cg@1954
  2563
                        ].
sv@2481
  2564
                    ].
cg@1954
  2565
                ]
cg@1954
  2566
            ] ifFalse:[
cg@1954
  2567
                self extentToFrame:#TopBottom do:[:aLayout|
cg@1954
  2568
                    aLayout topOffset:0.
cg@1954
  2569
                    aLayout topFraction:0.0.
cg@1954
  2570
                    aLayout bottomOffset:0.
cg@1954
  2571
                    aLayout bottomFraction:1.0.
cg@1954
  2572
                ]
cg@1954
  2573
            ]
cg@1954
  2574
        ].
cg@1954
  2575
        self layoutChanged
cg@60
  2576
    ]
cg@60
  2577
!
cg@60
  2578
cg@60
  2579
centerSelection:aOneArgBlockXorY orientation:orientation
cg@60
  2580
    "center selection horizontal or vertical dependant on the block result( x or y).
cg@60
  2581
     The argument to the block is the point.
cg@60
  2582
    "
cg@60
  2583
    |superview min max delta val|
cg@60
  2584
ca@128
  2585
    (self moveableSelection) isNil ifTrue:[
cg@1120
  2586
	^ self
ca@61
  2587
    ].
ca@61
  2588
ca@61
  2589
    self withSelectionHiddenDo:[
cg@1120
  2590
	max := 0.
cg@1120
  2591
cg@1120
  2592
	self selectionDo:[:aView |
cg@1120
  2593
	    superview isNil ifTrue:[
cg@1120
  2594
		superview := self findContainerOfView:aView
cg@1120
  2595
	    ] ifFalse:[
cg@1120
  2596
		(self findContainerOfView:aView) == superview ifFalse:[
cg@1120
  2597
		    ^ self notify:'views must have same superview'.
cg@1120
  2598
		]
cg@1120
  2599
	    ].
cg@1120
  2600
	    val := aOneArgBlockXorY value:(aView computeOrigin).    
cg@1120
  2601
cg@1120
  2602
	    min isNil ifTrue:[min := val]
cg@1120
  2603
		     ifFalse:[min := min min:val].
cg@1120
  2604
cg@1120
  2605
	    val := aOneArgBlockXorY value:(aView computeCorner).
cg@1120
  2606
	    max := max max:val.
cg@1120
  2607
	].
cg@1120
  2608
cg@1120
  2609
	val := aOneArgBlockXorY value:(superview computeExtent).
cg@1120
  2610
	max := (min + val - max) // 2.
cg@1120
  2611
cg@1120
  2612
	max == min ifFalse:[
cg@1120
  2613
	    |type|
cg@1120
  2614
	    (orientation == #y) ifTrue:[type := #centerVertical]
cg@1120
  2615
			       ifFalse:[type := #centerHorizontal].
cg@1120
  2616
	    delta := max - min.
cg@1120
  2617
cg@1120
  2618
	    self transaction:type selectionDo:[:v|
cg@1120
  2619
		orientation == #y ifTrue:[
cg@1120
  2620
		    self shiftLayout:v top:delta bottom:delta
cg@1120
  2621
		] ifFalse:[
cg@1120
  2622
		    self shiftLayout:v left:delta right:delta
cg@1120
  2623
		]
cg@1120
  2624
	    ]
cg@1120
  2625
	].
cg@1120
  2626
	self layoutChanged
cg@60
  2627
    ]
cg@60
  2628
cg@60
  2629
cg@60
  2630
!
cg@60
  2631
cg@60
  2632
centerSelectionHor
cg@60
  2633
    "center selection horizontal
cg@60
  2634
    "
cg@60
  2635
    self centerSelection:[:aPoint| aPoint x] orientation:#x
cg@60
  2636
cg@60
  2637
cg@60
  2638
!
cg@60
  2639
cg@60
  2640
centerSelectionVer
cg@60
  2641
    "center selection vertical
cg@60
  2642
    "
cg@60
  2643
    self centerSelection:[:aPoint| aPoint y] orientation:#y
cg@60
  2644
!
cg@60
  2645
ca@72
  2646
extentToFrame:toWhat do:aBlock
ca@72
  2647
    "align to frame (Left Right ...) and perform the block on a frameLayout
ca@72
  2648
    "
ca@72
  2649
    |layout type|
ca@72
  2650
ca@72
  2651
    type := ('extent', toWhat asString) asSymbol.
ca@72
  2652
ca@72
  2653
    self transaction:type selectionDo:[:aView|
cg@1120
  2654
	layout := self class asLayoutFrameFromView:aView.
cg@1120
  2655
cg@1120
  2656
	layout notNil ifTrue:[
cg@1120
  2657
	    self createUndoLayout:aView.
cg@1120
  2658
	    aBlock value:layout.
cg@1120
  2659
	    aView geometryLayout:layout.
cg@1120
  2660
	    self elementChangedSize:aView.
cg@1120
  2661
	]
ca@72
  2662
    ]
ca@72
  2663
!
ca@72
  2664
cg@60
  2665
spreadSelectionHor
ca@61
  2666
    "spread multiple selection horizontal
ca@61
  2667
    "
ca@128
  2668
    |sumWidths min max viewsInOrder topsInOrder count space sel|
ca@128
  2669
ca@128
  2670
    sel := self moveableSelection.
ca@128
  2671
ca@128
  2672
    (sel notNil and:[self numberOfSelections > 1]) ifFalse:[
cg@1120
  2673
	^ self
cg@60
  2674
    ].
cg@60
  2675
ca@61
  2676
    self withSelectionHiddenDo:[
cg@1120
  2677
	count := 0.
cg@1120
  2678
	sumWidths := 0.
cg@1120
  2679
	max := 0.
cg@1120
  2680
cg@1120
  2681
	self selectionDo:[:aView |
cg@1120
  2682
	    sumWidths := sumWidths + aView width.
cg@1120
  2683
cg@1120
  2684
	    min isNil ifTrue:[min := aView left]
cg@1120
  2685
		     ifFalse:[min := min min:(aView left)].
cg@1120
  2686
cg@1120
  2687
	    max := max max:(aView right).
cg@1120
  2688
	    count := count + 1
cg@1120
  2689
	].
cg@1120
  2690
	viewsInOrder := Array withAll:sel.
cg@1120
  2691
	topsInOrder  := viewsInOrder collect:[:aView | aView left].
cg@1120
  2692
	topsInOrder sortWith:viewsInOrder.
cg@1120
  2693
cg@1120
  2694
	space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger.
cg@1120
  2695
cg@1120
  2696
	self transaction:#spreadHorizontal objects:viewsInOrder do:[:aView|
cg@1120
  2697
	    |delta|
cg@1120
  2698
cg@1120
  2699
	    delta := min - aView computeOrigin x.
cg@1120
  2700
	    self shiftLayout:aView left:delta right:delta.
cg@1120
  2701
	    min := min + aView computeExtent x + space
cg@1120
  2702
	]
ca@61
  2703
    ].
ca@225
  2704
    self layoutChanged
cg@60
  2705
cg@60
  2706
!
cg@60
  2707
cg@60
  2708
spreadSelectionVer
ca@61
  2709
    "spread multiple selection vertical
ca@61
  2710
    "
ca@128
  2711
    |sumHeights min max viewsInOrder topsInOrder count space sel|
ca@128
  2712
ca@128
  2713
    sel := self moveableSelection.
ca@128
  2714
ca@128
  2715
    (sel notNil and:[self numberOfSelections > 1]) ifFalse:[
cg@1120
  2716
	^ self
cg@60
  2717
    ].
cg@60
  2718
ca@61
  2719
    self withSelectionHiddenDo:[
cg@1120
  2720
	count := 0.
cg@1120
  2721
	sumHeights := 0.
cg@1120
  2722
	max := 0.
cg@1120
  2723
cg@1120
  2724
	self selectionDo:[:aView |
cg@1120
  2725
	    sumHeights := sumHeights + aView height.
cg@1120
  2726
cg@1120
  2727
	    min isNil ifTrue:[min := aView top]
cg@1120
  2728
		     ifFalse:[min := min min:(aView top)].
cg@1120
  2729
cg@1120
  2730
	    max   := max max:(aView bottom).
cg@1120
  2731
	    count := count + 1
cg@1120
  2732
	].
cg@1120
  2733
	viewsInOrder := Array withAll:sel.
cg@1120
  2734
	topsInOrder  := viewsInOrder collect:[:aView|aView top].
cg@1120
  2735
	topsInOrder sortWith:viewsInOrder.
cg@1120
  2736
cg@1120
  2737
	space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger.
cg@1120
  2738
cg@1120
  2739
	self transaction:#spreadVertical objects:viewsInOrder do:[:aView|
cg@1120
  2740
	    |delta|
cg@1120
  2741
cg@1120
  2742
	    delta := min - aView computeOrigin y.
cg@1120
  2743
	    self shiftLayout:aView top:delta bottom:delta.
cg@1120
  2744
	    min := min + aView height + space
cg@1120
  2745
	]
ca@61
  2746
    ].
ca@225
  2747
    self layoutChanged
cg@60
  2748
! !
cg@60
  2749
cg@1715
  2750
!UIObjectView methodsFor:'user actions-undo history'!
cg@60
  2751
ca@72
  2752
enableUndoHistory:aState
cg@1954
  2753
    "enable or disable undo history"
cg@1954
  2754
ca@72
  2755
    undoHistory enabled:aState
ca@72
  2756
!
ca@72
  2757
cg@60
  2758
openUndoMenu
ca@149
  2759
    self select:nil.
ca@138
  2760
    undoHistory openUndoMenu
cg@60
  2761
!
cg@60
  2762
cg@60
  2763
removeUndoHistory
cg@1954
  2764
    "delete total undo history"
cg@1954
  2765
cg@1954
  2766
    undoHistory initializeFor:self.
cg@1954
  2767
    self undoHistoryChanged
cg@60
  2768
!
cg@60
  2769
cg@60
  2770
undoLast
cg@1954
  2771
    "undo last action"
cg@1954
  2772
ca@138
  2773
    |newSel oldSel|
ca@138
  2774
cg@1954
  2775
    undoHistory notEmpty ifTrue:[
cg@1954
  2776
        self hasSelection ifTrue:[
cg@1954
  2777
            oldSel := OrderedCollection new.
cg@1954
  2778
            newSel := OrderedCollection new.
cg@1954
  2779
cg@1954
  2780
            self selectionDo:[:aView||p|
cg@1954
  2781
                (p := self propertyOfView:aView) notNil ifTrue:[
cg@1954
  2782
                    oldSel add:(p identifier)
cg@1954
  2783
                ]
cg@1954
  2784
            ].
cg@1954
  2785
            self setSelection:nil withRedraw:true.
cg@1954
  2786
        ].
cg@1954
  2787
cg@1954
  2788
        self withSelectionHiddenDo:[undoHistory undoLast:1].
cg@1954
  2789
cg@1954
  2790
        oldSel notNil ifTrue:[
cg@1954
  2791
            oldSel do:[:id||v|
cg@1954
  2792
                (v := self findViewWithId:id) notNil ifTrue:[newSel add:v]
cg@1954
  2793
            ].
cg@1954
  2794
            self select:newSel.
cg@1954
  2795
        ].
cg@1954
  2796
        self undoHistoryChanged.
ca@61
  2797
    ].
cg@60
  2798
! !
cg@60
  2799
ca@1672
  2800
!UIObjectView::PostEventHandler methodsFor:'event handling'!
ca@1672
  2801
ca@1672
  2802
processEvent:anEvent
ca@1672
  2803
    |evView|
ca@1672
  2804
ca@1672
  2805
    anEvent isDamage ifTrue:[
ca@1672
  2806
        onView testMode ifFalse:[
ca@1672
  2807
            evView := anEvent view.
ca@1672
  2808
ca@1672
  2809
            (onView isSelected:evView) ifTrue:[
ca@1672
  2810
                onView showSelected:evView.
ca@1672
  2811
            ]
ca@1672
  2812
        ]
ca@1672
  2813
    ].
ca@1672
  2814
    ^ false
ca@1672
  2815
! !
ca@1672
  2816
ca@1672
  2817
!UIObjectView::PostEventHandler methodsFor:'instance creation'!
ca@1672
  2818
ca@1672
  2819
onView:aView
ca@1672
  2820
    onView := aView.
ca@1672
  2821
! !
ca@1672
  2822
ca@1437
  2823
!UIObjectView::ResizeData methodsFor:'accessing'!
ca@1437
  2824
cg@2536
  2825
checkForChangeSelector
cg@2536
  2826
    ^ checkForChangeSelector
cg@2536
  2827
!
cg@2536
  2828
ca@1437
  2829
delta
ca@1437
  2830
    ^ delta
ca@1437
  2831
ca@1437
  2832
    "Created: / 2.2.1998 / 13:40:32 / cg"
ca@1437
  2833
!
ca@1437
  2834
ca@1437
  2835
object
ca@1437
  2836
    ^ object
ca@1437
  2837
ca@1437
  2838
    "Created: / 2.2.1998 / 13:40:24 / cg"
ca@1437
  2839
!
ca@1437
  2840
cg@2536
  2841
object:anObject selector:selectorArg checkForChangeSelector:checkForChangeSelectorArg delta:anInteger
cg@2536
  2842
    object := anObject.
cg@2536
  2843
    selector := selectorArg.
cg@2536
  2844
    checkForChangeSelector := checkForChangeSelectorArg.