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