UIPainterView.st
changeset 111 c6699a14d3d9
parent 103 139c7537c6b6
child 115 e4200c506aad
equal deleted inserted replaced
110:a00f1446c10b 111:c6699a14d3d9
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 UIObjectView subclass:#UIPainterView
    13 UIObjectView subclass:#UIPainterView
    14 	instanceVariableNames:'viewProperties superclassName className methodName categoryName'
    14 	instanceVariableNames:'listHolder superclassName className methodName categoryName'
    15 	classVariableNames:'HandCursor'
    15 	classVariableNames:'HandCursor'
    16 	poolDictionaries:''
    16 	poolDictionaries:''
    17 	category:'Interface-UIPainter'
    17 	category:'Interface-UIPainter'
    18 !
    18 !
    19 
    19 
    24 	privateIn:UIPainterView
    24 	privateIn:UIPainterView
    25 !
    25 !
    26 
    26 
    27 UIPainterView::ViewProperty subclass:#GroupProperties
    27 UIPainterView::ViewProperty subclass:#GroupProperties
    28 	instanceVariableNames:'controlledObjects group name'
    28 	instanceVariableNames:'controlledObjects group name'
       
    29 	classVariableNames:''
       
    30 	poolDictionaries:''
       
    31 	privateIn:UIPainterView
       
    32 !
       
    33 
       
    34 MultiSelectionInList subclass:#ListHolder
       
    35 	instanceVariableNames:'painter propertyList masterElement disabledChanged'
    29 	classVariableNames:''
    36 	classVariableNames:''
    30 	poolDictionaries:''
    37 	poolDictionaries:''
    31 	privateIn:UIPainterView
    38 	privateIn:UIPainterView
    32 !
    39 !
    33 
    40 
    61     ^ #menu
    68     ^ #menu
    62 
    69 
    63 
    70 
    64 ! !
    71 ! !
    65 
    72 
       
    73 !UIPainterView class methodsFor:'menu specs'!
       
    74 
       
    75 menu
       
    76 
       
    77   ^ #(#Menu #(
       
    78         #(#MenuItem
       
    79                 #'label:' 'copy'
       
    80                 #'nameKey:' #copySelection
       
    81                 #'shortcutKeyCharacter:' #Copy
       
    82          )
       
    83         #(#MenuItem
       
    84                 #'label:' 'cut'
       
    85                 #'nameKey:' #deleteSelection
       
    86                 #'shortcutKeyCharacter:' #Cut
       
    87          )
       
    88         #(#MenuItem
       
    89                 #'label:' 'paste'
       
    90                 #'nameKey:' #paste
       
    91                 #'submenu:'
       
    92                         #(#Menu #(
       
    93                                 #(#MenuItem
       
    94                                         #'label:' 'paste'
       
    95                                         #'nameKey:' #pasteBuffer
       
    96                                         #'shortcutKeyCharacter:' #Paste
       
    97                                  )
       
    98                                 #(#MenuItem
       
    99                                         #'label:' 'keep layout'
       
   100                                         #'nameKey:' #pasteWithLayout
       
   101                                  )
       
   102                                 )
       
   103                                 nil 
       
   104                                 nil
       
   105                          )
       
   106           )
       
   107          #(#MenuItem
       
   108                 #'label:' 'undo'
       
   109                 #'nameKey:' #undoLast)
       
   110          #(#MenuItem
       
   111                 #'label:' 'arrange'
       
   112                 #'nameKey:' #arrange
       
   113                 #'submenu:'
       
   114                         #(#Menu #(
       
   115                                 #(#MenuItem
       
   116                                         #'label:' 'to front'
       
   117                                         #'nameKey:' #raiseSelection
       
   118                                  )
       
   119                                 #(#MenuItem
       
   120                                         #'label:' 'to back'
       
   121                                         #'nameKey:' #lowerSelection
       
   122                                  )
       
   123                                 )
       
   124                                 nil
       
   125                                 nil
       
   126                           )
       
   127           )
       
   128          #(#MenuItem
       
   129                 #'label:' 'dimension'
       
   130                 #'nameKey:' #dimension
       
   131                 #'submenu:'
       
   132                         #(#Menu #(
       
   133                                 #(#MenuItem
       
   134                                         #'label:' 'default extent'
       
   135                                         #'nameKey:' #setToDefaultExtent
       
   136                                  )
       
   137                                 #(#MenuItem
       
   138                                         #'label:' 'default width'
       
   139                                         #'nameKey:' #setToDefaultWidth
       
   140                                  )
       
   141                                 #(#MenuItem
       
   142                                         #'label:' 'default height'
       
   143                                         #'nameKey:' #setToDefaultHeight
       
   144                                  )
       
   145                                 #(#MenuItem
       
   146                                         #'label:' 'copy extent'
       
   147                                         #'nameKey:' #copyExtent
       
   148                                  )
       
   149                                 #(#MenuItem
       
   150                                         #'label:' 'paste extent'
       
   151                                         #'nameKey:' #pasteExtent
       
   152                                  )
       
   153                                 #(#MenuItem
       
   154                                         #'label:' 'paste width'
       
   155                                         #'nameKey:' #pasteWidth
       
   156                                  )
       
   157                                 #(#MenuItem
       
   158                                         #'label:' 'paste height'
       
   159                                         #'nameKey:' #pasteHeight
       
   160                                  )
       
   161                                 #(#MenuItem
       
   162                                         #'label:' 'copy  layout'
       
   163                                         #'nameKey:' #copyLayout
       
   164                                  )
       
   165                                 #(#MenuItem
       
   166                                         #'label:' 'paste layout'
       
   167                                         #'nameKey:' #pasteLayout
       
   168                                  )
       
   169                                 )
       
   170                                 #(3 1 3) 
       
   171                                 nil
       
   172                         )
       
   173          )
       
   174         #(#MenuItem
       
   175                 #'label:' 'align'
       
   176                 #'nameKey:' #align
       
   177                 #'submenu:'
       
   178                         #(#Menu #(
       
   179                                 #(#MenuItem
       
   180                                         #'label:' 'align left'
       
   181                                         #'nameKey:' #alignSelectionLeft
       
   182                                  )
       
   183                                 #(#MenuItem
       
   184                                         #'label:' 'align right'
       
   185                                         #'nameKey:' #alignSelectionRight
       
   186                                  )
       
   187                                 #(#MenuItem
       
   188                                         #'label:' 'align left & right'
       
   189                                         #'nameKey:' #alignSelectionLeftAndRight
       
   190                                  )
       
   191                                 #(#MenuItem
       
   192                                         #'label:' 'align top'
       
   193                                         #'nameKey:' #alignSelectionTop
       
   194                                  )
       
   195                                 #(#MenuItem
       
   196                                         #'label:' 'align bottom' #'nameKey:'
       
   197                                         #alignSelectionBottom
       
   198                                  )
       
   199                                 #(#MenuItem
       
   200                                         #'label:' 'align centered vertical'
       
   201                                         #'nameKey:' #alignSelectionCenterHor
       
   202                                  )
       
   203                                 #(#MenuItem
       
   204                                         #'label:' 'align centered horizontal'
       
   205                                         #'nameKey:' #alignSelectionCenterVer
       
   206                                  )
       
   207                                 #(#MenuItem
       
   208                                         #'label:' 'spread horizontal'
       
   209                                         #'nameKey:' #spreadSelectionHor
       
   210                                  )
       
   211                                 #(#MenuItem
       
   212                                         #'label:' 'spread vertical'
       
   213                                         #'nameKey:' #spreadSelectionVer
       
   214                                  )
       
   215                                 #(#MenuItem
       
   216                                         #'label:' 'center horizontal in frame'
       
   217                                         #'nameKey:' #centerSelectionHor
       
   218                                  )
       
   219                                 #(#MenuItem
       
   220                                         #'label:' 'center vertical in frame'
       
   221                                         #'nameKey:' #centerSelectionVer
       
   222                                  )
       
   223                                 )
       
   224                                #(7 2)
       
   225                                nil
       
   226                         )
       
   227          )
       
   228         )
       
   229         #(4) 
       
   230         nil
       
   231     )
       
   232 ! !
       
   233 
    66 !UIPainterView methodsFor:'accessing'!
   234 !UIPainterView methodsFor:'accessing'!
    67 
   235 
    68 application
   236 application
    69     self halt.
   237     self halt.
    70     ^ nil
   238     ^ nil
    91 className:aClassName superclassName:aSuperclassName selector:aSelector
   259 className:aClassName superclassName:aSuperclassName selector:aSelector
    92     className      := aClassName.
   260     className      := aClassName.
    93     superclassName := aSuperclassName.
   261     superclassName := aSuperclassName.
    94     methodName     := aSelector.
   262     methodName     := aSelector.
    95 
   263 
       
   264 !
       
   265 
       
   266 listHolder
       
   267     ^ listHolder
    96 !
   268 !
    97 
   269 
    98 methodName
   270 methodName
    99     ^ methodName
   271     ^ methodName
   100 !
   272 !
   132     prop isNil ifTrue:[^ self unselect]
   304     prop isNil ifTrue:[^ self unselect]
   133               ifFalse:[^ self select:(prop view)]
   305               ifFalse:[^ self select:(prop view)]
   134 
   306 
   135 ! !
   307 ! !
   136 
   308 
       
   309 !UIPainterView methodsFor:'change & update'!
       
   310 
       
   311 changed:aParameter
       
   312     aParameter == #layout ifTrue:[
       
   313         listHolder removeDependent:self.
       
   314         listHolder changed:aParameter.
       
   315         listHolder addDependent:self.
       
   316     ] ifFalse:[
       
   317         super changed:aParameter
       
   318     ]
       
   319 !
       
   320 
       
   321 selectionChanged
       
   322     "selection has changed
       
   323     "
       
   324     |newSel|
       
   325 
       
   326     selection notNil ifTrue:[
       
   327         self selectionDo:[:aView||p|
       
   328             (p := self propertyOfView:aView) notNil ifTrue:[
       
   329                 newSel isNil ifTrue:[
       
   330                     newSel := OrderedCollection new
       
   331                 ].
       
   332                 newSel add:(listHolder indexOfName:(p name))
       
   333             ]
       
   334         ]
       
   335     ].
       
   336     listHolder removeDependent:self.
       
   337     listHolder selectionIndex:newSel.
       
   338     listHolder addDependent:self.
       
   339 !
       
   340 
       
   341 update:what with:aParm from:aSender
       
   342     |loIdx newSel|
       
   343 
       
   344     (what == #selectionIndex and:[aSender == listHolder]) ifFalse:[
       
   345         ^ self
       
   346     ].
       
   347     loIdx := listHolder selectionIndex.
       
   348 
       
   349     loIdx size ~~ 0 ifTrue:[
       
   350         newSel := loIdx collect:[:i|(listHolder propertyAt:i) view]
       
   351     ].
       
   352     self withSelectionHiddenDo:[
       
   353         selection := newSel
       
   354     ].
       
   355 
       
   356 ! !
       
   357 
   137 !UIPainterView methodsFor:'copy & cut & paste'!
   358 !UIPainterView methodsFor:'copy & cut & paste'!
   138 
   359 
   139 copySelection
   360 copySelection
   140     "copy the selection into the cut&paste-buffer
   361     "copy the selection into the cut&paste-buffer
   141     "
   362     "
   159     |text specs coll|
   380     |text specs coll|
   160 
   381 
   161     coll := self minSetOfSuperViews:selection.
   382     coll := self minSetOfSuperViews:selection.
   162 
   383 
   163     coll notNil ifTrue:[
   384     coll notNil ifTrue:[
   164         self unselect.
   385         listHolder disableNotificationsWhileEvaluating:[
   165         specs := coll collect:[:aView| self fullSpecFor:aView ].
   386             self unselect.
   166         text  := self transactionTextFor:coll.
   387             specs := coll collect:[:aView| self fullSpecFor:aView ].
   167 
   388             text  := self transactionTextFor:coll.
   168         undoHistory transaction:#cut text:text do:[
   389 
   169             coll reverseDo:[:o||p|
   390             undoHistory transaction:#cut text:text do:[
   170                 (p := self propertyOfView:o) notNil ifTrue:[
   391                 coll reverseDo:[:o||p|
   171                     self undoRemove:(p identifier)
   392                     (p := self propertyOfView:o) notNil ifTrue:[
   172                 ].
   393                         self undoRemove:(p identifier)
   173                 self remove:o
   394                     ].
   174             ]
   395                     self remove:o
   175         ].
   396                 ]
   176 
   397             ].
   177         self setSelection:specs.
   398             self setSelection:specs.
   178         self changed:#tree.
   399         ]
   179     ]
   400     ]
   180 !
   401 !
   181 
   402 
   182 pasteBuffer
   403 pasteBuffer
   183     "add the objects in the paste-buffer to the object view
   404     "add the objects in the paste-buffer to the object view
   187 !
   408 !
   188 
   409 
   189 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   410 pasteSpecifications:aSpecificationOrList keepLayout:keepLayout
   190     "add the specs to the object view
   411     "add the specs to the object view
   191     "
   412     "
   192     |paste frame pasteOrigin pasteOffset builder|
   413     |paste frame pasteOrigin pasteOffset builder newSel|
   193 
   414 
   194     (self canPaste:aSpecificationOrList) ifFalse:[
   415     (self canPaste:aSpecificationOrList) ifFalse:[
   195         ^ self
   416         ^ self
   196     ].
   417     ].
   197     aSpecificationOrList isCollection ifTrue:[
   418     aSpecificationOrList isCollection ifTrue:[
   204     (self canPasteInto:frame) ifFalse:[
   425     (self canPasteInto:frame) ifFalse:[
   205         frame := self
   426         frame := self
   206     ].
   427     ].
   207     self unselect.
   428     self unselect.
   208 
   429 
   209     selection := OrderedCollection new.
   430     newSel  := OrderedCollection new.
   210     builder   := UIBuilder new.
   431     builder := UIBuilder new.
   211 
   432 
   212     keepLayout ifFalse:[
   433     keepLayout ifFalse:[
   213         pasteOffset := 0@0.
   434         pasteOffset := 0@0.
   214         pasteOrigin := self sensor mousePoint.
   435         pasteOrigin := self sensor mousePoint.
   215         pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
   436         pasteOrigin := device translatePoint:pasteOrigin from:device rootView id to:frame id.
   216     ].
   437     ].
   217 
   438 
   218     paste do:[:aSpec|
   439     listHolder disableNotificationsWhileEvaluating:[
   219         |view|
   440         paste do:[:aSpec|
   220 
   441             |view|
   221         view := self addSpec:aSpec builder:builder in:frame.
   442 
   222 
   443             view := self addSpec:aSpec builder:builder in:frame.
   223         keepLayout ifFalse:[
   444 
   224             (frame bounds containsPoint:pasteOrigin) ifFalse:[
   445             keepLayout ifFalse:[
   225                 self moveObject:view to:pasteOffset.
   446                 (frame bounds containsPoint:pasteOrigin) ifFalse:[
   226             ] ifTrue:[
   447                     self moveObject:view to:pasteOffset.
   227                 self moveObject:view to:pasteOrigin + pasteOffset.
   448                 ] ifTrue:[
       
   449                     self moveObject:view to:pasteOrigin + pasteOffset.
       
   450                 ].
       
   451                 pasteOffset := pasteOffset + 4
   228             ].
   452             ].
   229             pasteOffset := pasteOffset + 4
   453             view realize.
       
   454             newSel add:view.
   230         ].
   455         ].
   231         view realize.
   456     ].
   232         selection add:view.
   457 
   233     ].
   458     self transaction:#paste objects:newSel do:[:v|
   234 
       
   235     self transaction:#paste selectionDo:[:v|
       
   236         self undoCreate:((self propertyOfView:v) identifier)
   459         self undoCreate:((self propertyOfView:v) identifier)
   237     ].
   460     ].
   238     selection size == 1 ifTrue:[
   461     newSel size == 1 ifTrue:[
   239         selection := selection at:1
   462         newSel := newSel at:1
   240     ].
   463     ].
   241     self showSelection.
       
   242     self realizeAllSubViews.
   464     self realizeAllSubViews.
   243     inputView raise.
   465     inputView raise.
       
   466     self select:newSel.
   244     self elementChangedSize:frame.
   467     self elementChangedSize:frame.
   245     self changed:#tree
       
   246 
       
   247     "Modified: 8.4.1997 / 01:08:15 / cg"
       
   248 !
   468 !
   249 
   469 
   250 pasteWithLayout
   470 pasteWithLayout
   251     "add the objects in the paste-buffer to the object view; don't change the
   471     "add the objects in the paste-buffer to the object view; don't change the
   252      layout
   472      layout
   315         self warn:'set the class first'.
   535         self warn:'set the class first'.
   316         ^ code
   536         ^ code
   317     ].
   537     ].
   318     cls := Smalltalk classNamed:className.
   538     cls := Smalltalk classNamed:className.
   319 
   539 
   320     viewProperties do:[:aProp |
   540     listHolder propertiesDo:[:aProp |
   321         |modelSelector menuSelector protoSpec thisCode|
   541         |modelSelector menuSelector protoSpec thisCode|
   322 
   542 
   323         (modelSelector := aProp model) notNil ifTrue:[
   543         (modelSelector := aProp model) notNil ifTrue:[
   324             (cls implements:modelSelector asSymbol) ifFalse:[
   544             (cls implements:modelSelector asSymbol) ifFalse:[
   325                 protoSpec := aProp view specClass basicNew.
   545                 protoSpec := aProp view specClass basicNew.
   338                 protoSpec := aProp view specClass basicNew.
   558                 protoSpec := aProp view specClass basicNew.
   339                 "/ kludge ..
   559                 "/ kludge ..
   340                 thisCode := (self generateAspectMethodFor:menuSelector spec:protoSpec inClass:cls).
   560                 thisCode := (self generateAspectMethodFor:menuSelector spec:protoSpec inClass:cls).
   341                 code := code , thisCode
   561                 code := code , thisCode
   342             ]
   562             ]
   343         ]
   563         ].
       
   564 
       
   565         aProp spec aspectSelectors do:[:aSel|
       
   566             (cls implements:aSel asSymbol) ifFalse:[
       
   567                 protoSpec := aProp view specClass basicNew.
       
   568                 "/ kludge ..
       
   569                 thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
       
   570                 code := code , thisCode
       
   571             ]
       
   572         ].
       
   573 
   344     ].
   574     ].
   345     ^ code
   575     ^ code
   346 
   576 
   347 !
   577 !
   348 
   578 
   419 
   649 
   420     code := ''.
   650     code := ''.
   421 
   651 
   422     "generate code for groups"
   652     "generate code for groups"
   423 
   653 
   424     viewProperties do:[:props |
   654     listHolder propertiesDo:[:props|
   425         g := props at:#group ifAbsent:[nil].
   655         g := props at:#group ifAbsent:[nil].
   426         g notNil ifTrue:[
   656         g notNil ifTrue:[
   427             code := code , (self generateInitCodeForGroup:g)
   657             code := code , (self generateInitCodeForGroup:g)
   428         ]
   658         ]
   429     ].
   659     ].
   616 
   846 
   617 
   847 
   618 !
   848 !
   619 
   849 
   620 storeContentsOn:aStream
   850 storeContentsOn:aStream
   621     viewProperties do:[:p| p storeOn:aStream]
   851     listHolder propertiesDo:[:p| p storeOn:aStream]
   622 !
   852 !
   623 
   853 
   624 subviewsOf:aView do:aBlock
   854 subviewsOf:aView do:aBlock
   625     |subs v|
   855     |subs v|
   626 
   856 
   627     (subs := aView subViews) notNil ifTrue:[
   857     (subs := aView subViews) notNil ifTrue:[
   628         subs do:[:v|
   858         subs do:[:v|
   629             (v ~~ inputView and:[v notNil]) ifTrue:[
   859             (v ~~ inputView and:[v notNil]) ifTrue:[
   630                 (viewProperties detect:[:p | p view == v] ifNone:nil) notNil ifTrue:[ 
   860                 (listHolder detectProperty:[:p|p view == v]) notNil ifTrue:[ 
   631                     (v superView == aView) ifTrue:[
   861                     (v superView == aView) ifTrue:[
   632                         aBlock value:v
   862                         aBlock value:v
   633                     ]
   863                     ]
   634                 ]
   864                 ]
   635             ]
   865             ]
   651         ]
   881         ]
   652     ].
   882     ].
   653     self withSelectionHiddenDo:[
   883     self withSelectionHiddenDo:[
   654         group := EnterFieldGroup new.
   884         group := EnterFieldGroup new.
   655         props := GroupProperties new.
   885         props := GroupProperties new.
   656         name  := self uniqueNameFor:EnterFieldGroup.
   886         name  := self uniqueNameFor:(EnterFieldGroup className).
   657         props group:group.
   887         props group:group.
   658         props name:name.
   888         props name:name.
   659         group groupID:name asSymbol.
   889         group groupID:name asSymbol.
   660         objects := OrderedCollection new.
   890         objects := OrderedCollection new.
   661         props controlledObjects:objects.
   891         props controlledObjects:objects.
   662         viewProperties add:props.
   892         listHolder add:props.
   663 
   893 
   664         self selectionDo:[:aView |
   894         self selectionDo:[:aView |
   665             objects add:aView.
   895             objects add:aView.
   666             group add:aView
   896             group add:aView
   667         ].
   897         ].
   681         ]
   911         ]
   682     ].
   912     ].
   683     self withSelectionHiddenDo:[
   913     self withSelectionHiddenDo:[
   684         group := RadioButtonGroup new.
   914         group := RadioButtonGroup new.
   685         props := GroupProperties new.
   915         props := GroupProperties new.
   686         name  := self uniqueNameFor:RadioButtonGroup.
   916         name  := self uniqueNameFor:(RadioButtonGroup className).
   687         props group:group.
   917         props group:group.
   688         props name:name.
   918         props name:name.
   689         group groupID:name asSymbol.
   919         group groupID:name asSymbol.
   690         objects := OrderedCollection new.
   920         objects := OrderedCollection new.
   691         props controlledObjects:objects.
   921         props controlledObjects:objects.
   692         viewProperties add:props.
   922         listHolder add:props.
   693 
   923 
   694         self selectionDo:[:aView |
   924         self selectionDo:[:aView |
   695             aView turnOff.
   925             aView turnOff.
   696             objects add:aView.
   926             objects add:aView.
   697             group add:aView
   927             group add:aView
   710 
   940 
   711     superclassName := 'ApplicationModel'.
   941     superclassName := 'ApplicationModel'.
   712     className      := 'NewApplication'.
   942     className      := 'NewApplication'.
   713     methodName     := 'windowSpec'.
   943     methodName     := 'windowSpec'.
   714     categoryName   := 'Applications'.
   944     categoryName   := 'Applications'.
   715     viewProperties := OrderedCollection new.
   945     listHolder     := ListHolder for:self.
   716     HandCursor     := Cursor leftHand.
   946     HandCursor     := Cursor leftHand.
   717 
   947 
   718     "Modified: 5.9.1995 / 19:58:06 / claus"
       
   719 !
   948 !
   720 
   949 
   721 initializeCreatedObject:anObject
   950 initializeCreatedObject:anObject
   722     "set default properties for a created object
   951     "set default properties for a created object
   723     "
   952     "
   726     cls   := anObject class.
   955     cls   := anObject class.
   727     spec  := anObject specClass fromView:anObject.
   956     spec  := anObject specClass fromView:anObject.
   728     props := ViewProperty new.
   957     props := ViewProperty new.
   729     props view:anObject.
   958     props view:anObject.
   730     props spec:spec.
   959     props spec:spec.
   731     props name:(self uniqueNameFor:cls).
   960     props name:(self uniqueNameFor:spec).
   732     viewProperties add:props.
   961     listHolder add:props.
   733 
   962 
   734     ((spec respondsTo:#label:) and:[self supportsLabel:anObject]) ifTrue:[
   963     ((spec respondsTo:#label:) and:[self supportsLabel:anObject]) ifTrue:[
   735         anObject label:(props name).
   964         anObject label:(props name).
   736         spec label:(props name)
   965         spec label:(props name)
   737     ].
   966     ].
   742 !
   971 !
   743 
   972 
   744 setupFromSpec:specOrSpecArray
   973 setupFromSpec:specOrSpecArray
   745     |spec builder|
   974     |spec builder|
   746 
   975 
   747     self removeAll.
   976     listHolder disableNotificationsWhileEvaluating:[
   748 
   977         self removeAll.
   749     spec    := UISpecification from:specOrSpecArray.
   978         spec    := UISpecification from:specOrSpecArray.
   750     builder := UIBuilder new.
   979         builder := UIBuilder new.
   751     spec window setupView:self topView for:builder.
   980         spec window setupView:self topView for:builder.
   752     self addSpec:(spec component) builder:builder in:self.
   981         self addSpec:(spec component) builder:builder in:self.
   753     self realizeAllSubViews.
   982         self realizeAllSubViews.
   754     inputView raise.
   983         inputView raise.
   755     self changed:#tree.
   984     ]
   756 ! !
   985 ! !
   757 
   986 
   758 !UIPainterView methodsFor:'menus'!
   987 !UIPainterView methodsFor:'menus'!
   759 
   988 
   760 menu
   989 menu
   761     "returns middle-button menu dependent on the selection
   990     "returns middle-button menu dependent on the selection
   762     "
   991     "
   763     |menu canPaste undoIdx undoText|
   992     |menu canPaste|
   764 
   993 
   765     testMode ifTrue:[^ nil ].
   994     testMode ifTrue:[^ nil ].
       
   995     menu := MenuPanel fromSpec:(self class menu) receiver:self.
   766 
   996 
   767     canPaste := self canPaste:(self getSelection).
   997     canPaste := self canPaste:(self getSelection).
   768     undoText := undoHistory lastTypeAsString.
       
   769 
   998 
   770     selection isNil ifTrue:[
   999     selection isNil ifTrue:[
   771         undoIdx := 2.
  1000         menu disableAll
   772 
       
   773         menu := PopUpMenu labels:( resources array:#('paste' 'undo') )
       
   774                        selectors:#( #paste #undoLast )
       
   775                         receiver:self
       
   776     ] ifFalse:[    
       
   777         undoIdx := 4.
       
   778 
       
   779         menu := PopUpMenu labels:( resources array:#(
       
   780                                       'copy' 
       
   781                                       'cut' 
       
   782                                       'paste'
       
   783                                       'undo'
       
   784                                       '-' 
       
   785                                       'arrange'
       
   786                                       'dimension'
       
   787                                       'align'
       
   788                                     )
       
   789                                   )
       
   790                        selectors:#(   #copySelection
       
   791                                       #deleteSelection
       
   792                                       #paste
       
   793                                       #undoLast
       
   794                                       nil
       
   795                                       #arrange
       
   796                                       #dimension
       
   797                                       #align
       
   798                                   )
       
   799                        accelerators:#(#Copy
       
   800                                       #Cut
       
   801                                       nil
       
   802                                       nil
       
   803                                       nil
       
   804                                       nil
       
   805                                       nil
       
   806                                       nil
       
   807                                   )
       
   808                          receiver:self.
       
   809 
       
   810         canPaste := (canPaste and:[self canPasteInto:selection]).
       
   811         menu subMenuAt:#arrange   put:(self subMenuArrange).
       
   812         menu subMenuAt:#dimension put:(self subMenuDimension).
       
   813         menu subMenuAt:#align     put:(self subMenuAlign).
       
   814     ].
       
   815 
       
   816     menu subMenuAt:#paste put:(self subMenuPaste).
       
   817     canPaste ifFalse:[menu disable:#paste].
       
   818 
       
   819     undoText notNil ifTrue:[
       
   820         menu labelAt:undoIdx put:((menu labels at:undoIdx), ':  ', undoText)
       
   821     ] ifFalse:[
  1001     ] ifFalse:[
   822         menu disable:#undoLast
  1002         canPaste := (canPaste and:[self canPasteInto:selection])
   823     ].
  1003     ].
       
  1004     menu enabledAt:#paste put:[|can|
       
  1005         can := self canPaste:(self getSelection).
       
  1006         selection isNil ifTrue:[can]
       
  1007                        ifFalse:[(can and:[self canPasteInto:selection])]
       
  1008     ].
       
  1009 
       
  1010     menu enabledAt:#undoLast put:(undoHistory notEmpty).
   824   ^ menu
  1011   ^ menu
   825 
  1012 
   826 
  1013 
   827 
  1014 
   828 !
  1015 !
   841             self changeFont:theFont
  1028             self changeFont:theFont
   842         ]
  1029         ]
   843     ]
  1030     ]
   844 
  1031 
   845     "Modified: 10.4.1997 / 10:06:15 / cg"
  1032     "Modified: 10.4.1997 / 10:06:15 / cg"
   846 !
       
   847 
       
   848 subMenuAlign
       
   849     "returns submenu alignment
       
   850     "
       
   851     |menu|
       
   852 
       
   853     menu := PopUpMenu labels:(
       
   854                 resources array:#(
       
   855                                     'align left' 
       
   856                                     'align right'
       
   857                                     'align left & right'
       
   858                                     'align top' 
       
   859                                     'align bottom'
       
   860                                     'align centered vertical'
       
   861                                     'align centered horizontal'
       
   862                                     '-'
       
   863                                     'spread horizontal'
       
   864                                     'spread vertical'
       
   865                                     '-'
       
   866                                     'center horizontal in frame'
       
   867                                     'center vertical in frame'
       
   868                                   )
       
   869                          )
       
   870 
       
   871               selectors:#(  
       
   872                             alignSelectionLeft
       
   873                             alignSelectionRight
       
   874                             alignSelectionLeftAndRight
       
   875                             alignSelectionTop
       
   876                             alignSelectionBottom
       
   877                             alignSelectionCenterHor
       
   878                             alignSelectionCenterVer
       
   879                             nil
       
   880                             spreadSelectionHor
       
   881                             spreadSelectionVer
       
   882                             nil
       
   883                             centerSelectionHor
       
   884                             centerSelectionVer
       
   885                          )
       
   886                receiver:self.
       
   887     ^ menu    
       
   888 
       
   889 !
       
   890 
       
   891 subMenuArrange
       
   892     "returns submenu arrange
       
   893     "
       
   894     |menu|
       
   895 
       
   896     menu := PopUpMenu labels:( 
       
   897                 resources array:#(
       
   898                                     'to front' 
       
   899                                     'to back' 
       
   900                                  )
       
   901                               )
       
   902                    selectors:#(
       
   903                                     raiseSelection
       
   904                                     lowerSelection
       
   905                               )
       
   906                      receiver:self.
       
   907   ^ menu
       
   908 !
       
   909 
       
   910 subMenuDimension
       
   911     "returns submenu dimension
       
   912     "
       
   913     |menu|
       
   914 
       
   915     menu := PopUpMenu labels:( 
       
   916                 resources array:#(
       
   917                                     'default extent' 
       
   918                                     'default width' 
       
   919                                     'default height'
       
   920                                     '-'
       
   921                                     'copy extent'
       
   922                                     '-'
       
   923                                     'paste extent'
       
   924                                     'paste width'
       
   925                                     'paste height'
       
   926                                     '-'
       
   927                                     'copy  layout'
       
   928                                     'paste layout'
       
   929                                  )
       
   930                               )
       
   931                    selectors:#(
       
   932                                     setToDefaultExtent
       
   933                                     setToDefaultWidth
       
   934                                     setToDefaultHeight
       
   935                                     nil
       
   936                                     copyExtent
       
   937                                     nil
       
   938                                     pasteExtent
       
   939                                     pasteWidth
       
   940                                     pasteHeight
       
   941                                     nil
       
   942                                     copyLayout
       
   943                                     pasteLayout
       
   944                               )
       
   945                      receiver:self.
       
   946   ^ menu
       
   947 !
       
   948 
       
   949 subMenuFont
       
   950     "returns submenu dimension
       
   951     "
       
   952     |menu|
       
   953 
       
   954     menu := PopUpMenu labels:( 
       
   955                 resources array:#(
       
   956                                     'larger' 
       
   957                                     'smaller'
       
   958                                     '-'
       
   959                                     'normal'
       
   960                                     'bold'
       
   961                                     'italic'
       
   962                                     'bold italic'
       
   963                                     '-'
       
   964                                     'font panel'
       
   965                                  )
       
   966                               )
       
   967                    selectors:#(
       
   968                                     largerFont 
       
   969                                     smallerFont
       
   970                                     nil
       
   971                                     normalFont
       
   972                                     boldFont
       
   973                                     italicFont
       
   974                                     boldItalicFont
       
   975                                     nil
       
   976                                     showFontPanel
       
   977                               )
       
   978                      receiver:self.
       
   979   ^ menu
       
   980 !
       
   981 
       
   982 subMenuPaste
       
   983     "returns submenu Paste
       
   984     "
       
   985     |menu|
       
   986 
       
   987     menu := PopUpMenu labels:( resources array:#('paste' 'keep layout') )
       
   988                    selectors:#( #pasteBuffer #pasteWithLayout )
       
   989                 accelerators:#( #Paste       nil )
       
   990                     receiver:self.
       
   991 
       
   992   ^ menu    
       
   993 
       
   994 ! !
  1033 ! !
   995 
  1034 
   996 !UIPainterView methodsFor:'misc'!
  1035 !UIPainterView methodsFor:'misc'!
   997 
  1036 
   998 changeFont:aFontDescription
  1037 changeFont:aFontDescription
  1009             self selectionDo:[:aView |
  1048             self selectionDo:[:aView |
  1010                 aView font:f.
  1049                 aView font:f.
  1011                 self elementChangedSize:aView.
  1050                 self elementChangedSize:aView.
  1012             ]
  1051             ]
  1013         ].
  1052         ].
  1014         self changed:#any.
       
  1015     ]
  1053     ]
  1016 
  1054 
  1017     "Modified: 5.9.1995 / 12:13:27 / claus"
  1055     "Modified: 5.9.1995 / 12:13:27 / claus"
  1018     "Created: 10.4.1997 / 09:56:16 / cg"
  1056     "Created: 10.4.1997 / 09:56:16 / cg"
  1019 !
  1057 !
  1030         self withSelectionHiddenDo:[
  1068         self withSelectionHiddenDo:[
  1031             self selectionDo:[:aView |
  1069             self selectionDo:[:aView |
  1032                 aView font:f.
  1070                 aView font:f.
  1033                 self elementChangedSize:aView.
  1071                 self elementChangedSize:aView.
  1034             ]
  1072             ]
  1035         ].
  1073         ]
  1036         self changed:#any.
       
  1037     ]
  1074     ]
  1038 
  1075 
  1039     "Modified: 5.9.1995 / 12:13:27 / claus"
  1076     "Modified: 5.9.1995 / 12:13:27 / claus"
  1040 ! !
  1077 ! !
  1041 
  1078 
  1042 !UIPainterView methodsFor:'removing components'!
  1079 !UIPainterView methodsFor:'removing components'!
  1043 
  1080 
  1044 remove:anObject
  1081 remove:anObject
  1045     "remove anObject from the contents do redraw
  1082     "remove anObject from the contents do redraw
  1046     "
  1083     "
  1047     |props|
  1084     listHolder remove:anObject.
  1048 
       
  1049     anObject notNil ifTrue:[
       
  1050         (anObject subViews notNil) ifTrue:[
       
  1051             anObject subViews copy do:[:sub |
       
  1052                 self remove:sub
       
  1053             ]
       
  1054         ].
       
  1055         (props := self propertyOfView:anObject) notNil ifTrue:[
       
  1056             viewProperties remove:props ifAbsent:nil
       
  1057         ].
       
  1058         anObject destroy
       
  1059     ]
       
  1060 !
  1085 !
  1061 
  1086 
  1062 removeAll
  1087 removeAll
  1063     "remove all objects and properties
  1088     "remove all objects and properties
  1064     "
  1089     "
  1065     self unselect.
  1090     listHolder disableNotificationsWhileEvaluating:[
  1066     viewProperties := OrderedCollection new.
  1091         self unselect.
  1067 
  1092         listHolder  removeAll.
  1068     subViews notNil ifTrue:[
  1093         undoHistory reinitialize.
  1069         subViews copy do:[:sub |
  1094     ]
  1070             sub ~~ inputView ifTrue:[   
       
  1071                 self remove:sub
       
  1072             ]
       
  1073         ]
       
  1074     ].
       
  1075     undoHistory reinitialize.
       
  1076     self changed:#tree
       
  1077 ! !
  1095 ! !
  1078 
  1096 
  1079 !UIPainterView methodsFor:'searching'!
  1097 !UIPainterView methodsFor:'searching'!
  1080 
  1098 
  1081 findContainerViewAt:aPoint
  1099 findContainerViewAt:aPoint
  1125 !
  1143 !
  1126 
  1144 
  1127 propertyOfGroup:aGroup
  1145 propertyOfGroup:aGroup
  1128     "returns property assigned to group
  1146     "returns property assigned to group
  1129     "
  1147     "
  1130     ^ viewProperties detect:[:p| p group == aGroup] ifNone:nil
  1148     ^ listHolder detectProperty:[:p| p group == aGroup ]
  1131 !
  1149 !
  1132 
  1150 
  1133 propertyOfIdentifier:anId
  1151 propertyOfIdentifier:anId
  1134     "returns property assigned to unique identifier
  1152     "returns property assigned to unique identifier
  1135     "
  1153     "
  1136     anId notNil ifTrue:[
  1154     anId notNil ifTrue:[
  1137         ^ viewProperties detect:[:p| p identifier == anId] ifNone:nil.
  1155         ^ listHolder detectProperty:[:p| p identifier == anId ]
  1138     ].
  1156     ].
  1139     ^ nil
  1157     ^ nil
  1140 !
  1158 !
  1141 
  1159 
  1142 propertyOfName:aString
  1160 propertyOfName:aString
  1143     "returns property assigned to name
  1161     "returns property assigned to name
  1144     "
  1162     "
  1145     aString = 'self' ifFalse:[
  1163     |name|
  1146         ^ viewProperties detect:[:p| p name = aString] ifNone:nil
  1164 
       
  1165     aString isNil ifFalse:[
       
  1166         name := aString string withoutSeparators.
       
  1167 
       
  1168         name = 'self' ifFalse:[
       
  1169             ^ listHolder detectProperty:[:p| p name = name ].
       
  1170         ]
  1147     ].
  1171     ].
  1148     ^ nil
  1172     ^ nil
  1149 !
  1173 !
  1150 
  1174 
  1151 propertyOfView:aView
  1175 propertyOfView:aView
  1152     "returns property assigned to view
  1176     "returns property assigned to view
  1153     "
  1177     "
  1154     (aView isNil or:[aView == self]) ifFalse:[
  1178     (aView isNil or:[aView == self]) ifFalse:[
  1155         ^ viewProperties detect:[:p| p view == aView] ifNone:nil
  1179         ^ listHolder detectProperty:[:p| p view == aView ]
  1156     ].
  1180     ].
  1157     ^ nil
  1181     ^ nil
  1158 !
  1182 !
  1159 
  1183 
  1160 uniqueNameFor:aClass
  1184 uniqueNameFor:aSpecOrString
  1161     "generate and return an unique name for a class
  1185     "generate and return an unique name for a class
  1162     "
  1186     "
  1163     |next name size|
  1187     |next name size|
  1164 
  1188 
       
  1189     aSpecOrString isString ifFalse:[name := aSpecOrString className asString]
       
  1190                             ifTrue:[name := aSpecOrString].
       
  1191 
       
  1192     (name endsWith:'Spec') ifTrue:[
       
  1193         name := name copyFrom:1 to:(name size - 4).
       
  1194     ] ifFalse:[
       
  1195         name := name copy
       
  1196     ].
       
  1197     name at:1 put:(name at:1) asLowercase.
       
  1198     size  := name size + 1.
  1165     next  := 0.
  1199     next  := 0.
  1166     name  := aClass name asString copy.
  1200 
  1167     size  := name size + 1.
  1201     listHolder propertiesDo:[:p|
  1168 
  1202         |n|
  1169     name at:1 put:(name at:1) asLowercase.
       
  1170 
       
  1171     viewProperties do:[:p||n|
       
  1172         n := p name.
  1203         n := p name.
  1173 
  1204 
  1174         (n size >= size and:[n startsWith:name]) ifTrue:[
  1205         (n size >= size and:[n startsWith:name]) ifTrue:[
  1175             next := next max:(p extractNumberStartingAt:size)
  1206             next := next max:(p extractNumberStartingAt:size)
  1176         ]
  1207         ]
  1182 
  1213 
  1183 
  1214 
  1184 !
  1215 !
  1185 
  1216 
  1186 uniqueNameOf:aView
  1217 uniqueNameOf:aView
  1187     |name prop|
  1218     |prop|
  1188 
  1219 
  1189     aView notNil ifTrue:[
  1220     (prop := self propertyOfView:aView) notNil ifTrue:[
  1190         prop := self propertyOfView:aView
  1221         prop name isNil ifTrue:[
  1191     ].
  1222             prop name:(self uniqueNameFor:(prop spec)).
  1192     prop isNil ifTrue:[
  1223         ].
  1193         ^ 'self'
  1224         ^ prop name
  1194     ].
  1225     ].
  1195     (name := prop name) isNil ifTrue:[
  1226     ^ 'self'
  1196         name := self uniqueNameFor:(aView class).
       
  1197         prop name:name.
       
  1198     ].
       
  1199     ^ name
       
  1200 
  1227 
  1201 ! !
  1228 ! !
  1202 
  1229 
  1203 !UIPainterView methodsFor:'selection'!
  1230 !UIPainterView methodsFor:'selection'!
  1204 
  1231 
  1239 
  1266 
  1240     aCollection size > 1 ifTrue:[
  1267     aCollection size > 1 ifTrue:[
  1241         self withSelectionHiddenDo:[
  1268         self withSelectionHiddenDo:[
  1242             selection := aCollection
  1269             selection := aCollection
  1243         ].
  1270         ].
  1244         self changed:#selection
  1271         self selectionChanged
  1245     ]
  1272     ]
  1246 ! !
  1273 ! !
  1247 
  1274 
  1248 !UIPainterView methodsFor:'specification'!
  1275 !UIPainterView methodsFor:'specification'!
  1249 
  1276 
  1251     "build view and subviews from aSpecification into a frame. The top view
  1278     "build view and subviews from aSpecification into a frame. The top view
  1252      is returned. The contained components of a spec are set to nil
  1279      is returned. The contained components of a spec are set to nil
  1253     "
  1280     "
  1254     aBuilder applicationClass:(Smalltalk classNamed:className).
  1281     aBuilder applicationClass:(Smalltalk classNamed:className).
  1255 
  1282 
  1256     aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s|
  1283     aBuilder componentCreationHook:[:aView :aSpec :aBdr||sv p s n|
  1257         p := ViewProperty new.
  1284         p := ViewProperty new.
  1258         s := aSpec copy.
  1285         s := aSpec copy.
  1259         p spec:s.
  1286         p spec:s.
  1260         p view:aView.
  1287         p view:aView.
  1261 
  1288 
  1262         s class supportsSubComponents ifTrue:[
  1289         s class supportsSubComponents ifTrue:[
  1263             s component:nil
  1290             s component:nil
  1264         ].
  1291         ].
  1265 
  1292 
  1266         (self propertyOfName:(s name)) notNil ifTrue:[
  1293         n := s name.
  1267             s name:(self uniqueNameFor:(aView class))
  1294 
       
  1295         (n isNil or:[(self propertyOfName:n) notNil]) ifTrue:[
       
  1296             s name:(self uniqueNameFor:s)
  1268         ].
  1297         ].
  1269         viewProperties add:p
  1298         listHolder add:p
  1270     ].
  1299     ].
  1271 
  1300 
  1272     ^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame.
  1301     ^ aSpecification buildViewWithLayoutFor:aBuilder in:aFrame.
  1273 
  1302 
  1274 !
  1303 !
  1349                     inputView raise.
  1378                     inputView raise.
  1350                 ] ifFalse:[
  1379                 ] ifFalse:[
  1351                     aSpec setAttributesIn:aView with:builder.
  1380                     aSpec setAttributesIn:aView with:builder.
  1352                     self elementChangedSize:aView.
  1381                     self elementChangedSize:aView.
  1353                 ].
  1382                 ].
  1354 
       
  1355                 props spec:(aSpec copy).
  1383                 props spec:(aSpec copy).
       
  1384                 listHolder propertyChanged:props.
  1356             ]
  1385             ]
  1357         ].
  1386         ]
  1358         self changed:#tree
       
  1359     ]
  1387     ]
  1360 ! !
  1388 ! !
  1361 
  1389 
  1362 !UIPainterView methodsFor:'testing'!
  1390 !UIPainterView methodsFor:'testing'!
  1363 
  1391 
  1554                     view become:v
  1582                     view become:v
  1555                 ] ifFalse:[
  1583                 ] ifFalse:[
  1556                     spec setAttributesIn:view with:builder.
  1584                     spec setAttributesIn:view with:builder.
  1557                     self elementChangedSize:view.
  1585                     self elementChangedSize:view.
  1558                 ].
  1586                 ].
       
  1587                 listHolder propertyChanged:props.
  1559             ]
  1588             ]
  1560         ]
  1589         ]
  1561     ].
  1590     ].
  1562 
  1591 
  1563 
  1592 
  1694     "set the value of the group name
  1723     "set the value of the group name
  1695     "
  1724     "
  1696     name := aName
  1725     name := aName
  1697 ! !
  1726 ! !
  1698 
  1727 
       
  1728 !UIPainterView::ListHolder class methodsFor:'instance creation'!
       
  1729 
       
  1730 for:aPainter
       
  1731     ^ self new for:aPainter
       
  1732 ! !
       
  1733 
       
  1734 !UIPainterView::ListHolder methodsFor:'accessing'!
       
  1735 
       
  1736 canModify
       
  1737     ^ (painter notNil and:[painter testMode not])
       
  1738 !
       
  1739 
       
  1740 painter
       
  1741     "returns painter
       
  1742     "
       
  1743     ^ painter
       
  1744 !
       
  1745 
       
  1746 propertyAt:anIndex
       
  1747     "returns property at an index
       
  1748     "
       
  1749     ^ propertyList at:anIndex
       
  1750 ! !
       
  1751 
       
  1752 !UIPainterView::ListHolder methodsFor:'adding & removing'!
       
  1753 
       
  1754 add:aProperty
       
  1755     "add property and update list
       
  1756     "
       
  1757     |idx list name last|
       
  1758 
       
  1759     list := self list.
       
  1760     idx  := self findParentProperty:aProperty.
       
  1761     name := aProperty name.
       
  1762 
       
  1763     idx == 0 ifTrue:[
       
  1764         last := list size
       
  1765     ] ifFalse:[
       
  1766         last := self lastInGroupStartingAt:idx.
       
  1767         name := (String new:(4+((list at:idx) leftIndent))), name.
       
  1768     ].
       
  1769     propertyList add:aProperty afterIndex:last.
       
  1770     list         add:name      afterIndex:last.
       
  1771     self changed:#size
       
  1772 
       
  1773 
       
  1774 !
       
  1775 
       
  1776 remove:aView
       
  1777     "remove all view relevant resources
       
  1778     "
       
  1779     |start|
       
  1780 
       
  1781     aView notNil ifTrue:[
       
  1782         start := self findProperty:[:p| p view == aView ].
       
  1783 
       
  1784         start ~~ 0 ifTrue:[
       
  1785             self basicRemove:start.
       
  1786             self changed:#size.
       
  1787         ]
       
  1788     ]
       
  1789 !
       
  1790 
       
  1791 removeAll
       
  1792     masterElement := nil.
       
  1793     self selection:#().
       
  1794 
       
  1795     [propertyList notEmpty] whileTrue:[
       
  1796         self basicRemove:1
       
  1797     ].
       
  1798     self changed:#size.
       
  1799 
       
  1800 ! !
       
  1801 
       
  1802 !UIPainterView::ListHolder methodsFor:'change & update'!
       
  1803 
       
  1804 changed:aParameter
       
  1805     "notify all dependents that the receiver has changed somehow.
       
  1806      Each dependent gets a '#update:'-message with aParameter
       
  1807      as argument. In case of disabled no notifications are raised
       
  1808     "
       
  1809     disabledChanged ifFalse:[
       
  1810         super changed:aParameter
       
  1811     ]
       
  1812 !
       
  1813 
       
  1814 disableNotificationsWhileEvaluating:aBlock
       
  1815     "perform block without notification; after evaluation of block,
       
  1816      a #size changed notification is raised
       
  1817     "
       
  1818     |oldState|
       
  1819 
       
  1820     oldState := disabledChanged.
       
  1821     disabledChanged := true.
       
  1822     aBlock value.
       
  1823     disabledChanged := oldState.
       
  1824     self changed:#size.
       
  1825 !
       
  1826 
       
  1827 propertyChanged:aProperty
       
  1828     "property list changed; update list names
       
  1829     "
       
  1830     |list idx oldName newName wspName view indent mid|
       
  1831 
       
  1832     view := aProperty view.
       
  1833     idx  := self findProperty:[:p| p view == view ].
       
  1834 
       
  1835     idx == 0 ifTrue:[
       
  1836         ^ self error
       
  1837     ].
       
  1838 
       
  1839     list    := self list.
       
  1840     oldName := list at:idx.
       
  1841     wspName := oldName string withoutSeparators.
       
  1842     newName := aProperty name.
       
  1843 
       
  1844     wspName = newName ifFalse:[
       
  1845         mid := self masterElement.
       
  1846         list at:idx put:((String new:(oldName leftIndent)), newName).
       
  1847 
       
  1848         idx == mid ifTrue:[
       
  1849             masterElement := nil.
       
  1850             self masterElement:idx
       
  1851         ].
       
  1852     ].
       
  1853     self changed:#property
       
  1854 
       
  1855 ! !
       
  1856 
       
  1857 !UIPainterView::ListHolder methodsFor:'enumerating'!
       
  1858 
       
  1859 propertiesDo:aBlock
       
  1860     "evaluate a block for each property
       
  1861     "
       
  1862     propertyList do:aBlock
       
  1863 ! !
       
  1864 
       
  1865 !UIPainterView::ListHolder methodsFor:'initialization'!
       
  1866 
       
  1867 for:aPainter
       
  1868     "initialize for a painter
       
  1869     "
       
  1870     self list:(OrderedCollection new).
       
  1871     propertyList := OrderedCollection new.
       
  1872     self selection:#().
       
  1873     disabledChanged := false.
       
  1874     painter := aPainter.
       
  1875     self addDependent:painter.
       
  1876 
       
  1877 
       
  1878 ! !
       
  1879 
       
  1880 !UIPainterView::ListHolder methodsFor:'private'!
       
  1881 
       
  1882 basicRemove:start
       
  1883     "remove all resources assigned to a group starting at start;
       
  1884      no notifications are raised
       
  1885     "
       
  1886     |end view superView|
       
  1887 
       
  1888     end  := self lastInGroupStartingAt:start.
       
  1889     view := (propertyList at:start) view.
       
  1890 
       
  1891     view notNil ifTrue:[
       
  1892         superView := view superView.
       
  1893         view destroy.
       
  1894         superView sizeChanged:nil.
       
  1895     ].
       
  1896 
       
  1897     propertyList removeFromIndex:start toIndex:end.
       
  1898     self list    removeFromIndex:start toIndex:end.
       
  1899 !
       
  1900 
       
  1901 masterElement
       
  1902     "returns index of master
       
  1903     "
       
  1904     ^ self indexOfName:masterElement.
       
  1905 !
       
  1906 
       
  1907 masterElement:newIndex
       
  1908     "change master of selection
       
  1909     "
       
  1910     |name list oldIdx|
       
  1911 
       
  1912     (oldIdx := self masterElement) ~~ newIndex ifTrue:[
       
  1913         list := self list.
       
  1914         
       
  1915         oldIdx ~~ 0 ifTrue:[
       
  1916             list at:oldIdx put:masterElement
       
  1917         ].
       
  1918         newIndex ~~ 0 ifTrue:[
       
  1919             masterElement := list at:newIndex.
       
  1920             name := Text string:masterElement.
       
  1921             name emphasizeFrom:(1+(name leftIndent)) with:#(#bold #underline).
       
  1922             list at:newIndex put:name.
       
  1923         ] ifFalse:[
       
  1924             masterElement := nil
       
  1925         ].
       
  1926         self changed:#list.
       
  1927     ]
       
  1928 ! !
       
  1929 
       
  1930 !UIPainterView::ListHolder methodsFor:'searching'!
       
  1931 
       
  1932 detectProperty:aBlock
       
  1933     "find the property, for which evaluation of the argument, aBlock
       
  1934      returns true; return the property or nil if none detected
       
  1935     "
       
  1936     |idx|
       
  1937 
       
  1938     idx := self findProperty:aBlock.
       
  1939     idx ~~ 0 ifTrue:[ ^ propertyList at:idx ].
       
  1940   ^ nil
       
  1941 !
       
  1942 
       
  1943 findParentProperty:aChildProp
       
  1944     "returns index of parent or 0
       
  1945     "
       
  1946     |view index|
       
  1947 
       
  1948     view := aChildProp view.
       
  1949 
       
  1950     view notNil ifTrue:[
       
  1951         [ (view := view superView) notNil ] whileTrue:[
       
  1952             index := self findProperty:[:aProp| aProp view == view ].
       
  1953             index ~~ 0 ifTrue:[
       
  1954                 ^ index
       
  1955             ]
       
  1956         ]
       
  1957     ].
       
  1958     ^ 0
       
  1959 
       
  1960 
       
  1961 !
       
  1962 
       
  1963 findProperty:aBlock
       
  1964     "find the first property, for which evaluation of the argument, aBlock
       
  1965      returns true; return its index or 0 if none detected
       
  1966     "
       
  1967     ^ propertyList findFirst:aBlock
       
  1968 !
       
  1969 
       
  1970 indexOfName:aString
       
  1971     "returns index assigned to a string or 0
       
  1972     "
       
  1973     |name list size|
       
  1974 
       
  1975     aString notNil ifTrue:[
       
  1976         name := aString string withoutSeparators.
       
  1977         size := name size.
       
  1978         list := self list.
       
  1979 
       
  1980         list keysAndValuesDo:[:anIndex :aName|
       
  1981             |el|
       
  1982 
       
  1983             el := aName string.
       
  1984             (el endsWith:name) ifTrue:[
       
  1985                 (el size - el leftIndent) == name size ifTrue:[
       
  1986                     ^ anIndex
       
  1987                 ]
       
  1988             ]
       
  1989         ]
       
  1990     ].
       
  1991     ^ 0
       
  1992 
       
  1993 !
       
  1994 
       
  1995 lastInGroupStartingAt:start
       
  1996     "returns last index of a group
       
  1997     "
       
  1998     |end list idt|
       
  1999 
       
  2000     list := self list.
       
  2001 
       
  2002     start < list size ifTrue:[
       
  2003         idt := (list at:start) leftIndent.
       
  2004         end := list findFirst:[:el|(el leftIndent) <= idt] startingAt:(start+1).
       
  2005         end ~~ 0 ifTrue:[
       
  2006             ^ end - 1
       
  2007         ]
       
  2008     ].
       
  2009     ^ list size
       
  2010 ! !
       
  2011 
       
  2012 !UIPainterView::ListHolder methodsFor:'selection'!
       
  2013 
       
  2014 selectGroup
       
  2015     "select all elements assigned to master
       
  2016     "
       
  2017     |start end sel size|
       
  2018 
       
  2019     self canModify ifTrue:[
       
  2020         (start := self masterElement) ~~ 0 ifTrue:[
       
  2021             end  := self lastInGroupStartingAt:start.
       
  2022             size := end - start + 1.
       
  2023             sel  := Array new:size.
       
  2024 
       
  2025             1 to:size do:[:i|
       
  2026                 sel at:i put:start.
       
  2027                 start := start + 1
       
  2028             ].
       
  2029             self selectionIndex:sel.
       
  2030         ] ifFalse:[
       
  2031             (self selectionIndex) size == 0 ifFalse:[
       
  2032                 self selectionIndex:#()
       
  2033             ].
       
  2034         ]
       
  2035     ]
       
  2036 !
       
  2037 
       
  2038 selectedProperty
       
  2039     "returns current selected instance; in case of multiple selection
       
  2040      or no selection nil is returned
       
  2041     "
       
  2042     |selection|
       
  2043     selection := self selectionIndex.
       
  2044 
       
  2045     selection size == 1 ifTrue:[
       
  2046         ^ propertyList at:(selection at:1)
       
  2047     ].
       
  2048     ^ nil
       
  2049 !
       
  2050 
       
  2051 selectionIndex:aList
       
  2052     |masterIndex aSel|
       
  2053 
       
  2054     self canModify ifTrue:[aSel := aList]
       
  2055                   ifFalse:[aSel := nil].
       
  2056 
       
  2057     aSel size ~~ 0 ifTrue:[masterIndex := aSel at:1]
       
  2058                   ifFalse:[masterIndex := 0].
       
  2059 
       
  2060     self masterElement:masterIndex.
       
  2061     super selectionIndex:aSel
       
  2062 ! !
       
  2063 
  1699 !UIPainterView class methodsFor:'documentation'!
  2064 !UIPainterView class methodsFor:'documentation'!
  1700 
  2065 
  1701 version
  2066 version
  1702     ^ '$Header$'
  2067     ^ '$Header$'
  1703 ! !
  2068 ! !