UIPainterView.st
changeset 60 7542ab7fbbfe
parent 59 0a2b2ff030a0
child 62 0e8573b4329a
equal deleted inserted replaced
59:0a2b2ff030a0 60:7542ab7fbbfe
       
     1 "
       
     2  COPYRIGHT (c) 1995 by Claus Gittinger
       
     3 	      All Rights Reserved
       
     4 
       
     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
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 'From Smalltalk/X, Version:3.1.4 on 25-feb-1997 at 2:17:29 pm'                  !
       
    14 
       
    15 UIObjectView subclass:#UIPainterView
       
    16 	instanceVariableNames:'fontPanel viewProperties superclassName className methodName
       
    17 		categoryName'
       
    18 	classVariableNames:'HandCursor'
       
    19 	poolDictionaries:''
       
    20 	category:'Interface-UIPainter'
       
    21 !
       
    22 
     1 Object subclass:#ViewProperty
    23 Object subclass:#ViewProperty
     2 	instanceVariableNames:'aspectSelector changeSelector nameIndex view elementClass
    24 	instanceVariableNames:'aspectSelector changeSelector nameIndex view elementClass
     3 		labelSelector identifier tabable defaultable menuSelector
    25 		labelSelector identifier tabable defaultable menuSelector
     4 		initiallyInvisible'
    26 		initiallyInvisible'
     5 	classVariableNames:'Identifier'
    27 	classVariableNames:'Identifier'
     6 	poolDictionaries:''
    28 	poolDictionaries:''
     7 	privateIn:UIPainterView
    29 	privateIn:UIPainterView
     8 !
    30 !
     9 
    31 
       
    32 UIPainterView::ViewProperty subclass:#GroupProperties
       
    33 	instanceVariableNames:'controlledObjects group'
       
    34 	classVariableNames:''
       
    35 	poolDictionaries:''
       
    36 	privateIn:UIPainterView
       
    37 !
       
    38 
       
    39 !UIPainterView class methodsFor:'documentation'!
       
    40 
       
    41 copyright
       
    42 "
       
    43  COPYRIGHT (c) 1995 by Claus Gittinger
       
    44 	      All Rights Reserved
       
    45 
       
    46  This software is furnished under a license and may be used
       
    47  only in accordance with the terms of that license and with the
       
    48  inclusion of the above copyright notice.   This software may not
       
    49  be provided or otherwise made available to, or used by, any
       
    50  other person.  No title to or ownership of the software is
       
    51  hereby transferred.
       
    52 "
       
    53 !
       
    54 
       
    55 documentation
       
    56 "
       
    57     not yet finished, not yet published, not yet released.
       
    58 "
       
    59 ! !
       
    60 
       
    61 !UIPainterView class methodsFor:'defaults'!
       
    62 
       
    63 defaultMenuMessage   
       
    64     "This message is the default yo be sent to the menuHolder to get a menu
       
    65     "
       
    66     ^ #menu
       
    67 
       
    68 
       
    69 ! !
       
    70 
       
    71 !UIPainterView methodsFor:'accessing'!
       
    72 
       
    73 application
       
    74     self halt.
       
    75     ^ nil
       
    76 
       
    77     "Modified: 6.9.1995 / 00:46:44 / claus"
       
    78 !
       
    79 
       
    80 className
       
    81     ^ className
       
    82 
       
    83     "Modified: 5.9.1995 / 18:41:30 / claus"
       
    84 !
       
    85 
       
    86 className:aString
       
    87     className := aString
       
    88 
       
    89     "Modified: 5.9.1995 / 18:47:17 / claus"
       
    90 !
       
    91 
       
    92 className:aClassName superclassName:aSuperclassName selector:aSelector
       
    93     className := aClassName.
       
    94     superclassName := aSuperclassName.
       
    95     methodName := aSelector.
       
    96 
       
    97 !
       
    98 
       
    99 methodName
       
   100     ^ methodName
       
   101 
       
   102     "Modified: 5.9.1995 / 18:41:34 / claus"
       
   103 !
       
   104 
       
   105 methodName:aString
       
   106     methodName := aString
       
   107 
       
   108     "Modified: 5.9.1995 / 18:47:27 / claus"
       
   109 !
       
   110 
       
   111 selectNames:aStringOrCollection
       
   112     |prop coll s|
       
   113 
       
   114     (aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[
       
   115         ^ self unselect
       
   116     ].
       
   117 
       
   118     (s := aStringOrCollection) isString ifFalse:[
       
   119         s size == 1 ifTrue:[
       
   120             s := s first
       
   121         ] ifFalse:[
       
   122             coll := OrderedCollection new.
       
   123 
       
   124             s do:[:aName|
       
   125                 (prop := self propertyOfName:aName) notNil ifTrue:[
       
   126                     coll add:(prop view)
       
   127                 ]
       
   128             ].
       
   129             coll size == 1 ifTrue:[ ^ self select:(coll at:1) ].
       
   130             coll size == 0 ifTrue:[ ^ self unselect ].
       
   131 
       
   132           ^ self select:coll.
       
   133         ]
       
   134     ].
       
   135 
       
   136     prop := self propertyOfName:s.
       
   137     prop isNil ifTrue:[^ self unselect]
       
   138               ifFalse:[^ self select:(prop view)]
       
   139 
       
   140 ! !
       
   141 
       
   142 !UIPainterView ignoredMethodsFor:'code manipulation'!
       
   143 
       
   144 changeClass
       
   145     |box classNameHolder superclassNameHolder|
       
   146 
       
   147     classNameHolder := (className ? 'MyClass') asValue.
       
   148     superclassNameHolder := (superclassName ? 'ApplicationModel') asValue.
       
   149 
       
   150     box := DialogBox new.
       
   151     box addTextLabel:'class:'.
       
   152     box addInputFieldOn:classNameHolder.
       
   153     box addTextLabel:'super class:'.
       
   154     box addInputFieldOn:superclassNameHolder.
       
   155     box addAbortButton; addOkButton.
       
   156 
       
   157     box open.
       
   158 
       
   159     box accepted ifTrue:[
       
   160         className := classNameHolder value.
       
   161         superclassName := superclassNameHolder value.
       
   162     ].
       
   163 
       
   164 
       
   165 
       
   166 
       
   167 
       
   168 
       
   169 !
       
   170 
       
   171 changeVariables
       
   172     | box names propList p n newName|
       
   173 
       
   174     names := VariableArray new.
       
   175     propList := VariableArray new.
       
   176     viewProperties do:[:props |
       
   177         n := props name.
       
   178         n notNil ifTrue:[
       
   179             names add:n.
       
   180             propList add:props
       
   181         ]
       
   182     ].
       
   183     box := BuilderVariablesBox new.
       
   184     box list:names.
       
   185     box selectAction:[:selection |
       
   186         p := propList at:selection
       
   187     ].
       
   188     box okAction:[
       
   189         newName := box enterValue.
       
   190 Transcript showCR:('renamed ' , (p name) , 'to:' , newName).
       
   191         p name:newName
       
   192     ].
       
   193     box showAtPointer
       
   194 
       
   195 
       
   196 
       
   197 ! !
       
   198 
       
   199 !UIPainterView methodsFor:'copy & cut & paste'!
       
   200 
       
   201 copySelection
       
   202     "copy the selection into the cut&paste-buffer
       
   203     "
       
   204     |specs|
       
   205 
       
   206     specs := self generateSpecFor:selection.
       
   207 
       
   208     specs notNil ifTrue:[
       
   209         self setSelection:specs
       
   210     ].
       
   211     self unselect.
       
   212 !
       
   213 
       
   214 deleteSelection
       
   215     "delete the selection; not into the paste buffer (undo)
       
   216     "
       
   217     |text|
       
   218 
       
   219     self numberOfSelections ~~ 0 ifTrue:[
       
   220         text := self transactionTextFor:selection.
       
   221 
       
   222         undoHistory transaction:#cut text:text do:[
       
   223             super deleteSelection
       
   224         ].
       
   225     ]
       
   226 !
       
   227 
       
   228 pasteBuffer
       
   229     "add the objects in the paste-buffer
       
   230     "
       
   231     |paste builder frame pasteOrigin pasteOffset|
       
   232 
       
   233     paste := self getSelection.
       
   234 
       
   235     (self canPaste:paste) ifFalse:[ ^ self].
       
   236     (paste isCollection)  ifFalse:[ paste := Array with:paste].
       
   237 
       
   238     frame := self singleSelection.
       
   239 
       
   240     (self supportsSubComponents:frame) ifFalse:[
       
   241         frame := self
       
   242     ].
       
   243     self unselect.
       
   244 
       
   245     builder     := UIBuilder new.
       
   246     selection   := OrderedCollection new.
       
   247     pasteOffset := 0@0.
       
   248     pasteOrigin := self sensor mousePoint.
       
   249     pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
       
   250 
       
   251     paste do:[:aSpec|
       
   252         |view org|
       
   253 
       
   254         builder componentCreationHook:[:aView :aSpecification :aBuilder |  
       
   255             self createdComponent:aView forSpec:aSpecification builder:aBuilder.
       
   256         ].
       
   257         builder applicationClass:(Smalltalk classNamed:className).
       
   258         view := aSpec buildViewWithLayoutFor:builder in:frame.
       
   259 
       
   260         (frame bounds containsPoint:pasteOrigin) ifFalse:[
       
   261             self moveObject:view to:pasteOffset.
       
   262         ] ifTrue:[
       
   263             self moveObject:view to:pasteOrigin + pasteOffset.
       
   264         ].
       
   265 
       
   266         view realize.
       
   267         selection add:view.
       
   268         pasteOffset := pasteOffset + 4.
       
   269     ].
       
   270 
       
   271     self transaction:#paste selectionDo:[:v|
       
   272         self undoCreate:((self propertyOfView:v) identifier)
       
   273     ].
       
   274     selection size == 1 ifTrue:[
       
   275         selection := selection at:1
       
   276     ].
       
   277     self showSelection.
       
   278     self realizeAllSubViews.
       
   279     inputView raise.
       
   280     self changed:#tree
       
   281 
       
   282 ! !
       
   283 
       
   284 !UIPainterView methodsFor:'creating subviews'!
       
   285 
       
   286 addProperties:properties for:aView
       
   287     "set properties to a view and add properties to viewProperties.
       
   288      In case that properties are nil properties are created
       
   289     "
       
   290     |name props|
       
   291 
       
   292     (props := properties) isNil ifTrue:[
       
   293         props := self propertiesForNewView:aView.
       
   294     ].
       
   295 
       
   296     viewProperties add:props.
       
   297     name := props name.
       
   298 
       
   299     aView specClass basicNew supportsLabel ifTrue:[
       
   300         aView label:name
       
   301     ].
       
   302     aView name:name.
       
   303   ^ props
       
   304 !
       
   305 
       
   306 propertiesForNewView:aView
       
   307     |cls props index|
       
   308 
       
   309     cls := aView class.
       
   310 
       
   311     props := ViewProperty new.
       
   312     props view:aView.
       
   313     props elementClass:cls.
       
   314     index := self variableIndexForClass:cls.
       
   315     props nameIndex:index.
       
   316     props name:(self variableNameForClass:cls index:index).
       
   317 
       
   318     ^ props
       
   319 !
       
   320 
       
   321 setupCreatedObject:anObject
       
   322     "set default properties for a created object
       
   323     "
       
   324     |props|
       
   325 
       
   326     props := self addProperties:nil for:anObject.
       
   327 
       
   328     undoHistory transaction:#create text:(props name) do:[
       
   329         self undoCreate:(props identifier).
       
   330     ].
       
   331 ! !
       
   332 
       
   333 !UIPainterView methodsFor:'drag & drop'!
       
   334 
       
   335 canDrop:anObjectOrCollection
       
   336     Transcript showCR:'canDrop'.
       
   337     ^ true
       
   338 
       
   339 
       
   340 !
       
   341 
       
   342 drop:anObjectOrCollection at:aPoint
       
   343     Transcript showCR:'drop:anObjectOrCollection at:aPoint'.
       
   344 
       
   345 
       
   346 ! !
       
   347 
       
   348 !UIPainterView methodsFor:'event handling'!
       
   349 
       
   350 keyPress:key x:x y:y
       
   351     <resource: #keyboard ( #Copy #Paste) >
       
   352 
       
   353     key == #Copy ifTrue:[
       
   354         ^ self copySelection
       
   355     ].
       
   356 
       
   357     key == #Paste ifTrue:[
       
   358         ^ self pasteBuffer
       
   359     ].
       
   360 
       
   361     super keyPress:key x:x y:y
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 
       
   367 ! !
       
   368 
       
   369 !UIPainterView methodsFor:'generating output'!
       
   370 
       
   371 generateActionMethodFor:aspect spec:protoSpec inClass:targetClass
       
   372     ^ ('!!' , targetClass name , ' methodsFor:''actions''!!\\' ,
       
   373       aspect , '\' ,
       
   374       '    "automatically generated by UIPainter ..."\' ,
       
   375       '\' ,
       
   376       '    "action to be added ..."\' ,
       
   377       '    Transcript showCR:''action for ' , aspect , ' ...''.\' ,
       
   378       '!! !!\\') withCRs
       
   379 !
       
   380 
       
   381 generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass
       
   382     ^ ('!!' , targetClass name , ' methodsFor:''aspects''!!\\' ,
       
   383       aspect , '\' ,
       
   384       '    "automatically generated by UIPainter ..."\' ,
       
   385       '\' ,
       
   386       '    |holder|\' ,
       
   387       '\' ,
       
   388       '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
       
   389       '        builder aspectAt:#' , aspect , ' put:(holder := ' , ' ValueHolder new' , ').\' ,
       
   390       '    ].\' ,
       
   391       '    ^ holder\' ,
       
   392       '!! !!\\') withCRs
       
   393 !
       
   394 
       
   395 generateAspectMethods
       
   396     |cls code|
       
   397 
       
   398     className isNil ifTrue:[
       
   399         ^ self warn:'set the class first'
       
   400     ].
       
   401     (cls := Smalltalk at:className asSymbol) isNil ifTrue:[
       
   402         ^ self warn:'create the class first'
       
   403     ].
       
   404 
       
   405     code := ''.
       
   406 
       
   407     viewProperties do:[:aProp |
       
   408         |modelSelector protoSpec thisCode|
       
   409 
       
   410         (modelSelector := aProp aspectSelector) notNil ifTrue:[
       
   411             (cls implements:modelSelector asSymbol) ifFalse:[
       
   412                 protoSpec := aProp view specClass basicNew.
       
   413                 "/ kludge ..
       
   414                 (protoSpec isMemberOf:ActionButtonSpec) ifTrue:[
       
   415                     thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   416                 ] ifFalse:[
       
   417                     thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls).
       
   418                 ].
       
   419                 code := code , thisCode
       
   420             ]
       
   421         ]
       
   422     ].
       
   423     ^ code
       
   424 
       
   425 ! !
       
   426 
       
   427 !UIPainterView ignoredMethodsFor:'generating output'!
       
   428 
       
   429 generateClassDefinition
       
   430     |defCode|
       
   431 
       
   432     defCode := superclassName , ' subclass:#' , className , '\'.
       
   433     defCode := defCode , '  instanceVariableNames:'''.
       
   434     defCode := defCode , self subviewVariableNames , '''\'.
       
   435     defCode := defCode , '  classVariableNames:''''\'.
       
   436     defCode := defCode , '  poolDictionaries:''''\'.
       
   437     defCode := defCode , '  category:''' , categoryName , '''\'.
       
   438     defCode := defCode , Character excla asString , '\\'.
       
   439 
       
   440     ^ defCode withCRs
       
   441 
       
   442 
       
   443 
       
   444 ! !
       
   445 
       
   446 !UIPainterView methodsFor:'generating output'!
       
   447 
       
   448 generateCode
       
   449     "generate code for the windowSpec method"
       
   450 
       
   451     |code|
       
   452 
       
   453     code := ''.
       
   454 
       
   455 "/    (Smalltalk classNamed:className asSymbol) isNil ifTrue:[
       
   456 "/        code := code , self generateClassDefinition.
       
   457 "/    ].
       
   458 "/    code := code , self generateInitMethod.
       
   459 
       
   460     code := code , self generateWindowSpecMethodSource.
       
   461 
       
   462 "/    code := code , self generateAspectMethods.
       
   463 
       
   464     ^ code withCRs
       
   465 
       
   466     "Modified: 5.9.1995 / 20:57:53 / claus"
       
   467 ! !
       
   468 
       
   469 !UIPainterView ignoredMethodsFor:'generating output'!
       
   470 
       
   471 generateInitCodeForGroup:aGroup
       
   472     |code c name p objects outlets moreCode sym typ val|
       
   473 
       
   474     " <name> := <GroupClass> in:<name-of-superview>"
       
   475 
       
   476     code := ''.
       
   477 
       
   478     p := self propertyOfGroup:aGroup.
       
   479     name := p at:#variableName.
       
   480     c := '  ' , name , ' := ' , (aGroup class name) , ' new.\'.
       
   481 
       
   482     code := code , c withCRs.
       
   483 
       
   484     " <name> <symbol>:<value>"
       
   485 
       
   486     objects := p at:#controlledObjects ifAbsent:[nil].
       
   487     objects notNil ifTrue:[
       
   488         objects do:[:controlledObject |
       
   489             c := c , name , ' add:' , (self variableNameOf:controlledObject) , '.\'
       
   490         ]
       
   491     ].
       
   492 
       
   493     code := code , c withCRs
       
   494 
       
   495 
       
   496 
       
   497 
       
   498 
       
   499 !
       
   500 
       
   501 generateInitCodeForOtherStuff
       
   502     |code g c name p outlets moreCode sym typ val|
       
   503 
       
   504     code := ''.
       
   505 
       
   506     "generate code for groups"
       
   507 
       
   508     viewProperties do:[:props |
       
   509         g := props at:#group ifAbsent:[nil].
       
   510         g notNil ifTrue:[
       
   511             code := code , (self generateInitCodeForGroup:g)
       
   512         ]
       
   513     ].
       
   514     ^ code
       
   515 
       
   516 
       
   517 !
       
   518 
       
   519 generateInitCodeForView:aView
       
   520     |code c name p outlets moreCode sym typ val|
       
   521 
       
   522     " <name> := <ViewClass> in:<name-of-superview>"
       
   523 
       
   524     code := ''.
       
   525 
       
   526     p := self propertyOfView:aView.
       
   527     name := p at:#variableName.
       
   528     c := '    ' , name , ' := ' ,
       
   529          (aView class name) , ' in:' , (self variableNameOf:(aView superView)) , '.\'.
       
   530 
       
   531     " <name> origin:(...) extent:(...)"
       
   532 
       
   533     c := c , '    ' , name , ' origin:(', aView origin printString , ')'
       
   534                     , ' extent:(', aView extent printString , ').\'.
       
   535 
       
   536     moreCode := p at:#initCode ifAbsent:nil.
       
   537     moreCode notNil ifTrue:[
       
   538         c := c , moreCode , '\' withCRs
       
   539     ].
       
   540 
       
   541     code := code , c withCRs.
       
   542 
       
   543     " <name> <symbol>:<value>"
       
   544 
       
   545     outlets := p at:#outlets ifAbsent:[nil].
       
   546     outlets notNil ifTrue:[
       
   547         outlets do:[:selectorOutlet |
       
   548             sym := selectorOutlet at:#selector.
       
   549             typ := selectorOutlet at:#type.
       
   550             val := selectorOutlet at:#value.
       
   551             c :=  '    ' , name , ' ' , sym.
       
   552             (typ == #number) ifTrue:[
       
   553                 c := c , val printString
       
   554             ].
       
   555             (typ == #string) ifTrue:[
       
   556                 c := c , '''' , val , ''''
       
   557             ].
       
   558             (typ == #text) ifTrue:[
       
   559                 c := c , '''' , val asString , ''''
       
   560             ].
       
   561             (typ == #strings) ifTrue:[
       
   562                 c := c , '#( '.
       
   563                 val asText do:[:aString |
       
   564                     c := c , '''' , aString , ''' '
       
   565                 ].
       
   566                 c := c , ')'
       
   567             ].
       
   568             (typ == #block) ifTrue:[
       
   569                 c := c , val
       
   570             ].
       
   571             (typ == #color) ifTrue:[
       
   572                 c := c , '(Color name:''' , val , ''')'
       
   573             ].
       
   574             c := c , '.' , Character cr asString.
       
   575             code := code , c
       
   576         ]
       
   577     ].
       
   578 
       
   579     self subviewsOf:aView do:[:v |
       
   580         code := code , (self generateInitCodeForView:v)
       
   581     ].
       
   582     ^ code.
       
   583 
       
   584     "Modified: 5.9.1995 / 20:06:07 / claus"
       
   585 !
       
   586 
       
   587 generateInitMethod
       
   588     |defCode code|
       
   589 
       
   590     defCode := Character excla asString ,
       
   591                className , ' methodsFor:''initialization''' ,
       
   592                Character excla asString , '\\'.
       
   593 
       
   594     defCode := defCode , 'initialize\'.
       
   595     defCode := defCode , '    super initialize.\'.
       
   596     defCode := defCode , '    self setupSubViews.\'.
       
   597     defCode := defCode , '    self setupLocalStuff\'.
       
   598     defCode := defCode , Character excla asString , '\\'.
       
   599 
       
   600     defCode := defCode , 'setupSubViews\'.
       
   601     code := defCode withCRs.
       
   602 
       
   603     self subviewsOf:self do:[:v |
       
   604         code := code , (self generateInitCodeForView:v)
       
   605     ].
       
   606 
       
   607     code := code , (self generateInitCodeForOtherStuff).
       
   608 
       
   609     code := code , '    ^ self\' withCRs.
       
   610 
       
   611     defCode := Character excla asString , '\\'.
       
   612     defCode := defCode , 'setupLocalStuff\'.
       
   613     defCode := defCode , '    ^ self\'.
       
   614     defCode := defCode , Character excla asString , ' ' ,
       
   615                          Character excla asString , '\\'.
       
   616 
       
   617     code := code , defCode withCRs.
       
   618     ^ code.
       
   619 
       
   620 
       
   621 
       
   622 
       
   623 !
       
   624 
       
   625 generateOutlets
       
   626     ^ self
       
   627 ! !
       
   628 
       
   629 !UIPainterView methodsFor:'generating output'!
       
   630 
       
   631 generateSpecFor:something 
       
   632     "generate a spec for a view or collection of views
       
   633     "
       
   634     |spec views|
       
   635 
       
   636     something notNil ifTrue:[
       
   637         something isCollection ifTrue:[views := something]
       
   638                               ifFalse:[views := Array with:something].
       
   639 
       
   640         spec := views collect:[:aView||topSpec|
       
   641             aView specClass isNil ifTrue:[
       
   642                 ^ nil
       
   643             ].
       
   644 
       
   645             topSpec := aView specClass 
       
   646                             fromView:aView 
       
   647                             callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec].
       
   648             topSpec
       
   649         ]
       
   650     ].
       
   651     ^ spec
       
   652 
       
   653 
       
   654 
       
   655 
       
   656 
       
   657 
       
   658 !
       
   659 
       
   660 generateWindowSpecMethodSource
       
   661     |spec specArray str code|
       
   662 
       
   663     subViews remove:inputView.
       
   664     [
       
   665         spec := FullSpec fromView:self callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec].
       
   666     ] valueNowOrOnUnwindDo:[
       
   667         subViews addFirst:inputView.
       
   668     ].
       
   669     specArray := spec literalArrayEncoding.
       
   670 
       
   671     str := WriteStream on:String new.
       
   672     self prettyPrintSpecArray:specArray on:str indent:5.
       
   673 
       
   674     code := Character excla asString 
       
   675             , className , ' class methodsFor:''interface specs'''
       
   676             , Character excla asString , '\\'
       
   677 
       
   678             , methodName , '\'
       
   679             , '    "this window spec was automatically generated by the ST/X UIPainter"\\'
       
   680             , '    "do not manually edit this - the painter/builder may not be able to\'
       
   681             , '     handle the specification if its corrupted."\\'
       
   682             , '    "\'
       
   683             , '     UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '\'
       
   684             , '     ' , className , ' new openInterface:#' , methodName , '\'
       
   685             , '    "\'.
       
   686 
       
   687     methodName = 'windowSpec' ifTrue:[
       
   688         code := code , '    "' , className , ' open"\'
       
   689     ].
       
   690     code := code 
       
   691             , '\'
       
   692             , '    <resource: #canvas>\\'
       
   693             , '    ^\' 
       
   694             , '     ', str contents
       
   695             , '\'
       
   696             , Character excla asString
       
   697             , ' '
       
   698             , Character excla asString
       
   699             , '\\'.
       
   700 
       
   701     ^ code withCRs
       
   702 
       
   703     "Modified: 5.9.1995 / 21:01:35 / claus"
       
   704 ! !
       
   705 
       
   706 !UIPainterView ignoredMethodsFor:'generating output'!
       
   707 
       
   708 nameOfClass
       
   709     ^ 'NewView'
       
   710 ! !
       
   711 
       
   712 !UIPainterView methodsFor:'generating output'!
       
   713 
       
   714 outletValueOf:aSymbol for:aView
       
   715 "/    |c name p outlets moreCode sym typ val|
       
   716 "/
       
   717 "/    p := self propertyOfView:aView.
       
   718 "/    outlets := p at:#outlets ifAbsent:[^ nil].
       
   719 "/    outlets notNil ifTrue:[
       
   720 "/        outlets do:[:selectorOutlet |
       
   721 "/            sym := selectorOutlet at:#selector.
       
   722 "/            (sym == aSymbol) ifTrue:[
       
   723 "/                typ := selectorOutlet at:#type.
       
   724 "/                val := selectorOutlet at:#value.
       
   725 "/                ^ val
       
   726 "/            ]
       
   727 "/        ]
       
   728 "/    ].
       
   729     ^ nil
       
   730 
       
   731 
       
   732 
       
   733 
       
   734 !
       
   735 
       
   736 prettyPrintSpecArray:spec on:aStream indent:i
       
   737     "just for your convenience: prettyPrint a specArray to aStream - it looks better that way"
       
   738 
       
   739     |what oneLine|
       
   740 
       
   741     spec isArray ifFalse:[
       
   742         spec isLiteral ifTrue:[
       
   743             aStream nextPutAll:spec storeString
       
   744         ] ifFalse:[
       
   745             self halt.
       
   746         ].
       
   747         ^ self
       
   748     ].
       
   749 
       
   750     spec isEmpty ifTrue:[
       
   751         aStream nextPutAll:'#()'.
       
   752         ^ self
       
   753     ].
       
   754 
       
   755     what := spec at:1.
       
   756     what isArray ifTrue:[
       
   757         aStream cr; spaces:i+2.
       
   758         aStream nextPutAll:'#('.
       
   759         "/ a spec-collection
       
   760         spec do:[:element |
       
   761             self prettyPrintSpecArray:element on:aStream indent:i+2.
       
   762         ].
       
   763         aStream cr.
       
   764         aStream spaces:i+1.
       
   765         aStream nextPutAll:')'.
       
   766         ^ self.
       
   767     ].
       
   768 
       
   769     oneLine := false.
       
   770     (#(#LayoutFrame #LayoutOrigin #AlignmentOrigin 
       
   771        #Rectangle #Point
       
   772        #Color #ColorValue
       
   773     ) 
       
   774     includesIdentical:what) ifTrue:[
       
   775         oneLine := true
       
   776     ].
       
   777 
       
   778     oneLine ifFalse:[
       
   779         aStream cr.
       
   780         aStream spaces:i+2.
       
   781     ].
       
   782     aStream nextPutAll:'#('.
       
   783 
       
   784 
       
   785     aStream nextPutAll:what storeString.
       
   786 
       
   787     oneLine ifFalse:[
       
   788         aStream cr.
       
   789         aStream spaces:i+4.
       
   790     ].
       
   791 
       
   792     2 to:spec size do:[:index |
       
   793         aStream space.
       
   794         self prettyPrintSpecArray:(spec at:index) on:aStream indent:i+4.
       
   795         oneLine ifFalse:[
       
   796             (index odd and:[index ~~ (spec size)]) ifTrue:[
       
   797                 aStream cr; spaces:i+4.
       
   798             ]
       
   799         ]
       
   800     ].
       
   801     oneLine ifFalse:[
       
   802         aStream cr.
       
   803         aStream spaces:i+1.
       
   804     ].
       
   805     aStream nextPutAll:')'.
       
   806 
       
   807     "Modified: 5.9.1995 / 17:44:20 / claus"
       
   808 !
       
   809 
       
   810 storeContentsOn:aStream
       
   811     viewProperties do:[:p| p storeOn:aStream]
       
   812 !
       
   813 
       
   814 stuffPropertiesFrom:view intoSpec:newSpec
       
   815     "stuff any additional information (held in the properties) into the spec
       
   816      which was just created from view"
       
   817 
       
   818     |props aspectSelector changeSelector labelSelector name tabable defaultable
       
   819      menuSelector initiallyInvisible|
       
   820 
       
   821     props := self propertyOfView:view.
       
   822     props isNil ifTrue:[^ self].
       
   823 
       
   824     (aspectSelector := props aspectSelector) notNil ifTrue:[
       
   825         newSpec model:aspectSelector
       
   826     ].
       
   827     (changeSelector := props changeSelector) notNil ifTrue:[
       
   828         newSpec change:changeSelector
       
   829     ].
       
   830     (menuSelector := props menuSelector) notNil ifTrue:[
       
   831         newSpec menu:menuSelector
       
   832     ].
       
   833     (labelSelector := props labelSelector) notNil ifTrue:[
       
   834         newSpec label:labelSelector
       
   835     ].
       
   836     (tabable := props tabable) notNil ifTrue:[
       
   837         newSpec tabable:tabable
       
   838     ].
       
   839     (defaultable := props defaultable) notNil ifTrue:[
       
   840         newSpec defaultable:defaultable
       
   841     ].
       
   842     (initiallyInvisible := props initiallyInvisible) notNil ifTrue:[
       
   843         newSpec initiallyInvisible:initiallyInvisible
       
   844     ].
       
   845     (name := props name) notNil ifTrue:[
       
   846         newSpec name:name
       
   847     ].
       
   848 
       
   849 ! !
       
   850 
       
   851 !UIPainterView ignoredMethodsFor:'generating output'!
       
   852 
       
   853 subviewVariableNames
       
   854     |names|
       
   855 
       
   856     names := ''.
       
   857     viewProperties do:[:p| names := names , ' ' , (p name)].
       
   858   ^ names
       
   859 ! !
       
   860 
       
   861 !UIPainterView methodsFor:'generating output'!
       
   862 
       
   863 subviewsOf:aView do:aBlock
       
   864     |subs v|
       
   865 
       
   866     (subs := aView subViews) notNil ifTrue:[
       
   867         subs do:[:v|
       
   868             (v ~~ inputView and:[v notNil]) ifTrue:[
       
   869                 (viewProperties detect:[:p | p view == v] ifNone:nil) notNil ifTrue:[ 
       
   870                     (v superView == aView) ifTrue:[
       
   871                         aBlock value:v
       
   872                     ]
       
   873                 ]
       
   874             ]
       
   875         ]
       
   876     ]
       
   877 
       
   878 ! !
       
   879 
       
   880 !UIPainterView methodsFor:'group manipulations'!
       
   881 
       
   882 groupEnterFields
       
   883     |props name index group objects|
       
   884 
       
   885     selection isNil ifTrue:[^ self].
       
   886     self selectionDo:[:aView |
       
   887         (aView isKindOf:EditField) ifFalse:[
       
   888             self warn:'select EditFields only !!'.
       
   889             ^ self
       
   890         ]
       
   891     ].
       
   892     self selectionHiddenDo:[
       
   893         group := EnterFieldGroup new.
       
   894 
       
   895         props := GroupProperties new.
       
   896         props elementClass:EnterFieldGroup.
       
   897         props group:group.
       
   898         index := self variableIndexForClass:EnterFieldGroup.
       
   899         props nameIndex:index.
       
   900         name := self variableNameForClass:EnterFieldGroup index:index.
       
   901         props name:name.
       
   902         objects := OrderedCollection new.
       
   903         props controlledObjects:objects.
       
   904         viewProperties add:props.
       
   905 
       
   906         self selectionDo:[:aView |
       
   907             objects add:aView.
       
   908             group add:aView
       
   909         ].
       
   910     ]
       
   911 
       
   912 
       
   913 !
       
   914 
       
   915 groupRadioButtons
       
   916     |props name index group objects|
       
   917 
       
   918     selection isNil ifTrue:[^ self].
       
   919     self selectionDo:[:aView |
       
   920         (aView isKindOf:RadioButton) ifFalse:[
       
   921             self warn:'select RadioButtons only !!'.
       
   922             ^ self
       
   923         ]
       
   924     ].
       
   925     self selectionHiddenDo:[
       
   926         group := RadioButtonGroup new.
       
   927 
       
   928         props := GroupProperties new.
       
   929         props elementClass:RadioButtonGroup.
       
   930         props group:group.
       
   931         index := self variableIndexForClass:RadioButtonGroup.
       
   932         props nameIndex:index.
       
   933         name := self variableNameForClass:RadioButtonGroup index:index.
       
   934         props name:name.
       
   935         group groupID:name asSymbol.
       
   936         objects := OrderedCollection new.
       
   937         props controlledObjects:objects.
       
   938         viewProperties add:props.
       
   939 
       
   940         self selectionDo:[:aView |
       
   941             aView turnOff.
       
   942             objects add:aView.
       
   943             group add:aView
       
   944         ].
       
   945     ]
       
   946 
       
   947     "Modified: 5.9.1995 / 16:06:15 / claus"
       
   948 ! !
       
   949 
       
   950 !UIPainterView methodsFor:'initialization'!
       
   951 
       
   952 initialize
       
   953     super initialize.
       
   954 
       
   955     superclassName := 'ApplicationModel'.
       
   956     className      := 'NewApplication'.
       
   957     methodName     := 'windowSpec'.
       
   958     categoryName   := 'Applications'.
       
   959     viewProperties := OrderedCollection new.
       
   960     HandCursor     := Cursor leftHand.
       
   961 
       
   962     "Modified: 5.9.1995 / 19:58:06 / claus"
       
   963 ! !
       
   964 
       
   965 !UIPainterView methodsFor:'interface to Builder'!
       
   966 
       
   967 addOutletDefinitionFor:outletSymbol type:type value:outletValue for:aView
       
   968     |outletProps selectorProps viewProps|
       
   969 
       
   970     viewProps := self propertyOfView:aView.
       
   971 "/    outletProps := viewProps at:#outlets ifAbsent:[nil].
       
   972 "/    outletProps isNil ifTrue:[
       
   973 "/        outletProps := Dictionary new.
       
   974 "/        viewProps at:#outlets put:outletProps
       
   975 "/    ].
       
   976 "/    selectorProps := outletProps at:outletSymbol ifAbsent:[nil].
       
   977 "/    selectorProps isNil ifTrue:[
       
   978 "/        selectorProps := Dictionary new.
       
   979 "/        outletProps at:outletSymbol put:selectorProps
       
   980 "/    ].
       
   981 "/
       
   982 "/    selectorProps at:#selector put:outletSymbol.
       
   983 "/    selectorProps at:#type put:type.
       
   984 "/    selectorProps at:#value put:outletValue
       
   985 
       
   986 !
       
   987 
       
   988 addSpec:specOrSpecArray
       
   989     |spec builder|
       
   990 
       
   991     spec := UISpecification from:specOrSpecArray.
       
   992 
       
   993     builder := UIBuilder new.
       
   994     builder componentCreationHook:[:view :spec :aBuilder |
       
   995                 self createdComponent:view forSpec:spec builder:aBuilder
       
   996             ].
       
   997     builder applicationClass:(Smalltalk classNamed:className).
       
   998     spec setupView:self for:builder.
       
   999 
       
  1000     self realizeAllSubViews.
       
  1001     inputView raise.
       
  1002 
       
  1003 "/    viewProperties := OrderedCollection new.
       
  1004 "/    self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]).
       
  1005 
       
  1006     self changed:#tree.
       
  1007 
       
  1008 
       
  1009     "Modified: 5.9.1995 / 23:36:55 / claus"
       
  1010 !
       
  1011 
       
  1012 applicationName
       
  1013     ^ className
       
  1014 !
       
  1015 
       
  1016 aspectAt:aSymbol
       
  1017     self halt.
       
  1018     ^ nil
       
  1019 
       
  1020     "Modified: 6.9.1995 / 00:45:35 / claus"
       
  1021 !
       
  1022 
       
  1023 createdComponent:newView forSpec:aSpec builder:aBuilder
       
  1024     "callBack from UISpec view building"
       
  1025 
       
  1026     |props|
       
  1027 
       
  1028     props := self propertiesForNewView:newView.
       
  1029 
       
  1030     aSpec name notNil ifTrue:[
       
  1031         (self propertyOfName:(aSpec name)) isNil ifTrue:[
       
  1032             props name:aSpec name
       
  1033         ]
       
  1034     ].
       
  1035 
       
  1036     props labelSelector:(aSpec labelSelector).
       
  1037     props aspectSelector:(aSpec modelSelector).
       
  1038     props menuSelector:(aSpec menuSelector).
       
  1039     props tabable:(aSpec tabable).
       
  1040     props defaultable:(aSpec defaultable).
       
  1041     props initiallyInvisible:(aSpec initiallyInvisible).
       
  1042 
       
  1043     viewProperties add:props.
       
  1044 !
       
  1045 
       
  1046 generatePropertiesFor:aCollectionOfViews
       
  1047 
       
  1048     "/ done as two loops, to get bread-first naming
       
  1049 
       
  1050     aCollectionOfViews do:[:aView|
       
  1051         |props|
       
  1052 
       
  1053         props := self propertiesForNewView:aView.
       
  1054         viewProperties add:props.
       
  1055         aView name:(props name).
       
  1056 
       
  1057         aView geometryLayout isNil ifTrue:[
       
  1058             aView geometryLayout:(aView bounds asLayout).
       
  1059         ]
       
  1060     ].
       
  1061 
       
  1062     aCollectionOfViews do:[:aView |
       
  1063         |subs|
       
  1064 
       
  1065         subs := aView subViews.
       
  1066         subs notNil ifTrue:[
       
  1067             self generatePropertiesFor:subs
       
  1068         ]
       
  1069     ].
       
  1070 
       
  1071 !
       
  1072 
       
  1073 inspectAttributes
       
  1074     |p|
       
  1075 
       
  1076     self singleSelectionDo:[:aView |
       
  1077         p := self propertyOfView:aView.
       
  1078         p inspect
       
  1079     ]
       
  1080 !
       
  1081 
       
  1082 inspectSpec
       
  1083     |s|
       
  1084 
       
  1085     self singleSelectionDo:[:aView |
       
  1086         s := self generateSpecFor:aView.
       
  1087         s first inspect
       
  1088     ]
       
  1089 !
       
  1090 
       
  1091 setupFromSpec:specOrSpecArray
       
  1092     self removeAll.
       
  1093     self addSpec:specOrSpecArray
       
  1094 !
       
  1095 
       
  1096 showFontPanel
       
  1097     |action|
       
  1098 
       
  1099     fontPanel isNil ifTrue:[
       
  1100 	fontPanel := FontPanel new 
       
  1101     ].
       
  1102 
       
  1103     selection notNil ifTrue:[
       
  1104 	action := [:family :face :style :size |
       
  1105 		       self changeFontFamily:family face:face
       
  1106 				       style:style size:size
       
  1107 		  ].
       
  1108 	fontPanel action:action.
       
  1109 	fontPanel showAtPointer
       
  1110     ]
       
  1111 ! !
       
  1112 
       
  1113 !UIPainterView methodsFor:'menus'!
       
  1114 
       
  1115 menu
       
  1116     |menu canPaste|
       
  1117 
       
  1118     testMode ifTrue:[^ nil ].
       
  1119 
       
  1120     canPaste := self canPaste:(self getSelection).
       
  1121 
       
  1122     selection isNil ifTrue:[
       
  1123         menu := PopUpMenu labels:( resources array:#('paste' 'undo'))
       
  1124                        selectors:#( #pasteBuffer #undoLast )
       
  1125                     accelerators:#( #Paste nil )
       
  1126                         receiver:self.
       
  1127 
       
  1128         canPaste           ifFalse:[menu disable:#pasteBuffer].
       
  1129         undoHistory isEmpty ifTrue:[menu disable:#undoLast].
       
  1130       ^ menu
       
  1131     ].    
       
  1132 
       
  1133     menu := PopUpMenu labels:( resources array:#(
       
  1134                                   'copy' 
       
  1135                                   'cut' 
       
  1136                                   'paste' 
       
  1137                                   '-' 
       
  1138                                   'arrange'
       
  1139                                   'dimension'
       
  1140                                   'align'
       
  1141                                 )
       
  1142                               )
       
  1143                    selectors:#(   #copySelection
       
  1144                                   #deleteSelection
       
  1145                                   #pasteBuffer
       
  1146                                   nil
       
  1147                                   #arrange
       
  1148                                   #dimension
       
  1149                                   #align
       
  1150                               )
       
  1151                    accelerators:#(#Copy
       
  1152                                   #Cut
       
  1153                                   #Paste
       
  1154                                   nil
       
  1155                                   nil
       
  1156                                   nil
       
  1157                                   nil
       
  1158                               )
       
  1159                      receiver:self.
       
  1160 
       
  1161     (canPaste and:[self supportsSubComponents:selection]) ifFalse:[
       
  1162         menu disable:#pasteBuffer
       
  1163     ].
       
  1164 
       
  1165     menu subMenuAt:#arrange   put:(self subMenuArrange).
       
  1166     menu subMenuAt:#dimension put:(self subMenuDimension).
       
  1167     menu subMenuAt:#align     put:(self subMenuAlign).
       
  1168   ^ menu
       
  1169 
       
  1170 !
       
  1171 
       
  1172 subMenuAlign
       
  1173     "returns submenu alignment
       
  1174     "
       
  1175     |menu|
       
  1176 
       
  1177     menu := PopUpMenu labels:(
       
  1178                 resources array:#(
       
  1179                                     'align left' 
       
  1180                                     'align right'
       
  1181                                     'align left & right'
       
  1182                                     'align top' 
       
  1183                                     'align bottom'
       
  1184                                     'align centered vertical'
       
  1185                                     'align centered horizontal'
       
  1186                                     '-'
       
  1187                                     'spread horizontal'
       
  1188                                     'spread vertical'
       
  1189                                     'center horizontal in frame'
       
  1190                                     'center vertical in frame'
       
  1191                                   )
       
  1192                          )
       
  1193 
       
  1194               selectors:#(  
       
  1195                             alignSelectionLeft
       
  1196                             alignSelectionRight
       
  1197                             alignSelectionLeftAndRight
       
  1198                             alignSelectionTop
       
  1199                             alignSelectionBottom
       
  1200                             alignSelectionCenterHor
       
  1201                             alignSelectionCenterVer
       
  1202                             nil
       
  1203                             spreadSelectionHor
       
  1204                             spreadSelectionVer
       
  1205                             centerSelectionHor
       
  1206                             centerSelectionVer
       
  1207                          )
       
  1208                receiver:self.
       
  1209     ^ menu    
       
  1210 
       
  1211 !
       
  1212 
       
  1213 subMenuArrange
       
  1214     "returns submenu arrange
       
  1215     "
       
  1216     |menu|
       
  1217 
       
  1218     menu := PopUpMenu labels:( 
       
  1219                 resources array:#(
       
  1220                                     'to front' 
       
  1221                                     'to back' 
       
  1222                                  )
       
  1223                               )
       
  1224                    selectors:#(
       
  1225                                     raiseSelection
       
  1226                                     lowerSelection
       
  1227                               )
       
  1228                      receiver:self.
       
  1229   ^ menu
       
  1230 !
       
  1231 
       
  1232 subMenuDimension
       
  1233     "returns submenu dimension
       
  1234     "
       
  1235     |menu|
       
  1236 
       
  1237     menu := PopUpMenu labels:( 
       
  1238                 resources array:#(
       
  1239                                     'default extent' 
       
  1240                                     'default width' 
       
  1241                                     'default height'
       
  1242                                     '-'
       
  1243                                     'copy extent'
       
  1244                                     '-'
       
  1245                                     'paste extent'
       
  1246                                     'paste width'
       
  1247                                     'paste height'
       
  1248                                  )
       
  1249                               )
       
  1250                    selectors:#(
       
  1251                                     setToDefaultExtent
       
  1252                                     setToDefaultWidth
       
  1253                                     setToDefaultHeight
       
  1254                                     nil
       
  1255                                     copyExtent
       
  1256                                     nil
       
  1257                                     pasteExtent
       
  1258                                     pasteWidth
       
  1259                                     pasteHeight
       
  1260                               )
       
  1261                      receiver:self.
       
  1262   ^ menu
       
  1263 !
       
  1264 
       
  1265 subMenuFont
       
  1266     "returns submenu dimension
       
  1267     "
       
  1268     |menu|
       
  1269 
       
  1270     menu := PopUpMenu labels:( 
       
  1271                 resources array:#(
       
  1272                                     'larger' 
       
  1273                                     'smaller'
       
  1274                                     '-'
       
  1275                                     'normal'
       
  1276                                     'bold'
       
  1277                                     'italic'
       
  1278                                     'bold italic'
       
  1279                                     '-'
       
  1280                                     'font panel'
       
  1281                                  )
       
  1282                               )
       
  1283                    selectors:#(
       
  1284                                     largerFont 
       
  1285                                     smallerFont
       
  1286                                     nil
       
  1287                                     normalFont
       
  1288                                     boldFont
       
  1289                                     italicFont
       
  1290                                     boldItalicFont
       
  1291                                     nil
       
  1292                                     showFontPanel
       
  1293                               )
       
  1294                      receiver:self.
       
  1295   ^ menu
       
  1296 ! !
       
  1297 
       
  1298 !UIPainterView methodsFor:'misc'!
       
  1299 
       
  1300 changeFontFamily:family face:face style:style size:size
       
  1301     |f|
       
  1302 
       
  1303     f := Font family:family
       
  1304                 face:face
       
  1305                style:style
       
  1306                 size:size.
       
  1307 
       
  1308     f notNil ifTrue:[
       
  1309         self selectionHiddenDo:[
       
  1310             self selectionDo:[:aView |
       
  1311                 aView font:f.
       
  1312                 self elementChanged:aView.
       
  1313             ]
       
  1314         ]
       
  1315     ]
       
  1316 
       
  1317     "Modified: 5.9.1995 / 12:13:27 / claus"
       
  1318 !
       
  1319 
       
  1320 changeVariableNameOf:aView to:newName
       
  1321     |prop|
       
  1322 
       
  1323     prop := self propertyOf:aView.
       
  1324 
       
  1325     prop isNil ifTrue:[
       
  1326         ^ self error:'no such view'
       
  1327     ].
       
  1328 
       
  1329     ((aView respondsTo:#label:) and:[aView label = prop name]) ifTrue:[
       
  1330         self selectionHiddenDo:[
       
  1331             |layout|
       
  1332             layout := aView geometryLayout copy.
       
  1333             aView label:newName.
       
  1334             aView geometryLayout:layout.
       
  1335         ]
       
  1336     ].
       
  1337 
       
  1338     prop  name:newName.
       
  1339     aView name:newName.
       
  1340     self changed:#widgetName
       
  1341 
       
  1342 
       
  1343 
       
  1344 !
       
  1345 
       
  1346 variableIndexForClass:aClass
       
  1347     |max|
       
  1348 
       
  1349     max := 0.
       
  1350 
       
  1351     viewProperties do:[:p|
       
  1352         p elementClass == aClass ifTrue:[
       
  1353             max := max max:(p nameIndex)
       
  1354         ]
       
  1355     ].
       
  1356     ^ max + 1
       
  1357 
       
  1358 !
       
  1359 
       
  1360 variableNameForClass:aClass index:index
       
  1361     |n|
       
  1362 
       
  1363     n := (aClass name) , index printString.
       
  1364     n at:1 put:(n at:1) asLowercase.
       
  1365   ^ n
       
  1366 
       
  1367 !
       
  1368 
       
  1369 variableNameOf:aView
       
  1370     |prop|
       
  1371 
       
  1372     aView notNil ifTrue:[
       
  1373         prop := self propertyOf:aView
       
  1374     ].
       
  1375 
       
  1376     prop notNil ifTrue:[^ prop name]
       
  1377                ifFalse:[^ 'self']
       
  1378 
       
  1379 ! !
       
  1380 
       
  1381 !UIPainterView methodsFor:'removing components'!
       
  1382 
       
  1383 remove:something
       
  1384     "remove something, anObject or a collection of objects from the contents do redraw
       
  1385     "
       
  1386     self forEach:something do:[:anObject |
       
  1387         self removeObject:anObject
       
  1388     ]
       
  1389 
       
  1390 
       
  1391 !
       
  1392 
       
  1393 removeAll
       
  1394     "remove the argument, anObject"
       
  1395 
       
  1396     self unselect.
       
  1397 
       
  1398     subViews notNil ifTrue:[
       
  1399         subViews copy do:[:sub |
       
  1400             sub ~~ inputView ifTrue:[   
       
  1401                 self removeTreeFrom:sub
       
  1402             ]
       
  1403         ]
       
  1404     ].
       
  1405     viewProperties := OrderedCollection new.
       
  1406     undoHistory reinitialize.
       
  1407     self changed:#tree
       
  1408 !
       
  1409 
       
  1410 removeObject:anObject
       
  1411     "remove the argument, anObject
       
  1412     "
       
  1413     |spec prop|
       
  1414 
       
  1415     undoHistory isTransactionOpen ifTrue:[
       
  1416         (prop := self propertyOfView:anObject) notNil ifTrue:[
       
  1417             self undoRemove:(prop identifier)
       
  1418         ]
       
  1419     ].
       
  1420     self removeTreeFrom:anObject.
       
  1421     self changed:#tree
       
  1422 !
       
  1423 
       
  1424 removeTreeFrom:anObject
       
  1425     "remove the argument, anObject and all of its children
       
  1426     "
       
  1427     |props|
       
  1428 
       
  1429     anObject notNil ifTrue:[
       
  1430         (anObject subViews notNil) ifTrue:[
       
  1431             anObject subViews copy do:[:sub |
       
  1432                 self removeTreeFrom:sub
       
  1433             ]
       
  1434         ].
       
  1435         props := self propertyOf:anObject.
       
  1436 
       
  1437         props notNil ifTrue:[
       
  1438             viewProperties remove:props ifAbsent:nil
       
  1439         ].
       
  1440         anObject destroy
       
  1441     ]
       
  1442 ! !
       
  1443 
       
  1444 !UIPainterView methodsFor:'searching'!
       
  1445 
       
  1446 findObjectAt:aPoint
       
  1447     "find the origin/corner of the currentWidget
       
  1448     "
       
  1449     |view|
       
  1450 
       
  1451     view := super findObjectAt:aPoint.
       
  1452 
       
  1453     view notNil ifTrue:[
       
  1454         "can be a view within a view not visible
       
  1455         "
       
  1456         [ (self propertyOfView:view) isNil ] whileTrue:[
       
  1457             (view := view superView) == self ifTrue:[^ nil]
       
  1458         ]
       
  1459     ].
       
  1460     ^ view
       
  1461 !
       
  1462 
       
  1463 findViewWithId:aViewId
       
  1464     "finds view assigned to id and returns the view or nil
       
  1465     "
       
  1466     |prop|
       
  1467 
       
  1468     prop := self propertyOfIdentifier:aViewId.
       
  1469 
       
  1470     prop notNil ifTrue:[^ prop view]
       
  1471                ifFalse:[^ nil]
       
  1472 ! !
       
  1473 
       
  1474 !UIPainterView methodsFor:'seraching property'!
       
  1475 
       
  1476 propertyOf:something
       
  1477 
       
  1478     ^ viewProperties detect:[:p| (p view == something or:[p group == something])]
       
  1479                      ifNone:nil
       
  1480 
       
  1481 
       
  1482 
       
  1483 
       
  1484 
       
  1485 !
       
  1486 
       
  1487 propertyOfGroup:aGroup
       
  1488 
       
  1489     ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil
       
  1490 !
       
  1491 
       
  1492 propertyOfIdentifier:anId
       
  1493 
       
  1494     anId notNil ifTrue:[
       
  1495         ^ viewProperties detect:[:p| p identifier == anId] ifNone:nil.
       
  1496     ].
       
  1497     ^ nil
       
  1498 !
       
  1499 
       
  1500 propertyOfName:aString
       
  1501 
       
  1502     aString = 'self' ifFalse:[
       
  1503         ^ viewProperties detect:[:p| p name = aString] ifNone:nil
       
  1504     ].
       
  1505     ^ nil
       
  1506 !
       
  1507 
       
  1508 propertyOfView:aView
       
  1509 
       
  1510     (aView isNil or:[aView == self]) ifFalse:[
       
  1511         ^ viewProperties detect:[:p| p view == aView] ifNone:nil
       
  1512     ].
       
  1513     ^ nil
       
  1514 ! !
       
  1515 
       
  1516 !UIPainterView methodsFor:'testing'!
       
  1517 
       
  1518 isHorizontalResizable:aComponent
       
  1519 
       
  1520     (aComponent isKindOf:ScrollBar) ifTrue:[
       
  1521         ^ aComponent orientation == #horizontal
       
  1522     ].
       
  1523     (aComponent isKindOf:Scroller) ifTrue:[
       
  1524         ^ aComponent orientation == #horizontal
       
  1525     ].
       
  1526     (aComponent isKindOf:Slider) ifTrue:[
       
  1527         ^ aComponent orientation == #horizontal
       
  1528     ].
       
  1529     ^ true
       
  1530 
       
  1531 
       
  1532 !
       
  1533 
       
  1534 isVerticalResizable:aComponent
       
  1535 
       
  1536     (aComponent isKindOf:EditField) ifTrue:[
       
  1537         ^ false
       
  1538     ].
       
  1539     (aComponent isKindOf:ComboBoxView) ifTrue:[
       
  1540         ^ false
       
  1541     ].
       
  1542     (aComponent isKindOf:CheckBox) ifTrue:[
       
  1543         ^ false
       
  1544     ].
       
  1545     (aComponent isKindOf:ScrollBar) ifTrue:[
       
  1546         ^ aComponent orientation == #vertical
       
  1547     ].
       
  1548     (aComponent isKindOf:Scroller) ifTrue:[
       
  1549         ^ aComponent orientation == #vertical
       
  1550     ].
       
  1551     (aComponent isKindOf:Slider) ifTrue:[
       
  1552         ^ aComponent orientation == #vertical
       
  1553     ].
       
  1554     ^ true
       
  1555 
       
  1556 
       
  1557 ! !
       
  1558 
       
  1559 !UIPainterView methodsFor:'transaction'!
       
  1560 
       
  1561 transaction:aType objects:something do:aOneArgBlock
       
  1562     "opens a transaction and evaluates a block within the transaction; the
       
  1563      argument to the block is a view from derived from something
       
  1564     "
       
  1565     |text|
       
  1566 
       
  1567     something notNil ifTrue:[
       
  1568         text := self transactionTextFor:something.
       
  1569 
       
  1570         undoHistory transaction:aType text:text do:[
       
  1571             something isCollection ifTrue:[
       
  1572                 something do:[:aView| aOneArgBlock value:aView ]
       
  1573             ] ifFalse:[
       
  1574                 aOneArgBlock value:something
       
  1575             ]
       
  1576         ]
       
  1577     ]
       
  1578 !
       
  1579 
       
  1580 transactionTextFor:anElementOrCollection
       
  1581     "returns text used by transaction or nil
       
  1582     "
       
  1583     |props size|
       
  1584 
       
  1585     anElementOrCollection notNil ifTrue:[
       
  1586         anElementOrCollection isCollection ifTrue:[
       
  1587             size := anElementOrCollection size.
       
  1588             size == 0 ifTrue:[^ nil].
       
  1589             size ~~ 1 ifTrue:[^ size printString, ' elements'].
       
  1590 
       
  1591             props := self propertyOfView:(anElementOrCollection at:1).
       
  1592         ] ifFalse:[
       
  1593             props := self propertyOfView:anElementOrCollection
       
  1594         ].
       
  1595         props notNil ifTrue:[ ^ props name ]
       
  1596     ].
       
  1597     ^ nil
       
  1598 ! !
       
  1599 
       
  1600 !UIPainterView methodsFor:'undo actions'!
       
  1601 
       
  1602 undoCreate:aViewId
       
  1603     |view|
       
  1604 
       
  1605     undoHistory addUndoBlock:[
       
  1606         (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1607             self removeObject:view
       
  1608         ]
       
  1609     ]
       
  1610 
       
  1611 !
       
  1612 
       
  1613 undoLayout:aViewId
       
  1614     "undo method layout
       
  1615     "
       
  1616     |view layout|
       
  1617 
       
  1618     (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1619         layout := view geometryLayout copy.
       
  1620         view   := nil.
       
  1621 
       
  1622         layout notNil ifTrue:[
       
  1623             undoHistory addUndoBlock:[
       
  1624                 (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1625                     view geometryLayout:layout
       
  1626                 ]
       
  1627             ]
       
  1628         ] ifFalse:[
       
  1629             layout := view pixelOrigin.
       
  1630 
       
  1631             undoHistory addUndoBlock:[
       
  1632                 (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1633                     view pixelOrigin:layout
       
  1634                 ]
       
  1635             ]
       
  1636         ]
       
  1637     ]
       
  1638 !
       
  1639 
       
  1640 undoLayoutView:aView
       
  1641     "undo method for changing layout on a view
       
  1642     "
       
  1643     |prop|
       
  1644 
       
  1645     undoHistory isTransactionOpen ifTrue:[
       
  1646         prop := self propertyOfView:aView.
       
  1647         prop notNil ifTrue:[
       
  1648             self undoLayout:(prop identifier)
       
  1649         ]
       
  1650     ]
       
  1651 !
       
  1652 
       
  1653 undoRemove:aViewId
       
  1654     "prepare undo method
       
  1655     "
       
  1656     |view prop spec parentId|
       
  1657 
       
  1658     (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1659         spec := (self generateSpecFor:view) first.
       
  1660         view := view superView.
       
  1661 
       
  1662         (self supportsSubComponents:view) ifTrue:[
       
  1663             prop := self propertyOfView:view.
       
  1664 
       
  1665             prop notNil ifTrue:[
       
  1666                 parentId := prop identifier
       
  1667             ]
       
  1668         ].
       
  1669         view := nil.
       
  1670         prop := nil.
       
  1671 
       
  1672         undoHistory addUndoBlock:[
       
  1673             |builder|
       
  1674 
       
  1675             builder := UIBuilder new.
       
  1676             view    := self findViewWithId:parentId.
       
  1677 
       
  1678             view isNil ifTrue:[
       
  1679                 view := self
       
  1680             ].
       
  1681 
       
  1682             builder componentCreationHook:[:aView :aSpec :aBuilder |  
       
  1683                 self createdComponent:aView forSpec:aSpec builder:aBuilder.
       
  1684             ].
       
  1685 
       
  1686             builder applicationClass:(Smalltalk classNamed:className).
       
  1687             (spec buildViewWithLayoutFor:builder in:view) realize.
       
  1688             inputView raise.
       
  1689         ].
       
  1690     ]
       
  1691 !
       
  1692 
       
  1693 undoSpecModify:aViewId
       
  1694     "undo for updateFromSpec
       
  1695     "
       
  1696     |builder view spec|
       
  1697 
       
  1698     (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1699         spec := (self generateSpecFor:view) first.
       
  1700         view := nil.
       
  1701 
       
  1702         undoHistory addUndoBlock:[
       
  1703             (view := self findViewWithId:aViewId) notNil ifTrue:[
       
  1704                 builder := UIBuilder new.
       
  1705                 spec setAttributesIn:view with:builder.
       
  1706                 view superView sizeChanged:nil
       
  1707             ]
       
  1708         ]
       
  1709     ].
       
  1710 
       
  1711 
       
  1712 
       
  1713 ! !
       
  1714 
       
  1715 !UIPainterView methodsFor:'update from Specification'!
       
  1716 
       
  1717 updateFromSpec:aSpec
       
  1718     "update current selected view from specification
       
  1719     "
       
  1720     |props name builder|
       
  1721 
       
  1722     self singleSelection notNil ifTrue:[
       
  1723         self selectionHiddenDo:[
       
  1724             self transaction:#specification selectionDo:[:aView|
       
  1725                 builder := UIBuilder new.
       
  1726                 props   := self propertyOfView:aView.
       
  1727                 name    := aSpec name.
       
  1728 
       
  1729                 self undoSpecModify:(props identifier).
       
  1730 
       
  1731                 name = (aView name) ifFalse:[
       
  1732                     name notNil ifTrue:[
       
  1733                         name := name withoutSeparators.
       
  1734 
       
  1735                         (name isEmpty or:[(self propertyOfName:name) notNil]) ifTrue:[
       
  1736                             name := nil
       
  1737                         ]
       
  1738                     ].
       
  1739                     name isNil ifTrue:[
       
  1740                         aSpec name:(aView name).
       
  1741                     ]
       
  1742                 ].
       
  1743 
       
  1744                 aSpec setAttributesIn:aView with:builder.
       
  1745                 aView superView sizeChanged:nil.
       
  1746 
       
  1747                 props tabable:aSpec tabable.
       
  1748                 props defaultable:aSpec defaultable.
       
  1749                 props initiallyInvisible:aSpec initiallyInvisible.
       
  1750                 props aspectSelector:aSpec modelSelector.
       
  1751                 props changeSelector:aSpec changeSelector.
       
  1752                 props labelSelector:aSpec labelSelector.
       
  1753                 props menuSelector:aSpec menuSelector.
       
  1754             ].
       
  1755             self changed:#tree
       
  1756         ]
       
  1757     ].
       
  1758 
       
  1759 ! !
       
  1760 
       
  1761 !UIPainterView::ViewProperty class methodsFor:'documentation'!
       
  1762 
       
  1763 version
       
  1764     ^ '$Header$'
       
  1765 ! !
       
  1766 
    10 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
  1767 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
    11 
  1768 
    12 new
  1769 new
    13     Identifier notNil ifTrue:[Identifier := Identifier + 1]
  1770     Identifier notNil ifTrue:[Identifier := Identifier + 1]
    14                      ifFalse:[Identifier := 1].
  1771                      ifFalse:[Identifier := 1].
   147 initialize
  1904 initialize
   148     super initialize.
  1905     super initialize.
   149     identifier := Identifier
  1906     identifier := Identifier
   150 ! !
  1907 ! !
   151 
  1908 
       
  1909 !UIPainterView::GroupProperties methodsFor:'accessing'!
       
  1910 
       
  1911 controlledObjects
       
  1912     "return the value of the instance variable 'controlledObjects' (automatically generated)"
       
  1913 
       
  1914     ^ controlledObjects!
       
  1915 
       
  1916 controlledObjects:something
       
  1917     "set the value of the instance variable 'controlledObjects' (automatically generated)"
       
  1918 
       
  1919     controlledObjects := something.!
       
  1920 
       
  1921 group
       
  1922     "return the value of the instance variable 'group' (automatically generated)"
       
  1923 
       
  1924     ^ group!
       
  1925 
       
  1926 group:something
       
  1927     "set the value of the instance variable 'group' (automatically generated)"
       
  1928 
       
  1929     group := something.! !
       
  1930 
       
  1931 !UIPainterView class methodsFor:'documentation'!
       
  1932 
       
  1933 version
       
  1934     ^ '$Header$'
       
  1935 ! !