UIPainterView.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:07:51 +0100
branchjv
changeset 3630 5e718e0a754e
parent 3360 b7f7e48455dd
child 3387 462d9e0dea1f
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present

- All source *.st files are now Unicode UTF8 without BOM
Files are in two groups (fileOut works this way in Smalltalk/X):
- containing a unicode character have "{ Encoding: utf8 }" at the header
- ASCII only are without the header
cg@60
     1
"
cg@156
     2
 COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
werner@1834
     3
	      All Rights Reserved
cg@60
     4
cg@60
     5
 This software is furnished under a license and may be used
cg@60
     6
 only in accordance with the terms of that license and with the
tz@742
     7
 inclusion of the above copyright notice. This software may not
cg@60
     8
 be provided or otherwise made available to, or used by, any
cg@60
     9
 other person.  No title to or ownership of the software is
cg@60
    10
 hereby transferred.
cg@60
    11
"
ca@1387
    12
"{ Package: 'stx:libtool2' }"
ca@1387
    13
cg@3223
    14
"{ NameSpace: Smalltalk }"
cg@3223
    15
cg@60
    16
UIObjectView subclass:#UIPainterView
cg@278
    17
	instanceVariableNames:'treeView listHolder superclassName className methodName
cg@2244
    18
		categoryName handleColorBlack handleColorWhite handleMasterColor
cg@2276
    19
		sketchPainter listOfAspectsHolder'
cg@3097
    20
	classVariableNames:'HandCursor RedefineAspectMethods AspectsAsInstances'
cg@60
    21
	poolDictionaries:''
cg@60
    22
	category:'Interface-UIPainter'
cg@60
    23
!
cg@60
    24
cg@211
    25
Object subclass:#ViewProperty
cg@211
    26
	instanceVariableNames:'view spec identifier'
cg@211
    27
	classVariableNames:'Identifier'
cg@211
    28
	poolDictionaries:''
cg@211
    29
	privateIn:UIPainterView
cg@211
    30
!
cg@211
    31
cg@60
    32
!UIPainterView class methodsFor:'documentation'!
cg@60
    33
cg@60
    34
copyright
cg@60
    35
"
cg@156
    36
 COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
werner@1834
    37
	      All Rights Reserved
cg@60
    38
cg@60
    39
 This software is furnished under a license and may be used
cg@60
    40
 only in accordance with the terms of that license and with the
tz@742
    41
 inclusion of the above copyright notice. This software may not
cg@60
    42
 be provided or otherwise made available to, or used by, any
cg@60
    43
 other person.  No title to or ownership of the software is
cg@60
    44
 hereby transferred.
cg@60
    45
"
cg@60
    46
!
cg@60
    47
cg@60
    48
documentation
cg@60
    49
"
ca@128
    50
    buildIn view used by the UIPainter; from this view, the layout of the
ca@128
    51
    new application derives from.
ca@128
    52
ca@128
    53
    [see also:]
werner@1834
    54
	UIBuilder
werner@1834
    55
	UIObjectView
cg@156
    56
cg@156
    57
    [author:]
werner@1834
    58
	Claus Gittinger
werner@1834
    59
	Claus Atzkern
cg@60
    60
"
cg@60
    61
! !
cg@60
    62
sv@1225
    63
!UIPainterView class methodsFor:'initialization'!
sv@1225
    64
sv@1225
    65
initialize
sv@1225
    66
cg@1494
    67
    AspectsAsInstances := true. "/ false.
sv@1225
    68
    RedefineAspectMethods := false.
sv@1225
    69
sv@1225
    70
    "Created: / 22.9.1999 / 12:32:31 / stefan"
sv@1225
    71
! !
sv@1225
    72
tz@698
    73
!UIPainterView class methodsFor:'code generation mode'!
tz@698
    74
cg@925
    75
generateAspectsAsInstanceVariables
cg@925
    76
    "if on, aspects are held as instance variables;
cg@2244
    77
     if off (the default), they are kept in the bindings dictionary."
cg@2244
    78
cg@925
    79
    ^ AspectsAsInstances
cg@925
    80
cg@925
    81
    "Created: / 29.7.1998 / 11:21:38 / cg"
cg@925
    82
    "Modified: / 29.7.1998 / 11:22:01 / cg"
cg@925
    83
!
cg@925
    84
cg@925
    85
generateAspectsAsInstanceVariables:aBoolean
cg@925
    86
    "if on, aspects are held as instance variables;
cg@2244
    87
     if off (the default), they are kept in the bindings dictionary."
cg@2244
    88
cg@925
    89
    AspectsAsInstances := aBoolean
cg@925
    90
cg@925
    91
    "Created: / 29.7.1998 / 11:21:26 / cg"
cg@925
    92
    "Modified: / 29.7.1998 / 11:22:11 / cg"
cg@925
    93
!
cg@925
    94
cg@2244
    95
generateCommentedCode
cg@2244
    96
    "comments in generated aspect methods; yes or no."
cg@2244
    97
cg@2714
    98
    ^ UserPreferences current generateComments
cg@2714
    99
    and:[ UserPreferences current generateCommentsForAspectMethods ]
cg@2244
   100
!
cg@2244
   101
cg@2244
   102
generateCommentedCode:aBoolean
cg@2244
   103
    "comments in generated aspect methods; yes or no."
cg@2244
   104
cg@2716
   105
    UserPreferences current generateComments ifFalse:[
cg@2716
   106
        aBoolean ifTrue:[
cg@2716
   107
            UserPreferences current generateComments:true
cg@2716
   108
        ].
cg@2716
   109
    ].
cg@2716
   110
cg@2714
   111
    UserPreferences current 
cg@2716
   112
        generateCommentsForAspectMethods:aBoolean.
cg@2244
   113
!
cg@2244
   114
tz@742
   115
redefineAspectMethods
cg@2244
   116
    "redefine methods yes or no. 
cg@2244
   117
     If a method is defined in super class should the message be reinstalled ?"
cg@2244
   118
sv@1225
   119
    ^ RedefineAspectMethods
tz@698
   120
sv@1225
   121
    "Modified: / 22.9.1999 / 12:33:03 / stefan"
tz@698
   122
!
tz@698
   123
tz@742
   124
redefineAspectMethods:aBoolean
cg@2244
   125
    "redefine methods yes or no.
cg@2244
   126
     If a method is defined in super class should the message be reinstalled ?"
cg@2244
   127
tz@742
   128
    RedefineAspectMethods := aBoolean
tz@698
   129
! !
tz@698
   130
cg@60
   131
!UIPainterView class methodsFor:'defaults'!
cg@60
   132
werner@1834
   133
defaultMenuMessage
cg@60
   134
    "This message is the default yo be sent to the menuHolder to get a menu
cg@60
   135
    "
ca@121
   136
    ^ #showMiddleButtonMenu
cg@60
   137
cg@60
   138
cg@60
   139
! !
cg@60
   140
cg@60
   141
!UIPainterView methodsFor:'accessing'!
cg@60
   142
cg@60
   143
application
cg@60
   144
    ^ nil
cg@60
   145
cg@60
   146
    "Modified: 6.9.1995 / 00:46:44 / claus"
cg@60
   147
!
cg@60
   148
ca@78
   149
applicationName
ca@78
   150
    ^ self className
ca@78
   151
!
ca@78
   152
ca@78
   153
applicationName:aName
ca@78
   154
    self className:aName
ca@78
   155
!
ca@78
   156
cg@1977
   157
class:aClass superclassName:aSuperclassName selector:aSelector
cg@1977
   158
    self assert:(aClass isBehavior).
cg@1977
   159
    className      := aClass name.
cg@1977
   160
    superclassName := aSuperclassName.
cg@1977
   161
    methodName     := aSelector.
cg@1977
   162
!
cg@1977
   163
cg@60
   164
className
cg@60
   165
    ^ className
cg@60
   166
!
cg@60
   167
ca@78
   168
className:aName
cg@1977
   169
    self assert:(aName isString).
ca@78
   170
    className := aName
cg@60
   171
!
cg@60
   172
cg@60
   173
className:aClassName superclassName:aSuperclassName selector:aSelector
cg@1977
   174
    self assert:(aClassName isString).
ca@78
   175
    className      := aClassName.
cg@60
   176
    superclassName := aSuperclassName.
ca@78
   177
    methodName     := aSelector.
cg@60
   178
!
cg@60
   179
cg@2276
   180
listOfAspectsHolder:something
cg@2276
   181
    listOfAspectsHolder := something.
cg@2276
   182
!
cg@2276
   183
cg@60
   184
methodName
cg@60
   185
    ^ methodName
cg@60
   186
!
cg@60
   187
ca@78
   188
methodName:aName
ca@78
   189
    methodName := aName
cg@60
   190
!
cg@60
   191
cg@60
   192
selectNames:aStringOrCollection
cg@1031
   193
    |prop coll s n newSel|
cg@60
   194
cg@1031
   195
    (aStringOrCollection size == 0) ifTrue:[
werner@1834
   196
	newSel := nil.
cg@1031
   197
    ] ifFalse:[
werner@1834
   198
	(s := aStringOrCollection) isString ifFalse:[
werner@1834
   199
	    s size == 1 ifTrue:[
werner@1834
   200
		s := s first
werner@1834
   201
	    ] ifFalse:[
werner@1834
   202
		coll := OrderedCollection new.
werner@1834
   203
werner@1834
   204
		s do:[:aName|
werner@1834
   205
		    (prop := self propertyOfName:aName) notNil ifTrue:[
werner@1834
   206
			coll add:(prop view)
werner@1834
   207
		    ]
werner@1834
   208
		].
werner@1834
   209
		(n := coll size) == 1 ifTrue:[
werner@1834
   210
		    newSel := coll at:1
werner@1834
   211
		] ifFalse:[
werner@1834
   212
		    n == 0 ifTrue:[
werner@1834
   213
			newSel := nil
werner@1834
   214
		    ] ifFalse:[
werner@1834
   215
			newSel := coll
werner@1834
   216
		    ]
werner@1834
   217
		].
werner@1834
   218
		^ self select:newSel.
werner@1834
   219
	    ]
werner@1834
   220
	].
werner@1834
   221
werner@1834
   222
	prop := self propertyOfName:s.
werner@1834
   223
	prop isNil ifTrue:[
werner@1834
   224
	    newSel := nil
werner@1834
   225
	] ifFalse:[
werner@1834
   226
	    newSel := prop view
werner@1834
   227
	].
cg@60
   228
    ].
cg@60
   229
cg@1031
   230
    ^ self select:newSel
cg@60
   231
! !
cg@60
   232
ca@111
   233
!UIPainterView methodsFor:'change & update'!
ca@111
   234
ca@223
   235
layoutChanged
cg@1445
   236
    treeView notNil ifTrue:[
werner@1834
   237
	treeView layoutChanged
cg@1445
   238
    ]
ca@111
   239
! !
ca@111
   240
cg@60
   241
!UIPainterView methodsFor:'copy & cut & paste'!
cg@60
   242
cg@2221
   243
changeSelectionAfterPasteOf:sel
cg@2221
   244
    sel notNil ifTrue:[
cg@2221
   245
        self select:sel.
cg@2221
   246
    ].
cg@2221
   247
!
cg@2221
   248
cg@1744
   249
commonContainerOf:someComponents
cg@1744
   250
    |container|
cg@1744
   251
cg@1744
   252
    container := someComponents first container.
cg@1744
   253
    [container notNil
cg@1744
   254
     and:[ (someComponents conform:[:eachComponent | eachComponent isComponentOf:container]) not]]
werner@1834
   255
	whileTrue:[
werner@1834
   256
	container := container container.
cg@1744
   257
    ].
cg@1744
   258
    ^ container
cg@1744
   259
!
cg@1744
   260
cg@60
   261
copySelection
cg@1959
   262
    "copy the selection into the cut & paste-buffer"
cg@1959
   263
cg@2362
   264
    |specs coll|
cg@60
   265
cg@2257
   266
    coll := self minClosedViewSetFor:(self selection).
cg@60
   267
ca@71
   268
    coll notNil ifTrue:[
ca@776
   269
"/        self select:nil.
cg@2362
   270
        specs := coll collect:[:eachView | self fullSpecWithAbsolutePositionFor:eachView].
ca@1870
   271
        self setClipboardObject:specs.
ca@776
   272
"/        treeView selection: sel
cg@60
   273
    ].
cg@60
   274
!
cg@60
   275
tz@723
   276
deleteSelection
cg@1959
   277
    "delete the selection buffered"
cg@1959
   278
tz@887
   279
    self deleteSelectionBuffered: true
tz@887
   280
!
tz@887
   281
ca@2396
   282
deleteSelectionBuffered:buffered
cg@2257
   283
    "cut the selection. If buffered is true, place it into the cut&paste-buffer"
cg@2257
   284
ca@2396
   285
    |specs viewsToRemove newSelection firstView|
cg@60
   286
tm@1621
   287
    treeView askForSelectionChangeAllowed ifFalse:[^ self].
tm@1621
   288
ca@2396
   289
    viewsToRemove := self minClosedViewSetFor:(self selection).
ca@2396
   290
    viewsToRemove isEmptyOrNil ifTrue:[ ^ self].
ca@2396
   291
ca@2396
   292
    buffered ifTrue:[
ca@2396
   293
        specs := viewsToRemove collect:[:aView| self fullSpecWithAbsolutePositionFor:aView ].
ca@2396
   294
        self setClipboardObject:specs
ca@2396
   295
    ].
ca@2396
   296
    firstView    := viewsToRemove first.
ca@2396
   297
    newSelection := self findContainerOfView:firstView.
ca@2396
   298
ca@2396
   299
    newSelection isNil ifTrue:[
ca@2396
   300
        newSelection := self.
ca@2396
   301
    ] ifFalse:[
ca@2396
   302
        viewsToRemove size == 1 ifTrue:[
ca@2396
   303
            |subviews index|
ca@2396
   304
cg@2508
   305
            "/ newSelection components notEmptyOrNil ifTrue:[ self halt ].
ca@2396
   306
            subviews := newSelection subViews.
ca@2396
   307
ca@2396
   308
            subviews size > 1 ifTrue:[
ca@2396
   309
                index := subviews findFirst:[:eachView| eachView isSameOrComponentOf:firstView ].
ca@2396
   310
                index > 0 ifTrue:[
ca@2396
   311
                    newSelection := subviews
ca@2396
   312
                            at:(index + 1)
ca@2396
   313
                            ifAbsent:[subviews at:index -1].
ca@2396
   314
                ].
ca@2396
   315
            ].
ca@2396
   316
        ].
ca@2396
   317
    ].
ca@2396
   318
ca@2396
   319
    self withSelectionHiddenDo:[
ca@2396
   320
        self select:newSelection.
ca@2396
   321
cg@2257
   322
        treeView canvasEventsDisabledDo:[
ca@2396
   323
            self withinTransaction:#cut objects:viewsToRemove do:[
ca@2396
   324
                viewsToRemove reverseDo:[:aView|
ca@1870
   325
                    self createUndoRemove:aView.
ca@1870
   326
                    self remove:aView.
ca@1870
   327
                ]
ca@1870
   328
            ].
ca@2396
   329
        ].
ca@2396
   330
        self windowGroup processRealExposeEvents.
ca@2396
   331
    ].
tz@698
   332
!
tz@698
   333
tz@723
   334
deleteTotalSelection
cg@1959
   335
    "delete the selection"
cg@1959
   336
tz@887
   337
    self deleteSelectionBuffered: false
cg@60
   338
!
cg@60
   339
werner@1832
   340
getSelectedViewsAndSpecs
werner@1832
   341
    "return an array filed with selected views and corresponding specs.
cg@1959
   342
     Nil if there is none."
cg@1959
   343
werner@1832
   344
    |specs coll sel|
werner@1832
   345
werner@1832
   346
    sel := treeView selection.
werner@1832
   347
cg@2257
   348
    coll := self minClosedViewSetFor:(self selection).
werner@1832
   349
werner@1832
   350
    coll isNil ifTrue:[^ nil].
werner@1832
   351
werner@1832
   352
    specs := coll collect:[:aView| self fullSpecFor:aView ].
werner@1832
   353
    ^ Array with: coll with: specs
werner@1832
   354
!
werner@1832
   355
cg@60
   356
pasteBuffer
sv@2311
   357
    "add the objects in the paste-buffer to the object view; 
sv@2311
   358
     don't change the layout if more than a single item has been selected"
sv@2311
   359
sv@2311
   360
    |sel clipboard|
sv@2311
   361
cg@2362
   362
    self enabled ifFalse:[
cg@2362
   363
        Dialog warn:'Operation currently disabled (In geometry test mode)'.
cg@2362
   364
        ^ self
cg@2362
   365
    ]. 
cg@2362
   366
sv@2311
   367
    clipboard := self getClipboardObject.
cg@2951
   368
    clipboard isString ifTrue:[
cg@2951
   369
        Dialog warn:'can only paste widgets here'.
cg@2951
   370
    ] ifFalse:[
cg@2951
   371
        sel := self pasteSpecifications:clipboard keepLayout:true "(clipboard size > 1)".
cg@2951
   372
        self changeSelectionAfterPasteOf:sel.
cg@2951
   373
    ].
ca@89
   374
!
ca@89
   375
cg@1338
   376
pasteKeepingPosition
werner@1834
   377
    "add the objects in the paste-buffer to the object view;
cg@1338
   378
     translate the layout as appropriate, to position the component
cg@1959
   379
     at the same absolute position (relative to topView) as before"
cg@1959
   380
cg@1338
   381
    |sel|
cg@1338
   382
cg@1338
   383
    sel := self
ca@1872
   384
        pasteSpecifications:(self getClipboardObject)
ca@1872
   385
        keepLayout:true
ca@1872
   386
        keepPosition:true
cg@3055
   387
        at:#keep.
cg@1338
   388
cg@2221
   389
    self changeSelectionAfterPasteOf:sel.
cg@1338
   390
!
cg@1338
   391
ca@2395
   392
pasteSpecifications:aSpecificationOrList into:aContainerOrNil beforeIndex:anIndexOrNil keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep
cg@2537
   393
    "add the specs to the object view; 
cg@2537
   394
     if given a collection of specs, returns a list of pasted widgets;
cg@2537
   395
     if given a single spec, returns that view (sigh - a stupid bw-compatibility kludge)"
cg@2257
   396
cg@2494
   397
    |sensor specsToPaste pasteOffset builder newSel 
mb@2560
   398
     bounds containerToPasteInto pastePoint beforeIndex count|
tm@1621
   399
tm@1621
   400
    treeView askForSelectionChangeAllowed ifFalse:[^ nil].
tm@1621
   401
cg@2494
   402
    sensor := self window sensor.
cg@2494
   403
ca@2387
   404
    containerToPasteInto := aContainerOrNil.
ca@2387
   405
cg@2366
   406
    (aPointOrNilOrKeep == #keep
cg@2494
   407
    or:[ sensor shiftDown
cg@2494
   408
    or:[ sensor ctrlDown ]]) ifTrue:[
cg@2362
   409
        "/ paste into the selection
ca@2387
   410
        containerToPasteInto isNil ifTrue:[
ca@2387
   411
            containerToPasteInto := self singleSelection.
ca@2387
   412
        ].
cg@2362
   413
    ] ifFalse:[
cg@2362
   414
        "/ ignore the selection and paste where we drop!!
cg@2366
   415
        pastePoint := aPointOrNilOrKeep.
cg@2362
   416
        pastePoint isNil ifTrue:[
cg@3262
   417
            pastePoint := device 
cg@2494
   418
                                translatePoint:(sensor mousePoint)
cg@2362
   419
                                fromView:nil
cg@2362
   420
                                toView:self.
cg@2362
   421
        ].
ca@2387
   422
        containerToPasteInto isNil ifTrue:[
ca@2387
   423
            containerToPasteInto := self findObjectAt:pastePoint.
ca@2387
   424
        ].
cg@2362
   425
    ].
cg@2362
   426
cg@1744
   427
    containerToPasteInto isNil ifTrue:[
sv@1878
   428
        self selection size > 0 ifTrue:[
sv@1878
   429
            containerToPasteInto := self commonContainerOf:self selection
sv@1878
   430
        ] ifFalse:[
sv@1878
   431
            containerToPasteInto := self
sv@1878
   432
        ].
cg@2221
   433
"/        self selection:containerToPasteInto.
cg@1744
   434
    ].
cg@1744
   435
cg@2362
   436
    "/ search up parent list for something we can paste into
cg@2362
   437
    [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[
cg@2362
   438
        containerToPasteInto == self ifTrue:[
cg@2362
   439
            containerToPasteInto := nil
cg@2362
   440
        ] ifFalse:[
cg@2362
   441
            containerToPasteInto := containerToPasteInto container.
sv@1878
   442
        ].
tm@1621
   443
    ].
cg@1752
   444
    containerToPasteInto isNil ifTrue:[
sv@1878
   445
        containerToPasteInto := self
cg@1752
   446
    ].
cg@60
   447
cg@2221
   448
    (self canPaste:aSpecificationOrList into:containerToPasteInto)
cg@2221
   449
    ifFalse:[
cg@2362
   450
        self enabled ifTrue:[
cg@2362
   451
            Dialog warn:'Cannot paste into selected component (not a container ?)'.
cg@2362
   452
        ] ifFalse:[
cg@2951
   453
            Dialog warn:'Operation currently disabled (In geometry test mode)'.
cg@2362
   454
        ]. 
sv@1878
   455
        ^ nil
ca@89
   456
    ].
ca@223
   457
cg@2537
   458
    self hideSelection.
cg@2537
   459
ca@776
   460
    aSpecificationOrList isCollection ifTrue:[
cg@2257
   461
        specsToPaste := aSpecificationOrList
ca@776
   462
    ] ifFalse:[
cg@2257
   463
        specsToPaste := Array with:aSpecificationOrList
ca@776
   464
    ].
cg@2221
   465
"/    self setClipboardObject:nil.
ca@776
   466
ca@776
   467
    newSel  := OrderedCollection new.
ca@776
   468
    builder := UIBuilder new isEditing:true.
ca@776
   469
ca@776
   470
    className notNil ifTrue:[
sv@1878
   471
        builder applicationClass:(self resolveName:className)
ca@776
   472
    ].
cg@2362
   473
    bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent).
cg@2362
   474
cg@2362
   475
    pasteOffset := 0.
cg@2362
   476
ca@2395
   477
    (anIndexOrNil notNil and:[anIndexOrNil > 0]) ifTrue:[
ca@2395
   478
        beforeIndex := anIndexOrNil.
ca@2395
   479
    ].
cg@2362
   480
    specsToPaste do:[:eachSpec|
cg@2362
   481
        |view newOrigin uiPainterAttributes thisAbsOrigin|
cg@2362
   482
cg@2362
   483
        uiPainterAttributes := eachSpec otherAttributeAt:#uiPainterAttributes.
sr@2388
   484
        eachSpec otherAttributeAt:#uiPainterAttributes put:nil.
cg@2362
   485
ca@2395
   486
        view := self addSpec:eachSpec builder:builder in:containerToPasteInto beforeIndex:beforeIndex.
ca@2395
   487
        beforeIndex notNil ifTrue:[
ca@2395
   488
            beforeIndex := beforeIndex + 1
ca@2395
   489
        ].
cg@3244
   490
        (keepLayout or:[eachSpec keepUILayout]) ifTrue:[
cg@3249
   491
            eachSpec layout isAssociation ifTrue:[
cg@3249
   492
                eachSpec layout key == #extent ifTrue:[
cg@3249
   493
                    view pixelExtent:eachSpec layout value
cg@3249
   494
                ] ifFalse:[
cg@3249
   495
                    "/ self halt.
cg@3249
   496
                    view geometryLayout:eachSpec layout value
cg@3249
   497
                ].
cg@3249
   498
            ] ifFalse:[    
cg@3249
   499
                view geometryLayout:eachSpec layout.
cg@3249
   500
            ]
cg@3129
   501
        ] ifFalse:[
cg@3129
   502
            (keepPosition and:[ uiPainterAttributes notNil ]) ifTrue:[
cg@3129
   503
                aPointOrNilOrKeep == #keep ifTrue:[
cg@3129
   504
                    newOrigin := uiPainterAttributes at:#origin.
cg@3129
   505
                ] ifFalse:[
cg@3129
   506
                    thisAbsOrigin := uiPainterAttributes at:#absOrigin.
cg@3129
   507
cg@3262
   508
                    newOrigin := device 
cg@3129
   509
                                        translatePoint:thisAbsOrigin
cg@3129
   510
                                        fromView:self
cg@3129
   511
                                        toView:containerToPasteInto.
cg@3129
   512
                ].
ca@2386
   513
            ] ifFalse:[
cg@3129
   514
                pastePoint isNil ifTrue:[ pastePoint := 0@0 ].
cg@3262
   515
                newOrigin := device 
cg@3129
   516
                                    translatePoint:pastePoint
ca@2386
   517
                                    fromView:self
ca@2386
   518
                                    toView:containerToPasteInto.
ca@2386
   519
            ].
cg@3129
   520
cg@3129
   521
            (bounds containsPoint:newOrigin) ifFalse:[
cg@3129
   522
                newOrigin := pasteOffset asPoint.
cg@3129
   523
                pasteOffset := pasteOffset + 4.
cg@3129
   524
            ].
cg@3129
   525
            newOrigin notNil ifTrue:[
cg@3129
   526
                self moveObject:view to:newOrigin.
cg@3129
   527
            ].
sv@1878
   528
        ].
ca@2395
   529
        view realized ifFalse:[
ca@2395
   530
            view realize.
ca@2395
   531
        ].
sv@1878
   532
        newSel add:view.
ca@776
   533
    ].
ca@312
   534
cg@2537
   535
    self 
cg@2537
   536
        withinTransaction:#paste 
cg@2537
   537
        objects:newSel 
cg@2537
   538
        do:[
cg@2537
   539
            undoHistory 
cg@2537
   540
                addUndoSelector:#undoCreate:
cg@2537
   541
                withArgs:(newSel collect:[:v| (self propertyOfView:v) identifier]).
cg@2537
   542
            self undoHistoryChanged.
cg@2537
   543
        ].
cg@60
   544
ca@776
   545
    self realizeAllSubViews.
ca@2395
   546
    "/ newSel do:[:v| v raise].
cg@1744
   547
    self elementChangedSize:containerToPasteInto.
cg@60
   548
cg@2818
   549
    "/ nil wg if embedded in a browser
cg@2818
   550
    self windowGroup notNil ifTrue:[
cg@2818
   551
        "/ because the new-created view will destroy the handles, when it redraws itself,
cg@2818
   552
        "/ give it a chance to do so, before we return. (bail out after half a second, in case of trouble)
cg@2818
   553
        count := 0.
cg@2818
   554
        [ (newSel conform:[:v | v shown]) or:[count > 50] ] whileFalse:[
cg@2818
   555
            self windowGroup repairDamage.
cg@2818
   556
            Delay waitForSeconds:0.01.
cg@2818
   557
            count := count+1.
cg@2818
   558
        ].
cg@2818
   559
        Delay waitForSeconds:0.01.
mb@2560
   560
        self windowGroup repairDamage.
cg@2537
   561
    ].
cg@2537
   562
ca@776
   563
    newSel size == 1 ifTrue:[newSel := newSel at:1].
ca@223
   564
    ^ newSel
cg@1500
   565
cg@2818
   566
    "Modified: / 03-11-2010 / 07:20:06 / cg"
ca@89
   567
!
ca@89
   568
cg@3055
   569
pasteSpecifications:aSpecificationOrList into:aContainerOrNil keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep 
ca@2395
   570
    "add the specs to the object view; returns list of pasted widgets"
cg@3055
   571
    
cg@3055
   572
    ^ self 
cg@3055
   573
        pasteSpecifications:aSpecificationOrList
cg@3055
   574
        into:aContainerOrNil
cg@3055
   575
        beforeIndex:nil
cg@3055
   576
        keepLayout:keepLayout
cg@3055
   577
        keepPosition:keepPosition
cg@3055
   578
        at:aPointOrNilOrKeep
ca@2395
   579
!
ca@2395
   580
ca@2387
   581
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
ca@2387
   582
    "add the specs to the object view; returns list of pasted widgets"
ca@2387
   583
ca@2387
   584
    ^ self
ca@2387
   585
        pasteSpecifications:aSpecificationOrList
ca@2387
   586
        keepLayout:keepLayout
ca@2387
   587
        keepPosition:true
cg@2627
   588
        at:#keep "/ nil
ca@2387
   589
ca@2387
   590
    "Modified: 11.8.1997 / 01:00:35 / cg"
ca@2387
   591
!
ca@2387
   592
ca@2387
   593
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil
ca@2387
   594
    "add the specs to the object view; returns list of pasted widgets"
ca@2387
   595
ca@2387
   596
    ^ self
ca@2387
   597
        pasteSpecifications:aSpecificationOrList
ca@2387
   598
        keepLayout:keepLayout
ca@2387
   599
        keepPosition:true
ca@2387
   600
        at:aPointOrNil
ca@2387
   601
!
ca@2387
   602
ca@2387
   603
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep
ca@2387
   604
    "add the specs to the object view; returns list of pasted widgets"
ca@2387
   605
ca@2387
   606
    ^ self pasteSpecifications:aSpecificationOrList
ca@2387
   607
        into:nil
ca@2395
   608
        beforeIndex:nil
ca@2387
   609
        keepLayout:keepLayout
ca@2387
   610
        keepPosition:keepPosition
ca@2387
   611
        at:aPointOrNilOrKeep
ca@2387
   612
!
ca@2387
   613
sv@2315
   614
pasteWithLayout
cg@2369
   615
    "add the objects in the paste-buffer to the object view - keep the old layout"
sv@2315
   616
sv@2315
   617
    |sel|
sv@2315
   618
cg@2366
   619
    sel := self 
cg@2366
   620
            pasteSpecifications:(self getClipboardObject)
cg@2366
   621
            keepLayout:true
cg@2366
   622
            keepPosition:true
cg@2366
   623
            at:#keep.
sv@2315
   624
    self changeSelectionAfterPasteOf:sel.
sv@2315
   625
!
sv@2315
   626
sv@2311
   627
pasteWithoutLayout
cg@2369
   628
    "add the objects in the paste-buffer to the object view - do not keep the old layout"
cg@1959
   629
ca@223
   630
    |sel|
ca@89
   631
cg@2367
   632
    sel := self 
cg@2367
   633
            pasteSpecifications:(self getClipboardObject)
cg@2367
   634
            keepLayout:false
cg@2367
   635
            keepPosition:true
cg@2367
   636
            at:#keep.
cg@2221
   637
    self changeSelectionAfterPasteOf:sel.
cg@2257
   638
!
cg@2257
   639
cg@2257
   640
replaceSelectionBy:aNewSpec
cg@2257
   641
    "replace the selected widget by another one."
cg@2257
   642
cg@3360
   643
    |oldSelection treeModel newView oldView container specs index|
ca@2387
   644
ca@2387
   645
    (self singleSelection notNil and:[treeView askForSelectionChangeAllowed]) ifFalse:[
ca@2387
   646
        ^ self
ca@2387
   647
    ].
cg@3360
   648
    
ca@2387
   649
    treeModel    := treeView model.
cg@2257
   650
    oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
ca@2387
   651
    oldSelection isNil ifTrue:[^ self].
ca@2387
   652
ca@2395
   653
    oldView := oldSelection contents view.
ca@2395
   654
ca@2395
   655
    (oldSelection hasChildren and:[aNewSpec class supportsSubComponents]) ifTrue:[
cg@3360
   656
        specs := 
cg@3360
   657
            oldSelection children collect:[:each|
cg@3360
   658
                self fullSpecWithAbsolutePositionFor:(each contents view)
cg@3360
   659
            ].
ca@2395
   660
    ].
ca@2387
   661
ca@2387
   662
    aNewSpec
ca@2387
   663
        otherAttributeAt:#uiPainterAttributes 
ca@2387
   664
        put:(Dictionary new
ca@2387
   665
                at:#origin put:oldView origin;
ca@2387
   666
                at:#extent put:oldView extent;
ca@2387
   667
                at:#absOrigin put:(oldView originRelativeTo:self);
ca@2387
   668
                yourself).
ca@2387
   669
cg@3360
   670
    index := oldSelection parent children identityIndexOf:oldSelection.
ca@2387
   671
    container := self singleSelection container.
cg@3360
   672
    
ca@2387
   673
    self withinTransaction:#replaceBy objects:(Array with:oldView) do:[
ca@2395
   674
        self withSelectionHiddenDo:[
ca@2395
   675
            newView := self 
ca@2395
   676
                    pasteSpecifications:(Array with:aNewSpec)
ca@2395
   677
                    into:container
cg@3360
   678
                    beforeIndex:index
ca@2395
   679
                    keepLayout:true
ca@2395
   680
                    keepPosition:true
ca@2395
   681
                    at:#keep.
ca@2395
   682
ca@2395
   683
            self deleteSelectionBuffered:false.
ca@2395
   684
ca@2395
   685
            specs size > 0 ifTrue:[
ca@2395
   686
                self pasteSpecifications:specs 
ca@2395
   687
                            into:newView
ca@2395
   688
                            keepLayout:(aNewSpec class canResizeSubComponents)
ca@2395
   689
                            keepPosition:(aNewSpec class isLayoutContainer not)
cg@3360
   690
                            at:index.
ca@2395
   691
            ].
ca@2395
   692
            self select:newView.
ca@2395
   693
       ].
ca@2387
   694
    ].
ca@2395
   695
    ^ newView.
cg@60
   696
! !
cg@60
   697
cg@60
   698
!UIPainterView methodsFor:'drag & drop'!
cg@60
   699
cg@2116
   700
canDrop:aDropContext
cg@2116
   701
    ^ self canDropObjects:aDropContext dropObjects
cg@2116
   702
cg@2116
   703
    "Created: / 13-10-2006 / 17:46:11 / cg"
cg@2116
   704
!
cg@2116
   705
cg@2116
   706
canDropObjects:aCollectionOfDropObjects
cg@1914
   707
    "returns true if something can be dropped"
cg@1914
   708
cg@2362
   709
    ^ (true "aCollectionOfDropObjects size == 1" 
cg@2112
   710
    and:[ self enabled 
cg@2362
   711
    and:[ true "self numberOfSelections <= 1"
cg@2362
   712
    and:[ aCollectionOfDropObjects conform:[:each| each theObject isKindOf:UISpecification]
cg@2362
   713
              ]]])
cg@2112
   714
cg@2116
   715
    "Created: / 13-10-2006 / 16:09:24 / cg"
ca@223
   716
!
ca@223
   717
ca@285
   718
canPaste
cg@1914
   719
    "returns true if there is something which can be pasted in the clipboard"
cg@1914
   720
ca@1872
   721
    ^ self canPaste:(self getClipboardObject)
ca@285
   722
!
ca@285
   723
ca@223
   724
canPaste:something
cg@1914
   725
    "returns true if something could be pasted"
cg@1914
   726
cg@2221
   727
    ^ self canPaste:something into:(self singleSelection)
cg@2221
   728
!
cg@2221
   729
cg@2221
   730
canPaste:something into:containerToPasteInto
cg@2221
   731
    "returns true if something could be pasted"
cg@2221
   732
cg@2276
   733
    (self enabled) ifFalse:[
cg@1914
   734
        ^ false
ca@223
   735
    ].
cg@2276
   736
    something isCollection ifTrue:[
cg@2276
   737
        something isEmpty ifTrue:[ ^ false].
cg@2276
   738
        ^ something conform:[:el | (self canPaste:el into:containerToPasteInto)]
cg@2276
   739
    ].
cg@2276
   740
cg@2276
   741
    (something isKindOf:UISpecification) ifFalse:[
cg@1914
   742
        ^ false
ca@223
   743
    ].
ca@223
   744
cg@2276
   745
    ^ self canPasteInto:containerToPasteInto
ca@223
   746
!
ca@223
   747
ca@223
   748
canPasteInto:aView
cg@1914
   749
    "return true, if I can paste into a view"
cg@1914
   750
ca@285
   751
    |prop|
cg@60
   752
ca@1870
   753
    aView isNil ifTrue:[ ^ false ].
cg@2265
   754
    aView == self ifTrue:[ ^ true ].
ca@1870
   755
ca@1870
   756
    (prop := self propertyOfView:aView) notNil ifTrue:[
ca@1870
   757
        ^ prop spec class supportsSubComponents
ca@89
   758
    ].
ca@1870
   759
    ^ aView specClass supportsSubComponents.
cg@60
   760
!
cg@60
   761
cg@2116
   762
dropObjects:aCollectionOfDropObjects at:aPoint
cg@2537
   763
    |spec newSel oldSel dragOffset dropPoint widg|
cg@2537
   764
ca@288
   765
    self selection notNil ifTrue:[
cg@1953
   766
        oldSel := self singleSelection.
cg@1953
   767
cg@1953
   768
        "/ search selections hierarchy for a widget into which we can paste
cg@1953
   769
        widg := oldSel.
cg@1953
   770
        [widg isNil or:[self canPasteInto:widg]] whileFalse:[
cg@1953
   771
            widg notNil ifTrue:[
cg@1953
   772
                widg := widg container
cg@1953
   773
            ].
cg@1953
   774
        ].
cg@1953
   775
cg@1953
   776
        oldSel := nil.
cg@1953
   777
        self setSelection:widg withRedraw:true.
ca@231
   778
    ].
cg@1953
   779
    spec := (aCollectionOfDropObjects at:1) theObject.
cg@2537
   780
cg@2537
   781
    dragOffset := DragAndDropManager dragOffsetQuerySignal query.
cg@2537
   782
    aPoint isNil ifTrue:[
cg@2537
   783
        dropPoint := #keep.
cg@2537
   784
    ] ifFalse:[
cg@2537
   785
        dropPoint := aPoint - dragOffset.
werner@1833
   786
    ].
cg@2537
   787
    newSel := self pasteSpecifications:spec keepLayout:false keepPosition:false at:dropPoint.
cg@2537
   788
cg@2537
   789
    self select:(oldSel ? newSel).
sv@1060
   790
cg@2116
   791
    "Modified: / 18-03-1999 / 18:29:43 / stefan"
cg@2116
   792
    "Created: / 13-10-2006 / 16:09:27 / cg"
cg@60
   793
! !
cg@60
   794
cg@2244
   795
!UIPainterView methodsFor:'drawing'!
cg@2244
   796
cg@2244
   797
clearRectangle:visRect
cg@2244
   798
    super clearRectangle:visRect.
cg@2244
   799
    sketchPainter notNil ifTrue:[
cg@2244
   800
        sketchPainter redrawInTargetView
cg@2244
   801
    ].
cg@2244
   802
cg@2244
   803
    "Created: / 16-01-2008 / 17:52:27 / cg"
cg@2244
   804
!
cg@2244
   805
cg@2244
   806
clearView
cg@2244
   807
    super clearView.
cg@2244
   808
    sketchPainter notNil ifTrue:[
cg@2244
   809
        sketchPainter redrawInTargetView
cg@2244
   810
    ].
cg@2244
   811
cg@2244
   812
    "Created: / 16-01-2008 / 17:46:08 / cg"
cg@2244
   813
!
cg@2244
   814
cg@2248
   815
useSketchFile:aFilename 
cg@2443
   816
    "a little neat goody: allow for a tablet-sketch file (WALTROP digital notepad)
cg@2443
   817
     to be used as a background of the UIPainter window. This allows for sketches to
cg@2443
   818
     be drawn, shown in the UIPainter, and then used as a placement hint (manual placement)
cg@2443
   819
     for the user. Not a high-tech solution, but helped a lot, when we protoyped GUIs."
cg@2443
   820
cg@2248
   821
    |mime sketchPainterClass|
cg@2248
   822
cg@2248
   823
    mime := aFilename asFilename mimeTypeFromName.
cg@2248
   824
    mime isNil ifTrue:[
cg@2248
   825
        mime := aFilename asFilename mimeTypeOfContents.
cg@2248
   826
    ].
cg@2248
   827
cg@2248
   828
    mime notNil ifTrue:[
sv@2278
   829
        (mime startsWith:'image') ifTrue:[
sv@2278
   830
            self viewBackground:(ImageReader fromFile:aFilename).
sv@2278
   831
            ^ self.
sv@2278
   832
        ].
cg@2444
   833
        mime = 'application/x-waltop-digital-notepad' ifTrue:[
cg@2444
   834
            sketchPainterClass := TOPFileDrawer.
cg@2444
   835
        ].
cg@2248
   836
    ].
cg@2248
   837
    sketchPainterClass isNil ifTrue:[
cg@2444
   838
        self error:'Unsupported sketch file format'
cg@2248
   839
    ].
cg@2248
   840
cg@2248
   841
    sketchPainter := sketchPainterClass new.
cg@2244
   842
    sketchPainter targetView:self.
cg@2244
   843
    sketchPainter readFile:aFilename.
cg@2244
   844
    sketchPainter ajustSketch.
cg@2244
   845
    self invalidate.
cg@2244
   846
cg@2244
   847
    "Created: / 16-01-2008 / 17:46:26 / cg"
cg@2244
   848
! !
cg@2244
   849
ca@361
   850
!UIPainterView methodsFor:'event handling'!
ca@361
   851
ca@361
   852
keyPress:key x:x y:y view:aView
cg@376
   853
    "a delegated keyEvent from aView"
cg@376
   854
ca@361
   855
    self keyPress:key x:x y:y
ca@361
   856
cg@376
   857
    "Modified: / 31.10.1997 / 20:27:22 / cg"
ca@361
   858
!
ca@361
   859
ca@361
   860
keyRelease:key x:x y:y view:aView
cg@376
   861
    "a delegated keyEvent from aView"
cg@376
   862
ca@361
   863
    self keyRelease:key x:x y:y
ca@361
   864
cg@376
   865
    "Modified: / 31.10.1997 / 20:27:32 / cg"
tz@754
   866
!
tz@754
   867
tz@754
   868
sizeChanged:how
tz@754
   869
werner@1834
   870
    super sizeChanged:how.
tz@754
   871
tz@754
   872
    self layoutChanged
ca@361
   873
! !
ca@361
   874
ca@78
   875
!UIPainterView methodsFor:'generating output'!
cg@60
   876
cg@352
   877
aspectMethods
cg@352
   878
    "extract a list of aspect methods - for browsing"
cg@352
   879
cg@1683
   880
    |cls methods|
cg@352
   881
cg@352
   882
    className isNil ifTrue:[
werner@1834
   883
	self warn:'No class defined !!'.
werner@1834
   884
	^ #()
cg@352
   885
    ].
cg@352
   886
cg@352
   887
    cls := self resolveName:className.
cg@352
   888
    methods := IdentitySet new.
cg@352
   889
cg@1683
   890
    self aspectSelectorsAndTypesDo:
werner@1834
   891
	[:selector :typeSymbol |
werner@1834
   892
	    |skip|
werner@1834
   893
werner@1834
   894
	    (cls includesSelector:selector) ifTrue:[
werner@1834
   895
werner@1834
   896
		skip := false.
werner@1834
   897
		(typeSymbol == #modelAspect) ifTrue:[
werner@1834
   898
		    (cls isSubclassOf:SimpleDialog) ifTrue:[
werner@1834
   899
			skip := SimpleDialog includesSelector:(selector asSymbol)
werner@1834
   900
		    ].
werner@1834
   901
		].
werner@1834
   902
		skip ifFalse:[
werner@1834
   903
		    methods add:(cls compiledMethodAt:selector)
werner@1834
   904
		].
werner@1834
   905
	    ]
werner@1834
   906
	].
cg@1683
   907
cg@1683
   908
    ^ methods
cg@1683
   909
cg@1683
   910
    "Created: / 25.10.1997 / 18:58:25 / cg"
cg@1683
   911
    "Modified: / 26.10.1997 / 15:06:18 / cg"
cg@1683
   912
!
cg@1683
   913
cg@1683
   914
aspectSelectorsAndTypesDo:aTwoArgBlock
cg@1683
   915
    "evaluate aBlock for every aspect methods selector; 2nd arg describes the aspects type"
cg@1683
   916
sv@1726
   917
    |cls selector protoSpec|
cg@1683
   918
cg@1683
   919
    className isNil ifTrue:[
sv@2195
   920
        self warn:'No class defined !!'.
sv@2195
   921
        ^ self
cg@1683
   922
    ].
cg@1683
   923
cg@1683
   924
    cls := self resolveName:className.
cg@1683
   925
cg@352
   926
    treeView propertiesDo:[:aProp|
sv@2195
   927
        |selector|
sv@2195
   928
sv@2195
   929
        (selector := aProp model) notNil ifTrue:[
sv@2195
   930
            selector isArray ifFalse:[
sv@2195
   931
                aTwoArgBlock value:(selector asSymbol) value:#modelAspect
sv@2195
   932
            ].
sv@2195
   933
        ].
sv@2195
   934
sv@2195
   935
        (selector := aProp menu) notNil ifTrue:[
sv@2195
   936
            selector isArray ifFalse:[
sv@2195
   937
                aTwoArgBlock value:(selector asSymbol) value:#menu
sv@2195
   938
            ].
sv@2195
   939
        ].
sv@2195
   940
sv@2195
   941
        (aProp spec aspectSelectors) do:[:aSel |
cg@2250
   942
            (aSel isString or:[aSel isSymbol]) ifTrue:[
sv@2195
   943
                aTwoArgBlock value:(aSel asSymbol) value:#channelAspect
sv@2195
   944
            ].
sv@2195
   945
        ].
sv@2195
   946
        aProp spec actionSelectors do:[:aSel|
cg@2250
   947
            (aSel isString or:[aSel isSymbol]) ifTrue:[
sv@2195
   948
                aTwoArgBlock value:(aSel asSymbol) value:#actionSelector
sv@2195
   949
            ].
sv@2195
   950
        ].
sv@2195
   951
        aProp spec valueSelectors do:[:aSel|
cg@2250
   952
            (aSel isString or:[aSel isSymbol]) ifTrue:[
sv@2195
   953
                aTwoArgBlock value:(aSel asSymbol) value:#valueSelector
sv@2195
   954
            ].
sv@2195
   955
        ]
cg@352
   956
    ].
cg@352
   957
cg@352
   958
    protoSpec := treeView canvasSpec.
cg@352
   959
cg@352
   960
    (selector := protoSpec menu) notNil ifTrue:[
sv@2195
   961
        selector isArray ifFalse:[
sv@2195
   962
            aTwoArgBlock value:(selector asSymbol) value:#menu
sv@2195
   963
        ].
cg@352
   964
    ].
cg@352
   965
!
cg@352
   966
cg@60
   967
generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
cg@2244
   968
    |selector args showIt codeStream alreadyInSuperclass numArgs method|
ca@141
   969
ca@288
   970
    selector := aspect asSymbol.
ca@288
   971
ca@288
   972
    alreadyInSuperclass := targetClass superclass canUnderstand:selector.
ca@288
   973
ca@568
   974
    numArgs := selector numArgs.
ca@568
   975
    method  := aspect.
ca@568
   976
ca@568
   977
    numArgs == 1 ifTrue:[
cg@2244
   978
        args := 'anArgument'.
cg@2295
   979
        showIt := ''' , anArgument printString , ''...''.'.
werner@1834
   980
    ] ifFalse:[
cg@2244
   981
        args := ''.
cg@2244
   982
        showIt := ' ...''.'.
cg@2244
   983
cg@2244
   984
        numArgs ~~ 0 ifTrue:[
cg@2244
   985
            method := ''.
cg@2244
   986
cg@2244
   987
            selector keywords keysAndValuesDo:[:i :key|
cg@2244
   988
                method := method, key, 'arg', i printString, ' '
cg@2244
   989
            ]
cg@2244
   990
        ]
ca@149
   991
    ].
cg@2244
   992
    codeStream := WriteStream on:(String new:100).
cg@2244
   993
    codeStream  
cg@2244
   994
        nextPutLine:('!!',targetClass name,' methodsFor:''actions''!!');
cg@2244
   995
        nextPutLine:(method,args);
cg@2244
   996
        nextPutLine:'    <resource: #uiCallback>';
cg@2244
   997
        cr.
cg@2244
   998
cg@2244
   999
    self class generateCommentedCode ifTrue:[
cg@2244
  1000
        codeStream
cg@2295
  1001
            nextPutAll:'    "automatically generated by UIPainter..."
cg@2244
  1002
cg@2244
  1003
    "*** the code below performs no action"
cg@2244
  1004
    "*** (except for some feedback on the Transcript)"
cg@2244
  1005
    "*** Please change as required and accept in the browser."
cg@2244
  1006
    "*** (and replace this comment by something more useful ;-)"
cg@2244
  1007
cg@2244
  1008
'.
cg@2244
  1009
cg@2244
  1010
        alreadyInSuperclass ifTrue:[
cg@2244
  1011
            codeStream  
cg@2244
  1012
                nextPutLine:'    "action for ' , aspect , ' is already provided in a superclass."';
cg@2244
  1013
                nextPutLine:'    "It may be redefined here..."';
cg@2244
  1014
                cr.
cg@2244
  1015
        ] ifFalse:[
cg@2244
  1016
            codeStream  
cg@2244
  1017
                nextPutLine:'    "action to be defined here..."';
cg@2244
  1018
                cr.
cg@2244
  1019
        ].
cg@2244
  1020
    ].
cg@2244
  1021
cg@2244
  1022
    codeStream  
sv@3304
  1023
        nextPutAll:'    Logger info:'''.
ca@288
  1024
ca@288
  1025
    alreadyInSuperclass ifTrue:[
cg@2244
  1026
        codeStream  
cg@2244
  1027
            nextPutAll:'inherited '.
ca@288
  1028
    ].
cg@2244
  1029
    codeStream  
cg@2244
  1030
        nextPutAll:'action for ';
cg@2244
  1031
        nextPutAll:aspect;
cg@2244
  1032
        nextPutLine:showIt.
cg@2244
  1033
ca@288
  1034
    alreadyInSuperclass ifTrue:[
cg@2244
  1035
        codeStream  
cg@2244
  1036
            nextPutAll:'    super ';
cg@2244
  1037
            nextPutAll:aspect;
cg@2244
  1038
            nextPutAll:args;
cg@2244
  1039
            nextPutLine:'.'.
ca@288
  1040
    ].
cg@2244
  1041
cg@2244
  1042
    codeStream  
cg@2244
  1043
        nextPutLine:'!! !!'; cr.
cg@2244
  1044
cg@2244
  1045
    ^ codeStream contents.
cg@2244
  1046
cg@2244
  1047
    "Modified: / 12-01-2008 / 10:21:52 / cg"
cg@60
  1048
!
cg@60
  1049
cg@1683
  1050
generateAspectMethodCode
cg@1683
  1051
    "generate aspect, action & menu methods
cg@1683
  1052
     - but do not overwrite existing ones.
cg@2714
  1053
     Return a string ready to compile into the application class.
cg@2714
  1054
     TODO: refactor and move to CodeGenerator"
cg@1683
  1055
cg@1683
  1056
    ^ self generateAspectMethodCodeFiltering:nil
cg@1683
  1057
!
cg@1683
  1058
cg@1683
  1059
generateAspectMethodCodeFiltering:aFilterOrEmpty
cg@1683
  1060
    "generate aspect, action & menu methods
cg@1683
  1061
     - but do not overwrite existing ones.
cg@2714
  1062
     Return a string ready to compile into the application class.
cg@2714
  1063
     TODO: refactor and move to CodeGenerator"
cg@1683
  1064
cg@1683
  1065
    |cls codePieces skip protoSpec thisCode
cg@1683
  1066
     definedMethodSelectors iVars t exportSels|
cg@1683
  1067
cg@1683
  1068
    cls := self targetClass.
cg@1683
  1069
    cls isNil ifTrue:[
cg@2024
  1070
        ^ nil
cg@1683
  1071
    ].
cg@1683
  1072
cg@1683
  1073
    codePieces := OrderedCollection new.
cg@1683
  1074
    definedMethodSelectors := IdentitySet new.
cg@1683
  1075
cg@1683
  1076
    treeView propertiesDo:[:aProp|
cg@2024
  1077
        |modelSelector|
cg@2024
  1078
cg@2024
  1079
        protoSpec := aProp spec.
cg@2024
  1080
cg@2024
  1081
        (modelSelector := aProp model) notNil ifTrue:[
cg@2024
  1082
            self generateCodeFrom:(Array with:modelSelector) in:cls
cg@2024
  1083
                do:[:aSel|
cg@2024
  1084
                    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
cg@2024
  1085
                        skip := false.
cg@2024
  1086
cg@2024
  1087
                        (cls isSubclassOf:SimpleDialog) ifTrue:[
cg@2024
  1088
                            skip := SimpleDialog includesSelector:aSel
cg@2024
  1089
                        ].
cg@2024
  1090
                        (definedMethodSelectors includes:aSel) ifTrue:[
cg@2024
  1091
                            skip := true.
cg@2024
  1092
                        ].
cg@2024
  1093
cg@2024
  1094
                        skip ifFalse:[
cg@2024
  1095
                            "/ kludge ..
cg@2024
  1096
                            "/ (protoSpec isKindOf:ActionButtonSpec)
cg@2024
  1097
                            (protoSpec defaultModelIsCallBackMethodSelector:aSel)
cg@2024
  1098
                            ifTrue:[
cg@2024
  1099
                                thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
cg@2024
  1100
                            ] ifFalse:[
cg@2024
  1101
                                thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
cg@2024
  1102
                            ].
cg@2024
  1103
                            codePieces add:thisCode.
cg@2024
  1104
                            definedMethodSelectors add:aSel.
cg@2024
  1105
                            Transcript showCR:'code generated for aspect: ' , aSel
cg@2024
  1106
                        ] ifTrue:[
cg@2024
  1107
                            Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)'
cg@2024
  1108
                        ].
cg@2024
  1109
                    ].
cg@2024
  1110
                ].
cg@2024
  1111
        ].
cg@2024
  1112
cg@2024
  1113
        "/ for each aspect, generate getter (if not yet implemented)
cg@2024
  1114
        self generateCodeFrom:(aProp spec aspectSelectors) in:cls
cg@2024
  1115
                do:[:aSel|
cg@2024
  1116
                    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
cg@2024
  1117
                        (definedMethodSelectors includes:aSel) ifFalse:[
cg@2024
  1118
                            thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
cg@2024
  1119
                            codePieces add:thisCode.
cg@2024
  1120
                            definedMethodSelectors add:aSel.
cg@2024
  1121
                            Transcript showCR:'code generated for aspect: ' , aSel
cg@2024
  1122
                        ]
cg@2024
  1123
                    ]
cg@2024
  1124
                ].
cg@2024
  1125
cg@2024
  1126
        "/ exported aspects - need setter methods
cg@3092
  1127
        exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect) asMutator].
cg@2024
  1128
        self generateCodeFrom:exportSels in:cls
cg@2024
  1129
                do:[:aSel|
cg@2024
  1130
                    |aspect|
cg@2024
  1131
cg@2024
  1132
                    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
cg@2024
  1133
                        (definedMethodSelectors includes:aSel) ifFalse:[
cg@3136
  1134
                            aspect := (aSel copyButLast) asSymbol.
cg@2024
  1135
                            thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls).
cg@2024
  1136
                            codePieces add:thisCode.
cg@2024
  1137
                            definedMethodSelectors add:aSel.
cg@2024
  1138
                            Transcript showCR:'export code generated for aspect: ' , aSel
cg@2024
  1139
                        ]
cg@2024
  1140
                    ]
cg@2024
  1141
                ].
cg@2024
  1142
cg@2024
  1143
        self generateCodeFrom:(aProp spec actionSelectors) in:cls
cg@2024
  1144
                do:[:aSel|
cg@2024
  1145
                    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
cg@2024
  1146
                        (definedMethodSelectors includes:aSel) ifFalse:[
cg@2024
  1147
                            thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
cg@2024
  1148
                            codePieces add:thisCode.
cg@2024
  1149
                            definedMethodSelectors add:aSel.
cg@2024
  1150
                            Transcript showCR:'action generated for aspect: ' , aSel
cg@2024
  1151
                        ]
cg@2024
  1152
                    ]
cg@2024
  1153
                ].
cg@2024
  1154
cg@2024
  1155
        self generateCodeFrom:(aProp spec valueSelectors) in:cls
cg@2024
  1156
                do:[:aSel|
cg@2024
  1157
                    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
cg@2024
  1158
                        (definedMethodSelectors includes:aSel) ifFalse:[
cg@2024
  1159
                            "/ uppercase: - assume its a globals name.
cg@2024
  1160
                            aSel isUppercaseFirst ifFalse:[
cg@2024
  1161
                                thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
cg@2024
  1162
                                codePieces add:thisCode.
cg@2024
  1163
                                definedMethodSelectors add:aSel.
cg@2024
  1164
                                Transcript showCR:'code generated for aspect: ' , aSel
cg@2024
  1165
                            ]
cg@2024
  1166
                        ]
cg@2024
  1167
                    ]
cg@2024
  1168
                ].
cg@1683
  1169
    ].
cg@1683
  1170
cg@1683
  1171
    AspectsAsInstances ifTrue:[
cg@2024
  1172
        iVars := cls instVarNames asOrderedCollection.
cg@2024
  1173
        definedMethodSelectors do:[:ivar |
cg@2024
  1174
            (iVars includes:ivar) ifFalse:[
cg@2024
  1175
                iVars add:ivar
cg@2024
  1176
            ]
cg@2024
  1177
        ].
cg@2024
  1178
        iVars := iVars asArray.
cg@2024
  1179
        t := cls shallowCopy.
cg@2024
  1180
        t setInstanceVariableString:iVars asStringCollection asString.
cg@2024
  1181
        codePieces addFirst:(t definition , '!!\' withCRs).
cg@1683
  1182
    ].
cg@1683
  1183
werner@1834
  1184
    ^ String
cg@2024
  1185
        streamContents:
cg@2024
  1186
            [:codeStream |
cg@2024
  1187
                codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece].
cg@2024
  1188
            ].
cg@1683
  1189
cg@1683
  1190
    "Modified: / 29.7.1998 / 12:21:19 / cg"
cg@1683
  1191
!
cg@1683
  1192
cg@60
  1193
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
cg@2244
  1194
    |modelClass modelValueString modelValue modelGen codeStream|
ca@134
  1195
ca@149
  1196
    modelClass := protoSpec defaultModelClassFor:aspect.
cg@1257
  1197
    modelValueString := protoSpec defaultModelValueStringFor:aspect.
cg@1257
  1198
    modelValueString notNil ifTrue:[
cg@2244
  1199
        modelGen := modelValueString
cg@1257
  1200
    ] ifFalse:[
cg@2244
  1201
        modelValue := protoSpec defaultModelValueFor:aspect.
cg@2244
  1202
        modelValue isNil ifTrue:[
cg@2244
  1203
            modelGen := modelClass name , ' new'
cg@2244
  1204
        ] ifFalse:[
cg@2244
  1205
            modelGen := modelValue storeString , ' asValue'
cg@2244
  1206
        ].
cg@352
  1207
cg@352
  1208
    ].
ca@134
  1209
cg@2244
  1210
    codeStream := WriteStream on:(String new:100).
cg@2244
  1211
    codeStream  
cg@2244
  1212
        nextPutLine:('!!' , targetClass name , ' methodsFor:''aspects''!!');
cg@2244
  1213
        nextPutLine:aspect;
cg@2244
  1214
        nextPutLine:'    <resource: #uiAspect>';
cg@2244
  1215
        cr.
cg@2244
  1216
cg@2244
  1217
    self class generateCommentedCode ifTrue:[
cg@2244
  1218
        codeStream  
cg@2244
  1219
            nextPutAll:'    "automatically generated by UIPainter ..."
cg@2244
  1220
cg@2244
  1221
    "*** the code below creates a default model when invoked."
cg@2244
  1222
    "*** (which may not be the one you wanted)"
cg@2244
  1223
    "*** Please change as required and accept it in the browser."
cg@2244
  1224
    "*** (and replace this comment by something more useful ;-)"
cg@2244
  1225
cg@2244
  1226
'.
cg@2244
  1227
    ].
cg@1474
  1228
cg@925
  1229
    AspectsAsInstances ifTrue:[
cg@2244
  1230
        codeStream
cg@2244
  1231
            nextPutLine:('    ',aspect,' isNil ifTrue:[');
cg@2244
  1232
            nextPutLine:('        ',aspect,' := ',modelGen,'.').
cg@2244
  1233
cg@2244
  1234
        modelClass ~~ TriggerValue ifTrue:[
cg@2244
  1235
            self class generateCommentedCode ifTrue:[
cg@2244
  1236
                codeStream
cg@2244
  1237
                    nextPutLine:'"/ if your app needs to be notified of changes, uncomment one of the lines below:'.
cg@2244
  1238
            ].
cg@2244
  1239
            codeStream
cg@2244
  1240
                nextPutLine:'"/       ',aspect,' addDependent:self.';
cg@2244
  1241
                nextPutLine:'"/       ',aspect,' onChangeSend:#',aspect,'Changed to:self.'.
cg@2244
  1242
        ].
cg@2244
  1243
        codeStream
cg@2244
  1244
            nextPutLine:'    ].';
cg@2244
  1245
            nextPutLine:'    ^ ',aspect,'.'.
cg@925
  1246
    ] ifFalse:[
cg@2244
  1247
        codeStream
cg@2244
  1248
            nextPutLine:('    |holder|');
cg@2244
  1249
            cr;
cg@2244
  1250
            nextPutLine:('    (holder := builder bindingAt:#',aspect,') isNil ifTrue:[');
cg@2244
  1251
            nextPutLine:('        holder := ',modelGen,'.');
cg@2244
  1252
            nextPutLine:('        builder aspectAt:#',aspect,' put:holder.').
cg@2244
  1253
cg@2244
  1254
        modelClass ~~ TriggerValue ifTrue:[
cg@2244
  1255
            self class generateCommentedCode ifTrue:[
cg@2244
  1256
                codeStream
cg@2244
  1257
                    nextPutLine:'"/ if your app needs to be notified of changes, uncomment one of the lines below:'.
cg@2244
  1258
            ].
cg@2244
  1259
            codeStream
cg@2244
  1260
                nextPutLine:'"/       holder addDependent:self.';
cg@2244
  1261
                nextPutLine:'"/       holder onChangeSend:#',aspect,'Changed to:self.'.
cg@2244
  1262
        ].
cg@2244
  1263
        codeStream
cg@2244
  1264
            nextPutLine:'    ].';
cg@2244
  1265
            nextPutLine:'    ^ holder.'.
cg@925
  1266
    ].
cg@1361
  1267
cg@2244
  1268
    codeStream
cg@2244
  1269
        nextPutLine:'!! !!'; cr.
cg@2244
  1270
"/ self halt.
cg@2244
  1271
    ^ codeStream contents.
cg@2244
  1272
cg@2244
  1273
    "Modified: / 22-09-1999 / 12:33:47 / stefan"
cg@2244
  1274
    "Modified: / 12-01-2008 / 10:21:43 / cg"
cg@60
  1275
!
cg@60
  1276
ca@1358
  1277
generateAspectSelectorsMethod
ca@1358
  1278
    "generate aspectSelectors method.
ca@1358
  1279
     Return a string ready to compile into the application class."
ca@1358
  1280
ca@1358
  1281
    |cls code spec|
ca@1358
  1282
cg@1683
  1283
    cls := self targetClass.
cg@1683
  1284
    cls isNil ifTrue:[
werner@1834
  1285
	^ nil
ca@1358
  1286
    ].
ca@1358
  1287
ca@1358
  1288
    spec := treeView exportedAspects.
ca@1358
  1289
    spec size == 0 ifTrue:[^ nil].
ca@1358
  1290
ca@1358
  1291
    "/ make it an array ...
cg@1362
  1292
    spec := spec collect:[:entry | |subAspect type|
werner@1834
  1293
		subAspect := entry subAspect asSymbol.
werner@1834
  1294
		(type := entry type) isNil ifTrue:[
werner@1834
  1295
		    subAspect
werner@1834
  1296
		] ifFalse:[
werner@1834
  1297
		    Array with:subAspect with:type asSymbol
werner@1834
  1298
		].
werner@1834
  1299
	    ].
ca@1358
  1300
    spec := spec asArray.
ca@1358
  1301
ca@1358
  1302
    code := '!!' , cls name , ' class methodsFor:''plugIn spec''!!\\' .
ca@1358
  1303
ca@1358
  1304
    code := code , 'aspectSelectors
ca@1358
  1305
    "This resource specification was automatically generated
ca@1358
  1306
     by the UIPainter of ST/X."
ca@1358
  1307
ca@1358
  1308
    "Do not manually edit this. If it is corrupted,
ca@1358
  1309
     the UIPainter may not be able to read the specification."
ca@1358
  1310
ca@1358
  1311
    "Return a description of exported aspects;
ca@1358
  1312
     these can be connected to aspects of an embedding application
ca@1358
  1313
     (if this app is embedded in a subCanvas)."
ca@1358
  1314
cg@1362
  1315
    ^ #(\'.
cg@1362
  1316
    spec do:[:el | code := code , ('        ' , el storeString , '\') ].
cg@1362
  1317
    code := code , '      ).\'.
cg@1362
  1318
    code := code , '\!!\'.
ca@1358
  1319
    code := code withCRs.
ca@1358
  1320
    ^ code
ca@1358
  1321
cg@1362
  1322
    "Modified: / 18.2.2000 / 02:08:34 / cg"
ca@1358
  1323
!
ca@1358
  1324
cg@1361
  1325
generateAspectSetMethodFor:aspect spec:protoSpec inClass:targetClass
cg@1361
  1326
    |code|
cg@1361
  1327
cg@1361
  1328
    code := '!!' , targetClass name , ' methodsFor:''aspects - exported''!!\\' ,
cg@1361
  1329
      aspect , ':something\' ,
cg@1361
  1330
      '    "automatically generated by UIPainter ..."\\' ,
cg@1361
  1331
      '    "This method is used when I am embedded as subApplication,"\' ,
cg@1361
  1332
      '    "and the mainApp wants to connect its aspects to mine."\'.
cg@1361
  1333
cg@1361
  1334
    AspectsAsInstances ifTrue:[
werner@1834
  1335
	code := (code , '\' ,
werner@1834
  1336
	  '"/     ' , aspect , ' notNil ifTrue:[\' ,
werner@1834
  1337
	  '"/        ' , aspect , ' removeDependent:self.\' ,
werner@1834
  1338
	  '"/     ].\' ,
werner@1834
  1339
	  '    ' , aspect ,' := something.\' ,
werner@1834
  1340
	  '"/     ' , aspect ,' notNil ifTrue:[\' ,
werner@1834
  1341
	  '"/        ' , aspect , ' addDependent:self.\' ,
werner@1834
  1342
	  '"/     ].\' ,
werner@1834
  1343
	  '    ^ self.\' ,
werner@1834
  1344
	  '!! !!\\')
cg@1361
  1345
    ] ifFalse:[
werner@1834
  1346
	code := (code , '\' ,
werner@1834
  1347
	  '"/     |holder|\' ,
werner@1834
  1348
	  '\' ,
werner@1834
  1349
	  '"/     (holder := builder bindingAt:#' , aspect , ') notNil ifTrue:[\' ,
werner@1834
  1350
	  '"/         holder removeDependent:self.\' ,
werner@1834
  1351
	  '"/     ].\' ,
werner@1834
  1352
	  '    builder aspectAt:#' , aspect , ' put:something.\',
werner@1834
  1353
	  '"/     something notNil ifTrue:[\' ,
werner@1834
  1354
	  '"/         something addDependent:self.\' ,
werner@1834
  1355
	  '"/     ].\' ,
werner@1834
  1356
	  '    ^ self.\' ,
werner@1834
  1357
	  '!! !!\\')
cg@1361
  1358
    ].
cg@1361
  1359
cg@1361
  1360
    ^ code withCRs
cg@1361
  1361
cg@1361
  1362
    "Modified: / 29.7.1998 / 11:29:16 / cg"
cg@1361
  1363
    "Modified: / 22.9.1999 / 12:33:47 / stefan"
cg@1361
  1364
!
cg@1361
  1365
tz@698
  1366
generateCodeFrom:aListOfSelectors in:aClass do:aBlock
cg@1696
  1367
    |realSelectors redefCondition redefMessage|
cg@1696
  1368
cg@2250
  1369
    realSelectors := aListOfSelectors select:[:sel | sel isString or:[sel isSymbol]].
tz@698
  1370
tz@744
  1371
    self class redefineAspectMethods ifTrue:[
sv@2195
  1372
        redefCondition := [:cls :sel | (cls includesSelector:sel) not].
sv@2195
  1373
        redefMessage := ' skipped - already implemented in the class'.
tz@698
  1374
    ] ifFalse:[
sv@2195
  1375
        redefCondition := [:cls :sel | (cls canUnderstand:sel) not].
sv@2195
  1376
        redefMessage := ' skipped - already implemented in the class (or superclass)'.
cg@1696
  1377
    ].
cg@1696
  1378
cg@1696
  1379
    realSelectors do:[:aSelector|
sv@2195
  1380
        (redefCondition value:aClass value:aSelector) ifTrue:[
sv@2195
  1381
            aBlock value:aSelector asSymbol
sv@2195
  1382
        ] ifFalse:[
sv@2195
  1383
            Transcript showCR:('#' , aSelector , redefMessage)
sv@2195
  1384
        ]
tz@698
  1385
    ]
cg@376
  1386
!
cg@376
  1387
cg@376
  1388
generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass
cg@376
  1389
    ^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' ,
cg@376
  1390
      selectorSpec , '\' ,
cg@376
  1391
      '    "automatically generated by UIPainter ..."\\' ,
cg@376
  1392
      '    "*** the code here does nothing. It is invoked when"\' ,
cg@376
  1393
      '    "*** ' , commentWhen , '"\' ,
cg@376
  1394
      '    "*** Please change as required and accept in the browser."\' ,
cg@376
  1395
      '\' ,
cg@376
  1396
      '    "specific code to be added below ..."\' ,
cg@376
  1397
      '    "' , (noteOrNil ? '') , '"\' ,
cg@376
  1398
      '\' ,
cg@376
  1399
      (defaultCode ? '^ self.') ,
cg@376
  1400
      '!! !!\\') withCRs
cg@376
  1401
cg@376
  1402
    "Modified: / 25.10.1997 / 19:22:17 / cg"
cg@376
  1403
    "Created: / 31.10.1997 / 17:31:53 / cg"
cg@376
  1404
!
cg@376
  1405
cg@376
  1406
generateHookMethods
cg@376
  1407
    "generate hook methods
cg@376
  1408
     - but do not overwrite existing ones.
cg@376
  1409
     Return a string ready to compile into the application class."
cg@376
  1410
cg@1683
  1411
    |cls|
cg@1683
  1412
cg@1683
  1413
    cls := self targetClass.
cg@1683
  1414
    cls isNil ifTrue:[
werner@1834
  1415
	^ nil
cg@376
  1416
    ].
cg@1683
  1417
cg@1683
  1418
    ^ self generateHookMethodsInClass:cls.
cg@376
  1419
!
cg@376
  1420
cg@376
  1421
generateHookMethodsInClass:targetClass
cg@376
  1422
    |code|
cg@376
  1423
cg@376
  1424
    code := ''.
cg@376
  1425
cg@1554
  1426
    (targetClass includesSelector:#postBuildWith:) ifFalse:[
werner@1834
  1427
	code := code
werner@1834
  1428
		, (self
werner@1834
  1429
		    generateHookMethodFor:'postBuildWith:aBuilder'
werner@1834
  1430
		    comment:'the widgets have been built, but before the view is opened'
werner@1834
  1431
		    note:'or after the super send'
werner@1834
  1432
		    defaultCode:'    super postBuildWith:aBuilder'
werner@1834
  1433
		    inClass:targetClass)
cg@376
  1434
    ].
cg@1554
  1435
    (targetClass includesSelector:#postOpenWith:) ifFalse:[
werner@1834
  1436
	code := code
werner@1834
  1437
		, (self
werner@1834
  1438
		    generateHookMethodFor:'postOpenWith:aBuilder'
werner@1834
  1439
		    comment:'the topView has been opened, but before events are dispatched for it'
werner@1834
  1440
		    note:'or after the super send'
werner@1834
  1441
		    defaultCode:'    super postOpenWith:aBuilder'
werner@1834
  1442
		    inClass:targetClass)
cg@376
  1443
    ].
cg@1554
  1444
    (targetClass includesSelector:#closeRequest) ifFalse:[
werner@1834
  1445
	code := code
werner@1834
  1446
		, (self
werner@1834
  1447
		    generateHookMethodFor:'closeRequest'
werner@1834
  1448
		    comment:'the topView has been asked to close'
werner@1834
  1449
		    note:'return without the ''super closeRequest'' to stay open'
werner@1834
  1450
		    defaultCode:'    ^super closeRequest'
werner@1834
  1451
		    inClass:targetClass)
cg@376
  1452
    ].
cg@376
  1453
    ^ code
cg@376
  1454
cg@376
  1455
    "Modified: / 31.10.1997 / 17:30:34 / cg"
cg@376
  1456
    "Created: / 31.10.1997 / 17:32:49 / cg"
cg@60
  1457
!
cg@60
  1458
cg@965
  1459
generateMenuMethodFor:menuSel inClass:targetClass
cg@1805
  1460
    |selector args showIt code alreadyInSuperclass numArgs method category|
cg@965
  1461
cg@965
  1462
    selector := menuSel asSymbol.
cg@1805
  1463
    category := UserPreferences current categoryForMenuActionsMethods.
cg@965
  1464
cg@965
  1465
    alreadyInSuperclass := targetClass superclass canUnderstand:selector.
cg@965
  1466
cg@1805
  1467
    code := '!!' , targetClass name , ' methodsFor:''' , category , '''!!\\'.
cg@965
  1468
cg@965
  1469
    selector = 'openAboutThisApplication' ifTrue:[
werner@1834
  1470
	code := code ,
werner@1834
  1471
		'openAboutThisApplication\' ,
werner@1834
  1472
		'    "opens an about box for this application."\\' ,
werner@1834
  1473
		'    "automatically generated by UIPainter ..."\\' ,
werner@1834
  1474
werner@1834
  1475
		'    |rev box myClass clsRev image msg|\\' ,
werner@1834
  1476
werner@1834
  1477
		'    rev := ''''.\' ,
werner@1834
  1478
		'    myClass := self class.\' ,
werner@1834
  1479
werner@1834
  1480
		'    (clsRev := myClass revision) notNil ifTrue:[\' ,
werner@1834
  1481
		'       rev := ''  (rev: '', clsRev printString, '')''].\\' ,
werner@1834
  1482
werner@1834
  1483
		'    msg := Character cr asString , myClass name asBoldText, rev.\' ,
werner@1834
  1484
		'    msg := (msg , ''\\*** add more info here ***\\'') withCRs.\\' ,
werner@1834
  1485
		'    box := AboutBox title:msg.\' ,
werner@1834
  1486
werner@1834
  1487
		'    "/ *** add a #defaultIcon method in the class\' ,
werner@1834
  1488
		'    "/ *** and uncomment the following line:\' ,
werner@1834
  1489
		'    "/ image := self class defaultIcon.\\' ,
werner@1834
  1490
		'    image notNil ifTrue:[\' ,
werner@1834
  1491
		'        box image:image\' ,
werner@1834
  1492
		'    ].\' ,
werner@1834
  1493
		'    box   label:(resources string:''About %1'' with:myClass name).\' ,
werner@1834
  1494
		'    box   autoHideAfter:10 with:[].\' ,
werner@1834
  1495
		'    box   showAtPointer.\' ,
werner@1834
  1496
		'!! !!\\'.
werner@1834
  1497
	^ code withCRs
cg@965
  1498
    ].
cg@965
  1499
cg@965
  1500
    selector = 'menuOpen' ifTrue:[
werner@1834
  1501
	code := code ,
werner@1834
  1502
		'menuOpen\' ,
werner@1834
  1503
		'    "automatically generated by UIPainter ..."\\' ,
werner@1834
  1504
		'    "*** the code below opens a dialog for file selection"\' ,
werner@1834
  1505
		'    "*** and invokes the #doOpen: method with the selected file."\' ,
werner@1834
  1506
		'    "*** Please change as required and accept in the browser."\\' ,
werner@1834
  1507
		'    |file|\\' ,
werner@1834
  1508
		'    file :=\' ,
werner@1834
  1509
		'        (FileSelectionBrowser\' ,
werner@1834
  1510
		'            request: ''Open''\' ,
werner@1834
  1511
		'            fileName: ''''\' ,
werner@1834
  1512
		'            "/ inDirectory: lastOpenDirectory\' ,
werner@1834
  1513
		'            withFileFilters: #(''*'')).\\' ,
werner@1834
  1514
		'    file notNil ifTrue:[\' ,
werner@1834
  1515
		'       "/ lastOpenDirectory := file asFilename directory.\' ,
werner@1834
  1516
		'       self doOpen:file\' ,
werner@1834
  1517
		'    ]\' ,
werner@1834
  1518
		'!! !!\'.
werner@1834
  1519
	^ code withCRs
cg@965
  1520
    ].
cg@965
  1521
cg@965
  1522
    numArgs := selector numArgs.
cg@965
  1523
    method  := selector.
cg@965
  1524
cg@965
  1525
    numArgs == 1 ifTrue:[
werner@1834
  1526
	args := 'anArgument'.
werner@1834
  1527
	showIt := ''' , anArgument printString , '' ...''.\'.
werner@1834
  1528
    ] ifFalse:[
werner@1834
  1529
	args := ''.
werner@1834
  1530
	showIt := ' ...''.\'.
werner@1834
  1531
werner@1834
  1532
	numArgs ~~ 0 ifTrue:[
werner@1834
  1533
	    method := ''.
werner@1834
  1534
werner@1834
  1535
	    selector keywords keysAndValuesDo:[:i :key|
werner@1834
  1536
		method := method, key, 'arg', i printString, ' '
werner@1834
  1537
	    ]
werner@1834
  1538
	]
cg@965
  1539
    ].
cg@965
  1540
cg@965
  1541
    code := code ,
werner@1834
  1542
		method , args , '\' ,
werner@1834
  1543
		'    "automatically generated by UIPainter ..."\\' ,
werner@1834
  1544
		'    "*** the code below performs no action"\' ,
werner@1834
  1545
		'    "*** (except for some feedback on the Transcript)"\' ,
werner@1834
  1546
		'    "*** Please change as required and accept in the browser."\' ,
werner@1834
  1547
		'\' .
cg@965
  1548
cg@965
  1549
    alreadyInSuperclass ifTrue:[
werner@1834
  1550
	code := code ,
werner@1834
  1551
		    '    "action for ' , selector , ' is already provided in a superclass."\' ,
werner@1834
  1552
		    '    "It may be redefined here ..."\\'.
cg@965
  1553
    ] ifFalse:[
werner@1834
  1554
	code := code ,
werner@1834
  1555
		    '    "action to be added ..."\\'.
cg@965
  1556
    ].
cg@965
  1557
cg@965
  1558
    code := code ,
werner@1834
  1559
		'    Transcript showCR:self class name, '': '.
cg@965
  1560
    alreadyInSuperclass ifTrue:[
werner@1834
  1561
	code := code , 'inherited '.
cg@965
  1562
    ].
cg@965
  1563
    code := code , 'menu action for ' , selector , showIt.
cg@965
  1564
cg@965
  1565
    alreadyInSuperclass ifTrue:[
werner@1834
  1566
	code := code ,
werner@1834
  1567
			'    super ' , selector , args , '.\'.
cg@965
  1568
    ].
cg@965
  1569
cg@965
  1570
    code := code ,
werner@1834
  1571
		'!! !!\\'.
cg@965
  1572
    ^ code withCRs
cg@965
  1573
cg@965
  1574
    "Created: / 23.8.1998 / 16:46:51 / cg"
cg@965
  1575
    "Modified: / 23.8.1998 / 18:13:05 / cg"
cg@965
  1576
!
cg@965
  1577
cg@965
  1578
generateMenuMethods
cg@965
  1579
    "generate menu methods
cg@965
  1580
     - but do not overwrite existing ones.
cg@965
  1581
     Return a string ready to compile into the application class."
cg@965
  1582
cg@1069
  1583
    |cls code menuSelector thisCode
cg@1069
  1584
     definedMethodSelectors
cg@2276
  1585
     spec specArray fullSpec winSpec menuSpec|
cg@965
  1586
cg@1683
  1587
    cls := self targetClass.
cg@1683
  1588
    cls isNil ifTrue:[
cg@2276
  1589
        ^ nil
cg@965
  1590
    ].
cg@965
  1591
cg@2276
  1592
    spec := treeView generateFullSpecForComponents:#() named:nil.
cg@2276
  1593
    specArray := spec literalArrayEncoding.
cg@965
  1594
    fullSpec := specArray decodeAsLiteralArray.
cg@965
  1595
    winSpec := fullSpec window.
cg@965
  1596
    menuSelector := winSpec menu.
cg@965
  1597
werner@1834
  1598
    (menuSelector notNil
cg@1069
  1599
    and:[ (cls respondsTo:menuSelector) ]) ifFalse:[
cg@2276
  1600
        self warn:'No menu defined (yet)'.
cg@2276
  1601
        ^ nil.
cg@965
  1602
    ].
cg@965
  1603
    menuSpec := cls perform:menuSelector.
cg@965
  1604
    menuSpec := menuSpec decodeAsLiteralArray.
cg@965
  1605
cg@965
  1606
    definedMethodSelectors := IdentitySet new.
cg@965
  1607
    code := ''.
cg@965
  1608
cg@965
  1609
    menuSpec allItemsDo:[:item |
cg@2276
  1610
        |sel|
cg@2276
  1611
cg@2276
  1612
        (sel := item value) notNil ifTrue:[
cg@2276
  1613
            (definedMethodSelectors includes:sel) ifFalse:[
cg@2276
  1614
                self generateCodeFrom:(Array with:sel) in:cls do:[:aSel|
cg@2276
  1615
                    thisCode := (self generateMenuMethodFor:aSel inClass:cls).
cg@2276
  1616
                    code := code, thisCode.
cg@2276
  1617
                ].
cg@2276
  1618
                definedMethodSelectors add:sel.
cg@2276
  1619
            ].
cg@2276
  1620
        ]
cg@965
  1621
    ].
cg@965
  1622
cg@965
  1623
    (definedMethodSelectors includes:#menuOpen) ifTrue:[
cg@2276
  1624
        self generateCodeFrom:(Array with:#doOpen:) in:cls do:[:aSel|
cg@2276
  1625
            thisCode := (self generateMenuMethodFor:aSel inClass:cls).
cg@2276
  1626
            code := code, thisCode.
cg@2276
  1627
        ].
cg@965
  1628
    ].
cg@965
  1629
cg@965
  1630
    ^ code
cg@965
  1631
cg@965
  1632
    "Created: / 23.8.1998 / 16:12:09 / cg"
cg@965
  1633
    "Modified: / 23.8.1998 / 18:12:23 / cg"
cg@965
  1634
!
cg@965
  1635
ca@188
  1636
generateValueMethodFor:aspect spec:protoSpec inClass:targetClass
ca@188
  1637
    ^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' ,
ca@188
  1638
      aspect , '\' ,
cg@352
  1639
      '    "automatically generated by UIPainter ..."\\' ,
cg@352
  1640
      '    "*** the code below returns a default value when invoked."\' ,
cg@352
  1641
      '    "*** (which may not be the one you wanted)"\' ,
cg@352
  1642
      '    "*** Please change as required and accept in the browser."\' ,
ca@188
  1643
      '\' ,
ca@188
  1644
      '    "value to be added below ..."\' ,
ca@188
  1645
      '    Transcript showCR:self class name , '': no value yet for ' , aspect , ' ...''.\' ,
ca@188
  1646
      '\' ,
ca@188
  1647
      '^ nil.' ,
ca@188
  1648
      '!! !!\\') withCRs
ca@188
  1649
cg@352
  1650
    "Modified: / 25.10.1997 / 19:22:17 / cg"
ca@188
  1651
!
ca@188
  1652
cg@2197
  1653
generateWindowSpec
cg@3038
  1654
    |spec addToSpec specsAlready|
cg@2197
  1655
cg@2197
  1656
    spec := OrderedCollection new.
cg@3038
  1657
    specsAlready := IdentitySet new.
cg@2197
  1658
cg@2499
  1659
    addToSpec :=
cg@2499
  1660
        [:aView|
cg@2499
  1661
            |vSpec|
cg@2499
  1662
            "/ care for wrapped views ...
cg@2499
  1663
            vSpec := self fullSpecFor:aView.
cg@2499
  1664
            vSpec isNil ifTrue:[
cg@2499
  1665
                aView subViews size == 1 ifTrue:[
cg@2499
  1666
                    vSpec := self fullSpecFor:(aView subViews first).
cg@2499
  1667
                ]
cg@2499
  1668
            ].
cg@2499
  1669
            vSpec isNil ifTrue:[
cg@2505
  1670
                (Dialog 
cg@2505
  1671
                    confirm:('Oops - could not create spec for view: %1\\Continue ?' bindWith:aView printString) withCRs
cg@2505
  1672
                    noLabel:'Abort')
cg@2505
  1673
                ifFalse:[
sv@3067
  1674
                    AbortOperationRequest raise
cg@2505
  1675
                ].
cg@2499
  1676
            ].
cg@3038
  1677
            (specsAlready includes:vSpec) ifTrue:[self halt].
cg@3038
  1678
            specsAlready add:vSpec.
cg@2499
  1679
            spec add:vSpec
cg@2197
  1680
        ].
cg@2499
  1681
cg@2499
  1682
    self subViews do:addToSpec.
cg@2499
  1683
    self components do:addToSpec.
cg@2197
  1684
    spec := treeView generateFullSpecForComponents:spec named:methodName.
cg@2197
  1685
    ^ spec
cg@3038
  1686
cg@3038
  1687
    "Modified: / 30-07-2013 / 09:13:13 / cg"
cg@2197
  1688
!
cg@2197
  1689
ca@78
  1690
generateWindowSpecMethodSource
cg@3031
  1691
    ^ self 
cg@3031
  1692
        generateWindowSpecMethodSourceFor:(self generateWindowSpec) 
cg@3031
  1693
        class:className 
cg@3031
  1694
        selector:methodName
cg@3031
  1695
cg@3031
  1696
    "Modified: / 5.9.1995 / 21:01:35 / claus"
cg@3031
  1697
    "Modified: / 15.10.1998 / 11:29:53 / cg"
cg@3031
  1698
!
cg@3031
  1699
cg@3031
  1700
generateWindowSpecMethodSourceFor:spec class:className selector:methodName
cg@3031
  1701
    |specArray str code category cls mthd specCode|
cg@3031
  1702
cg@2276
  1703
    specArray := spec literalArrayEncoding.
cg@2197
  1704
sv@3327
  1705
    str  := WriteStream on:''.
cg@3031
  1706
    UISpecification prettyPrintSpecArray:specArray on:str indent:4.
cg@464
  1707
    specCode := str contents.
cg@457
  1708
cg@457
  1709
    (specCode includes:$!!) ifTrue:[
cg@2197
  1710
        "/ oops - must be chunk format ...
sv@3327
  1711
        str  := WriteStream on:''.
cg@2197
  1712
        str nextPutAllAsChunk:specCode.
cg@2197
  1713
        specCode := str contents.
cg@457
  1714
    ].
cg@60
  1715
cg@178
  1716
    "/ if that method already exists, do not overwrite the category
cg@178
  1717
cg@178
  1718
    category := 'interface specs'.
ca@330
  1719
    cls := self resolveName:className.
ca@330
  1720
ca@330
  1721
    cls notNil ifTrue:[
cg@2197
  1722
        (mthd := cls class compiledMethodAt:methodName asSymbol) notNil ifTrue:[
cg@2197
  1723
            category := mthd category.
cg@2197
  1724
        ]
cg@178
  1725
    ].
cg@178
  1726
cg@238
  1727
    code := '!!'
cg@2197
  1728
            , className , ' class methodsFor:' , category storeString
cg@2197
  1729
            , '!!' , '\\'
cg@2197
  1730
cg@2197
  1731
            , methodName , '\'
cg@2197
  1732
            , ((ResourceSpecEditor codeGenerationCommentForClass: UIPainter) replChar:$!! withString:'!!!!')
cg@2197
  1733
            , '\\    "\'
cg@2197
  1734
            , ('     UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\').
cg@1013
  1735
cg@1050
  1736
    (cls notNil and:[cls isSubclassOf:ApplicationModel]) ifTrue:[
cg@2197
  1737
        code := code
cg@2197
  1738
            , ('     ' , className , ' new openInterface:#' , methodName , '\').
cg@1013
  1739
    ].
cg@1013
  1740
cg@1013
  1741
    code := code
cg@2197
  1742
            ,(methodName = 'windowSpec'
cg@2197
  1743
                ifTrue:['     ' , className , ' open\'] ifFalse: [''])
cg@2197
  1744
            , '    "\'.
werner@1834
  1745
werner@1834
  1746
    code := code
cg@2197
  1747
            , '\'
cg@3223
  1748
            , '    <resource: #canvas>\\'.
cg@3223
  1749
    code := code withCRs.
cg@3223
  1750
    code := code
cg@2197
  1751
            , '    ^ ' , specCode
cg@3223
  1752
            , '\' withCRs
cg@2197
  1753
            , '!! !!'
cg@3223
  1754
            , '\\' withCRs.
cg@3223
  1755
cg@3223
  1756
    ^ code
cg@1683
  1757
!
cg@1683
  1758
cg@2244
  1759
listOfAspects
cg@2244
  1760
    |cls aspects|
cg@2244
  1761
cg@2276
  1762
    listOfAspectsHolder notNil ifTrue:[
cg@2276
  1763
        ^ listOfAspectsHolder value
cg@2276
  1764
    ].
cg@2276
  1765
cg@2244
  1766
    aspects := IdentitySet new.
cg@2244
  1767
cg@2244
  1768
    cls := self targetClass.
cg@2244
  1769
    cls notNil ifTrue:[
cg@2265
  1770
        cls withAllSuperclassesDo:[:cls |
cg@2265
  1771
            cls methodsDo:[:m |
cg@3293
  1772
                ((m resources ? #()) includes:#uiAspect) ifTrue:[
cg@2265
  1773
                    aspects add:m selector
cg@2265
  1774
                ].                  
cg@2265
  1775
            ]
cg@2244
  1776
        ]
cg@2244
  1777
    ].
cg@2244
  1778
cg@2244
  1779
    treeView propertiesDo:[:aProp|
cg@2244
  1780
        |modelSelector|
cg@2244
  1781
cg@2244
  1782
        (modelSelector := aProp model) notNil ifTrue:[
cg@2244
  1783
            aspects add:modelSelector asSymbol
cg@2244
  1784
        ].
cg@2244
  1785
cg@2244
  1786
"/        aspects addAll:aProp spec actionSelectors.
cg@2250
  1787
cg@2250
  1788
        aspects addAll:(aProp spec valueSelectors select:[:a | a isString or:[a isSymbol]]).
cg@2250
  1789
        aspects addAll:(aProp spec aspectSelectors select:[:a | a isString or:[a isSymbol]]).
cg@2244
  1790
    ].
cg@2244
  1791
cg@2244
  1792
    ^ aspects asOrderedCollection sort.
cg@2244
  1793
cg@2244
  1794
    "Created: / 12-01-2008 / 19:24:45 / cg"
cg@2244
  1795
!
cg@2244
  1796
cg@2244
  1797
listOfCallbacks
cg@2244
  1798
    |cls aspects|
cg@2244
  1799
cg@2244
  1800
    aspects := IdentitySet new.
cg@2244
  1801
cg@2244
  1802
    cls := self targetClass.
cg@2244
  1803
    cls notNil ifTrue:[
cg@2244
  1804
        cls methodsDo:[:m |
cg@3293
  1805
            ((m resources ? #()) includes:#uiCallback) ifTrue:[
cg@2244
  1806
                aspects add:m selector
cg@2244
  1807
            ].                  
cg@2244
  1808
        ]
cg@2244
  1809
    ].
cg@2244
  1810
cg@2244
  1811
    treeView propertiesDo:[:aProp|
cg@2244
  1812
        |modelSelector|
cg@2244
  1813
cg@2244
  1814
        aspects addAll:aProp spec actionSelectors.
cg@2244
  1815
"/        aspects addAll:aProp spec valueSelectors.
cg@2244
  1816
"/        aspects addAll:aProp spec aspectSelectors.
cg@2244
  1817
    ].
cg@2244
  1818
cg@2244
  1819
    ^ aspects asOrderedCollection sort.
cg@2244
  1820
cg@2244
  1821
    "Created: / 12-01-2008 / 19:25:19 / cg"
cg@2244
  1822
!
cg@2244
  1823
cg@1683
  1824
targetClass
cg@1683
  1825
    |cls|
cg@1683
  1826
cg@1683
  1827
    className isNil ifTrue:[
cg@2248
  1828
        self warn:'No TargetClass defined !!'.
cg@2248
  1829
        ^ nil
cg@1683
  1830
    ].
cg@1683
  1831
    (cls := self resolveName:className) isNil ifTrue:[
cg@2248
  1832
"/        self warn:('Class ', className asString, ' does not exist !!').
cg@2248
  1833
        ^ nil
cg@1683
  1834
    ].
cg@1683
  1835
    ^ cls.
cg@60
  1836
! !
cg@60
  1837
tz@754
  1838
!UIPainterView methodsFor:'grid manipulation'!
tz@754
  1839
tz@754
  1840
newGrid
tz@754
  1841
    "define a new grid - this is a private helper which has to be
tz@754
  1842
     called after any change in the grid. It (re)creates the gridPixmap,
tz@754
  1843
     clears the view and redraws all visible objects."
tz@754
  1844
tz@754
  1845
    |defaultViewBackground|
tz@754
  1846
tz@754
  1847
    gridPixmap := nil.
tz@754
  1848
    defaultViewBackground := self class defaultViewBackgroundColor.
tz@754
  1849
tz@754
  1850
    shown ifTrue:[
sv@3083
  1851
        self viewBackground: (defaultViewBackground isColor
sv@3083
  1852
            ifTrue: [defaultViewBackground]
sv@3083
  1853
            ifFalse:[self blackColor]).
sv@3083
  1854
        self clear.
tz@754
  1855
    ].
tz@754
  1856
tz@754
  1857
    gridShown ifTrue:[
sv@3083
  1858
        self defineGrid.
sv@3083
  1859
        gridPixmap colorMap: (defaultViewBackground isColor
sv@3083
  1860
            ifTrue: [Array with:defaultViewBackground with:Color darkGray]
sv@3083
  1861
            ifFalse:[Array with:self whiteColor with:self blackColor]).
sv@3083
  1862
        self viewBackground:gridPixmap.
tz@754
  1863
    ].
tz@754
  1864
tz@754
  1865
    self invalidate
tz@754
  1866
! !
tz@754
  1867
werner@1832
  1868
!UIPainterView methodsFor:'group & ungroup'!
werner@1832
  1869
werner@1832
  1870
group
werner@1832
  1871
werner@1832
  1872
    self groupSelectionWithLayout: false
werner@1832
  1873
!
werner@1832
  1874
werner@1832
  1875
groupSelectionWithLayout: withLayout
ca@2392
  1876
    |minViews specs spec menu newView target keepLyt keepPos rectangle|
ca@2392
  1877
ca@2392
  1878
    self canGroup ifFalse:[^ self ].
ca@2392
  1879
ca@2392
  1880
    keepLyt := withLayout.
ca@2392
  1881
    keepPos := true.
werner@1832
  1882
werner@1832
  1883
    menu := Menu new.
werner@1832
  1884
    menu receiver: self.
cg@3021
  1885
    menu addItem:(MenuItem label:'Box' itemValue:[spec := ViewSpec new]).
cg@3021
  1886
    menu addItem:(MenuItem label:'TBox' itemValue:[spec := TBoxSpec new]).
cg@3021
  1887
    menu addItem:(MenuItem label:'FramedBox' itemValue:[spec := FramedBoxSpec new]).
cg@3021
  1888
cg@3021
  1889
    menu addItem:(MenuItem 
cg@3021
  1890
                    label:'HorizontalPanel'
cg@3021
  1891
                    itemValue:[
ca@2392
  1892
                        keepLyt := keepPos := false.
ca@2392
  1893
                        spec := HorizontalPanelViewSpec new.
ca@2392
  1894
                        spec verticalLayout: #fit.
ca@2392
  1895
                        spec horizontalLayout: #leftSpace.
ca@2392
  1896
                    ]).
cg@3021
  1897
    menu addItem:(MenuItem 
cg@3021
  1898
                    label:'VerticalPanel'
cg@3021
  1899
                    itemValue:[
ca@2392
  1900
                        keepLyt := keepPos := false.
ca@2392
  1901
                        spec := VerticalPanelViewSpec new.
ca@2392
  1902
                        spec verticalLayout: #topSpace.
ca@2392
  1903
                        spec horizontalLayout: #fit.
ca@2392
  1904
                    ]).
ca@2392
  1905
ca@2392
  1906
    menu startUp.
ca@2392
  1907
    spec isNil ifTrue:[^ self].
ca@2392
  1908
ca@2392
  1909
    minViews := self minClosedViewSetFor:(self selection).
ca@2392
  1910
    minViews size > 1 ifFalse:[^ self].
ca@2392
  1911
ca@2392
  1912
    specs     := OrderedCollection new.
ca@2392
  1913
    rectangle := minViews first frame copy.
ca@2392
  1914
ca@2392
  1915
    minViews do:[:eachView|
ca@2392
  1916
        specs add:(self fullSpecWithAbsolutePositionFor:eachView).
ca@2392
  1917
        rectangle := rectangle quickMerge:(eachView frame).
werner@1832
  1918
    ].
ca@2392
  1919
    spec layout:rectangle.
ca@2392
  1920
ca@2392
  1921
    target := self findContainerOfView:(minViews first).
ca@2392
  1922
ca@2392
  1923
    self withinTransaction:#group objects:(Array with:target) do:[ |widgets|
ca@2392
  1924
        self deleteSelectionBuffered:false.
ca@2392
  1925
ca@2392
  1926
        spec otherAttributeAt:#uiPainterAttributes put:(Dictionary new
ca@2392
  1927
                at:#origin put:(rectangle origin);
ca@2392
  1928
                at:#extent put:(rectangle extent);
ca@2392
  1929
                at:#absOrigin put:(rectangle origin);
ca@2392
  1930
                yourself).
ca@2392
  1931
ca@2392
  1932
        newView := self pasteSpecifications:(Array with:spec) 
ca@2392
  1933
                    into:target
ca@2392
  1934
                    keepLayout:true
ca@2392
  1935
                    keepPosition:true
ca@2392
  1936
                    at:#keep.
ca@2392
  1937
ca@2392
  1938
        widgets := self pasteSpecifications:specs
ca@2392
  1939
                into:newView
ca@2392
  1940
                keepLayout:keepLyt
ca@2392
  1941
                keepPosition:keepPos
ca@2392
  1942
                at:nil.
werner@1832
  1943
    ].
ca@2392
  1944
    self select:newView.
werner@1832
  1945
!
werner@1832
  1946
werner@1832
  1947
groupWithLayout
werner@1832
  1948
werner@1832
  1949
    self groupSelectionWithLayout: true
werner@1832
  1950
!
werner@1832
  1951
werner@1832
  1952
ungroup
werner@1832
  1953
werner@1832
  1954
    self ungroupSelectionWithLayout: false
werner@1832
  1955
!
werner@1832
  1956
werner@1832
  1957
ungroupSelectionWithLayout: withLayout
werner@1832
  1958
werner@1832
  1959
    | canvas cS views specs frame view layout superView|
werner@1832
  1960
ca@2392
  1961
    self canUngroup ifFalse:[^ self ].
ca@2392
  1962
werner@1832
  1963
    canvas := self painter.
werner@1832
  1964
    cS := canvas getSelectedViewsAndSpecs.
werner@1832
  1965
    cS isNil ifTrue:[^self].
werner@1832
  1966
    views := cS first first subViews copy.
werner@1832
  1967
    superView := cS first first superView.
werner@1832
  1968
    cS last first component isNil ifTrue:[^self].
werner@1832
  1969
    cS last first component collection isEmpty ifTrue:[^self].
werner@1834
  1970
    specs := cS last first component collection copy.
werner@1832
  1971
    frame := cS first first frame.
werner@1832
  1972
    canvas deleteSelection.
werner@1832
  1973
    withLayout ifFalse:[
ca@2392
  1974
        1 to: specs size do:[:i|
ca@2392
  1975
            view := views at: i.
ca@2392
  1976
            layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x + frame origin x)
ca@2392
  1977
                                  rightFraction:0.0 offset: (view corner x + frame origin x + 1)
ca@2392
  1978
                                    topFraction:0.0 offset: (view origin y + frame origin y )
ca@2392
  1979
                                 bottomFraction:0.0 offset: (view corner y + frame origin y + 1).
ca@2392
  1980
            (specs at: i) layout: layout.
ca@2392
  1981
        ].
werner@1834
  1982
    ].
werner@1832
  1983
    canvas selection: superView.
werner@1832
  1984
    canvas pasteSpecifications:specs keepLayout:true.
werner@1832
  1985
    canvas selection: superView.
werner@1832
  1986
!
werner@1832
  1987
werner@1832
  1988
ungroupWithLayout
werner@1832
  1989
werner@1832
  1990
    self ungroupSelectionWithLayout: true
werner@1832
  1991
! !
werner@1832
  1992
cg@60
  1993
!UIPainterView methodsFor:'initialization'!
cg@60
  1994
ca@770
  1995
create
cg@1959
  1996
    "colors on device"
cg@1959
  1997
    
ca@770
  1998
    super create.
cg@3262
  1999
    handleColorBlack := handleColorBlack onDevice:device.
cg@3262
  2000
    handleColorWhite := handleColorWhite onDevice:device.
cg@3262
  2001
    handleMasterColor := handleMasterColor onDevice:device.
ca@770
  2002
!
ca@770
  2003
cg@60
  2004
initialize
ca@62
  2005
    "setup attributes
ca@62
  2006
    "
cg@60
  2007
    super initialize.
ca@770
  2008
    superclassName    := 'ApplicationModel'.
ca@770
  2009
    className         := 'NewApplication'.
ca@770
  2010
    methodName        := 'windowSpec'.
ca@770
  2011
    categoryName      := 'Applications'.
ca@770
  2012
    HandCursor        := Cursor leftHand.
sv@3314
  2013
    handleColorBlack  := self blackColor.
sv@3314
  2014
    handleColorWhite  := self whiteColor.
ca@770
  2015
    handleMasterColor := Color red.
cg@60
  2016
tz@712
  2017
    self backgroundColor: self class defaultViewBackgroundColor.
cg@60
  2018
!
cg@60
  2019
cg@60
  2020
setupFromSpec:specOrSpecArray
cg@2197
  2021
    |spec builder specWindow|
ca@78
  2022
tz@784
  2023
    Cursor wait showWhile: [
cg@2197
  2024
        self removeAll.
cg@2197
  2025
        specOrSpecArray notNil ifTrue:[
cg@2526
  2026
            spec := UISpecification from:specOrSpecArray.
cg@2197
  2027
        ].
cg@2197
  2028
        builder := UIBuilder new isEditing:true.
cg@2197
  2029
        "set applicationClass, in order that subspecifications may be resolved"
cg@2197
  2030
        className notNil ifTrue:[
cg@2197
  2031
            builder applicationClass:(self resolveName:className).
cg@2197
  2032
        ].
cg@2197
  2033
        spec notNil ifTrue:[
cg@2197
  2034
            specWindow := spec window.
cg@2197
  2035
        ].
cg@2197
  2036
        specWindow notNil ifTrue:[
cg@2197
  2037
            specWindow setupView:self topView for:builder.
cg@2197
  2038
            self addSpec:(spec component) builder:builder in:self.
cg@2197
  2039
        ].
cg@2197
  2040
        self realizeAllSubViews.
cg@2197
  2041
        specWindow notNil ifTrue:[
cg@2197
  2042
            treeView setAttributesFromWindowSpec:specWindow
cg@2197
  2043
        ].
ca@1671
  2044
    ].
ca@223
  2045
!
ca@223
  2046
ca@223
  2047
treeView:aTreeView
ca@361
  2048
    treeView := aTreeView.
ca@361
  2049
ca@361
  2050
    treeView delegate:(
werner@1834
  2051
	"/
werner@1834
  2052
	"/ I want to handle everything typed
werner@1834
  2053
	"/ in the treeView, except for Return and Cursor-keys
werner@1834
  2054
	"/
werner@1834
  2055
	KeyboardForwarder
werner@1834
  2056
	    toView:self
werner@1834
  2057
	    condition:nil
werner@1834
  2058
	    filter:[:k | (k isSymbol
werner@1834
  2059
			 and:[k ~~ #Return
werner@1834
  2060
			 and:[k ~~ #Tab
werner@1834
  2061
			 and:[(k startsWith:#Cursor) not]]])
werner@1834
  2062
		   ]
ca@361
  2063
    )
ca@361
  2064
cg@376
  2065
    "Modified: / 31.10.1997 / 20:22:09 / cg"
cg@60
  2066
! !
cg@60
  2067
cg@60
  2068
!UIPainterView methodsFor:'menus'!
cg@60
  2069
ca@121
  2070
showMiddleButtonMenu
cg@2191
  2071
    "show the middle button menu; this returns nil"
ca@1635
  2072
ca@1635
  2073
    |m|
ca@1635
  2074
ca@223
  2075
    self enabled ifTrue:[
cg@2191
  2076
        m := MenuPanel fromSpec:(UIPainter menuEdit) receiver:self superView application.
cg@2191
  2077
        self startUpMenu:m
ca@121
  2078
    ].
cg@2191
  2079
    ^ nil
cg@2191
  2080
cg@2191
  2081
    "Modified: / 31-10-2007 / 11:10:10 / cg"
cg@60
  2082
! !
cg@60
  2083
cg@1714
  2084
!UIPainterView methodsFor:'private-handles'!
tz@754
  2085
werner@1832
  2086
painter
werner@1832
  2087
    ^ treeView canvas
werner@1832
  2088
!
werner@1832
  2089
tz@754
  2090
showSelected:aComponent
tz@754
  2091
    "show object selected
tz@754
  2092
    "
cg@2537
  2093
    |wasClipped sel hInsideColor hOutsideColor bg|
tz@754
  2094
tz@754
  2095
    selectionHiddenLevel == 0 ifTrue:[
cg@2499
  2096
        sel := treeView selection.
cg@2499
  2097
        (sel size > 1 and: [(treeView model list at: sel first) contents view == aComponent])
cg@2499
  2098
        ifTrue: [
cg@2537
  2099
            hInsideColor := handleMasterColor.
cg@2499
  2100
        ] ifFalse:[
cg@2499
  2101
            bg := aComponent viewBackground.
cg@2499
  2102
            bg isColor ifTrue:[
cg@2499
  2103
                bg brightness < 0.5 ifTrue:[
cg@2537
  2104
                    hInsideColor := handleColorWhite
cg@2499
  2105
                ] ifFalse:[
cg@2537
  2106
                    hInsideColor := handleColorBlack
cg@2499
  2107
                ]
cg@2499
  2108
            ] ifFalse:[
cg@2537
  2109
                hInsideColor := handleColorBlack
cg@2499
  2110
            ]
cg@2499
  2111
        ].
cg@2499
  2112
cg@2537
  2113
        hInsideColor brightness < 0.5 ifTrue:[
cg@2537
  2114
            hOutsideColor := handleColorWhite
cg@2537
  2115
        ] ifFalse:[
cg@2537
  2116
            hOutsideColor := handleColorBlack
cg@2537
  2117
        ].
cg@2499
  2118
cg@2499
  2119
        (wasClipped := clipChildren) ifTrue:[
cg@2499
  2120
            self clippedByChildren:(clipChildren := false).
cg@2499
  2121
        ].
cg@2499
  2122
cg@2499
  2123
        self handlesOf:aComponent do:[:aRectangle :what| 
cg@2499
  2124
            |l t w h|
cg@2499
  2125
cg@2537
  2126
            l := aRectangle left.
cg@2537
  2127
            t := aRectangle top.
cg@2537
  2128
            w := aRectangle width.
cg@2537
  2129
            h := aRectangle height.
cg@2537
  2130
cg@2537
  2131
            self paint:hOutsideColor.
cg@2537
  2132
            self displayRectangleX:l y:t width:w height:h.
cg@2537
  2133
cg@2537
  2134
            self paint:hInsideColor.
cg@2499
  2135
cg@2499
  2136
            what == #view ifTrue:[
cg@2537
  2137
                self displayRectangleX:l+1 y:t+1 width:w-2 height:h-2
cg@2499
  2138
            ] ifFalse:[
cg@2537
  2139
                self fillRectangleX:l+1 y:t+1 width:w-2 height:h-2
cg@2499
  2140
            ]
cg@2499
  2141
        ].
cg@2499
  2142
cg@2499
  2143
        wasClipped ifTrue:[
cg@2499
  2144
            self clippedByChildren:(clipChildren := true).
cg@2499
  2145
        ]
tz@754
  2146
    ]
bg@1543
  2147
bg@1543
  2148
    "Modified: / 6.12.2001 / 00:00:16 / cg"
tz@754
  2149
! !
tz@754
  2150
ca@335
  2151
!UIPainterView methodsFor:'queries'!
ca@335
  2152
cg@2276
  2153
isEditingSpecOnly
cg@2583
  2154
    "/ should not be invoked
cg@2421
  2155
    self breakPoint:#ca.
cg@2582
  2156
    ^ false.
cg@2276
  2157
!
cg@2276
  2158
cg@2276
  2159
isNotEditingSpecOnly
cg@2583
  2160
    "/ should not be invoked
cg@2421
  2161
    self breakPoint:#ca.
cg@2583
  2162
    ^ true.
cg@2276
  2163
!
cg@2276
  2164
ca@335
  2165
resolveName:aName
ca@335
  2166
    |appl|
ca@335
  2167
ca@335
  2168
    appl := self application.
ca@335
  2169
ca@335
  2170
    appl notNil ifTrue:[
werner@1834
  2171
	^ appl resolveName:aName
ca@335
  2172
    ].
ca@335
  2173
    ^ Smalltalk resolveName:aName inClass:self class
ca@335
  2174
! !
ca@335
  2175
cg@60
  2176
!UIPainterView methodsFor:'removing components'!
cg@60
  2177
ca@78
  2178
remove:anObject
ca@78
  2179
    "remove anObject from the contents do redraw
cg@60
  2180
    "
ca@134
  2181
    anObject notNil ifTrue:[
werner@1834
  2182
	treeView removeView:anObject.
ca@134
  2183
    ]
cg@60
  2184
!
cg@60
  2185
cg@60
  2186
removeAll
ca@62
  2187
    "remove all objects and properties
ca@62
  2188
    "
ca@776
  2189
    self select:nil.
ca@776
  2190
    treeView removeAll.
ca@776
  2191
    self removeUndoHistory.
cg@60
  2192
! !
cg@60
  2193
cg@60
  2194
!UIPainterView methodsFor:'searching'!
cg@60
  2195
ca@285
  2196
findContainerOfView:aView
ca@285
  2197
    "returns the super view assigned to a view
ca@89
  2198
    "
ca@285
  2199
    |p|
ca@89
  2200
ca@285
  2201
    (p := self propertyOfParentForView:aView) isNil ifTrue:[
werner@1834
  2202
	^ self
ca@89
  2203
    ].
ca@285
  2204
    ^ p view
ca@89
  2205
!
ca@89
  2206
cg@60
  2207
findObjectAt:aPoint
ca@285
  2208
    |view prop|
cg@60
  2209
cg@60
  2210
    view := super findObjectAt:aPoint.
cg@2499
  2211
    view isNil ifTrue:[^ nil].
cg@2499
  2212
cg@2362
  2213
    "/ stupid check, if I know about this view
ca@1870
  2214
    prop := self propertyOfView:view.
ca@285
  2215
    prop notNil ifTrue:[^ prop view].
cg@2963
  2216
    self halt:'nil property'.
ca@1870
  2217
    ^ nil
cg@60
  2218
!
cg@60
  2219
cg@60
  2220
findViewWithId:aViewId
ca@62
  2221
    "finds view assigned to identifier and returns the view or nil
cg@60
  2222
    "
cg@60
  2223
    |prop|
cg@60
  2224
cg@60
  2225
    prop := self propertyOfIdentifier:aViewId.
cg@60
  2226
cg@60
  2227
    prop notNil ifTrue:[^ prop view]
werner@1834
  2228
	       ifFalse:[^ nil]
ca@78
  2229
!
ca@78
  2230
ca@78
  2231
propertyOfIdentifier:anId
ca@78
  2232
    "returns property assigned to unique identifier
ca@78
  2233
    "
ca@78
  2234
    anId notNil ifTrue:[
werner@1834
  2235
	^ treeView propertyDetect:[:p| p identifier == anId ]
ca@78
  2236
    ].
ca@78
  2237
    ^ nil
ca@78
  2238
!
ca@78
  2239
ca@78
  2240
propertyOfName:aString
cg@2231
  2241
    "returns the property for a given widgets name (name in tree)"
cg@2231
  2242
ca@111
  2243
    |name|
ca@111
  2244
ca@111
  2245
    aString isNil ifFalse:[
cg@2231
  2246
        name := aString string withoutSeparators.
cg@2231
  2247
        ^ treeView propertyDetect:[:p| p name = name ].
ca@78
  2248
    ].
ca@78
  2249
    ^ nil
ca@78
  2250
!
ca@78
  2251
ca@285
  2252
propertyOfParentForView:aSubView
ca@285
  2253
    "returns the property of the parent or nil
ca@285
  2254
    "
ca@285
  2255
    |item|
ca@285
  2256
ca@1870
  2257
    (item := treeView detectItemCorespondingToView:aSubView) notNil ifTrue:[
ca@1870
  2258
        (item := item parent) notNil ifTrue:[^ item contents]
ca@285
  2259
    ].
ca@285
  2260
    ^ nil
ca@285
  2261
!
ca@285
  2262
ca@78
  2263
propertyOfView:aView
ca@1870
  2264
    "detect the property for the argument, a view. The property of the view or
ca@285
  2265
     the first subview providing the properties is returned. If no property is detected
ca@285
  2266
     nil is returned.
ca@285
  2267
    "
ca@285
  2268
    |item|
ca@285
  2269
ca@1870
  2270
    item := treeView detectItemCorespondingToView:aView.
ca@285
  2271
    (item notNil and:[item parent notNil]) ifTrue:[
ca@1870
  2272
        ^ item contents
ca@285
  2273
    ].
ca@285
  2274
    ^ nil
ca@285
  2275
!
ca@285
  2276
ca@111
  2277
uniqueNameFor:aSpecOrString
cg@2231
  2278
    "generate and return a unique name for a specClass or an items name.
cg@2231
  2279
     (unique name in the tree)"
cg@2231
  2280
cg@2231
  2281
    |maxUsedIndex name nameLen|
cg@2231
  2282
cg@2231
  2283
    name := aSpecOrString isString 
cg@2231
  2284
                ifFalse:[aSpecOrString userFriendlyName]
cg@2231
  2285
                ifTrue:[aSpecOrString].
cg@2231
  2286
cg@2231
  2287
    nameLen := name size.
cg@2231
  2288
    maxUsedIndex := 0.
ca@78
  2289
cg@238
  2290
    treeView propertiesDo:[:p|
cg@2231
  2291
        |thisName|
cg@2231
  2292
cg@2231
  2293
        thisName := p name.
cg@2231
  2294
cg@2231
  2295
        (thisName size > nameLen and:[thisName startsWith:name]) ifTrue:[
cg@2231
  2296
            maxUsedIndex := maxUsedIndex max:(p extractNumberStartingAt:nameLen+1)
cg@2231
  2297
        ]
ca@78
  2298
    ].
cg@2231
  2299
    ^ name, (maxUsedIndex+1) printString.
ca@78
  2300
!
ca@78
  2301
ca@78
  2302
uniqueNameOf:aView
ca@111
  2303
    |prop|
ca@78
  2304
ca@111
  2305
    (prop := self propertyOfView:aView) notNil ifTrue:[
werner@1834
  2306
	prop name isNil ifTrue:[
werner@1834
  2307
	    prop name:(self uniqueNameFor:(prop spec)).
werner@1834
  2308
	].
werner@1834
  2309
	^ prop name
ca@78
  2310
    ].
ca@111
  2311
    ^ 'self'
ca@78
  2312
cg@60
  2313
! !
cg@60
  2314
ca@223
  2315
!UIPainterView methodsFor:'selection basics'!
ca@223
  2316
ca@223
  2317
addToSelection:anObject
ca@223
  2318
    "add an object to the selection
ca@223
  2319
    "
ca@223
  2320
    (self enabled and:[(self isSelected:anObject) not]) ifTrue:[
cg@2257
  2321
        selection isCollection ifFalse:[
cg@2257
  2322
            selection isNil ifTrue:[
cg@2257
  2323
                selection := anObject
cg@2257
  2324
            ] ifFalse:[
cg@2257
  2325
                selection := OrderedCollection with:selection with:anObject
cg@2257
  2326
            ]
cg@2257
  2327
        ] ifTrue:[
cg@2257
  2328
            "/ to enforce the change-message (value is identical to oldValue)
cg@2257
  2329
            selection isList ifTrue:[
cg@2257
  2330
                selection add:anObject
cg@2257
  2331
            ] ifFalse:[
cg@2257
  2332
                selection := selection asOrderedCollection.
cg@2257
  2333
                selection := selection copyWith:anObject
cg@2257
  2334
            ]
cg@2257
  2335
        ].
cg@2257
  2336
        self showSelected:anObject.
cg@2257
  2337
        treeView canvasSelectionAdd:anObject.
ca@223
  2338
    ]
ca@223
  2339
cg@1347
  2340
    "Modified: / 11.2.2000 / 01:39:05 / cg"
ca@223
  2341
!
ca@223
  2342
ca@223
  2343
removeFromSelection:anObject
ca@223
  2344
    "remove an object from the selection
ca@223
  2345
    "
ca@223
  2346
    (self isSelected:anObject) ifTrue:[
cg@2257
  2347
        self showUnselected:anObject.
cg@2257
  2348
cg@2257
  2349
        selection size > 1 ifTrue:[
cg@2257
  2350
            selection isList ifTrue:[
cg@2257
  2351
                selection remove:anObject ifAbsent:nil
cg@2257
  2352
            ] ifFalse:[
cg@2257
  2353
                "/ to enforce the change-message (value is identical to oldValue)
cg@2257
  2354
                selection := selection asOrderedCollection.
cg@2257
  2355
                selection := selection copyWithout:anObject
cg@2257
  2356
            ].
cg@2257
  2357
            self showSelection.
cg@2257
  2358
        ] ifFalse:[
cg@2257
  2359
            selection := nil
cg@2257
  2360
        ].
cg@2257
  2361
        treeView canvasSelectionRemove:anObject.
ca@223
  2362
    ]
ca@223
  2363
cg@1347
  2364
    "Modified: / 11.2.2000 / 01:41:11 / cg"
ca@223
  2365
!
ca@223
  2366
ca@223
  2367
select:something
ca@223
  2368
    "change selection to something
werner@1834
  2369
    "
werner@1834
  2370
    (self enabled and:[something ~= self selection]) ifTrue:[
cg@2257
  2371
        something isNil
cg@2257
  2372
            ifTrue: [treeView selection: (Array with: 1)]
cg@2257
  2373
            ifFalse:[treeView canvasSelection:something].
cg@2257
  2374
        self setSelection:something withRedraw:true
ca@223
  2375
    ]
ca@223
  2376
!
ca@223
  2377
werner@1830
  2378
selectNextUpInHierarchy
werner@1830
  2379
    | sel |
werner@1830
  2380
werner@1830
  2381
    (sel := self selection) isNil ifTrue:[^self].
werner@1830
  2382
    sel isCollection ifTrue:[
cg@2257
  2383
        sel := self selection first.
werner@1830
  2384
    ].
werner@1830
  2385
    sel := sel superView.
werner@1830
  2386
    sel isNil ifTrue:[^self].
cg@2257
  2387
    treeView canvasSelection: sel.
werner@1830
  2388
    self selection: sel.
werner@1830
  2389
!
werner@1830
  2390
ca@2392
  2391
selectedNodes
ca@2392
  2392
    ^ treeView model selectedNodes
ca@2392
  2393
!
ca@2392
  2394
ca@285
  2395
updateSelectionFromModel:aSelOrNil
ca@223
  2396
    "update selection from a new selection
ca@223
  2397
    "
ca@1427
  2398
    |list|
ca@768
  2399
ab@2180
  2400
    "/ do not return here if not shown - we NEED the correct selection
ca@223
  2401
    selectionHiddenLevel == 0 ifTrue:[
cg@2039
  2402
        aSelOrNil size ~~ 0 ifTrue:[
cg@2039
  2403
            list := OrderedCollection new.
cg@2039
  2404
cg@2039
  2405
            self selectionDo:[:el|
cg@2039
  2406
                (aSelOrNil includes:el) ifFalse:[list add:el]
cg@2039
  2407
            ].
ab@2180
  2408
            self shown ifTrue:[self showUnselected:list].
cg@2039
  2409
        ] ifFalse:[
ab@2180
  2410
            self shown ifTrue:[self hideSelection].
cg@2039
  2411
        ]
ca@223
  2412
    ].
cg@2515
  2413
    self repairDamage.
ca@285
  2414
    self setSelection:aSelOrNil withRedraw:false.
cg@2515
  2415
    self showSelection.
ca@223
  2416
! !
ca@223
  2417
ca@78
  2418
!UIPainterView methodsFor:'specification'!
cg@60
  2419
ca@78
  2420
addSpec:aSpecification builder:aBuilder in:aFrame
ca@78
  2421
    "build view and subviews from aSpecification into a frame. The top view
ca@78
  2422
     is returned. The contained components of a spec are set to nil
ca@62
  2423
    "
ca@2390
  2424
    ^ self addSpec:aSpecification builder:aBuilder in:aFrame beforeIndex:nil.
ca@2390
  2425
!
ca@2390
  2426
ca@2390
  2427
addSpec:aSpecification builder:aBuilder in:aFrame beforeIndex:anIndexOrNil
ca@2390
  2428
    "build view and subviews from aSpecification into a frame. The top view
ca@2390
  2429
     is returned. The contained components of a spec are set to nil
ca@2390
  2430
    "
ca@2390
  2431
    |cls newView viewPosition subviewToRealize|
cg@212
  2432
ca@330
  2433
    cls := self resolveName:className.
ca@330
  2434
ca@330
  2435
    cls notNil ifTrue:[
cg@2226
  2436
        aBuilder applicationClass:cls.
cg@212
  2437
    ].
cg@60
  2438
ca@2390
  2439
    (     anIndexOrNil notNil
ca@2390
  2440
     and:[anIndexOrNil between:1 and:(aFrame subViews size)]
ca@2390
  2441
    ) ifTrue:[
ca@2390
  2442
        viewPosition := anIndexOrNil.
ca@2390
  2443
    ].
ca@2390
  2444
cg@2229
  2445
    "/ remember view<->spec associations to tree
cg@2499
  2446
    aBuilder 
cg@2499
  2447
        componentCreationHook:[:aView :aSpec :builder|
cg@2499
  2448
            |newProperty copyOfSpec nameOfSpec beforeIndex|
cg@2499
  2449
cg@2499
  2450
            (viewPosition notNil and:[aSpecification == aSpec]) ifTrue:[
cg@2499
  2451
                subviewToRealize := aView.
cg@2499
  2452
cg@2499
  2453
                [ (subviewToRealize notNil and:[subviewToRealize superView ~~ aFrame]) ] whileTrue:[
cg@2499
  2454
                    subviewToRealize := subviewToRealize superView.
cg@2499
  2455
                ].
cg@2499
  2456
                subviewToRealize notNil ifTrue:[
cg@2499
  2457
                    beforeIndex := viewPosition.
cg@2499
  2458
                    aFrame changeSequenceOrderFor:subviewToRealize to:viewPosition.
cg@2499
  2459
                ].
ca@2390
  2460
            ].
cg@2499
  2461
cg@2499
  2462
            newProperty := ViewProperty new.
cg@2499
  2463
            copyOfSpec := aSpec copy.
cg@2499
  2464
            newProperty spec:copyOfSpec.
cg@2499
  2465
            newProperty view:aView.
cg@2499
  2466
cg@2499
  2467
            "/ break refs to child-specs
cg@2499
  2468
            "/ (not needed, as we keep the child info in the view hierarchy)
cg@2499
  2469
            copyOfSpec class supportsSubComponents ifTrue:[
cg@2499
  2470
                copyOfSpec component:nil
ca@2390
  2471
            ].
cg@2499
  2472
cg@2499
  2473
            nameOfSpec := copyOfSpec name.
cg@2853
  2474
            "/ old: enforce a name
cg@2853
  2475
            "/ (nameOfSpec isNil or:[(self propertyOfName:nameOfSpec) notNil]) ifTrue:[
cg@2853
  2476
            "/     copyOfSpec name:(nameOfSpec := self uniqueNameFor:copyOfSpec)
cg@2853
  2477
            "/ ].
cg@2853
  2478
            "/ aView name:nameOfSpec.
cg@2853
  2479
            "/ new:
cg@2853
  2480
            (nameOfSpec isNil "notEmptyOrNil" or:[ (self propertyOfName:nameOfSpec) notNil]) ifTrue:[
cg@2853
  2481
                copyOfSpec name:(nameOfSpec := self uniqueNameFor:copyOfSpec).
cg@2853
  2482
                aView name:nameOfSpec.
cg@2499
  2483
            ].
cg@2853
  2484
            "/ end
cg@2853
  2485
cg@2499
  2486
            treeView addProperty:newProperty beforeIndex:beforeIndex.
ca@2390
  2487
        ].
cg@2231
  2488
ca@2390
  2489
    newView := aSpecification buildViewWithLayoutFor:aBuilder in:aFrame.
ca@2390
  2490
ca@2390
  2491
    subviewToRealize notNil ifTrue:[
ca@2390
  2492
        subviewToRealize realize.
ca@2390
  2493
cg@2499
  2494
        aFrame components notEmptyOrNil ifTrue:[ self halt ].
ca@2390
  2495
        aFrame subViews from:(viewPosition + 1 ) do:[:v|
ca@2390
  2496
            v shown ifTrue:[v raise]
ca@2390
  2497
        ].
ca@2390
  2498
    ].
ca@2390
  2499
    ^ newView
cg@60
  2500
cg@2853
  2501
    "Modified: / 17-08-2011 / 13:56:24 / cg"
cg@60
  2502
!
cg@60
  2503
cg@2362
  2504
fullSpecFor:aView
cg@3031
  2505
    "generate a full spec for aView (or component)"
cg@2526
  2506
ca@78
  2507
    |mySpec subSpecs|
ca@78
  2508
cg@2362
  2509
    mySpec := self specFor:aView.
ca@78
  2510
    (mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[
cg@2505
  2511
        subSpecs isNil ifTrue:[
cg@2505
  2512
            subSpecs := OrderedCollection new
cg@2505
  2513
        ].
cg@2505
  2514
cg@2505
  2515
        ((aView components ? #()) , (aView subViews ? #())) do:[:aSubViewOrComponent |
cg@2505
  2516
            |spec|
cg@2505
  2517
cg@2505
  2518
            spec := self fullSpecFor:aSubViewOrComponent.
cg@2505
  2519
            spec notNil ifTrue:[
cg@2505
  2520
                subSpecs add:spec.
cg@2362
  2521
            ].
cg@2505
  2522
        ].
cg@2505
  2523
cg@2505
  2524
        subSpecs notEmptyOrNil ifTrue:[
cg@2505
  2525
            mySpec component:(SpecCollection new collection:subSpecs)
cg@2362
  2526
        ]
ca@78
  2527
    ].
ca@78
  2528
    ^ mySpec
cg@3038
  2529
cg@3038
  2530
    "Modified: / 30-07-2013 / 09:12:18 / cg"
cg@2362
  2531
!
cg@2362
  2532
cg@2362
  2533
fullSpecWithAbsolutePositionFor:aView
cg@2362
  2534
    |spec|
cg@2362
  2535
cg@2362
  2536
    spec := self fullSpecFor:aView.
cg@2362
  2537
    spec 
cg@2362
  2538
        otherAttributeAt:#uiPainterAttributes 
cg@2362
  2539
        put:(Dictionary new
cg@2362
  2540
                at:#origin put:aView origin;
cg@2362
  2541
                at:#extent put:aView extent;
cg@2362
  2542
                at:#absOrigin put:(aView originRelativeTo:self);
cg@2362
  2543
                yourself).
cg@2362
  2544
    ^ spec
cg@60
  2545
!
cg@60
  2546
cg@1173
  2547
rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil
cg@2257
  2548
    self
cg@2257
  2549
        rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil forceNewView:false
cg@2257
  2550
!
cg@2257
  2551
cg@2257
  2552
rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil forceNewView:forceNewView
cg@1173
  2553
    |v builder|
cg@1173
  2554
cg@1173
  2555
    (builder := aBuilderOrNil) isNil ifTrue:[
cg@2257
  2556
        "/ create a dummy builder
cg@2257
  2557
        builder := UIBuilder new isEditing:true.
cg@2257
  2558
        className notNil ifTrue:[
cg@2257
  2559
            builder applicationClass:(self resolveName:className).
cg@2257
  2560
        ].
cg@1173
  2561
    ].
ca@285
  2562
cg@1252
  2563
    aSpec class isLayoutContainer ifTrue:[
cg@2257
  2564
        "/ TODO:
cg@2257
  2565
        "/ go through subviews and let them resize to their default/preferred
cg@2257
  2566
        "/ needed if we change a containers layout from fit to non-fit.
cg@2257
  2567
cg@2257
  2568
        (aView subViews ? #()) do:[:aSubView |
cg@2265
  2569
            |fix spec prop container|
cg@2257
  2570
cg@2257
  2571
            (prop := self propertyOfView:aSubView) notNil ifTrue:[
cg@2257
  2572
                spec := prop spec.
cg@2257
  2573
cg@2257
  2574
                spec useDefaultExtent ifTrue:[
cg@2257
  2575
                    fix := aSubView sizeFixed:false.
cg@2265
  2576
                    aView class == VerticalPanelView ifTrue:[
cg@2348
  2577
                        aSubView height:aSubView preferredHeight.
cg@2265
  2578
                    ] ifFalse:[
cg@2265
  2579
                        aView class == HorizontalPanelView ifTrue:[
cg@2348
  2580
                            aSubView width:aSubView preferredWidth.
cg@2265
  2581
                        ] ifFalse:[
cg@2265
  2582
                            aSubView extent:aSubView preferredExtent.
cg@2265
  2583
                        ].
cg@2265
  2584
                    ].
cg@2257
  2585
                    aSubView sizeFixed:fix
cg@2257
  2586
                ]
cg@2257
  2587
            ]
cg@2257
  2588
        ].
cg@1252
  2589
    ].
cg@1252
  2590
cg@2257
  2591
    (forceNewView or:[aSpec needsRebuildForAttributes]) ifTrue:[
cg@2257
  2592
        "/ needs a full rebuild (in case view class depends upon spec-attribute)
cg@2257
  2593
        v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView).
cg@2257
  2594
        v realize.
cg@2257
  2595
        aView destroy.
sv@3083
  2596
        self sync.
cg@2257
  2597
        aView becomeSameAs:v.
cg@2257
  2598
        "/ inputView raise.
ca@285
  2599
    ] ifFalse:[
cg@2257
  2600
        aSpec setAttributesIn:aView with:builder.
cg@2257
  2601
        self elementChangedSize:aView.
ca@285
  2602
    ].
ca@285
  2603
!
ca@285
  2604
cg@2362
  2605
specFor:aView
cg@2362
  2606
    "returns a copy of the spec assigned to an object"
cg@2362
  2607
ca@78
  2608
    |prop spec|
ca@78
  2609
cg@2362
  2610
    (prop := self propertyOfView:aView) isNil ifTrue:[^ nil].
cg@3038
  2611
    "/ attention: the above prop may be a superview's prop,
cg@3038
  2612
    "/ for subviews which have not been built by me
cg@3038
  2613
    "/ (for example, in a box with a given viewClass like Inspector,
cg@3038
  2614
    "/ we would return the boxes spec for the subviews.
cg@3038
  2615
    "/ This is definitely NOT what we want (as it generates wrong specs).
cg@3038
  2616
    "/ therefore check:
cg@3038
  2617
    prop view == aView ifFalse:[^ nil].
cg@2362
  2618
cg@1744
  2619
    spec := prop spec copy.
cg@2362
  2620
    spec layoutFromView:aView.
ca@78
  2621
    ^ spec
cg@3038
  2622
cg@3038
  2623
    "Modified (comment): / 30-07-2013 / 09:47:51 / cg"
cg@60
  2624
!
cg@60
  2625
ca@146
  2626
specForSelection
cg@2526
  2627
    "returns the spec assigned to current single selection or nil.
cg@2526
  2628
     Nil is also returned for multiple selections (sigh)"
cg@2526
  2629
cg@2526
  2630
    |theSpec|
cg@2526
  2631
cg@2526
  2632
    theSpec := self specFor:(self singleSelection).
cg@2526
  2633
    theSpec isNil ifTrue:[
cg@2526
  2634
        treeView isCanvasSelected ifTrue:[
cg@2526
  2635
            theSpec := treeView canvasSpec.
cg@2526
  2636
        ]
cg@2526
  2637
    ].
cg@2526
  2638
    ^ theSpec
ca@146
  2639
!
ca@146
  2640
ca@78
  2641
updateFromSpec:aSpec
ca@78
  2642
    "update current selected view from specification
ca@62
  2643
    "
cg@1173
  2644
    |props name|
ca@78
  2645
ca@281
  2646
    aSpec class == WindowSpec ifTrue:[
cg@2499
  2647
         ^ treeView canvasSpec:aSpec
ca@281
  2648
    ].
ca@281
  2649
ca@78
  2650
    self singleSelection notNil ifTrue:[
cg@2499
  2651
        self withSelectionHiddenDo:[
cg@2499
  2652
            self transaction:#specification selectionDo:[:aView|
cg@2853
  2653
cg@2499
  2654
                props   := self propertyOfView:aView.
cg@2499
  2655
                name    := (aSpec name) withoutSeparators.
cg@2499
  2656
cg@2853
  2657
                name isNil ifTrue:[
cg@2853
  2658
                    "/ not yet given a name
cg@2853
  2659
                    (name ~= props name) ifTrue:[
cg@2853
  2660
                        (self propertyOfName:name) notNil ifTrue:[
cg@2853
  2661
                            name := props name
cg@2853
  2662
                        ]
cg@2853
  2663
                    ].
cg@2499
  2664
                ].
cg@2499
  2665
                aSpec name:name.
cg@2499
  2666
                self createUndoSpecModify:props.
cg@2499
  2667
                self rebuildView:aView fromSpec:aSpec withBuilder:nil.
cg@2499
  2668
                props spec:(aSpec copy).
cg@2499
  2669
                treeView propertyChanged:props.
cg@2499
  2670
            ]
cg@2499
  2671
        ]
ca@82
  2672
    ]
cg@212
  2673
cg@2853
  2674
    "Modified: / 17-08-2011 / 13:56:38 / cg"
cg@2853
  2675
    "Modified (format): / 18-08-2011 / 02:19:01 / cg"
cg@60
  2676
! !
cg@60
  2677
ca@285
  2678
!UIPainterView methodsFor:'testing'!
ca@285
  2679
ca@285
  2680
canChangeLayoutOfView:aView
cg@2362
  2681
    "returns true if the view can change its layout.
cg@2362
  2682
     This is dependent on its parent view."
cg@2362
  2683
sv@2483
  2684
    |item parent|
cg@2362
  2685
cg@2362
  2686
    item := treeView itemOfView:aView.
cg@2362
  2687
    item isNil ifTrue:[
cg@3348
  2688
        "/ I don't know anything about that view (cg: how can this happen ?)
cg@2362
  2689
        "/ self breakPoint:#cg.
cg@2362
  2690
        ^ false
ca@285
  2691
    ].
cg@2362
  2692
    parent := item parent.
cg@2362
  2693
    parent isNil ifTrue:[
cg@2362
  2694
        "/ that view has no parent (cg: does this mean its the canvas itself ?)
cg@2362
  2695
        "/ self breakPoint:#cg.
cg@2362
  2696
        ^ false
cg@2362
  2697
    ].
sv@2483
  2698
    parent contents view == self ifTrue:[
sv@2483
  2699
        "aView is a direct subview of the canvas
sv@2483
  2700
         -- and the canvas supports layout changes of its subviews"
sv@2483
  2701
        ^ true.
cg@2362
  2702
    ].
sv@2480
  2703
    ^ parent contents spec class isLayoutContainer not
ca@285
  2704
!
ca@285
  2705
cg@1230
  2706
canExchangeSelectionLayouts
cg@1230
  2707
    "returns true if the selection size is exactly 2
cg@1230
  2708
     and all elements in the selection can be moved or aligned
cg@1230
  2709
    "
sv@2480
  2710
    selection size ~~ 2 ifTrue:[
sv@2480
  2711
        ^ false
cg@1230
  2712
    ].
cg@1230
  2713
    ^ self canMoveOrAlignSelection
cg@1230
  2714
!
cg@1230
  2715
ca@2392
  2716
canGroup
ca@2392
  2717
    "test whether selected elements can be grouped; minimum two elements
ca@2392
  2718
     must be selected and all must have the same parent"
ca@2392
  2719
ca@2392
  2720
    |selectedNodes parent|
ca@2392
  2721
ca@2392
  2722
    selectedNodes := self selectedNodes.
ca@2392
  2723
ca@2392
  2724
    selectedNodes size < 2ifTrue:[ ^ false ].
ca@2392
  2725
ca@2392
  2726
    parent := selectedNodes first parent.
ca@2392
  2727
    parent isNil ifTrue:[ ^ false ].    "/ test whether not the canvas itself is selected
ca@2392
  2728
ca@2392
  2729
    selectedNodes do:[:each|
ca@2392
  2730
        each parent ~~ parent ifTrue:[^ false ].
ca@2392
  2731
    ].
ca@2392
  2732
ca@2392
  2733
    ^true
ca@2392
  2734
!
ca@2392
  2735
ca@285
  2736
canKeepLayoutInSelection
ca@285
  2737
    "returns true if layout can be kept during a paste operation
ca@285
  2738
    "
ca@285
  2739
    |prop|
ca@285
  2740
ca@285
  2741
    prop := self propertyOfView:(self singleSelection).
ca@285
  2742
  ^ (prop isNil or:[prop spec class isLayoutContainer not])
ca@285
  2743
!
ca@285
  2744
ca@285
  2745
canMove:something
ca@285
  2746
    "checks whether something is not nil and if all widgets derived from
ca@285
  2747
     something can change their layout ( move, align, ... operation ).
ca@285
  2748
    "
ca@285
  2749
    something notNil ifTrue:[
cg@2362
  2750
        self forEach:something do:[:aView|
cg@2362
  2751
            (self canChangeLayoutOfView:aView) ifFalse:[^ false]
cg@2362
  2752
        ].
cg@2362
  2753
        ^ true
ca@285
  2754
    ].
ca@285
  2755
    ^ false
ca@285
  2756
!
ca@285
  2757
ca@285
  2758
canMoveOrAlignSelection
ca@285
  2759
    "returns true if a selection exists and all elements in the selection
ca@285
  2760
     can be moved or aligned
ca@285
  2761
    "
cg@2362
  2762
    ^ self canMove:(self selection)
ca@2392
  2763
!
ca@2392
  2764
sv@2480
  2765
canResize:something
sv@2480
  2766
    "checks whether something is not nil and if all widgets derived from
sv@2480
  2767
     something can be resized."
sv@2480
  2768
sv@2480
  2769
    something notNil ifTrue:[
sv@2480
  2770
        self forEach:something do:[:aView|
sv@2480
  2771
            (self canResizeView:aView) ifFalse:[^ false]
sv@2480
  2772
        ].
sv@2480
  2773
        ^ true
sv@2480
  2774
    ].
sv@2480
  2775
    ^ false
sv@2480
  2776
!
sv@2480
  2777
sv@2480
  2778
canResizeSelection
sv@2480
  2779
    "returns true if a selection exists and all elements in the selection
sv@2480
  2780
     can be resized"
sv@2480
  2781
sv@2480
  2782
    ^ self canResize:(self selection)
sv@2480
  2783
!
sv@2480
  2784
sv@2480
  2785
canResizeView:aView
sv@2480
  2786
    "returns true if the view can be resized.
sv@2480
  2787
     This is dependent on its parent view."
sv@2480
  2788
sv@2480
  2789
    |item parent|
sv@2480
  2790
sv@2480
  2791
    item := treeView itemOfView:aView.
sv@2480
  2792
    item isNil ifTrue:[
cg@3348
  2793
        "/ I don't know anything about that view (cg: how can this happen ?)
sv@2480
  2794
        "/ self breakPoint:#cg.
sv@2480
  2795
        ^ false
sv@2480
  2796
    ].
sv@2480
  2797
    parent := item parent.
sv@2480
  2798
    parent isNil ifTrue:[
sv@2480
  2799
        "/ that view has no parent (cg: does this mean its the canvas itself ?)
sv@2480
  2800
        "/ self breakPoint:#cg.
sv@2480
  2801
        ^ false
sv@2480
  2802
    ].
sv@2483
  2803
    parent contents view == self ifTrue:[
sv@2483
  2804
        "aView is a direct subview of the canvas
sv@2483
  2805
         -- and the canvas supports resizing of its subviews"
sv@2483
  2806
        ^ true.
sv@2483
  2807
    ].
sv@2480
  2808
    ^ parent contents spec class canResizeSubComponents
sv@2480
  2809
!
sv@2480
  2810
ca@2392
  2811
canUngroup
ca@2392
  2812
    "test whether the selected element can be ungrouped; only one
ca@2392
  2813
     element is selected and has children"
ca@2392
  2814
ca@2392
  2815
    "/ the #ungroupSelectionWithLayout: dosnot work yet - so disable
ca@2392
  2816
ca@2392
  2817
"/    |selectedNodes node|
ca@2392
  2818
"/
ca@2392
  2819
"/    selectedNodes := self selectedNodes.
ca@2392
  2820
"/
ca@2392
  2821
"/
ca@2392
  2822
"/    selectedNodes size == 1 ifTrue:[
ca@2392
  2823
"/        node := selectedNodes first.
ca@2392
  2824
"/        node parent isNil ifTrue:[ ^ false ].    "/ test whether not the canvas itself is selected
ca@2392
  2825
"/
ca@2392
  2826
"/        ^ node hasChildren
ca@23