UIPainter.st
author tz
Sat, 17 Jan 1998 00:27:00 +0100
changeset 416 d28e8c5f25f3
parent 394 1933896da0c3
child 437 6317d2f08662
permissions -rw-r--r--
image editor startup revised

"
 COPYRIGHT (c) 1995 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"


ApplicationModel subclass:#UIPainter
	instanceVariableNames:'treeView selectionPanel tabSelection specClass specSelector
		specSuperclass aspects layoutCanvas helpCanvas specCanvas
		transcript'
	classVariableNames:'IconStepUp IconStepOut IconStepIn IconStepDown'
	poolDictionaries:''
	category:'Interface-UIPainter'
!

SelectionInTreeView subclass:#TreeView
	instanceVariableNames:'lastDrawnMaster cvsEventsDisabled imageMasterParent
		imageEmptyParent imageMasterChild windowSpec'
	classVariableNames:'ImageMasterParent ImageMasterChild ImageEmptyParent'
	poolDictionaries:''
	privateIn:UIPainter
!

!UIPainter class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

!

documentation
"
    GUI-Builder:
    this class allows the user to build its own applications providing a graphical
    user interface to buildin components and to define the behavior of the components
    during runtime. The resulting specifications can be installed as methods on 
    classes, typically subclasses of an ApplicationModel. These specifications
    are used by the UIBuilder to generate the application window and its component
    structues when open the application.

    [start with:]
        UIPainter open

    [author:]
        Claus Gittinger
        Claus Atzkern

    [see also:]
        UIBuilder
        ApplicationModel
        UISpecification
"

! !

!UIPainter class methodsFor:'instance creation'!

openOnClass:aClass andSelector:aSelector
    "open up an interface builder, fetching a spec from aClass
     via some selector
    "
    ^ self new openOnClass:aClass andSelector:aSelector
!

painter:aBuilderView
    "set the painter
    "
    |application|

    application := self new.
    application painter:aBuilderView.
  ^ application open
! !

!UIPainter class methodsFor:'ST-80 queries'!

preferenceFor:aSymbol
    "ST-80 compatible; always returns false
    "
    ^ false


! !

!UIPainter class methodsFor:'help specs'!

helpSpec
    "return a dictionary filled with helpKey -> helptext associations.
     These are used by the activeHelp tool."

    "
    UIHelpTool openOnClass:UIPainter    
    "

    <resource: #help>

  ^ super helpSpec addPairsFrom:#(

#moveSelectionLeft
'move selected widgets left while pressing the button'

#setToDefaultWidth
'set selected widgets to their default width'

#pasteBuffer
'paste widgets at current mouse position'

#moveSelectionUp
'move selected widgets up while pressing the button'

#galleryShown
'show or hide gallery view'

#moveSelectionDown
'move selected widgets down while pressing the button'

#spreadSelectionVer
'vertical spacing between selected widgets is made the same'

#menuChangeHierarchy
'change hierarchy of the selected widget'

#copyExtent
'copy extent of the selected widget'

#moveSelectionRight
'move selected widgets right while pressing the button'

#cancel
'reread specification and layout'

#pasteWithLayout
'paste widgets without changing their layouts'

#alignSelectionRight
'align selected widgets to the right edge of the dominant widget'

#alignSelectionLeftAndRight
'align selected widgets to the right and left edge of the dominant widget'

#pasteWidth
'change width of all selected widgets to the last copied extent width'

#alignSelectionTopAndBottom
'align selected widgets to the top and bottom edge of the dominant widget'

#copyLayout
'copy layout of the selected widget'

#painterShown
'show or hide painter view'

#pasteExtent
'change extent of all selected widgets to the last copied extent'

#pasteHeight
'change height of all selected widgets to the last copied extent height'

#accept
'write back changes'

#centerSelectionVer
'center vertical horizontal in contained view'

#centerSelectionHor
'center widgets horizontal to their top widget'

#menuAlignment
'provides a set of alignment operation on the current selected widgets'

#alignSelectionCenterVer
'align selected widgets horizontal to the center of the dominant widget'

#pasteLayout
'change layout of all selected widgets to the last copied layout'

#alignSelectionLeft
'align selected widgets to the left edge of the dominant widget'

#spreadSelectionHor
'horizontal spacing between selected widgets is made the same'

#alignSelectionBottom
'align selected widgets to the bottom edge of the dominant widget'

#setToDefaultExtent
'set selected widgets to their default extent'

#alignSelectionCenterHor
'align selected widgets vertical to the center of the dominant widget'

#alignSelectionTop
'align selected widgets to the top edge of the dominant widget'

#setToDefaultHeight
'set selected widgets to their default height'

)

    "Modified: / 29.10.1997 / 03:19:58 / cg"
! !

!UIPainter class methodsFor:'helpers'!

convertString:aString maxLineSize:maxCharactersPerLine skipLineFeed:skipLineFeed
    "converts a string to a string collection with maximum characters
     per line
    "
    |stream
        max     "{ Class:SmallInteger }"
        size    "{ Class:SmallInteger }"
        start   "{ Class:SmallInteger }"
        stop    "{ Class:SmallInteger }"
        cpySz   "{ Class:SmallInteger }"
        lnSz    "{ Class:SmallInteger }"|

    maxCharactersPerLine < 20 ifFalse:[max := maxCharactersPerLine - 1]
                               ifTrue:[max := 20].

    (size := aString size) <= max ifTrue:[
        ^ aString
    ].
    start  := 1.
    lnSz   := 0.
    stream := (String new:size) writeStream.

    [start <= size] whileTrue:[
        (start := aString indexOfNonSeparatorStartingAt:start) == 0 ifTrue:[
            ^ stream contents
        ].
        (aString at:start) == $\ ifTrue:[
            skipLineFeed ifFalse:[
                stream nextPut:$\
            ].
            start := start + 1.
            stream cr.
            start := start + 1.
            lnSz := 0.
        ] ifFalse:[
            (stop := aString indexOfSeparatorStartingAt:start) == 0 ifTrue:[
                    stop := size + 1
            ].
            (aString at:(stop - 1)) == $\ ifTrue:[
                stop := stop - 1
            ].
            cpySz := stop - start.

            lnSz == 0 ifFalse:[
                (lnSz := lnSz + cpySz) >= max ifTrue:[stream cr.    lnSz := cpySz ]
                                             ifFalse:[stream space. lnSz := lnSz + 1]
            ] ifTrue:[
                lnSz := cpySz
            ].
            stream nextPutAll:aString startingAt:start to:(stop - 1).
            start := stop.
        ]
    ].
    ^ stream contents
! !

!UIPainter class methodsFor:'icons'!

iconAlignB
    "returns image assigned to align bottom
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignB.xbm'

    "Modified: / 29.10.1997 / 03:18:16 / cg"
!

iconAlignCenterH
    "returns image assigned to center horizontal
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignCH.xbm'

    "Modified: / 29.10.1997 / 03:18:34 / cg"
!

iconAlignCenterV
    "returns image assigned to center vertical
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignCV.xbm'

    "Modified: / 29.10.1997 / 03:18:39 / cg"
!

iconAlignL
    "returns image assigned to align left
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignL.xbm'

    "Modified: / 29.10.1997 / 03:18:43 / cg"
!

iconAlignLR
    "returns image assigned to align left and right
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignLR.xbm'

    "Modified: / 29.10.1997 / 03:18:48 / cg"
!

iconAlignR
    "returns image assigned to align right
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignR.xbm'

    "Modified: / 29.10.1997 / 03:18:51 / cg"
!

iconAlignT
    "returns image assigned to align top
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignT.xbm'

    "Modified: / 29.10.1997 / 03:18:56 / cg"
!

iconAlignTB
    "returns image assigned to align top and bottom
    "

    <resource: #fileImage>

    ^ Image fromFile:'b_alignTB.xbm'

    "Modified: / 29.10.1997 / 03:19:01 / cg"
!

iconInstall

    <resource: #fileImage>

    ^ Image fromFile:'bitmaps/xpmBitmaps/misc_tools/SaveButton.xpm'

    "Modified: / 29.10.1997 / 03:19:06 / cg"
!

iconStepDown
    "returns image assigned to step down (change hierarchy).
    "

    <resource: #fileImage>

    IconStepDown isNil ifTrue:[
        IconStepDown := ((Image fromFile:'stepOver.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepDown

"
IconStepDown := nil
"

    "Modified: / 29.10.1997 / 03:19:14 / cg"
!

iconStepIn
    "returns image assigned to step in (change hierarchy).
    "

    <resource: #fileImage>

    IconStepIn isNil ifTrue:[
        IconStepIn := ((Image fromFile:'stepIn.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepIn

    "Modified: / 29.10.1997 / 03:19:19 / cg"
!

iconStepOut
    "returns image assigned to step out (change hierarchy).
    "

    <resource: #fileImage>

    IconStepOut isNil ifTrue:[
        IconStepOut := ((Image fromFile:'stepOut.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepOut

    "Modified: / 29.10.1997 / 03:19:25 / cg"
!

iconStepUp
    "returns image assigned to step up (change hierarchy).
    "

    <resource: #fileImage>

    IconStepUp isNil ifTrue:[
        IconStepUp := ((Image fromFile:'stepOver.xpm') rotated:90) flipHorizontal flipVertical
    ].
  ^ IconStepUp

"
IconStepUp := nil
"

    "Modified: / 29.10.1997 / 03:19:29 / cg"
! !

!UIPainter class methodsFor:'interface specs'!

gridParametersSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UIPainter andSelector:#gridParametersSpec
     UIPainter new openInterface:#gridParametersSpec
    "
    "UIPainter open"

    <resource: #canvas>

    ^

       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'Grid Parameters:'
              #'layout:' #(#LayoutFrame 219 0 193 0 484 0 366 0)
              #'label:' 'Grid Parameters:'
              #'min:' #(#Point 10 10)
              #'max:' #(#Point 1280 1024)
              #'bounds:' #(#Rectangle 219 193 485 367)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#LabelSpec
                    #'name:' 'gridParameters'
                    #'layout:' #(#LayoutOrigin 0 0 0 0)
                    #'label:' 'Grid Parameters:'
                    #'adjust:' #left
                    #'resizeForLabel:' true
                )
                 #(#CheckBoxSpec
                    #'name:' 'show'
                    #'layout:' #(#Point 30 31)
                    #'model:' #showGrid
                    #'label:' 'show grid'
                )
                 #(#CheckBoxSpec
                    #'name:' 'align'
                    #'layout:' #(#Point 30 57)
                    #'model:' #alignToGrid
                    #'label:' 'align to grid'
                )
                 #(#LabelSpec
                    #'name:' 'hrzLabel'
                    #'layout:' #(#Point 90 94)
                    #'label:' 'pixels horizontal'
                    #'resizeForLabel:' true
                )
                 #(#InputFieldSpec
                    #'name:' 'hrzField'
                    #'layout:' #(#LayoutFrame 33 0 91 0 86 0 113 0)
                    #'model:' #hspace
                    #'type:' #numberOrNil
                )
                 #(#LabelSpec
                    #'name:' 'vrtLabel'
                    #'layout:' #(#Point 90 118)
                    #'label:' 'pixels vertical'
                    #'resizeForLabel:' true
                )
                 #(#InputFieldSpec
                    #'name:' 'vrtField'
                    #'layout:' #(#LayoutFrame 33 0 115 0 86 0 137 0)
                    #'model:' #vspace
                    #'type:' #numberOrNil
                )
                 #(#HorizontalPanelViewSpec
                    #'name:' 'horizontalPanelView1'
                    #'layout:' #(#LayoutFrame 0 0.0 -30 1.0 0 1.0 0 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#ActionButtonSpec
                              #'name:' 'cancel'
                              #'label:' 'cancel'
                              #'model:' #cancel
                              #'extent:' #(#Point 128 24)
                          )
                           #(#ActionButtonSpec
                              #'name:' 'accept'
                              #'label:' 'accept'
                              #'model:' #accept
                              #'extent:' #(#Point 129 24)
                          )
                        )
                    )
                    #'horizontalLayout:' #fitSpace
                    #'verticalLayout:' #fitSpace
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
              )
          )
      )


!

nameAndSelectorSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UIPainter andSelector:#nameAndSelectorSpec
     UIPainter new openInterface:#nameAndSelectorSpec
    "

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'NameAndSelectorSpec'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'Painter'
              #'bounds:' #(#Rectangle 0 0 391 170)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#LabelSpec
                    #'name:' 'classLabel'
                    #'layout:' #(#AlignmentOrigin 50 0.11 51 0 1 0.5)
                    #'label:' 'class:'
                    #'adjust:' #right
                    #'resizeForLabel:' true
                )
                 #(#LabelSpec
                    #'name:' 'superClassLabel'
                    #'layout:' #(#AlignmentOrigin 50 0.11 77 0 1 0.5)
                    #'label:' 'superclass:'
                    #'adjust:' #right
                    #'resizeForLabel:' true
                )
                 #(#LabelSpec
                    #'name:' 'selectorLabel'
                    #'layout:' #(#AlignmentOrigin 50 0.11 105 0 1 0.5)
                    #'label:' 'selector:'
                    #'adjust:' #right
                    #'resizeForLabel:' true
                )
                 #(#InputFieldSpec
                    #'name:' 'methodNameField'
                    #'layout:' #(#LayoutFrame 51 0.11 95 0 -2 1.0 117 0)
                    #'tabable:' true
                    #'model:' #methodNameChannel
                )
                 #(#LabelSpec
                    #'name:' 'boxLabel'
                    #'layout:' #(#Point 2 10)
                    #'label:' 'class & selector for code:'
                    #'adjust:' #left
                    #'resizeForLabel:' true
                )
                 #(#InputFieldSpec
                    #'name:' 'classNameField'
                    #'layout:' #(#LayoutFrame 51 0.11 39 0 -2 1.0 61 0)
                    #'tabable:' true
                    #'model:' #classNameChannel
                )
                 #(#ComboBoxSpec
                    #'name:' 'comboBox1'
                    #'layout:' #(#LayoutFrame 51 0.11 67 0 0 1.0 89 0)
                    #'tabable:' true
                    #'model:' #superclassNameChannel
                    #'comboList:' #superclassNameDefaults
                )
                 #(#HorizontalPanelViewSpec
                    #'name:' 'commitPanel'
                    #'layout:' #(#LayoutFrame 0 0.0 -26 1.0 0 1.0 -2 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#ActionButtonSpec
                              #'name:' 'button1'
                              #'label:' 'cancel'
                              #'tabable:' true
                              #'model:' #cancel
                              #'extent:' #(#Point 190 24)
                          )
                           #(#ActionButtonSpec
                              #'name:' 'button2'
                              #'label:' 'ok'
                              #'tabable:' true
                              #'isDefault:' true
                              #'model:' #accept
                              #'extent:' #(#Point 190 22)
                          )
                        )
                    )
                    #'horizontalLayout:' #fitSpace
                    #'verticalLayout:' #fit
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
              )
          )
      )

    "Modified: 28.7.1997 / 16:49:49 / cg"
!

windowSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UIPainter andSelector:#windowSpec
     UIPainter new openInterface:#windowSpec
    "
    "UIPainter open"

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'Tree-View'
              #'layout:' #(#LayoutFrame 30 0 56 0 543 0 516 0)
              #'label:' 'Tree-View'
              #'min:' #(#Point 10 10)
              #'max:' #(#Point 1160 870)
              #'bounds:' #(#Rectangle 30 56 544 517)
              #'usePreferredExtent:' false
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#MenuPanelSpec
                    #'name:' 'menuPullDown'
                    #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 25 0)
                    #'tabable:' true
                    #'menu:' #menuPullDown
                )
                 #(#HorizontalPanelViewSpec
                    #'name:' 'menuContainer'
                    #'layout:' #(#LayoutFrame 0 0.0 26 0 0 1.0 58 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#MenuPanelSpec
                              #'name:' 'menuChangeHierarchy'
                              #'activeHelpKey:' #menuChangeHierarchy
                              #'enableChannel:' #hasOneSelectionOtherThanCanvas
                              #'tabable:' true
                              #'menu:' #menuChangeHierarchy
                              #'showSeparatingLines:' true
                              #'extent:' #(#Point 103 32)
                          )
                           #(#MenuPanelSpec
                              #'name:' 'menuAlignment'
                              #'activeHelpKey:' #menuAlignment
                              #'enableChannel:' #canMoveOrAlignSelection
                              #'tabable:' true
                              #'menu:' #menuAlignment
                              #'showSeparatingLines:' true
                              #'extent:' #(#Point 233 32)
                          )
                           #(#HorizontalPanelViewSpec
                              #'name:' 'panelViewButtons'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveLeft'
                                        #'activeHelpKey:' #moveSelectionLeft
                                        #'tabable:' true
                                        #'model:' #moveSelectionLeft
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'isTriggerOnDown:' true
                                        #'direction:' #left
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveRight'
                                        #'activeHelpKey:' #moveSelectionRight
                                        #'model:' #moveSelectionRight
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'isTriggerOnDown:' true
                                        #'direction:' #right
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveDown'
                                        #'activeHelpKey:' #moveSelectionDown
                                        #'model:' #moveSelectionDown
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'isTriggerOnDown:' true
                                        #'direction:' #down
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveUp'
                                        #'activeHelpKey:' #moveSelectionUp
                                        #'model:' #moveSelectionUp
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'isTriggerOnDown:' true
                                        #'direction:' #up
                                        #'extent:' #(#Point 22 24)
                                    )
                                  )
                              )
                              #'level:' 1
                              #'horizontalLayout:' #spreadSpace
                              #'verticalLayout:' #fitSpace
                              #'horizontalSpace:' 4
                              #'verticalSpace:' 4
                              #'extent:' #(#Point 125 32)
                          )
                        )
                    )
                    #'horizontalLayout:' #spread
                    #'verticalLayout:' #fit
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
                 #(#VariableVerticalPanelSpec
                    #'name:' 'vpanel'
                    #'layout:' #(#LayoutFrame 0 0.0 59 0.0 0 1.0 0 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#VariableHorizontalPanelSpec
                              #'name:' 'hpanel'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#ArbitraryComponentSpec
                                        #'name:' 'treeView'
                                        #'tabable:' true
                                        #'menu:' #menuCanvas
                                        #'hasHorizontalScrollBar:' true
                                        #'hasVerticalScrollBar:' true
                                        #'miniScrollerHorizontal:' true
                                        #'miniScrollerVertical:' true
                                        #'component:' #treeView
                                        #'hasBorder:' false
                                    )
                                     #(#ViewSpec
                                        #'name:' 'specHolderView'
                                        #'component:' 
                                         #(#SpecCollection
                                            #'collection:' 
                                             #(
                                               #(#NoteBookViewSpec
                                                  #'name:' 'noteBook'
                                                  #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -30 1.0)
                                                  #'enableChannel:' #enableChannel
                                                  #'tabable:' true
                                                  #'model:' #tabModel
                                                  #'menu:' #tabList
                                                  #'style:' #(#FontDescription #helvetica #medium #roman 10)
                                                  #'canvas:' #noteBookView
                                              )
                                               #(#HorizontalPanelViewSpec
                                                  #'name:' 'modifyPanel'
                                                  #'layout:' #(#LayoutFrame 0 0.0 -30 1.0 0 1.0 0 1.0)
                                                  #'component:' 
                                                   #(#SpecCollection
                                                      #'collection:' 
                                                       #(
                                                         #(#ActionButtonSpec
                                                            #'name:' 'cancelButton'
                                                            #'activeHelpKey:' #cancel
                                                            #'label:' 'cancel'
                                                            #'tabable:' true
                                                            #'model:' #cancel
                                                            #'enableChannel:' #modifiedChannel
                                                            #'extent:' #(#Point 164 24)
                                                        )
                                                         #(#ActionButtonSpec
                                                            #'name:' 'acceptButton'
                                                            #'activeHelpKey:' #accept
                                                            #'label:' 'accept'
                                                            #'tabable:' true
                                                            #'model:' #accept
                                                            #'enableChannel:' #modifiedChannel
                                                            #'extent:' #(#Point 165 24)
                                                        )
                                                      )
                                                  )
                                                  #'horizontalLayout:' #fitSpace
                                                  #'verticalLayout:' #fitSpace
                                                  #'horizontalSpace:' 3
                                                  #'verticalSpace:' 3
                                              )
                                            )
                                        )
                                        #'borderWidth:' 1
                                    )
                                  )
                              )
                              #'level:' 1
                              #'handles:' #(#Any 0.329435 1.0)
                          )
                           #(#TextEditorSpec
                              #'name:' 'Transcript'
                              #'hasHorizontalScrollBar:' true
                              #'hasVerticalScrollBar:' true
                              #'miniScrollerHorizontal:' true
                              #'miniScrollerVertical:' true
                          )
                        )
                    )
                    #'handles:' #(#Any 0.880597 1.0)
                )
              )
          )
      )

    "Modified: / 31.10.1997 / 18:35:20 / cg"
! !

!UIPainter class methodsFor:'menu specs'!

menuAlignment
    "this window spec was automatically generated by the ST/X MenuEditor"

    "do not manually edit this - the builder may not be able to
     handle the specification if its corrupted."

    "
     MenuEditor new openOnClass:UIPainter andSelector:#menuAlignment
     (Menu new fromLiteralArrayEncoding:(UIPainter menuAlignment)) startUp
    "

    <resource: #menu>

    ^
     
       #(#Menu
          
           #(
             #(#MenuItem
                #'label:' 'align left'
                #'value:' #alignSelectionLeft
                #'activeHelpKey:' #alignSelectionLeft
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignL
                )
            )
             #(#MenuItem
                #'label:' 'align right'
                #'value:' #alignSelectionRight
                #'activeHelpKey:' #alignSelectionRight
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignR
                )
            )
             #(#MenuItem
                #'label:' 'align left & right'
                #'value:' #alignSelectionLeftAndRight
                #'activeHelpKey:' #alignSelectionLeftAndRight
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignLR
                )
            )
             #(#MenuItem
                #'label:' 'align top'
                #'value:' #alignSelectionTop
                #'activeHelpKey:' #alignSelectionTop
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignT
                )
            )
             #(#MenuItem
                #'label:' 'align bottom'
                #'value:' #alignSelectionBottom
                #'activeHelpKey:' #alignSelectionBottom
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignB
                )
            )
             #(#MenuItem
                #'label:' 'align top & bottom'
                #'value:' #alignSelectionTopAndBottom
                #'activeHelpKey:' #alignSelectionTopAndBottom
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignTB
                )
            )
             #(#MenuItem
                #'label:' 'align centered horizontal'
                #'value:' #alignSelectionCenterHor
                #'activeHelpKey:' #alignSelectionCenterHor
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignCenterH
                )
            )
             #(#MenuItem
                #'label:' 'align centered vertical'
                #'value:' #alignSelectionCenterVer
                #'activeHelpKey:' #alignSelectionCenterVer
                #'labelImage:' 
                 #(#ResourceRetriever
                    nil #iconAlignCenterV
                )
            )
          )
          #( 3 3 )
          nil
      )
!

menuCanvas
    "this window spec was automatically generated by the ST/X MenuEditor"

    "do not manually edit this - the builder may not be able to
     handle the specification if its corrupted."

    "
     MenuEditor new openOnClass:UIPainter andSelector:#menuCanvas
     (Menu new fromLiteralArrayEncoding:(UIPainter menuCanvas)) startUp
    "

    <resource: #menu>

    ^

       #(#Menu
           #(
             #(#MenuItem
                #'label:' 'copy'
                #'value:' #copySelection
                #'enabled:' #hasSelection
                #'shortcutKeyCharacter:' #Copy
            )
             #(#MenuItem
                #'label:' 'cut'
                #'value:' #deleteSelection
                #'enabled:' #hasSelection
                #'shortcutKeyCharacter:' #Cut
            )
             #(#MenuItem
                #'label:' 'paste'
                #'nameKey:' #paste
                #'enabled:' #canPaste
                #'value:' #paste
                #'submenu:' 
                 #(#Menu

                     #(
                       #(#MenuItem
                          #'label:' 'paste'
                          #'value:' #pasteBuffer
                          #'activeHelpKey:' #pasteBuffer
                          #'shortcutKeyCharacter:' #Paste
                      )
                       #(#MenuItem
                          #'label:' 'keep layout'
                          #'value:' #pasteWithLayout
                          #'enabled:' #canKeepLayoutInSelection
                          #'activeHelpKey:' #pasteWithLayout
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' '-'
            )
             #(#MenuItem
                #'label:' 'undo'
                #'nameKey:' #undo
                #'enabled:' #hasUndoHistory
                #'shortcutKeyCharacter:' #Cmdu
                #'value:' #undoLast
            )
             #(#MenuItem
                #'label:' '-'
            )
             #(#MenuItem
                #'label:' 'dimension'
                #'value:' #dimension
                #'enabled:' #hasSelection
                #'submenu:' 
                 #(#Menu

                     #(
                       #(#MenuItem
                          #'label:' 'default extent'
                          #'value:' #setToDefaultExtent
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #setToDefaultExtent
                      )
                       #(#MenuItem
                          #'label:' 'default width'
                          #'value:' #setToDefaultWidth
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #setToDefaultWidth
                      )
                       #(#MenuItem
                          #'label:' 'default height'
                          #'value:' #setToDefaultHeight
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #setToDefaultHeight
                      )
                       #(#MenuItem
                          #'label:' 'copy extent'
                          #'value:' #copyExtent
                          #'enabled:' #hasSingleSelection
                          #'activeHelpKey:' #copyExtent
                      )
                       #(#MenuItem
                          #'label:' 'paste extent'
                          #'value:' #pasteExtent
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #pasteExtent
                      )
                       #(#MenuItem
                          #'label:' 'paste width'
                          #'value:' #pasteWidth
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #pasteWidth
                      )
                       #(#MenuItem
                          #'label:' 'paste height'
                          #'value:' #pasteHeight
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #pasteHeight
                      )
                       #(#MenuItem
                          #'label:' 'copy  layout'
                          #'value:' #copyLayout
                          #'enabled:' #hasSingleSelection
                          #'activeHelpKey:' #copyLayout
                      )
                       #(#MenuItem
                          #'label:' 'paste layout'
                          #'value:' #pasteLayout
                          #'enabled:' #canMoveOrAlignSelection
                          #'activeHelpKey:' #pasteLayout
                      )
                    )
                    #(3 1 3)
                    nil
                )
            )
             #(#MenuItem
                #'label:' 'align'
                #'value:' #align
                #'enabled:' #canMoveOrAlignSelection
                #'submenu:' 
                 #(#Menu

                     #(
                       #(#MenuItem
                          #'label:' 'align left'
                          #'value:' #alignSelectionLeft
                          #'activeHelpKey:' #alignSelectionLeft
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignL
                              'align left'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align right'
                          #'value:' #alignSelectionRight
                          #'activeHelpKey:' #alignSelectionRight
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignR
                              'align right'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align left & right'
                          #'value:' #alignSelectionLeftAndRight
                          #'activeHelpKey:' #alignSelectionLeftAndRight
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignLR
                              'align left & right'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align top'
                          #'value:' #alignSelectionTop
                          #'activeHelpKey:' #alignSelectionTop
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignT
                              'align top'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align bottom'
                          #'value:' #alignSelectionBottom
                          #'activeHelpKey:' #alignSelectionBottom
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignB
                              'align bottom'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align top & bottom'
                          #'value:' #alignSelectionTopAndBottom
                          #'activeHelpKey:' #alignSelectionTopAndBottom
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignTB
                              'align top & bottom'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align centered horizontal'
                          #'value:' #alignSelectionCenterHor
                          #'activeHelpKey:' #alignSelectionCenterHor
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignCenterH
                              'align centered horizontal'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'align centered vertical'
                          #'value:' #alignSelectionCenterVer
                          #'activeHelpKey:' #alignSelectionCenterVer
                          #'labelImage:' 
                           #(#ResourceRetriever
                              #UIPainter #iconAlignCenterV
                              'align centered vertical'
                          )
                      )
                       #(#MenuItem
                          #'label:' 'spread horizontal'
                          #'value:' #spreadSelectionHor
                          #'activeHelpKey:' #spreadSelectionHor
                      )
                       #(#MenuItem
                          #'label:' 'spread vertical'
                          #'value:' #spreadSelectionVer
                          #'activeHelpKey:' #spreadSelectionVer
                      )
                       #(#MenuItem
                          #'label:' 'center horizontal in frame'
                          #'value:' #centerSelectionHor
                          #'activeHelpKey:' #centerSelectionHor
                      )
                       #(#MenuItem
                          #'label:' 'center vertical in frame'
                          #'value:' #centerSelectionVer
                          #'activeHelpKey:' #centerSelectionVer
                      )
                    )
                    #(8 2)
                    nil
                )
            )
          ) nil
          nil
      )


!

menuChangeHierarchy
    "this window spec was automatically generated by the ST/X MenuEditor"

    "do not manually edit this - the builder may not be able to
     handle the specification if its corrupted."

    "
     MenuEditor new openOnClass:UIPainter andSelector:#menuChangeHierarchy
     (Menu new fromLiteralArrayEncoding:(UIPainter menuChangeHierarchy)) startUp
    "

    <resource: #menu>

    ^
     
       #(#Menu
          
           #(
             #(#MenuItem
                #'label:' 'stepUp'
                #'value:' #doStepUp
                #'labelImage:' #(#ResourceRetriever #UIPainter #iconStepUp)
            )
             #(#MenuItem
                #'label:' 'stepDown'
                #'value:' #doStepDown
                #'labelImage:' #(#ResourceRetriever #UIPainter #iconStepDown)
            )
             #(#MenuItem
                #'label:' 'stepIn'
                #'value:' #doStepIn
                #'enabled:' #canMoveSelectionIntoContainer
                #'labelImage:' #(#ResourceRetriever #UIPainter #iconStepIn)
            )
             #(#MenuItem
                #'label:' 'stepOut'
                #'value:' #doStepOut
                #'enabled:' #canMoveSelectionOutOfContainer
                #'labelImage:' #(#ResourceRetriever #UIPainter #iconStepOut)
            )
          ) nil
          nil
      )
!

menuPullDown
    "this window spec was automatically generated by the ST/X MenuEditor"

    "do not manually edit this - the builder may not be able to
     handle the specification if its corrupted."

    "
     MenuEditor new openOnClass:UIPainter andSelector:#menuPullDown
     (Menu new fromLiteralArrayEncoding:(UIPainter menuPullDown)) startUp
    "

    <resource: #menu>

    ^
     
       #(#Menu
          
           #(
             #(#MenuItem
                #'label:' 'file'
                #'value:' #file
                #'enabled:' #enableChannel
                #'submenu:' 
                 #(#Menu
                    
                     #(
                       #(#MenuItem
                          #'label:' 'new'
                          #'value:' #doNew
                      )
                       #(#MenuItem
                          #'label:' 'from class ...'
                          #'value:' #doFromClass
                      )
                       #(#MenuItem
                          #'label:' 'pick a view '
                          #'value:' #doPickAView
                      )
                       #(#MenuItem
                          #'label:' '-'
                      )
                       #(#MenuItem
                          #'label:' 'quit'
                          #'value:' #closeRequest
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' 'misc'
                #'value:' #misc
                #'enabled:' #enableChannel
                #'submenu:' 
                 #(#Menu
                    
                     #(
                       #(#MenuItem
                          #'label:' 'grid'
                          #'value:' #grid
                          #'submenu:' 
                           #(#Menu
                              
                               #(
                                 #(#MenuItem
                                    #'label:' 'show'
                                    #'indication:' #'gridShown:'
                                )
                                 #(#MenuItem
                                    #'label:' 'align'
                                    #'indication:' #'gridAlign:'
                                )
                                 #(#MenuItem
                                    #'label:' '-'
                                )
                                 #(#MenuItem
                                    #'label:' 'menu'
                                    #'value:' #gridMenu
                                )
                              ) nil
                              nil
                          )
                      )
                       #(#MenuItem
                          #'label:' 'undo'
                          #'value:' #undo
                          #'submenu:' 
                           #(#Menu
                              
                               #(
                                 #(#MenuItem
                                    #'label:' 'last'
                                    #'value:' #undoLast
                                )
                                 #(#MenuItem
                                    #'label:' 'menu'
                                    #'value:' #openUndoMenu
                                )
                                 #(#MenuItem
                                    #'label:' '-'
                                )
                                 #(#MenuItem
                                    #'label:' 'delete'
                                    #'value:' #removeUndoHistory
                                )
                              ) nil
                              nil
                          )
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' 'code'
                #'value:' #code
                #'enabled:' #enableChannel
                #'submenu:' 
                 #(#Menu
                    
                     #(
                       #(#MenuItem
                          #'label:' 'class && method ...'
                          #'value:' #defineClassAndSelector
                      )
                       #(#MenuItem
                          #'label:' '-'
                      )
                       #(#MenuItem
                          #'label:' 'install window spec.'
                          #'value:' #doInstallSpec
                      )
                       #(#MenuItem
                          #'label:' 'install aspects'
                          #'value:' #doInstallAspects
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' 'install hooks'
                          #'value:' #doInstallHooks
                      )
                       #(#MenuItem
                          #'label:' 'install help spec.'
                          #'value:' #doInstallHelp
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' '-'
                      )
                       #(#MenuItem
                          #'label:' 'show window spec.'
                          #'value:' #doWindowSpec
                      )
                       #(#MenuItem
                          #'label:' 'browse application'
                          #'value:' #doBrowseAppClass
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' 'browse aspect methods'
                          #'value:' #doBrowseAspectMethods
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' 'test'
                #'nameKey:' #test
                #'value:' #test
                #'submenu:' 
                 #(#Menu
                    
                     #(
                       #(#MenuItem
                          #'label:' 'geometry test mode'
                          #'indication:' #'testMode:'
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' ''
            )
             #(#MenuItem
                #'label:' 'Gallery'
                #'indication:' #galleryShown
            )
             #(#MenuItem
                #'label:' 'Canvas'
                #'indication:' #painterShown
            )
             #(#MenuItem
                #'label:' ''
            )
             #(#MenuItem
                #'label:' '-'
            )
             #(#MenuItem
                #'label:' 'Install'
                #'value:' #doInstallSpec
                #'labelImage:' #(#ResourceRetriever nil #iconInstall 'Install')
            )
             #(#MenuItem
                #'label:' '-'
            )
             #(#MenuItem
                #'label:' 'Run'
                #'value:' #doStartApplication
            )
             #(#MenuItem
                #'label:' '-'
            )
          ) nil
          nil
      )

    "Modified: / 31.10.1997 / 17:35:38 / cg"
! !

!UIPainter methodsFor:'actions'!

accept
    "accept changes done to the specification. The component assigned to the
     specification will change immediately dependant on the attributes derived
     from the specification.
    "
    |layout spec prop key layoutTool|

    self isLayoutToolSelected ifTrue:[
        layoutTool := self layoutTool.

        (layout := layoutTool layout) notNil ifTrue:[
            layoutTool layoutType == #Extent ifTrue:[
                layoutTool layoutView == self painter topView ifTrue:[
                    layoutTool layoutView extent:layout
                ] ifFalse:[
                    self painter setExtent:layout
                ]
            ] ifFalse:[
                self painter setLayout:layout
            ]
        ]
    ] ifFalse:[
        spec := self specTool specification.

        self isHelpToolSelected ifTrue:[
            self helpTool accept.
            key  := self helpTool helpKey.
            prop := treeView propertySelected.

            prop notNil ifTrue:[
                prop spec activeHelpKey:key
            ].
            spec activeHelpKey:key.
        ] ifFalse:[
            self painter updateFromSpec:spec.
        ]
    ].
    self modifiedChannel value:false.
!

cancel
    "cancel all changes done to the specification; reread attributes from the
     assigned component
    "
    |spec key view|

    self isModified ifTrue:[
        (spec := self painter specForSelection) notNil ifTrue:[
            key := spec activeHelpKey.
        ].
        self helpTool helpKey:key.
        self specTool specification:spec.
        view := self layoutTool layoutView.

        self setViewInLayoutTool:view.
        spec class == DataSetSpec ifTrue:[
            view columnDescriptors:(spec columns)
        ].        
        self modifiedChannel value:false.
    ]
!

moveSelectionDown
    "move selected components down
    "
    self painter moveSelectionDown
!

moveSelectionLeft
    "move selected components left
    "
    self painter moveSelectionLeft

!

moveSelectionRight
    "move selected components right
    "
    self painter moveSelectionRight

!

moveSelectionUp
    "move selected components up
    "
    self painter moveSelectionUp

!

openDataSetColumnEditor
    "opens a column editor
    "
    |cls aspect editor columns|

    cls := self resolveName:specClass.

    cls isNil ifTrue:[
        ^ self information:'no application class defined yet'
    ].
    aspect := self specTool specification columns.
    editor := DataSetBuilder new.
    editor masterApplication:self.
    editor columns:aspect fromView:(self layoutTool layoutView).
    editor rowClassName:(self specTool specification rowClassName).
    editor openModal.

    editor hasChanged ifTrue:[
        self specTool specification columns:(editor columns).
        self specTool specification rowClassName:(editor rowClassName).
        self modifiedChannel value:true.
    ].
!

openEditMenu
    "opens a menu editor on current widget
    "
    |cls aspect editor|

    cls := self resolveName:specClass.

    cls isNil ifTrue:[
        ^ self information:'no application class defined yet'
    ].

    cls notNil ifTrue:[
        (aspect := self specTool specification menuSelector) notNil ifTrue:[
            aspect := aspect asSymbol
        ] ifFalse:[
            "/ cg: q&d hack ...

            aspect := treeView propertySelected.
            aspect notNil ifTrue:[
                Object errorSignal handle:[:ex |
                    aspect := nil.
                ] do:[
                    aspect := aspect view asMenu.
                ]
            ].
        ].
        
        editor := MenuEditor new.
        editor masterApplication:self.
        editor useHelpDictionary:(self helpTool dictionary).
        editor openModalOnClass:cls andSelector:aspect.
        self helpTool updateList.

        editor selectorName ~= aspect ifTrue:[
            editor didInstall ifTrue:[
                self specTool specification menuSelector:editor selectorName asSymbol.
                self modifiedChannel value:true.
                self accept
            ]
        ].
    ]

    "Modified: 31.7.1997 / 14:26:13 / cg"
!

openHierarchicalListEditor
    "opens a hierarchical list editor editor on current widget
    "
    |cls aspect editor|

    cls := self resolveName:specClass.

    cls isNil ifTrue:[
        ^ self information:'no application class defined yet'
    ].

    (aspect := self specTool specification hierarchicalList) notNil ifTrue:[
        aspect := aspect asSymbol
    ] ifFalse:[
        "/ cg: q&d hack ...

        aspect := treeView propertySelected.
        aspect notNil ifTrue:[
            Object errorSignal handle:[:ex |
                aspect := nil.
            ] do:[
                aspect := aspect view asMenu.
            ]
        ].
    ].
    
    editor := HierarchicalListEditor new.
    editor masterApplication:self.
    editor openModalOnClass:cls andSelector:aspect.

    editor selectorName ~= aspect ifTrue:[
        editor didInstall ifTrue:[
            self specTool specification hierarchicalList:editor selectorName asSymbol.
            self modifiedChannel value:true.
            self accept
        ]
    ]
! !

!UIPainter methodsFor:'active help'!

showHelp:aHelpText for:view
    "display active help texts in my own info area."

    |txt|

    aHelpText isNil ifTrue:[
        txt := nil
    ] ifFalse:[
        txt := self class 
                convertString:(aHelpText asString)
                maxLineSize:(transcript width // transcript font width)
               skipLineFeed:true
    ].
    transcript hideCursor.
    transcript contents:txt.
    ^ true

    "Modified: / 29.10.1997 / 22:33:55 / cg"
! !

!UIPainter methodsFor:'aspects'!

canMoveOrAlignSelection
    "returns a boolean value holder which is true in case that any selection exists
     and all widgets in the selection can change its layout through to a move or
     align operation
    "
    ^ builder booleanValueAspectFor:#canMoveOrAlignSelection
!

canMoveSelectionIntoContainer
    "returns a boolean value holder which is true in case that one component is selected
     and can change its container widget to the next element in the list which will have
     the same container.
    "
    ^ builder booleanValueAspectFor:#canMoveSelectionIntoContainer
!

canMoveSelectionOutOfContainer
    "returns a boolean value holder which is true in case that one component is selected
     which is contained within another component
    "
    ^ builder booleanValueAspectFor:#canMoveSelectionOutOfContainer
!

enableChannel
    "true if modifications are allowed otherwise running test
    "
  ^ self painter enableChannel
!

galleryShown
    "returns a boolean value holder which is set to true if the gallery is shown
    "
    |holder|

    (holder := builder bindingAt:#galleryShown) isNil ifTrue:[
        builder aspectAt:#galleryShown put:(holder :=  true asValue).
        holder addDependent:self
    ].
    ^ holder

!

hasOneSelectionOtherThanCanvas
    "returns a value holder which is true in case that one component is selected
     other than the canvas.
    "
    ^ builder booleanValueAspectFor:#hasOneSelectionOtherThanCanvas
!

modifiedChannel
    "returns a boolean value holder which is set to true if something is modified
     and not accepted
    "
    ^ builder booleanValueAspectFor:#modifiedChannel
!

noteBookView
    "returns the notebook view; initialize components within the notebook
    "
    |noteBook channel helpTool layoutTool specTool|

    (noteBook := builder bindingAt:#noteBookView) isNil ifTrue:[
        noteBook   := View new.
        layoutTool := UILayoutTool new.
        helpTool   := UIHelpTool   new.
        helpTool helpSpecFrom:specClass.
        specTool   := UISpecificationTool new.
        channel    := self modifiedChannel.

        layoutTool masterApplication:self.
        specTool   masterApplication:self.
        helpTool   masterApplication:self.

        layoutCanvas := SubCanvas origin:0.0@0.0 corner:1.0@1.0 in:noteBook.
        helpCanvas   := SubCanvas origin:0.0@0.0 corner:1.0@1.0 in:noteBook.
        specCanvas   := SubCanvas origin:0.0@0.0 corner:1.0@1.0 in:noteBook.

        layoutCanvas client:layoutTool.
        helpCanvas   client:helpTool.
        specTool builder:(specCanvas client:specTool).

        layoutTool masterApplication:self.
        specTool   masterApplication:self.
        helpTool   masterApplication:self.

        layoutTool modifiedHolder:channel.
        helpTool   modifiedHolder:channel.
        specTool   modifiedHolder:channel.

        builder aspectAt:#noteBookView put:noteBook.
    ].
    ^ noteBook
!

painterShown
    "returns a boolean value holder which is set to true if the painter is shown
    "
    |holder|

    (holder := builder bindingAt:#painterShown) isNil ifTrue:[
        builder aspectAt:#painterShown put:(holder :=  true asValue).
        holder addDependent:self
    ].
    ^ holder

!

tabList
    "returns a value holder which keeps a list of labels assigned to the tabs
    "
    |holder|

    (holder := builder bindingAt:#tabList) isNil ifTrue:[
        builder aspectAt:#tabList put:(holder :=  ValueHolder new).
        holder value:#( 'Properties' ).
    ].
    ^ holder
!

tabModel
    "returns a value holder which keeps the current name of the tab selected
    "
    |holder|

    (holder := builder bindingAt:#tabModel) isNil ifTrue:[
        holder := AspectAdaptor new subject:self; forAspect:#tabSelection.
        builder aspectAt:#tabModel put:holder.
    ].
    ^ holder
!

treeView
    "returns the selection tree view which holds all widget identifiers
    "
    ^ treeView
! !

!UIPainter methodsFor:'binding access'!

aspectFor:aKey
    "aspect for a key
    "
  ^ aspects at:aKey ifAbsent:[ super aspectFor:aKey ]
! !

!UIPainter methodsFor:'change & update'!

layoutChanged
    "called by the painter/canvas whenever the layout of the current selected
     widget changed
    "
    self isModified ifFalse:[
        self layoutTool update.
        self modifiedChannel value:false
    ]
!

propertyChanged
    "called by the painter/canvas whenever the property of the current selected
     widget changed
    "
    |p|

    (p := treeView propertySelected) notNil ifTrue:[
        self specTool specification:(p spec copy).
        self setViewInLayoutTool:(p view).
        self modifiedChannel value:false
    ] ifFalse:[
        self layoutTool layoutView notNil ifTrue:[
            self modifiedChannel value:false.
            self treeSelection
        ]
    ]
!

update:something with:aParameter from:someObject
    "catch change notifications
    "
    someObject == treeView model ifTrue:[
        (something == #selection
        or:[something == #selectionIndex]) ifTrue:[self treeSelection].
      ^ self
    ].

    self galleryShown == someObject ifTrue:[
        (self galleryShown value) ifTrue:[
            self raiseUIView:(selectionPanel window)
        ] ifFalse:[
            self hideUIView:(selectionPanel window)
        ].
      ^ self
    ].

    self painterShown == someObject ifTrue:[
        (self painterShown value) ifTrue:[
            self raiseUIView:(self painter topView)
        ] ifFalse:[
            self hideUIView:(self painter topView)
        ].
      ^ self
    ].

    "Modified: / 29.10.1997 / 17:48:19 / cg"
! !

!UIPainter methodsFor:'event handling'!

doesNotUnderstand:aMessage

    |painter|

    painter := self painter.

    (painter respondsTo:(aMessage selector)) ifTrue:[
        ^ aMessage sendTo:painter
    ].
    super doesNotUnderstand:aMessage

! !

!UIPainter methodsFor:'menu accessing'!

menuAlignment
    "returns the pull down menu which keeps the alignment operations
    "
    ^ self class menuAlignment

!

menuCanvas
    "returns the middle button menu used by the painter and the tree view
    "
    ^ [ treeView canvas showMiddleButtonMenu ]
!

menuChangeHierarchy
    "returns the hierarchy pull down menu
    "
    ^ self class menuChangeHierarchy


!

menuPullDown
    "returns the main pull down menu
    "
    ^ self class menuPullDown


! !

!UIPainter methodsFor:'printing'!

show:aText
    transcript hideCursor.
    transcript contents:aText.
        
! !

!UIPainter methodsFor:'private'!

hideUIView:aView
    "hide the view which is an application or top view
    "
    aView beIndependent.
    aView unmap.
!

raiseTabView

    self isLayoutToolSelected ifTrue:[
        layoutCanvas raise
    ] ifFalse:[
        self isHelpToolSelected ifTrue:[
            helpCanvas raise
        ] ifFalse:[
            self specTool selection:tabSelection.
            specCanvas raise
        ]
    ]
!

raiseUIView:aView
    "raise the view which is an application or top view
    "
    aView map.
    aView bePartner.
!

setClass:cls selector:selector
    "set the application class and the selector under which the
     window specification should be stored
    "
    |clsName superClassName|

    clsName := cls name.
    superClassName := cls superclass name.

    (self aspectFor:#classNameChannel) value:clsName.
    (self aspectFor:#methodNameChannel) value:(selector ? '').
    (self aspectFor:#superclassNameChannel) value:superClassName.

    self painter 
            className:clsName 
            superclassName:superClassName
            selector:(selector ? '').

    self specClass:clsName.
    specSelector := (selector ? '').
    specSuperclass := superClassName.

    "Modified: 24.6.1997 / 19:07:01 / cg"
!

setViewInLayoutTool:aView
    "set view for layout tool
    "
    |type|

    self painter topView == aView ifTrue:[
        type := #Extent
    ].
    self layoutTool layoutView:aView type:type

!

specClass:aClass
    specClass := aClass.
    self helpTool helpSpecFrom:specClass.
! !

!UIPainter methodsFor:'private tools'!

helpTool
    "returns the help tool
    "
    helpCanvas isNil ifTrue:[
        self noteBookView
    ].
    ^ helpCanvas application
!

layoutTool
    "returns the layout tool
    "
    layoutCanvas isNil ifTrue:[
        self noteBookView
    ].
    ^ layoutCanvas application
!

painter
    "returns the painter/canvas view
    "
    ^ treeView canvas
!

specTool
    "returns the spec tool
    "
    specCanvas isNil ifTrue:[
        self noteBookView
    ].
    ^ specCanvas application
! !

!UIPainter methodsFor:'queries'!

hasSpecClass
    "checks whether an application class is defined
    "
    ^ (self resolveName:specClass) notNil
!

hasSpecClassAndSelector
    "checks whether an application class and a selector under which
     the window specification is stored is defined.
    "
    specSelector size > 1 ifTrue:[
        ^ self hasSpecClass
    ].
  ^ false
!

isHelpToolSelected
    "returns true if current selected tab in the noteBook is assigned
     to the 'Help' tool
    "
    ^ tabSelection = UIHelpTool label

!

isLayoutToolSelected
    "returns true if current selected tab in the noteBook is assigned
     to the 'Layout' tool
    "
    ^ tabSelection = UILayoutTool label
!

isModified
    "returns true if current specification or layout is modified
    "
    ^ self modifiedChannel value
!

isPainterEnabled
    "returns true if not running in test mode
    "
    ^ self painter enabled
! !

!UIPainter methodsFor:'selection'!

tabSelection
    "returns name of current selected tab in the notebook.
    "
    ^ tabSelection
!

tabSelection:something
    "the tab selection of the notebook changed
    "

    |whatToDo|

    (something isNil or:[tabSelection = something]) ifTrue:[
        ^ self
    ].

    self isModified ifTrue:[
        whatToDo := DialogBox 
                        confirmWithCancel:'accept change made in ' , tabSelection printString , ' section ?'
                        labels:#('cancel' 'ignore' 'accept')
                        default:3.
        whatToDo isNil ifTrue:[^self].
        whatToDo == true ifTrue:[
            self accept
        ] ifFalse:[
            self cancel
        ]
    ].

    tabSelection := something.
    self raiseTabView.
    self cancel.

    "Modified: / 26.10.1997 / 15:54:15 / cg"
!

treeSelection
    "called whenever the selection of the treeview changed
    "
    |view list spec slices size property tabComponent|

    self isModified ifTrue:[
        (self confirm:'accept change made in ' , tabSelection printString , ' section ?') ifTrue:[
            self accept
        ]
    ].
    self canMoveOrAlignSelection        value:(treeView canMoveOrAlignSelection).
    self canMoveSelectionIntoContainer  value:(treeView canMoveSelectionIntoContainer).
    self canMoveSelectionOutOfContainer value:(treeView canMoveSelectionOutOfContainer).
    self hasOneSelectionOtherThanCanvas value:(treeView hasOneSelectionOtherThanCanvas).

    treeView isCanvasSelected ifTrue:[
        spec := treeView canvasSpec.
        view := self painter topView.
    ] ifFalse:[
        (property := treeView propertySelected) notNil ifTrue:[
            treeView canResizeSelectedWidget ifTrue:[
                view := property view.
            ].
            spec := property spec copy.
        ]
    ].
    tabComponent := builder componentAt:#noteBook.
    self setViewInLayoutTool:view.
    self specTool specification:spec.

    spec notNil ifTrue:[
        self helpTool helpKey:(spec activeHelpKey).
        slices := spec class slices.
        size   := slices size.

        view notNil ifTrue:[
            list := Array new:(size + 2).
            list at:(size + 2) put:(UILayoutTool label).
        ] ifFalse:[
            list := Array new:(size + 1).
        ].
        1 to:size do:[:i| list at:i put:((slices at:i) first asString)].
        list at:(size + 1) put:(UIHelpTool   label).

        self tabList value:list.
        self show:(spec class name).
        tabComponent enabled:true.

        (tabSelection := tabComponent selection) isNil ifTrue:[
            tabComponent setSelection:(tabSelection := list first)
        ].
        self raiseTabView
    ] ifFalse:[
        self helpTool helpKey:nil.
        tabComponent enabled:false.
        self show:nil.
    ].
    self modifiedChannel value:false.
! !

!UIPainter methodsFor:'startup / release'!

closeRequest
    "close all windows open by builder
    "
    self painter isModified ifTrue:[
        (self confirm:'quit without without saving your modifications ?') ifFalse:[
            ^ self
        ]
    ].

    treeView model removeDependent:self.
    self painter release.
    ColorMenu releaseResources.

    selectionPanel notNil ifTrue:[
        selectionPanel masterApplication:nil.
        selectionPanel closeRequest
    ].
    selectionPanel := nil.
    treeView       := nil.

    ActiveHelp stopFor:self.

    super closeRequest.

    "Modified: / 27.10.1997 / 00:01:30 / cg"
!

closeRequestFor:aTopView
    "handle a close request for a specific view
    "
    |topView|

    topView := self window.

    topView == aTopView ifTrue:[
        super closeRequestFor:aTopView
    ] ifFalse:[
        aTopView = selectionPanel window ifTrue:[
            self galleryShown value:false
        ] ifFalse:[
            self painterShown value:false
        ].
        topView raise.
    ].
!

openInterface:aSymbol
    "open interfaces
    "
    |painterView painter cls topView|

    aspects := IdentityDictionary new.

    aspects at:#classNameChannel put:(
        (specClass notNil ifTrue:[specClass]
                         ifFalse:['NewApplication']) asValue
    ).
    specSuperclass isNil ifTrue:[
        specClass notNil ifTrue:[
            (cls := self resolveName:specClass) notNil ifTrue:[
                specSuperclass := cls superclass name.
            ]
        ]
    ].
    aspects at:#superclassNameChannel put:(
        (specSuperclass notNil ifTrue:[specSuperclass]
                         ifFalse:['ApplicationModel']) asValue
    ).
    aspects at:#superclassNameDefaults put:#('ApplicationModel' 'SimpleDialog') asValue.
    aspects at:#methodNameChannel put:(
        (specSelector notNil ifTrue:[specSelector asValue]
                            ifFalse:[#windowSpec]) asValue
    ).

    treeView    := TreeView new.
    painterView := StandardSystemView new.
    painterView label:'unnamed canvas'.
    painterView extent:300@300.

    painter := UIPainterView in:painterView.
    painter layout:(0.0 @ 0.0 corner:1.0 @ 1.0) asLayout.

    treeView := treeView canvas:painter.
    painter treeView:treeView.
    treeView model addDependent:self.

    super openInterface:aSymbol.

    transcript := (self builder componentAt:#Transcript) scrolledView.
    topView := self window.
    topView bePartner.
    topView label:'GUI Painter'.

    painterView openInGroup:(topView windowGroup).
    painterView bePartner.
    painterView application:self.
    painterView open.

    painterView application:self.
    selectionPanel := UISelectionPanel new.
    selectionPanel allButOpenInterface:#windowSpec.
    selectionPanel window openInGroup:(topView windowGroup).
    selectionPanel window bePartner.
    selectionPanel openWindow.
    selectionPanel masterApplication:self.

    topView iconLabel:'GUI Painter'.
    topView icon:(Image fromFile:'bitmaps/UIPainter.xbm' resolution:100).

    painterView iconLabel:'GUI Painter'.
    painterView icon:(Image fromFile:'bitmaps/UIPainter.xbm' resolution:100).

    selectionPanel window iconLabel:'GUI Painter'.
    selectionPanel window icon:(Image fromFile:'bitmaps/UIPainter.xbm' resolution:100).

    ActiveHelp startFor:self.

    "Modified: / 27.10.1997 / 00:01:12 / cg"
!

openNewWindowCanvas
    "open new
    "
    self open.


!

openOnClass:aClass
    "open up an interface builder
    "
    self openOnClass:aClass andSelector:#windowSpec
!

openOnClass:aClass andSelector:aSelector
    "open up an interface builder, fetching a spec from someClass
     via some selector
    "
    |painter|

    aClass isNil ifTrue:[
        (self confirm:'nil class given to UIPainter (class was probably renamed ?)\\Open anyway (to create a new interface) ?' withCRs)
        ifFalse:[^ nil].
    ].

    self openInterface.

    aClass notNil ifTrue:[
        painter        := self painter.

        self setClass:aClass selector:aSelector.
"/        specClass      := aClass name.
"/        specSuperclass := aClass superclass name.
"/        specSelector   := aSelector.
"/
"/        (aspects at:#classNameChannel) value:specClass.
"/        (aspects at:#superclassNameChannel) value:specSuperclass.
"/        (aspects at:#methodNameChannel) value:specSelector asSymbol.
"/
"/        painter 
"/            className:aClass name 
"/            superclassName:aClass superclass name
"/            selector:aSelector.

        (aClass respondsTo:aSelector) ifTrue:[
            painter setupFromSpec:(aClass perform:aSelector).
        ]
    ]

    "Modified: / 25.10.1997 / 19:11:51 / cg"
! !

!UIPainter methodsFor:'user interaction - dialog'!

checkClassAndSelector
    "check for class & superclass"

    |superclass cls|

    specClass isNil ifTrue:[^ false].

    cls := self resolveName:specClass.

    cls isNil ifTrue:[
        superclass := self resolveName:specSuperclass.

        superclass isNil ifTrue:[
            self warn:'no class named ' , specSuperclass , ' exists.'.
            ^ false.
        ].
        (self confirm:'create ' , specClass , ' ?') ifTrue:[
            superclass subclass:(specClass asSymbol)
                       instanceVariableNames:''
                       classVariableNames:''
                       poolDictionaries:''
                       category:'Applications'.
            ^ true.
        ].
        ^ false.
    ].
    cls isBehavior ifFalse:[
        self warn:'a global named ' , specClass , ' exists, but is no class.'.
        ^ false.
    ].

    specSuperclass isBehavior ifFalse:[
        specSuperclass isEmpty ifFalse:[
            superclass := self resolveName:specSuperclass
        ] ifTrue:[
            specSuperclass := nil.
        ]
    ] ifTrue:[
        superclass := specSuperclass
    ].

    specSuperclass notNil ifTrue:[
        superclass isNil ifTrue:[
            self warn:'no class named ' , specSuperclass , ' exists.'.
            ^ false.
        ].

        (cls isSubclassOf:superclass) ifFalse:[
            self information:('a global named ' , specClass , ' exists,\' ,
                              'but is not a subclass of ' , superclass name , '.\\' ,
                              'Check and try again if that is not what you want.') withCRs.
        ]
    ].

    superclass isNil ifTrue:[
        cls notNil ifTrue:[
            specSuperclass := cls superclass name
        ]
    ].

    ^ true

    "Modified: 12.8.1997 / 23:39:10 / cg"
!

defineClassAndSelector
    "launch a dialog to define class, superclass and method"

    |again tmp|

    [
        again := false.

        (tmp := specClass) isNil ifTrue:[tmp := 'NewApplication'].
        aspects at:#classNameChannel put:tmp asValue.

        (tmp := specSelector) isNil ifTrue:[tmp := 'windowSpec'].
        aspects at:#methodNameChannel put:tmp asValue.

        (tmp := specSuperclass) isNil ifTrue:[tmp := 'ApplicationModel'].
        aspects at:#superclassNameChannel put:tmp asValue.

        (self openDialogInterface:#nameAndSelectorSpec) ifTrue:[

            specClass    := (self aspectFor:#classNameChannel) value.
            specSelector := (self aspectFor:#methodNameChannel) value.
            specSelector notNil ifTrue:[specSelector := specSelector asSymbol].
            specSuperclass := (self aspectFor:#superclassNameChannel) value.

            (again := self checkClassAndSelector not) ifFalse:[
                self painter className:specClass
                        superclassName:specSuperclass
                              selector:specSelector.
            ]
        ]

    ] doWhile:[again].

    self specClass:specClass.
!

gridMenu
    "open a dialog for grip parameters configuration
    "
    |hspace vspace bindings painter gridPara|

    painter  := self painter.
    bindings := IdentityDictionary new.
    gridPara := painter gridParameters copy.

    bindings at:#showGrid    put:(painter gridShown asValue).
    bindings at:#alignToGrid put:(painter gridAlign asValue).
    bindings at:#hspace      put:((gridPara at:1) asValue).
    bindings at:#vspace      put:((gridPara at:2) asValue).

    (self openDialogInterface:#gridParametersSpec withBindings:bindings) ifFalse:[
        ^ self
    ].

    hspace := (bindings at:#hspace) value ? 5.
    vspace := (bindings at:#vspace) value ? 5.

    gridPara at:1 put:hspace.
    gridPara at:2 put:vspace.
    gridPara at:5 put:hspace.
    gridPara at:6 put:vspace.

    painter gridShown:false.
    painter gridAlign:false.
    painter gridParameters:gridPara.
    painter gridAlign:(bindings at:#alignToGrid) value.
    painter gridShown:(bindings at:#showGrid) value.


! !

!UIPainter methodsFor:'user interaction - move'!

doStepDown
    "move selected component after the next component in the hierarchy of
     its container widget
    "
    treeView doStepOver:1
!

doStepIn
    "change the container of the selected widget
    "
    treeView doStepIn
!

doStepOut
    "change the container of the selected widget
    "
    treeView doStepOut
!

doStepUp
    "move selected component before the previous component in the hierarchy of
     its container widget
    "
    treeView doStepOver:-1
! !

!UIPainter methodsFor:'user interaction - pullDown'!

doBrowseAppClass
    "open a browser on the class"

    |cls|

    self painter isModified ifTrue:[
        self warn:'the change have not yet been reinstalled.\\The browser will show the old interfaces code.' withCRs.
    ].
    cls := self resolveName:specClass.

    cls notNil ifTrue:[
        SystemBrowser openInClass:cls
    ] ifFalse:[
        self information:'no class yet'.
    ].

!

doBrowseAspectMethods
    "open a browser on the aspect methods"

    |cls methods|

    self painter isModified ifTrue:[
        self warn:'the changes have not yet been reinstalled.\\The browser may show old code.' withCRs.
    ].
    cls := self resolveName:specClass.

    cls notNil ifTrue:[
        methods := self painter aspectMethods.
        methods isEmpty ifTrue:[
            self warn:'no aspect methods have been installed yet.'.
            ^ self.
        ].
        SystemBrowser browseMethods:methods title:'aspect methods'.
    ] ifFalse:[
        self information:'no class yet'.
    ].

    "Created: / 25.10.1997 / 19:07:55 / cg"
!

doFromClass
    "setup new specification from a class and selector accessed through
     to a dialog
    "
    |className methodName cls sel accepted failed spec s painter|

    self painter isModified ifTrue:[
        (self confirm:'edit another interface without saving your modifications ?') ifFalse:[
            ^ self
        ]
    ].

    className  := (specClass ? '') asValue.
    methodName := (specSelector ? '') asValue.
    painter    := self painter.

    (s := painter className) notNil ifTrue:[
        className value:s
    ].
    (s := painter methodName) notNil ifTrue:[
        methodName value:s
    ].

    failed := false.
    [
        accepted :=
            (DialogBox new
                addTextLabel:'Classes name:';
                addInputFieldOn:className; 
                addVerticalSpace;
                addTextLabel:'methods name:';
                addInputFieldOn:methodName; 
                addAbortButton; 
                addOkButton; 
                open
            ) accepted.

         accepted ifTrue:[
            cls := self resolveName:className value.

            cls isNil ifTrue:[
                failed := true.
                self warn:'no such class'.
            ] ifFalse:[
                sel := methodName value asSymbol.
                (cls respondsTo:sel ) ifFalse:[
                    failed := true.
                    self warn:'no such method'
                ] ifTrue:[
                    spec := cls perform:sel.
                    spec isArray ifFalse:[
                        failed := true.
                        self warn:'not a windowSpec method'    
                    ].
                    "/ ok, got it
                
                    self setClass:cls selector:sel.

                    painter setupFromSpec:spec.

                    ^ self
                 ]
            ]
         ]
    ] doWhile:[accepted and:[failed]].

    "Modified: 24.6.1997 / 18:59:29 / cg"
!

doInstallAspects
    "install aspects and actions
    "
    |code|

    self hasSpecClassAndSelector ifFalse:[
        self defineClassAndSelector
    ].

    self checkClassAndSelector ifFalse:[
        ^ self
    ].

    self painter className:specClass
        superclassName:specSuperclass
              selector:specSelector.

    code := self painter generateAspectMethods.
    (ReadStream on:code) fileIn.

!

doInstallHelp
    "install help text
    "
    self helpTool installHelpSpecInto:specClass
!

doInstallHooks
    "install application hooks
    "
    |code|

    self hasSpecClassAndSelector ifFalse:[
        self defineClassAndSelector
    ].

    self checkClassAndSelector ifFalse:[
        ^ self
    ].

    self painter className:specClass
        superclassName:specSuperclass
              selector:specSelector.

    code := self painter generateHookMethods.
    (ReadStream on:code) fileIn.

    "Created: / 31.10.1997 / 17:37:54 / cg"
!

doInstallSpec
    "install window specification
    "
    |code painter|

    self hasSpecClassAndSelector ifFalse:[
        self defineClassAndSelector
    ].

    self checkClassAndSelector ifFalse:[
        ^ self
    ].

    self isModified ifTrue:[
        (self confirm:'accept change made in ' , tabSelection printString , ' section ?') ifTrue:[
            self accept
        ] ifFalse:[
            (self confirm:'install old specification ?') ifFalse:[
                ^ self
            ]
        ]
    ].

    painter := self painter.

    painter className:specClass
       superclassName:specSuperclass
             selector:specSelector.

    code := painter generateWindowSpecMethodSource withCRs.
    painter resetModification.
    (ReadStream on:code) fileIn.

    "Modified: / 26.10.1997 / 15:47:48 / cg"
!

doNew
    "remove all components and associated resources
    "
    self painter isModified ifTrue:[
        (self confirm:'edit a new interface without saving your modifications ?') ifFalse:[
            ^ self
        ]
    ].
    self painter removeAll
!

doPickAView
    "pick a view and setup specifications
    "
    |painter view cls spec app|

    self painter isModified ifTrue:[
        (self confirm:'pick another interface without saving your modifications ?') ifFalse:[
            ^ self
        ]
    ].

    (view := Screen current viewFromUser) notNil ifTrue:[
        view == Screen current rootView ifFalse:[
            painter := self painter.
            spec    := UISpecification fromView:view topView.

         "/ ok, got it

            (app := view application) notNil ifTrue:[
                cls := app class
            ] ifFalse:[
                cls := view class
            ].
            self setClass:cls selector:nil.

            painter setupFromSpec:spec.
        ]
    ]

    "Modified: / 1.11.1997 / 13:47:49 / cg"
!

doStartApplication
    "start current edited application
    "
    |cls app infoMessage|

    self isModified ifTrue:[
        (self confirm:'accept change made in ' , tabSelection printString , ' section ?') ifTrue:[
            self accept.
            "/  "XXX must be fixed - canvas changes are not recorded in the history
            "/  so isModified returns false here
            "/
            "/ self painter isModified ifTrue:[
            "/
                (self confirm:'reinstall the new spec ?' withCRs) ifTrue:[
                    self doInstallSpec
                ]
            "/ ].
        ]
    ].
    self painter isModified ifTrue:[
        (self confirm:'the changed spec has not yet been reinstalled.\\Start anyway (based upon the previous interface) ?' withCRs) ifFalse:[
            ^ self
        ]
    ].

    (specClass isNil or:[specSelector size < 2]) ifTrue:[
        infoMessage := 'no class or selector defined'.
    ] ifFalse:[
        cls := self resolveName:specClass.

        cls isNil ifTrue:[
            infoMessage := 'class not existant'.
        ] ifFalse:[
            (cls respondsTo:specSelector) ifFalse:[
                infoMessage := ('no method for: #' 
                                , specSelector , ' in ' , cls name
                                , '\\(did you install the spec ?)') withCRs.
            ]
        ]
    ].

    infoMessage notNil ifTrue:[
        ^ self information:infoMessage
    ].
    app := cls new.
    (app respondsTo:#openInterface:) ifFalse:[
        ^ self warn:('The application does not respond to the ''openInterface:'' message.\\(maybe its supposed to be used as subApplication/subCanvas)') withCRs.
    ].        
    app openInterface:specSelector

    "Modified: / 29.10.1997 / 19:01:50 / cg"
!

doWindowSpec
   "create the window specification but do not write to application; instead
    open a view
   "
   |code v|

   code := self painter generateWindowSpecMethodSource.

   v := CodeView open.
   v contents:code.
   v label:'windowSpec'.

! !

!UIPainter::TreeView class methodsFor:'constants'!

defaultNameOfCanvas
    "returns the default name (id) of the application
    "
    ^ 'Canvas'
!

imageEmptyParent
    <resource: #fileImage>


    ImageEmptyParent isNil ifTrue:[
        ImageEmptyParent := Image fromFile:('xpmBitmaps/document_images/tiny_dir.xpm').
    ].
    ^ ImageEmptyParent

    "
    ImageEmptyParent := nil
    "

    "Modified: / 29.10.1997 / 03:36:37 / cg"
!

imageMasterChild
    <resource: #fileImage>


    ImageMasterChild isNil ifTrue:[
        ImageMasterChild := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain_gray.xpm').
    ].
    ^ ImageMasterChild

    "
    ImageMasterChild := nil
    "

    "Modified: / 29.10.1997 / 03:36:42 / cg"
!

imageMasterParent
    <resource: #fileImage>


    ImageMasterParent isNil ifTrue:[
        ImageMasterParent := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_gray.xpm').
    ].
    ^ ImageMasterParent

    "
    ImageMasterParent := nil
    "

    "Modified: / 29.10.1997 / 03:36:47 / cg"
! !

!UIPainter::TreeView class methodsFor:'documentation'!

documentation
"
    selection in tree view; only used by the UIPainter

    [see also:]
        SelectionInTreeView
        SelectionInTree
        TreeItem
        UIPainter

    [author:]
        Claus Atzkern
"


! !

!UIPainter::TreeView methodsFor:'accessing'!

canvas
    "returns the canvas( UIPainter )
    "
  ^ model root contents view


!

canvas:aCanvas
    "install canvas( UIPainter )
    "
    |props|

    props := UIPainterView::ViewProperty new.
    props view:aCanvas.
    model root:(TreeItem name:(self class defaultNameOfCanvas) contents:props).
    model root expand.
    self enableChannel:(aCanvas enableChannel).

!

canvasSpec
    "returns spec assigned to canvas
    "
    |spec|

    spec := WindowSpec new.

    spec fromView:(self canvas topView) callBack:nil.
    spec name:(listOfNodes at:1) name.

    windowSpec notNil ifTrue:[
        spec copyValuesFromSpec:windowSpec
    ].
    ^ spec

    "Modified: / 29.10.1997 / 18:06:44 / cg"
!

canvasSpec:aSpec
    "update canvas from spec
    "
    |spec|

    self setAttributesFromWindowSpec:aSpec.
    spec := aSpec copy.
    spec  menu:nil.
    spec flags:nil.

    spec setAttributesIn:(self canvas topView) with:(UIBuilder new isEditing:true).
!

itemOfView:aView
    "returns item assigned to view or nil
    "
    aView notNil ifTrue:[
        self allItemsDo:[:anItem|
            (anItem contents view == aView) ifTrue:[^ anItem]
        ]
    ].
  ^ nil


! !

!UIPainter::TreeView methodsFor:'accessing property'!

propertiesDo:aOneArgBlock
    "evaluate the argument a block on each property
    "
    self allItemsDo:[:anItem| aOneArgBlock value:(anItem contents)]


!

propertyDetect:aOneArgBlock
    "evaluate the block on each property
    "
    self allItemsDo:[:anItem|
        (aOneArgBlock value:(anItem contents)) ifTrue:[^ anItem contents]
    ].
  ^ nil

!

propertySelected
    "returns current selected property or nil in case of multi selection
     or empty selection
    "
    |idx|

    selection size == 1 ifTrue:[
        (idx := selection first) ~~ 1 ifTrue:[          "canvas: not yet supported"
            ^ (listOfNodes at:idx) contents
        ]
    ].
  ^ nil

! !

!UIPainter::TreeView methodsFor:'adding & removing'!

addProperty:aProperty
    "add a new item
    "
    |parent|

    parent := self detectItemRespondsToView:(aProperty view superView).

    parent notNil ifTrue:[
        model add:(TreeItem name:(aProperty name) contents:aProperty) below:parent
    ]

!

removeAll
    "remove all items other than canvas
    "
    lastDrawnMaster := nil.
    windowSpec := nil.

    self canvas subViews copy do:[:aView|
        (aView isKindOf:InputView) ifFalse:[aView destroy]
    ].
    model root name:(self class defaultNameOfCanvas).
    model root children:(OrderedCollection new).
    model recomputeList.
    self selection:nil.


!

removeView:aView
    "remove a view
    "
    |item prnt|

    ((item := self itemOfView:aView) notNil and:[(prnt := item parent) notNil]) ifTrue:[
        aView destroy.
        prnt contents view sizeChanged:nil.
        model remove:item
    ]


! !

!UIPainter::TreeView methodsFor:'building'!

generateFullSpecForComponents:aSpecArray
    "generates a full spec for components
    "
    |fullSpec winSpec|

    fullSpec := FullSpec new.

    fullSpec fromBuilder:(self canvas topView)
              components:(SpecCollection new collection:aSpecArray).

    windowSpec notNil ifTrue:[
        winSpec := fullSpec window.
        winSpec copyValuesFromSpec:windowSpec
    ].    
    ^ fullSpec literalArrayEncoding.

    "Modified: / 29.10.1997 / 18:05:58 / cg"
!

setAttributesFromWindowSpec:aWindowSpec
    "set windowSpec from argument a WindowSpec
    "
    windowSpec := WindowSpec new copyValuesFromSpec:aWindowSpec.
    self canvasNameChanged:aWindowSpec name.

    "Modified: / 29.10.1997 / 18:06:56 / cg"
! !

!UIPainter::TreeView methodsFor:'canvas selection'!

cvsSelection:aSelection
    "canvas changed its selection
    "
    |sel list rcLt|

    list := OrderedCollection new.

    aSelection isNil ifFalse:[
        aSelection isCollection ifTrue:[
            aSelection notNil ifTrue:[sel := aSelection]
        ] ifFalse:[
            sel := Array with:aSelection
        ]
    ].

    sel notNil ifTrue:[
        rcLt := false.

        sel do:[:aView||item|
            (item := self itemOfView:aView) notNil ifTrue:[
                list add:item.

                [(item := item parent) notNil] whileTrue:[
                    item hidden ifTrue:[
                        rcLt := true.
                        item expand.
                    ]
                ]
            ]
        ].
        rcLt ifTrue:[model recomputeList].
        sel := list collect:[:anItem| listOfNodes findFirst:[:el| el == anItem]]
    ] ifFalse:[
        sel := list
    ].
    self cvsEventsDisabledDo:[ self selection:sel ].            




!

cvsSelectionAdd:aView
    "canvas adds a view to current selection
    "
    |parent item rcLt oldSel|

    item := self itemOfView:aView.

    item notNil ifTrue:[
        parent := item.

        [ (parent := parent parent) notNil ] whileTrue:[
            parent hidden ifTrue:[
                rcLt := true.
                parent expand.
            ]
        ].
        rcLt == true ifTrue:[model recomputeList].

        oldSel := selection copy.
        self addToSelection:(listOfNodes findFirst:[:el| el == item]).
        self selectionChangedFrom:oldSel
    ].            



!

cvsSelectionRemove:aView
    "canvas removes a view from current selection
    "
    |parent item rcLt oldSel|

    item := self itemOfView:aView.

    item notNil ifTrue:[
        parent := item.

        [ (parent := parent parent) notNil ] whileTrue:[
            parent hidden ifTrue:[
                rcLt := true.
                parent expand.
            ]
        ].
        rcLt == true ifTrue:[model recomputeList].

        oldSel := selection copy.
        self removeFromSelection:(listOfNodes findFirst:[:el| el == item]).
        self selectionChangedFrom:oldSel
    ].            



! !

!UIPainter::TreeView methodsFor:'change & update'!

canvasNameChanged:aName
    "called if identification name assigned to window (canvas) changed
    "
    |name node|

    node := listOfNodes at:1.

    (    aName size ~~ 0
     and:[(name := aName string withoutSeparators) size ~~ 0
     and:[(self propertyDetect:[:p| p name = name]) isNil
     and:[node name ~= name]]]
    ) ifTrue:[
        node name:name.
        self redrawLine:1.
    ].
!

layoutChanged
    "layout of any component changed; in case of single selection, the
     application will be informed to update its layout
    "
    selection size == 1 ifTrue:[
        self application layoutChanged
    ]


!

propertyChanged:aProperty
    "property of view derived from argument a property changed
    "
    |item idx end|

    item := self itemOfView:(aProperty view).

    item notNil ifTrue:[
        item contents:aProperty.

        item name = aProperty name ifFalse:[
            idx := self firstLineShown.

            (end := self lastLineShown) > listOfNodes size ifTrue:[
                end := listOfNodes size
            ].
            item name:aProperty name.

            [idx <= end] whileTrue:[
                (listOfNodes at:idx) == item ifTrue:[
                    self redrawLine:idx.                "/ is visible; redraw line
                    end := 0
                ] ifFalse:[
                    idx := idx + 1
                ]
            ]
        ].

        self selectedNode == item ifTrue:[              "/ inform application
            self application propertyChanged
        ]
    ].


! !

!UIPainter::TreeView methodsFor:'drag & drop'!

canDrop:anObjectOrCollection
    "can drop ? delegate to canvas
    "
  ^ self canvas canDrop:anObjectOrCollection
!

drop:anObjectOrCollection at:aPoint
    "drop objects ? delegate to canvas
    "
    self canvas drop:anObjectOrCollection at:aPoint
! !

!UIPainter::TreeView methodsFor:'enumerating'!

allItemsDo:aOneArgBlock
    "evaluate the argument a block on each item other than the canvas
    "
    model root allChildrenDo:aOneArgBlock


! !

!UIPainter::TreeView methodsFor:'event processing'!

cvsEventsDisabledDo:aBlock
    "evaluate the block without raising selection changed notifications
     to canvas
    "
    |restoreCvsEvents|

    restoreCvsEvents  := cvsEventsDisabled.
    cvsEventsDisabled := true.
    aBlock value.
    cvsEventsDisabled := restoreCvsEvents.


!

cvsSetupListDo:aBlock
    "evaluate block without handling notifications from model; after evaluation
     the new list will be recomputed
    "
    model removeDependent:self.

    self cvsEventsDisabledDo:[
        self selection:nil.
        aBlock value
    ].
    model addDependent:self.
    model recomputeList.

!

doubleClicked
    "disable collapse of canvas item
    "
    self selectedNode == model root ifFalse:[
        super doubleClicked
    ]


! !

!UIPainter::TreeView methodsFor:'initialization'!

fetchImageResources
    "get special images for UIPainter,
     returns the maximum extent of all images"

    |extent|

    extent := super fetchImageResources.

    imageMasterChild := self class imageMasterChild. 
    imageMasterChild notNil ifTrue:[
        imageMasterChild := imageMasterChild onDevice:device.
        extent := extent max:(imageMasterChild extent).
    ].
    imageMasterParent := self class imageMasterParent. 
    imageMasterParent notNil ifTrue:[
        imageMasterParent := imageMasterParent onDevice:device.
        extent := extent max:(imageMasterParent extent).
    ].
    imageEmptyParent := self class imageEmptyParent.  
    imageEmptyParent notNil ifTrue:[
        imageEmptyParent := imageEmptyParent onDevice:device.
        extent := extent max:(imageEmptyParent extent).
    ].

    ^ extent.

    "Modified: 19.9.1997 / 17:18:46 / stefan"
!

initialize
    "initialization; set multiple select and model
    "
    super initialize.
    self multipleSelectOk:true.
    cvsEventsDisabled := false.

! !

!UIPainter::TreeView methodsFor:'private'!

figureFor:aNode
    "returns image for an item; testing whether item is the first
     entry into the selection
    "
    |master subComp|

    subComp := (aNode parent isNil or:[aNode contents spec class supportsSubComponents]).

    selection size == 0 ifFalse:[
        master := listOfNodes at:(selection first).

        aNode == master ifTrue:[
            lastDrawnMaster := master.
            subComp ifFalse:[^ imageMasterChild]
                     ifTrue:[^ imageMasterParent].
        ]
    ].
    subComp ifFalse:[
        ^ imageItem
    ].
    aNode hasChildren ifTrue:[
        aNode isExpandable ifTrue:[ ^ imageClosed ]
                          ifFalse:[ ^ imageOpened ]
    ].
    ^ imageEmptyParent

!

selectionChangedFrom:oldSelection
    "selection has changed. update master selection and raise notification
     to canvas in case of enabled cvs events
    "
    |sel size|

    super selectionChangedFrom:oldSelection.
    size := selection size.

    cvsEventsDisabled ifFalse:[
        (size ~~ 0 and:[size ~~ 1 or:[selection first ~~ 1]]) ifTrue:[
            sel := OrderedCollection new.

            selection do:[:i|
                i ~~ 1 ifTrue:[sel add:(listOfNodes at:i) contents view]
            ]
        ].
        self canvas updateSelectionFromModel:sel
    ].

    size ~~ 0 ifTrue:[
        sel := selection first.

        (listOfNodes at:sel) == lastDrawnMaster ifFalse:[
            self redrawLine:sel
        ]
    ]
! !

!UIPainter::TreeView methodsFor:'queries'!

canMoveOrAlignSelection
    "returns true if any selection exists and all widgets in the selection
     can change their layout through to a move or align operation.
    "
    |canvas|

    selection size == 0 ifTrue:[
        ^ false
    ].
    canvas := self canvas.

    selection do:[:i|
        i == 1 ifTrue:[^ false].

        (canvas canChangeLayoutOfView:((listOfNodes at:i) contents view)) ifFalse:[
            ^ false
        ]
    ].
    ^ true
!

canMoveSelectionIntoContainer
    "returns true in case that one component is selected and can change its container
     widget to the next element in the list which will have the same container.
    "
    |item prnt|

    (     (item := self selectedNode) isNil
      or:[(prnt := item parent) isNil
      or:[(prnt := prnt childAt:((prnt indexOfChild:item) + 1)) isNil
      or:[prnt contents spec class supportsSubComponents not]]]
    ) ifTrue:[
        ^ false
    ].
  ^ true
!

canMoveSelectionOutOfContainer
    "returns true in case that one component is selected which is contained within
     another component.
    "
    |item prnt|

    (     (item := self selectedNode) isNil
      or:[(prnt := item parent) isNil
      or:[prnt parent isNil]]
    ) ifTrue:[
        ^ false
    ].
  ^ true
!

canResizeSelectedWidget
    "returns true in case of one widget selected and is contained
     within a widget which allows to resize sub components
    "
    |n|

    (n := self selectedNode) notNil ifTrue:[
        (n := n parent) notNil ifTrue:[
            ^ (n parent isNil or:[n contents spec class canResizeSubComponents])
        ]
    ].
    ^ false
!

hasOneSelectionOtherThanCanvas
    "returns true in case that one selection exists other than the canvas
    "
    ^ (selection size == 1 and:[selection first ~~ 1])
!

isCanvasSelected
    "returns true in case of a single selection and the
     selection is the canvas (index 1)
    "
    ^ (selection size == 1 and:[self isInSelection:1])
! !

!UIPainter::TreeView methodsFor:'seraching'!

detectItemRespondsToView:aView
    "detect the item responding to the view. The item of the view or the first
     subview providing the item is returned. If no property is detected nil is
     returned
    "
    |view item|

    (view := aView) notNil ifTrue:[
        [(item := self itemOfView:view) isNil] whileTrue:[
            (view := view superView) isNil ifTrue:[^ listOfNodes at:1]
        ].
    ].
    ^ item

! !

!UIPainter::TreeView methodsFor:'user interactions'!

doStepIn
    |item prnt canvas|

    (     (item := self selectedNode) isNil
      or:[(prnt := item parent) isNil
      or:[(prnt := prnt childAt:((prnt indexOfChild:item) + 1)) isNil
      or:[prnt contents spec class supportsSubComponents not]]]
    ) ifFalse:[
        canvas := self canvas.
        canvas deleteSelection.
        canvas setSelection:(prnt contents view) withRedraw:false.
        canvas pasteWithLayout.
    ]
!

doStepOut
    |item next prnt canvas|

    (     (item := self selectedNode) isNil
      or:[(prnt := item parent) isNil
      or:[(next := prnt parent) isNil]]
    ) ifTrue:[
        ^ self
    ].
    model removeDependent:self.

    canvas := self canvas.
    canvas deleteSelection.
    canvas setSelection:(next contents view) withRedraw:false.
    canvas pasteWithLayout.

!

doStepOver:anIndex
    "move child 'anOffset' forward or backward in list of children
    "
    |item idx size prnt spVw view canvas|

    (    (item := self selectedNode) isNil
     or:[(prnt := item parent) isNil
     or:[(size := prnt children size) < 2
     or:[(idx  := prnt indexOfChild:item) == 0]]]
    ) ifTrue:[
        ^ self
    ].
    model removeDependent:self.
    model removeSelection.
    selection := nil.
    model addDependent:self.
    idx := idx + anIndex.

    idx < 1 ifTrue:[idx := size]
           ifFalse:[idx > size ifTrue:[idx := 1]].

    model add:item beforeIndex:idx below:prnt.
    idx    := prnt indexOfChild:item.
    view   := item contents view.
    spVw   := prnt contents view.
    canvas := self canvas.

    canvas hideSelection.

 "/ input view might by contained in sequence
    ((size := canvas findInputViewIn:spVw) ~~ 0 and:[idx >= size]) ifTrue:[
        idx := idx + 1
    ].
    spVw changeSequenceOrderFor:view to:idx.

    spVw specClass isLayoutContainer ifFalse:[
        spVw subViews do:[:v| v raise ].
        canvas inputView raise
    ].
    canvas showSelection.
    self selectNode:item.
! !

!UIPainter class methodsFor:'documentation'!

version
    ^ '$Header$'
! !