UIPainterView.st
changeset 53 d03569a6ff03
parent 52 40a98a1507b4
child 55 19e021c8f1ef
--- a/UIPainterView.st	Sat Feb 15 19:21:15 1997 +0100
+++ b/UIPainterView.st	Mon Feb 17 18:22:30 1997 +0100
@@ -55,8 +55,25 @@
 "
 ! !
 
+!UIPainterView class methodsFor:'defaults'!
+
+defaultMenuMessage   
+    "This message is the default yo be sent to the menuHolder to get a menu
+    "
+    ^ #menu
+
+
+! !
+
 !UIPainterView methodsFor:'accessing'!
 
+application
+    self halt.
+    ^ nil
+
+    "Modified: 6.9.1995 / 00:46:44 / claus"
+!
+
 className
     ^ className
 
@@ -79,41 +96,40 @@
     methodName := aString
 
     "Modified: 5.9.1995 / 18:47:27 / claus"
-! !
-
-!UIPainterView methodsFor:'builder interface'!
-
-application
-    self halt.
-    ^ nil
-
-    "Modified: 6.9.1995 / 00:46:44 / claus"
 !
 
-aspectAt:aSymbol
-    self halt.
-    ^ nil
+selectNames:aStringOrCollection
+    |prop coll s|
 
-    "Modified: 6.9.1995 / 00:45:35 / claus"
-!
+    (aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[
+        ^ self unselect
+    ].
+
+    (s := aStringOrCollection) isString ifFalse:[
+        s size == 1 ifTrue:[
+            s := s first
+        ] ifFalse:[
+            coll := OrderedCollection new.
 
-createdComponent:newView forSpec:aSpec
-    "callBack from UISpec view building"
-
-    |props|
+            s do:[:aName|
+                (prop := self propertyOfName:aName) notNil ifTrue:[
+                    coll add:(prop view)
+                ]
+            ].
+            coll size == 1 ifTrue:[ ^ self select:(coll at:1) ].
+            coll size == 0 ifTrue:[ ^ self unselect ].
 
-    props := self propertiesForNewView:newView.
-
-    aSpec name notNil ifTrue:[
-        (self propertyOfName:(aSpec name)) isNil ifTrue:[
-            props name:aSpec name
+            self hideSelection.
+            selection := coll.
+            self showSelection.
+          ^ self changed:#selection
         ]
     ].
 
-    props labelSelector:(aSpec labelSelector).
-    props aspectSelector:(aSpec modelSelector).
+    prop := self propertyOfName:s.
+    prop isNil ifTrue:[^ self unselect]
+              ifFalse:[^ self select:(prop view)]
 
-    viewProperties add:props.
 ! !
 
 !UIPainterView methodsFor:'code manipulation'!
@@ -218,87 +234,10 @@
     |props|
 
     props := self addProperties:nil for:anObject.
-    self undoCreate:(props identifier).
-! !
 
-!UIPainterView methodsFor:'cut & paste'!
-
-convertForPaste:something
-    ^ nil
-
-
-!
-
-copySelection
-    "copy the selection into the cut&paste-buffer
-    "
-    |tmp|
-
-    tmp := OrderedCollection new.
-
-    self selectionDo:[:aView||topSpec|
-        topSpec := aView specClass 
-                        fromView:aView 
-                        callBack:[:spec :aSubView | 
-                                aSubView geometryLayout:(aSubView geometryLayout copy)
-                        ].
-        tmp add:topSpec.
-    ].
-
-    self setSelection:tmp
-
-!
-
-deleteSelection
-    "delete the selection
-    "
-    undoHistory transactionNamed:'delete' do:[
-        super deleteSelection
+    undoHistory transaction:#create text:(props name) do:[
+        self undoCreate:(props identifier).
     ].
-
-
-!
-
-pasteBuffer
-    "add the objects in the paste-buffer
-    "
-    |sel firstEntry builder|
-
-    sel := self getSelection.
-    self unselect.
-
-    sel size == 0 ifTrue:[firstEntry := sel]
-                 ifFalse:[firstEntry := sel at:1].
-
-    (firstEntry isKindOf:UISpecification) ifFalse:[
-        ^ self
-    ].
-    builder   := UIBuilder new.
-    selection := OrderedCollection new.
-
-    sel do:[:aSpec|
-        builder componentCreationHook:[:view :spec :aBuilder |
-            self createdComponent:view forSpec:spec
-        ].
-        builder applicationClass:(Smalltalk classNamed:className).
-        selection add:(aSpec buildViewWithLayoutFor:builder in:self).
-    ].
-
-    undoHistory transactionNamed:'paste' do:[
-        selection do:[:aView| |props|
-            props := self propertyOfView:aView.
-            self undoCreate:(props identifier)
-        ]
-    ].
-
-    selection size == 1 ifTrue:[
-        selection := selection at:1
-    ].
-    self showSelection.
-    self realizeAllSubViews.
-    inputView raise.
-    self changed:#tree
-
 ! !
 
 !UIPainterView methodsFor:'generating output'!
@@ -489,6 +428,27 @@
     ^ self
 !
 
+generateSpecFor:something
+    "generate a spec for a view or collection of views
+    "
+    |spec views|
+
+    something notNil ifTrue:[
+        something isCollection ifTrue:[views := something]
+                              ifFalse:[views := Array with:something].
+
+        spec := views collect:[:aView||topSpec|
+            topSpec := aView specClass 
+                            fromView:aView 
+                            callBack:[:spec :aSubView | 
+"/                                aSubView geometryLayout:(aSubView geometryLayout copy)
+                            ].
+            topSpec
+        ]
+    ].
+    ^ spec
+!
+
 generateWindowSpec
     |spec specArray str|
 
@@ -770,37 +730,6 @@
     HandCursor     := Cursor leftHand.
 
     "Modified: 5.9.1995 / 19:58:06 / claus"
-!
-
-initializeMiddleButtonMenu
-    |labels|
-
-    labels := resources array:#(
-			'copy'
-			'cut'
-			'paste'
-			'-'
-			'save'
-			'print'
-			'-'
-			'inspect'
-		      ).
-
-    self middleButtonMenu:(PopUpMenu
-				labels:labels
-			     selectors:#(
-					 copySelection
-					 deleteSelection
-					 pasteBuffer
-					 nil               
-					 save
-					 print
-					 nil               
-					 inspectSelection
-					)
-				receiver:self
-				     for:self)
-
 ! !
 
 !UIPainterView methodsFor:'interface to Builder'!
@@ -853,6 +782,13 @@
     ^ className
 !
 
+aspectAt:aSymbol
+    self halt.
+    ^ nil
+
+    "Modified: 6.9.1995 / 00:45:35 / claus"
+!
+
 aspectSelectorForView:aView
     |props aspect|
 
@@ -871,6 +807,25 @@
     ^ nil
 !
 
+createdComponent:newView forSpec:aSpec
+    "callBack from UISpec view building"
+
+    |props|
+
+    props := self propertiesForNewView:newView.
+
+    aSpec name notNil ifTrue:[
+        (self propertyOfName:(aSpec name)) isNil ifTrue:[
+            props name:aSpec name
+        ]
+    ].
+
+    props labelSelector:(aSpec labelSelector).
+    props aspectSelector:(aSpec modelSelector).
+
+    viewProperties add:props.
+!
+
 generatePropertiesFor:aCollectionOfViews
 
     "/ done as two loops, to get bread-first naming
@@ -912,30 +867,28 @@
 
     props := self propertyOfView:aView.
 
-    undoHistory transactionNamed:'aspect' do:[
-        self selectionDo:[:aView|
-            undoHistory isTransactionOpen ifTrue:[
-                |oldAspect|
+    props notNil ifTrue:[
+        self transaction:#aspect selectionDo:[:aView|
+            |oldAspect|
+
+            oldAspect := props aspectSelector.
 
-                oldAspect := props aspectSelector.
-                undoHistory addUndoBlock:[
-                    props aspectSelector:oldAspect.
-                    self elementChanged:aView.
-                ]
-            ].
+            undoHistory addUndoBlock:[
+                props aspectSelector:oldAspect.
+                aView superView sizeChanged:nil
+            ]
         ].
-    ].
-
-    props aspectSelector:aspectSymbol
-
+        props aspectSelector:aspectSymbol
+    ]
 !
 
 setChangeSelector:changeSymbol forView:aView
     |props|
 
     props := self propertyOfView:aView.
-    props changeSelector:changeSymbol
-
+    props notNil ifTrue:[
+        props changeSelector:changeSymbol
+    ]
 !
 
 setupFromSpec:specOrSpecArray
@@ -960,6 +913,285 @@
     ]
 ! !
 
+!UIPainterView methodsFor:'menu & submenus'!
+
+menu
+    testMode ifFalse:[
+        selection notNil ifTrue:[^ self menuSelection ]
+                        ifFalse:[^ self menuPainter   ]
+    ].
+    ^ nil
+!
+
+menuPainter
+    "menu in case of non empty selection; for views
+    "
+    |menu gridMenu|
+
+    menu := PopUpMenu labels:( 
+                resources array:#(
+                                  'paste' 
+                                  '-' 
+                                  'undo'
+                                  'grid'
+                                 ) 
+                              )
+                   selectors:#( 
+                                #pasteBuffer
+                                nil 
+                                #undo
+                                #grid
+                              )
+                     receiver:self.
+
+
+    undoHistory isEmpty ifTrue:[
+        menu disable:#undo
+    ] ifFalse:[
+        menu subMenuAt:#undo put:(undoHistory popupMenu)
+    ].
+
+    gridMenu := PopUpMenu labels:(
+                            resources array:#(
+                                    '\c show' 
+                                    '\c align'
+                                  )
+                                )
+                      selectors:#(
+                                    #gridShown:
+                                    #gridAlign:
+                                ).
+
+    gridMenu checkToggleAt:#gridShown: put:(self gridShown).
+    gridMenu checkToggleAt:#gridAlign: put:aligning.
+    menu subMenuAt:#grid put:gridMenu.
+
+  ^ menu
+
+
+!
+
+menuSelection
+    "menu in case of non empty selection; for views
+    "
+    |menu arrangeMenu subMenuAlign|
+
+    menu := PopUpMenu labels:( resources array:#(
+                                  'copy' 
+                                  'cut' 
+                                  'paste' 
+                                  '-' 
+                                  'arrange'
+                                  'dimension'
+                                )
+                              )
+                   selectors:#(   #copySelection
+                                  #deleteSelection
+                                  #pasteBuffer
+                                  nil
+                                  #arrange
+                                  #dimension
+                              )
+                     receiver:self.
+
+    (self supportsSubComponents:selection) ifFalse:[
+        menu disable:#pasteBuffer
+    ].
+
+    arrangeMenu := PopUpMenu labels:#( 'to front' 'to back' )
+                          selectors:#( #raiseSelection  #lowerSelection )
+                           receiver:self.
+
+
+    menu subMenuAt:#arrange put:arrangeMenu.
+    menu subMenuAt:#dimension put:(self subMenuDimension).
+
+    selection size > 1 ifTrue:[
+        menu addLabels:( resources array:#('align') )
+             selectors:#( align ).
+
+        menu subMenuAt:#align put:self subMenuAlign
+    ].
+  ^ menu
+!
+
+subMenuAlign
+    "returns submenu alignment
+    "
+    |menu|
+
+    menu := PopUpMenu labels:(
+                resources array:#(
+                                    'align left' 
+                                    'align right'
+                                    'align left & right'
+                                    'align top' 
+                                    'align bottom'
+                                    'align centered vertical'
+                                    'align centered horizontal'
+                                    '-'
+                                    'spread horizontal'
+                                    'spread vertical'
+                                    'center horizontal in frame'
+                                    'center vertical in frame'
+                                  )
+                         )
+
+              selectors:#(  
+                            alignSelectionLeft
+                            alignSelectionRight
+                            alignSelectionLeftAndRight
+                            alignSelectionTop
+                            alignSelectionBottom
+                            alignSelectionCenterHor
+                            alignSelectionCenterVer
+                            nil
+                            spreadSelectionHor
+                            spreadSelectionVer
+                            centerSelectionHor
+                            centerSelectionVer
+                         )
+               receiver:self.
+    ^ menu    
+
+!
+
+subMenuDimension
+    "returns submenu dimension
+    "
+    |menu|
+
+    menu := PopUpMenu labels:( 
+                resources array:#(
+                                    'default extent' 
+                                    'default width' 
+                                    'default height'
+                                    '-'
+                                    'copy extent'
+                                    '-'
+                                    'paste extent'
+                                    'paste width'
+                                    'paste height'
+                                 )
+                              )
+                   selectors:#(
+                                    setToDefaultExtent
+                                    setToDefaultWidth
+                                    setToDefaultHeight
+                                    nil
+                                    copyExtent
+                                    nil
+                                    pasteExtent
+                                    pasteWidth
+                                    pasteHeight
+                              )
+                     receiver:self.
+  ^ menu
+! !
+
+!UIPainterView methodsFor:'menu actions'!
+
+copySelection
+    "copy the selection into the cut&paste-buffer
+    "
+    |specs|
+
+    specs := self generateSpecFor:selection.
+
+    specs notNil ifTrue:[
+        self setSelection:specs
+    ].
+    self unselect.
+!
+
+deleteSelection
+    "delete the selection
+    "
+    |specs text|
+
+    selection notNil ifTrue:[
+        specs := self generateSpecFor:selection.
+        text := self transactionTextFor:selection.
+
+        undoHistory transaction:#cut text:text do:[
+            super deleteSelection
+        ].
+        self setSelection:specs
+    ]
+!
+
+gridAlign:aBool
+    aBool ifTrue:[self alignOn]
+         ifFalse:[self alignOff]
+!
+
+gridShown:aBool
+    aBool ifTrue:[self showGrid]
+         ifFalse:[self hideGrid]
+
+!
+
+lowerSelection
+
+    self selectionDo:[:aView| aView lower ].
+!
+
+pasteBuffer
+    "add the objects in the paste-buffer
+    "
+    |sel firstEntry builder frame|
+
+    sel   := self getSelection.
+    frame := self.
+
+    selection notNil ifTrue:[
+        (self supportsSubComponents:selection) ifTrue:[
+            frame := selection
+        ].
+        self unselect
+    ].
+
+    sel size == 0 ifTrue:[firstEntry := sel]
+                 ifFalse:[firstEntry := sel at:1].
+
+    (firstEntry isKindOf:UISpecification) ifFalse:[
+        ^ self
+    ].
+    builder   := UIBuilder new.
+    selection := OrderedCollection new.
+
+    sel do:[:aSpec||v|
+        builder componentCreationHook:[:view :spec :aBuilder |
+            self createdComponent:view forSpec:spec
+        ].
+        builder applicationClass:(Smalltalk classNamed:className).
+        v := aSpec buildViewWithLayoutFor:builder in:frame.
+        v realize.
+        selection add:v.
+    ].
+
+    self transaction:#paste selectionDo:[:v|
+        self undoCreate:((self propertyOfView:v) identifier)
+    ].
+    selection size == 1 ifTrue:[
+        selection := selection at:1
+    ].
+    self showSelection.
+    self realizeAllSubViews.
+    inputView raise.
+    self changed:#tree
+
+!
+
+raiseSelection
+
+    self selectionDo:[:aView|
+        aView raise.
+        inputView raise.
+    ].
+
+! !
+
 !UIPainterView methodsFor:'misc'!
 
 changeFontFamily:family face:face style:style size:size
@@ -1043,66 +1275,6 @@
 
 ! !
 
-!UIPainterView methodsFor:'private undo-actions'!
-
-undoCreate:aViewIdentifier
-
-    undoHistory isTransactionOpen ifTrue:[
-        undoHistory addUndoBlock:[
-            |props|
-
-            props := self propertyOfIdentifier:aViewIdentifier.
-
-            props notNil ifTrue:[
-                self removeObject:(props view)
-            ]
-        ]
-    ]
-!
-
-undoRemove:propertyOfView
-    |clsName layout parent aView|
-
-    undoHistory isTransactionOpen ifFalse:[
-        ^ self
-    ].
-
-    aView   := propertyOfView view.
-    clsName := aView class.
-    layout  := aView geometryLayout.
-    parent  := aView superView.
-
-    parent ~~ self ifTrue:[
-        parent := (self propertyOf:parent) identifier.
-    ] ifFalse:[
-        parent := nil
-    ].
-    propertyOfView view:nil.    
-
-    undoHistory addUndoBlock:[
-        |recreatedView props|
-
-        parent notNil ifTrue:[
-            props := self propertyOfIdentifier:parent.
-
-            props notNil ifTrue:[parent := props view]
-                        ifFalse:[parent := self]
-        ] ifFalse:[
-            parent := self
-        ].
-
-        recreatedView := clsName in:parent.
-        recreatedView geometryLayout:layout.
-        propertyOfView view:recreatedView.    
-        self addProperties:propertyOfView for:recreatedView.
-        recreatedView realize.
-        inputView raise.
-        self changed:#tree.
-    ].
-    aView := nil.
-
-! !
-
 !UIPainterView methodsFor:'removing components'!
 
 remove:something
@@ -1155,68 +1327,32 @@
             ]
         ].
         props := self propertyOf:anObject.
-        self undoRemove:props.
-        viewProperties remove:props.
+
+        props notNil ifTrue:[
+            self undoRemove:props.
+            viewProperties remove:props
+        ].
         anObject destroy
     ]
 ! !
 
-!UIPainterView methodsFor:'selections'!
-
-addNameToSelection:aString
-    |prop|
-
-    prop := self propertyOfName:aString.
-
-    prop notNil ifTrue:[
-        self addToSelection:(prop view)
-    ]
+!UIPainterView methodsFor:'searching'!
 
-!
-
-removeNameFromSelection:aString
-    |prop|
-
-    prop := self propertyOfName:aString.
-
-    prop notNil ifTrue:[
-        self removeFromSelection:(prop view)
-    ]
-
-!
+findObjectAt:aPoint
+    "find the origin/corner of the currentWidget
+    "
+    |view|
 
-selectName:aStringOrCollection
-    |prop coll s|
-
-    (aStringOrCollection isNil or:[aStringOrCollection isEmpty]) ifTrue:[
-        ^ self unselect
-    ].
-
-    (s := aStringOrCollection) isString ifFalse:[
-        s size == 1 ifTrue:[
-            s := s first
-        ] ifFalse:[
-            coll := OrderedCollection new.
+    view := super findObjectAt:aPoint.
 
-            s do:[:aName|
-                (prop := self propertyOfName:aName) notNil ifTrue:[
-                    coll add:(prop view)
-                ]
-            ].
-            coll size == 1 ifTrue:[ ^ self select:(coll at:1) ].
-            coll size == 0 ifTrue:[ ^ self unselect ].
-
-            self hideSelection.
-            selection := coll.
-            self showSelection.
-          ^ self changed:#selection
+    view notNil ifTrue:[
+        "can be a view within a view not visible
+        "
+        [ (self propertyOfView:view) isNil ] whileTrue:[
+            (view := view superView) == self ifTrue:[^ nil]
         ]
     ].
-
-    prop := self propertyOfName:s.
-    prop isNil ifTrue:[^ self unselect]
-              ifFalse:[^ self select:(prop view)]
-
+    ^ view
 ! !
 
 !UIPainterView methodsFor:'seraching property'!
@@ -1281,6 +1417,12 @@
     (aComponent isKindOf:EditField) ifTrue:[
         ^ false
     ].
+    (aComponent isKindOf:ComboBoxView) ifTrue:[
+        ^ false
+    ].
+    (aComponent isKindOf:CheckBox) ifTrue:[
+        ^ false
+    ].
     (aComponent isKindOf:ScrollBar) ifTrue:[
         ^ aComponent orientation == #vertical
     ].
@@ -1295,6 +1437,109 @@
 
 ! !
 
+!UIPainterView methodsFor:'transaction & undo'!
+
+transaction:aType objects:something do:aOneArgBlock
+    "opens a transaction and evaluates a block within the transaction; the
+     argument to the block is a view from derived from something
+    "
+    |text|
+
+    something notNil ifTrue:[
+        text := self transactionTextFor:something.
+
+        undoHistory transaction:aType text:text do:[
+            something isCollection ifTrue:[
+                something do:[:aView| aOneArgBlock value:aView ]
+            ] ifFalse:[
+                aOneArgBlock value:something
+            ]
+        ]
+    ]
+!
+
+transactionTextFor:anElementOrCollection
+    "returns text used by transaction or nil
+    "
+    |props|
+
+    anElementOrCollection notNil ifTrue:[
+        anElementOrCollection size > 1 ifTrue:[
+            ^ 'a collection'
+        ].
+
+        anElementOrCollection isCollection ifFalse:[
+            props := self propertyOfView:anElementOrCollection
+        ] ifTrue:[
+            anElementOrCollection notEmpty ifTrue:[
+                props := self propertyOfView:(anElementOrCollection at:1)
+            ]
+        ].
+
+        props notNil ifTrue:[
+            ^ props name
+        ]
+    ].
+    ^ nil
+!
+
+undoCreate:aViewIdentifier
+
+    undoHistory isTransactionOpen ifTrue:[
+        undoHistory addUndoBlock:[
+            |props|
+
+            props := self propertyOfIdentifier:aViewIdentifier.
+
+            props notNil ifTrue:[
+                self removeObject:(props view)
+            ]
+        ]
+    ]
+!
+
+undoRemove:propertyOfView
+    |clsName layout parent aView|
+
+    (propertyOfView notNil and:[undoHistory isTransactionOpen]) ifFalse:[
+        ^ self
+    ].
+
+    aView   := propertyOfView view.
+    clsName := aView class.
+    layout  := aView geometryLayout.
+    parent  := aView superView.
+
+    parent ~~ self ifTrue:[
+        parent := (self propertyOf:parent) identifier.
+    ] ifFalse:[
+        parent := nil
+    ].
+    propertyOfView view:nil.    
+
+    undoHistory addUndoBlock:[
+        |recreatedView props|
+
+        parent notNil ifTrue:[
+            props := self propertyOfIdentifier:parent.
+
+            props notNil ifTrue:[parent := props view]
+                        ifFalse:[parent := self]
+        ] ifFalse:[
+            parent := self
+        ].
+
+        recreatedView := clsName in:parent.
+        recreatedView geometryLayout:layout.
+        propertyOfView view:recreatedView.    
+        self addProperties:propertyOfView for:recreatedView.
+        recreatedView realize.
+        inputView raise.
+    ].
+    aView := nil.
+
+! !
+
 !UIPainterView::ViewProperty class methodsFor:'instance creation'!
 
 new