UIPainterView.st
changeset 43 3dd91a85c243
child 45 506f6af801e8
equal deleted inserted replaced
42:877a25e8f5aa 43:3dd91a85c243
       
     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 ViewPainterView subclass:#UIPainterView
       
    14 	instanceVariableNames:'fontPanel code viewProperties superclassName className methodName
       
    15 		categoryName'
       
    16 	classVariableNames:'HandCursor'
       
    17 	poolDictionaries:''
       
    18 	category:'Interface-UIPainter'
       
    19 !
       
    20 
       
    21 !UIPainterView class methodsFor:'documentation'!
       
    22 
       
    23 copyright
       
    24 "
       
    25  COPYRIGHT (c) 1995 by Claus Gittinger
       
    26 	      All Rights Reserved
       
    27 
       
    28  This software is furnished under a license and may be used
       
    29  only in accordance with the terms of that license and with the
       
    30  inclusion of the above copyright notice.   This software may not
       
    31  be provided or otherwise made available to, or used by, any
       
    32  other person.  No title to or ownership of the software is
       
    33  hereby transferred.
       
    34 "
       
    35 !
       
    36 
       
    37 documentation
       
    38 "
       
    39     not yet finished, not yet published, not yet released.
       
    40 "
       
    41 ! !
       
    42 
       
    43 !UIPainterView methodsFor:'accessing'!
       
    44 
       
    45 className
       
    46     ^ className
       
    47 
       
    48     "Modified: 5.9.1995 / 18:41:30 / claus"
       
    49 !
       
    50 
       
    51 className:aString
       
    52     className := aString
       
    53 
       
    54     "Modified: 5.9.1995 / 18:47:17 / claus"
       
    55 !
       
    56 
       
    57 methodName
       
    58     ^ methodName
       
    59 
       
    60     "Modified: 5.9.1995 / 18:41:34 / claus"
       
    61 !
       
    62 
       
    63 methodName:aString
       
    64     methodName := aString
       
    65 
       
    66     "Modified: 5.9.1995 / 18:47:27 / claus"
       
    67 ! !
       
    68 
       
    69 !UIPainterView methodsFor:'builder interface'!
       
    70 
       
    71 application
       
    72     self halt.
       
    73     ^ nil
       
    74 
       
    75     "Modified: 6.9.1995 / 00:46:44 / claus"
       
    76 !
       
    77 
       
    78 aspectAt:aSymbol
       
    79     self halt.
       
    80     ^ nil
       
    81 
       
    82     "Modified: 6.9.1995 / 00:45:35 / claus"
       
    83 !
       
    84 
       
    85 createdComponent:newView forSpec:aSpec
       
    86     "callBack from UISpec view building"
       
    87 
       
    88     |props|
       
    89 
       
    90     props := self propertiesForNewView:newView.
       
    91 
       
    92     aSpec name notNil ifTrue:[
       
    93         props name:aSpec name
       
    94     ].
       
    95 
       
    96     props labelSelector:(aSpec labelSelector).
       
    97     props aspectSelector:(aSpec modelSelector).
       
    98 
       
    99     viewProperties add:props.
       
   100 ! !
       
   101 
       
   102 !UIPainterView methodsFor:'code manipulation'!
       
   103 
       
   104 changeClass
       
   105     |box classNameHolder superclassNameHolder|
       
   106 
       
   107     classNameHolder := (className ? 'MyClass') asValue.
       
   108     superclassNameHolder := (superclassName ? 'ApplicationModel') asValue.
       
   109 
       
   110     box := DialogBox new.
       
   111     box addTextLabel:'class:'.
       
   112     box addInputFieldOn:classNameHolder.
       
   113     box addTextLabel:'super class:'.
       
   114     box addInputFieldOn:superclassNameHolder.
       
   115     box addAbortButton; addOkButton.
       
   116 
       
   117     box open.
       
   118 
       
   119     box accepted ifTrue:[
       
   120         className := classNameHolder value.
       
   121         superclassName := superclassNameHolder value.
       
   122     ].
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 !
       
   130 
       
   131 changeVariables
       
   132     | box names propList p n newName|
       
   133 
       
   134     names := VariableArray new.
       
   135     propList := VariableArray new.
       
   136     viewProperties do:[:props |
       
   137         n := props name.
       
   138         n notNil ifTrue:[
       
   139             names add:n.
       
   140             propList add:props
       
   141         ]
       
   142     ].
       
   143     box := BuilderVariablesBox new.
       
   144     box list:names.
       
   145     box selectAction:[:selection |
       
   146         p := propList at:selection
       
   147     ].
       
   148     box okAction:[
       
   149         newName := box enterValue.
       
   150 Transcript showCR:('renamed ' , (p name) , 'to:' , newName).
       
   151         p name:newName
       
   152     ].
       
   153     box showAtPointer
       
   154 
       
   155 
       
   156 
       
   157 ! !
       
   158 
       
   159 !UIPainterView methodsFor:'creating subviews'!
       
   160 
       
   161 addProperties:properties for:aView
       
   162     "set properties to a view and add properties to viewProperties.
       
   163      In case that properties are nil properties are created
       
   164     "
       
   165     |name props|
       
   166 
       
   167     (props := properties) isNil ifTrue:[
       
   168         props := self propertiesForNewView:aView.
       
   169     ].
       
   170 
       
   171     viewProperties add:props.
       
   172     name := props name.
       
   173 
       
   174     (aView respondsTo:#label:) ifTrue:[
       
   175         aView label:name
       
   176     ].
       
   177     aView name:name.
       
   178   ^ props
       
   179 !
       
   180 
       
   181 initializeCreatedObject:anObject
       
   182     "set default properties for a created object
       
   183     "
       
   184     |props|
       
   185 
       
   186     props := self addProperties:nil for:anObject.
       
   187     self undoCreate:(props identifier).
       
   188 !
       
   189 
       
   190 propertiesForNewView:aView
       
   191     |cls props index|
       
   192 
       
   193     cls := aView class.
       
   194 
       
   195     props := ViewProperty new.
       
   196     props view:aView.
       
   197     props elementClass:cls.
       
   198     index := self variableIndexForClass:cls.
       
   199     props nameIndex:index.
       
   200     props name:(self variableNameForClass:cls index:index).
       
   201 
       
   202 "/    props initCode:nil.       --- add user-defined init code later
       
   203 
       
   204     ^ props
       
   205 ! !
       
   206 
       
   207 !UIPainterView methodsFor:'cut & paste'!
       
   208 
       
   209 copySelection
       
   210     "copy the selection into the cut&paste-buffer
       
   211     "
       
   212     |tmp|
       
   213 
       
   214     tmp := OrderedCollection new.
       
   215 
       
   216     self selectionDo:[:aView||topSpec|
       
   217         topSpec := aView specClass 
       
   218                         fromView:aView 
       
   219                         callBack:[:spec :aSubView | 
       
   220                                 aSubView geometryLayout:(aSubView geometryLayout copy)
       
   221                         ].
       
   222         tmp add:topSpec.
       
   223     ].
       
   224 
       
   225     self setSelection:tmp
       
   226 
       
   227 !
       
   228 
       
   229 pasteBuffer
       
   230     "add the objects in the paste-buffer
       
   231     "
       
   232 
       
   233     |sel|
       
   234 
       
   235     Transcript showCR:'pasteBuffer'.
       
   236     sel := self getSelection.
       
   237     self unselect.
       
   238     sel do:[:aSpec |
       
   239         self createFromSpec:aSpec
       
   240     ]
       
   241 ! !
       
   242 
       
   243 !UIPainterView methodsFor:'draw-object initialization'!
       
   244 
       
   245 setupCreatedObject
       
   246     ^ self
       
   247 ! !
       
   248 
       
   249 !UIPainterView methodsFor:'generating output'!
       
   250 
       
   251 generateClassDefinition
       
   252     |defCode|
       
   253 
       
   254     defCode := superclassName , ' subclass:#' , className , '\'.
       
   255     defCode := defCode , '  instanceVariableNames:'''.
       
   256     defCode := defCode , self subviewVariableNames , '''\'.
       
   257     defCode := defCode , '  classVariableNames:''''\'.
       
   258     defCode := defCode , '  poolDictionaries:''''\'.
       
   259     defCode := defCode , '  category:''' , categoryName , '''\'.
       
   260     defCode := defCode , Character excla asString , '\\'.
       
   261 
       
   262     code := code , (defCode withCRs)
       
   263 
       
   264 
       
   265 
       
   266 !
       
   267 
       
   268 generateCode
       
   269     code := ''.
       
   270     (Smalltalk classNamed:className) isNil ifTrue:[
       
   271         self generateClassDefinition.
       
   272     ].
       
   273 "/    self generateInitMethod.
       
   274     code := code , self generateWindowSpec.
       
   275     self generateOutlets.
       
   276 
       
   277 
       
   278     ^ code withCRs
       
   279 
       
   280     "Modified: 5.9.1995 / 20:57:53 / claus"
       
   281 ! !
       
   282 
       
   283 !UIPainterView ignoredMethodsFor:'generating output'!
       
   284 
       
   285 generateInitCodeForGroup:aGroup
       
   286     |c name p objects outlets moreCode sym typ val|
       
   287 
       
   288     " <name> := <GroupClass> in:<name-of-superview>"
       
   289 
       
   290     p := self propertyOfGroup:aGroup.
       
   291     name := p at:#variableName.
       
   292     c := '  ' , name , ' := ' , (aGroup class name) , ' new.\'.
       
   293 
       
   294     code := code , c withCRs.
       
   295 
       
   296     " <name> <symbol>:<value>"
       
   297 
       
   298     objects := p at:#controlledObjects ifAbsent:[nil].
       
   299     objects notNil ifTrue:[
       
   300 	objects do:[:controlledObject |
       
   301 	    c := c , name , ' add:' , (self variableNameOf:controlledObject) , '.\'
       
   302 	]
       
   303     ].
       
   304 
       
   305     code := code , c withCRs
       
   306 
       
   307 
       
   308 
       
   309 
       
   310 
       
   311 !
       
   312 
       
   313 generateInitCodeForOtherStuff
       
   314     |g c name p outlets moreCode sym typ val|
       
   315 
       
   316     "generate code for groups"
       
   317 
       
   318     viewProperties do:[:props |
       
   319 	g := props at:#group ifAbsent:[nil].
       
   320 	g notNil ifTrue:[
       
   321 	    self generateInitCodeForGroup:g
       
   322 	]
       
   323     ]
       
   324 
       
   325 
       
   326 !
       
   327 
       
   328 generateInitCodeForView:aView
       
   329     |c name p outlets moreCode sym typ val|
       
   330 
       
   331     " <name> := <ViewClass> in:<name-of-superview>"
       
   332 
       
   333     p := self propertyOfView:aView.
       
   334     name := p at:#variableName.
       
   335     c := '    ' , name , ' := ' ,
       
   336 	 (aView class name) , ' in:' , (self variableNameOf:(aView superView)) , '.\'.
       
   337 
       
   338     " <name> origin:(...) extent:(...)"
       
   339 
       
   340     c := c , '    ' , name , ' origin:(', aView origin printString , ')'
       
   341 		    , ' extent:(', aView extent printString , ').\'.
       
   342 
       
   343     moreCode := p at:#initCode ifAbsent:nil.
       
   344     moreCode notNil ifTrue:[
       
   345 	c := c , moreCode , '\' withCRs
       
   346     ].
       
   347 
       
   348     code := code , c withCRs.
       
   349 
       
   350     " <name> <symbol>:<value>"
       
   351 
       
   352     outlets := p at:#outlets ifAbsent:[nil].
       
   353     outlets notNil ifTrue:[
       
   354 	outlets do:[:selectorOutlet |
       
   355 	    sym := selectorOutlet at:#selector.
       
   356 	    typ := selectorOutlet at:#type.
       
   357 	    val := selectorOutlet at:#value.
       
   358 	    c :=  '    ' , name , ' ' , sym.
       
   359 	    (typ == #number) ifTrue:[
       
   360 		c := c , val printString
       
   361 	    ].
       
   362 	    (typ == #string) ifTrue:[
       
   363 		c := c , '''' , val , ''''
       
   364 	    ].
       
   365 	    (typ == #text) ifTrue:[
       
   366 		c := c , '''' , val asString , ''''
       
   367 	    ].
       
   368 	    (typ == #strings) ifTrue:[
       
   369 		c := c , '#( '.
       
   370 		val asText do:[:aString |
       
   371 		    c := c , '''' , aString , ''' '
       
   372 		].
       
   373 		c := c , ')'
       
   374 	    ].
       
   375 	    (typ == #block) ifTrue:[
       
   376 		c := c , val
       
   377 	    ].
       
   378 	    (typ == #color) ifTrue:[
       
   379 		c := c , '(Color name:''' , val , ''')'
       
   380 	    ].
       
   381 	    c := c , '.' , Character cr asString.
       
   382 	    code := code , c
       
   383 	]
       
   384     ].
       
   385 
       
   386     self subviewsOf:aView do:[:v |
       
   387 	self generateInitCodeForView:v
       
   388     ]
       
   389 
       
   390     "Modified: 5.9.1995 / 20:06:07 / claus"
       
   391 !
       
   392 
       
   393 generateInitMethod
       
   394     |defCode|
       
   395 
       
   396     defCode := Character excla asString ,
       
   397 	       className , ' methodsFor:''initialization''' ,
       
   398 	       Character excla asString , '\\'.
       
   399 
       
   400     defCode := defCode , 'initialize\'.
       
   401     defCode := defCode , '    super initialize.\'.
       
   402     defCode := defCode , '    self setupSubViews.\'.
       
   403     defCode := defCode , '    self setupLocalStuff\'.
       
   404     defCode := defCode , Character excla asString , '\\'.
       
   405 
       
   406     defCode := defCode , 'setupSubViews\'.
       
   407     code := code , defCode withCRs.
       
   408 
       
   409     self subviewsOf:self do:[:v |
       
   410 	self generateInitCodeForView:v
       
   411     ].
       
   412 
       
   413     self generateInitCodeForOtherStuff.
       
   414 
       
   415     code := code , '    ^ self\' withCRs.
       
   416 
       
   417     defCode := Character excla asString , '\\'.
       
   418     defCode := defCode , 'setupLocalStuff\'.
       
   419     defCode := defCode , '    ^ self\'.
       
   420     defCode := defCode , Character excla asString , ' ' ,
       
   421 			 Character excla asString , '\\'.
       
   422 
       
   423     code := code , defCode withCRs
       
   424 
       
   425 
       
   426 
       
   427 
       
   428 
       
   429 ! !
       
   430 
       
   431 !UIPainterView methodsFor:'generating output'!
       
   432 
       
   433 generateOutlets
       
   434     ^ self
       
   435 !
       
   436 
       
   437 generateWindowSpec
       
   438     |spec specArray str|
       
   439 
       
   440     subViews remove:inputView.
       
   441     [
       
   442         spec := FullSpec fromView:self callBack:[:newSpec :view | self stuffPropertiesFrom:view intoSpec:newSpec].
       
   443     ] valueNowOrOnUnwindDo:[
       
   444         subViews addFirst:inputView.
       
   445     ].
       
   446 
       
   447     specArray := spec literalArrayEncoding.
       
   448     str := WriteStream on:String new.
       
   449     self prettyPrintSpecArray:specArray on:str indent:5.
       
   450 
       
   451     code := Character excla asString 
       
   452             , className , ' class methodsFor:''interface specs'''
       
   453             , Character excla asString , '\\'
       
   454 
       
   455             , methodName , '\'
       
   456             , '    "this window spec was automatically generated by the ST/X UIPainter"\\'
       
   457             , '    "do not manually edit this - the painter/builder may not be able to\'
       
   458             , '     handle the specification if its corrupted."\\'
       
   459             , '    "UIPainter new openOnClass:' , className , ' andSelector:#' , methodName , '"\'
       
   460             , '    "' , className , ' new openInterface:#' , methodName , '"\'.
       
   461 
       
   462     methodName = 'windowSpec' ifTrue:[
       
   463         code := code , '    "' , className , ' open"\'
       
   464     ].
       
   465     code := code 
       
   466             , '\'
       
   467             , '    <resource: #canvas>\\'
       
   468             , '    ^\' 
       
   469             , '     ', str contents
       
   470             , '\'
       
   471             , Character excla asString
       
   472             , ' '
       
   473             , Character excla asString
       
   474             , '\\'.
       
   475 
       
   476     ^ code withCRs
       
   477 
       
   478     "Modified: 5.9.1995 / 21:01:35 / claus"
       
   479 !
       
   480 
       
   481 nameOfClass
       
   482     ^ 'NewView'
       
   483 !
       
   484 
       
   485 outletValueOf:aSymbol for:aView
       
   486 "/    |c name p outlets moreCode sym typ val|
       
   487 "/
       
   488 "/    p := self propertyOfView:aView.
       
   489 "/    outlets := p at:#outlets ifAbsent:[^ nil].
       
   490 "/    outlets notNil ifTrue:[
       
   491 "/        outlets do:[:selectorOutlet |
       
   492 "/            sym := selectorOutlet at:#selector.
       
   493 "/            (sym == aSymbol) ifTrue:[
       
   494 "/                typ := selectorOutlet at:#type.
       
   495 "/                val := selectorOutlet at:#value.
       
   496 "/                ^ val
       
   497 "/            ]
       
   498 "/        ]
       
   499 "/    ].
       
   500     ^ nil
       
   501 
       
   502 
       
   503 
       
   504 
       
   505 !
       
   506 
       
   507 prettyPrintSpecArray:spec on:aStream indent:i
       
   508     "just for your convenience: prettyPrint a specArray to aStream - it looks better that way"
       
   509 
       
   510     |what oneLine|
       
   511 
       
   512     spec isArray ifFalse:[
       
   513         spec isLiteral ifTrue:[
       
   514             aStream nextPutAll:spec storeString
       
   515         ] ifFalse:[
       
   516             self halt.
       
   517         ].
       
   518         ^ self
       
   519     ].
       
   520 
       
   521     spec isEmpty ifTrue:[
       
   522         aStream nextPutAll:'#()'.
       
   523         ^ self
       
   524     ].
       
   525 
       
   526     what := spec at:1.
       
   527     what isArray ifTrue:[
       
   528         aStream cr; spaces:i+2.
       
   529         aStream nextPutAll:'#('.
       
   530         "/ a spec-collection
       
   531         spec do:[:element |
       
   532             self prettyPrintSpecArray:element on:aStream indent:i+2.
       
   533         ].
       
   534         aStream cr.
       
   535         aStream spaces:i+1.
       
   536         aStream nextPutAll:')'.
       
   537         ^ self.
       
   538     ].
       
   539 
       
   540     oneLine := false.
       
   541     (#(#LayoutFrame #LayoutOrigin #AlignmentOrigin 
       
   542        #Rectangle #Point
       
   543        #Color #ColorValue
       
   544     ) 
       
   545     includesIdentical:what) ifTrue:[
       
   546         oneLine := true
       
   547     ].
       
   548 
       
   549     oneLine ifFalse:[
       
   550         aStream cr.
       
   551         aStream spaces:i+2.
       
   552     ].
       
   553     aStream nextPutAll:'#('.
       
   554 
       
   555 
       
   556     aStream nextPutAll:what storeString.
       
   557 
       
   558     oneLine ifFalse:[
       
   559         aStream cr.
       
   560         aStream spaces:i+4.
       
   561     ].
       
   562 
       
   563     2 to:spec size do:[:index |
       
   564         aStream space.
       
   565         self prettyPrintSpecArray:(spec at:index) on:aStream indent:i+4.
       
   566         oneLine ifFalse:[
       
   567             (index odd and:[index ~~ (spec size)]) ifTrue:[
       
   568                 aStream cr; spaces:i+4.
       
   569             ]
       
   570         ]
       
   571     ].
       
   572     oneLine ifFalse:[
       
   573         aStream cr.
       
   574         aStream spaces:i+1.
       
   575     ].
       
   576     aStream nextPutAll:')'.
       
   577 
       
   578     "Modified: 5.9.1995 / 17:44:20 / claus"
       
   579 !
       
   580 
       
   581 storeContentsOn:aStream
       
   582     viewProperties do:[:p| p storeOn:aStream]
       
   583 !
       
   584 
       
   585 stuffPropertiesFrom:view intoSpec:newSpec
       
   586     "stuff any additional information (held in the properties) into the spec
       
   587      which was just created from view"
       
   588 
       
   589     |props aspectSelector changeSelector labelSelector name|
       
   590 
       
   591     props := self propertyOfView:view.
       
   592     props isNil ifTrue:[^ self].
       
   593 
       
   594     (aspectSelector := props aspectSelector) notNil ifTrue:[
       
   595         newSpec model:aspectSelector
       
   596     ].
       
   597     (changeSelector := props changeSelector) notNil ifTrue:[
       
   598         newSpec change:changeSelector
       
   599     ].
       
   600     (labelSelector := props labelSelector) notNil ifTrue:[
       
   601         newSpec label:labelSelector
       
   602     ].
       
   603     (name := props name) notNil ifTrue:[
       
   604         newSpec name:name
       
   605     ].
       
   606 
       
   607 !
       
   608 
       
   609 subviewVariableNames
       
   610     |names|
       
   611 
       
   612     names := ''.
       
   613     viewProperties do:[:p| names := names , ' ' , (p name)].
       
   614   ^ names
       
   615 !
       
   616 
       
   617 subviewsOf:aView do:aBlock
       
   618     |subs v|
       
   619 
       
   620     (subs := aView subViews) notNil ifTrue:[
       
   621         subs do:[:v|
       
   622             (v ~~ inputView and:[v notNil]) ifTrue:[
       
   623                 (viewProperties detect:[:p | p view == v] ifNone:nil) notNil ifTrue:[ 
       
   624                     (v superView == aView) ifTrue:[
       
   625                         aBlock value:v
       
   626                     ]
       
   627                 ]
       
   628             ]
       
   629         ]
       
   630     ]
       
   631 
       
   632 ! !
       
   633 
       
   634 !UIPainterView methodsFor:'group manipulations'!
       
   635 
       
   636 groupEnterFields
       
   637     |props name index group objects|
       
   638 
       
   639     selection isNil ifTrue:[^ self].
       
   640     self selectionDo:[:aView |
       
   641         (aView isKindOf:EditField) ifFalse:[
       
   642             self warn:'select EditFields only !!'.
       
   643             ^ self
       
   644         ]
       
   645     ].
       
   646     self selectionHiddenDo:[
       
   647         group := EnterFieldGroup new.
       
   648 
       
   649         props := GroupProperties new.
       
   650         props elementClass:EnterFieldGroup.
       
   651         props group:group.
       
   652         index := self variableIndexForClass:EnterFieldGroup.
       
   653         props nameIndex:index.
       
   654         name := self variableNameForClass:EnterFieldGroup index:index.
       
   655         props name:name.
       
   656         objects := OrderedCollection new.
       
   657         props controlledObjects:objects.
       
   658         viewProperties add:props.
       
   659 
       
   660         self selectionDo:[:aView |
       
   661             objects add:aView.
       
   662             group add:aView
       
   663         ].
       
   664     ]
       
   665 
       
   666 
       
   667 !
       
   668 
       
   669 groupRadioButtons
       
   670     |props name index group objects|
       
   671 
       
   672     selection isNil ifTrue:[^ self].
       
   673     self selectionDo:[:aView |
       
   674         (aView isKindOf:RadioButton) ifFalse:[
       
   675             self warn:'select RadioButtons only !!'.
       
   676             ^ self
       
   677         ]
       
   678     ].
       
   679     self selectionHiddenDo:[
       
   680 
       
   681         group := RadioButtonGroup new.
       
   682 
       
   683         props := GroupProperties new.
       
   684         props elementClass:RadioButtonGroup.
       
   685         props group:group.
       
   686         index := self variableIndexForClass:RadioButtonGroup.
       
   687         props nameIndex:index.
       
   688         name := self variableNameForClass:RadioButtonGroup index:index.
       
   689         props name:name.
       
   690         group groupID:name asSymbol.
       
   691         objects := OrderedCollection new.
       
   692         props controlledObjects:objects.
       
   693         viewProperties add:props.
       
   694 
       
   695         self selectionDo:[:aView |
       
   696             aView turnOff.
       
   697             objects add:aView.
       
   698             group add:aView
       
   699         ].
       
   700     ]
       
   701 
       
   702     "Modified: 5.9.1995 / 16:06:15 / claus"
       
   703 ! !
       
   704 
       
   705 !UIPainterView methodsFor:'initialization'!
       
   706 
       
   707 initialize
       
   708     super initialize.
       
   709 
       
   710     superclassName := 'ApplicationModel'.
       
   711     className := 'NewApplication'.
       
   712     methodName := 'windowSpec'.
       
   713     categoryName := 'Applications'.
       
   714 
       
   715     pressAction := [:pressPoint | self startSelectOrMove:pressPoint].
       
   716     shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint].
       
   717     motionAction := [:movePoint | true].
       
   718     releaseAction := [true].
       
   719     keyPressAction := [:key | self doKeyInput:key].
       
   720 
       
   721     viewProperties := OrderedCollection new.
       
   722 
       
   723     HandCursor := Cursor leftHand.
       
   724 
       
   725     "Modified: 5.9.1995 / 19:58:06 / claus"
       
   726 !
       
   727 
       
   728 initializeMiddleButtonMenu
       
   729     |labels|
       
   730 
       
   731     labels := resources array:#(
       
   732 			'copy'
       
   733 			'cut'
       
   734 			'paste'
       
   735 			'-'
       
   736 			'save'
       
   737 			'print'
       
   738 			'-'
       
   739 			'inspect'
       
   740 		      ).
       
   741 
       
   742     self middleButtonMenu:(PopUpMenu
       
   743 				labels:labels
       
   744 			     selectors:#(
       
   745 					 copySelection
       
   746 					 deleteSelection
       
   747 					 pasteBuffer
       
   748 					 nil               
       
   749 					 save
       
   750 					 print
       
   751 					 nil               
       
   752 					 inspectSelection
       
   753 					)
       
   754 				receiver:self
       
   755 				     for:self)
       
   756 
       
   757 ! !
       
   758 
       
   759 !UIPainterView methodsFor:'interface to Builder'!
       
   760 
       
   761 addOutletDefinitionFor:outletSymbol type:type value:outletValue for:aView
       
   762     |outletProps selectorProps viewProps|
       
   763 
       
   764     viewProps := self propertyOfView:aView.
       
   765 "/    outletProps := viewProps at:#outlets ifAbsent:[nil].
       
   766 "/    outletProps isNil ifTrue:[
       
   767 "/        outletProps := Dictionary new.
       
   768 "/        viewProps at:#outlets put:outletProps
       
   769 "/    ].
       
   770 "/    selectorProps := outletProps at:outletSymbol ifAbsent:[nil].
       
   771 "/    selectorProps isNil ifTrue:[
       
   772 "/        selectorProps := Dictionary new.
       
   773 "/        outletProps at:outletSymbol put:selectorProps
       
   774 "/    ].
       
   775 "/
       
   776 "/    selectorProps at:#selector put:outletSymbol.
       
   777 "/    selectorProps at:#type put:type.
       
   778 "/    selectorProps at:#value put:outletValue
       
   779 
       
   780 !
       
   781 
       
   782 addSpec:specOrSpecArray
       
   783     |spec builder|
       
   784 
       
   785     spec := UISpecification from:specOrSpecArray.
       
   786 
       
   787     builder := UIBuilder new.
       
   788     builder componentCreationHook:[:view :spec :aBuilder |
       
   789                 self createdComponent:view forSpec:spec
       
   790             ].
       
   791     builder applicationClass:(Smalltalk classNamed:className).
       
   792     spec setupView:self for:builder.
       
   793     self realizeAllSubViews.
       
   794     inputView raise.
       
   795 
       
   796 "/    viewProperties := OrderedCollection new.
       
   797 "/    self generatePropertiesFor:(self subViews select:[:v | v ~~ inputView]).
       
   798 
       
   799     self changed:#tree.
       
   800 
       
   801 
       
   802     "Modified: 5.9.1995 / 23:36:55 / claus"
       
   803 !
       
   804 
       
   805 applicationName
       
   806     ^ className
       
   807 !
       
   808 
       
   809 aspectSelectorForView:aView
       
   810     |props aspect|
       
   811 
       
   812     props := self propertyOfView:aView.
       
   813     props isNil ifTrue:[^ nil].
       
   814     ^ props aspectSelector
       
   815 
       
   816 !
       
   817 
       
   818 changeSelectorForView:aView
       
   819     |props aspect|
       
   820 
       
   821     props := self propertyOfView:aView.
       
   822     props isNil ifTrue:[^ nil].
       
   823 "/    ^ props changeSelector
       
   824     ^ nil
       
   825 !
       
   826 
       
   827 createFromSpec:specOrSpecArray
       
   828     |spec builder v|
       
   829 
       
   830     spec := UISpecification from:specOrSpecArray.
       
   831 
       
   832     builder := UIBuilder new.
       
   833     builder componentCreationHook:[:view :spec :aBuilder |
       
   834                 self createdComponent:view forSpec:spec
       
   835             ].
       
   836     builder applicationClass:(Smalltalk classNamed:className).
       
   837     v := spec buildViewWithLayoutFor:builder in:self.
       
   838     self realizeAllSubViews.
       
   839     inputView raise.
       
   840 
       
   841     self changed:#tree.
       
   842 
       
   843 
       
   844     "Modified: 5.9.1995 / 23:36:55 / claus"
       
   845 !
       
   846 
       
   847 generatePropertiesFor:aCollectionOfViews
       
   848 
       
   849     "/ done as two loops, to get bread-first naming
       
   850 
       
   851     aCollectionOfViews do:[:aView|
       
   852         |props|
       
   853 
       
   854         props := self propertiesForNewView:aView.
       
   855         viewProperties add:props.
       
   856         aView name:(props name).
       
   857 
       
   858         aView geometryLayout isNil ifTrue:[
       
   859             aView geometryLayout:(aView bounds asLayout).
       
   860         ]
       
   861     ].
       
   862 
       
   863     aCollectionOfViews do:[:aView |
       
   864         |subs|
       
   865 
       
   866         subs := aView subViews.
       
   867         subs notNil ifTrue:[
       
   868             self generatePropertiesFor:subs
       
   869         ]
       
   870     ].
       
   871 
       
   872 !
       
   873 
       
   874 inspectAttributes
       
   875     |p|
       
   876 
       
   877     self singleSelectionDo:[:aView |
       
   878         p := self propertyOfView:aView.
       
   879         p inspect
       
   880     ]
       
   881 !
       
   882 
       
   883 setAspectSelector:aspectSymbol forView:aView
       
   884     |props|
       
   885 
       
   886     props := self propertyOfView:aView.
       
   887 
       
   888     undoHistory transactionNamed:'aspect' do:[
       
   889         self selectionDo:[:aView|
       
   890             undoHistory isTransactionOpen ifTrue:[
       
   891                 |oldAspect|
       
   892 
       
   893                 oldAspect := props aspectSelector.
       
   894                 undoHistory addUndoBlock:[
       
   895                     props aspectSelector:oldAspect.
       
   896                     self elementChanged:aView.
       
   897                 ]
       
   898             ].
       
   899         ].
       
   900     ].
       
   901 
       
   902     props aspectSelector:aspectSymbol
       
   903 
       
   904 !
       
   905 
       
   906 setChangeSelector:changeSymbol forView:aView
       
   907     |props|
       
   908 
       
   909     props := self propertyOfView:aView.
       
   910     props changeSelector:changeSymbol
       
   911 
       
   912 !
       
   913 
       
   914 setupFromSpec:specOrSpecArray
       
   915     self removeAll.
       
   916     self addSpec:specOrSpecArray
       
   917 !
       
   918 
       
   919 showFontPanel
       
   920     |action|
       
   921 
       
   922     fontPanel isNil ifTrue:[
       
   923 	fontPanel := FontPanel new 
       
   924     ].
       
   925 
       
   926     selection notNil ifTrue:[
       
   927 	action := [:family :face :style :size |
       
   928 		       self changeFontFamily:family face:face
       
   929 				       style:style size:size
       
   930 		  ].
       
   931 	fontPanel action:action.
       
   932 	fontPanel showAtPointer
       
   933     ]
       
   934 ! !
       
   935 
       
   936 !UIPainterView methodsFor:'misc'!
       
   937 
       
   938 changeFontFamily:family face:face style:style size:size
       
   939     |f|
       
   940 
       
   941     f := Font family:family
       
   942                 face:face
       
   943                style:style
       
   944                 size:size.
       
   945 
       
   946     f notNil ifTrue:[
       
   947         self selectionHiddenDo:[
       
   948             self selectionDo:[:aView |
       
   949                 aView font:f.
       
   950                 self elementChanged:aView.
       
   951             ]
       
   952         ]
       
   953     ]
       
   954 
       
   955     "Modified: 5.9.1995 / 12:13:27 / claus"
       
   956 !
       
   957 
       
   958 changeVariableNameOf:aView to:newName
       
   959     |prop|
       
   960 
       
   961     prop := self propertyOf:aView.
       
   962 
       
   963     prop isNil ifTrue:[
       
   964         ^ self error:'no such view'
       
   965     ].
       
   966 
       
   967     ((aView respondsTo:#label:) and:[aView label = prop name]) ifTrue:[
       
   968         self selectionHiddenDo:[
       
   969             |layout|
       
   970             layout := aView geometryLayout copy.
       
   971             aView label:newName.
       
   972             aView geometryLayout:layout.
       
   973         ]
       
   974     ].
       
   975 
       
   976     prop  name:newName.
       
   977     aView name:newName.
       
   978     self changed:#widgetName
       
   979 
       
   980 
       
   981 
       
   982 !
       
   983 
       
   984 propertyOf:something
       
   985 
       
   986     ^ viewProperties detect:[:p| (p view == something or:[p group == something])]
       
   987                      ifNone:nil
       
   988 
       
   989 
       
   990 
       
   991 
       
   992 
       
   993 !
       
   994 
       
   995 propertyOfGroup:aGroup
       
   996 
       
   997     ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil
       
   998 !
       
   999 
       
  1000 propertyOfName:aString
       
  1001 
       
  1002     aString = 'self' ifFalse:[
       
  1003         ^ viewProperties detect:[:p| p name = aString] ifNone:nil
       
  1004     ].
       
  1005     ^ nil
       
  1006 !
       
  1007 
       
  1008 propertyOfView:aView
       
  1009 
       
  1010     aView == self ifFalse:[
       
  1011         ^ viewProperties detect:[:p| p view == aView] ifNone:nil
       
  1012     ].
       
  1013     ^ nil
       
  1014 !
       
  1015 
       
  1016 removePropertyOf:aView
       
  1017     |p|
       
  1018 
       
  1019     p := self propertyOf:aView.
       
  1020     p notNil ifTrue:[viewProperties remove:p]
       
  1021 
       
  1022 
       
  1023 !
       
  1024 
       
  1025 variableIndexForClass:aClass
       
  1026     |max|
       
  1027 
       
  1028     max := 0.
       
  1029 
       
  1030     viewProperties do:[:p|
       
  1031         p elementClass == aClass ifTrue:[
       
  1032             max := max max:(p nameIndex)
       
  1033         ]
       
  1034     ].
       
  1035     ^ max + 1
       
  1036 
       
  1037 !
       
  1038 
       
  1039 variableNameForClass:aClass index:index
       
  1040     |n|
       
  1041 
       
  1042     n := (aClass name) , index printString.
       
  1043     n at:1 put:(n at:1) asLowercase.
       
  1044   ^ n
       
  1045 
       
  1046 !
       
  1047 
       
  1048 variableNameOf:aView
       
  1049     |prop|
       
  1050 
       
  1051     aView notNil ifTrue:[
       
  1052         prop := self propertyOf:aView
       
  1053     ].
       
  1054 
       
  1055     prop notNil ifTrue:[^ prop name]
       
  1056                ifFalse:[^ 'self']
       
  1057 
       
  1058 ! !
       
  1059 
       
  1060 !UIPainterView methodsFor:'private undo-actions'!
       
  1061 
       
  1062 undoCreate:aViewIdentifier
       
  1063 
       
  1064     undoHistory isTransactionOpen ifTrue:[
       
  1065         undoHistory addUndoBlock:[
       
  1066             |p|
       
  1067 
       
  1068             p := viewProperties detect:[:p| p identifier == aViewIdentifier]
       
  1069                                 ifNone:nil.
       
  1070 
       
  1071             p notNil ifTrue:[
       
  1072                 self removeObject:(p view)
       
  1073             ]
       
  1074         ]
       
  1075     ]
       
  1076 !
       
  1077 
       
  1078 undoRemove:propertyOfView
       
  1079     |clsName layout parent aView|
       
  1080 
       
  1081     undoHistory isTransactionOpen ifFalse:[
       
  1082         ^ self
       
  1083     ].
       
  1084 
       
  1085     aView   := propertyOfView view.
       
  1086     clsName := aView class.
       
  1087     layout  := aView geometryLayout.
       
  1088     parent  := aView superView.
       
  1089 
       
  1090     parent ~~ self ifTrue:[
       
  1091         parent := (self propertyOf:parent) identifier.
       
  1092     ] ifFalse:[
       
  1093         parent := nil
       
  1094     ].
       
  1095 
       
  1096     propertyOfView view:nil.    
       
  1097 
       
  1098     undoHistory addUndoBlock:[
       
  1099         |recreatedView props|
       
  1100 
       
  1101         parent notNil ifTrue:[
       
  1102             props := viewProperties detect:[:p| p identifier == parent] ifNone:nil.
       
  1103 
       
  1104             props notNil ifTrue:[parent := props view]
       
  1105                         ifFalse:[parent := self]
       
  1106         ] ifFalse:[
       
  1107             parent := self
       
  1108         ].
       
  1109 
       
  1110         recreatedView := clsName in:parent.
       
  1111         recreatedView geometryLayout:layout.
       
  1112         propertyOfView view:recreatedView.    
       
  1113         self addProperties:propertyOfView for:recreatedView.
       
  1114         recreatedView realize.
       
  1115         inputView raise.
       
  1116         self changed:#tree.
       
  1117     ].
       
  1118     aView := nil.
       
  1119 
       
  1120 ! !
       
  1121 
       
  1122 !UIPainterView methodsFor:'removing components'!
       
  1123 
       
  1124 remove:something
       
  1125     "remove something, anObject or a collection of objects from the contents
       
  1126      do redraw"
       
  1127 
       
  1128     self forEach:something do:[:anObject |
       
  1129 	self removeObject:anObject
       
  1130     ]
       
  1131 
       
  1132 
       
  1133 !
       
  1134 
       
  1135 removeAll
       
  1136     "remove the argument, anObject"
       
  1137 
       
  1138     self unselect.
       
  1139 
       
  1140     subViews notNil ifTrue:[
       
  1141         subViews copy do:[:sub |
       
  1142             sub ~~ inputView ifTrue:[   
       
  1143                 self removeTreeFrom:sub
       
  1144             ]
       
  1145         ]
       
  1146     ].
       
  1147 
       
  1148     viewProperties := OrderedCollection new.
       
  1149     undoHistory reinitialize.
       
  1150 
       
  1151     self changed:#tree
       
  1152 
       
  1153     "Modified: 5.9.1995 / 23:39:08 / claus"
       
  1154 !
       
  1155 
       
  1156 removeObject:anObject
       
  1157     "remove the argument, anObject"
       
  1158 
       
  1159     self removeTreeFrom:anObject.
       
  1160     self changed:#tree
       
  1161 
       
  1162     "Modified: 5.9.1995 / 20:51:28 / claus"
       
  1163 !
       
  1164 
       
  1165 removeTreeFrom:anObject
       
  1166     "remove the argument, anObject and all of its children
       
  1167     "
       
  1168     anObject isNil ifTrue:[
       
  1169         ^ self
       
  1170     ].
       
  1171 
       
  1172     (anObject subViews notNil) ifTrue:[
       
  1173         anObject subViews copy do:[:sub |
       
  1174             self removeTreeFrom:sub
       
  1175         ]
       
  1176     ].
       
  1177 
       
  1178     self undoRemove:(self propertyOf:anObject).
       
  1179     self removePropertyOf:anObject.
       
  1180     anObject destroy
       
  1181 ! !
       
  1182 
       
  1183 !UIPainterView methodsFor:'selections'!
       
  1184 
       
  1185 addNameToSelection:aString
       
  1186     |prop|
       
  1187 
       
  1188     prop := self propertyOfName:aString.
       
  1189 
       
  1190     prop notNil ifTrue:[
       
  1191         self addToSelection:(prop view)
       
  1192     ]
       
  1193 
       
  1194 !
       
  1195 
       
  1196 removeNameFromSelection:aString
       
  1197     |prop|
       
  1198 
       
  1199     prop := self propertyOfName:aString.
       
  1200 
       
  1201     prop notNil ifTrue:[
       
  1202         self removeFromSelection:(prop view)
       
  1203     ]
       
  1204 
       
  1205 !
       
  1206 
       
  1207 selectName:aString
       
  1208     |prop|
       
  1209 
       
  1210     prop := self propertyOfName:aString.
       
  1211 
       
  1212     prop notNil ifTrue:[
       
  1213         self select:(prop view)
       
  1214     ] ifFalse:[
       
  1215         self unselect
       
  1216     ]
       
  1217 ! !
       
  1218 
       
  1219 !UIPainterView methodsFor:'testing'!
       
  1220 
       
  1221 isHorizontalResizable:aComponent
       
  1222 
       
  1223     (aComponent isKindOf:ScrollBar) ifTrue:[
       
  1224         ^ aComponent orientation == #horizontal
       
  1225     ].
       
  1226     (aComponent isKindOf:Scroller) ifTrue:[
       
  1227         ^ aComponent orientation == #horizontal
       
  1228     ].
       
  1229     (aComponent isKindOf:Slider) ifTrue:[
       
  1230         ^ aComponent orientation == #horizontal
       
  1231     ].
       
  1232     ^ true
       
  1233 
       
  1234 
       
  1235 !
       
  1236 
       
  1237 isVerticalResizable:aComponent
       
  1238 
       
  1239     (aComponent isKindOf:EditField) ifTrue:[
       
  1240         ^ false
       
  1241     ].
       
  1242     (aComponent isKindOf:ScrollBar) ifTrue:[
       
  1243         ^ aComponent orientation == #vertical
       
  1244     ].
       
  1245     (aComponent isKindOf:Scroller) ifTrue:[
       
  1246         ^ aComponent orientation == #vertical
       
  1247     ].
       
  1248     (aComponent isKindOf:Slider) ifTrue:[
       
  1249         ^ aComponent orientation == #vertical
       
  1250     ].
       
  1251     ^ true
       
  1252 
       
  1253 
       
  1254 ! !
       
  1255 
       
  1256 !UIPainterView class methodsFor:'documentation'!
       
  1257 
       
  1258 version
       
  1259     ^ '$Header$'
       
  1260 ! !