Tools__ViewTreeItem.st
author Claus Gittinger <cg@exept.de>
Wed, 29 Jul 2009 20:02:02 +0200
changeset 2570 4e663bc64364
parent 2456 3d8a5dd293ba
permissions -rw-r--r--
changed #requestPackage
ca@2178
     1
"{ Package: 'stx:libtool2' }"
ca@2178
     2
ca@2178
     3
"{ NameSpace: Tools }"
ca@2178
     4
ca@2178
     5
HierarchicalItem subclass:#ViewTreeItem
ca@2452
     6
	instanceVariableNames:'widget isDrawnShown exists xOffsetAdditionalName'
ca@2178
     7
	classVariableNames:'HandleExtent'
ca@2178
     8
	poolDictionaries:''
ca@2178
     9
	category:'A-Views-Support'
ca@2178
    10
!
ca@2178
    11
ca@2178
    12
!ViewTreeItem class methodsFor:'documentation'!
ca@2178
    13
ca@2178
    14
documentation
ca@2178
    15
"
ca@2178
    16
    ViewTreeItems represants a pickable object within a ViewTreeModel.
ca@2178
    17
    The class is used to build up the hierarchical tree.
ca@2178
    18
ca@2178
    19
    [Instance variables:]
ca@2178
    20
        widget        <View>            the widget represented by the item
ca@2178
    21
        spec          <UISpecification> the UISpecification or nil
ca@2178
    22
ca@2178
    23
    [Class variables:]
ca@2178
    24
        HandleExtent  <Point>           keeps the extent of a handle
ca@2178
    25
ca@2178
    26
ca@2178
    27
    [author:]
ca@2178
    28
        Claus Atzkern
ca@2178
    29
ca@2178
    30
    [see also:]
ca@2178
    31
        HierarchicalItem
ca@2178
    32
        ViewTreeModel
ca@2178
    33
"
ca@2178
    34
! !
ca@2178
    35
ca@2178
    36
!ViewTreeItem class methodsFor:'initialization'!
ca@2178
    37
ca@2178
    38
initialize
ca@2178
    39
    "set the extent of the Handle
ca@2178
    40
    "
ca@2178
    41
    HandleExtent := 6@6.
ca@2178
    42
! !
ca@2178
    43
ca@2178
    44
!ViewTreeItem class methodsFor:'instance creation'!
ca@2178
    45
ca@2178
    46
forView:aView
ca@2178
    47
    |item|
ca@2178
    48
ca@2178
    49
    item := self basicNew initialize.
ca@2178
    50
    item forView:aView.
ca@2178
    51
  ^ item
ca@2178
    52
!
ca@2178
    53
ca@2178
    54
new
ca@2178
    55
    self error:'not allowed'.
ca@2178
    56
  ^ nil
ca@2178
    57
!
ca@2178
    58
ca@2178
    59
on:aView withSpec:aSpec
ca@2178
    60
    |item|
ca@2178
    61
ca@2178
    62
    item := self basicNew initialize.
ca@2178
    63
    item on:aView withSpec:aSpec.
ca@2178
    64
  ^ item
ca@2178
    65
! !
ca@2178
    66
ca@2178
    67
!ViewTreeItem class methodsFor:'building'!
ca@2178
    68
ca@2178
    69
buildViewsFrom:aView
ca@2178
    70
    "build the items starting from a source view;
ca@2178
    71
     returns the anhor.
ca@2178
    72
    "
ca@2178
    73
    |item subViews subItems|
ca@2178
    74
ca@2178
    75
    aView isNil ifTrue:[^ nil].
ca@2178
    76
ca@2178
    77
    item     := self forView:aView.
ca@2178
    78
    subViews := aView subViews.
ca@2178
    79
ca@2178
    80
    subViews notEmptyOrNil ifTrue:[
ca@2178
    81
        subItems := OrderedCollection new.
ca@2178
    82
        subViews do:[:aSubView|
ca@2178
    83
            subItems add:(self buildViewsFrom:aSubView).
ca@2178
    84
        ].
ca@2178
    85
        item children:subItems.
ca@2178
    86
    ].
ca@2178
    87
    ^ item
ca@2178
    88
! !
ca@2178
    89
ca@2178
    90
!ViewTreeItem methodsFor:'accessing'!
ca@2178
    91
ca@2178
    92
applicationClass
ca@2178
    93
    |appl|
ca@2178
    94
ca@2178
    95
    widget notNil ifTrue:[
ca@2178
    96
        appl := widget application.
ca@2178
    97
        appl notNil ifTrue:[^ appl class ].
ca@2178
    98
    ].
ca@2178
    99
    ^ nil
ca@2178
   100
!
ca@2178
   101
ca@2178
   102
isDrawnShown
ca@2178
   103
    "returns true if the last display operations was done during the widget was shown
ca@2178
   104
    "
ca@2178
   105
    ^ isDrawnShown
ca@2178
   106
!
ca@2178
   107
ca@2178
   108
isDrawnShown:aBoolean
ca@2178
   109
    isDrawnShown := aBoolean.
ca@2178
   110
!
ca@2178
   111
ca@2178
   112
rootView
ca@2178
   113
    "returns the widget assigned to the root or nil
ca@2178
   114
    "
ca@2178
   115
    ^ parent rootView
ca@2178
   116
!
ca@2178
   117
ca@2178
   118
specClass
ca@2178
   119
    "returns the spec-class assigned to the item
ca@2178
   120
    "
ca@2178
   121
    ^ widget specClass
ca@2178
   122
!
ca@2178
   123
ca@2178
   124
treeModel
ca@2178
   125
    "returns the assigned treeModel, an instance of ViewTreeModel
ca@2178
   126
    "
ca@2178
   127
    ^ parent treeModel
ca@2178
   128
!
ca@2178
   129
ca@2178
   130
widget
ca@2178
   131
    "returns the widget assigned to the item
ca@2178
   132
    "
ca@2178
   133
    ^ widget
ca@2178
   134
! !
ca@2178
   135
ca@2178
   136
!ViewTreeItem methodsFor:'accessing layout'!
ca@2178
   137
ca@2178
   138
boundsRelativeToRoot
ca@2178
   139
    "returns the bounds relative to the root widget
ca@2178
   140
    "
ca@2178
   141
    ^ self originRelativeToRoot extent:(widget extent)
ca@2178
   142
!
ca@2178
   143
ca@2178
   144
cornerRelativeToRoot
ca@2178
   145
    "returns the corner relative to the root widget
ca@2178
   146
    "
ca@2178
   147
    ^ self originRelativeToRoot + (widget extent)
ca@2178
   148
!
ca@2178
   149
ca@2178
   150
extent
ca@2178
   151
    "returns the extent of the widget
ca@2178
   152
    "
ca@2178
   153
    ^ widget extent
ca@2178
   154
!
ca@2178
   155
ca@2178
   156
layoutType
ca@2178
   157
    "returns the type of layout assigned to the wiget; nil if the
ca@2178
   158
     superView cannot resize its sub widgets
ca@2178
   159
    "
ca@2178
   160
    |layout specClass superView|
ca@2178
   161
ca@2178
   162
    (superView := widget superView) isNil ifTrue:[
ca@2178
   163
        ^ #Extent
ca@2178
   164
    ].
ca@2178
   165
        
ca@2178
   166
    specClass := superView specClass.
ca@2178
   167
ca@2178
   168
    (specClass notNil and:[specClass isLayoutContainer]) ifTrue:[
ca@2178
   169
        ^ specClass canResizeSubComponents ifTrue:[#Extent] ifFalse:[nil]
ca@2178
   170
    ].
ca@2178
   171
ca@2178
   172
    (layout := widget geometryLayout) isNil ifTrue:[
ca@2178
   173
        ^ #Extent
ca@2178
   174
    ].
ca@2178
   175
ca@2178
   176
    layout isLayout ifTrue:[
ca@2178
   177
        layout isLayoutFrame        ifTrue:[ ^ #LayoutFrame ].
ca@2178
   178
        layout isAlignmentOrigin    ifTrue:[ ^ #AlignmentOrigin ].
ca@2178
   179
        layout isLayoutOrigin       ifTrue:[ ^ #LayoutOrigin ].
ca@2178
   180
    ] ifFalse:[
ca@2178
   181
        layout isRectangle          ifTrue:[ ^ #Rectangle ].
ca@2178
   182
        layout isPoint              ifTrue:[ ^ #Point ].
ca@2178
   183
ca@2178
   184
    ].
ca@2178
   185
    Transcript showCR:'UNSUPPORTRD LAYOUT: ', layout printString.
ca@2178
   186
  ^ nil
ca@2178
   187
!
ca@2178
   188
ca@2178
   189
originRelativeToRoot
ca@2178
   190
    "returns the origin relative to the root widget
ca@2178
   191
    "
ca@2178
   192
    ^ widget originRelativeTo:(self rootView)
ca@2178
   193
! !
ca@2178
   194
ca@2178
   195
!ViewTreeItem methodsFor:'accessing optimize'!
ca@2178
   196
ca@2178
   197
children
ca@2178
   198
    "redefined: optimize
ca@2178
   199
    "
ca@2178
   200
    ^ children
ca@2178
   201
!
ca@2178
   202
ca@2178
   203
hasChildren
ca@2178
   204
    |subViews list item|
ca@2178
   205
ca@2178
   206
    children size ~~ 0 ifTrue:[
ca@2178
   207
        ^ true
ca@2178
   208
    ].
ca@2178
   209
    isExpanded := false.
ca@2178
   210
    subViews   := widget subViews.
ca@2178
   211
ca@2178
   212
    subViews size == 0 ifTrue:[^ false].
ca@2178
   213
ca@2178
   214
    list := OrderedCollection new.
ca@2178
   215
ca@2178
   216
    subViews do:[:aSubView|
ca@2178
   217
        item := self class buildViewsFrom:aSubView.
ca@2178
   218
        item parent:self.
ca@2178
   219
        list add:item.
ca@2178
   220
    ].
ca@2178
   221
    children := list.
ca@2178
   222
    ^ true
ca@2178
   223
!
ca@2178
   224
ca@2178
   225
size
ca@2178
   226
    "redefined: returns list of children
ca@2178
   227
    "
ca@2178
   228
    ^ children size
ca@2178
   229
! !
ca@2178
   230
ca@2178
   231
!ViewTreeItem methodsFor:'displaying'!
ca@2178
   232
ca@2452
   233
additionalLabelForItem:anItem
ca@2452
   234
    "answer an additional item for an Item or nil"
ca@2452
   235
ca@2452
   236
    parent notNil ifTrue:[
ca@2452
   237
        ^ parent additionalLabelForItem:anItem
ca@2452
   238
    ].
ca@2452
   239
    ^ nil
ca@2452
   240
!
ca@2452
   241
ca@2456
   242
displayIcon:anIcon atX:x y:y on:aGC
ca@2456
   243
    |x0 y0 y1 w|
ca@2456
   244
ca@2456
   245
    super displayIcon:anIcon atX:x y:y on:aGC.
ca@2456
   246
ca@2456
   247
    self exists ifFalse:[
ca@2456
   248
        aGC paint:(Color red).
ca@2456
   249
ca@2456
   250
        y0 := y + 1.
ca@2456
   251
        y1 := y + anIcon height - 2.
ca@2456
   252
ca@2456
   253
        x0 := x - 1.
ca@2456
   254
        w  := anIcon width.
ca@2456
   255
ca@2456
   256
        2 timesRepeat:[
ca@2456
   257
            aGC displayLineFromX:x0 y:y0 toX:(x0 + w) y:y1.
ca@2456
   258
            aGC displayLineFromX:x0 y:y1 toX:(x0 + w) y:y0.
ca@2456
   259
            x0 := x0 + 1.
ca@2456
   260
        ].
ca@2456
   261
    ].
ca@2456
   262
!
ca@2456
   263
ca@2178
   264
displayOn:aGC x:x y:y h:h
ca@2456
   265
    |labelHeight additionalName label isValidAndShown|
ca@2456
   266
ca@2456
   267
    label := self label.
ca@2456
   268
    label isEmptyOrNil ifTrue:[^ self].
ca@2178
   269
ca@2178
   270
    widget id isNil ifTrue:[
ca@2178
   271
        isDrawnShown := false.
ca@2456
   272
ca@2456
   273
        self exists ifFalse:[
ca@2456
   274
            xOffsetAdditionalName := nil.
ca@2456
   275
        ].
ca@2456
   276
        isValidAndShown := false.
ca@2178
   277
    ] ifFalse:[
ca@2456
   278
        isValidAndShown := widget shown.
ca@2178
   279
    ].
ca@2456
   280
    isValidAndShown ifFalse:[
ca@2456
   281
        label := Text string:label emphasis:#italic
ca@2456
   282
    ].
ca@2178
   283
ca@2178
   284
    labelHeight := self heightOn:aGC.
ca@2456
   285
    self displayLabel:label h:labelHeight on:aGC x:x y:y h:h.
ca@2178
   286
ca@2452
   287
    xOffsetAdditionalName notNil ifTrue:[
ca@2452
   288
        additionalName := self additionalLabelForItem:self.
ca@2452
   289
ca@2452
   290
        additionalName notNil ifTrue:[
ca@2452
   291
            self displayLabel:additionalName
ca@2178
   292
                            h:labelHeight on:aGC
ca@2452
   293
                            x:(x + xOffsetAdditionalName)
ca@2178
   294
                            y:y
ca@2178
   295
                            h:h.
ca@2452
   296
        ] ifFalse:[
ca@2452
   297
            xOffsetAdditionalName := nil.
ca@2178
   298
        ].
ca@2178
   299
    ].
ca@2178
   300
!
ca@2178
   301
ca@2452
   302
recursiveAdditionalNameBehaviourChanged
ca@2452
   303
    width := xOffsetAdditionalName := nil.
ca@2405
   304
ca@2452
   305
    children notNil ifTrue:[
ca@2452
   306
        children do:[:each| each recursiveAdditionalNameBehaviourChanged ]
ca@2405
   307
    ].
ca@2405
   308
!
ca@2405
   309
ca@2178
   310
widthOn:aGC
ca@2178
   311
    "return the width of the receiver, if it is to be displayed on aGC
ca@2178
   312
    "
ca@2452
   313
    |additionalName|
ca@2405
   314
ca@2178
   315
    width isNil ifTrue:[
ca@2178
   316
        width := self widthOf:(self label) on:aGC.
ca@2178
   317
        width := width + 2.
ca@2405
   318
ca@2452
   319
        additionalName := self additionalLabelForItem:self.
ca@2405
   320
ca@2452
   321
        additionalName notNil ifTrue:[
ca@2452
   322
            xOffsetAdditionalName := width + 10.
ca@2452
   323
            width := xOffsetAdditionalName + (self widthOf:additionalName on:aGC).
ca@2405
   324
            width := width + 2.
ca@2452
   325
        ] ifFalse:[
ca@2452
   326
            xOffsetAdditionalName := nil.
ca@2405
   327
        ].
ca@2178
   328
    ].
ca@2178
   329
    ^ width
ca@2178
   330
! !
ca@2178
   331
ca@2178
   332
!ViewTreeItem methodsFor:'enumerating'!
ca@2178
   333
ca@2178
   334
handlesDo:aTwoArgAction
ca@2178
   335
    "evaluate the two arg block on each handle; the arguments to the block is
ca@2178
   336
     the rectangle relative to the rootView and the handle type which is
ca@2178
   337
     set to nil if not resizeable.
ca@2178
   338
ca@2178
   339
     TYPES:     type    position( X - Y )
ca@2178
   340
                -------------------------        
ca@2178
   341
                #LT     Left   - Top
ca@2178
   342
                #LC     Left   - Center
ca@2178
   343
                #LB     Left   - Bottom
ca@2178
   344
                #CT     Center - Top
ca@2178
   345
                #CB     Center - Bottom
ca@2178
   346
                #RT     Right  - Top
ca@2178
   347
                #RC     Right  - Center
ca@2178
   348
                #RB     Right  - Bottom
ca@2178
   349
ca@2178
   350
                nil     ** handle not pickable **
ca@2178
   351
    "
ca@2178
   352
    |type relOrg relCrn maxExt rootView w h
ca@2178
   353
     xL    "{ Class:SmallInteger }"
ca@2178
   354
     xC    "{ Class:SmallInteger }"
ca@2178
   355
     xR    "{ Class:SmallInteger }"
ca@2178
   356
     yT    "{ Class:SmallInteger }"
ca@2178
   357
     yC    "{ Class:SmallInteger }"
ca@2178
   358
     yB    "{ Class:SmallInteger }"
ca@2178
   359
    |
ca@2178
   360
    rootView := self rootView.
ca@2178
   361
    relOrg   := widget originRelativeTo:rootView.
ca@2178
   362
    relOrg isNil ifTrue:[ ^ self ].    "/ widget destroyed
ca@2178
   363
ca@2178
   364
    relOrg   := relOrg - (HandleExtent // 2).
ca@2178
   365
    relCrn   := relOrg + widget extent.
ca@2178
   366
    maxExt   := rootView extent - HandleExtent.
ca@2178
   367
ca@2178
   368
    xL := relOrg x max:0.
ca@2178
   369
    xR := relCrn x min:(maxExt x).
ca@2178
   370
    xC := xR + xL // 2.
ca@2178
   371
ca@2178
   372
    yT := relOrg y max:0.
ca@2178
   373
    yB := relCrn y min:(maxExt y).
ca@2178
   374
    yC := yB + yT // 2.
ca@2178
   375
ca@2178
   376
    type := self layoutType.
ca@2178
   377
    w   := HandleExtent x.
ca@2178
   378
    h   := HandleExtent y.
ca@2178
   379
ca@2178
   380
    (type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[
ca@2178
   381
        aTwoArgAction value:(Rectangle left:xL top:yT width:w height:h) value:#LT.
ca@2178
   382
        aTwoArgAction value:(Rectangle left:xL top:yC width:w height:h) value:#LC.
ca@2178
   383
        aTwoArgAction value:(Rectangle left:xL top:yB width:w height:h) value:#LB.
ca@2178
   384
        aTwoArgAction value:(Rectangle left:xC top:yT width:w height:h) value:#CT.
ca@2178
   385
        aTwoArgAction value:(Rectangle left:xC top:yB width:w height:h) value:#CB.
ca@2178
   386
        aTwoArgAction value:(Rectangle left:xR top:yT width:w height:h) value:#RT.
ca@2178
   387
        aTwoArgAction value:(Rectangle left:xR top:yC width:w height:h) value:#RC.
ca@2178
   388
        aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:#RB.
ca@2178
   389
      ^ self
ca@2178
   390
    ].
ca@2178
   391
ca@2178
   392
    aTwoArgAction value:(Rectangle left:xL top:yT width:w height:h) value:nil.
ca@2178
   393
    aTwoArgAction value:(Rectangle left:xL top:yB width:w height:h) value:nil.
ca@2178
   394
    aTwoArgAction value:(Rectangle left:xR top:yT width:w height:h) value:nil.
ca@2178
   395
ca@2178
   396
    type == #Extent ifTrue:[
ca@2178
   397
        aTwoArgAction value:(Rectangle left:xC top:yB width:w height:h) value:#CB.
ca@2178
   398
        aTwoArgAction value:(Rectangle left:xR top:yC width:w height:h) value:#RC.
ca@2178
   399
        aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:#RB.
ca@2178
   400
      ^ self
ca@2178
   401
    ].
ca@2178
   402
    aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:nil.
ca@2178
   403
!
ca@2178
   404
ca@2178
   405
recursiveEachVisibleItemDo:anOneArgBlock
ca@2178
   406
    "recursive evaluate the block on each child which is visible
ca@2178
   407
    "
ca@2178
   408
    (isExpanded and:[children size > 0]) ifTrue:[
ca@2178
   409
        children do:[:aChild|
ca@2178
   410
            anOneArgBlock value:aChild.
ca@2178
   411
            aChild recursiveEachVisibleItemDo:anOneArgBlock.
ca@2178
   412
        ]
ca@2178
   413
    ].
ca@2178
   414
!
ca@2178
   415
ca@2178
   416
subViewsDo:aOneArgBlock
ca@2178
   417
    "evaluate aBlock for all subviews other than InputView's   
ca@2178
   418
    "
ca@2178
   419
    |subViews|
ca@2178
   420
ca@2178
   421
    subViews := widget subViews.
ca@2178
   422
ca@2178
   423
    subViews notNil ifTrue:[
ca@2178
   424
        subViews do:aOneArgBlock
ca@2178
   425
    ].
ca@2178
   426
! !
ca@2178
   427
ca@2178
   428
!ViewTreeItem methodsFor:'initialization'!
ca@2178
   429
ca@2178
   430
forView:aView
ca@2178
   431
    widget := aView.
ca@2178
   432
!
ca@2178
   433
ca@2178
   434
initialize
ca@2178
   435
    "setup default attributes
ca@2178
   436
    "
ca@2178
   437
    super initialize.
ca@2178
   438
    isDrawnShown := false.
ca@2178
   439
    isExpanded   := false.
ca@2178
   440
    children     := OrderedCollection new.
ca@2178
   441
! !
ca@2178
   442
ca@2178
   443
!ViewTreeItem methodsFor:'operations delete'!
ca@2178
   444
ca@2178
   445
delete
ca@2178
   446
    "delete self and all contained items; the assigned views are destroyed
ca@2178
   447
     in case of rootView, only the children are deleted
ca@2178
   448
    "
ca@2178
   449
    parent isHierarchicalItem ifTrue:[
ca@2178
   450
        self criticalDo:[
ca@2178
   451
            parent remove:self.
ca@2178
   452
            widget destroy.
ca@2178
   453
        ]
ca@2178
   454
    ] ifFalse:[
ca@2178
   455
        self deleteAll
ca@2178
   456
    ].
ca@2178
   457
!
ca@2178
   458
ca@2178
   459
deleteAll
ca@2178
   460
    "delete all contained items; the assigned views are destroyed
ca@2178
   461
    "
ca@2178
   462
    children size == 0 ifTrue:[^ self].
ca@2178
   463
ca@2178
   464
    self criticalDo:[
ca@2178
   465
        self nonCriticalDo:[:el| el widget destroy ].
ca@2178
   466
        self removeAll
ca@2178
   467
    ].
ca@2178
   468
! !
ca@2178
   469
ca@2178
   470
!ViewTreeItem methodsFor:'operations layout'!
ca@2178
   471
ca@2178
   472
asLayoutFrame
ca@2178
   473
    "convert the layout of the widget to a LayoutFrame;
ca@2178
   474
    "
ca@2178
   475
    |extent layout newLyt lftFrc lftOff topFrc topOff|
ca@2178
   476
ca@2178
   477
    layout := widget geometryLayout.
ca@2178
   478
ca@2178
   479
    layout isNil ifTrue:[
ca@2178
   480
        ^ widget bounds asLayout
ca@2178
   481
    ].
ca@2178
   482
ca@2178
   483
    layout isLayout ifFalse:[
ca@2178
   484
        layout isRectangle ifTrue:[
ca@2178
   485
            ^ LayoutFrame leftOffset:(layout left) rightOffset:(layout right)
ca@2178
   486
                           topOffset:(layout top) bottomOffset:(layout bottom)
ca@2178
   487
        ].
ca@2178
   488
        layout isPoint ifTrue:[
ca@2178
   489
            extent := widget extent.
ca@2178
   490
          ^ LayoutFrame leftOffset:(layout x)  rightOffset:(layout x + extent x)
ca@2178
   491
                         topOffset:(layout y) bottomOffset:(layout y + extent y)
ca@2178
   492
        ].
ca@2178
   493
ca@2178
   494
        Transcript showCR:'UNSUPPORTRD LAYOUT: ', layout printString.
ca@2178
   495
      ^ nil
ca@2178
   496
    ].
ca@2178
   497
ca@2178
   498
    layout isLayoutFrame ifTrue:[ ^ layout copy ].    
ca@2178
   499
ca@2178
   500
    lftFrc := layout leftFraction.
ca@2178
   501
    lftOff := layout leftOffset.
ca@2178
   502
    topFrc := layout topFraction.
ca@2178
   503
    topOff := layout topOffset.
ca@2178
   504
    extent := widget extent.
ca@2178
   505
ca@2178
   506
    newLyt := LayoutFrame leftFraction:lftFrc offset:lftOff
ca@2178
   507
                         rightFraction:lftFrc offset:(lftOff + extent x)
ca@2178
   508
                           topFraction:topFrc offset:topOff
ca@2178
   509
                        bottomFraction:topFrc offset:(topOff + extent y).
ca@2178
   510
ca@2178
   511
    (      layout isAlignmentOrigin
ca@2178
   512
     and:[(layout leftAlignmentFraction ~= 0 or:[layout topAlignmentFraction ~= 0])]
ca@2178
   513
    ) ifTrue:[
ca@2178
   514
        |svRc prBd dlta|
ca@2178
   515
ca@2178
   516
        svRc := widget superView viewRectangle.
ca@2178
   517
        prBd := widget preferredBounds.
ca@2178
   518
ca@2178
   519
        dlta := (  ((layout rectangleRelativeTo:svRc preferred:prBd) corner)
ca@2178
   520
                 - ((newLyt rectangleRelativeTo:svRc preferred:prBd) corner)
ca@2178
   521
                ) rounded.
ca@2178
   522
ca@2178
   523
        newLyt   leftOffset:(lftOff + dlta x).
ca@2178
   524
        newLyt  rightOffset:(lftOff + extent x + dlta x).
ca@2178
   525
        newLyt    topOffset:(topOff + dlta y).
ca@2178
   526
        newLyt bottomOffset:(topOff + extent y + dlta y).
ca@2178
   527
    ].
ca@2178
   528
    ^ newLyt
ca@2178
   529
!
ca@2178
   530
ca@2178
   531
moveLeft:l top:t
ca@2178
   532
    "move the widget n pixele left and right
ca@2178
   533
    "
ca@2178
   534
    |layout|
ca@2178
   535
ca@2178
   536
    self isMoveable ifFalse:[ ^ self ].
ca@2178
   537
ca@2178
   538
    (layout := widget geometryLayout) isNil ifTrue:[
ca@2178
   539
        "Extent"
ca@2178
   540
        widget origin:(widget origin + (l@t)).
ca@2178
   541
      ^ self
ca@2178
   542
    ].
ca@2178
   543
ca@2178
   544
    layout := layout copy.
ca@2178
   545
ca@2178
   546
    layout isLayout ifTrue:[
ca@2178
   547
        layout leftOffset:(layout leftOffset + l)
ca@2178
   548
                topOffset:(layout topOffset  + t).
ca@2178
   549
ca@2178
   550
        layout isLayoutFrame ifTrue:[
ca@2178
   551
            layout  rightOffset:(layout rightOffset  + l).
ca@2178
   552
            layout bottomOffset:(layout bottomOffset + t).
ca@2178
   553
        ]
ca@2178
   554
ca@2178
   555
    ] ifFalse:[
ca@2178
   556
        layout isRectangle ifTrue:[
ca@2178
   557
            layout setLeft:(layout left + l).
ca@2178
   558
            layout  setTop:(layout top  + t).
ca@2178
   559
        ] ifFalse:[
ca@2178
   560
            layout isPoint ifFalse:[^ self].
ca@2178
   561
            layout x:(layout x + l) y:(layout y + t).
ca@2178
   562
        ]
ca@2178
   563
    ].
ca@2178
   564
    widget geometryLayout:layout.
ca@2178
   565
!
ca@2178
   566
ca@2178
   567
resizeLeft:l top:t right:r bottom:b
ca@2178
   568
    "resize the widget measured in pixels
ca@2178
   569
    "
ca@2178
   570
    |layout|
ca@2178
   571
ca@2178
   572
    self isResizeable ifFalse:[
ca@2178
   573
        ^ self
ca@2178
   574
    ].
ca@2178
   575
ca@2178
   576
    (layout := widget geometryLayout) isNil ifTrue:[
ca@2178
   577
        "Extent"
ca@2178
   578
        (r == l and:[b == t]) ifFalse:[
ca@2178
   579
            widget extent:(widget computeExtent + ((r-l) @ (b-t))).
ca@2178
   580
        ].
ca@2178
   581
        ^ self
ca@2178
   582
    ].
ca@2178
   583
ca@2178
   584
    layout isLayout ifTrue:[
ca@2178
   585
        layout := layout copy.
ca@2178
   586
ca@2178
   587
        layout leftOffset:(layout leftOffset + l)
ca@2178
   588
                topOffset:(layout topOffset  + t).
ca@2178
   589
ca@2178
   590
        layout isLayoutFrame ifTrue:[
ca@2178
   591
            layout bottomOffset:(layout bottomOffset + b).
ca@2178
   592
            layout  rightOffset:(layout rightOffset  + r).
ca@2178
   593
        ]
ca@2178
   594
    ] ifFalse:[
ca@2178
   595
        layout isRectangle ifFalse:[^ self].
ca@2178
   596
        layout := layout copy.
ca@2178
   597
ca@2178
   598
        layout left:(layout left   + l)
ca@2178
   599
              right:(layout right  + r)
ca@2178
   600
                top:(layout top    + t)
ca@2178
   601
             bottom:(layout bottom + b).
ca@2178
   602
    ].
ca@2178
   603
    widget geometryLayout:layout.
ca@2178
   604
! !
ca@2178
   605
ca@2178
   606
!ViewTreeItem methodsFor:'operations update'!
ca@2178
   607
ca@2178
   608
updateChildren
ca@2178
   609
    |list|
ca@2178
   610
ca@2178
   611
    self do:[:el|
ca@2178
   612
        el exists ifTrue:[
ca@2178
   613
            el updateChildren.
ca@2178
   614
        ] ifFalse:[
ca@2178
   615
            list isNil ifTrue:[list := OrderedCollection new].
ca@2178
   616
            list add:el.
ca@2178
   617
        ]
ca@2178
   618
    ].
ca@2178
   619
    list notNil ifTrue:[
ca@2178
   620
        list do:[:el| self remove:el ].
ca@2178
   621
    ].
ca@2178
   622
!
ca@2178
   623
ca@2178
   624
updateFromChildren:mergedList
ca@2178
   625
    "update my children against the list of items derived from
ca@2178
   626
     the merged list.
ca@2178
   627
    "
ca@2178
   628
ca@2178
   629
    mergedList size == 0 ifTrue:[ ^ self removeAll ].
ca@2178
   630
    children   size == 0 ifTrue:[ ^ self addAll:mergedList ].
ca@2178
   631
ca@2178
   632
    self criticalDo:[
ca@2178
   633
        self nonCriticalDo:[:el| |wdg|
ca@2178
   634
            wdg := el widget.
ca@2178
   635
            mergedList detect:[:e2| e2 widget == wdg ] ifNone:[ self remove:el ].
ca@2178
   636
        ].
ca@2178
   637
ca@2178
   638
        mergedList keysAndValuesDo:[:i :el| |wdg e2|
ca@2178
   639
            wdg := el widget.
ca@2178
   640
ca@2178
   641
            e2  := self at:i ifAbsent:nil.
ca@2178
   642
ca@2178
   643
            (e2 isNil or:[e2 widget ~~ wdg]) ifTrue:[
ca@2178
   644
                self add:el beforeIndex:i
ca@2178
   645
            ]
ca@2178
   646
        ]
ca@2178
   647
    ].
ca@2178
   648
! !
ca@2178
   649
ca@2178
   650
!ViewTreeItem methodsFor:'printing & storing'!
ca@2178
   651
ca@2178
   652
icon
ca@2178
   653
    "get the icon used for presentation
ca@2178
   654
    "
ca@2178
   655
    |specClass model|
ca@2178
   656
ca@2178
   657
    specClass := self specClass.
ca@2178
   658
    specClass isNil ifTrue:[^ nil].
ca@2178
   659
ca@2178
   660
    model := self treeModel.
ca@2178
   661
ca@2178
   662
    model notNil ifTrue:[
ca@2178
   663
        ^ model iconAt:specClass ifNonePut:[specClass icon]
ca@2178
   664
    ].
ca@2178
   665
    ^ specClass icon
ca@2178
   666
!
ca@2178
   667
ca@2178
   668
label
ca@2178
   669
    "get the label used for presentation
ca@2178
   670
    "
ca@2178
   671
    ^ self string
ca@2178
   672
!
ca@2178
   673
ca@2178
   674
printOn:aStream
ca@2178
   675
    "append a a printed representation of the item to aStream
ca@2178
   676
    "
ca@2178
   677
    aStream nextPutAll:(self string)
ca@2178
   678
!
ca@2178
   679
ca@2178
   680
string
ca@2178
   681
    "get the string
ca@2178
   682
    "
ca@2178
   683
    ^ widget class name.
ca@2178
   684
! !
ca@2178
   685
ca@2178
   686
!ViewTreeItem methodsFor:'queries'!
ca@2178
   687
ca@2178
   688
canChangeLayout
ca@2178
   689
    "returns true if the layout of the widget can be changed and the
ca@2178
   690
     layout is not organized by its superView
ca@2178
   691
    "
ca@2178
   692
    ^ self isResizeable
ca@2178
   693
!
ca@2178
   694
ca@2178
   695
canResizeSubComponents
ca@2178
   696
    "returns true if the widget can resize its sub components
ca@2178
   697
    "
ca@2178
   698
    |specClass|
ca@2178
   699
ca@2178
   700
    specClass := self specClass.
ca@2178
   701
ca@2178
   702
    specClass notNil ifTrue:[
ca@2178
   703
        ^ specClass canResizeSubComponents
ca@2178
   704
    ].
ca@2178
   705
    ^ false
ca@2178
   706
!
ca@2178
   707
ca@2178
   708
exists
ca@2178
   709
    widget id notNil ifTrue:[^ true ].
ca@2178
   710
ca@2178
   711
    exists ~~ false ifTrue:[
ca@2178
   712
        exists := false.
ca@2178
   713
ca@2178
   714
        widget superView notNil ifTrue:[
ca@2178
   715
            (parent isHierarchicalItem and:[parent exists]) ifTrue:[
ca@2178
   716
                exists := (parent widget subViews includesIdentical:widget).
ca@2178
   717
            ].
ca@2178
   718
        ].
ca@2178
   719
    ].
ca@2178
   720
    ^ exists
ca@2178
   721
!
ca@2178
   722
ca@2178
   723
isApplicationClass
ca@2178
   724
    |cls|
ca@2178
   725
ca@2178
   726
    cls := widget class.
ca@2178
   727
ca@2178
   728
    ^ (    cls == ApplicationSubView
ca@2178
   729
        or:[cls == ApplicationWindow
ca@2178
   730
        or:[cls == SubCanvas]]
ca@2178
   731
      ) 
ca@2178
   732
!
ca@2178
   733
ca@2178
   734
isSelected
ca@2178
   735
    |model|
ca@2178
   736
ca@2178
   737
    model := self treeModel.
ca@2178
   738
    model notNil ifTrue:[^ model isSelected:self].
ca@2178
   739
    ^ false
ca@2178
   740
!
ca@2178
   741
ca@2178
   742
supportsSubComponents
ca@2178
   743
    "returns true if the widget supports sub components
ca@2178
   744
    "
ca@2178
   745
    |specClass|
ca@2178
   746
ca@2178
   747
    widget isScrollWrapper ifTrue:[
ca@2178
   748
        ^ false
ca@2178
   749
    ].
ca@2178
   750
    specClass := self specClass.
ca@2178
   751
ca@2178
   752
    specClass notNil ifTrue:[
ca@2178
   753
        ^ specClass supportsSubComponents
ca@2178
   754
    ].
ca@2178
   755
    ^ false
ca@2178
   756
! !
ca@2178
   757
ca@2178
   758
!ViewTreeItem methodsFor:'testing'!
ca@2178
   759
ca@2178
   760
isInLayoutContainer
ca@2178
   761
    "returns true if the widget is in a layout container
ca@2178
   762
    "
ca@2178
   763
    |sv specClass|
ca@2178
   764
ca@2178
   765
    sv := widget superView.
ca@2178
   766
ca@2178
   767
    sv notNil ifTrue:[
ca@2178
   768
        specClass := sv specClass.
ca@2178
   769
ca@2178
   770
        specClass notNil ifTrue:[
ca@2178
   771
            ^ specClass isLayoutContainer
ca@2178
   772
        ].
ca@2178
   773
    ].
ca@2178
   774
    ^ false
ca@2178
   775
!
ca@2178
   776
ca@2178
   777
isLayoutContainer
ca@2178
   778
    "answer whether corresponding view instances of the spec class can contain
ca@2178
   779
     (and arrange) other view
ca@2178
   780
    "
ca@2178
   781
    |specClass|
ca@2178
   782
ca@2178
   783
    specClass := self specClass.
ca@2178
   784
ca@2178
   785
    specClass notNil ifTrue:[
ca@2178
   786
        ^ specClass isLayoutContainer
ca@2178
   787
    ].
ca@2178
   788
    ^ false
ca@2178
   789
!
ca@2178
   790
ca@2178
   791
isMoveable
ca@2178
   792
    "returns true if the widget is not in a layout container
ca@2178
   793
    "
ca@2178
   794
    self isInLayoutContainer ifFalse:[
ca@2178
   795
        ^ widget superView notNil
ca@2178
   796
    ].
ca@2178
   797
    ^ false
ca@2178
   798
!
ca@2178
   799
ca@2178
   800
isResizeable
ca@2178
   801
    "returns true if the widget is resizeable
ca@2178
   802
    "
ca@2178
   803
    |sv specClass|
ca@2178
   804
ca@2178
   805
    sv := widget superView.
ca@2178
   806
ca@2178
   807
    sv notNil ifTrue:[
ca@2178
   808
        specClass := sv specClass.
ca@2178
   809
ca@2178
   810
        specClass notNil ifTrue:[
ca@2178
   811
            ^ specClass canResizeSubComponents
ca@2178
   812
        ].
ca@2178
   813
    ].
ca@2178
   814
    ^ false
ca@2178
   815
! !
ca@2178
   816
ca@2178
   817
!ViewTreeItem class methodsFor:'documentation'!
ca@2178
   818
ca@2178
   819
version
ca@2178
   820
    ^ '$Header$'
ca@2178
   821
! !
ca@2178
   822
ca@2178
   823
ViewTreeItem initialize!