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