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