UIPainter.st
author ca
Wed, 20 Aug 1997 18:06:57 +0200
changeset 289 7bbe22b39d9b
parent 287 1ecabfd468dc
child 295 114befd1c369
permissions -rw-r--r--
check state for 0 during button motion

"
 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'
	classVariableNames:'IconStepUp IconStepOut IconStepIn IconStepDown'
	poolDictionaries:''
	category:'Interface-UIPainter'
!

SelectionInTreeView subclass:#TreeView
	instanceVariableNames:'lastDrawnMaster cvsEventsDisabled imageMasterParent
		imageEmptyParent imageMasterChild'
	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.
    "
  ^ 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'

#galleryShown
'show or hide gallery view'

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

#moveSelectionUp
'move selected widgets up 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'

)
! !

!UIPainter class methodsFor:'icons'!

iconAlignB
    "returns image assigned to align bottom
    "
    ^ Image fromFile:'b_alignB.xbm'

!

iconAlignCenterH
    "returns image assigned to center horizontal
    "
    ^ Image fromFile:'b_alignCH.xbm'

!

iconAlignCenterV
    "returns image assigned to center vertical
    "
    ^ Image fromFile:'b_alignCV.xbm'

!

iconAlignL
    "returns image assigned to align left
    "
    ^ Image fromFile:'b_alignL.xbm'
!

iconAlignLR
    "returns image assigned to align left and right
    "
    ^ Image fromFile:'b_alignLR.xbm'

!

iconAlignR
    "returns image assigned to align right
    "
    ^ Image fromFile:'b_alignR.xbm'

!

iconAlignT
    "returns image assigned to align top
    "
    ^ Image fromFile:'b_alignT.xbm'

!

iconAlignTB
    "returns image assigned to align top and bottom
    "
    ^ Image fromFile:'b_alignTB.xbm'

!

iconStepDown
    "returns image assigned to step down (change hierarchy).
    "
    IconStepDown isNil ifTrue:[
        IconStepDown := ((Image fromFile:'stepOver.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepDown

"
IconStepDown := nil
"

!

iconStepIn
    "returns image assigned to step in (change hierarchy).
    "
    IconStepIn isNil ifTrue:[
        IconStepIn := ((Image fromFile:'stepIn.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepIn

!

iconStepOut
    "returns image assigned to step out (change hierarchy).
    "
    IconStepOut isNil ifTrue:[
        IconStepOut := ((Image fromFile:'stepOut.xpm') rotated:90) flipHorizontal
    ].
  ^ IconStepOut
!

iconStepUp
    "returns image assigned to step up (change hierarchy).
    "
    IconStepUp isNil ifTrue:[
        IconStepUp := ((Image fromFile:'stepOver.xpm') rotated:90) flipHorizontal flipVertical
    ].
  ^ IconStepUp

"
IconStepUp := nil
"
! !

!UIPainter class methodsFor:'interface specs'!

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 199 0 167 0 759 0 616 0)
              #'label:' 'Tree-View'
              #'min:' #(#Point 10 10)
              #'max:' #(#Point 1160 870)
              #'bounds:' #(#Rectangle 199 167 760 617)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#MenuPanelSpec
                    #'name:' 'menuPullDown'
                    #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 25 0)
                    #'tabable:' true
                    #'menu:' #menuPullDown
                )
                 #(#NoteBookViewSpec
                    #'name:' 'noteBook'
                    #'layout:' #(#LayoutFrame 0 0.4 59 0.0 0 1.0 -55 1.0)
                    #'enableChannel:' #enableChannel
                    #'tabable:' true
                    #'menu:' #tabList
                    #'model:' #tabModel
                    #'tabWidget:' #Window
                    #'canvas:' #noteBookView
                )
                 #(#HorizontalPanelViewSpec
                    #'name:' 'modifyPanel'
                    #'layout:' #(#LayoutFrame 0 0.4 -55 1.0 0 1.0 -25 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:' 'ok'
                              #'tabable:' true
                              #'model:' #accept
                              #'enableChannel:' #modifiedChannel
                              #'extent:' #(#Point 164 24)
                          )
                        )
                    )
                    #'level:' 0
                    #'horizontalLayout:' #fitSpace
                    #'verticalLayout:' #fitSpace
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
                 #(#LabelSpec
                    #'name:' 'helpInfo'
                    #'layout:' #(#LayoutFrame 2 0.0 -25 1.0 -2 1.0 -2 1.0)
                    #'level:' -1
                    #'adjust:' #left
                )
                 #(#ToggleSpec
                    #'name:' 'galleryLabel'
                    #'layout:' #(#LayoutFrame -162 1.0 1 0 -82 1.0 23 0)
                    #'activeHelpKey:' #galleryShown
                    #'label:' 'Gallery'
                    #'model:' #galleryShown
                    #'isTriggerOnDown:' true
                    #'showLamp:' true
                    #'lampColor:' #(#Color 100.0 100.0 0.0)
                )
                 #(#ToggleSpec
                    #'name:' 'painterLabel'
                    #'layout:' #(#LayoutFrame -81 1.0 1 0 -1 1.0 23 0)
                    #'activeHelpKey:' #painterShown
                    #'label:' 'Painter'
                    #'model:' #painterShown
                    #'isTriggerOnDown:' true
                    #'showLamp:' true
                    #'lampColor:' #(#Color 100.0 100.0 0.0)
                )
                 #(#ArbitraryComponentSpec
                    #'name:' 'treeView'
                    #'layout:' #(#LayoutFrame 0 0.0 59 0 0 0.4 -25 1.0)
                    #'menu:' #menuCanvas
                    #'hasHorizontalScrollBar:' true
                    #'hasVerticalScrollBar:' true
                    #'miniScrollerHorizontal:' true
                    #'miniScrollerVertical:' true
                    #'component:' #treeView
                    #'hasBorder:' false
                )
                 #(#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
                              #'menu:' #menuChangeHierarchy
                              #'showSeparatingLines:' true
                              #'extent:' #(#Point 123 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
                                        #'isTriggerOnDown:' true
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'direction:' #left
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveRight'
                                        #'activeHelpKey:' #moveSelectionRight
                                        #'model:' #moveSelectionRight
                                        #'isTriggerOnDown:' true
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'direction:' #right
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveDown'
                                        #'activeHelpKey:' #moveSelectionDown
                                        #'model:' #moveSelectionDown
                                        #'isTriggerOnDown:' true
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'direction:' #down
                                        #'extent:' #(#Point 22 24)
                                    )
                                     #(#ArrowButtonSpec
                                        #'name:' 'moveUp'
                                        #'activeHelpKey:' #moveSelectionUp
                                        #'model:' #moveSelectionUp
                                        #'isTriggerOnDown:' true
                                        #'enableChannel:' #canMoveOrAlignSelection
                                        #'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
                )
              )
          )
      )
! !

!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
                #'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:' '-'
            )
             #(#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:'
                                )
                              ) 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
                          #'enabled:' #hasSpecClassAndSelector
                      )
                       #(#MenuItem
                          #'label:' 'install help spec.'
                          #'value:' #doInstallHelp
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' '-'
                      )
                       #(#MenuItem
                          #'label:' 'install aspects'
                          #'value:' #doInstallAspects
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' '='
                      )
                       #(#MenuItem
                          #'label:' 'show window spec.'
                          #'value:' #doWindowSpec
                      )
                       #(#MenuItem
                          #'label:' '='
                      )
                       #(#MenuItem
                          #'label:' 'browse application'
                          #'value:' #doBrowseAppClass
                          #'enabled:' #hasSpecClass
                      )
                       #(#MenuItem
                          #'label:' 'start  application'
                          #'value:' #doStartApplication
                          #'enabled:' #hasSpecClass
                      )
                    ) nil
                    nil
                )
            )
             #(#MenuItem
                #'label:' 'test'
                #'nameKey:' #test
                #'value:' #test
                #'submenu:' 
                 #(#Menu
                    
                     #(
                       #(#MenuItem
                          #'label:' 'test mode'
                          #'indication:' #'testMode:'
                      )
                    ) nil
                    nil
                )
            )
          ) nil
          nil
      )
! !

!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|

    self isModified ifTrue:[
        (spec := self painter specForSelection) notNil ifTrue:[
            key := spec activeHelpKey.
        ].
        self helpTool helpKey:key.
        self specTool specification:spec.
        self setViewInLayoutTool:(self layoutTool layoutView).
        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

!

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

    specClass isNil ifTrue:[
        ^ self information:'no application class defined yet'.
    ].
    (cls := specClass) isBehavior ifFalse:[
        cls := Smalltalk at:specClass asSymbol.
        cls isNil ifTrue:[
            ^ self information:'no application class defined yet'
        ]
    ].

    cls notNil ifTrue:[
        (aspect := self specTool specification menu) 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 menu:editor selectorName asSymbol.
                self modifiedChannel value:true.
                self accept
            ]
        ].
    ]

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

!UIPainter methodsFor:'active help'!

showHelp:aHelpText for:view
    "hook to allow an application to display active help
     texts in its own info area.
     This method may be redefined in a concrete application.
     If it returns false, the ActiveHelp manager will popup a
     bubble with the help text."

    |l|

    (l := self builder componentAt:#helpInfo) notNil ifTrue:[
        aHelpText replaceAll:(Character cr) by:(Character space).
        l label:aHelpText.
      ^ true.
    ].
    ^ false


! !

!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 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
    ].

! !

!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:'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
    "
    specClass notNil ifTrue:[
        ^ (specClass isBehavior or:[(Smalltalk at:specClass asSymbol) notNil])
    ].
  ^ false
!

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
    "
    (something isNil or:[tabSelection = something]) ifTrue:[
        ^ self
    ].

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

    tabSelection := something.
    self raiseTabView.
    self cancel.
!

treeSelection
    "called whenever the selection of the treeview changed
    "
    |view list spec 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:[
            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).
        list := spec class slices collect:[:aSlice| aSlice first asString].
        list add:(UIHelpTool   label).
        list add:(UILayoutTool label).
        self tabList value:list.
        self showHelp:(spec class name) for:nil.
        tabComponent enabled:true.

        (tabSelection := tabComponent selection) isNil ifTrue:[
            tabComponent setSelection:(tabSelection := list first)
        ].
        self raiseTabView
    ] ifFalse:[
        self helpTool helpKey:nil.
        tabComponent enabled:false.
        self showHelp:'' for: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.

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

    super closeRequest.

    "Modified: 28.7.1997 / 18:28:37 / 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
    "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 := Smalltalk at:specClass asSymbol) 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.

    topView := self window.
    topView bePartner.
    topView label:'GUI Builder'.

    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:'Builder'.
    topView icon:(Image fromFile:'bitmaps/UIPainter.xbm' resolution:100).

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

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

    "Modified: 1.8.1997 / 14:22:10 / 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 warn:'nil class given (class was probably renamed ?)'.
    ].

    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: 1.7.1997 / 19:18:54 / cg"
! !

!UIPainter methodsFor:'user interaction - dialog'!

checkClassAndSelector
    "check for class & superclass"

    |superclass cls|

    specClass isNil ifTrue:[^ false].

    specClass isBehavior ifFalse:[
        cls := Smalltalk at:specClass asSymbol
    ] ifTrue:[
        cls := specClass
    ].
    cls isNil ifTrue:[
        (superclass := Smalltalk at:specSuperclass asSymbol) 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 := Smalltalk at:specSuperclass asSymbol
        ] 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.
! !

!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.
    ].

    specClass isNil ifTrue:[
        ^ self information:'no class yet'.
    ].

    specClass isBehavior ifFalse:[
        cls := Smalltalk at:specClass asSymbol
    ] ifTrue:[
        cls := specClass
    ].

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

    SystemBrowser openInClass:cls

    "Modified: 28.7.1997 / 18:30:13 / 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 := Smalltalk classNamed: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
!

doInstallSpec
    "install window specification
    "
    |code painter|

    self hasSpecClassAndSelector ifFalse:[
        self defineClassAndSelector
    ].

    self checkClassAndSelector ifFalse:[
        ^ self
    ].
    painter := self painter.

    painter className:specClass
       superclassName:specSuperclass
             selector:specSelector.

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

!

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|

    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

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

            painter setupFromSpec:spec.
        ]
    ]

    "Modified: 24.6.1997 / 19:02:57 / cg"
!

doStartApplication
    "start current edited application
    "
    |cls|

    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:[
        ^ self information:'no class or selector defined'.
    ].

    specClass isBehavior ifFalse:[
        cls := Smalltalk at:specClass asSymbol
    ] ifTrue:[
        cls := specClass
    ].

    cls isNil ifTrue:[
        ^ self information:'class not existant'.
    ].

    (cls respondsTo:specSelector) ifFalse:[
        ^ self information:('no method for: #' 
                             , specSelector , ' in ' , cls name ,
                             '\\(did you install the spec ?)') withCRs.
    ].
    cls new openInterface:specSelector

    "Modified: 28.7.1997 / 18:30:25 / 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

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

    "
    ImageEmptyParent := nil
    "
!

imageMasterChild

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

    "
    ImageMasterChild := nil
    "

    "Modified: 28.7.1997 / 11:55:22 / cg"
!

imageMasterParent

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

    "
    ImageMasterParent := nil
    "

    "Modified: 28.7.1997 / 11:56:29 / 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.
  ^ spec
!

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
    "
    model add:(TreeItem name:(aProperty name) contents:aProperty) 
        below:(self detectItemRespondsToView:(aProperty view superView))


!

removeAll
    "remove all items other than canvas
    "
    lastDrawnMaster := 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:'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'!

initialize
    "initialization; set multiple select and model
    "
    super initialize.
    self multipleSelectOk:true.
    self model:(SelectionInTree new).
    cvsEventsDisabled := false.
    imageMasterChild  := (self class imageMasterChild) onDevice:device.
    imageMasterParent := (self class imageMasterParent) onDevice:device.
    imageEmptyParent  := (self class imageEmptyParent)  onDevice:device.

! !

!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
!

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$'
! !