UIPainterView.st
changeset 1834 2c640b5f7fa9
parent 1833 6ad211a201cf
child 1869 d7a4c2b7fddb
equal deleted inserted replaced
1833:6ad211a201cf 1834:2c640b5f7fa9
     1 "
     1 "
     2  COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
     2  COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
     3               All Rights Reserved
     3 	      All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice. This software may not
     7  inclusion of the above copyright notice. This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
    30 !UIPainterView class methodsFor:'documentation'!
    30 !UIPainterView class methodsFor:'documentation'!
    31 
    31 
    32 copyright
    32 copyright
    33 "
    33 "
    34  COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
    34  COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG
    35               All Rights Reserved
    35 	      All Rights Reserved
    36 
    36 
    37  This software is furnished under a license and may be used
    37  This software is furnished under a license and may be used
    38  only in accordance with the terms of that license and with the
    38  only in accordance with the terms of that license and with the
    39  inclusion of the above copyright notice. This software may not
    39  inclusion of the above copyright notice. This software may not
    40  be provided or otherwise made available to, or used by, any
    40  be provided or otherwise made available to, or used by, any
    47 "
    47 "
    48     buildIn view used by the UIPainter; from this view, the layout of the
    48     buildIn view used by the UIPainter; from this view, the layout of the
    49     new application derives from.
    49     new application derives from.
    50 
    50 
    51     [see also:]
    51     [see also:]
    52         UIBuilder
    52 	UIBuilder
    53         UIObjectView
    53 	UIObjectView
    54 
    54 
    55     [author:]
    55     [author:]
    56         Claus Gittinger
    56 	Claus Gittinger
    57         Claus Atzkern
    57 	Claus Atzkern
    58 "
    58 "
    59 ! !
    59 ! !
    60 
    60 
    61 !UIPainterView class methodsFor:'initialization'!
    61 !UIPainterView class methodsFor:'initialization'!
    62 
    62 
   108 
   108 
   109 ! !
   109 ! !
   110 
   110 
   111 !UIPainterView class methodsFor:'defaults'!
   111 !UIPainterView class methodsFor:'defaults'!
   112 
   112 
   113 defaultMenuMessage   
   113 defaultMenuMessage
   114     "This message is the default yo be sent to the menuHolder to get a menu
   114     "This message is the default yo be sent to the menuHolder to get a menu
   115     "
   115     "
   116     ^ #showMiddleButtonMenu
   116     ^ #showMiddleButtonMenu
   117 
   117 
   118 
   118 
   159 
   159 
   160 selectNames:aStringOrCollection
   160 selectNames:aStringOrCollection
   161     |prop coll s n newSel|
   161     |prop coll s n newSel|
   162 
   162 
   163     (aStringOrCollection size == 0) ifTrue:[
   163     (aStringOrCollection size == 0) ifTrue:[
   164         newSel := nil.
   164 	newSel := nil.
   165     ] ifFalse:[
   165     ] ifFalse:[
   166         (s := aStringOrCollection) isString ifFalse:[
   166 	(s := aStringOrCollection) isString ifFalse:[
   167             s size == 1 ifTrue:[
   167 	    s size == 1 ifTrue:[
   168                 s := s first
   168 		s := s first
   169             ] ifFalse:[
   169 	    ] ifFalse:[
   170                 coll := OrderedCollection new.
   170 		coll := OrderedCollection new.
   171 
   171 
   172                 s do:[:aName|
   172 		s do:[:aName|
   173                     (prop := self propertyOfName:aName) notNil ifTrue:[
   173 		    (prop := self propertyOfName:aName) notNil ifTrue:[
   174                         coll add:(prop view)
   174 			coll add:(prop view)
   175                     ]
   175 		    ]
   176                 ].
   176 		].
   177                 (n := coll size) == 1 ifTrue:[ 
   177 		(n := coll size) == 1 ifTrue:[
   178                     newSel := coll at:1 
   178 		    newSel := coll at:1
   179                 ] ifFalse:[
   179 		] ifFalse:[
   180                     n == 0 ifTrue:[ 
   180 		    n == 0 ifTrue:[
   181                         newSel := nil
   181 			newSel := nil
   182                     ] ifFalse:[
   182 		    ] ifFalse:[
   183                         newSel := coll
   183 			newSel := coll
   184                     ]
   184 		    ]
   185                 ].
   185 		].
   186                 ^ self select:newSel.
   186 		^ self select:newSel.
   187             ]
   187 	    ]
   188         ].
   188 	].
   189 
   189 
   190         prop := self propertyOfName:s.
   190 	prop := self propertyOfName:s.
   191         prop isNil ifTrue:[
   191 	prop isNil ifTrue:[
   192             newSel := nil
   192 	    newSel := nil
   193         ] ifFalse:[
   193 	] ifFalse:[
   194             newSel := prop view
   194 	    newSel := prop view
   195         ].
   195 	].
   196     ].
   196     ].
   197 
   197 
   198     ^ self select:newSel
   198     ^ self select:newSel
   199 ! !
   199 ! !
   200 
   200 
   201 !UIPainterView methodsFor:'change & update'!
   201 !UIPainterView methodsFor:'change & update'!
   202 
   202 
   203 layoutChanged
   203 layoutChanged
   204     treeView notNil ifTrue:[
   204     treeView notNil ifTrue:[
   205         treeView layoutChanged
   205 	treeView layoutChanged
   206     ]
   206     ]
   207 ! !
   207 ! !
   208 
   208 
   209 !UIPainterView methodsFor:'copy & cut & paste'!
   209 !UIPainterView methodsFor:'copy & cut & paste'!
   210 
   210 
   212     |container|
   212     |container|
   213 
   213 
   214     container := someComponents first container.
   214     container := someComponents first container.
   215     [container notNil
   215     [container notNil
   216      and:[ (someComponents conform:[:eachComponent | eachComponent isComponentOf:container]) not]]
   216      and:[ (someComponents conform:[:eachComponent | eachComponent isComponentOf:container]) not]]
   217         whileTrue:[
   217 	whileTrue:[
   218         container := container container.
   218 	container := container container.
   219     ].
   219     ].
   220     ^ container
   220     ^ container
   221 !
   221 !
   222 
   222 
   223 copySelection
   223 copySelection
   229 
   229 
   230     coll := self minSetOfSuperViews:(self selection).
   230     coll := self minSetOfSuperViews:(self selection).
   231 
   231 
   232     coll notNil ifTrue:[
   232     coll notNil ifTrue:[
   233 "/        self select:nil.
   233 "/        self select:nil.
   234         specs := coll collect:[:aView| self fullSpecFor:aView ].
   234 	specs := coll collect:[:aView| self fullSpecFor:aView ].
   235         self setSelection:specs.
   235 	self setSelection:specs.
   236 "/        treeView selection: sel
   236 "/        treeView selection: sel
   237     ].
   237     ].
   238 
   238 
   239 
   239 
   240 !
   240 !
   254     treeView askForSelectionChangeAllowed ifFalse:[^ self].
   254     treeView askForSelectionChangeAllowed ifFalse:[^ self].
   255 
   255 
   256     coll := self minSetOfSuperViews:(self selection).
   256     coll := self minSetOfSuperViews:(self selection).
   257 
   257 
   258     coll notNil ifTrue:[
   258     coll notNil ifTrue:[
   259         treeView cvsEventsDisabledDo:[
   259 	treeView cvsEventsDisabledDo:[
   260             treeModel    := treeView model.
   260 	    treeModel    := treeView model.
   261             oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
   261 	    oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
   262 
   262 
   263             oldSelection notNil ifTrue:[
   263 	    oldSelection notNil ifTrue:[
   264                 children := oldSelection parent children.
   264 		children := oldSelection parent children.
   265                 (size := children size) > 1 ifTrue:[
   265 		(size := children size) > 1 ifTrue:[
   266                     index := children identityIndexOf:oldSelection.
   266 		    index := children identityIndexOf:oldSelection.
   267                     size == index ifTrue:[
   267 		    size == index ifTrue:[
   268                         index := index - 1
   268 			index := index - 1
   269                     ].
   269 		    ].
   270                     newSelection := children at:index ifAbsent:1.
   270 		    newSelection := children at:index ifAbsent:1.
   271                 ] ifFalse:[
   271 		] ifFalse:[
   272                     newSelection := oldSelection parent
   272 		    newSelection := oldSelection parent
   273                 ].
   273 		].
   274                 newSelection := treeModel indexOf:newSelection.
   274 		newSelection := treeModel indexOf:newSelection.
   275             ] ifFalse:[
   275 	    ] ifFalse:[
   276                 newSelection := 1
   276 		newSelection := 1
   277             ].
   277 	    ].
   278 
   278 
   279             self hideSelection.
   279 	    self hideSelection.
   280             selection := nil.
   280 	    selection := nil.
   281             specs := coll collect:[:aView| self fullSpecFor:aView ].
   281 	    specs := coll collect:[:aView| self fullSpecFor:aView ].
   282 
   282 
   283             self withinTransaction:#cut objects:coll do:[
   283 	    self withinTransaction:#cut objects:coll do:[
   284                 coll reverseDo:[:aView|
   284 		coll reverseDo:[:aView|
   285                     self createUndoRemove:aView.
   285 		    self createUndoRemove:aView.
   286                     self remove:aView.
   286 		    self remove:aView.
   287                 ]
   287 		]
   288             ].
   288 	    ].
   289             buffered ifTrue: [self setSelection:specs].
   289 	    buffered ifTrue: [self setSelection:specs].
   290             treeView selection:nil.
   290 	    treeView selection:nil.
   291             treeView selection:(Array with: newSelection).
   291 	    treeView selection:(Array with: newSelection).
   292             (nd := treeView selectedNode) notNil ifTrue:[
   292 	    (nd := treeView selectedNode) notNil ifTrue:[
   293                 self setSelection:nd contents view withRedraw:true.
   293 		self setSelection:nd contents view withRedraw:true.
   294             ]
   294 	    ]
   295         ]
   295 	]
   296     ]
   296     ]
   297 !
   297 !
   298 
   298 
   299 deleteTotalSelection
   299 deleteTotalSelection
   300     "delete the selection
   300     "delete the selection
   301     "            
   301     "
   302     self deleteSelectionBuffered: false
   302     self deleteSelectionBuffered: false
   303 !
   303 !
   304 
   304 
   305 getSelectedViewsAndSpecs
   305 getSelectedViewsAndSpecs
   306     "return an array filed with selected views and corresponding specs.
   306     "return an array filed with selected views and corresponding specs.
   324     |sel|
   324     |sel|
   325 
   325 
   326     sel := self pasteSpecifications:(self getSelection) keepLayout:false.
   326     sel := self pasteSpecifications:(self getSelection) keepLayout:false.
   327 
   327 
   328     sel notNil ifTrue:[
   328     sel notNil ifTrue:[
   329         self select:sel.
   329 	self select:sel.
   330     ].
   330     ].
   331 
   331 
   332 !
   332 !
   333 
   333 
   334 pasteFromClipBoard:aString
   334 pasteFromClipBoard:aString
   336 
   336 
   337 
   337 
   338 !
   338 !
   339 
   339 
   340 pasteKeepingPosition
   340 pasteKeepingPosition
   341     "add the objects in the paste-buffer to the object view; 
   341     "add the objects in the paste-buffer to the object view;
   342      translate the layout as appropriate, to position the component
   342      translate the layout as appropriate, to position the component
   343      at the same absolute position (relative to topView) as before
   343      at the same absolute position (relative to topView) as before
   344     "
   344     "
   345     |sel|
   345     |sel|
   346 
   346 
   347     sel := self
   347     sel := self
   348         pasteSpecifications:(self getSelection) 
   348 	pasteSpecifications:(self getSelection)
   349         keepLayout:true 
   349 	keepLayout:true
   350         keepPosition:true 
   350 	keepPosition:true
   351         at:nil.
   351 	at:nil.
   352 
   352 
   353     sel notNil ifTrue:[
   353     sel notNil ifTrue:[
   354         self select:sel.
   354 	self select:sel.
   355     ].
   355     ].
   356 !
   356 !
   357 
   357 
   358 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   358 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   359     "add the specs to the object view; returns list of pasted components
   359     "add the specs to the object view; returns list of pasted components
   360     "
   360     "
   361 
   361 
   362     ^ self
   362     ^ self
   363         pasteSpecifications:aSpecificationOrList 
   363 	pasteSpecifications:aSpecificationOrList
   364         keepLayout:keepLayout 
   364 	keepLayout:keepLayout
   365         at:nil
   365 	at:nil
   366 
   366 
   367     "Modified: 11.8.1997 / 01:00:35 / cg"
   367     "Modified: 11.8.1997 / 01:00:35 / cg"
   368 !
   368 !
   369 
   369 
   370 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil
   370 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil
   371     "add the specs to the object view; returns list of pasted components
   371     "add the specs to the object view; returns list of pasted components
   372     "
   372     "
   373     ^ self 
   373     ^ self
   374         pasteSpecifications:aSpecificationOrList 
   374 	pasteSpecifications:aSpecificationOrList
   375         keepLayout:keepLayout 
   375 	keepLayout:keepLayout
   376         keepPosition:false 
   376 	keepPosition:false
   377         at:aPointOrNil
   377 	at:aPointOrNil
   378 
   378 
   379 !
   379 !
   380 
   380 
   381 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil
   381 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNil
   382     "add the specs to the object view; returns list of pasted components
   382     "add the specs to the object view; returns list of pasted components
   385 
   385 
   386     treeView askForSelectionChangeAllowed ifFalse:[^ nil].
   386     treeView askForSelectionChangeAllowed ifFalse:[^ nil].
   387 
   387 
   388     containerToPasteInto := self singleSelection.
   388     containerToPasteInto := self singleSelection.
   389     containerToPasteInto isNil ifTrue:[
   389     containerToPasteInto isNil ifTrue:[
   390         self selection size > 0 ifTrue:[
   390 	self selection size > 0 ifTrue:[
   391             containerToPasteInto := self commonContainerOf:self selection    
   391 	    containerToPasteInto := self commonContainerOf:self selection
   392         ] ifFalse:[
   392 	] ifFalse:[
   393             containerToPasteInto := self
   393 	    containerToPasteInto := self
   394         ].
   394 	].
   395         self selection:containerToPasteInto.
   395 	self selection:containerToPasteInto.
   396     ].
   396     ].
   397 
   397 
   398     (self canPasteInto:containerToPasteInto) ifFalse:[
   398     (self canPasteInto:containerToPasteInto) ifFalse:[
   399         containerToPasteInto notNil ifTrue:[
   399 	containerToPasteInto notNil ifTrue:[
   400             "/ search up parent list for something we can paste into
   400 	    "/ search up parent list for something we can paste into
   401             [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[
   401 	    [containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[
   402                 containerToPasteInto := containerToPasteInto container.                
   402 		containerToPasteInto := containerToPasteInto container.
   403             ].
   403 	    ].
   404             self selection:containerToPasteInto.
   404 	    self selection:containerToPasteInto.
   405         ].
   405 	].
   406     ].
   406     ].
   407     containerToPasteInto isNil ifTrue:[
   407     containerToPasteInto isNil ifTrue:[
   408         containerToPasteInto := self
   408 	containerToPasteInto := self
   409     ].
   409     ].
   410 
   410 
   411     (self canPaste:aSpecificationOrList) ifFalse:[
   411     (self canPaste:aSpecificationOrList) ifFalse:[
   412         Dialog warn:'Cannot paste into selected component (not a container ?)'.
   412 	Dialog warn:'Cannot paste into selected component (not a container ?)'.
   413         ^ nil
   413 	^ nil
   414     ].
   414     ].
   415 
   415 
   416     aSpecificationOrList isCollection ifTrue:[
   416     aSpecificationOrList isCollection ifTrue:[
   417         paste := aSpecificationOrList
   417 	paste := aSpecificationOrList
   418     ] ifFalse:[
   418     ] ifFalse:[
   419         paste := Array with:aSpecificationOrList
   419 	paste := Array with:aSpecificationOrList
   420     ].
   420     ].
   421     self setSelection:nil.
   421     self setSelection:nil.
   422 
   422 
   423     newSel  := OrderedCollection new.
   423     newSel  := OrderedCollection new.
   424     builder := UIBuilder new isEditing:true.
   424     builder := UIBuilder new isEditing:true.
   425 
   425 
   426     className notNil ifTrue:[
   426     className notNil ifTrue:[
   427         builder applicationClass:(self resolveName:className)
   427 	builder applicationClass:(self resolveName:className)
   428     ].
   428     ].
   429 
   429 
   430     (keepLayout not or:[keepPosition]) ifTrue:[
   430     (keepLayout not or:[keepPosition]) ifTrue:[
   431         pasteOffset := 0@0.
   431 	pasteOffset := 0@0.
   432 
   432 
   433         keepPosition ifTrue:[
   433 	keepPosition ifTrue:[
   434             pasteOrigin := device translatePoint:0@0
   434 	    pasteOrigin := device translatePoint:0@0
   435                                   fromView:self
   435 				  fromView:self
   436                                   toView:containerToPasteInto.
   436 				  toView:containerToPasteInto.
   437         ] ifFalse:[
   437 	] ifFalse:[
   438             aPointOrNil isNil ifTrue:[
   438 	    aPointOrNil isNil ifTrue:[
   439                 pasteOrigin := self sensor mousePoint.
   439 		pasteOrigin := self sensor mousePoint.
   440                 pasteOrigin := device translatePoint:pasteOrigin
   440 		pasteOrigin := device translatePoint:pasteOrigin
   441                                             fromView:nil
   441 					    fromView:nil
   442                                               toView:containerToPasteInto.
   442 					      toView:containerToPasteInto.
   443             ] ifFalse:[
   443 	    ] ifFalse:[
   444                 pasteOrigin := device translatePoint:aPointOrNil
   444 		pasteOrigin := device translatePoint:aPointOrNil
   445                                             fromView:self
   445 					    fromView:self
   446                                               toView:containerToPasteInto.
   446 					      toView:containerToPasteInto.
   447             ]
   447 	    ]
   448         ].
   448 	].
   449 
   449 
   450         bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent)
   450 	bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent)
   451     ].
   451     ].
   452 
   452 
   453     paste do:[:aSpec|
   453     paste do:[:aSpec|
   454         |view newOrigin|
   454 	|view newOrigin|
   455 
   455 
   456         view := self addSpec:aSpec builder:builder in:containerToPasteInto.
   456 	view := self addSpec:aSpec builder:builder in:containerToPasteInto.
   457 
   457 
   458         keepPosition ifTrue:[
   458 	keepPosition ifTrue:[
   459             self moveObject:view to:(view origin + pasteOrigin).
   459 	    self moveObject:view to:(view origin + pasteOrigin).
   460         ] ifFalse:[
   460 	] ifFalse:[
   461             keepLayout ifFalse:[
   461 	    keepLayout ifFalse:[
   462                 (bounds containsPoint:pasteOrigin) ifFalse:[
   462 		(bounds containsPoint:pasteOrigin) ifFalse:[
   463                     newOrigin := pasteOffset.
   463 		    newOrigin := pasteOffset.
   464                 ] ifTrue:[
   464 		] ifTrue:[
   465                     newOrigin := pasteOrigin + pasteOffset.
   465 		    newOrigin := pasteOrigin + pasteOffset.
   466                 ].
   466 		].
   467                 self moveObject:view to:newOrigin.
   467 		self moveObject:view to:newOrigin.
   468                 pasteOffset := pasteOffset + 4
   468 		pasteOffset := pasteOffset + 4
   469             ].
   469 	    ].
   470         ].
   470 	].
   471         view realize.
   471 	view realize.
   472         newSel add:view.
   472 	newSel add:view.
   473     ].
   473     ].
   474 
   474 
   475     self withinTransaction:#paste objects:newSel do:[
   475     self withinTransaction:#paste objects:newSel do:[
   476         undoHistory addUndoSelector:#undoCreate:
   476 	undoHistory addUndoSelector:#undoCreate:
   477                            withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier])
   477 			   withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier])
   478     ].
   478     ].
   479 
   479 
   480     self realizeAllSubViews.
   480     self realizeAllSubViews.
   481     newSel do:[:v| v raise].
   481     newSel do:[:v| v raise].
   482     self elementChangedSize:containerToPasteInto.
   482     self elementChangedSize:containerToPasteInto.
   494     |sel|
   494     |sel|
   495 
   495 
   496     sel := self pasteSpecifications:(self getSelection) keepLayout:true.
   496     sel := self pasteSpecifications:(self getSelection) keepLayout:true.
   497 
   497 
   498     sel notNil ifTrue:[
   498     sel notNil ifTrue:[
   499         self select:sel.
   499 	self select:sel.
   500     ].
   500     ].
   501 ! !
   501 ! !
   502 
   502 
   503 !UIPainterView methodsFor:'drag & drop'!
   503 !UIPainterView methodsFor:'drag & drop'!
   504 
   504 
   505 canDrop:something
   505 canDrop:something
   506     "returns true if something can be droped
   506     "returns true if something can be droped
   507     "      
   507     "
   508     (something size == 1 and:[self enabled and:[self numberOfSelections <= 1]]) ifTrue:[
   508     (something size == 1 and:[self enabled and:[self numberOfSelections <= 1]]) ifTrue:[
   509       ^ something first theObject isKindOf:UISpecification
   509       ^ something first theObject isKindOf:UISpecification
   510     ].
   510     ].
   511     ^ false
   511     ^ false
   512 !
   512 !
   522     "returns true if something could be paste
   522     "returns true if something could be paste
   523     "
   523     "
   524     |el size|
   524     |el size|
   525 
   525 
   526     ((size := self numberOfSelections) <= 1 and:[self enabled]) ifFalse:[
   526     ((size := self numberOfSelections) <= 1 and:[self enabled]) ifFalse:[
   527         ^ false
   527 	^ false
   528     ].
   528     ].
   529     something isCollection ifTrue:[something notEmpty ifTrue:[el := something first]]
   529     something isCollection ifTrue:[something notEmpty ifTrue:[el := something first]]
   530                           ifFalse:[el := something].
   530 			  ifFalse:[el := something].
   531 
   531 
   532     (el isKindOf:UISpecification) ifFalse:[
   532     (el isKindOf:UISpecification) ifFalse:[
   533         ^ false
   533 	^ false
   534     ].
   534     ].
   535 
   535 
   536     size == 1 ifTrue:[
   536     size == 1 ifTrue:[
   537         ^ self canPasteInto:(self singleSelection)
   537 	^ self canPasteInto:(self singleSelection)
   538     ].
   538     ].
   539   ^ true
   539   ^ true
   540 !
   540 !
   541 
   541 
   542 canPasteInto:aView
   542 canPasteInto:aView
   543     "can paste into a view
   543     "can paste into a view
   544     "
   544     "
   545     |prop|
   545     |prop|
   546 
   546 
   547     aView notNil ifTrue:[
   547     aView notNil ifTrue:[
   548         (prop := self propertyRespondsToView:aView) notNil ifTrue:[
   548 	(prop := self propertyRespondsToView:aView) notNil ifTrue:[
   549             ^ prop spec class supportsSubComponents
   549 	    ^ prop spec class supportsSubComponents
   550         ].
   550 	].
   551       ^ aView specClass supportsSubComponents.
   551       ^ aView specClass supportsSubComponents.
   552     ].
   552     ].
   553     ^ false
   553     ^ false
   554 
   554 
   555 !
   555 !
   557 drop:anObjectOrCollection at:aPoint
   557 drop:anObjectOrCollection at:aPoint
   558     |spec newSel oldSel dragOffset widg doit|
   558     |spec newSel oldSel dragOffset widg doit|
   559 
   559 
   560     doit := true.
   560     doit := true.
   561     self selection notNil ifTrue:[
   561     self selection notNil ifTrue:[
   562         oldSel := self singleSelection.
   562 	oldSel := self singleSelection.
   563 
   563 
   564         "/ search selections hierarchy for a widget into which we can paste
   564 	"/ search selections hierarchy for a widget into which we can paste
   565         widg := oldSel.
   565 	widg := oldSel.
   566         [widg isNil or:[self canPasteInto:widg]] whileFalse:[
   566 	[widg isNil or:[self canPasteInto:widg]] whileFalse:[
   567             widg notNil ifTrue:[
   567 	    widg notNil ifTrue:[
   568                 widg := widg container
   568 		widg := widg container
   569             ].
   569 	    ].
   570         ].
   570 	].
   571 
   571 
   572         oldSel := nil.
   572 	oldSel := nil.
   573         self setSelection:widg withRedraw:true.
   573 	self setSelection:widg withRedraw:true.
   574     ].
   574     ].
   575     spec := (anObjectOrCollection at:1) theObject.
   575     spec := (anObjectOrCollection at:1) theObject.
   576     doit ifTrue:[
   576     doit ifTrue:[
   577         dragOffset := DragAndDropManager dragOffsetQuerySignal query.
   577 	dragOffset := DragAndDropManager dragOffsetQuerySignal query.
   578         newSel := self pasteSpecifications:spec keepLayout:false at:aPoint - dragOffset.
   578 	newSel := self pasteSpecifications:spec keepLayout:false at:aPoint - dragOffset.
   579 
   579 
   580         self select:(oldSel ? newSel)
   580 	self select:(oldSel ? newSel)
   581     ].
   581     ].
   582 
   582 
   583     "Modified: / 18.3.1999 / 18:29:43 / stefan"
   583     "Modified: / 18.3.1999 / 18:29:43 / stefan"
   584     "Modified: / 30.10.2001 / 14:02:35 / cg"
   584     "Modified: / 30.10.2001 / 14:02:35 / cg"
   585 ! !
   585 ! !
   602     "Modified: / 31.10.1997 / 20:27:32 / cg"
   602     "Modified: / 31.10.1997 / 20:27:32 / cg"
   603 !
   603 !
   604 
   604 
   605 sizeChanged:how
   605 sizeChanged:how
   606 
   606 
   607     super sizeChanged:how. 
   607     super sizeChanged:how.
   608 
   608 
   609     self layoutChanged
   609     self layoutChanged
   610 ! !
   610 ! !
   611 
   611 
   612 !UIPainterView methodsFor:'generating output'!
   612 !UIPainterView methodsFor:'generating output'!
   615     "extract a list of aspect methods - for browsing"
   615     "extract a list of aspect methods - for browsing"
   616 
   616 
   617     |cls methods|
   617     |cls methods|
   618 
   618 
   619     className isNil ifTrue:[
   619     className isNil ifTrue:[
   620         self warn:'No class defined !!'.
   620 	self warn:'No class defined !!'.
   621         ^ #()
   621 	^ #()
   622     ].
   622     ].
   623 
   623 
   624     cls := self resolveName:className.
   624     cls := self resolveName:className.
   625     methods := IdentitySet new.
   625     methods := IdentitySet new.
   626 
   626 
   627     self aspectSelectorsAndTypesDo:
   627     self aspectSelectorsAndTypesDo:
   628         [:selector :typeSymbol |
   628 	[:selector :typeSymbol |
   629             |skip|
   629 	    |skip|
   630 
   630 
   631             (cls includesSelector:selector) ifTrue:[
   631 	    (cls includesSelector:selector) ifTrue:[
   632 
   632 
   633                 skip := false.
   633 		skip := false.
   634                 (typeSymbol == #modelAspect) ifTrue:[
   634 		(typeSymbol == #modelAspect) ifTrue:[
   635                     (cls isSubclassOf:SimpleDialog) ifTrue:[
   635 		    (cls isSubclassOf:SimpleDialog) ifTrue:[
   636                         skip := SimpleDialog includesSelector:(selector asSymbol)
   636 			skip := SimpleDialog includesSelector:(selector asSymbol)
   637                     ].
   637 		    ].
   638                 ].
   638 		].
   639                 skip ifFalse:[
   639 		skip ifFalse:[
   640                     methods add:(cls compiledMethodAt:selector)
   640 		    methods add:(cls compiledMethodAt:selector)
   641                 ].
   641 		].
   642             ]
   642 	    ]
   643         ].
   643 	].
   644 
   644 
   645     ^ methods
   645     ^ methods
   646 
   646 
   647     "Created: / 25.10.1997 / 18:58:25 / cg"
   647     "Created: / 25.10.1997 / 18:58:25 / cg"
   648     "Modified: / 26.10.1997 / 15:06:18 / cg"
   648     "Modified: / 26.10.1997 / 15:06:18 / cg"
   652     "evaluate aBlock for every aspect methods selector; 2nd arg describes the aspects type"
   652     "evaluate aBlock for every aspect methods selector; 2nd arg describes the aspects type"
   653 
   653 
   654     |cls selector protoSpec|
   654     |cls selector protoSpec|
   655 
   655 
   656     className isNil ifTrue:[
   656     className isNil ifTrue:[
   657         self warn:'No class defined !!'.
   657 	self warn:'No class defined !!'.
   658         ^ self
   658 	^ self
   659     ].
   659     ].
   660 
   660 
   661     cls := self resolveName:className.
   661     cls := self resolveName:className.
   662 
   662 
   663     treeView propertiesDo:[:aProp|
   663     treeView propertiesDo:[:aProp|
   664         |selector|
   664 	|selector|
   665 
   665 
   666         (selector := aProp model) notNil ifTrue:[
   666 	(selector := aProp model) notNil ifTrue:[
   667             selector isArray ifFalse:[
   667 	    selector isArray ifFalse:[
   668                 aTwoArgBlock value:(selector asSymbol) value:#modelAspect
   668 		aTwoArgBlock value:(selector asSymbol) value:#modelAspect
   669             ].
   669 	    ].
   670         ].
   670 	].
   671 
   671 
   672         (selector := aProp menu) notNil ifTrue:[
   672 	(selector := aProp menu) notNil ifTrue:[
   673             selector isArray ifFalse:[
   673 	    selector isArray ifFalse:[
   674                 aTwoArgBlock value:(selector asSymbol) value:#menu
   674 		aTwoArgBlock value:(selector asSymbol) value:#menu
   675             ].
   675 	    ].
   676         ].
   676 	].
   677 
   677 
   678         (aProp spec aspectSelectors) do:[:aSel |
   678 	(aProp spec aspectSelectors) do:[:aSel |
   679             aSel isArray ifFalse:[
   679 	    aSel isArray ifFalse:[
   680                 aTwoArgBlock value:(aSel asSymbol) value:#channelAspect
   680 		aTwoArgBlock value:(aSel asSymbol) value:#channelAspect
   681             ].
   681 	    ].
   682         ].
   682 	].
   683         aProp spec actionSelectors do:[:aSel|
   683 	aProp spec actionSelectors do:[:aSel|
   684             aSel isArray ifFalse:[
   684 	    aSel isArray ifFalse:[
   685                 aTwoArgBlock value:(aSel asSymbol) value:#actionSelector
   685 		aTwoArgBlock value:(aSel asSymbol) value:#actionSelector
   686             ].
   686 	    ].
   687         ].
   687 	].
   688         aProp spec valueSelectors do:[:aSel|
   688 	aProp spec valueSelectors do:[:aSel|
   689             aSel isArray ifFalse:[
   689 	    aSel isArray ifFalse:[
   690                 aTwoArgBlock value:(aSel asSymbol) value:#valueSelector
   690 		aTwoArgBlock value:(aSel asSymbol) value:#valueSelector
   691             ].
   691 	    ].
   692         ]
   692 	]
   693     ].
   693     ].
   694 
   694 
   695     protoSpec := treeView canvasSpec.
   695     protoSpec := treeView canvasSpec.
   696 
   696 
   697     (selector := protoSpec menu) notNil ifTrue:[
   697     (selector := protoSpec menu) notNil ifTrue:[
   698         selector isArray ifFalse:[
   698 	selector isArray ifFalse:[
   699             aTwoArgBlock value:(selector asSymbol) value:#menu
   699 	    aTwoArgBlock value:(selector asSymbol) value:#menu
   700         ].
   700 	].
   701     ].
   701     ].
   702 !
   702 !
   703 
   703 
   704 generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
   704 generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
   705     |selector args showIt code alreadyInSuperclass numArgs method|
   705     |selector args showIt code alreadyInSuperclass numArgs method|
   710 
   710 
   711     numArgs := selector numArgs.
   711     numArgs := selector numArgs.
   712     method  := aspect.
   712     method  := aspect.
   713 
   713 
   714     numArgs == 1 ifTrue:[
   714     numArgs == 1 ifTrue:[
   715         args := 'anArgument'.
   715 	args := 'anArgument'.
   716         showIt := ''' , anArgument printString , '' ...''.\'.
   716 	showIt := ''' , anArgument printString , '' ...''.\'.
   717     ] ifFalse:[    
   717     ] ifFalse:[
   718         args := ''.
   718 	args := ''.
   719         showIt := ' ...''.\'.
   719 	showIt := ' ...''.\'.
   720 
   720 
   721         numArgs ~~ 0 ifTrue:[
   721 	numArgs ~~ 0 ifTrue:[
   722             method := ''.
   722 	    method := ''.
   723 
   723 
   724             selector keywords keysAndValuesDo:[:i :key|
   724 	    selector keywords keysAndValuesDo:[:i :key|
   725                 method := method, key, 'arg', i printString, ' '
   725 		method := method, key, 'arg', i printString, ' '
   726             ]
   726 	    ]
   727         ]
   727 	]
   728     ].
   728     ].
   729 
   729 
   730     code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' ,
   730     code := '!!' , targetClass name , ' methodsFor:''actions''!!\\' ,
   731                 method , args , '\' ,
   731 		method , args , '\' ,
   732                 '    "automatically generated by UIPainter ..."\\' ,
   732 		'    "automatically generated by UIPainter ..."\\' ,
   733                 '    "*** the code below performs no action"\' ,
   733 		'    "*** the code below performs no action"\' ,
   734                 '    "*** (except for some feedback on the Transcript)"\' ,
   734 		'    "*** (except for some feedback on the Transcript)"\' ,
   735                 '    "*** Please change as required and accept in the browser."\' ,
   735 		'    "*** Please change as required and accept in the browser."\' ,
   736                 '\' .
   736 		'\' .
   737 
   737 
   738     alreadyInSuperclass ifTrue:[
   738     alreadyInSuperclass ifTrue:[
   739         code := code ,
   739 	code := code ,
   740                     '    "action for ' , aspect , ' is already provided in a superclass."\' ,
   740 		    '    "action for ' , aspect , ' is already provided in a superclass."\' ,
   741                     '    "It may be redefined here ..."\\'.
   741 		    '    "It may be redefined here ..."\\'.
   742     ] ifFalse:[
   742     ] ifFalse:[
   743         code := code ,
   743 	code := code ,
   744                     '    "action to be added ..."\\'.
   744 		    '    "action to be added ..."\\'.
   745     ].
   745     ].
   746 
   746 
   747     code := code ,
   747     code := code ,
   748                 '    Transcript showCR:self class name, '': '.
   748 		'    Transcript showCR:self class name, '': '.
   749     alreadyInSuperclass ifTrue:[
   749     alreadyInSuperclass ifTrue:[
   750         code := code , 'inherited '.
   750 	code := code , 'inherited '.
   751     ].
   751     ].
   752     code := code , 'action for ' , aspect , showIt.
   752     code := code , 'action for ' , aspect , showIt.
   753 
   753 
   754     alreadyInSuperclass ifTrue:[
   754     alreadyInSuperclass ifTrue:[
   755         code := code ,
   755 	code := code ,
   756                         '    super ' , aspect , args , '.\'.
   756 			'    super ' , aspect , args , '.\'.
   757     ].
   757     ].
   758 
   758 
   759     code := code ,
   759     code := code ,
   760                 '!! !!\\'.
   760 		'!! !!\\'.
   761     ^ code withCRs
   761     ^ code withCRs
   762 
   762 
   763     "Modified: / 25.10.1997 / 19:18:50 / cg"
   763     "Modified: / 25.10.1997 / 19:18:50 / cg"
   764 !
   764 !
   765 
   765 
   779     |cls codePieces skip protoSpec thisCode
   779     |cls codePieces skip protoSpec thisCode
   780      definedMethodSelectors iVars t exportSels|
   780      definedMethodSelectors iVars t exportSels|
   781 
   781 
   782     cls := self targetClass.
   782     cls := self targetClass.
   783     cls isNil ifTrue:[
   783     cls isNil ifTrue:[
   784         ^ nil
   784 	^ nil
   785     ].
   785     ].
   786 
   786 
   787     codePieces := OrderedCollection new.
   787     codePieces := OrderedCollection new.
   788     definedMethodSelectors := IdentitySet new.
   788     definedMethodSelectors := IdentitySet new.
   789 
   789 
   790     treeView propertiesDo:[:aProp|
   790     treeView propertiesDo:[:aProp|
   791         |modelSelector|
   791 	|modelSelector|
   792 
   792 
   793         protoSpec := aProp spec.
   793 	protoSpec := aProp spec.
   794 
   794 
   795         (modelSelector := aProp model) notNil ifTrue:[
   795 	(modelSelector := aProp model) notNil ifTrue:[
   796             self generateCodeFrom:(Array with:modelSelector) in:cls
   796 	    self generateCodeFrom:(Array with:modelSelector) in:cls
   797                 do:[:aSel|
   797 		do:[:aSel|
   798                     (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   798 		    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   799                         skip := false.
   799 			skip := false.
   800 
   800 
   801                         (cls isSubclassOf:SimpleDialog) ifTrue:[
   801 			(cls isSubclassOf:SimpleDialog) ifTrue:[
   802                             skip := SimpleDialog includesSelector:aSel
   802 			    skip := SimpleDialog includesSelector:aSel
   803                         ].
   803 			].
   804                         (definedMethodSelectors includes:aSel) ifTrue:[
   804 			(definedMethodSelectors includes:aSel) ifTrue:[
   805                             skip := true.
   805 			    skip := true.
   806                         ].
   806 			].
   807 
   807 
   808                         skip ifFalse:[
   808 			skip ifFalse:[
   809                             "/ kludge ..
   809 			    "/ kludge ..
   810                             "/ (protoSpec isKindOf:ActionButtonSpec) 
   810 			    "/ (protoSpec isKindOf:ActionButtonSpec)
   811                             (protoSpec defaultModelIsCallBackMethodSelector:aSel)
   811 			    (protoSpec defaultModelIsCallBackMethodSelector:aSel)
   812                             ifTrue:[
   812 			    ifTrue:[
   813                                 thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   813 				thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   814                             ] ifFalse:[
   814 			    ] ifFalse:[
   815                                 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   815 				thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   816                             ].
   816 			    ].
   817                             codePieces add:thisCode.
   817 			    codePieces add:thisCode.
   818                             definedMethodSelectors add:aSel.
   818 			    definedMethodSelectors add:aSel.
   819                             Transcript showCR:'code generated for aspect: ' , aSel
   819 			    Transcript showCR:'code generated for aspect: ' , aSel
   820                         ] ifTrue:[
   820 			] ifTrue:[
   821                             Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)'
   821 			    Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)'
   822                         ].
   822 			].
   823                     ].
   823 		    ].
   824                 ].
   824 		].
   825         ].
   825 	].
   826 
   826 
   827         "/ for each aspect, generate getter (if not yet implemented)
   827 	"/ for each aspect, generate getter (if not yet implemented)
   828         self generateCodeFrom:(aProp spec aspectSelectors) in:cls
   828 	self generateCodeFrom:(aProp spec aspectSelectors) in:cls
   829                 do:[:aSel|
   829 		do:[:aSel|
   830                     (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   830 		    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   831                         (definedMethodSelectors includes:aSel) ifFalse:[
   831 			(definedMethodSelectors includes:aSel) ifFalse:[
   832                             thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   832 			    thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   833                             codePieces add:thisCode.
   833 			    codePieces add:thisCode.
   834                             definedMethodSelectors add:aSel.
   834 			    definedMethodSelectors add:aSel.
   835                             Transcript showCR:'code generated for aspect: ' , aSel
   835 			    Transcript showCR:'code generated for aspect: ' , aSel
   836                         ]
   836 			]
   837                     ]
   837 		    ]
   838                 ].
   838 		].
   839 
   839 
   840         "/ exported aspects - need setter methods
   840 	"/ exported aspects - need setter methods
   841         exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect , ':') asSymbol].
   841 	exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect , ':') asSymbol].
   842         self generateCodeFrom:exportSels in:cls
   842 	self generateCodeFrom:exportSels in:cls
   843                 do:[:aSel|
   843 		do:[:aSel|
   844                     |aspect|
   844 		    |aspect|
   845 
   845 
   846                     (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   846 		    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   847                         (definedMethodSelectors includes:aSel) ifFalse:[
   847 			(definedMethodSelectors includes:aSel) ifFalse:[
   848                             aspect := (aSel copyWithoutLast:1) asSymbol.
   848 			    aspect := (aSel copyWithoutLast:1) asSymbol.
   849                             thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls).
   849 			    thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls).
   850                             codePieces add:thisCode.
   850 			    codePieces add:thisCode.
   851                             definedMethodSelectors add:aSel.
   851 			    definedMethodSelectors add:aSel.
   852                             Transcript showCR:'export code generated for aspect: ' , aSel
   852 			    Transcript showCR:'export code generated for aspect: ' , aSel
   853                         ]
   853 			]
   854                     ]
   854 		    ]
   855                 ].
   855 		].
   856 
   856 
   857         self generateCodeFrom:(aProp spec actionSelectors) in:cls
   857 	self generateCodeFrom:(aProp spec actionSelectors) in:cls
   858                 do:[:aSel|
   858 		do:[:aSel|
   859                     (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   859 		    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   860                         (definedMethodSelectors includes:aSel) ifFalse:[
   860 			(definedMethodSelectors includes:aSel) ifFalse:[
   861                             thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   861 			    thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   862                             codePieces add:thisCode.
   862 			    codePieces add:thisCode.
   863                             definedMethodSelectors add:aSel.
   863 			    definedMethodSelectors add:aSel.
   864                             Transcript showCR:'action generated for aspect: ' , aSel
   864 			    Transcript showCR:'action generated for aspect: ' , aSel
   865                         ]
   865 			]
   866                     ]
   866 		    ]
   867                 ].
   867 		].
   868 
   868 
   869         self generateCodeFrom:(aProp spec valueSelectors) in:cls
   869 	self generateCodeFrom:(aProp spec valueSelectors) in:cls
   870                 do:[:aSel|
   870 		do:[:aSel|
   871                     (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   871 		    (aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[
   872                         (definedMethodSelectors includes:aSel) ifFalse:[
   872 			(definedMethodSelectors includes:aSel) ifFalse:[
   873                             "/ uppercase: - assume its a globals name.
   873 			    "/ uppercase: - assume its a globals name.
   874                             aSel first isUppercase ifFalse:[
   874 			    aSel first isUppercase ifFalse:[
   875                                 thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
   875 				thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
   876                                 codePieces add:thisCode.
   876 				codePieces add:thisCode.
   877                                 definedMethodSelectors add:aSel.
   877 				definedMethodSelectors add:aSel.
   878                                 Transcript showCR:'code generated for aspect: ' , aSel
   878 				Transcript showCR:'code generated for aspect: ' , aSel
   879                             ]
   879 			    ]
   880                         ]
   880 			]
   881                     ]
   881 		    ]
   882                 ].
   882 		].
   883     ].
   883     ].
   884 
   884 
   885     AspectsAsInstances ifTrue:[
   885     AspectsAsInstances ifTrue:[
   886         iVars := cls instVarNames asOrderedCollection.
   886 	iVars := cls instVarNames asOrderedCollection.
   887         definedMethodSelectors do:[:ivar |
   887 	definedMethodSelectors do:[:ivar |
   888             (iVars includes:ivar) ifFalse:[
   888 	    (iVars includes:ivar) ifFalse:[
   889                 iVars add:ivar
   889 		iVars add:ivar
   890             ]
   890 	    ]
   891         ].
   891 	].
   892         iVars := iVars asArray.
   892 	iVars := iVars asArray.
   893         t := cls shallowCopy.
   893 	t := cls shallowCopy.
   894         t setInstanceVariableString:iVars asStringCollection asString.
   894 	t setInstanceVariableString:iVars asStringCollection asString.
   895         codePieces addFirst:(t definition , '!!\' withCRs).
   895 	codePieces addFirst:(t definition , '!!\' withCRs).
   896     ].
   896     ].
   897 
   897 
   898     ^ String 
   898     ^ String
   899         streamContents:
   899 	streamContents:
   900             [:codeStream | 
   900 	    [:codeStream |
   901                 codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece].
   901 		codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece].
   902             ].
   902 	    ].
   903 
   903 
   904     "Modified: / 29.7.1998 / 12:21:19 / cg"
   904     "Modified: / 29.7.1998 / 12:21:19 / cg"
   905 !
   905 !
   906 
   906 
   907 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
   907 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
   908     |modelClass modelValueString modelValue modelGen code|
   908     |modelClass modelValueString modelValue modelGen code|
   909 
   909 
   910     modelClass := protoSpec defaultModelClassFor:aspect.
   910     modelClass := protoSpec defaultModelClassFor:aspect.
   911     modelValueString := protoSpec defaultModelValueStringFor:aspect.
   911     modelValueString := protoSpec defaultModelValueStringFor:aspect.
   912     modelValueString notNil ifTrue:[
   912     modelValueString notNil ifTrue:[
   913         modelGen := modelValueString
   913 	modelGen := modelValueString
   914     ] ifFalse:[
   914     ] ifFalse:[
   915         modelValue := protoSpec defaultModelValueFor:aspect.
   915 	modelValue := protoSpec defaultModelValueFor:aspect.
   916         modelValue isNil ifTrue:[
   916 	modelValue isNil ifTrue:[
   917             modelGen := modelClass name , ' new'
   917 	    modelGen := modelClass name , ' new'
   918         ] ifFalse:[
   918 	] ifFalse:[
   919             modelGen := modelValue storeString , ' asValue'
   919 	    modelGen := modelValue storeString , ' asValue'
   920         ].
   920 	].
   921 
   921 
   922     ].
   922     ].
   923 
   923 
   924     code := '!!' , targetClass name , ' methodsFor:''aspects''!!\\' ,
   924     code := '!!' , targetClass name , ' methodsFor:''aspects''!!\\' ,
   925       aspect , '\' ,
   925       aspect , '\' ,
   929       '    "*** Please change as required and accept it in the browser."\' ,
   929       '    "*** Please change as required and accept it in the browser."\' ,
   930       '    "*** (and replace this comment by something more useful ;-)"\' .
   930       '    "*** (and replace this comment by something more useful ;-)"\' .
   931 
   931 
   932 
   932 
   933     AspectsAsInstances ifTrue:[
   933     AspectsAsInstances ifTrue:[
   934         code := code , '\' ,
   934 	code := code , '\' ,
   935           '    ' , aspect , ' isNil ifTrue:[\' ,
   935 	  '    ' , aspect , ' isNil ifTrue:[\' ,
   936           '        ' , aspect , ' := ' , modelGen , '.\'.
   936 	  '        ' , aspect , ' := ' , modelGen , '.\'.
   937         modelClass ~~ TriggerValue ifTrue:[
   937 	modelClass ~~ TriggerValue ifTrue:[
   938             code := code ,
   938 	    code := code ,
   939               '"/ if your app needs to be notified of changes, uncomment one of the lines below:\' ,
   939 	      '"/ if your app needs to be notified of changes, uncomment one of the lines below:\' ,
   940               '"/       ' , aspect , ' addDependent:self.\' ,
   940 	      '"/       ' , aspect , ' addDependent:self.\' ,
   941               '"/       ' , aspect , ' onChangeSend:#', aspect ,'Changed to:self.\'.
   941 	      '"/       ' , aspect , ' onChangeSend:#', aspect ,'Changed to:self.\'.
   942         ].
   942 	].
   943         code := code ,
   943 	code := code ,
   944           '    ].\' ,
   944 	  '    ].\' ,
   945           '    ^ ' , aspect ,'.\' ,
   945 	  '    ^ ' , aspect ,'.\' ,
   946           '!! !!\\' 
   946 	  '!! !!\\'
   947     ] ifFalse:[
   947     ] ifFalse:[
   948         code := code , '\' ,
   948 	code := code , '\' ,
   949           '    |holder|\' ,
   949 	  '    |holder|\' ,
   950           '\' ,
   950 	  '\' ,
   951           '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   951 	  '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
   952           '        holder := ', modelGen, '.\',
   952 	  '        holder := ', modelGen, '.\',
   953           '        builder aspectAt:#' , aspect , ' put:holder.\'.
   953 	  '        builder aspectAt:#' , aspect , ' put:holder.\'.
   954         modelClass ~~ TriggerValue ifTrue:[
   954 	modelClass ~~ TriggerValue ifTrue:[
   955             code := code ,
   955 	    code := code ,
   956               '"/ if your app needs to be notified of changes, uncomment one of the lines below:\' ,
   956 	      '"/ if your app needs to be notified of changes, uncomment one of the lines below:\' ,
   957               '"/        holder addDependent:self.\' ,
   957 	      '"/        holder addDependent:self.\' ,
   958               '"/        holder onChangeSend:#', aspect ,'Changed to:self.\'.
   958 	      '"/        holder onChangeSend:#', aspect ,'Changed to:self.\'.
   959         ].
   959 	].
   960         code := code ,
   960 	code := code ,
   961           '    ].\' ,
   961 	  '    ].\' ,
   962           '    ^ holder.\' ,
   962 	  '    ^ holder.\' ,
   963           '!! !!\\' 
   963 	  '!! !!\\'
   964     ].
   964     ].
   965 
   965 
   966     ^ code withCRs
   966     ^ code withCRs
   967 
   967 
   968     "Modified: / 29.7.1998 / 11:29:16 / cg"
   968     "Modified: / 29.7.1998 / 11:29:16 / cg"
   975 
   975 
   976     |cls code spec|
   976     |cls code spec|
   977 
   977 
   978     cls := self targetClass.
   978     cls := self targetClass.
   979     cls isNil ifTrue:[
   979     cls isNil ifTrue:[
   980         ^ nil
   980 	^ nil
   981     ].
   981     ].
   982 
   982 
   983     spec := treeView exportedAspects.
   983     spec := treeView exportedAspects.
   984     spec size == 0 ifTrue:[^ nil].
   984     spec size == 0 ifTrue:[^ nil].
   985 
   985 
   986     "/ make it an array ...
   986     "/ make it an array ...
   987     spec := spec collect:[:entry | |subAspect type|
   987     spec := spec collect:[:entry | |subAspect type|
   988                 subAspect := entry subAspect asSymbol.
   988 		subAspect := entry subAspect asSymbol.
   989                 (type := entry type) isNil ifTrue:[
   989 		(type := entry type) isNil ifTrue:[
   990                     subAspect
   990 		    subAspect
   991                 ] ifFalse:[
   991 		] ifFalse:[
   992                     Array with:subAspect with:type asSymbol
   992 		    Array with:subAspect with:type asSymbol
   993                 ].
   993 		].
   994             ].
   994 	    ].
   995     spec := spec asArray.
   995     spec := spec asArray.
   996 
   996 
   997     code := '!!' , cls name , ' class methodsFor:''plugIn spec''!!\\' .
   997     code := '!!' , cls name , ' class methodsFor:''plugIn spec''!!\\' .
   998 
   998 
   999     code := code , 'aspectSelectors
   999     code := code , 'aspectSelectors
  1025       '    "automatically generated by UIPainter ..."\\' ,
  1025       '    "automatically generated by UIPainter ..."\\' ,
  1026       '    "This method is used when I am embedded as subApplication,"\' ,
  1026       '    "This method is used when I am embedded as subApplication,"\' ,
  1027       '    "and the mainApp wants to connect its aspects to mine."\'.
  1027       '    "and the mainApp wants to connect its aspects to mine."\'.
  1028 
  1028 
  1029     AspectsAsInstances ifTrue:[
  1029     AspectsAsInstances ifTrue:[
  1030         code := (code , '\' ,
  1030 	code := (code , '\' ,
  1031           '"/     ' , aspect , ' notNil ifTrue:[\' ,
  1031 	  '"/     ' , aspect , ' notNil ifTrue:[\' ,
  1032           '"/        ' , aspect , ' removeDependent:self.\' ,
  1032 	  '"/        ' , aspect , ' removeDependent:self.\' ,
  1033           '"/     ].\' ,
  1033 	  '"/     ].\' ,
  1034           '    ' , aspect ,' := something.\' ,
  1034 	  '    ' , aspect ,' := something.\' ,
  1035           '"/     ' , aspect ,' notNil ifTrue:[\' ,
  1035 	  '"/     ' , aspect ,' notNil ifTrue:[\' ,
  1036           '"/        ' , aspect , ' addDependent:self.\' ,
  1036 	  '"/        ' , aspect , ' addDependent:self.\' ,
  1037           '"/     ].\' ,
  1037 	  '"/     ].\' ,
  1038           '    ^ self.\' ,
  1038 	  '    ^ self.\' ,
  1039           '!! !!\\') 
  1039 	  '!! !!\\')
  1040     ] ifFalse:[
  1040     ] ifFalse:[
  1041         code := (code , '\' ,
  1041 	code := (code , '\' ,
  1042           '"/     |holder|\' ,
  1042 	  '"/     |holder|\' ,
  1043           '\' ,
  1043 	  '\' ,
  1044           '"/     (holder := builder bindingAt:#' , aspect , ') notNil ifTrue:[\' ,
  1044 	  '"/     (holder := builder bindingAt:#' , aspect , ') notNil ifTrue:[\' ,
  1045           '"/         holder removeDependent:self.\' ,
  1045 	  '"/         holder removeDependent:self.\' ,
  1046           '"/     ].\' ,
  1046 	  '"/     ].\' ,
  1047           '    builder aspectAt:#' , aspect , ' put:something.\',
  1047 	  '    builder aspectAt:#' , aspect , ' put:something.\',
  1048           '"/     something notNil ifTrue:[\' ,
  1048 	  '"/     something notNil ifTrue:[\' ,
  1049           '"/         something addDependent:self.\' ,
  1049 	  '"/         something addDependent:self.\' ,
  1050           '"/     ].\' ,
  1050 	  '"/     ].\' ,
  1051           '    ^ self.\' ,
  1051 	  '    ^ self.\' ,
  1052           '!! !!\\') 
  1052 	  '!! !!\\')
  1053     ].
  1053     ].
  1054 
  1054 
  1055     ^ code withCRs
  1055     ^ code withCRs
  1056 
  1056 
  1057     "Modified: / 29.7.1998 / 11:29:16 / cg"
  1057     "Modified: / 29.7.1998 / 11:29:16 / cg"
  1062     |realSelectors redefCondition redefMessage|
  1062     |realSelectors redefCondition redefMessage|
  1063 
  1063 
  1064     realSelectors := aListOfSelectors select:[:sel | sel isArray not].
  1064     realSelectors := aListOfSelectors select:[:sel | sel isArray not].
  1065 
  1065 
  1066     self class redefineAspectMethods ifTrue:[
  1066     self class redefineAspectMethods ifTrue:[
  1067         redefCondition := [:cls :sel | (cls includesSelector:sel) not].
  1067 	redefCondition := [:cls :sel | (cls includesSelector:sel) not].
  1068         redefMessage := ' skipped - already implemented in the class'.
  1068 	redefMessage := ' skipped - already implemented in the class'.
  1069     ] ifFalse:[
  1069     ] ifFalse:[
  1070         redefCondition := [:cls :sel | (cls canUnderstand:sel) not].
  1070 	redefCondition := [:cls :sel | (cls canUnderstand:sel) not].
  1071         redefMessage := ' skipped - already implemented in the class (or superclass)'.
  1071 	redefMessage := ' skipped - already implemented in the class (or superclass)'.
  1072     ].
  1072     ].
  1073 
  1073 
  1074     realSelectors do:[:aSelector|
  1074     realSelectors do:[:aSelector|
  1075         (redefCondition value:aClass value:aSelector) ifTrue:[
  1075 	(redefCondition value:aClass value:aSelector) ifTrue:[
  1076             aBlock value:aSelector asSymbol
  1076 	    aBlock value:aSelector asSymbol
  1077         ] ifFalse:[
  1077 	] ifFalse:[
  1078             Transcript showCR:('#' , aSelector , redefMessage)
  1078 	    Transcript showCR:('#' , aSelector , redefMessage)
  1079         ]
  1079 	]
  1080     ]
  1080     ]
  1081 !
  1081 !
  1082 
  1082 
  1083 generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass
  1083 generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass
  1084     ^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' ,
  1084     ^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' ,
  1105 
  1105 
  1106     |cls|
  1106     |cls|
  1107 
  1107 
  1108     cls := self targetClass.
  1108     cls := self targetClass.
  1109     cls isNil ifTrue:[
  1109     cls isNil ifTrue:[
  1110         ^ nil
  1110 	^ nil
  1111     ].
  1111     ].
  1112 
  1112 
  1113     ^ self generateHookMethodsInClass:cls.
  1113     ^ self generateHookMethodsInClass:cls.
  1114 !
  1114 !
  1115 
  1115 
  1117     |code|
  1117     |code|
  1118 
  1118 
  1119     code := ''.
  1119     code := ''.
  1120 
  1120 
  1121     (targetClass includesSelector:#postBuildWith:) ifFalse:[
  1121     (targetClass includesSelector:#postBuildWith:) ifFalse:[
  1122         code := code 
  1122 	code := code
  1123                 , (self 
  1123 		, (self
  1124                     generateHookMethodFor:'postBuildWith:aBuilder'
  1124 		    generateHookMethodFor:'postBuildWith:aBuilder'
  1125                     comment:'the widgets have been built, but before the view is opened'
  1125 		    comment:'the widgets have been built, but before the view is opened'
  1126                     note:'or after the super send'
  1126 		    note:'or after the super send'
  1127                     defaultCode:'    super postBuildWith:aBuilder'
  1127 		    defaultCode:'    super postBuildWith:aBuilder'
  1128                     inClass:targetClass)
  1128 		    inClass:targetClass)
  1129     ].
  1129     ].
  1130     (targetClass includesSelector:#postOpenWith:) ifFalse:[
  1130     (targetClass includesSelector:#postOpenWith:) ifFalse:[
  1131         code := code 
  1131 	code := code
  1132                 , (self 
  1132 		, (self
  1133                     generateHookMethodFor:'postOpenWith:aBuilder'
  1133 		    generateHookMethodFor:'postOpenWith:aBuilder'
  1134                     comment:'the topView has been opened, but before events are dispatched for it'
  1134 		    comment:'the topView has been opened, but before events are dispatched for it'
  1135                     note:'or after the super send'
  1135 		    note:'or after the super send'
  1136                     defaultCode:'    super postOpenWith:aBuilder'
  1136 		    defaultCode:'    super postOpenWith:aBuilder'
  1137                     inClass:targetClass)
  1137 		    inClass:targetClass)
  1138     ].
  1138     ].
  1139     (targetClass includesSelector:#closeRequest) ifFalse:[
  1139     (targetClass includesSelector:#closeRequest) ifFalse:[
  1140         code := code 
  1140 	code := code
  1141                 , (self 
  1141 		, (self
  1142                     generateHookMethodFor:'closeRequest'
  1142 		    generateHookMethodFor:'closeRequest'
  1143                     comment:'the topView has been asked to close'
  1143 		    comment:'the topView has been asked to close'
  1144                     note:'return without the ''super closeRequest'' to stay open'
  1144 		    note:'return without the ''super closeRequest'' to stay open'
  1145                     defaultCode:'    ^super closeRequest'
  1145 		    defaultCode:'    ^super closeRequest'
  1146                     inClass:targetClass)
  1146 		    inClass:targetClass)
  1147     ].
  1147     ].
  1148     ^ code
  1148     ^ code
  1149 
  1149 
  1150     "Modified: / 31.10.1997 / 17:30:34 / cg"
  1150     "Modified: / 31.10.1997 / 17:30:34 / cg"
  1151     "Created: / 31.10.1997 / 17:32:49 / cg"
  1151     "Created: / 31.10.1997 / 17:32:49 / cg"
  1160     alreadyInSuperclass := targetClass superclass canUnderstand:selector.
  1160     alreadyInSuperclass := targetClass superclass canUnderstand:selector.
  1161 
  1161 
  1162     code := '!!' , targetClass name , ' methodsFor:''' , category , '''!!\\'.
  1162     code := '!!' , targetClass name , ' methodsFor:''' , category , '''!!\\'.
  1163 
  1163 
  1164     selector = 'openAboutThisApplication' ifTrue:[
  1164     selector = 'openAboutThisApplication' ifTrue:[
  1165         code := code ,
  1165 	code := code ,
  1166                 'openAboutThisApplication\' ,
  1166 		'openAboutThisApplication\' ,
  1167                 '    "opens an about box for this application."\\' ,
  1167 		'    "opens an about box for this application."\\' ,
  1168                 '    "automatically generated by UIPainter ..."\\' ,
  1168 		'    "automatically generated by UIPainter ..."\\' ,
  1169 
  1169 
  1170                 '    |rev box myClass clsRev image msg|\\' ,
  1170 		'    |rev box myClass clsRev image msg|\\' ,
  1171 
  1171 
  1172                 '    rev := ''''.\' ,
  1172 		'    rev := ''''.\' ,
  1173                 '    myClass := self class.\' ,
  1173 		'    myClass := self class.\' ,
  1174 
  1174 
  1175                 '    (clsRev := myClass revision) notNil ifTrue:[\' ,
  1175 		'    (clsRev := myClass revision) notNil ifTrue:[\' ,
  1176                 '       rev := ''  (rev: '', clsRev printString, '')''].\\' ,
  1176 		'       rev := ''  (rev: '', clsRev printString, '')''].\\' ,
  1177 
  1177 
  1178                 '    msg := Character cr asString , myClass name asBoldText, rev.\' ,
  1178 		'    msg := Character cr asString , myClass name asBoldText, rev.\' ,
  1179                 '    msg := (msg , ''\\*** add more info here ***\\'') withCRs.\\' ,
  1179 		'    msg := (msg , ''\\*** add more info here ***\\'') withCRs.\\' ,
  1180                 '    box := AboutBox title:msg.\' ,
  1180 		'    box := AboutBox title:msg.\' ,
  1181 
  1181 
  1182                 '    "/ *** add a #defaultIcon method in the class\' ,
  1182 		'    "/ *** add a #defaultIcon method in the class\' ,
  1183                 '    "/ *** and uncomment the following line:\' ,
  1183 		'    "/ *** and uncomment the following line:\' ,
  1184                 '    "/ image := self class defaultIcon.\\' ,
  1184 		'    "/ image := self class defaultIcon.\\' ,
  1185                 '    image notNil ifTrue:[\' ,
  1185 		'    image notNil ifTrue:[\' ,
  1186                 '        box image:image\' ,
  1186 		'        box image:image\' ,
  1187                 '    ].\' ,
  1187 		'    ].\' ,
  1188                 '    box   label:(resources string:''About %1'' with:myClass name).\' ,
  1188 		'    box   label:(resources string:''About %1'' with:myClass name).\' ,
  1189                 '    box   autoHideAfter:10 with:[].\' ,
  1189 		'    box   autoHideAfter:10 with:[].\' ,
  1190                 '    box   showAtPointer.\' ,
  1190 		'    box   showAtPointer.\' ,
  1191                 '!! !!\\'.
  1191 		'!! !!\\'.
  1192         ^ code withCRs
  1192 	^ code withCRs
  1193     ].
  1193     ].
  1194 
  1194 
  1195     selector = 'menuOpen' ifTrue:[
  1195     selector = 'menuOpen' ifTrue:[
  1196         code := code ,
  1196 	code := code ,
  1197                 'menuOpen\' ,
  1197 		'menuOpen\' ,
  1198                 '    "automatically generated by UIPainter ..."\\' ,
  1198 		'    "automatically generated by UIPainter ..."\\' ,
  1199                 '    "*** the code below opens a dialog for file selection"\' ,
  1199 		'    "*** the code below opens a dialog for file selection"\' ,
  1200                 '    "*** and invokes the #doOpen: method with the selected file."\' ,
  1200 		'    "*** and invokes the #doOpen: method with the selected file."\' ,
  1201                 '    "*** Please change as required and accept in the browser."\\' ,
  1201 		'    "*** Please change as required and accept in the browser."\\' ,
  1202                 '    |file|\\' ,
  1202 		'    |file|\\' ,
  1203                 '    file :=\' ,
  1203 		'    file :=\' ,
  1204                 '        (FileSelectionBrowser\' ,
  1204 		'        (FileSelectionBrowser\' ,
  1205                 '            request: ''Open''\' ,
  1205 		'            request: ''Open''\' ,
  1206                 '            fileName: ''''\' ,
  1206 		'            fileName: ''''\' ,
  1207                 '            "/ inDirectory: lastOpenDirectory\' ,
  1207 		'            "/ inDirectory: lastOpenDirectory\' ,
  1208                 '            withFileFilters: #(''*'')).\\' ,
  1208 		'            withFileFilters: #(''*'')).\\' ,
  1209                 '    file notNil ifTrue:[\' ,
  1209 		'    file notNil ifTrue:[\' ,
  1210                 '       "/ lastOpenDirectory := file asFilename directory.\' ,
  1210 		'       "/ lastOpenDirectory := file asFilename directory.\' ,
  1211                 '       self doOpen:file\' ,
  1211 		'       self doOpen:file\' ,
  1212                 '    ]\' ,
  1212 		'    ]\' ,
  1213                 '!! !!\'.
  1213 		'!! !!\'.
  1214         ^ code withCRs
  1214 	^ code withCRs
  1215     ].
  1215     ].
  1216 
  1216 
  1217     numArgs := selector numArgs.
  1217     numArgs := selector numArgs.
  1218     method  := selector.
  1218     method  := selector.
  1219 
  1219 
  1220     numArgs == 1 ifTrue:[
  1220     numArgs == 1 ifTrue:[
  1221         args := 'anArgument'.
  1221 	args := 'anArgument'.
  1222         showIt := ''' , anArgument printString , '' ...''.\'.
  1222 	showIt := ''' , anArgument printString , '' ...''.\'.
  1223     ] ifFalse:[    
  1223     ] ifFalse:[
  1224         args := ''.
  1224 	args := ''.
  1225         showIt := ' ...''.\'.
  1225 	showIt := ' ...''.\'.
  1226 
  1226 
  1227         numArgs ~~ 0 ifTrue:[
  1227 	numArgs ~~ 0 ifTrue:[
  1228             method := ''.
  1228 	    method := ''.
  1229 
  1229 
  1230             selector keywords keysAndValuesDo:[:i :key|
  1230 	    selector keywords keysAndValuesDo:[:i :key|
  1231                 method := method, key, 'arg', i printString, ' '
  1231 		method := method, key, 'arg', i printString, ' '
  1232             ]
  1232 	    ]
  1233         ]
  1233 	]
  1234     ].
  1234     ].
  1235 
  1235 
  1236     code := code ,
  1236     code := code ,
  1237                 method , args , '\' ,
  1237 		method , args , '\' ,
  1238                 '    "automatically generated by UIPainter ..."\\' ,
  1238 		'    "automatically generated by UIPainter ..."\\' ,
  1239                 '    "*** the code below performs no action"\' ,
  1239 		'    "*** the code below performs no action"\' ,
  1240                 '    "*** (except for some feedback on the Transcript)"\' ,
  1240 		'    "*** (except for some feedback on the Transcript)"\' ,
  1241                 '    "*** Please change as required and accept in the browser."\' ,
  1241 		'    "*** Please change as required and accept in the browser."\' ,
  1242                 '\' .
  1242 		'\' .
  1243 
  1243 
  1244     alreadyInSuperclass ifTrue:[
  1244     alreadyInSuperclass ifTrue:[
  1245         code := code ,
  1245 	code := code ,
  1246                     '    "action for ' , selector , ' is already provided in a superclass."\' ,
  1246 		    '    "action for ' , selector , ' is already provided in a superclass."\' ,
  1247                     '    "It may be redefined here ..."\\'.
  1247 		    '    "It may be redefined here ..."\\'.
  1248     ] ifFalse:[
  1248     ] ifFalse:[
  1249         code := code ,
  1249 	code := code ,
  1250                     '    "action to be added ..."\\'.
  1250 		    '    "action to be added ..."\\'.
  1251     ].
  1251     ].
  1252 
  1252 
  1253     code := code ,
  1253     code := code ,
  1254                 '    Transcript showCR:self class name, '': '.
  1254 		'    Transcript showCR:self class name, '': '.
  1255     alreadyInSuperclass ifTrue:[
  1255     alreadyInSuperclass ifTrue:[
  1256         code := code , 'inherited '.
  1256 	code := code , 'inherited '.
  1257     ].
  1257     ].
  1258     code := code , 'menu action for ' , selector , showIt.
  1258     code := code , 'menu action for ' , selector , showIt.
  1259 
  1259 
  1260     alreadyInSuperclass ifTrue:[
  1260     alreadyInSuperclass ifTrue:[
  1261         code := code ,
  1261 	code := code ,
  1262                         '    super ' , selector , args , '.\'.
  1262 			'    super ' , selector , args , '.\'.
  1263     ].
  1263     ].
  1264 
  1264 
  1265     code := code ,
  1265     code := code ,
  1266                 '!! !!\\'.
  1266 		'!! !!\\'.
  1267     ^ code withCRs
  1267     ^ code withCRs
  1268 
  1268 
  1269     "Created: / 23.8.1998 / 16:46:51 / cg"
  1269     "Created: / 23.8.1998 / 16:46:51 / cg"
  1270     "Modified: / 23.8.1998 / 18:13:05 / cg"
  1270     "Modified: / 23.8.1998 / 18:13:05 / cg"
  1271 !
  1271 !
  1280      specArray fullSpec winSpec menuSpec
  1280      specArray fullSpec winSpec menuSpec
  1281      |
  1281      |
  1282 
  1282 
  1283     cls := self targetClass.
  1283     cls := self targetClass.
  1284     cls isNil ifTrue:[
  1284     cls isNil ifTrue:[
  1285         ^ nil
  1285 	^ nil
  1286     ].
  1286     ].
  1287 
  1287 
  1288     specArray := treeView generateFullSpecForComponents:#() named:nil.
  1288     specArray := treeView generateFullSpecForComponents:#() named:nil.
  1289     fullSpec := specArray decodeAsLiteralArray.
  1289     fullSpec := specArray decodeAsLiteralArray.
  1290     winSpec := fullSpec window.
  1290     winSpec := fullSpec window.
  1291     menuSelector := winSpec menu.
  1291     menuSelector := winSpec menu.
  1292 
  1292 
  1293     (menuSelector notNil 
  1293     (menuSelector notNil
  1294     and:[ (cls respondsTo:menuSelector) ]) ifFalse:[
  1294     and:[ (cls respondsTo:menuSelector) ]) ifFalse:[
  1295         self warn:'No menu defined (yet)'.
  1295 	self warn:'No menu defined (yet)'.
  1296         ^ nil.
  1296 	^ nil.
  1297     ].
  1297     ].
  1298     menuSpec := cls perform:menuSelector.
  1298     menuSpec := cls perform:menuSelector.
  1299     menuSpec := menuSpec decodeAsLiteralArray.
  1299     menuSpec := menuSpec decodeAsLiteralArray.
  1300 
  1300 
  1301     definedMethodSelectors := IdentitySet new.
  1301     definedMethodSelectors := IdentitySet new.
  1302     code := ''.
  1302     code := ''.
  1303 
  1303 
  1304     menuSpec allItemsDo:[:item |
  1304     menuSpec allItemsDo:[:item |
  1305         |sel|
  1305 	|sel|
  1306 
  1306 
  1307         (sel := item value) notNil ifTrue:[
  1307 	(sel := item value) notNil ifTrue:[
  1308             (definedMethodSelectors includes:sel) ifFalse:[
  1308 	    (definedMethodSelectors includes:sel) ifFalse:[
  1309                 self generateCodeFrom:(Array with:sel) in:cls do:[:aSel|
  1309 		self generateCodeFrom:(Array with:sel) in:cls do:[:aSel|
  1310                     thisCode := (self generateMenuMethodFor:aSel inClass:cls).
  1310 		    thisCode := (self generateMenuMethodFor:aSel inClass:cls).
  1311                     code := code, thisCode.
  1311 		    code := code, thisCode.
  1312                 ].
  1312 		].
  1313                 definedMethodSelectors add:sel.
  1313 		definedMethodSelectors add:sel.
  1314             ].
  1314 	    ].
  1315         ]
  1315 	]
  1316     ].
  1316     ].
  1317 
  1317 
  1318     (definedMethodSelectors includes:#menuOpen) ifTrue:[
  1318     (definedMethodSelectors includes:#menuOpen) ifTrue:[
  1319         self generateCodeFrom:(Array with:#doOpen:) in:cls do:[:aSel|
  1319 	self generateCodeFrom:(Array with:#doOpen:) in:cls do:[:aSel|
  1320             thisCode := (self generateMenuMethodFor:aSel inClass:cls).
  1320 	    thisCode := (self generateMenuMethodFor:aSel inClass:cls).
  1321             code := code, thisCode.
  1321 	    code := code, thisCode.
  1322         ].
  1322 	].
  1323     ].
  1323     ].
  1324 
  1324 
  1325     ^ code
  1325     ^ code
  1326 
  1326 
  1327     "Created: / 23.8.1998 / 16:12:09 / cg"
  1327     "Created: / 23.8.1998 / 16:12:09 / cg"
  1349     |spec str code category cls mthd specCode|
  1349     |spec str code category cls mthd specCode|
  1350 
  1350 
  1351     spec := OrderedCollection new.
  1351     spec := OrderedCollection new.
  1352 
  1352 
  1353     self subViews do:[:aView|
  1353     self subViews do:[:aView|
  1354         |vSpec|
  1354 	|vSpec|
  1355 
  1355 
  1356         "/ care for wrapped views ...
  1356 	"/ care for wrapped views ...
  1357         vSpec := self fullSpecFor:aView.
  1357 	vSpec := self fullSpecFor:aView.
  1358         vSpec isNil ifTrue:[
  1358 	vSpec isNil ifTrue:[
  1359             aView subViews size == 1 ifTrue:[
  1359 	    aView subViews size == 1 ifTrue:[
  1360                 vSpec := self fullSpecFor:(aView subViews first).
  1360 		vSpec := self fullSpecFor:(aView subViews first).
  1361             ]
  1361 	    ]
  1362         ].
  1362 	].
  1363         vSpec isNil ifTrue:[
  1363 	vSpec isNil ifTrue:[
  1364             self warn:'Oops - could not create spec for some view'
  1364 	    self warn:'Oops - could not create spec for some view'
  1365         ].
  1365 	].
  1366         spec add:vSpec
  1366 	spec add:vSpec
  1367     ].
  1367     ].
  1368 
  1368 
  1369     spec := treeView generateFullSpecForComponents:spec named:methodName.
  1369     spec := treeView generateFullSpecForComponents:spec named:methodName.
  1370     str  := WriteStream on:String new.
  1370     str  := WriteStream on:String new.
  1371     UISpecification prettyPrintSpecArray:spec on:str indent:5.
  1371     UISpecification prettyPrintSpecArray:spec on:str indent:5.
  1372     specCode := str contents.
  1372     specCode := str contents.
  1373 
  1373 
  1374     (specCode includes:$!!) ifTrue:[
  1374     (specCode includes:$!!) ifTrue:[
  1375         "/ oops - must be chunk format ...
  1375 	"/ oops - must be chunk format ...
  1376         str  := WriteStream on:String new.
  1376 	str  := WriteStream on:String new.
  1377         str nextPutAllAsChunk:specCode.
  1377 	str nextPutAllAsChunk:specCode.
  1378         specCode := str contents.
  1378 	specCode := str contents.
  1379     ].
  1379     ].
  1380 
  1380 
  1381     "/ if that method already exists, do not overwrite the category
  1381     "/ if that method already exists, do not overwrite the category
  1382 
  1382 
  1383     category := 'interface specs'.
  1383     category := 'interface specs'.
  1384     cls := self resolveName:className.
  1384     cls := self resolveName:className.
  1385 
  1385 
  1386     cls notNil ifTrue:[
  1386     cls notNil ifTrue:[
  1387         (mthd := cls class compiledMethodAt:methodName asSymbol) notNil ifTrue:[
  1387 	(mthd := cls class compiledMethodAt:methodName asSymbol) notNil ifTrue:[
  1388             category := mthd category.
  1388 	    category := mthd category.
  1389         ]
  1389 	]
  1390     ].
  1390     ].
  1391 
  1391 
  1392     code := '!!'
  1392     code := '!!'
  1393             , className , ' class methodsFor:' , category storeString
  1393 	    , className , ' class methodsFor:' , category storeString
  1394             , '!!' , '\\'
  1394 	    , '!!' , '\\'
  1395 
  1395 
  1396             , methodName , '\'
  1396 	    , methodName , '\'
  1397             , ((ResourceSpecEditor codeGenerationCommentForClass: UIPainter) replChar:$!! withString:'!!!!')
  1397 	    , ((ResourceSpecEditor codeGenerationCommentForClass: UIPainter) replChar:$!! withString:'!!!!')
  1398             , '\\    "\'
  1398 	    , '\\    "\'
  1399             , ('     UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\').
  1399 	    , ('     UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\').
  1400 
  1400 
  1401     (cls notNil and:[cls isSubclassOf:ApplicationModel]) ifTrue:[
  1401     (cls notNil and:[cls isSubclassOf:ApplicationModel]) ifTrue:[
  1402         code := code
  1402 	code := code
  1403             , ('     ' , className , ' new openInterface:#' , methodName , '\').
  1403 	    , ('     ' , className , ' new openInterface:#' , methodName , '\').
  1404     ].
  1404     ].
  1405 
  1405 
  1406     code := code
  1406     code := code
  1407             ,(methodName = 'windowSpec' 
  1407 	    ,(methodName = 'windowSpec'
  1408                 ifTrue:['     ' , className , ' open\'] ifFalse: [''])
  1408 		ifTrue:['     ' , className , ' open\'] ifFalse: [''])
  1409             , '    "\'.
  1409 	    , '    "\'.
  1410 
  1410 
  1411     code := code 
  1411     code := code
  1412             , '\'
  1412 	    , '\'
  1413             , '    <resource: #canvas>\\'
  1413 	    , '    <resource: #canvas>\\'
  1414             , '    ^ ' , specCode 
  1414 	    , '    ^ ' , specCode
  1415             , '\'
  1415 	    , '\'
  1416             , '!! !!'
  1416 	    , '!! !!'
  1417             , '\\'.
  1417 	    , '\\'.
  1418 
  1418 
  1419     ^ code withCRs
  1419     ^ code withCRs
  1420 
  1420 
  1421     "Modified: / 5.9.1995 / 21:01:35 / claus"
  1421     "Modified: / 5.9.1995 / 21:01:35 / claus"
  1422     "Modified: / 15.10.1998 / 11:29:53 / cg"
  1422     "Modified: / 15.10.1998 / 11:29:53 / cg"
  1424 
  1424 
  1425 targetClass
  1425 targetClass
  1426     |cls|
  1426     |cls|
  1427 
  1427 
  1428     className isNil ifTrue:[
  1428     className isNil ifTrue:[
  1429         self warn:'No TargetClass defined !!'.
  1429 	self warn:'No TargetClass defined !!'.
  1430         ^ nil
  1430 	^ nil
  1431     ].
  1431     ].
  1432     (cls := self resolveName:className) isNil ifTrue:[
  1432     (cls := self resolveName:className) isNil ifTrue:[
  1433         self warn:('Class ', className asString, ' does not exist !!').
  1433 	self warn:('Class ', className asString, ' does not exist !!').
  1434         ^ nil
  1434 	^ nil
  1435     ].
  1435     ].
  1436     ^ cls.
  1436     ^ cls.
  1437 ! !
  1437 ! !
  1438 
  1438 
  1439 !UIPainterView methodsFor:'grid manipulation'!
  1439 !UIPainterView methodsFor:'grid manipulation'!
  1447 
  1447 
  1448     gridPixmap := nil.
  1448     gridPixmap := nil.
  1449     defaultViewBackground := self class defaultViewBackgroundColor.
  1449     defaultViewBackground := self class defaultViewBackgroundColor.
  1450 
  1450 
  1451     shown ifTrue:[
  1451     shown ifTrue:[
  1452         self viewBackground: (defaultViewBackground isColor
  1452 	self viewBackground: (defaultViewBackground isColor
  1453             ifTrue: [defaultViewBackground]
  1453 	    ifTrue: [defaultViewBackground]
  1454             ifFalse:[Black]).
  1454 	    ifFalse:[Black]).
  1455         self clear.
  1455 	self clear.
  1456     ].
  1456     ].
  1457 
  1457 
  1458     gridShown ifTrue:[
  1458     gridShown ifTrue:[
  1459         self defineGrid.
  1459 	self defineGrid.
  1460         gridPixmap colorMap: (defaultViewBackground isColor
  1460 	gridPixmap colorMap: (defaultViewBackground isColor
  1461             ifTrue: [Array with:defaultViewBackground with:Color darkGray]
  1461 	    ifTrue: [Array with:defaultViewBackground with:Color darkGray]
  1462             ifFalse:[Array with:White with:Black]).
  1462 	    ifFalse:[Array with:White with:Black]).
  1463         self viewBackground:gridPixmap.
  1463 	self viewBackground:gridPixmap.
  1464     ].
  1464     ].
  1465 
  1465 
  1466     self invalidate
  1466     self invalidate
  1467 
  1467 
  1468 ! !
  1468 ! !
  1492     (MenuPanel menu: menu) startUp.
  1492     (MenuPanel menu: menu) startUp.
  1493     canvas := self painter.
  1493     canvas := self painter.
  1494     cS := canvas getSelectedViewsAndSpecs.
  1494     cS := canvas getSelectedViewsAndSpecs.
  1495     cS isNil ifTrue:[^self].
  1495     cS isNil ifTrue:[^self].
  1496     views := cS first.
  1496     views := cS first.
  1497     specs := cS last. 
  1497     specs := cS last.
  1498     rect := views first frame.
  1498     rect := views first frame.
  1499     2 to: views size do:[:i| rect := rect merge: (views at: i) frame].
  1499     2 to: views size do:[:i| rect := rect merge: (views at: i) frame].
  1500     layout := LayoutFrame leftFraction:0.0 offset: rect origin x 
  1500     layout := LayoutFrame leftFraction:0.0 offset: rect origin x
  1501                          rightFraction:0.0 offset: rect corner x + 1 
  1501 			 rightFraction:0.0 offset: rect corner x + 1
  1502                            topFraction:0.0 offset: rect origin y 
  1502 			   topFraction:0.0 offset: rect origin y
  1503                         bottomFraction:0.0 offset:rect corner y + 1.
  1503 			bottomFraction:0.0 offset:rect corner y + 1.
  1504     oldSelection := canvas selection.
  1504     oldSelection := canvas selection.
  1505     canvas select: views first superView.
  1505     canvas select: views first superView.
  1506     spec layout: layout.
  1506     spec layout: layout.
  1507     spec class == VerticalPanelViewSpec ifTrue:[
  1507     spec class == VerticalPanelViewSpec ifTrue:[
  1508         spec verticalLayout: #topSpace.
  1508 	spec verticalLayout: #topSpace.
  1509         spec horizontalLayout: #fit.
  1509 	spec horizontalLayout: #fit.
  1510     ].
  1510     ].
  1511     spec class == HorizontalPanelViewSpec ifTrue:[
  1511     spec class == HorizontalPanelViewSpec ifTrue:[
  1512         spec verticalLayout: #fit.
  1512 	spec verticalLayout: #fit.
  1513         spec horizontalLayout: #leftSpace.
  1513 	spec horizontalLayout: #leftSpace.
  1514     ].
  1514     ].
  1515 
  1515 
  1516     box := self pasteSpecifications:spec keepLayout:true at:nil.
  1516     box := self pasteSpecifications:spec keepLayout:true at:nil.
  1517 
  1517 
  1518     xOffset := box origin x.
  1518     xOffset := box origin x.
  1519     yOffset := box origin y.
  1519     yOffset := box origin y.
  1520     withLayout ifFalse:[
  1520     withLayout ifFalse:[
  1521         1 to: specs size do:[:i|
  1521 	1 to: specs size do:[:i|
  1522             view := views at: i.
  1522 	    view := views at: i.
  1523             layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x - xOffset)
  1523 	    layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x - xOffset)
  1524                                   rightFraction:0.0 offset: (view corner x - xOffset + 1)
  1524 				  rightFraction:0.0 offset: (view corner x - xOffset + 1)
  1525                                     topFraction:0.0 offset: (view origin y - yOffset )
  1525 				    topFraction:0.0 offset: (view origin y - yOffset )
  1526                                  bottomFraction:0.0 offset: (view corner y - yOffset + 1).
  1526 				 bottomFraction:0.0 offset: (view corner y - yOffset + 1).
  1527             (specs at: i) layout: layout.
  1527 	    (specs at: i) layout: layout.
  1528         ].
  1528 	].
  1529     ]. 
  1529     ].
  1530     canvas selection: oldSelection.
  1530     canvas selection: oldSelection.
  1531     canvas deleteSelection.
  1531     canvas deleteSelection.
  1532     canvas selection:box.
  1532     canvas selection:box.
  1533     nViews := canvas pasteSpecifications:specs keepLayout:true.
  1533     nViews := canvas pasteSpecifications:specs keepLayout:true.
  1534     canvas selection: box.
  1534     canvas selection: box.
  1553     cS isNil ifTrue:[^self].
  1553     cS isNil ifTrue:[^self].
  1554     views := cS first first subViews copy.
  1554     views := cS first first subViews copy.
  1555     superView := cS first first superView.
  1555     superView := cS first first superView.
  1556     cS last first component isNil ifTrue:[^self].
  1556     cS last first component isNil ifTrue:[^self].
  1557     cS last first component collection isEmpty ifTrue:[^self].
  1557     cS last first component collection isEmpty ifTrue:[^self].
  1558     specs := cS last first component collection copy. 
  1558     specs := cS last first component collection copy.
  1559     frame := cS first first frame.
  1559     frame := cS first first frame.
  1560     canvas deleteSelection.
  1560     canvas deleteSelection.
  1561     withLayout ifFalse:[
  1561     withLayout ifFalse:[
  1562         1 to: specs size do:[:i|
  1562 	1 to: specs size do:[:i|
  1563             view := views at: i.
  1563 	    view := views at: i.
  1564             layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x + frame origin x)
  1564 	    layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x + frame origin x)
  1565                                   rightFraction:0.0 offset: (view corner x + frame origin x + 1)
  1565 				  rightFraction:0.0 offset: (view corner x + frame origin x + 1)
  1566                                     topFraction:0.0 offset: (view origin y + frame origin y )
  1566 				    topFraction:0.0 offset: (view origin y + frame origin y )
  1567                                  bottomFraction:0.0 offset: (view corner y + frame origin y + 1).
  1567 				 bottomFraction:0.0 offset: (view corner y + frame origin y + 1).
  1568             (specs at: i) layout: layout.
  1568 	    (specs at: i) layout: layout.
  1569         ].
  1569 	].
  1570     ]. 
  1570     ].
  1571     canvas selection: superView.
  1571     canvas selection: superView.
  1572     canvas pasteSpecifications:specs keepLayout:true.
  1572     canvas pasteSpecifications:specs keepLayout:true.
  1573     canvas selection: superView.
  1573     canvas selection: superView.
  1574 !
  1574 !
  1575 
  1575 
  1609 setupFromSpec:specOrSpecArray
  1609 setupFromSpec:specOrSpecArray
  1610 
  1610 
  1611     |spec builder|
  1611     |spec builder|
  1612 
  1612 
  1613     Cursor wait showWhile: [
  1613     Cursor wait showWhile: [
  1614         self removeAll.
  1614 	self removeAll.
  1615         specOrSpecArray notNil ifTrue:[
  1615 	specOrSpecArray notNil ifTrue:[
  1616             spec    := UISpecification from:specOrSpecArray.
  1616 	    spec    := UISpecification from:specOrSpecArray.
  1617         ].
  1617 	].
  1618         builder := UIBuilder new isEditing:true.
  1618 	builder := UIBuilder new isEditing:true.
  1619         "set applicationClass, in order that subspecifications may be resolved"
  1619 	"set applicationClass, in order that subspecifications may be resolved"
  1620         className notNil ifTrue:[
  1620 	className notNil ifTrue:[
  1621             builder applicationClass:(self resolveName:className).
  1621 	    builder applicationClass:(self resolveName:className).
  1622         ].
  1622 	].
  1623         spec notNil ifTrue:[
  1623 	spec notNil ifTrue:[
  1624             spec window setupView:self topView for:builder.
  1624 	    spec window setupView:self topView for:builder.
  1625             self addSpec:(spec component) builder:builder in:self.
  1625 	    self addSpec:(spec component) builder:builder in:self.
  1626         ].
  1626 	].
  1627         self realizeAllSubViews.
  1627 	self realizeAllSubViews.
  1628         spec notNil ifTrue:[
  1628 	spec notNil ifTrue:[
  1629             treeView setAttributesFromWindowSpec:(spec window)
  1629 	    treeView setAttributesFromWindowSpec:(spec window)
  1630         ].
  1630 	].
  1631     ].
  1631     ].
  1632 !
  1632 !
  1633 
  1633 
  1634 treeView:aTreeView
  1634 treeView:aTreeView
  1635     treeView := aTreeView.
  1635     treeView := aTreeView.
  1636 
  1636 
  1637     treeView delegate:(
  1637     treeView delegate:(
  1638         "/
  1638 	"/
  1639         "/ I want to handle everything typed
  1639 	"/ I want to handle everything typed
  1640         "/ in the treeView, except for Return and Cursor-keys
  1640 	"/ in the treeView, except for Return and Cursor-keys
  1641         "/
  1641 	"/
  1642         KeyboardForwarder 
  1642 	KeyboardForwarder
  1643             toView:self
  1643 	    toView:self
  1644             condition:nil
  1644 	    condition:nil
  1645             filter:[:k | (k isSymbol 
  1645 	    filter:[:k | (k isSymbol
  1646                          and:[k ~~ #Return 
  1646 			 and:[k ~~ #Return
  1647                          and:[k ~~ #Tab 
  1647 			 and:[k ~~ #Tab
  1648                          and:[(k startsWith:#Cursor) not]]])
  1648 			 and:[(k startsWith:#Cursor) not]]])
  1649                    ]
  1649 		   ]
  1650     )
  1650     )
  1651 
  1651 
  1652     "Modified: / 31.10.1997 / 20:22:09 / cg"
  1652     "Modified: / 31.10.1997 / 20:22:09 / cg"
  1653 ! !
  1653 ! !
  1654 
  1654 
  1659     "
  1659     "
  1660 
  1660 
  1661     |m|
  1661     |m|
  1662 
  1662 
  1663     self enabled ifTrue:[
  1663     self enabled ifTrue:[
  1664         m := MenuPanel fromSpec:(UIPainter menuEdit) receiver:self superView application.
  1664 	m := MenuPanel fromSpec:(UIPainter menuEdit) receiver:self superView application.
  1665         self startUpMenu:m
  1665 	self startUpMenu:m
  1666     ].
  1666     ].
  1667   ^ nil
  1667   ^ nil
  1668 ! !
  1668 ! !
  1669 
  1669 
  1670 !UIPainterView methodsFor:'private-handles'!
  1670 !UIPainterView methodsFor:'private-handles'!
  1677     "show object selected
  1677     "show object selected
  1678     "
  1678     "
  1679     |wasClipped sel hColor bg|
  1679     |wasClipped sel hColor bg|
  1680 
  1680 
  1681     selectionHiddenLevel == 0 ifTrue:[
  1681     selectionHiddenLevel == 0 ifTrue:[
  1682         sel := treeView selection.
  1682 	sel := treeView selection.
  1683         (sel size > 1 and: 
  1683 	(sel size > 1 and:
  1684         [(treeView model list at: sel first) contents view == aComponent])
  1684 	[(treeView model list at: sel first) contents view == aComponent])
  1685         ifTrue: [
  1685 	ifTrue: [
  1686             hColor := handleMasterColor
  1686 	    hColor := handleMasterColor
  1687         ] ifFalse:[
  1687 	] ifFalse:[
  1688             bg := aComponent viewBackground.
  1688 	    bg := aComponent viewBackground.
  1689             bg isColor ifTrue:[
  1689 	    bg isColor ifTrue:[
  1690                 bg brightness < 0.5 ifTrue:[
  1690 		bg brightness < 0.5 ifTrue:[
  1691                     hColor := handleColorWhite
  1691 		    hColor := handleColorWhite
  1692                 ] ifFalse:[
  1692 		] ifFalse:[
  1693                     hColor := handleColorBlack
  1693 		    hColor := handleColorBlack
  1694                 ]
  1694 		]
  1695             ] ifFalse:[
  1695 	    ] ifFalse:[
  1696                 hColor := handleColorBlack
  1696 		hColor := handleColorBlack
  1697             ]
  1697 	    ]
  1698         ].
  1698 	].
  1699 
  1699 
  1700         self paint:hColor.
  1700 	self paint:hColor.
  1701 
  1701 
  1702         (wasClipped := clipChildren) ifTrue:[
  1702 	(wasClipped := clipChildren) ifTrue:[
  1703             self clippedByChildren:(clipChildren := false). 
  1703 	    self clippedByChildren:(clipChildren := false).
  1704         ].
  1704 	].
  1705 
  1705 
  1706         self handlesOf:aComponent do:[:aRectangle :what| |l t w h|
  1706 	self handlesOf:aComponent do:[:aRectangle :what| |l t w h|
  1707             l := aRectangle left   + 1.
  1707 	    l := aRectangle left   + 1.
  1708             t := aRectangle top    + 1.
  1708 	    t := aRectangle top    + 1.
  1709             w := aRectangle width  - 2.
  1709 	    w := aRectangle width  - 2.
  1710             h := aRectangle height - 2.
  1710 	    h := aRectangle height - 2.
  1711 
  1711 
  1712             what == #view ifTrue:[self displayRectangleX:l y:t width:w height:h]
  1712 	    what == #view ifTrue:[self displayRectangleX:l y:t width:w height:h]
  1713                          ifFalse:[self fillRectangleX:l y:t width:w height:h]
  1713 			 ifFalse:[self fillRectangleX:l y:t width:w height:h]
  1714         ].
  1714 	].
  1715 
  1715 
  1716         wasClipped ifTrue:[
  1716 	wasClipped ifTrue:[
  1717             self clippedByChildren:(clipChildren := true).
  1717 	    self clippedByChildren:(clipChildren := true).
  1718         ]
  1718 	]
  1719     ]
  1719     ]
  1720 
  1720 
  1721     "Modified: / 6.12.2001 / 00:00:16 / cg"
  1721     "Modified: / 6.12.2001 / 00:00:16 / cg"
  1722 ! !
  1722 ! !
  1723 
  1723 
  1727     |appl|
  1727     |appl|
  1728 
  1728 
  1729     appl := self application.
  1729     appl := self application.
  1730 
  1730 
  1731     appl notNil ifTrue:[
  1731     appl notNil ifTrue:[
  1732         ^ appl resolveName:aName
  1732 	^ appl resolveName:aName
  1733     ].
  1733     ].
  1734     ^ Smalltalk resolveName:aName inClass:self class
  1734     ^ Smalltalk resolveName:aName inClass:self class
  1735 ! !
  1735 ! !
  1736 
  1736 
  1737 !UIPainterView methodsFor:'removing components'!
  1737 !UIPainterView methodsFor:'removing components'!
  1738 
  1738 
  1739 remove:anObject
  1739 remove:anObject
  1740     "remove anObject from the contents do redraw
  1740     "remove anObject from the contents do redraw
  1741     "
  1741     "
  1742     anObject notNil ifTrue:[
  1742     anObject notNil ifTrue:[
  1743         treeView removeView:anObject.
  1743 	treeView removeView:anObject.
  1744     ]
  1744     ]
  1745 !
  1745 !
  1746 
  1746 
  1747 removeAll
  1747 removeAll
  1748     "remove all objects and properties
  1748     "remove all objects and properties
  1758     "returns the super view assigned to a view
  1758     "returns the super view assigned to a view
  1759     "
  1759     "
  1760     |p|
  1760     |p|
  1761 
  1761 
  1762     (p := self propertyOfParentForView:aView) isNil ifTrue:[
  1762     (p := self propertyOfParentForView:aView) isNil ifTrue:[
  1763         ^ self
  1763 	^ self
  1764     ].
  1764     ].
  1765     ^ p view
  1765     ^ p view
  1766 !
  1766 !
  1767 
  1767 
  1768 findObjectAt:aPoint
  1768 findObjectAt:aPoint
  1783     |prop|
  1783     |prop|
  1784 
  1784 
  1785     prop := self propertyOfIdentifier:aViewId.
  1785     prop := self propertyOfIdentifier:aViewId.
  1786 
  1786 
  1787     prop notNil ifTrue:[^ prop view]
  1787     prop notNil ifTrue:[^ prop view]
  1788                ifFalse:[^ nil]
  1788 	       ifFalse:[^ nil]
  1789 !
  1789 !
  1790 
  1790 
  1791 propertyOfIdentifier:anId
  1791 propertyOfIdentifier:anId
  1792     "returns property assigned to unique identifier
  1792     "returns property assigned to unique identifier
  1793     "
  1793     "
  1794     anId notNil ifTrue:[
  1794     anId notNil ifTrue:[
  1795         ^ treeView propertyDetect:[:p| p identifier == anId ]
  1795 	^ treeView propertyDetect:[:p| p identifier == anId ]
  1796     ].
  1796     ].
  1797     ^ nil
  1797     ^ nil
  1798 !
  1798 !
  1799 
  1799 
  1800 propertyOfName:aString
  1800 propertyOfName:aString
  1801     "returns property assigned to name
  1801     "returns property assigned to name
  1802     "
  1802     "
  1803     |name|
  1803     |name|
  1804 
  1804 
  1805     aString isNil ifFalse:[
  1805     aString isNil ifFalse:[
  1806         name := aString string withoutSeparators.
  1806 	name := aString string withoutSeparators.
  1807       ^ treeView propertyDetect:[:p| p name = name ].
  1807       ^ treeView propertyDetect:[:p| p name = name ].
  1808     ].
  1808     ].
  1809     ^ nil
  1809     ^ nil
  1810 !
  1810 !
  1811 
  1811 
  1813     "returns the property of the parent or nil
  1813     "returns the property of the parent or nil
  1814     "
  1814     "
  1815     |item|
  1815     |item|
  1816 
  1816 
  1817     (item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[
  1817     (item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[
  1818         (item := item parent) notNil ifTrue:[^ item contents]
  1818 	(item := item parent) notNil ifTrue:[^ item contents]
  1819     ].
  1819     ].
  1820     ^ nil
  1820     ^ nil
  1821 !
  1821 !
  1822 
  1822 
  1823 propertyOfView:aView
  1823 propertyOfView:aView
  1824     "returns property assigned to view
  1824     "returns property assigned to view
  1825     "
  1825     "
  1826     (aView isNil or:[aView == self]) ifFalse:[
  1826     (aView isNil or:[aView == self]) ifFalse:[
  1827         ^ treeView propertyDetect:[:p| p view == aView ]
  1827 	^ treeView propertyDetect:[:p| p view == aView ]
  1828     ].
  1828     ].
  1829     ^ nil
  1829     ^ nil
  1830 !
  1830 !
  1831 
  1831 
  1832 propertyRespondsToView:aView
  1832 propertyRespondsToView:aView
  1837     |item|
  1837     |item|
  1838 
  1838 
  1839     item := treeView detectItemRespondsToView:aView.
  1839     item := treeView detectItemRespondsToView:aView.
  1840 
  1840 
  1841     (item notNil and:[item parent notNil]) ifTrue:[
  1841     (item notNil and:[item parent notNil]) ifTrue:[
  1842         ^ item contents
  1842 	^ item contents
  1843     ].
  1843     ].
  1844     ^ nil
  1844     ^ nil
  1845 !
  1845 !
  1846 
  1846 
  1847 uniqueNameFor:aSpecOrString
  1847 uniqueNameFor:aSpecOrString
  1848     "generate and return an unique name for a class
  1848     "generate and return an unique name for a class
  1849     "
  1849     "
  1850     |next name size|
  1850     |next name size|
  1851 
  1851 
  1852     aSpecOrString isString ifFalse:[name := aSpecOrString userFriendlyName]
  1852     aSpecOrString isString ifFalse:[name := aSpecOrString userFriendlyName]
  1853                             ifTrue:[name := aSpecOrString].
  1853 			    ifTrue:[name := aSpecOrString].
  1854 
  1854 
  1855     size  := name size + 1.
  1855     size  := name size + 1.
  1856     next  := 0.
  1856     next  := 0.
  1857 
  1857 
  1858     treeView propertiesDo:[:p|
  1858     treeView propertiesDo:[:p|
  1859         |n|
  1859 	|n|
  1860         n := p name.
  1860 	n := p name.
  1861 
  1861 
  1862         (n size >= size and:[n startsWith:name]) ifTrue:[
  1862 	(n size >= size and:[n startsWith:name]) ifTrue:[
  1863             next := next max:(p extractNumberStartingAt:size)
  1863 	    next := next max:(p extractNumberStartingAt:size)
  1864         ]
  1864 	]
  1865     ].
  1865     ].
  1866     next := next + 1.
  1866     next := next + 1.
  1867     name := name, next printString.
  1867     name := name, next printString.
  1868   ^ name
  1868   ^ name
  1869 
  1869 
  1874 
  1874 
  1875 uniqueNameOf:aView
  1875 uniqueNameOf:aView
  1876     |prop|
  1876     |prop|
  1877 
  1877 
  1878     (prop := self propertyOfView:aView) notNil ifTrue:[
  1878     (prop := self propertyOfView:aView) notNil ifTrue:[
  1879         prop name isNil ifTrue:[
  1879 	prop name isNil ifTrue:[
  1880             prop name:(self uniqueNameFor:(prop spec)).
  1880 	    prop name:(self uniqueNameFor:(prop spec)).
  1881         ].
  1881 	].
  1882         ^ prop name
  1882 	^ prop name
  1883     ].
  1883     ].
  1884     ^ 'self'
  1884     ^ 'self'
  1885 
  1885 
  1886 ! !
  1886 ! !
  1887 
  1887 
  1889 
  1889 
  1890 addToSelection:anObject
  1890 addToSelection:anObject
  1891     "add an object to the selection
  1891     "add an object to the selection
  1892     "
  1892     "
  1893     (self enabled and:[(self isSelected:anObject) not]) ifTrue:[
  1893     (self enabled and:[(self isSelected:anObject) not]) ifTrue:[
  1894         selection isCollection ifFalse:[
  1894 	selection isCollection ifFalse:[
  1895             selection isNil ifTrue:[
  1895 	    selection isNil ifTrue:[
  1896                 selection := anObject
  1896 		selection := anObject
  1897             ] ifFalse:[
  1897 	    ] ifFalse:[
  1898                 selection := OrderedCollection with:selection with:anObject
  1898 		selection := OrderedCollection with:selection with:anObject
  1899             ]
  1899 	    ]
  1900         ] ifTrue:[
  1900 	] ifTrue:[
  1901             "/ to enforce the change-message (value is identical to oldValue)
  1901 	    "/ to enforce the change-message (value is identical to oldValue)
  1902             selection isList ifTrue:[
  1902 	    selection isList ifTrue:[
  1903                 selection add:anObject
  1903 		selection add:anObject
  1904             ] ifFalse:[
  1904 	    ] ifFalse:[
  1905                 selection := selection asOrderedCollection.
  1905 		selection := selection asOrderedCollection.
  1906                 selection := selection copyWith:anObject
  1906 		selection := selection copyWith:anObject
  1907             ]
  1907 	    ]
  1908         ].
  1908 	].
  1909         self showSelected:anObject.
  1909 	self showSelected:anObject.
  1910         treeView cvsSelectionAdd:anObject.
  1910 	treeView cvsSelectionAdd:anObject.
  1911     ]
  1911     ]
  1912 
  1912 
  1913     "Modified: / 11.2.2000 / 01:39:05 / cg"
  1913     "Modified: / 11.2.2000 / 01:39:05 / cg"
  1914 !
  1914 !
  1915 
  1915 
  1916 removeFromSelection:anObject
  1916 removeFromSelection:anObject
  1917     "remove an object from the selection
  1917     "remove an object from the selection
  1918     "
  1918     "
  1919     (self isSelected:anObject) ifTrue:[
  1919     (self isSelected:anObject) ifTrue:[
  1920         self showUnselected:anObject.
  1920 	self showUnselected:anObject.
  1921 
  1921 
  1922         selection size > 1 ifTrue:[
  1922 	selection size > 1 ifTrue:[
  1923             selection isList ifTrue:[
  1923 	    selection isList ifTrue:[
  1924                 selection remove:anObject ifAbsent:nil
  1924 		selection remove:anObject ifAbsent:nil
  1925             ] ifFalse:[
  1925 	    ] ifFalse:[
  1926                 "/ to enforce the change-message (value is identical to oldValue)
  1926 		"/ to enforce the change-message (value is identical to oldValue)
  1927                 selection := selection asOrderedCollection.
  1927 		selection := selection asOrderedCollection.
  1928                 selection := selection copyWithout:anObject
  1928 		selection := selection copyWithout:anObject
  1929             ].
  1929 	    ].
  1930             self showSelection.
  1930 	    self showSelection.
  1931         ] ifFalse:[
  1931 	] ifFalse:[
  1932             selection := nil
  1932 	    selection := nil
  1933         ].
  1933 	].
  1934         treeView cvsSelectionRemove:anObject.
  1934 	treeView cvsSelectionRemove:anObject.
  1935     ]
  1935     ]
  1936 
  1936 
  1937     "Modified: / 11.2.2000 / 01:41:11 / cg"
  1937     "Modified: / 11.2.2000 / 01:41:11 / cg"
  1938 !
  1938 !
  1939 
  1939 
  1940 select:something
  1940 select:something
  1941     "change selection to something
  1941     "change selection to something
  1942     "         
  1942     "
  1943     (self enabled and:[something ~= self selection]) ifTrue:[   
  1943     (self enabled and:[something ~= self selection]) ifTrue:[
  1944         something isNil 
  1944 	something isNil
  1945             ifTrue: [treeView selection: (Array with: 1)]
  1945 	    ifTrue: [treeView selection: (Array with: 1)]
  1946             ifFalse:[treeView cvsSelection:something].
  1946 	    ifFalse:[treeView cvsSelection:something].
  1947         self setSelection:something withRedraw:true 
  1947 	self setSelection:something withRedraw:true
  1948     ]
  1948     ]
  1949 
  1949 
  1950 !
  1950 !
  1951 
  1951 
  1952 selectNextUpInHierarchy
  1952 selectNextUpInHierarchy
  1953     | sel |
  1953     | sel |
  1954 
  1954 
  1955     (sel := self selection) isNil ifTrue:[^self].
  1955     (sel := self selection) isNil ifTrue:[^self].
  1956     sel isCollection ifTrue:[
  1956     sel isCollection ifTrue:[
  1957         sel := self selection first.
  1957 	sel := self selection first.
  1958     ].
  1958     ].
  1959     sel := sel superView.
  1959     sel := sel superView.
  1960     sel isNil ifTrue:[^self].
  1960     sel isNil ifTrue:[^self].
  1961     treeView cvsSelection: sel.
  1961     treeView cvsSelection: sel.
  1962     self selection: sel.
  1962     self selection: sel.
  1966     "update selection from a new selection
  1966     "update selection from a new selection
  1967     "
  1967     "
  1968     |list|
  1968     |list|
  1969 
  1969 
  1970     selectionHiddenLevel == 0 ifTrue:[
  1970     selectionHiddenLevel == 0 ifTrue:[
  1971         aSelOrNil size ~~ 0 ifTrue:[
  1971 	aSelOrNil size ~~ 0 ifTrue:[
  1972             list := OrderedCollection new.
  1972 	    list := OrderedCollection new.
  1973 
  1973 
  1974             self selectionDo:[:el|
  1974 	    self selectionDo:[:el|
  1975                 (aSelOrNil includes:el) ifFalse:[list add:el]
  1975 		(aSelOrNil includes:el) ifFalse:[list add:el]
  1976             ].
  1976 	    ].
  1977             self showUnselected:list.
  1977 	    self showUnselected:list.
  1978         ] ifFalse:[
  1978 	] ifFalse:[
  1979             self hideSelection.
  1979 	    self hideSelection.
  1980         ]
  1980 	]
  1981     ].
  1981     ].
  1982     self setSelection:aSelOrNil withRedraw:false.
  1982     self setSelection:aSelOrNil withRedraw:false.
  1983     self showSelection
  1983     self showSelection
  1984 ! !
  1984 ! !
  1985 
  1985 
  1992     |cls|
  1992     |cls|
  1993 
  1993 
  1994     cls := self resolveName:className.
  1994     cls := self resolveName:className.
  1995 
  1995 
  1996     cls notNil ifTrue:[
  1996     cls notNil ifTrue:[
  1997         aBuilder applicationClass:cls.
  1997 	aBuilder applicationClass:cls.
  1998     ].
  1998     ].
  1999 
  1999 
  2000     aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n|
  2000     aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n|
  2001         p := ViewProperty new.
  2001 	p := ViewProperty new.
  2002         s := aSpec copy.
  2002 	s := aSpec copy.
  2003         p spec:s.
  2003 	p spec:s.
  2004         p view:aView.
  2004 	p view:aView.
  2005 
  2005 
  2006         s class supportsSubComponents ifTrue:[
  2006 	s class supportsSubComponents ifTrue:[
  2007             s component:nil
  2007 	    s component:nil
  2008         ].
  2008 	].
  2009 
  2009 
  2010         n := s name.
  2010 	n := s name.
  2011 
  2011 
  2012         (n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[
  2012 	(n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[
  2013             s name:(self uniqueNameFor:s)
  2013 	    s name:(self uniqueNameFor:s)
  2014         ].
  2014 	].
  2015         treeView addProperty:p.
  2015 	treeView addProperty:p.
  2016     ].
  2016     ].
  2017     ^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame.
  2017     ^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame.
  2018 
  2018 
  2019     "Modified: 4.7.1997 / 23:48:55 / cg"
  2019     "Modified: 4.7.1997 / 23:48:55 / cg"
  2020 !
  2020 !
  2025     |mySpec subSpecs|
  2025     |mySpec subSpecs|
  2026 
  2026 
  2027     mySpec := self specFor:anObject.
  2027     mySpec := self specFor:anObject.
  2028 
  2028 
  2029     (mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[
  2029     (mySpec notNil and:[mySpec class supportsSubComponents]) ifTrue:[
  2030         (anObject subViews notNil) ifTrue:[
  2030 	(anObject subViews notNil) ifTrue:[
  2031             anObject subViews do:[:aSubView||spec|
  2031 	    anObject subViews do:[:aSubView||spec|
  2032                 spec := self fullSpecFor:aSubView.
  2032 		spec := self fullSpecFor:aSubView.
  2033                 spec notNil ifTrue:[
  2033 		spec notNil ifTrue:[
  2034                     subSpecs isNil ifTrue:[
  2034 		    subSpecs isNil ifTrue:[
  2035                         subSpecs := OrderedCollection new
  2035 			subSpecs := OrderedCollection new
  2036                     ].
  2036 		    ].
  2037                     subSpecs add:spec.
  2037 		    subSpecs add:spec.
  2038                 ].
  2038 		].
  2039             ].
  2039 	    ].
  2040             subSpecs notNil ifTrue:[
  2040 	    subSpecs notNil ifTrue:[
  2041                 mySpec component:(SpecCollection new collection:subSpecs)
  2041 		mySpec component:(SpecCollection new collection:subSpecs)
  2042             ]
  2042 	    ]
  2043         ]
  2043 	]
  2044     ].
  2044     ].
  2045     ^ mySpec
  2045     ^ mySpec
  2046 
  2046 
  2047 
  2047 
  2048 
  2048 
  2053 
  2053 
  2054 rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil
  2054 rebuildView:aView fromSpec:aSpec withBuilder:aBuilderOrNil
  2055     |v builder|
  2055     |v builder|
  2056 
  2056 
  2057     (builder := aBuilderOrNil) isNil ifTrue:[
  2057     (builder := aBuilderOrNil) isNil ifTrue:[
  2058         "/ create a dummy builder
  2058 	"/ create a dummy builder
  2059         builder := UIBuilder new isEditing:true.
  2059 	builder := UIBuilder new isEditing:true.
  2060         className notNil ifTrue:[
  2060 	className notNil ifTrue:[
  2061             builder applicationClass:(self resolveName:className).
  2061 	    builder applicationClass:(self resolveName:className).
  2062         ].
  2062 	].
  2063     ].
  2063     ].
  2064 
  2064 
  2065     aSpec class isLayoutContainer ifTrue:[
  2065     aSpec class isLayoutContainer ifTrue:[
  2066         "/ TODO:
  2066 	"/ TODO:
  2067         "/ go through subviews and let them resize to their default/preferred
  2067 	"/ go through subviews and let them resize to their default/preferred
  2068         "/ needed if we change a containers layout from fit to non-fit.
  2068 	"/ needed if we change a containers layout from fit to non-fit.
  2069 
  2069 
  2070         (aView subViews ? #()) do:[:aSubView |
  2070 	(aView subViews ? #()) do:[:aSubView |
  2071             |fix spec prop|
  2071 	    |fix spec prop|
  2072 
  2072 
  2073             (prop := self propertyOfView:aSubView) notNil ifTrue:[
  2073 	    (prop := self propertyOfView:aSubView) notNil ifTrue:[
  2074                 spec := prop spec.
  2074 		spec := prop spec.
  2075 
  2075 
  2076                 spec useDefaultExtent ifTrue:[
  2076 		spec useDefaultExtent ifTrue:[
  2077                     fix := aSubView sizeFixed:false.
  2077 		    fix := aSubView sizeFixed:false.
  2078                     aSubView extent:aSubView preferredExtent.
  2078 		    aSubView extent:aSubView preferredExtent.
  2079                     aSubView sizeFixed:fix
  2079 		    aSubView sizeFixed:fix
  2080                 ]
  2080 		]
  2081             ]
  2081 	    ]
  2082         ].
  2082 	].
  2083     ].
  2083     ].
  2084 
  2084 
  2085     aSpec needsRebuildForAttributes ifTrue:[
  2085     aSpec needsRebuildForAttributes ifTrue:[
  2086         "/ needs a full rebuild (in case view class depends upon spec-attribute)
  2086 	"/ needs a full rebuild (in case view class depends upon spec-attribute)
  2087         v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView).
  2087 	v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView).
  2088         v realize.    
  2088 	v realize.
  2089         aView destroy.
  2089 	aView destroy.
  2090         device sync.
  2090 	device sync.
  2091         device flush.
  2091 	device flush.
  2092         aView becomeSameAs:v.
  2092 	aView becomeSameAs:v.
  2093         inputView raise.
  2093 	"/ inputView raise.
  2094     ] ifFalse:[
  2094     ] ifFalse:[
  2095         aSpec setAttributesIn:aView with:builder.
  2095 	aSpec setAttributesIn:aView with:builder.
  2096         self elementChangedSize:aView.
  2096 	self elementChangedSize:aView.
  2097     ].
  2097     ].
  2098 
  2098 
  2099 !
  2099 !
  2100 
  2100 
  2101 specFor:anObject
  2101 specFor:anObject
  2121     "update current selected view from specification
  2121     "update current selected view from specification
  2122     "
  2122     "
  2123     |props name|
  2123     |props name|
  2124 
  2124 
  2125     aSpec class == WindowSpec ifTrue:[
  2125     aSpec class == WindowSpec ifTrue:[
  2126          ^ treeView canvasSpec:aSpec
  2126 	 ^ treeView canvasSpec:aSpec
  2127     ].
  2127     ].
  2128 
  2128 
  2129     self singleSelection notNil ifTrue:[
  2129     self singleSelection notNil ifTrue:[
  2130         self withSelectionHiddenDo:[
  2130 	self withSelectionHiddenDo:[
  2131             self transaction:#specification selectionDo:[:aView|
  2131 	    self transaction:#specification selectionDo:[:aView|
  2132                 props   := self propertyOfView:aView.
  2132 		props   := self propertyOfView:aView.
  2133                 name    := (aSpec name) withoutSeparators.
  2133 		name    := (aSpec name) withoutSeparators.
  2134 
  2134 
  2135                 name = props name ifFalse:[
  2135 		name = props name ifFalse:[
  2136                     (self propertyOfName:name) notNil ifTrue:[
  2136 		    (self propertyOfName:name) notNil ifTrue:[
  2137                         name := props name
  2137 			name := props name
  2138                     ]
  2138 		    ]
  2139                 ].
  2139 		].
  2140 
  2140 
  2141                 aSpec name:name.
  2141 		aSpec name:name.
  2142                 self createUndoSpecModify:props.
  2142 		self createUndoSpecModify:props.
  2143                 self rebuildView:aView fromSpec:aSpec withBuilder:nil.
  2143 		self rebuildView:aView fromSpec:aSpec withBuilder:nil.
  2144                 props spec:(aSpec copy).
  2144 		props spec:(aSpec copy).
  2145                 treeView propertyChanged:props.
  2145 		treeView propertyChanged:props.
  2146             ]
  2146 	    ]
  2147         ]
  2147 	]
  2148     ]
  2148     ]
  2149 
  2149 
  2150     "Modified: / 30.10.2001 / 13:59:45 / cg"
  2150     "Modified: / 30.10.2001 / 13:59:45 / cg"
  2151 ! !
  2151 ! !
  2152 
  2152 
  2159     |item prnt|
  2159     |item prnt|
  2160 
  2160 
  2161     (     (item := treeView itemOfView:aView) isNil
  2161     (     (item := treeView itemOfView:aView) isNil
  2162       or:[(prnt := item parent) isNil]
  2162       or:[(prnt := item parent) isNil]
  2163     ) ifTrue:[
  2163     ) ifTrue:[
  2164         ^ false
  2164 	^ false
  2165     ].
  2165     ].
  2166     ^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not])
  2166     ^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not])
  2167 !
  2167 !
  2168 
  2168 
  2169 canExchangeSelectionLayouts
  2169 canExchangeSelectionLayouts
  2170     "returns true if the selection size is exactly 2
  2170     "returns true if the selection size is exactly 2
  2171      and all elements in the selection can be moved or aligned
  2171      and all elements in the selection can be moved or aligned
  2172     "
  2172     "
  2173     selection size == 2 ifFalse:[
  2173     selection size == 2 ifFalse:[
  2174         ^ false
  2174 	^ false
  2175     ].
  2175     ].
  2176     ^ self canMoveOrAlignSelection
  2176     ^ self canMoveOrAlignSelection
  2177 
  2177 
  2178 !
  2178 !
  2179 
  2179 
  2189 canMove:something
  2189 canMove:something
  2190     "checks whether something is not nil and if all widgets derived from
  2190     "checks whether something is not nil and if all widgets derived from
  2191      something can change their layout ( move, align, ... operation ).
  2191      something can change their layout ( move, align, ... operation ).
  2192     "
  2192     "
  2193     something notNil ifTrue:[
  2193     something notNil ifTrue:[
  2194         self forEach:something do:[:aView|
  2194 	self forEach:something do:[:aView|
  2195             (self canChangeLayoutOfView:aView) ifFalse:[^ false]
  2195 	    (self canChangeLayoutOfView:aView) ifFalse:[^ false]
  2196         ].
  2196 	].
  2197         ^ true
  2197 	^ true
  2198     ].
  2198     ].
  2199     ^ false
  2199     ^ false
  2200 !
  2200 !
  2201 
  2201 
  2202 canMoveOrAlignSelection
  2202 canMoveOrAlignSelection
  2212 transaction:aType objects:something do:aOneArgBlock
  2212 transaction:aType objects:something do:aOneArgBlock
  2213     "opens a transaction and evaluates a block within the transaction; the
  2213     "opens a transaction and evaluates a block within the transaction; the
  2214      argument to the block is a view from derived from something
  2214      argument to the block is a view from derived from something
  2215     "
  2215     "
  2216     self withinTransaction:aType objects:something do:[
  2216     self withinTransaction:aType objects:something do:[
  2217         self forEach:something do:aOneArgBlock
  2217 	self forEach:something do:aOneArgBlock
  2218     ]
  2218     ]
  2219 !
  2219 !
  2220 
  2220 
  2221 withinTransaction:aType objects:objects do:aNoneArgBlock
  2221 withinTransaction:aType objects:objects do:aNoneArgBlock
  2222     "evaluate a block with no arguments within a transaction
  2222     "evaluate a block with no arguments within a transaction
  2226     objects isNil ifTrue:[ ^ self ].
  2226     objects isNil ifTrue:[ ^ self ].
  2227 
  2227 
  2228     size := objects size.
  2228     size := objects size.
  2229 
  2229 
  2230     objects isCollection ifTrue:[
  2230     objects isCollection ifTrue:[
  2231         size == 0 ifTrue:[ ^ self ].
  2231 	size == 0 ifTrue:[ ^ self ].
  2232         size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ]
  2232 	size == 1 ifTrue:[ prop := self propertyOfView:(objects first) ]
  2233     ] ifFalse:[
  2233     ] ifFalse:[
  2234         prop := self propertyOfView:objects
  2234 	prop := self propertyOfView:objects
  2235     ].
  2235     ].
  2236 
  2236 
  2237     prop notNil ifTrue:[
  2237     prop notNil ifTrue:[
  2238         text := prop name
  2238 	text := prop name
  2239     ] ifFalse:[
  2239     ] ifFalse:[
  2240         text := size printString, ' elements'
  2240 	text := size printString, ' elements'
  2241     ].
  2241     ].
  2242 
  2242 
  2243     undoHistory withinTransaction:aType text:text do:[
  2243     undoHistory withinTransaction:aType text:text do:[
  2244         aNoneArgBlock value
  2244 	aNoneArgBlock value
  2245     ]
  2245     ]
  2246 ! !
  2246 ! !
  2247 
  2247 
  2248 !UIPainterView methodsFor:'undo actions'!
  2248 !UIPainterView methodsFor:'undo actions'!
  2249 
  2249 
  2251     "create undo action before changing a views layout
  2251     "create undo action before changing a views layout
  2252     "
  2252     "
  2253     |lyt args prop|
  2253     |lyt args prop|
  2254 
  2254 
  2255     undoHistory isTransactionOpen ifTrue:[
  2255     undoHistory isTransactionOpen ifTrue:[
  2256         prop := self propertyOfView:aView.
  2256 	prop := self propertyOfView:aView.
  2257 
  2257 
  2258         prop notNil ifTrue:[
  2258 	prop notNil ifTrue:[
  2259             args := Array new:3.
  2259 	    args := Array new:3.
  2260             args at:1 put:(prop identifier).
  2260 	    args at:1 put:(prop identifier).
  2261 
  2261 
  2262             (lyt := aView geometryLayout) notNil ifTrue:[
  2262 	    (lyt := aView geometryLayout) notNil ifTrue:[
  2263                 args at:2 put:#geometryLayout:
  2263 		args at:2 put:#geometryLayout:
  2264             ] ifFalse:[
  2264 	    ] ifFalse:[
  2265                 lyt := aView extent.
  2265 		lyt := aView extent.
  2266                 args at:2 put:#extent:
  2266 		args at:2 put:#extent:
  2267             ].
  2267 	    ].
  2268             args at:3 put:(lyt copy).
  2268 	    args at:3 put:(lyt copy).
  2269             undoHistory addUndoSelector:#undoLayout: withArgs:args.
  2269 	    undoHistory addUndoSelector:#undoLayout: withArgs:args.
  2270         ]
  2270 	]
  2271     ]
  2271     ]
  2272 !
  2272 !
  2273 
  2273 
  2274 createUndoRemove:aView
  2274 createUndoRemove:aView
  2275     "create undo method before deleting views
  2275     "create undo method before deleting views
  2276     "
  2276     "
  2277     |prop pid|
  2277     |prop pid|
  2278 
  2278 
  2279     (prop := self propertyOfView:aView) notNil ifTrue:[
  2279     (prop := self propertyOfView:aView) notNil ifTrue:[
  2280         (pid := self propertyOfParentForView:aView) notNil ifTrue:[
  2280 	(pid := self propertyOfParentForView:aView) notNil ifTrue:[
  2281             pid := pid identifier
  2281 	    pid := pid identifier
  2282         ].
  2282 	].
  2283 
  2283 
  2284         undoHistory addUndoSelector:#undoRemove:
  2284 	undoHistory addUndoSelector:#undoRemove:
  2285                            withArgs:(Array with:(self fullSpecFor:aView)
  2285 			   withArgs:(Array with:(self fullSpecFor:aView)
  2286                                with:(prop identifier)
  2286 			       with:(prop identifier)
  2287                                with:pid)
  2287 			       with:pid)
  2288     ]
  2288     ]
  2289 !
  2289 !
  2290 
  2290 
  2291 createUndoSpecModify:aProp
  2291 createUndoSpecModify:aProp
  2292     "undo method when changing the specification for an object
  2292     "undo method when changing the specification for an object
  2293     "
  2293     "
  2294     aProp notNil ifTrue:[
  2294     aProp notNil ifTrue:[
  2295         undoHistory addUndoSelector:#undoSpecModify:
  2295 	undoHistory addUndoSelector:#undoSpecModify:
  2296                            withArgs:(Array with:(aProp spec) with:(aProp identifier))
  2296 			   withArgs:(Array with:(aProp spec) with:(aProp identifier))
  2297     ]
  2297     ]
  2298 !
  2298 !
  2299 
  2299 
  2300 undoCreate:something
  2300 undoCreate:something
  2301     "undo method for creating or pasting an object
  2301     "undo method for creating or pasting an object
  2313     "undo method to set the old layout; see 'createUndoLayout:'
  2313     "undo method to set the old layout; see 'createUndoLayout:'
  2314     "
  2314     "
  2315     |view|
  2315     |view|
  2316 
  2316 
  2317     (view := self findViewWithId:(args at:1)) notNil ifTrue:[
  2317     (view := self findViewWithId:(args at:1)) notNil ifTrue:[
  2318         view perform:(args at:2) with:(args at:3).
  2318 	view perform:(args at:2) with:(args at:3).
  2319         self layoutChanged.
  2319 	self layoutChanged.
  2320     ]
  2320     ]
  2321 !
  2321 !
  2322 
  2322 
  2323 undoRemove:args
  2323 undoRemove:args
  2324     "undo method when removing an object; see 'createUndoRemove:'
  2324     "undo method when removing an object; see 'createUndoRemove:'
  2325     "
  2325     "
  2326     |frame prop view|
  2326     |frame prop view|
  2327 
  2327 
  2328     (args at:3) notNil ifTrue:[
  2328     (args at:3) notNil ifTrue:[
  2329         frame := self findViewWithId:(args at:3).
  2329 	frame := self findViewWithId:(args at:3).
  2330     ].
  2330     ].
  2331     frame isNil ifTrue:[
  2331     frame isNil ifTrue:[
  2332         frame := self
  2332 	frame := self
  2333     ].
  2333     ].
  2334     view := self addSpec:(args at:1) builder:(UIBuilder new isEditing:true) in:frame.
  2334     view := self addSpec:(args at:1) builder:(UIBuilder new isEditing:true) in:frame.
  2335     view realize.
  2335     view realize.
  2336 
  2336 
  2337     prop := self propertyOfView:view.
  2337     prop := self propertyOfView:view.
  2344     |view spec props|
  2344     |view spec props|
  2345 
  2345 
  2346     props := self propertyOfIdentifier:(args at:2).
  2346     props := self propertyOfIdentifier:(args at:2).
  2347 
  2347 
  2348     props notNil ifTrue:[
  2348     props notNil ifTrue:[
  2349         view    := props view.
  2349 	view    := props view.
  2350         spec    := args at:1.
  2350 	spec    := args at:1.
  2351 
  2351 
  2352         props spec:spec.
  2352 	props spec:spec.
  2353         self rebuildView:view fromSpec:spec withBuilder:nil.
  2353 	self rebuildView:view fromSpec:spec withBuilder:nil.
  2354         treeView propertyChanged:props.
  2354 	treeView propertyChanged:props.
  2355     ]
  2355     ]
  2356 ! !
  2356 ! !
  2357 
  2357 
  2358 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
  2358 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
  2359 
  2359 
  2360 new
  2360 new
  2361     Identifier notNil ifTrue:[Identifier := Identifier + 1]
  2361     Identifier notNil ifTrue:[Identifier := Identifier + 1]
  2362                      ifFalse:[Identifier := 1].
  2362 		     ifFalse:[Identifier := 1].
  2363 
  2363 
  2364   ^ self basicNew initialize
  2364   ^ self basicNew initialize
  2365 ! !
  2365 ! !
  2366 
  2366 
  2367 !UIPainterView::ViewProperty methodsFor:'accessing'!
  2367 !UIPainterView::ViewProperty methodsFor:'accessing'!
  2418     |val|
  2418     |val|
  2419 
  2419 
  2420     val := 0.
  2420     val := 0.
  2421 
  2421 
  2422     self name from:anIndex do:[:c|
  2422     self name from:anIndex do:[:c|
  2423         c isDigit ifTrue:[val := val * 10 + c digitValue]
  2423 	c isDigit ifTrue:[val := val * 10 + c digitValue]
  2424                  ifFalse:[^ 0]
  2424 		 ifFalse:[^ 0]
  2425     ].
  2425     ].
  2426     ^ val
  2426     ^ val
  2427         
  2427 
  2428 ! !
  2428 ! !
  2429 
  2429 
  2430 !UIPainterView::ViewProperty methodsFor:'spec messages'!
  2430 !UIPainterView::ViewProperty methodsFor:'spec messages'!
  2431 
  2431 
  2432 doesNotUnderstand:aMessage
  2432 doesNotUnderstand:aMessage
  2433     spec notNil ifTrue:[
  2433     spec notNil ifTrue:[
  2434         (spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec]
  2434 	(spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec]
  2435     ].
  2435     ].
  2436     ^ nil
  2436     ^ nil
  2437 !
  2437 !
  2438 
  2438 
  2439 layout
  2439 layout