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