UIObjectView.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2849 e061cea3416f
child 3011 ceaec66469ff
permissions -rw-r--r--
category of:15 methods
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@2849
   845
        org notNil ifTrue:[
cg@2849
   846
            delta := aPoint - org.
cg@2849
   847
            delta := (self alignToGrid:aPoint) - org.
cg@2849
   848
            dX := delta x.
cg@2849
   849
            dY := delta y.
cg@2849
   850
cg@2849
   851
            undoHistory withoutTransactionDo:[
cg@2849
   852
                self shiftLayout:anObject horizontal:dX vertical:dY
cg@2849
   853
            ]
cg@1954
   854
        ]
cg@60
   855
    ]
cg@2849
   856
cg@2849
   857
    "Modified: / 25-07-2011 / 17:27:08 / cg"
cg@60
   858
!
cg@60
   859
cg@60
   860
startObjectMoveAt:aPoint
cg@2501
   861
    "start object(s) move at a point"
cg@2501
   862
ca@128
   863
    self startObjectMove:(self selection) at:aPoint.
ca@128
   864
    movedObject := self selection.
ca@128
   865
ca@128
   866
    movedObject isCollection ifFalse:[
ca@1451
   867
        movedObject := Array with:movedObject
cg@60
   868
    ].
cg@2501
   869
"/    self setSelection:nil withRedraw:true.
cg@2501
   870
cg@2501
   871
    moveDelta := movedObject collect:[:aView | aPoint - aView computeOrigin].
cg@2501
   872
ca@175
   873
    self transaction:#move objects:movedObject do:[:v|self createUndoLayout:v].
ca@175
   874
    self invertOutlineOf:movedObject.
cg@60
   875
!
cg@60
   876
cg@60
   877
startSelectMoreOrMove:aPoint
cg@60
   878
    "add/remove to/from selection"
cg@60
   879
cg@60
   880
    |anObject|
cg@60
   881
ca@119
   882
    self enabled ifFalse:[^ self].
cg@60
   883
cg@60
   884
    anObject := self findObjectAt:aPoint.
cg@60
   885
    anObject notNil ifTrue:[
cg@1120
   886
	(self isSelected:anObject) ifTrue:[
cg@1120
   887
	    self removeFromSelection:anObject
cg@1120
   888
	] ifFalse:[
cg@1120
   889
	    self addToSelection:anObject
cg@1120
   890
	]
cg@60
   891
    ]
cg@60
   892
!
cg@60
   893
cg@60
   894
startSelectOrMove:aPoint
cg@2356
   895
    "a button is pressed at a point; start moving or selecting"
cg@2356
   896
cg@2356
   897
    |selectedView containerOfSelectedView
cg@2501
   898
     clickedView viewOperatedUpon borderHandleSelector pView|
cg@60
   899
ca@119
   900
    self enabled ifFalse:[^ self].
cg@60
   901
cg@2356
   902
    selectedView := self singleSelection.
cg@2364
   903
cg@2364
   904
"/    clickedView := self findObjectAt:aPoint.
cg@2364
   905
"/    (clickedView notNil 
cg@2364
   906
"/    and:[clickedView isComponentOf:selectedView]) ifTrue:[
cg@2364
   907
"/        self unselect.
cg@2364
   908
"/        selectedView := nil.    
cg@2364
   909
"/    ].
cg@60
   910
cg@2501
   911
    "/ if there is already a selection, see if user clicked onto a handle
cg@2501
   912
    "/ then, this may be the start of a resize operation.
cg@2356
   913
    selectedView notNil ifTrue:[
cg@2356
   914
        containerOfSelectedView := self findContainerOfView:selectedView.
cg@2356
   915
cg@2356
   916
        containerOfSelectedView specClass canResizeSubComponents ifTrue:[
cg@2501
   917
            borderHandleSelector := self whichHandleOf:selectedView isHitBy:aPoint.
cg@2501
   918
            (borderHandleSelector notNil and:[borderHandleSelector ~~ #view]) ifTrue:[
cg@2501
   919
                self startResizeBorder:borderHandleSelector.
cg@2356
   920
                ^ self
cg@2356
   921
            ]
cg@2356
   922
        ].
cg@2356
   923
        viewOperatedUpon := selectedView.
cg@2356
   924
cg@2356
   925
        pView := device translatePoint:aPoint fromView:self toView:selectedView superView.
cg@2356
   926
        (selectedView bounds containsPoint:pView) ifFalse:[
cg@2356
   927
            "/ clicked outside the selection
cg@2356
   928
            (self sensor ctrlDown and:[self canChangeLayoutOfView:selectedView]) ifFalse:[
cg@2356
   929
                viewOperatedUpon := nil
cg@2356
   930
            ]
cg@2356
   931
        ]
ca@61
   932
    ].
ca@61
   933
cg@2364
   934
    clickedView := self findObjectAt:aPoint.
cg@2368
   935
    clickedView notNil ifTrue:[
cg@2368
   936
        (clickedView isComponentOf:selectedView) ifTrue:[
cg@2530
   937
            "/ self unselect.
cg@2368
   938
            selectedView := nil.    
cg@2368
   939
            viewOperatedUpon := nil
cg@2368
   940
        ] ifFalse:[
cg@2530
   941
            "/ self unselect.
cg@2368
   942
            selectedView := nil.    
cg@2368
   943
            viewOperatedUpon := clickedView
cg@2368
   944
        ].
cg@2364
   945
    ].
cg@2364
   946
cg@2356
   947
    viewOperatedUpon isNil ifTrue:[
cg@2356
   948
        clickedView isNil ifTrue:[
cg@2538
   949
            "/ clicked outside - start a rectangle drag.
cg@2356
   950
            self select:nil.
cg@2538
   951
            self startRectangleDrag:aPoint.
cg@2356
   952
            ^ self.
cg@2356
   953
        ].
cg@2356
   954
cg@2356
   955
        (self canChangeLayoutOfView:clickedView) ifFalse:[
cg@2356
   956
            self select:clickedView.
cg@2356
   957
            ^ self
cg@2356
   958
        ].
cg@2356
   959
        viewOperatedUpon := clickedView
cg@60
   960
    ].
cg@60
   961
cg@2356
   962
    (self isSelected:viewOperatedUpon) ifFalse:[
cg@2356
   963
        self select:viewOperatedUpon.
cg@2356
   964
    ].
cg@2356
   965
cg@60
   966
    (self numberOfSelections ~~ 1) ifTrue:[
cg@2356
   967
        releaseAction := 
cg@2356
   968
            [
cg@2356
   969
                self setDefaultActions.
cg@2356
   970
                self select:viewOperatedUpon
cg@2356
   971
            ]
cg@60
   972
    ] ifFalse:[
cg@2356
   973
        releaseAction := [self setDefaultActions]
cg@60
   974
    ].
cg@60
   975
cg@2356
   976
    "prepare move operation for an object"
cg@2356
   977
    motionAction := 
cg@2356
   978
        [:movePoint|
cg@2356
   979
            (aPoint dist:movePoint) > 4.0 ifTrue:[
cg@2356
   980
                self startObjectMoveAt:aPoint
cg@2356
   981
            ]
cg@2356
   982
        ].
cg@60
   983
! !
cg@60
   984
cg@60
   985
!UIObjectView methodsFor:'object resize'!
cg@60
   986
cg@60
   987
actionResize:anObject selector:aSelector
cg@2536
   988
    "create and initialize action for resize"
cg@2536
   989
cg@2536
   990
    |delta|
cg@60
   991
cg@60
   992
    delta    := anObject container originRelativeTo:self.
cg@543
   993
    resizeData := ResizeData new
cg@2536
   994
                        object:anObject 
cg@2536
   995
                        selector:aSelector
cg@2536
   996
                        delta:delta.
cg@60
   997
cg@60
   998
"can change cursor dependent on vertical/horizontal resizing
cg@60
   999
"
cg@60
  1000
    oldCursor := cursor.
cg@60
  1001
    self cursor:(Cursor leftHand).
cg@60
  1002
cg@543
  1003
    "Modified: / 2.2.1998 / 13:40:55 / cg"
cg@60
  1004
!
cg@60
  1005
cg@60
  1006
doDragResize:aPoint
cg@2536
  1007
    "do a widget resize drag"
cg@2536
  1008
cg@60
  1009
    |p object|
cg@60
  1010
ca@175
  1011
    object := resizeData object.
cg@2536
  1012
    p := (self alignToGrid:aPoint) - (resizeData delta).
cg@2536
  1013
cg@2536
  1014
    (self resize:object handle:(resizeData selector) to:p check:true) ifFalse:[
cg@2536
  1015
        ^ self  "/ no real change (due to align)
cg@2536
  1016
    ].
cg@60
  1017
cg@2514
  1018
    self hideSelection.
cg@2514
  1019
cg@60
  1020
    self invertOutlineOf:object.
cg@2536
  1021
cg@2536
  1022
    self resize:object handle:(resizeData selector) to:p check:false.
cg@2536
  1023
ca@1451
  1024
    Delay waitForSeconds:0.05.
ca@1451
  1025
    [self sensor hasExposeEventFor:nil] whileTrue:[
ca@1451
  1026
        self windowGroup processExposeEvents
ca@1451
  1027
    ].
ca@1451
  1028
ca@79
  1029
   "/ object geometryLayout:(object geometryLayout).
cg@2501
  1030
    self invertOutlineOf:object.
cg@2501
  1031
cg@2514
  1032
    self showSelection.
cg@60
  1033
!
cg@60
  1034
cg@60
  1035
endResize
cg@2536
  1036
    "cleanup after object resize"
cg@2536
  1037
cg@2536
  1038
    |object savedSelection anyLayoutWrapper anyTransparentBox|
ca@61
  1039
ca@175
  1040
    object := resizeData object.
ca@175
  1041
    resizeData := nil.
ca@61
  1042
cg@2536
  1043
    "/ container objects might want to rearrange their elements after a size change;
cg@2536
  1044
    "/ therefore, we hide the handles while this is possibly done.
cg@2536
  1045
    "/ however, to avoid flicker, we check for containers first.
cg@2536
  1046
    anyLayoutWrapper := anyTransparentBox := false.
cg@2536
  1047
    self forEach:object do:[:aViewOrComponent | 
cg@2536
  1048
        aViewOrComponent isLayoutWrapper ifTrue:[ anyLayoutWrapper := true ].
cg@2536
  1049
        aViewOrComponent isTransparentBox ifTrue:[ anyTransparentBox := true ].
cg@2536
  1050
    ].
cg@2536
  1051
cg@2536
  1052
    (anyLayoutWrapper or:[anyTransparentBox]) ifTrue:[
cg@2536
  1053
cg@2536
  1054
        self invertOutlineOf:object.
cg@2536
  1055
cg@2536
  1056
        "/ temporarily hide the selection, in order to allow the container to move the
cg@2536
  1057
        "/ element around...
cg@2536
  1058
        savedSelection := selection.
cg@2536
  1059
        self setSelection:nil withRedraw:true.
cg@2536
  1060
cg@2536
  1061
        "/ handle any expose events (for subcomponents) before
cg@2536
  1062
        "/ redrawing the handles.
cg@2536
  1063
        self windowGroup processExposeEvents.
cg@2536
  1064
cg@2536
  1065
        self elementChangedSize:object.
cg@2536
  1066
cg@2536
  1067
        "/ handle any expose events (for subcomponents) before
cg@2536
  1068
        "/ redrawing the handles.
cg@2536
  1069
        Delay waitForSeconds:0.05.
cg@2536
  1070
        [self sensor hasExposeEventFor:nil] whileTrue:[
cg@2536
  1071
            self windowGroup processExposeEvents
cg@2536
  1072
        ].
cg@2536
  1073
cg@2536
  1074
        self forEach:savedSelection do:[:aView |
cg@2536
  1075
            self recomputeShapeIfTransparentBox:aView.
cg@2536
  1076
        ].
cg@2536
  1077
cg@2536
  1078
        self setSelection:object withRedraw:true.
cg@2536
  1079
    ].
cg@2536
  1080
cg@2536
  1081
    self layoutChanged.
cg@60
  1082
    self setDefaultActions.
cg@2536
  1083
!
cg@2536
  1084
cg@2536
  1085
layoutChanged
cg@2536
  1086
!
cg@2536
  1087
cg@2536
  1088
resize:aView bottom:aPoint
cg@2536
  1089
    "obsolete: resize a views bottom"
cg@2536
  1090
cg@2536
  1091
    self resize:aView handle:#bottom to:aPoint check:false.
cg@2536
  1092
"/    undoHistory withoutTransactionDo:[
cg@2536
  1093
"/        self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
cg@2536
  1094
"/    ].
cg@2536
  1095
!
cg@2536
  1096
cg@2536
  1097
resize:aView bottomLeft:aPoint
cg@2536
  1098
    "obsolete: resize a views bottom and left"
cg@2536
  1099
cg@2536
  1100
    self resize:aView handle:#bottomLeft to:aPoint check:false.
cg@2536
  1101
"/    undoHistory withoutTransactionDo:[
cg@2536
  1102
"/        self shiftLayout:aView top:0
cg@2536
  1103
"/                            bottom:((aPoint y) - (aView computeCorner y))
cg@2536
  1104
"/                              left:((aPoint x) - (aView computeOrigin x))
cg@2536
  1105
"/                             right:0
cg@2536
  1106
"/
cg@2536
  1107
"/    ]
cg@2536
  1108
!
cg@2536
  1109
cg@2536
  1110
resize:aView corner:aPoint
cg@2536
  1111
    "obsolete: resize a views corner"
cg@2536
  1112
cg@2536
  1113
    self resize:aView handle:#corner to:aPoint check:false.
cg@2536
  1114
"/    |delta|
cg@2536
  1115
"/
cg@2536
  1116
"/    delta := aPoint - aView computeCorner.
cg@2536
  1117
"/    undoHistory withoutTransactionDo:[
cg@2536
  1118
"/        self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
cg@2536
  1119
"/    ]
cg@2536
  1120
!
cg@2536
  1121
cg@2536
  1122
resize:aComponent endPoint:newEndPoint
cg@2536
  1123
    "obsolete: move a component's endPoint"
cg@2536
  1124
cg@2536
  1125
    self resize:aComponent handle:#endPoint to:newEndPoint check:false
cg@2536
  1126
cg@2536
  1127
"/    undoHistory 
cg@2536
  1128
"/        withoutTransactionDo:[
cg@2536
  1129
"/            self shiftLayout:aComponent startPoint:0 endPoint:(newEndPoint - (aComponent endPoint))
cg@2536
  1130
"/        ]
cg@2536
  1131
!
cg@2536
  1132
cg@2536
  1133
resize:aComponent handle:aSymbol to:aPoint check:doCheck
cg@2536
  1134
    "resize a views handle - if doCheck is true, only check if the handle would change
cg@2536
  1135
     (used to avoid flicker, when an aligned move would actually not move anything)"
cg@2536
  1136
cg@2536
  1137
    |newX newY oldBottom oldTop oldLeft oldRight 
cg@2536
  1138
     oldOrigin oldCorner shiftTop shiftBottom shiftLeft shiftRight|
cg@2536
  1139
cg@2536
  1140
    aSymbol == #startPoint ifTrue:[
cg@2536
  1141
        doCheck ifTrue:[
cg@2536
  1142
            ^ aPoint ~= (aComponent startPoint)
cg@2536
  1143
        ].
cg@2536
  1144
        self 
cg@2536
  1145
            shiftLayout:aComponent 
cg@2536
  1146
            startPoint:(aPoint - (aComponent startPoint)) endPoint:0.
cg@2536
  1147
        ^ self.
ca@138
  1148
    ].
cg@2536
  1149
    aSymbol == #endPoint ifTrue:[
cg@2536
  1150
        doCheck ifTrue:[
cg@2536
  1151
            ^ aPoint ~= (aComponent endPoint)
cg@2536
  1152
        ].
cg@2536
  1153
        self 
cg@2536
  1154
            shiftLayout:aComponent 
cg@2536
  1155
            startPoint:0 endPoint:(aPoint - (aComponent endPoint)).
cg@2536
  1156
        ^ self.
werner@1827
  1157
    ].
cg@2536
  1158
cg@2536
  1159
    newX := aPoint x.
cg@2536
  1160
    newY := aPoint y.
cg@2536
  1161
    shiftTop := shiftBottom := shiftLeft := shiftRight := 0.
cg@2536
  1162
cg@2536
  1163
    oldOrigin := aComponent computeOrigin.
cg@2536
  1164
    oldCorner := aComponent computeCorner.
cg@2536
  1165
cg@2536
  1166
    oldTop := oldOrigin y.
cg@2536
  1167
    oldBottom := oldCorner y.
cg@2536
  1168
    oldLeft := oldOrigin x.
cg@2536
  1169
    oldRight := oldCorner x.
cg@2536
  1170
cg@2536
  1171
    aSymbol == #bottom ifTrue:[
cg@2536
  1172
        shiftBottom := newY - oldBottom.
cg@2536
  1173
    ]. 
cg@2536
  1174
    aSymbol == #top ifTrue:[     
cg@2536
  1175
        shiftTop := newY - oldTop.
cg@2536
  1176
    ].
cg@2536
  1177
    aSymbol == #left ifTrue:[
cg@2536
  1178
        shiftLeft := newX - oldLeft.
cg@2536
  1179
    ].
cg@2536
  1180
    aSymbol == #right ifTrue:[
cg@2536
  1181
        shiftRight := newX - oldRight.
cg@2536
  1182
    ].
cg@2536
  1183
    aSymbol == #origin ifTrue:[
cg@2536
  1184
        shiftLeft := newX - oldLeft.
cg@2536
  1185
        shiftTop := newY - oldTop.
cg@2536
  1186
    ].
cg@2536
  1187
    aSymbol == #topRight ifTrue:[
cg@2536
  1188
        shiftRight := newX - oldRight.
cg@2536
  1189
        shiftTop := newY - oldTop.
cg@2536
  1190
    ].
cg@2536
  1191
    aSymbol == #corner ifTrue:[
cg@2536
  1192
        shiftRight := newX - oldRight.
cg@2536
  1193
        shiftBottom := newY - oldBottom.
cg@2536
  1194
    ].
cg@2536
  1195
    aSymbol == #bottomLeft ifTrue:[
cg@2536
  1196
        shiftLeft := newX - oldLeft.
cg@2536
  1197
        shiftBottom := newY - oldBottom.
cg@2536
  1198
    ].
cg@2536
  1199
cg@2536
  1200
    doCheck ifTrue:[
cg@2536
  1201
        ^ (shiftTop ~= 0) or:[ shiftBottom ~= 0 or:[ shiftLeft ~= 0 or:[ shiftRight ~= 0 ]]]
cg@2536
  1202
    ].
cg@2536
  1203
cg@2536
  1204
    undoHistory withoutTransactionDo:[
cg@2536
  1205
        self 
cg@2536
  1206
            shiftLayout:aComponent 
cg@2536
  1207
            top:shiftTop bottom:shiftBottom 
cg@2536
  1208
            left:shiftLeft right:shiftRight
cg@2536
  1209
    ].
cg@60
  1210
!
cg@60
  1211
cg@2536
  1212
resize:aView left:aPoint
cg@2536
  1213
    "obsolete: resize a views left"
cg@2536
  1214
cg@2536
  1215
    self resize:aView handle:#left to:aPoint check:false.
cg@2536
  1216
"/    undoHistory withoutTransactionDo:[
cg@2536
  1217
"/        self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
cg@2536
  1218
"/    ]
cg@2536
  1219
!
cg@2536
  1220
cg@2536
  1221
resize:aView origin:aPoint
cg@2536
  1222
    "obsolete: resize a views origin"
cg@2536
  1223
cg@2536
  1224
    self resize:aView handle:#origin to:aPoint check:false.
cg@2536
  1225
"/    |delta|
cg@2536
  1226
"/
cg@2536
  1227
"/    delta := aPoint - aView computeOrigin.
cg@2536
  1228
"/    undoHistory withoutTransactionDo:[
cg@2536
  1229
"/        self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
cg@2536
  1230
"/    ]
cg@2536
  1231
!
cg@2536
  1232
cg@2536
  1233
resize:aView right:aPoint
cg@2536
  1234
    "obsolete: resize a views right"
cg@2536
  1235
cg@2536
  1236
    self resize:aView handle:#right to:aPoint check:false.
cg@2536
  1237
"/    undoHistory withoutTransactionDo:[
cg@2536
  1238
"/        self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
cg@2536
  1239
"/    ]
cg@2536
  1240
!
cg@2536
  1241
cg@2536
  1242
resize:aComponent startPoint:newStartPoint
cg@2536
  1243
    "obsolete: move a component's startPoint"
cg@2536
  1244
cg@2536
  1245
    self resize:aComponent handle:#startPoint to:newStartPoint check:false
cg@2536
  1246
"/    undoHistory 
cg@2536
  1247
"/        withoutTransactionDo:[
cg@2536
  1248
"/            self shiftLayout:aComponent startPoint:(newStartPoint - (aComponent startPoint)) endPoint:0
cg@2536
  1249
"/        ]
cg@2536
  1250
!
cg@2536
  1251
cg@2536
  1252
resize:aView top:aPoint
cg@2536
  1253
    "obsolete: resize a views top"
cg@2536
  1254
cg@2536
  1255
    self resize:aView handle:#top to:aPoint check:false.
cg@2536
  1256
"/    undoHistory withoutTransactionDo:[
cg@2536
  1257
"/        self shiftLayout:aView 
cg@2536
  1258
"/                top:((aPoint y) - (aView computeOrigin y)) 
cg@2536
  1259
"/                bottom:0
cg@2536
  1260
"/    ]
cg@2536
  1261
!
cg@2536
  1262
cg@2536
  1263
resize:aView topRight:aPoint
cg@2536
  1264
    "obsolete: resize a views top and right"
cg@2536
  1265
cg@2536
  1266
    self resize:aView handle:#topRight to:aPoint check:false.
cg@2536
  1267
"/    undoHistory withoutTransactionDo:[
cg@2536
  1268
"/        self shiftLayout:aView 
cg@2536
  1269
"/                top:((aPoint y) - (aView computeOrigin y))
cg@2536
  1270
"/                bottom:0
cg@2536
  1271
"/                left:0
cg@2536
  1272
"/                right:((aPoint x) - (aView computeCorner x))
cg@2536
  1273
"/    ]
werner@1827
  1274
!
werner@1827
  1275
cg@2501
  1276
startResizeBorder:borderHandleSelector
cg@2501
  1277
    "start resizing the selected view at the given borderHandle"
cg@2501
  1278
cg@60
  1279
    |object|
cg@60
  1280
cg@60
  1281
    object := self singleSelection.
cg@2501
  1282
    self actionResize:object selector:borderHandleSelector.
cg@2501
  1283
cg@2501
  1284
    self 
cg@2501
  1285
        transaction:#resize 
cg@2501
  1286
        selectionDo:[:aView|
cg@2501
  1287
            self createUndoLayout:aView
cg@2501
  1288
        ].
cg@2501
  1289
    "/ self setSelection:nil withRedraw:true.
cg@60
  1290
cg@60
  1291
    motionAction  := [:movePoint | self doDragResize:movePoint].
cg@60
  1292
    releaseAction := [self endResize].
cg@2501
  1293
cg@60
  1294
    self invertOutlineOf:object
cg@60
  1295
! !
cg@60
  1296
cg@1954
  1297
!UIObjectView methodsFor:'private'!
cg@1954
  1298
cg@1954
  1299
undoHistoryChanged
cg@1954
  1300
    self hasUndoHistoryHolder value:(self hasUndoHistory).
cg@1954
  1301
! !
cg@1954
  1302
cg@1714
  1303
!UIObjectView methodsFor:'private-handles'!
cg@60
  1304
ca@175
  1305
handlesOf:aComponent do:aTwoArgAction
cg@2510
  1306
    "perform aTwoArgAction on each handle of a component"
cg@2510
  1307
ca@175
  1308
    |dlt ext|
ca@175
  1309
ca@175
  1310
    dlt := (aComponent originRelativeTo:self) - aComponent origin.
ca@1451
  1311
    dlt := dlt - (4@4).
ca@1451
  1312
    ext := 8@8.
ca@175
  1313
cg@2510
  1314
    self class 
cg@2510
  1315
        handlesOf:aComponent 
cg@2510
  1316
        do:[:pnt :wht |
cg@2510
  1317
            aTwoArgAction value:(pnt + dlt extent:ext) value:wht
cg@2510
  1318
        ]
cg@60
  1319
!
cg@60
  1320
ca@175
  1321
whichHandleOf:aComponent isHitBy:aPoint
cg@2501
  1322
    "returns kind of handle or nil"
cg@2501
  1323
ca@175
  1324
    self handlesOf:aComponent do:[:rectangle :what|
cg@2501
  1325
        (rectangle containsPoint:aPoint) ifTrue:[^ what]
cg@60
  1326
    ].
cg@2501
  1327
    ^ nil
cg@60
  1328
! !
cg@60
  1329
cg@1714
  1330
!UIObjectView methodsFor:'private-resizing subviews'!
cg@60
  1331
werner@1827
  1332
recomputeShapeIfTransparentBox:aView
werner@1829
  1333
    (aView notNil and:[aView isTransparentBox]) ifTrue:[
werner@1827
  1334
        aView computeShape.
werner@1827
  1335
        aView clear; redraw
werner@1827
  1336
    ].
cg@60
  1337
! !
cg@60
  1338
cg@1714
  1339
!UIObjectView methodsFor:'private-shift layout'!
cg@60
  1340
cg@2510
  1341
shiftLayout:aViewOrComponent horizontal:n
cg@2510
  1342
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1343
cg@2514
  1344
    self shiftLayout:aViewOrComponent horizontal:n vertical:0
cg@2514
  1345
!
cg@2514
  1346
cg@2514
  1347
shiftLayout:aViewOrComponent horizontal:h vertical:v
cg@2514
  1348
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2514
  1349
cg@2514
  1350
    (self specFor:aViewOrComponent) hasLayout ifTrue:[
cg@2514
  1351
        self shiftLayout:aViewOrComponent top:v bottom:v left:h right:h
cg@2510
  1352
    ] ifFalse:[
cg@2514
  1353
        self shiftLayout:aViewOrComponent startPoint:(h @ v) endPoint:(h @ v)
cg@2514
  1354
    ].
cg@2510
  1355
!
cg@2510
  1356
cg@60
  1357
shiftLayout:aView left:l right:r
cg@2510
  1358
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1359
cg@60
  1360
    self shiftLayout:aView top:0 bottom:0 left:l right:r
cg@60
  1361
!
cg@60
  1362
cg@2510
  1363
shiftLayout:aComponent startPoint:deltaS endPoint:deltaE
cg@2510
  1364
    "shift coordinates; in case of an open transaction, the undo action is registered"
cg@2510
  1365
cg@2510
  1366
    self createUndoStartPointEndPoint:aComponent.
cg@2510
  1367
    aComponent 
cg@2510
  1368
        startPoint:(aComponent startPoint + deltaS)
cg@2510
  1369
        endPoint:(aComponent endPoint + deltaE).
cg@2510
  1370
!
cg@2510
  1371
cg@60
  1372
shiftLayout:aView top:t bottom:b
cg@2510
  1373
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1374
cg@60
  1375
    self shiftLayout:aView top:t bottom:b left:0 right:0
cg@60
  1376
!
cg@60
  1377
cg@60
  1378
shiftLayout:aView top:t bottom:b left:l right:r
cg@2510
  1379
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1380
cg@2536
  1381
    |type layout oldExt dX dY|
ca@61
  1382
ca@61
  1383
    type := self class layoutType:aView.
cg@2536
  1384
    type isNil ifTrue:[ ^ self ].
cg@2536
  1385
cg@2536
  1386
    self createUndoLayout:aView.
cg@2536
  1387
cg@2536
  1388
    type == #Extent ifTrue:[
cg@2536
  1389
        oldExt := aView extent.
cg@2536
  1390
        dX := r-l.
cg@2536
  1391
        dY := b-t.
cg@2536
  1392
        aView extent:(oldExt + (dX @ dY)).
cg@2536
  1393
        ^ self 
cg@2536
  1394
    ].
cg@2536
  1395
cg@2536
  1396
    layout := aView geometryLayout copy.
cg@2536
  1397
    layout isLayout ifTrue:[
cg@2536
  1398
        layout leftOffset:(layout leftOffset + l)
cg@2536
  1399
                topOffset:(layout topOffset  + t).
cg@2536
  1400
                
cg@2536
  1401
        type == #LayoutFrame ifTrue:[
cg@2536
  1402
            layout bottomOffset:(layout bottomOffset + b).
cg@2536
  1403
            layout rightOffset:(layout rightOffset  + r).
cg@2536
  1404
        ]
cg@2536
  1405
    ] ifFalse:[
cg@2536
  1406
        type == #Rectangle ifTrue:[
cg@2536
  1407
            layout left:(layout left   + l)
cg@2536
  1408
                  right:(layout right  + r)
cg@2536
  1409
                    top:(layout top    + t)
cg@2536
  1410
                 bottom:(layout bottom + b).
cg@2536
  1411
        ] ifFalse:[     "POINT"
cg@2536
  1412
            layout x:(layout x + l) y:(layout y + t).
cg@2536
  1413
        ]
cg@2536
  1414
    ].
cg@2536
  1415
    aView geometryLayout:layout
cg@2510
  1416
!
cg@2510
  1417
cg@2510
  1418
shiftLayout:aViewOrComponent vertical:n
cg@2510
  1419
    "shift layout for a view; in case of an open transaction, the undo action is registered"
cg@2510
  1420
cg@2514
  1421
    self shiftLayout:aViewOrComponent horizontal:0 vertical:n
cg@60
  1422
! !
cg@60
  1423
cg@60
  1424
!UIObjectView methodsFor:'searching'!
cg@60
  1425
cg@60
  1426
findObjectAt:aPoint
cg@2501
  1427
    |view viewId lastId point component componentOrView|
cg@2501
  1428
cg@2501
  1429
    componentOrView := self findObjectAt:aPoint in:self.
cg@2501
  1430
cg@2501
  1431
    componentOrView == self ifTrue:[^ nil].
cg@2501
  1432
    ^ componentOrView.
cg@2501
  1433
cg@2501
  1434
"/ cg: old code, which I do not understand
cg@2501
  1435
"/    point := device translatePoint:aPoint fromView:self toView:rootView.
ca@1672
  1436
"/
cg@2501
  1437
"/    viewId := rootView id.
cg@2501
  1438
"/    [viewId notNil] whileTrue:[
cg@2501
  1439
"/        lastId := viewId.
cg@2501
  1440
"/        viewId := device viewIdFromPoint:point in:lastId. "/ must be rootView coordinate
ca@1672
  1441
"/    ].
ca@1672
  1442
"/
cg@2501
  1443
"/    view := device viewFromId:lastId.
cg@2501
  1444
"/    (view isNil or:[view == self]) ifTrue:[ 
cg@2501
  1445
"/        "/ used to return nil here;
cg@2501
  1446
"/        "/ now support a mix of views and components...
cg@2501
  1447
"/        components notEmptyOrNil ifTrue:[
cg@2501
  1448
"/            component := components detect:[:c | c bounds containsPoint:aPoint] ifNone:nil.
cg@2501
  1449
"/            ^ component
cg@2501
  1450
"/        ].
cg@2501
  1451
"/        ^ nil
ca@1672
  1452
"/    ].
cg@2501
  1453
"/    ^ view
cg@2501
  1454
!
cg@2501
  1455
cg@2501
  1456
findObjectAt:aPoint in:aView
cg@2501
  1457
    |lastHit lastRelPoint view point|
cg@2501
  1458
cg@2501
  1459
    "/ reverse search, to find covering ones first.
cg@2501
  1460
    aView subViews reverseDo:[:aSubView |
cg@2501
  1461
        |innerObject relPoint|
cg@2501
  1462
cg@2501
  1463
        ((aSubView origin extent:aSubView extent) containsPoint:aPoint) ifTrue:[
cg@2501
  1464
            relPoint := device translatePoint:aPoint fromView:aView toView:aSubView.
cg@2501
  1465
            innerObject := self findObjectAt:relPoint in:aSubView.
cg@2501
  1466
            innerObject notNil ifTrue:[ ^ innerObject ].
cg@2501
  1467
            lastHit := aSubView.
cg@2501
  1468
            lastRelPoint := relPoint.
cg@2501
  1469
        ]
cg@2501
  1470
    ].
cg@2501
  1471
    view := lastHit ? aView.
cg@2501
  1472
    point := lastRelPoint ? aPoint.
cg@2501
  1473
cg@2501
  1474
    view components notEmptyOrNil ifTrue:[
cg@2501
  1475
        view components reverseDo:[:eachComponent |
cg@2501
  1476
            (eachComponent frame containsPoint:point) ifTrue:[
cg@2501
  1477
                ^ eachComponent
cg@2501
  1478
            ].
cg@2501
  1479
        ].
cg@2501
  1480
    ].
cg@2501
  1481
    ^ view
cg@60
  1482
! !
cg@60
  1483
cg@60
  1484
!UIObjectView methodsFor:'selections'!
cg@60
  1485
ca@768
  1486
hideSelection
ca@1427
  1487
    "hide the selection - undraw hilights - whatever that is
ca@1427
  1488
    "
cg@2514
  1489
cg@2514
  1490
    super hideSelection.
cg@2514
  1491
    self repairDamage.   
cg@2501
  1492
"/    self showUnselected:selection.
ca@768
  1493
!
ca@768
  1494
ca@128
  1495
moveableSelection
ca@131
  1496
    "checks whether the selection is not empty and all selected instances
ca@131
  1497
     can be moved. If true the selection is returned otherwise nil
ca@128
  1498
    "
ca@128
  1499
    |coll|
ca@128
  1500
ca@128
  1501
    self hasSelection ifTrue:[
cg@2364
  1502
        (self canMove:(coll := self selection)) ifTrue:[
cg@2364
  1503
            ^ coll
cg@2364
  1504
        ]
ca@128
  1505
    ].
cg@2364
  1506
    ^ nil
ca@128
  1507
!
ca@128
  1508
cg@60
  1509
numberOfSelections
ca@131
  1510
    "return the number of selected instances
ca@61
  1511
    "
ca@128
  1512
    |coll size|
ca@128
  1513
ca@128
  1514
    coll := self selection.
ca@128
  1515
    size := coll size.
ca@128
  1516
ca@128
  1517
    (size ~~ 0 or:[coll isNil]) ifTrue:[^ size].
ca@128
  1518
  ^ 1
cg@60
  1519
!
cg@60
  1520
sv@2481
  1521
resizableSelection
sv@2481
  1522
    "checks whether the selection is not empty and all selected instances
sv@2481
  1523
     can be resized. If true the selection is returned otherwise nil
sv@2481
  1524
    "
sv@2481
  1525
    |coll|
sv@2481
  1526
sv@2481
  1527
    self hasSelection ifTrue:[
sv@2481
  1528
        coll := self selection.        
sv@2481
  1529
        (self canResize:coll) ifTrue:[
sv@2481
  1530
            ^ coll
sv@2481
  1531
        ]
sv@2481
  1532
    ].
sv@2481
  1533
    ^ nil
sv@2481
  1534
!
sv@2481
  1535
werner@1827
  1536
selectNextUpInHierarchy
cg@2422
  1537
    self halt:#ca.
werner@1827
  1538
!
werner@1827
  1539
cg@2215
  1540
selection:newSelection
cg@2215
  1541
    "change selection to newSelection"
cg@2215
  1542
cg@2215
  1543
    self select:newSelection
ca@149
  1544
!
ca@149
  1545
ca@128
  1546
selectionDo:aBlock
ca@128
  1547
    "apply block to every selected object
ca@128
  1548
    "
ca@128
  1549
    self forEach:(self selection) do:aBlock
ca@128
  1550
ca@128
  1551
ca@128
  1552
!
ca@128
  1553
ca@61
  1554
showSelection
cg@2501
  1555
    "show the selection - draw handles"
cg@2501
  1556
ca@61
  1557
    selectionHiddenLevel == 0 ifTrue:[
cg@2514
  1558
        super showSelection.
cg@2514
  1559
        self repairDamage.   
cg@60
  1560
    ].
cg@60
  1561
!
cg@60
  1562
cg@60
  1563
singleSelection
sv@2267
  1564
    "checks whether a single element is selected; in this case the element is
sv@2267
  1565
     returned otherwise nil"
sv@2267
  1566
sv@2267
  1567
    |sel|
sv@2267
  1568
sv@2267
  1569
    sel := self selection.
sv@2267
  1570
    sel isCollection ifTrue:[
sv@2267
  1571
        sel := sel size == 1 ifTrue:[sel first] ifFalse:[nil].
cg@60
  1572
    ].
sv@2267
  1573
    ^ sel
cg@60
  1574
!
cg@60
  1575
cg@60
  1576
singleSelectionDo:aBlock
ca@131
  1577
    "checks whether one element is selected; in this case the block
ca@131
  1578
     with argument the selected instance will be processed
ca@61
  1579
    "
cg@60
  1580
    |view|
cg@60
  1581
cg@60
  1582
    (view := self singleSelection) notNil ifTrue:[
cg@1120
  1583
	aBlock value:view
cg@60
  1584
    ]
cg@60
  1585
!
cg@60
  1586
cg@1230
  1587
twoElementSelection
cg@1230
  1588
    "checks whether exactly two elements are selected; 
cg@1230
  1589
     in this case, return the selection collection.
cg@1230
  1590
     otherwise return nil
cg@1230
  1591
    "
cg@1230
  1592
    |coll|
cg@1230
  1593
cg@1230
  1594
    (coll := self selection) isCollection ifFalse:[
cg@1230
  1595
        ^ nil "/ single
cg@1230
  1596
    ].
cg@1230
  1597
cg@1230
  1598
    coll size == 2 ifTrue:[ ^ coll].
cg@1230
  1599
    ^ nil
cg@1230
  1600
!
cg@1230
  1601
cg@60
  1602
unselect
ca@61
  1603
    "clear selection
ca@61
  1604
    "
ca@128
  1605
    self select:nil
cg@60
  1606
!
cg@60
  1607
cg@60
  1608
withSelectionHiddenDo:aBlock
cg@1959
  1609
    "apply block with selection hidden (no handles)"
cg@1959
  1610
ca@78
  1611
    |coll|
ca@78
  1612
ca@138
  1613
    selectionHiddenLevel == 0 ifTrue:[
cg@1555
  1614
        self hideSelection.
cg@1555
  1615
        device flush.
ca@61
  1616
    ].
ca@138
  1617
    selectionHiddenLevel := selectionHiddenLevel + 1.
ca@61
  1618
cg@2516
  1619
    aBlock 
cg@2516
  1620
        ensure:[
cg@2516
  1621
            selectionHiddenLevel == 1 ifTrue:[
cg@2516
  1622
                "/ careful to decrement selectionHiddenLevel AFTER the sizeChanged;
cg@2516
  1623
                "/ otherwise, we get endless recursion here.
cg@2516
  1624
                setOfSuperViewsSizeChanged notEmpty ifTrue:[
cg@2516
  1625
                    coll := self minClosedViewSetFor:setOfSuperViewsSizeChanged.
cg@2516
  1626
                    coll do:[:aView| aView sizeChanged:nil].
cg@2516
  1627
                    setOfSuperViewsSizeChanged := IdentitySet new
cg@2516
  1628
                ].
cg@2516
  1629
                selectionHiddenLevel := selectionHiddenLevel - 1.
cg@2516
  1630
                self showSelection.
cg@2516
  1631
            ] ifFalse:[
cg@2516
  1632
                selectionHiddenLevel := selectionHiddenLevel - 1.
cg@1555
  1633
            ].
cg@1555
  1634
        ]
ca@61
  1635
!
ca@61
  1636
ca@61
  1637
withoutSelectionDo:aBlock
ca@61
  1638
    "evaluate aBlock while selection is nilled
ca@61
  1639
    "
cg@60
  1640
    |sel|
cg@60
  1641
ca@128
  1642
    self hasSelection ifFalse:[
cg@1120
  1643
	aBlock value
ca@128
  1644
    ] ifTrue:[
cg@1120
  1645
	sel := self selection.
cg@1120
  1646
	self setSelection:nil withRedraw:true.
cg@1120
  1647
	aBlock value.
cg@1120
  1648
	self setSelection:sel withRedraw:true.
cg@60
  1649
    ]
cg@60
  1650
cg@60
  1651
cg@60
  1652
! !
cg@60
  1653
cg@1717
  1654
!UIObjectView methodsFor:'selections-basic'!
ca@131
  1655
ca@1427
  1656
recursiveRepair:theDamages startIn:aView
ca@1427
  1657
    "repair all views and contained views, which intersects the damage.
ca@1427
  1658
     !!!! all damages repaired are removed from the list of damages !!!!
ca@1427
  1659
    "
ca@1427
  1660
    |color isRepaired relOrg damage
ca@1427
  1661
     bwWidth    "{ Class:SmallInteger }"
ca@1427
  1662
     x          "{ Class:SmallInteger }"
ca@1427
  1663
     y          "{ Class:SmallInteger }"
ca@1427
  1664
     w          "{ Class:SmallInteger }"
ca@1427
  1665
     h          "{ Class:SmallInteger }"
ca@1427
  1666
     relOrgX    "{ Class:SmallInteger }"
ca@1427
  1667
     relOrgY    "{ Class:SmallInteger }"
ca@1427
  1668
     width      "{ Class:SmallInteger }"
ca@1427
  1669
     height     "{ Class:SmallInteger }"
ca@1427
  1670
     size       "{ Class:SmallInteger }"
ca@1427
  1671
    |
ca@1438
  1672
    aView isInputOnly ifTrue:[^ self ].
ca@1427
  1673
ca@1437
  1674
    (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ self ].
ca@1427
  1675
cg@2513
  1676
    aView components notEmptyOrNil ifTrue:[ 
cg@2513
  1677
        aView invalidate 
cg@2513
  1678
    ].
ca@1427
  1679
    aView subViews notNil ifTrue:[
ca@1427
  1680
        aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
ca@1427
  1681
        theDamages isEmpty ifTrue:[ ^ self ].
ca@1427
  1682
    ].
ca@1427
  1683
ca@1427
  1684
    relOrg  := aView originRelativeTo:self.
ca@1427
  1685
    bwWidth := aView borderWidth.
ca@1427
  1686
    size    := theDamages size.
ca@1427
  1687
ca@1427
  1688
    "/ compute relative origin starting from border left@top
ca@1427
  1689
    relOrgX := relOrg x - bwWidth.
ca@1427
  1690
    relOrgY := relOrg y - bwWidth.
ca@1427
  1691
    width   := aView width  + bwWidth + bwWidth.
sv@2482
  1692
    height  := aView height + bwWidth + bwWidth.
sv@2482
  1693
sv@2482
  1694
    size to:1 by:-1 do:[:anIndex|
sv@2482
  1695
        damage := theDamages at:anIndex.
sv@2482
  1696
sv@2482
  1697
        "/ compute the rectangle into the view
sv@2482
  1698
        y := damage top  - relOrgY.
sv@2482
  1699
        x := damage left - relOrgX.
sv@2482
  1700
        w := damage width.
sv@2482
  1701
        h := damage height.
sv@2482
  1702
sv@2482
  1703
        isRepaired := true.
sv@2482
  1704
sv@2482
  1705
        x     < 0      ifTrue:[ w := w + x. x := 0. isRepaired := false ].
sv@2482
  1706
        y     < 0      ifTrue:[ h := h + y. y := 0. isRepaired := false ].
sv@2482
  1707
        x + w > width  ifTrue:[ w := width  - x.    isRepaired := false ].
sv@2482
  1708
        y + h > height ifTrue:[ h := height - y.    isRepaired := false ].
sv@2482
  1709
sv@2482
  1710
        (w > 0 and:[h > 0]) ifTrue:[
sv@2482
  1711
            bwWidth ~~ 0 ifTrue:[
sv@2482
  1712
                color isNil ifTrue:[
sv@2482
  1713
                    "/ must force redraw of border
sv@2482
  1714
                    color := aView borderColor.
cg@2688
  1715
                    aView borderColor:(Color colorId:1).  "/ kludge to force a redraw
sv@2482
  1716
                    aView borderColor:color.
sv@2482
  1717
                ].
sv@2482
  1718
                w := w - bwWidth.
sv@2482
  1719
                h := h - bwWidth.
sv@2482
  1720
sv@2482
  1721
                (x := x - bwWidth) < 0 ifTrue:[w := w + x. x := 0].
sv@2482
  1722
                (y := y - bwWidth) < 0 ifTrue:[h := h + y. y := 0].
sv@2482
  1723
sv@2482
  1724
                (w > 0 and:[h > 0])  ifFalse:[w := 0].
sv@2482
  1725
            ].
sv@2482
  1726
sv@2482
  1727
            w > 0 ifTrue:[
sv@2482
  1728
                aView clearRectangleX:x y:y width:w height:h.
sv@2482
  1729
                aView exposeX:x y:y width:w height:h
sv@2482
  1730
            ].
sv@2482
  1731
            isRepaired ifTrue:[ theDamages removeIndex:anIndex ].
sv@2482
  1732
        ]
sv@2482
  1733
    ].
ca@1427
  1734
!
ca@1427
  1735
ca@131
  1736
selection
ca@131
  1737
    "returns the current selection
ca@131
  1738
    "
cg@2528
  1739
cg@2528
  1740
    "/ Q to ca: why redefine the collection building???
cg@2528
  1741
    ^ super selection.
cg@2528
  1742
ca@131
  1743
    ^ selection
ca@131
  1744
!
ca@131
  1745
cg@2356
  1746
setSelection:newSelection withRedraw:doRedraw
cg@2356
  1747
    "set a new selection without change notifications"
cg@2356
  1748
cg@2356
  1749
    | sel |
cg@2356
  1750
cg@2356
  1751
    (sel := newSelection) == self ifTrue:[
cg@2356
  1752
        sel := nil
cg@2356
  1753
    ].
cg@2356
  1754
cg@2356
  1755
    doRedraw ifTrue:[
cg@2356
  1756
        self hideSelection.
cg@2356
  1757
        selection := sel.
cg@2356
  1758
cg@2356
  1759
        self forEach:selection do:[:aView |
cg@2356
  1760
            |superView|
cg@2356
  1761
cg@2356
  1762
            superView := aView superView. 
cg@2356
  1763
            self recomputeShapeIfTransparentBox:superView.
cg@2356
  1764
        ].
cg@2356
  1765
        self showSelection.
cg@2356
  1766
    ] ifFalse:[
cg@2356
  1767
        selection := sel
cg@2356
  1768
    ]
cg@2356
  1769
!
cg@2356
  1770
ca@1427
  1771
showUnselected:something
cg@2501
  1772
    "show a component or list of components unselected"
cg@2501
  1773
cg@2501
  1774
    |damages oldClipped savedSelection|
ca@1427
  1775
ca@1427
  1776
    (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
ca@1427
  1777
        ^ self
ca@1427
  1778
    ].
ca@1438
  1779
ca@1427
  1780
    damages := OrderedCollection new.
ca@1427
  1781
ca@1427
  1782
    self forEach:something do:[:v|
ca@1437
  1783
        self handlesOf:v do:[:aDamage :wht|
ca@1437
  1784
            damages reverseDo:[:el|
ca@1437
  1785
                (el intersects:aDamage) ifTrue:[
ca@1437
  1786
                    damages removeIdentical:el.
ca@1437
  1787
cg@2503
  1788
                    aDamage left:(aDamage left   min:el left) floor
cg@2503
  1789
                           right:(aDamage right  max:el right) ceiling
cg@2503
  1790
                             top:(aDamage top    min:el top) floor
cg@2503
  1791
                          bottom:(aDamage bottom max:el bottom) ceiling
ca@1437
  1792
                ]
ca@1437
  1793
            ].                        
ca@1437
  1794
            damages add:aDamage
ca@1427
  1795
        ]
ca@1427
  1796
    ].
ca@1438
  1797
cg@2501
  1798
    damages do:[:el| self clearRectangle:el. ].
ca@1438
  1799
ca@1438
  1800
    (oldClipped := clipChildren) ifFalse:[
ca@1438
  1801
        self clippedByChildren:(clipChildren := true)
ca@1438
  1802
    ].
ca@1451
  1803
    self subViews reverseDo:[:v| self recursiveRepair:damages startIn:v].
ca@1437
  1804
ca@1427
  1805
    oldClipped ~~ clipChildren ifTrue:[
ca@1427
  1806
        self clippedByChildren:(clipChildren := oldClipped).
ca@1427
  1807
    ].
cg@2501
  1808
cg@2501
  1809
    device flush.
cg@2501
  1810
cg@2501
  1811
    savedSelection := selection.
cg@2501
  1812
    [
cg@2501
  1813
        selection := nil.
cg@2501
  1814
        damages do:[:el| self invalidate:el ].
cg@2501
  1815
        self repairDamage.
cg@2501
  1816
    ] ensure:[
cg@2501
  1817
        selection := savedSelection
cg@2501
  1818
    ].
ca@131
  1819
! !
ca@131
  1820
cg@60
  1821
!UIObjectView methodsFor:'testing'!
cg@60
  1822
ca@128
  1823
hasSelection
ca@284
  1824
    "returns true if any widget is selected
ca@61
  1825
    "
ca@128
  1826
    ^ self numberOfSelections ~~ 0
cg@60
  1827
cg@60
  1828
!
cg@60
  1829
ca@284
  1830
hasSingleSelection
ca@284
  1831
    "returns true if one widget is selected
ca@284
  1832
    "
ca@284
  1833
    ^ self numberOfSelections == 1
ca@284
  1834
ca@284
  1835
!
ca@284
  1836
ca@284
  1837
hasUndoHistory
cg@1918
  1838
    "returns true if undos exists"
cg@1918
  1839
cg@2722
  1840
    ^ undoHistory notEmpty
ca@284
  1841
!
ca@284
  1842
ca@134
  1843
isModified
cg@1918
  1844
    "returns true if painter is modified"
cg@1918
  1845
cg@1918
  1846
    ^ undoHistory isModified
ca@134
  1847
!
ca@134
  1848
ca@128
  1849
isSelected:anObject
ca@128
  1850
    "return true, if the argument, anObject is selected
ca@128
  1851
    "
ca@128
  1852
    anObject notNil ifTrue:[
cg@1120
  1853
	self selectionDo:[:el| el == anObject ifTrue:[^ true]]
ca@128
  1854
    ].
ca@128
  1855
  ^ false
ca@128
  1856
cg@2538
  1857
!
cg@2538
  1858
cg@2538
  1859
object:anObject isContainedIn:aRectangle
cg@2538
  1860
    ^ anObject bounds isContainedIn:aRectangle
cg@60
  1861
! !
cg@60
  1862
cg@60
  1863
!UIObjectView methodsFor:'transaction'!
cg@60
  1864
ca@134
  1865
createUndoLayout:aView
ca@134
  1866
    "prepare undo action for a view changing its layout
ca@134
  1867
    "
ca@134
  1868
    self subclassResponsibility
ca@134
  1869
ca@134
  1870
!
ca@134
  1871
cg@60
  1872
transaction:aType objects:something do:aOneArgBlock
cg@60
  1873
    "opens a transaction and evaluates a block within the transaction; the
cg@60
  1874
     argument to the block is a view from derived from something
cg@60
  1875
    "
cg@60
  1876
    self subclassResponsibility
cg@60
  1877
cg@60
  1878
cg@60
  1879
!
cg@60
  1880
cg@60
  1881
transaction:aType selectionDo:aOneArgBlock
cg@60
  1882
    "opens a transaction and evaluates a block within the transaction; the
cg@60
  1883
     argument to the block is a view from the selection
cg@60
  1884
    "
ca@128
  1885
    self transaction:aType objects:(self selection) do:aOneArgBlock
cg@60
  1886
cg@60
  1887
cg@60
  1888
! !
cg@60
  1889
cg@1715
  1890
!UIObjectView methodsFor:'user actions-dimension'!
cg@60
  1891
cg@60
  1892
copyExtent
cg@2364
  1893
    "copy the extent from the selected object"
cg@2364
  1894
cg@60
  1895
    |object|
cg@60
  1896
cg@60
  1897
    object := self singleSelection.
cg@60
  1898
    object notNil ifTrue:[
cg@2364
  1899
        CopiedExtent := object computeExtent
cg@60
  1900
    ] ifFalse:[
cg@2364
  1901
        self warn:'Exactly one element must be selected!!'.
cg@60
  1902
    ]
cg@60
  1903
!
cg@60
  1904
ca@89
  1905
copyLayout
cg@2364
  1906
    "copy the layout from the selected object"
cg@2364
  1907
ca@89
  1908
    |object|
ca@89
  1909
ca@89
  1910
    object := self singleSelection.
ca@89
  1911
    object notNil ifTrue:[
cg@2364
  1912
        CopiedLayout := object geometryLayout copy
ca@89
  1913
    ] ifFalse:[
cg@2364
  1914
        self warn:'Exactly one element must be selected!!'.
ca@89
  1915
    ]
ca@89
  1916
!
ca@89
  1917
cg@1230
  1918
exchangeLayouts
cg@1230
  1919
    "exchange the layout of two elements 
cg@1230
  1920
     (useful to change the order of radiobuttons or checkBoxes)
cg@1230
  1921
    "
cg@1230
  1922
    |objects l1 l2|
cg@1230
  1923
cg@1230
  1924
    objects := self twoElementSelection.
cg@1230
  1925
cg@1230
  1926
    objects notNil ifTrue:[
cg@1230
  1927
        l1 := (objects at:1) geometryLayout copy.
cg@1230
  1928
        l2 := (objects at:2) geometryLayout copy.
cg@1230
  1929
        self transaction:#exchangeLayout dimensionDo:[:v|
cg@1230
  1930
            v == (objects at:1) ifTrue:[
cg@1230
  1931
                v geometryLayout:(l2 copy)
cg@1230
  1932
            ] ifFalse:[
cg@1230
  1933
                v geometryLayout:(l1 copy).
cg@1230
  1934
            ]
cg@1230
  1935
        ]    
cg@1230
  1936
    ] ifFalse:[    
cg@1230
  1937
        self warn:'exactly two elements must be selected'.
cg@1230
  1938
    ]
cg@1230
  1939
cg@1230
  1940
cg@1230
  1941
cg@1230
  1942
!
cg@1230
  1943
cg@60
  1944
pasteExtent
cg@2364
  1945
    "paste the copied extent to all objects in the selection"
cg@2364
  1946
cg@2398
  1947
    |heightToPaste widthToPaste|
cg@2398
  1948
cg@2364
  1949
    CopiedExtent notNil ifTrue:[
cg@2398
  1950
        widthToPaste := CopiedExtent x.
cg@2398
  1951
        heightToPaste := CopiedExtent y.
cg@2398
  1952
    ] ifFalse:[
cg@2398
  1953
        CopiedLayout notNil ifTrue:[
cg@2398
  1954
            CopiedLayout leftFraction = CopiedLayout rightFraction ifTrue:[
cg@2398
  1955
                CopiedLayout topFraction = CopiedLayout bottomFraction ifTrue:[
cg@2398
  1956
                    widthToPaste := (CopiedLayout rightOffset - CopiedLayout leftOffset). 
cg@2398
  1957
                    heightToPaste := (CopiedLayout bottomOffset - CopiedLayout topOffset). 
cg@2398
  1958
                ]
cg@2398
  1959
            ]
cg@2398
  1960
        ].
cg@2398
  1961
    ].
cg@2398
  1962
cg@2398
  1963
    widthToPaste notNil ifTrue:[
cg@2398
  1964
        heightToPaste notNil ifTrue:[
cg@2398
  1965
            self transaction:#pasteExtent dimensionDo:[:v|
cg@2398
  1966
                self resize:v corner:(v computeOrigin + (widthToPaste@heightToPaste))
cg@2398
  1967
            ]    
cg@2364
  1968
        ]    
cg@60
  1969
    ]    
cg@60
  1970
!
cg@60
  1971
cg@60
  1972
pasteHeight
cg@2364
  1973
    "paste the copied extent's height to all objects in the selection"
cg@2364
  1974
cg@2398
  1975
    |heightToPaste|
cg@2398
  1976
cg@2364
  1977
    CopiedExtent notNil ifTrue:[
cg@2398
  1978
        heightToPaste := CopiedExtent y.
cg@2398
  1979
    ] ifFalse:[
cg@2398
  1980
        CopiedLayout notNil ifTrue:[
cg@2398
  1981
            CopiedLayout topFraction = CopiedLayout bottomFraction ifTrue:[
cg@2398
  1982
                heightToPaste := (CopiedLayout bottomOffset - CopiedLayout topOffset) 
cg@2398
  1983
            ]
cg@2398
  1984
        ].
cg@2398
  1985
    ].
cg@2398
  1986
cg@2398
  1987
    heightToPaste notNil ifTrue:[
cg@2364
  1988
        self transaction:#pasteHeight dimensionDo:[:v|
cg@2398
  1989
            self resize:v bottom:(v computeOrigin + heightToPaste)
cg@2398
  1990
        ].
cg@2398
  1991
    ].    
ca@89
  1992
!
ca@89
  1993
cg@2364
  1994
pasteLayout
cg@2364
  1995
    "paste the layout to all objects in the selection"
cg@2364
  1996
cg@2364
  1997
    CopiedLayout notNil ifTrue:[
cg@2364
  1998
        self transaction:#pasteLayout dimensionDo:[:v|
cg@2364
  1999
            v geometryLayout:(CopiedLayout copy)
cg@2364
  2000
        ]    
cg@2364
  2001
    ]    
cg@2364
  2002
!
cg@2364
  2003
cg@60
  2004
pasteWidth
cg@2364
  2005
    "paste the copied extent's width to all objects in the selection"
cg@2364
  2006
cg@2398
  2007
    |widthToPaste|
cg@2398
  2008
cg@2364
  2009
    CopiedExtent notNil ifTrue:[
cg@2398
  2010
        widthToPaste := CopiedExtent x.
cg@2398
  2011
    ] ifFalse:[
cg@2398
  2012
        CopiedLayout notNil ifTrue:[
cg@2398
  2013
            CopiedLayout leftFraction = CopiedLayout rightFraction ifTrue:[
cg@2398
  2014
                widthToPaste := (CopiedLayout rightOffset - CopiedLayout leftOffset) 
cg@2398
  2015
            ]
cg@2398
  2016
        ].
cg@2398
  2017
    ].
cg@2398
  2018
cg@2398
  2019
    widthToPaste notNil ifTrue:[
cg@2364
  2020
        self transaction:#pasteWidth dimensionDo:[:v|
cg@2398
  2021
            self resize:v right:(v computeOrigin + widthToPaste)
cg@2364
  2022
        ]    
cg@60
  2023
    ]    
cg@60
  2024
!
cg@60
  2025
ca@61
  2026
setExtent:anExtent
ca@61
  2027
    "change extent for all selected objects
ca@61
  2028
    "
ca@134
  2029
    self transaction:#extent dimensionDo:[:v|
cg@1120
  2030
	v geometryLayout:nil.
cg@1120
  2031
	v extent:anExtent.
cg@67
  2032
    ].
cg@67
  2033
cg@67
  2034
    "Modified: 28.2.1997 / 12:49:00 / cg"
ca@61
  2035
!
ca@61
  2036
ca@149
  2037
setLayout:aLayout
ca@149
  2038
    "change layout for all selected objects
ca@149
  2039
    "
ca@149
  2040
    self transaction:#layout dimensionDo:[:v|
cg@2501
  2041
        v geometryLayout:(aLayout copy)
ca@149
  2042
    ].    
ca@149
  2043
!
ca@149
  2044
cg@60
  2045
setToDefaultExtent
ca@61
  2046
    "change extent of all selected views to their default extent
ca@61
  2047
    "
ca@134
  2048
    self transaction:#defaultExtent dimensionDo:[:v|
cg@1120
  2049
	self resize:v corner:(v computeOrigin + (v preferredExtent)).
cg@60
  2050
    ]    
cg@60
  2051
cg@60
  2052
!
cg@60
  2053
cg@60
  2054
setToDefaultHeight
ca@61
  2055
    "change height of all selected views to their default height
ca@61
  2056
    "
ca@134
  2057
    self transaction:#defaultHeight dimensionDo:[:v|
cg@1120
  2058
	self resize:v bottom:(v computeOrigin + (v preferredExtent))
cg@60
  2059
    ]    
cg@60
  2060
cg@60
  2061
!
cg@60
  2062
cg@60
  2063
setToDefaultWidth
ca@61
  2064
    "change width of all selected views to their default width
ca@61
  2065
    "
ca@134
  2066
    self transaction:#defaultWidth dimensionDo:[:v|
cg@1120
  2067
	self resize:v right:(v computeOrigin + (v preferredExtent))
cg@60
  2068
    ]    
cg@60
  2069
cg@60
  2070
!
cg@60
  2071
ca@134
  2072
transaction:aType dimensionDo:aOneArgBlock
cg@60
  2073
    "change dimension within a transaction for the selected elements by evaluating
cg@60
  2074
     the block with the argument a view.
cg@60
  2075
    "
ca@61
  2076
    self withSelectionHiddenDo:[
cg@1120
  2077
	self transaction:aType selectionDo:[:aView|
cg@1120
  2078
	    (self class layoutType:aView) notNil ifTrue:[
cg@1120
  2079
		self createUndoLayout:aView.
cg@1120
  2080
		aOneArgBlock value:aView.
cg@1120
  2081
		self elementChangedSize:aView.
cg@1120
  2082
	    ]
cg@1120
  2083
	]
ca@61
  2084
    ].
ca@225
  2085
    self layoutChanged
ca@61
  2086
ca@61
  2087
! !
ca@61
  2088
cg@1715
  2089
!UIObjectView methodsFor:'user actions-move'!
ca@61
  2090
cg@2394
  2091
moveDo:aOneArgBlock 
cg@2394
  2092
    "perform a move operation (with auto repeat)"
cg@2394
  2093
ca@138
  2094
    |sensor tm|
ca@138
  2095
ca@138
  2096
    self moveableSelection isNil ifTrue:[
cg@2356
  2097
        ^ self
ca@138
  2098
    ].
ca@138
  2099
    sensor := self sensor.
ca@138
  2100
cg@2394
  2101
    tm := ButtonController defaultInitialDelay.
ca@138
  2102
ca@138
  2103
    self withSelectionHiddenDo:[
cg@2356
  2104
        self transaction:#move selectionDo:[:aView|self createUndoLayout:aView].
cg@2356
  2105
cg@2356
  2106
        [
cg@2356
  2107
            self selectionDo:[:aView| aOneArgBlock value:aView ].
cg@2510
  2108
cg@2394
  2109
            sensor leftButtonPressed ifTrue:[
cg@2394
  2110
                self windowGroup processExposeEvents.
cg@2394
  2111
                Delay waitForSeconds:tm.
cg@2394
  2112
                self windowGroup processExposeEvents.
cg@2394
  2113
                tm := ButtonController defaultRepeatDelay.
cg@2394
  2114
                self layoutChanged.
cg@2394
  2115
            ].
cg@2356
  2116
            sensor leftButtonPressed.
cg@2356
  2117
        ] whileTrue.
cg@2356
  2118
cg@2356
  2119
        "/ handle any expose events (for subcomponents) before
cg@2356
  2120
        "/ redrawing the handles.
cg@2356
  2121
        Delay waitForSeconds:0.1.
cg@2394
  2122
        self windowGroup processExposeEvents
ca@138
  2123
    ].
ca@138
  2124
!
ca@138
  2125
ca@113
  2126
moveSelectionDown
ca@61
  2127
    "move selection down
ca@61
  2128
    "
cg@1222
  2129
    self moveSelectionDown:1
cg@1222
  2130
cg@1222
  2131
!
cg@1222
  2132
cg@1222
  2133
moveSelectionDown:howMany
cg@2510
  2134
    "move selection down (pixelwise or aligned-grid wise)"
cg@2510
  2135
ca@138
  2136
    |gridY n|
ca@138
  2137
ca@138
  2138
    gridAlign notNil ifTrue:[gridY := gridAlign y]
cg@1222
  2139
                    ifFalse:[gridY := 1].
ca@138
  2140
ca@138
  2141
    self moveDo:[:aView|
cg@1222
  2142
        aligning ifTrue:[
cg@1222
  2143
            n := ((aView computeCorner y) \\ gridY).
cg@1222
  2144
cg@1222
  2145
            n ~~ 0 ifTrue:[
cg@1222
  2146
                n := gridY - n + 1.
cg@1222
  2147
            ] ifFalse:[
cg@1222
  2148
                n := gridY
cg@1222
  2149
            ]
cg@1222
  2150
        ] ifFalse:[
cg@2510
  2151
            n := 1.
cg@2510
  2152
            self sensor shiftDown ifTrue:[
cg@2510
  2153
                n := 8.    
cg@2510
  2154
            ].
cg@1222
  2155
        ].
cg@1222
  2156
        n := n * howMany.
cg@2510
  2157
        self shiftLayout:aView vertical:n
cg@60
  2158
    ]
cg@60
  2159
!
cg@60
  2160
ca@113
  2161
moveSelectionLeft
cg@60
  2162
    "move selection left
cg@60
  2163
    "
cg@1222
  2164
    self moveSelectionLeft:1
cg@1222
  2165
cg@1222
  2166
!
cg@1222
  2167
cg@1222
  2168
moveSelectionLeft:howMany
cg@2510
  2169
    "move selection to the left (pixelwise or aligned-grid wise)"
cg@2510
  2170
ca@113
  2171
    |gridX n|
cg@60
  2172
ca@138
  2173
    gridAlign notNil ifTrue:[gridX := gridAlign x]
cg@1222
  2174
                    ifFalse:[gridX := 1].
ca@138
  2175
ca@138
  2176
    self moveDo:[:aView|
cg@1222
  2177
        aligning ifTrue:[
cg@1222
  2178
            n := ((aView computeOrigin x) \\ gridX).
cg@1222
  2179
            n == 0 ifTrue:[n := gridX].
cg@1222
  2180
        ] ifFalse:[
cg@2538
  2181
            n := 1.
cg@2510
  2182
            self sensor shiftDown ifTrue:[
cg@2538
  2183
                n := 8.    
cg@2510
  2184
            ].
cg@1222
  2185
        ].
cg@1222
  2186
        n := n * howMany.
cg@2538
  2187
        self shiftLayout:aView horizontal:n negated
cg@60
  2188
    ]
cg@60
  2189
!
cg@60
  2190
ca@113
  2191
moveSelectionRight
cg@2356
  2192
    "move the selection to the right"
cg@2356
  2193
cg@1222
  2194
    self moveSelectionRight:1
cg@1222
  2195
!
cg@1222
  2196
cg@1222
  2197
moveSelectionRight:howMany
cg@2510
  2198
    "move selection to the right (pixelwise or aligned-grid wise)"
cg@2356
  2199
ca@113
  2200
    |gridX n|
ca@113
  2201
ca@138
  2202
    gridAlign notNil ifTrue:[gridX := gridAlign x]
cg@1222
  2203
                    ifFalse:[gridX := 1].
ca@138
  2204
ca@138
  2205
    self moveDo:[:aView|
cg@1222
  2206
        aligning ifTrue:[
cg@1222
  2207
            n := ((aView computeCorner x) \\ gridX).
cg@2538
  2208
            n == 0 ifTrue:[n := gridX].
cg@1222
  2209
        ] ifFalse:[
cg@2510
  2210
            n := 1.
cg@2510
  2211
            self sensor shiftDown ifTrue:[
cg@2510
  2212
                n := 8.    
cg@2510
  2213
            ].
cg@1222
  2214
        ].
cg@1222
  2215
        n := n * howMany.
cg@2510
  2216
        self shiftLayout:aView horizontal:n
ca@113
  2217
    ]
ca@113
  2218
!
ca@113
  2219
ca@113
  2220
moveSelectionUp
cg@60
  2221
    "move selection up
cg@60
  2222
    "
cg@1222
  2223
    self moveSelectionUp:1
cg@1222
  2224
!
cg@1222
  2225
cg@1222
  2226
moveSelectionUp:howMany
cg@2510
  2227
    "move selection up (pixelwise or aligned-grid wise)"
cg@2510
  2228
ca@113
  2229
    |gridY n|
cg@60
  2230
ca@138
  2231
    gridAlign notNil ifTrue:[gridY := gridAlign y]
cg@1222
  2232
                    ifFalse:[gridY := 1].
ca@138
  2233
ca@138
  2234
    self moveDo:[:aView|
cg@1222
  2235
        aligning ifTrue:[
sv@2485
  2236
            n := ((aView computeOrigin y) \\ gridY).
cg@1222
  2237
            n == 0 ifTrue:[n := gridY].
cg@1222
  2238
            n := n negated.
cg@1222
  2239
        ] ifFalse:[
cg@2510
  2240
            n := -1.
cg@2510
  2241
            self sensor shiftDown ifTrue:[
cg@2510
  2242
                n := -8.    
cg@2510
  2243
            ].
cg@1222
  2244
        ].
cg@1222
  2245
        n := n * howMany.
cg@2510
  2246
        self shiftLayout:aView vertical:n
cg@60
  2247
    ]
cg@60
  2248
! !
cg@60
  2249
cg@1715
  2250
!UIObjectView methodsFor:'user actions-position'!
cg@60
  2251
cg@2364
  2252
alignResizeSelectionLeft
cg@2364
  2253
    "resize the selection on the left to align their left edge with the 
cg@2364
  2254
     of the first object in the selection; 
cg@2364
  2255
     in case of a single object selection, the objects left edge is aligned with the left of its superview"
cg@2364
  2256
cg@2364
  2257
    |lmost delta sel|
cg@2364
  2258
cg@2364
  2259
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2260
        self withSelectionHiddenDo:[
cg@2364
  2261
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2262
                lmost := (sel first) computeOrigin x.
cg@2364
  2263
cg@2364
  2264
                self transaction:#alignResizeLeft selectionDo:[:v|
cg@2364
  2265
                    (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[
cg@2364
  2266
                        self shiftLayout:v left:delta right:0
cg@2364
  2267
                    ]
cg@2364
  2268
                ]
cg@2364
  2269
            ] ifFalse:[
cg@2364
  2270
                self extentToFrame:#Left do:[:aLayout|
cg@2364
  2271
                    aLayout leftFraction:0.0 offset:0.
cg@2364
  2272
                ]
cg@2364
  2273
            ]
cg@2364
  2274
        ].
cg@2364
  2275
        self layoutChanged
cg@2364
  2276
    ]
cg@2364
  2277
!
cg@2364
  2278
cg@2364
  2279
alignResizeSelectionRight
cg@2364
  2280
    "align selection to the right of the first object in the selection; 
cg@2364
  2281
     in case of one selection the object is aligned to the right of its superview"
cg@2364
  2282
cg@2364
  2283
    |rmost delta sel|
cg@2364
  2284
cg@2364
  2285
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2286
        self withSelectionHiddenDo:[
cg@2364
  2287
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2288
                rmost := (sel first) computeCorner x.
cg@2364
  2289
cg@2364
  2290
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2291
                    (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[
cg@2364
  2292
                        self shiftLayout:v left:0 right:delta
cg@2364
  2293
                    ]
cg@2364
  2294
                ]
cg@2364
  2295
            ] ifFalse:[
cg@2364
  2296
                self extentToFrame:#Right do:[:aLayout|
cg@2364
  2297
                    aLayout rightOffset:0.
cg@2364
  2298
                    aLayout rightFraction:1.0.
cg@2364
  2299
                ]
cg@2364
  2300
            ]
cg@2364
  2301
        ].
cg@2364
  2302
        self layoutChanged
cg@2364
  2303
    ]
cg@2364
  2304
!
cg@2364
  2305
cg@60
  2306
alignSelectionBottom
ca@61
  2307
    "align selection to the bottom of the first object in the selection; in case
ca@61
  2308
     of one selection the object is aligned to the bottom of its superview
ca@61
  2309
    "
ca@128
  2310
    |bmost delta sel|
ca@128
  2311
ca@128
  2312
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2313
	self withSelectionHiddenDo:[
cg@1120
  2314
	    self numberOfSelections > 1 ifTrue:[
cg@1120
  2315
		bmost := (sel first) computeCorner y.
cg@1120
  2316
cg@1120
  2317
		self transaction:#alignBottom selectionDo:[:v|
cg@1120
  2318
		    (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[
cg@1120
  2319
			self shiftLayout:v top:delta bottom:delta.
cg@1120
  2320
		    ]
cg@1120
  2321
		]
cg@1120
  2322
	    ] ifFalse:[
cg@1120
  2323
		self extentToFrame:#Bottom do:[:aLayout|
cg@1120
  2324
		    aLayout bottomOffset:0.
cg@1120
  2325
		    aLayout bottomFraction:1.0
cg@1120
  2326
		]
cg@1120
  2327
	    ]
cg@1120
  2328
	].
cg@1120
  2329
	self layoutChanged
cg@60
  2330
    ]
cg@60
  2331
cg@60
  2332
cg@60
  2333
cg@60
  2334
!
cg@60
  2335
cg@60
  2336
alignSelectionCenterHor
ca@61
  2337
    "align selection to the center/horizontal of the first object in the selection; in case
ca@61
  2338
     of one selection the object is aligned to the center/horizontal of its superview
ca@61
  2339
    "
ca@128
  2340
    |view center sel|
ca@128
  2341
ca@128
  2342
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2343
	self withSelectionHiddenDo:[
cg@1120
  2344
	    view := self singleSelection.
cg@1120
  2345
cg@1120
  2346
	    view notNil ifTrue:[
ca@284
  2347
                
cg@1120
  2348
		view   := self findContainerOfView:view.
cg@1120
  2349
		center := view computeExtent
cg@1120
  2350
	    ] ifFalse:[
cg@1120
  2351
		view   := sel first.
cg@1120
  2352
		center := view computeCorner + view computeOrigin.
cg@1120
  2353
	    ].
cg@1120
  2354
	    center := center x // 2.
cg@1120
  2355
cg@1120
  2356
	    self transaction:#alignCenterHorizontal selectionDo:[:v|
cg@1120
  2357
		|newX oldX delta|
cg@1120
  2358
cg@1120
  2359
		oldX  := v computeOrigin x.
cg@1120
  2360
		newX  := center - ((v computeCorner x - oldX) // 2).
cg@1120
  2361
		delta := newX - oldX.
cg@1120
  2362
cg@1120
  2363
		self shiftLayout:v left:delta right:delta
cg@1120
  2364
	    ]
cg@1120
  2365
	].
cg@1120
  2366
	self layoutChanged
cg@60
  2367
    ]
cg@60
  2368
cg@60
  2369
cg@60
  2370
cg@60
  2371
!
cg@60
  2372
cg@60
  2373
alignSelectionCenterVer
ca@61
  2374
    "align selection to the center/vertical of the first object in the selection; in case
ca@61
  2375
     of one selection the object is aligned to the center/vertical of its superview
ca@61
  2376
    "
ca@128
  2377
    |view center sel|
ca@128
  2378
ca@128
  2379
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2380
	self withSelectionHiddenDo:[
cg@1120
  2381
	    view := self singleSelection.
cg@1120
  2382
cg@1120
  2383
	    view notNil ifTrue:[
cg@1120
  2384
		view   := self findContainerOfView:view.
cg@1120
  2385
		center := view computeExtent
cg@1120
  2386
	    ] ifFalse:[
cg@1120
  2387
		view   := sel first.
cg@1120
  2388
		center := view computeCorner + view computeOrigin.
cg@1120
  2389
	    ].
cg@1120
  2390
	    center := center y // 2.
cg@1120
  2391
cg@1120
  2392
	    self transaction:#alignCenterVertical selectionDo:[:v|
cg@1120
  2393
		|newY oldY delta|
cg@1120
  2394
cg@1120
  2395
		oldY  := v computeOrigin y.
cg@1120
  2396
		newY  := center - ((v computeCorner y - oldY) // 2).
cg@1120
  2397
		delta := newY - oldY.
cg@1120
  2398
cg@1120
  2399
		self shiftLayout:v top:delta bottom:delta
cg@1120
  2400
	    ]
cg@1120
  2401
	].
cg@1120
  2402
	self layoutChanged
cg@60
  2403
    ]
cg@60
  2404
!
cg@60
  2405
cg@60
  2406
alignSelectionLeft
cg@2364
  2407
    "align the selection with the left edge of the first object in the selection.
cg@2364
  2408
     in case of a single object selection, the object is moved to the left of its superview"
cg@2364
  2409
cg@2364
  2410
    |dominantLeft delta sel|
ca@128
  2411
ca@128
  2412
    (sel := self moveableSelection) notNil ifTrue:[
cg@1581
  2413
        self withSelectionHiddenDo:[
cg@2364
  2414
            dominantLeft := (sel first) computeOrigin x.
cg@1581
  2415
            self numberOfSelections > 1 ifTrue:[
cg@1581
  2416
                self transaction:#alignLeft selectionDo:[:v|
cg@2364
  2417
                    (delta := dominantLeft - (v computeOrigin x)) ~~ 0 ifTrue:[
cg@1581
  2418
                        self shiftLayout:v left:delta right:delta
cg@1581
  2419
                    ]
cg@1581
  2420
                ]
cg@1581
  2421
            ] ifFalse:[
cg@2364
  2422
                self transaction:#alignLeft selectionDo:[:v|
cg@2364
  2423
                    self shiftLayout:v left:dominantLeft negated right:dominantLeft negated
cg@2364
  2424
                ].
cg@1581
  2425
            ]
cg@1581
  2426
        ].
cg@1581
  2427
        self layoutChanged
cg@60
  2428
    ]
cg@60
  2429
!
cg@60
  2430
cg@60
  2431
alignSelectionLeftAndRight
ca@61
  2432
    "align selection to the left/right of the first object in the selection; in case
ca@61
  2433
     of one selection the object is aligned to the left/right of its superview
ca@61
  2434
    "
ca@128
  2435
    |lmost rmost sel|
ca@128
  2436
sv@2481
  2437
    (sel := self resizableSelection) notNil ifTrue:[
cg@1581
  2438
        self withSelectionHiddenDo:[
cg@1581
  2439
            self numberOfSelections > 1 ifTrue:[
cg@1581
  2440
                lmost := (sel first) computeOrigin x.
cg@1581
  2441
                rmost := (sel first) computeCorner x.
cg@1581
  2442
cg@1581
  2443
                self transaction:#alignLeftRight selectionDo:[:aView|
cg@1581
  2444
                    |layout|
sv@2481
  2445
sv@2481
  2446
                    aView superView isLayoutWrapper ifTrue:[
sv@2481
  2447
                        "change size only"
cg@1581
  2448
                        self createUndoLayout:aView.
sv@2481
  2449
                        aView width:sel first width.
sv@2481
  2450
                        self elementChangedSize:aView
sv@2481
  2451
                    ] ifFalse:[
sv@2481
  2452
                        layout := self class asLayoutFrameFromView:aView.
sv@2481
  2453
sv@2481
  2454
                        layout notNil ifTrue:[
sv@2481
  2455
                            self createUndoLayout:aView.
sv@2481
  2456
                            aView geometryLayout:layout.
sv@2481
  2457
sv@2481
  2458
                            undoHistory withoutTransactionDo:[
sv@2481
  2459
                                self shiftLayout:aView left:(lmost - (aView computeOrigin x))
sv@2481
  2460
                                                      right:(rmost - (aView computeCorner x)).
sv@2481
  2461
                            ].
sv@2481
  2462
                            self elementChangedSize:aView
cg@1581
  2463
                        ].
sv@2481
  2464
                    ].
cg@1581
  2465
                ]
cg@1581
  2466
            ] ifFalse:[
cg@1581
  2467
                self extentToFrame:#LeftRight do:[:aLayout|
cg@1581
  2468
                    aLayout leftFraction:0.0 offset:0.
cg@1581
  2469
                    aLayout rightFraction:1.0 offset:0.
cg@1581
  2470
                ]
cg@1581
  2471
            ]
cg@1581
  2472
        ].
cg@1581
  2473
        self layoutChanged
ca@61
  2474
    ].
ca@61
  2475
!
ca@61
  2476
ca@61
  2477
alignSelectionRight
ca@61
  2478
    "align selection to the right of the first object in the selection; in case
ca@61
  2479
     of one selection the object is aligned to the right of its superview
ca@61
  2480
    "
cg@2364
  2481
    |dominantRight delta sel|
ca@128
  2482
ca@128
  2483
    (sel := self moveableSelection) notNil ifTrue:[
cg@2364
  2484
        self withSelectionHiddenDo:[
cg@2364
  2485
            dominantRight := (sel first) computeCorner x.
cg@2364
  2486
            self numberOfSelections > 1 ifTrue:[
cg@2364
  2487
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2488
                    (delta := dominantRight - (v computeCorner x)) ~~ 0 ifTrue:[
cg@2364
  2489
                        self shiftLayout:v left:delta right:delta
cg@2364
  2490
                    ]
cg@2364
  2491
                ]
cg@2364
  2492
            ] ifFalse:[
cg@2364
  2493
                self transaction:#alignRight selectionDo:[:v|
cg@2364
  2494
                    delta := v superView width - dominantRight.
cg@2364
  2495
                    self shiftLayout:v left:delta right:delta
cg@2364
  2496
                ]
cg@2364
  2497
"/                self extentToFrame:#Right do:[:aLayout|
cg@2364
  2498
"/                    aLayout rightOffset:0.
cg@2364
  2499
"/                    aLayout rightFraction:1.0.
cg@2364
  2500
"/                ]
cg@2364
  2501
            ]
cg@2364
  2502
        ].
cg@2364
  2503
        self layoutChanged
cg@60
  2504
    ]
cg@60
  2505
!
cg@60
  2506
cg@60
  2507
alignSelectionTop
ca@61
  2508
    "align selection to the top of the first object in the selection; in case
ca@61
  2509
     of one selection the object is aligned to the top of its superview
ca@61
  2510
    "
ca@128
  2511
    |tmost delta sel|
ca@128
  2512
ca@128
  2513
    (sel := self moveableSelection) notNil ifTrue:[
cg@1120
  2514
	self withSelectionHiddenDo:[
cg@1120
  2515
	    self numberOfSelections > 1 ifTrue:[
cg@1120
  2516
		tmost := (sel first) computeOrigin y.
cg@1120
  2517
cg@1120
  2518
		self transaction:#alignTop selectionDo:[:v|
cg@1120
  2519
		    (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[
cg@1120
  2520
			self shiftLayout:v top:delta bottom:delta
cg@1120
  2521
		    ]
cg@1120
  2522
		]
cg@1120
  2523
	    ] ifFalse:[
cg@1120
  2524
		self extentToFrame:#Top do:[:aLayout|
cg@1120
  2525
		    aLayout topOffset:0.
cg@1120
  2526
		    aLayout topFraction:0.0.
cg@1120
  2527
		]
cg@1120
  2528
	    ]
cg@1120
  2529
	].
cg@1120
  2530
	self layoutChanged
cg@60
  2531
    ]
cg@60
  2532
cg@60
  2533
!
cg@60
  2534
cg@60
  2535
alignSelectionTopAndBottom
ca@61
  2536
    "align selection to the top/bottom of the first object in the selection; in case
ca@61
  2537
     of one selection the object is aligned to the top/bottom of its superview
ca@61
  2538
    "
ca@128
  2539
    |tmost bmost sel|
ca@128
  2540
sv@2481
  2541
    (sel := self resizableSelection) notNil ifTrue:[
cg@1954
  2542
        self withSelectionHiddenDo:[
cg@1954
  2543
            self numberOfSelections > 1 ifTrue:[
cg@1954
  2544
                tmost := (sel first) computeOrigin y.
cg@1954
  2545
                bmost := (sel first) computeCorner y.
cg@1954
  2546
cg@1954
  2547
                self transaction:#alignTopBottom selectionDo:[:aView|
cg@1954
  2548
                    |layout|
sv@2481
  2549
                    aView superView isLayoutWrapper ifTrue:[
sv@2481
  2550
                        "change size only"
cg@1954
  2551
                        self createUndoLayout:aView.
sv@2481
  2552
                        aView height:sel first height.
sv@2481
  2553
                        self elementChangedSize:aView
sv@2481
  2554
                    ] ifFalse:[
sv@2481
  2555
                        layout := self class asLayoutFrameFromView:aView.
sv@2481
  2556
sv@2481
  2557
                        layout notNil ifTrue:[
sv@2481
  2558
                            self createUndoLayout:aView.
sv@2481
  2559
                            aView geometryLayout:layout.
sv@2481
  2560
sv@2481
  2561
                            undoHistory withoutTransactionDo:[
sv@2481
  2562
                                self shiftLayout:aView top:(tmost - (aView computeOrigin y))
sv@2481
  2563
                                                    bottom:(bmost - (aView computeCorner y)).
sv@2481
  2564
                            ].
sv@2481
  2565
                            self elementChangedSize:aView
cg@1954
  2566
                        ].
sv@2481
  2567
                    ].
cg@1954
  2568
                ]
cg@1954
  2569
            ] ifFalse:[
cg@1954
  2570
                self extentToFrame:#TopBottom do:[:aLayout|
cg@1954
  2571
                    aLayout topOffset:0.
cg@1954
  2572
                    aLayout topFraction:0.0.
cg@1954
  2573
                    aLayout bottomOffset:0.
cg@1954
  2574
                    aLayout bottomFraction:1.0.
cg@1954
  2575
                ]
cg@1954
  2576
            ]
cg@1954
  2577
        ].
cg@1954
  2578
        self layoutChanged
cg@60
  2579
    ]
cg@60
  2580
!
cg@60
  2581
cg@60
  2582
centerSelection:aOneArgBlockXorY orientation:orientation
cg@60
  2583
    "center selection horizontal or vertical dependant on the block result( x or y).
cg@60
  2584
     The argument to the block is the point.
cg@60
  2585
    "
cg@60
  2586
    |superview min max delta val|
cg@60
  2587
ca@128
  2588
    (self moveableSelection) isNil ifTrue:[
cg@1120
  2589
	^ self
ca@61
  2590
    ].
ca@61
  2591
ca@61
  2592
    self withSelectionHiddenDo:[
cg@1120
  2593
	max := 0.
cg@1120
  2594
cg@1120
  2595
	self selectionDo:[:aView |
cg@1120
  2596
	    superview isNil ifTrue:[
cg@1120
  2597
		superview := self findContainerOfView:aView
cg@1120
  2598
	    ] ifFalse:[
cg@1120
  2599
		(self findContainerOfView:aView) == superview ifFalse:[
cg@1120
  2600
		    ^ self notify:'views must have same superview'.
cg@1120
  2601
		]
cg@1120
  2602
	    ].
cg@1120
  2603
	    val := aOneArgBlockXorY value:(aView computeOrigin).    
cg@1120
  2604
cg@1120
  2605
	    min isNil ifTrue:[min := val]
cg@1120
  2606
		     ifFalse:[min := min min:val].
cg@1120
  2607
cg@1120
  2608
	    val := aOneArgBlockXorY value:(aView computeCorner).
cg@1120
  2609
	    max := max max:val.
cg@1120
  2610
	].
cg@1120
  2611
cg@1120
  2612
	val := aOneArgBlockXorY value:(superview computeExtent).
cg@1120
  2613
	max := (min + val - max) // 2.
cg@1120
  2614
cg@1120
  2615
	max == min ifFalse:[
cg@1120
  2616
	    |type|
cg@1120
  2617
	    (orientation == #y) ifTrue:[type := #centerVertical]
cg@1120
  2618
			       ifFalse:[type := #centerHorizontal].
cg@1120
  2619
	    delta := max - min.
cg@1120
  2620
cg@1120
  2621
	    self transaction:type selectionDo:[:v|
cg@1120
  2622
		orientation == #y ifTrue:[
cg@1120
  2623
		    self shiftLayout:v top:delta bottom:delta
cg@1120
  2624
		] ifFalse:[
cg@1120
  2625
		    self shiftLayout:v left:delta right:delta
cg@1120
  2626
		]
cg@1120
  2627
	    ]
cg@1120
  2628
	].
cg@1120
  2629
	self layoutChanged
cg@60
  2630
    ]
cg@60
  2631
cg@60
  2632
cg@60
  2633
!
cg@60
  2634
cg@60
  2635
centerSelectionHor
cg@60
  2636
    "center selection horizontal
cg@60
  2637
    "
cg@60
  2638
    self centerSelection:[:aPoint| aPoint x] orientation:#x
cg@60
  2639
cg@60
  2640
cg@60
  2641
!
cg@60
  2642
cg@60
  2643
centerSelectionVer
cg@60
  2644
    "center selection vertical
cg@60
  2645
    "
cg@60
  2646
    self centerSelection:[:aPoint| aPoint y] orientation:#y
cg@60
  2647
!
cg@60
  2648
ca@72
  2649
extentToFrame:toWhat do:aBlock
ca@72
  2650
    "align to frame (Left Right ...) and perform the block on a frameLayout
ca@72
  2651
    "
ca@72
  2652
    |layout type|
ca@72
  2653
ca@72
  2654
    type := ('extent', toWhat asString) asSymbol.
ca@72
  2655
ca@72
  2656
    self transaction:type selectionDo:[:aView|
cg@1120
  2657
	layout := self class asLayoutFrameFromView:aView.
cg@1120
  2658
cg@1120
  2659
	layout notNil ifTrue:[
cg@1120
  2660
	    self createUndoLayout:aView.
cg@1120
  2661
	    aBlock value:layout.
cg@1120
  2662
	    aView geometryLayout:layout.
cg@1120
  2663
	    self elementChangedSize:aView.
cg@1120
  2664
	]
ca@72
  2665
    ]
ca@72
  2666
!
ca@72
  2667
cg@60
  2668
spreadSelectionHor
ca@61
  2669
    "spread multiple selection horizontal
ca@61
  2670
    "
ca@128
  2671
    |sumWidths min max viewsInOrder topsInOrder count space sel|
ca@128
  2672
ca@128
  2673
    sel := self moveableSelection.
ca@128
  2674
ca@128
  2675
    (sel notNil and:[self numberOfSelections > 1]) ifFalse:[
cg@1120
  2676
	^ self
cg@60
  2677
    ].
cg@60
  2678
ca@61
  2679
    self withSelectionHiddenDo:[
cg@1120
  2680
	count := 0.
cg@1120
  2681
	sumWidths := 0.
cg@1120
  2682
	max := 0.
cg@1120
  2683
cg@1120
  2684
	self selectionDo:[:aView |
cg@1120
  2685
	    sumWidths := sumWidths + aView width.
cg@1120
  2686
cg@1120
  2687
	    min isNil ifTrue:[min := aView left]
cg@1120
  2688
		     ifFalse:[min := min min:(aView left)].
cg@1120
  2689
cg@1120
  2690
	    max := max max:(aView right).
cg@1120
  2691
	    count := count + 1
cg@1120
  2692
	].
cg@1120
  2693
	viewsInOrder := Array withAll:sel.
cg@1120
  2694
	topsInOrder  := viewsInOrder collect:[:aView | aView left].
cg@1120
  2695
	topsInOrder sortWith:viewsInOrder.
cg@1120
  2696
cg@1120
  2697
	space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger.
cg@1120
  2698
cg@1120
  2699
	self transaction:#spreadHorizontal objects:viewsInOrder do:[:aView|
cg@1120
  2700
	    |delta|
cg@1120
  2701
cg@1120
  2702
	    delta := min - aView computeOrigin x.
cg@1120
  2703
	    self shiftLayout:aView left:delta right:delta.
cg@1120
  2704
	    min := min + aView computeExtent x + space
cg@1120
  2705
	]
ca@61
  2706
    ].
ca@225
  2707
    self layoutChanged
cg@60
  2708
cg@60
  2709
!
cg@60
  2710
cg@60
  2711
spreadSelectionVer
ca@61
  2712
    "spread multiple selection vertical
ca@61
  2713
    "
ca@128
  2714
    |sumHeights min max viewsInOrder topsInOrder count space sel|
ca@128
  2715
ca@128
  2716
    sel := self moveableSelection.
ca@128
  2717
ca@128
  2718
    (sel notNil and:[self numberOfSelections > 1]) ifFalse:[
cg@1120
  2719
	^ self
cg@60
  2720
    ].
cg@60
  2721
ca@61
  2722
    self withSelectionHiddenDo:[
cg@1120
  2723
	count := 0.
cg@1120
  2724
	sumHeights := 0.
cg@1120
  2725
	max := 0.
cg@1120
  2726
cg@1120
  2727
	self selectionDo:[:aView |
cg@1120
  2728
	    sumHeights := sumHeights + aView height.
cg@1120
  2729
cg@1120
  2730
	    min isNil ifTrue:[min := aView top]
cg@1120
  2731
		     ifFalse:[min := min min:(aView top)].
cg@1120
  2732
cg@1120
  2733
	    max   := max max:(aView bottom).
cg@1120
  2734
	    count := count + 1
cg@1120
  2735
	].
cg@1120
  2736
	viewsInOrder := Array withAll:sel.
cg@1120
  2737
	topsInOrder  := viewsInOrder collect:[:aView|aView top].
cg@1120
  2738
	topsInOrder sortWith:viewsInOrder.
cg@1120
  2739
cg@1120
  2740
	space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger.
cg@1120
  2741
cg@1120
  2742
	self transaction:#spreadVertical objects:viewsInOrder do:[:aView|
cg@1120
  2743
	    |delta|
cg@1120
  2744
cg@1120
  2745
	    delta := min - aView computeOrigin y.
cg@1120
  2746
	    self shiftLayout:aView top:delta bottom:delta.
cg@1120
  2747
	    min := min + aView height + space
cg@1120
  2748
	]
ca@61
  2749
    ].
ca@225
  2750
    self layoutChanged
cg@60
  2751
! !
cg@60
  2752
cg@1715
  2753
!UIObjectView methodsFor:'user actions-undo history'!
cg@60
  2754
ca@72
  2755
enableUndoHistory:aState
cg@1954
  2756
    "enable or disable undo history"
cg@1954
  2757
ca@72
  2758
    undoHistory enabled:aState
ca@72
  2759
!
ca@72
  2760
cg@60
  2761
openUndoMenu
ca@149
  2762
    self select:nil.
ca@138
  2763
    undoHistory openUndoMenu
cg@60
  2764
!
cg@60
  2765
cg@60
  2766
removeUndoHistory
cg@1954
  2767
    "delete total undo history"
cg@1954
  2768
cg@1954
  2769
    undoHistory initializeFor:self.
cg@1954
  2770
    self undoHistoryChanged
cg@60
  2771
!
cg@60
  2772
cg@60
  2773
undoLast
cg@1954
  2774
    "undo last action"
cg@1954
  2775
ca@138
  2776
    |newSel oldSel|
ca@138
  2777
cg@1954
  2778
    undoHistory notEmpty ifTrue:[
cg@1954
  2779
        self hasSelection ifTrue:[
cg@1954
  2780
            oldSel := OrderedCollection new.
cg@1954
  2781
            newSel := OrderedCollection new.
cg@1954
  2782
cg@1954
  2783
            self selectionDo:[:aView||p|
cg@1954
  2784
                (p := self propertyOfView:aView) notNil ifTrue:[
cg@1954
  2785
                    oldSel add:(p identifier)
cg@1954
  2786
                ]
cg@1954
  2787
            ].
cg@1954
  2788
            self setSelection:nil withRedraw:true.
cg@1954
  2789
        ].
cg@1954
  2790
cg@1954
  2791
        self withSelectionHiddenDo:[undoHistory undoLast:1].
cg@1954
  2792
cg@1954
  2793
        oldSel notNil ifTrue:[
cg@1954
  2794
            oldSel do:[:id||v|
cg@1954
  2795
                (v := self findViewWithId:id) notNil ifTrue:[newSel add:v]
cg@1954
  2796
            ].
cg@1954
  2797
            self select:newSel.
cg@1954
  2798
        ].
cg@1954
  2799
        self undoHistoryChanged.
ca@61
  2800
    ].
cg@60
  2801
! !
cg@60
  2802
ca@1672
  2803
!UIObjectView::PostEventHandler methodsFor:'event handling'!
ca@1672
  2804
ca@1672
  2805
processEvent:anEvent
ca@1672
  2806
    |evView|
ca@1672
  2807
ca@1672
  2808
    anEvent isDamage ifTrue:[
ca@1672
  2809
        onView testMode ifFalse:[
ca@1672
  2810
            evView := anEvent view.
ca@1672
  2811
ca@1672
  2812
            (onView isSelected:evView) ifTrue:[
ca@1672
  2813
                onView showSelected:evView.
ca@1672
  2814
            ]
ca@1672
  2815
        ]
ca@1672
  2816
    ].
ca@1672
  2817
    ^ false
ca@1672
  2818
! !
ca@1672
  2819
ca@1672
  2820
!UIObjectView::PostEventHandler methodsFor:'instance creation'!
ca@1672
  2821
ca@1672
  2822
onView:aView
ca@1672
  2823
    onView := aView.
ca@1672
  2824
! !
ca@1672
  2825
ca@1437
  2826
!UIObjectView::ResizeData methodsFor:'accessing'!
ca@1437
  2827
cg@2536
  2828
checkForChangeSelector
cg@2536
  2829
    ^ checkForChangeSelector
cg@2536
  2830
!
cg@2536
  2831
ca@1437
  2832
delta
ca@1437
  2833
    ^ delta
ca@1437
  2834
ca@1437
  2835
    "Created: / 2.2.1998 / 13:40:32 / cg"
ca@1437
  2836
!
ca@1437
  2837
ca@1437
  2838
object
ca@1437
  2839
    ^ object
ca@1437
  2840
ca@1437
  2841
    "Created: / 2.2.1998 / 13:40:24 / cg"
ca@1437
  2842
!
ca@1437
  2843
cg@2536
  2844
object:anObject selector:selectorArg checkForChangeSelector:checkForChangeSelectorArg delta:anInteger