# HG changeset patch # User ca # Date 864644904 -7200 # Node ID 9779b7459a1cce8cb94a7d62fd23f430191c79ab # Parent 95070ea7ae4295d678e9637fd56c4c238eefeb64 selection and update from selection diff -r 95070ea7ae42 -r 9779b7459a1c UIObjectView.st --- a/UIObjectView.st Mon May 26 13:06:42 1997 +0200 +++ b/UIObjectView.st Mon May 26 13:08:24 1997 +0200 @@ -21,6 +21,19 @@ privateIn:UIObjectView::UndoHistory ! +!UIObjectView class methodsFor:'documentation'! + +documentation +" + buildIn view used by the UIPainter; from this view, the layout of the + new application derives from. + + [see also:] + UIBuilder + UIPainterView +" + +! ! !UIObjectView class methodsFor:'conversion'! @@ -233,16 +246,14 @@ " (aState == enableChannel value) ifFalse:[ aState ifFalse:[ - saveSelection := selection copy - ]. - enableChannel value:aState. - - aState ifFalse:[ + saveSelection := self selection copy. self unselect. - inputView unrealize + enableChannel value:aState. + inputView unrealize. ] ifTrue:[ inputView raise. inputView realize. + enableChannel value:aState. self select:saveSelection. ] ] @@ -298,9 +309,7 @@ "handle an expose event from device; redraw selection " super exposeX:x y:y width:w height:h. -"/ selectionHiddenLevel == 0 ifTrue:[ - self selectionDo:[:v | self showSelected:v] -"/ ] + self selectionDo:[:v | self showSelected:v] ! @@ -315,27 +324,14 @@ key == #Copy ifTrue:[ ^ self copySelection]. key == #Paste ifTrue:[ ^ self pasteBuffer]. - - super keyPress:key x:x y:y - - ! processEvent:anEvent "catch expose events for components, and redraw its handles after the redraw when this happens " - |view| - - selection notNil ifTrue:[ - anEvent type == #damage ifTrue:[ - view := anEvent view. - (selection == view - or:[selection isCollection - and:[selection includes:view]]) ifTrue:[ - self showSelected:view - ] - ] + (anEvent type == #damage and:[self isSelected:(anEvent view)]) ifTrue:[ + self showSelected:(anEvent view) ]. ^ false. @@ -630,19 +626,13 @@ "cleanup after object(s) move " movedObject notNil ifTrue:[ - movedObject do:[:aView| - self invertOutlineOf:aView - ]. - - movedObject do:[:aView| - self showSelected:aView + movedObject do:[:aView|self invertOutlineOf:aView]. + + movedObject size == 1 ifTrue:[ + movedObject := movedObject first ]. - movedObject size == 1 ifTrue:[ - selection := movedObject at:1 - ] ifFalse:[ - selection := movedObject - ]. - + + self setSelection:movedObject withRedraw:true. movedObject := nil. self setDefaultActions. self changed:#layout. @@ -672,14 +662,13 @@ startObjectMoveAt:aPoint "start object(s) move at a point " - self startObjectMove:selection at:aPoint. - - selection isCollection ifTrue:[ - movedObject := selection - ] ifFalse:[ - movedObject := Array with:selection + self startObjectMove:(self selection) at:aPoint. + movedObject := self selection. + + movedObject isCollection ifFalse:[ + movedObject := Array with:movedObject ]. - super unselect. + self setSelection:nil withRedraw:true. moveDelta := movedObject collect:[:aView| aPoint - aView computeOrigin @@ -738,13 +727,11 @@ ]. (self canMove:aView) ifFalse:[ - super unselect. - ^ self select:aView + ^ self select:aView ] ]. (self isSelected:aView) ifFalse:[ - super unselect. self select:aView. ]. @@ -817,7 +804,7 @@ self invertOutlineOf:object. self setDefaultActions. self elementChangedSize:object. - super select:object. + self setSelection:object withRedraw:true. self changed:#layout. ! @@ -832,7 +819,7 @@ self transaction:#resize selectionDo:[:aView| self undoLayoutView:aView ]. - super unselect. + self setSelection:nil withRedraw:true. motionAction := [:movePoint | self doDragResize:movePoint]. releaseAction := [self endResize]. @@ -1213,41 +1200,80 @@ !UIObjectView methodsFor:'selections'! -addToSelection:something - "add something to selection +addToSelection:anObject + "add anObject to selection " - (self canSelect:something) ifTrue:[ - super addToSelection:something. - self selectionChanged. + |coll| + + self enabled ifTrue:[ + self hasSelection ifFalse:[ + self select:anObject + ] ifTrue:[ + (self isSelected:anObject) ifFalse:[ + (coll := self selection) isCollection ifFalse:[ + coll := OrderedCollection with:coll + ]. + coll add:anObject. + self setSelection:coll withRedraw:false. + self showSelected:anObject. + self selectionChanged. + ] + ] ] ! +moveableSelection + "tests whether all selected objects are moveable and in case + of true the selection is returned, otherwise nil + " + |coll| + + self hasSelection ifTrue:[ + (self canMove:(coll := self selection)) ifTrue:[ + ^ coll + ] + ]. + ^ nil +! + numberOfSelections "return the number of selected entries " - |sz| - - selection isNil ifTrue:[^ 0]. - - selection isCollection ifTrue:[^ selection size] - ifFalse:[^ 1 ] + |coll size| + + coll := self selection. + size := coll size. + + (size ~~ 0 or:[coll isNil]) ifTrue:[^ size]. + ^ 1 ! -removeFromSelection:something - "remove something from selection +removeFromSelection:anObject + "remove anObject from selection " - something notNil ifTrue:[ - super removeFromSelection:something. - self selectionChanged + |sel| + + (self isSelected:anObject) ifFalse:[ + ^ self ]. + sel := self selection. + + sel size > 1 ifTrue:[ + sel := sel copy. + sel remove:anObject ifAbsent:nil. + ] ifFalse:[ + sel := nil + ]. + self setSelection:sel withRedraw:true. + self selectionChanged. ! select:something "change selection to something " - (self canSelect:something) ifTrue:[ - super select:something. + (self enabled and:[something ~= self selection]) ifTrue:[ + self setSelection:something withRedraw:true. self selectionChanged ] @@ -1270,20 +1296,45 @@ ! +selectionDo:aBlock + "apply block to every selected object + " + self forEach:(self selection) do:aBlock + + +! + +setSelection:aNewSelection withRedraw:doRedraw + "set a new selection + " + doRedraw ifTrue:[ + self hideSelection. + selection := aNewSelection. + self showSelection + ] ifFalse:[ + selection := aNewSelection + ] +! + showSelection + "show the selection - draw handles + " selectionHiddenLevel == 0 ifTrue:[ - super showSelection. + self selectionDo:[:el| self showSelected:el ] ]. ! singleSelection "returns single selection or nil " - selection isCollection ifFalse:[ - ^ selection + |coll| + + (coll := self selection) isCollection ifFalse:[ + ^ coll ]. - selection size == 1 ifTrue:[ ^ selection at:1] - ifFalse:[ ^ nil]. + + coll size == 1 ifTrue:[ ^ coll first]. + ^ nil ! singleSelectionDo:aBlock @@ -1299,12 +1350,7 @@ unselect "clear selection " - selection notNil ifTrue:[ - super unselect. - self selectionChanged - ] - - + self select:nil ! withSelectionHiddenDo:aBlock @@ -1338,13 +1384,13 @@ " |sel| - selection isNil ifTrue:[ + self hasSelection ifFalse:[ aBlock value - ] ifFalse:[ - sel := selection. - super unselect. + ] ifTrue:[ + sel := self selection. + self setSelection:nil withRedraw:true. aBlock value. - super select:sel + self setSelection:sel withRedraw:true. ] @@ -1415,10 +1461,10 @@ "Modified: 8.4.1997 / 01:19:14 / cg" ! -canSelect:something - "returns true if something can be selected and enabled is true +hasSelection + "returns true if any selected object exists " - ^ (self enabled and:[something ~~ selection]) + ^ self numberOfSelections ~~ 0 ! @@ -1436,6 +1482,16 @@ ! +isSelected:anObject + "return true, if the argument, anObject is selected + " + anObject notNil ifTrue:[ + self selectionDo:[:el| el == anObject ifTrue:[^ true]] + ]. + ^ false + +! + isVerticalResizable:aComponent "returns true if instance is vertical resizeable " @@ -1467,7 +1523,7 @@ "opens a transaction and evaluates a block within the transaction; the argument to the block is a view from the selection " - self transaction:aType objects:selection do:aOneArgBlock + self transaction:aType objects:(self selection) do:aOneArgBlock ! @@ -1645,9 +1701,9 @@ moveSelectionDown "move selection down " - |gridY n| - - (self canMove:selection) ifTrue:[ + |gridY n sel| + + self moveableSelection notNil ifTrue:[ gridAlign notNil ifTrue:[gridY := gridAlign y]. self withSelectionHiddenDo:[ @@ -1676,7 +1732,7 @@ " |gridX n| - (self canMove:selection) ifTrue:[ + self moveableSelection notNil ifTrue:[ gridAlign notNil ifTrue:[gridX := gridAlign x]. self withSelectionHiddenDo:[ @@ -1700,7 +1756,7 @@ " |gridX n| - (self canMove:selection) ifTrue:[ + self moveableSelection notNil ifTrue:[ gridAlign notNil ifTrue:[gridX := gridAlign x]. self withSelectionHiddenDo:[ @@ -1725,7 +1781,7 @@ " |gridY n| - (self canMove:selection) ifTrue:[ + self moveableSelection notNil ifTrue:[ gridAlign notNil ifTrue:[gridY := gridAlign y]. self withSelectionHiddenDo:[ @@ -1751,12 +1807,12 @@ "align selection to the bottom of the first object in the selection; in case of one selection the object is aligned to the bottom of its superview " - |bmost delta| - - (self canMove:selection) ifTrue:[ + |bmost delta sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - bmost := (selection at:1) computeCorner y. + bmost := (sel first) computeCorner y. self transaction:#alignBottom selectionDo:[:v| (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ @@ -1781,9 +1837,9 @@ "align selection to the center/horizontal of the first object in the selection; in case of one selection the object is aligned to the center/horizontal of its superview " - |view center| - - (self canMove:selection) ifTrue:[ + |view center sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ view := self singleSelection. @@ -1791,7 +1847,7 @@ view := view superView. center := view computeExtent ] ifFalse:[ - view := selection at:1. + view := sel first. center := view computeCorner + view computeOrigin. ]. center := center x // 2. @@ -1817,9 +1873,9 @@ "align selection to the center/vertical of the first object in the selection; in case of one selection the object is aligned to the center/vertical of its superview " - |view center| - - (self canMove:selection) ifTrue:[ + |view center sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ view := self singleSelection. @@ -1827,7 +1883,7 @@ view := view superView. center := view computeExtent ] ifFalse:[ - view := selection at:1. + view := sel first. center := view computeCorner + view computeOrigin. ]. center := center y // 2. @@ -1850,12 +1906,12 @@ "align selection to the left of the first object in the selection; in case of one selection the object is aligned to the left of its superview " - |lmost delta| - - (self canMove:selection) ifTrue:[ + |lmost delta sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - lmost := (selection at:1) computeOrigin x. + lmost := (sel first) computeOrigin x. self transaction:#alignLeft selectionDo:[:v| (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ @@ -1877,13 +1933,13 @@ "align selection to the left/right of the first object in the selection; in case of one selection the object is aligned to the left/right of its superview " - |lmost rmost| - - (self canMove:selection) ifTrue:[ + |lmost rmost sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - lmost := (selection at:1) computeOrigin x. - rmost := (selection at:1) computeCorner x. + lmost := (sel first) computeOrigin x. + rmost := (sel first) computeCorner x. self transaction:#alignLeftRight selectionDo:[:aView| |layout| @@ -1918,12 +1974,12 @@ "align selection to the right of the first object in the selection; in case of one selection the object is aligned to the right of its superview " - |rmost delta| - - (self canMove:selection) ifTrue:[ + |rmost delta sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - rmost := (selection at:1) computeCorner x. + rmost := (sel first) computeCorner x. self transaction:#alignRight selectionDo:[:v| (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ @@ -1945,12 +2001,12 @@ "align selection to the top of the first object in the selection; in case of one selection the object is aligned to the top of its superview " - |tmost delta| - - (self canMove:selection) ifTrue:[ + |tmost delta sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - tmost := (selection at:1) computeOrigin y. + tmost := (sel first) computeOrigin y. self transaction:#alignTop selectionDo:[:v| (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ @@ -1973,13 +2029,13 @@ "align selection to the top/bottom of the first object in the selection; in case of one selection the object is aligned to the top/bottom of its superview " - |tmost bmost| - - (self canMove:selection) ifTrue:[ + |tmost bmost sel| + + (sel := self moveableSelection) notNil ifTrue:[ self withSelectionHiddenDo:[ self numberOfSelections > 1 ifTrue:[ - tmost := (selection at:1) computeOrigin y. - bmost := (selection at:1) computeCorner y. + tmost := (sel first) computeOrigin y. + bmost := (sel first) computeCorner y. self transaction:#alignTopBottom selectionDo:[:aView| |layout| @@ -2015,7 +2071,7 @@ " |superview min max delta val| - (self canMove:selection) ifFalse:[ + (self moveableSelection) isNil ifTrue:[ ^ self ]. @@ -2098,9 +2154,11 @@ spreadSelectionHor "spread multiple selection horizontal " - |sumWidths min max viewsInOrder topsInOrder count space| - - (self numberOfSelections > 1 and:[self canMove:selection]) ifFalse:[ + |sumWidths min max viewsInOrder topsInOrder count space sel| + + sel := self moveableSelection. + + (sel notNil and:[self numberOfSelections > 1]) ifFalse:[ ^ self ]. @@ -2118,7 +2176,7 @@ max := max max:(aView right). count := count + 1 ]. - viewsInOrder := Array withAll:selection. + viewsInOrder := Array withAll:sel. topsInOrder := viewsInOrder collect:[:aView | aView left]. topsInOrder sortWith:viewsInOrder. @@ -2139,9 +2197,11 @@ spreadSelectionVer "spread multiple selection vertical " - |sumHeights min max viewsInOrder topsInOrder count space| - - (self numberOfSelections > 1 and:[self canMove:selection]) ifFalse:[ + |sumHeights min max viewsInOrder topsInOrder count space sel| + + sel := self moveableSelection. + + (sel notNil and:[self numberOfSelections > 1]) ifFalse:[ ^ self ]. @@ -2159,7 +2219,7 @@ max := max max:(aView bottom). count := count + 1 ]. - viewsInOrder := Array withAll:selection. + viewsInOrder := Array withAll:sel. topsInOrder := viewsInOrder collect:[:aView|aView top]. topsInOrder sortWith:viewsInOrder. diff -r 95070ea7ae42 -r 9779b7459a1c UIPainterView.st --- a/UIPainterView.st Mon May 26 13:06:42 1997 +0200 +++ b/UIPainterView.st Mon May 26 13:08:24 1997 +0200 @@ -17,16 +17,16 @@ category:'Interface-UIPainter' ! -MultiSelectionInList subclass:#ListHolder - instanceVariableNames:'painter propertyList masterElement disabledChanged' - classVariableNames:'' +Object subclass:#ViewProperty + instanceVariableNames:'view spec identifier' + classVariableNames:'Identifier' poolDictionaries:'' privateIn:UIPainterView ! -Object subclass:#ViewProperty - instanceVariableNames:'view spec identifier' - classVariableNames:'Identifier' +MultiSelectionInList subclass:#ListHolder + instanceVariableNames:'painter propertyList masterElement disabledChanged' + classVariableNames:'' poolDictionaries:'' privateIn:UIPainterView ! @@ -56,7 +56,12 @@ documentation " - not yet finished, not yet published, not yet released. + buildIn view used by the UIPainter; from this view, the layout of the + new application derives from. + + [see also:] + UIBuilder + UIObjectView " ! ! @@ -329,14 +334,12 @@ " |newSel| - selection notNil ifTrue:[ - self selectionDo:[:aView||p| - (p := self propertyOfView:aView) notNil ifTrue:[ - newSel isNil ifTrue:[ - newSel := OrderedCollection new - ]. - newSel add:(listHolder indexOfName:(p name)) - ] + self selectionDo:[:aView||p| + (p := self propertyOfView:aView) notNil ifTrue:[ + newSel isNil ifTrue:[ + newSel := OrderedCollection new + ]. + newSel add:(listHolder indexOfName:(p name)) ] ]. listHolder removeDependent:self. @@ -355,10 +358,27 @@ loIdx size ~~ 0 ifTrue:[ newSel := loIdx collect:[:i|(listHolder propertyAt:i) view] ]. - self withSelectionHiddenDo:[ - selection := newSel + self updateSelectionFrom:newSel. +! + +updateSelectionFrom:aSel + "update selection from a new selection + " + |csel| + + selectionHiddenLevel == 0 ifTrue:[ + aSel isCollection ifTrue:[ + self selectionDo:[:el| + (aSel includes:el) ifFalse:[self showUnselected:el] + ] + ] ifFalse:[ + self selectionDo:[:el| + aSel == el ifFalse:[self showUnselected:el] + ] + ] ]. - + self setSelection:aSel withRedraw:false. + self showSelection ! ! !UIPainterView methodsFor:'copy & cut & paste'! @@ -368,7 +388,7 @@ " |specs coll| - coll := self minSetOfSuperViews:selection. + coll := self minSetOfSuperViews:(self selection). coll notNil ifTrue:[ self unselect. @@ -385,7 +405,7 @@ " |text specs coll| - coll := self minSetOfSuperViews:selection. + coll := self minSetOfSuperViews:(self selection). coll notNil ifTrue:[ listHolder disableNotificationsWhileEvaluating:[ @@ -879,7 +899,9 @@ groupEnterFields |props group objects| - selection isNil ifTrue:[^ self]. + self hasSelection ifFalse:[ + ^ self + ]. self selectionDo:[:aView | (aView isKindOf:EditField) ifFalse:[ self warn:'select EditFields only !!'. @@ -909,7 +931,9 @@ groupRadioButtons |props name group objects| - selection isNil ifTrue:[^ self]. + self hasSelection ifFalse:[ + ^ self + ]. self selectionDo:[:aView | (aView isKindOf:RadioButton) ifFalse:[ self warn:'select RadioButtons only !!'. @@ -995,9 +1019,8 @@ showFontPanel |action theFont fontPanel| - fontPanel := FontPanel new. - - selection notNil ifTrue:[ + self hasSelection ifTrue:[ + fontPanel := FontPanel new. action := [:aFontDescription | theFont := aFontDescription]. fontPanel action:action. fontPanel showAtPointer. @@ -1006,8 +1029,6 @@ self changeFont:theFont ] ] - - "Modified: 10.4.1997 / 10:06:15 / cg" ! showMiddleButtonMenu @@ -1022,18 +1043,13 @@ canPaste := self canPaste:(self getSelection). - selection isNil ifTrue:[ + self hasSelection ifTrue:[ + canPaste := (canPaste and:[self canPasteInto:(self selection)]) + ] ifFalse:[ menu disableAll - ] ifFalse:[ - canPaste := (canPaste and:[self canPasteInto:selection]) ]. - menu enabledAt:#paste put:[|can| - can := self canPaste:(self getSelection). - selection isNil ifTrue:[can] - ifFalse:[(can and:[self canPasteInto:selection])] - ]. - - menu enabledAt:#undo put:(undoHistory notEmpty). + menu enabledAt:#paste put:canPaste. + menu enabledAt:#undo put:(undoHistory notEmpty). menu startUp. ^ nil @@ -1274,9 +1290,7 @@ ]. aCollection size > 1 ifTrue:[ - self withSelectionHiddenDo:[ - selection := aCollection - ]. + self updateSelectionFrom:aCollection. self selectionChanged ] ! ! @@ -1602,6 +1616,102 @@ ! ! +!UIPainterView::ViewProperty class methodsFor:'documentation'! + +version + ^ '$Header$' +! ! + +!UIPainterView::ViewProperty class methodsFor:'instance creation'! + +new + Identifier notNil ifTrue:[Identifier := Identifier + 1] + ifFalse:[Identifier := 1]. + + ^ self basicNew initialize +! ! + +!UIPainterView::ViewProperty methodsFor:'accessing'! + +group + ^ nil +! + +identifier + "return the unique identifier assigned to property + " + ^ identifier +! + +spec + "return the value of the instance variable 'spec' (automatically generated)" + + ^ spec! + +spec:something + "set the value of the instance variable 'spec' (automatically generated)" + + spec := something.! + +view + "return the value of the instance variable 'view' (automatically generated)" + + ^ view! + +view:something + "set the value of the instance variable 'view' (automatically generated)" + + view := something.! ! + +!UIPainterView::ViewProperty methodsFor:'initialization'! + +initialize + super initialize. + identifier := Identifier +! ! + +!UIPainterView::ViewProperty methodsFor:'misc'! + +extractNumberStartingAt:anIndex + "return the number from the name starting at anIndex or 0. + " + |val| + + val := 0. + + self name from:anIndex do:[:c| + c isDigit ifTrue:[val := val * 10 + c digitValue] + ifFalse:[^ 0] + ]. + ^ val + +! ! + +!UIPainterView::ViewProperty methodsFor:'spec messages'! + +doesNotUnderstand:aMessage + spec notNil ifTrue:[ + (spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] + ]. + ^ nil +! + +layout + spec layout +! + +layout:aLayout + spec layout:aLayout +! + +name + ^ spec name +! + +name:aName + spec name:aName +! ! + !UIPainterView::ListHolder class methodsFor:'instance creation'! for:aPainter @@ -1933,102 +2043,6 @@ super selectionIndex:aSel ! ! -!UIPainterView::ViewProperty class methodsFor:'documentation'! - -version - ^ '$Header$' -! ! - -!UIPainterView::ViewProperty class methodsFor:'instance creation'! - -new - Identifier notNil ifTrue:[Identifier := Identifier + 1] - ifFalse:[Identifier := 1]. - - ^ self basicNew initialize -! ! - -!UIPainterView::ViewProperty methodsFor:'accessing'! - -group - ^ nil -! - -identifier - "return the unique identifier assigned to property - " - ^ identifier -! - -spec - "return the value of the instance variable 'spec' (automatically generated)" - - ^ spec! - -spec:something - "set the value of the instance variable 'spec' (automatically generated)" - - spec := something.! - -view - "return the value of the instance variable 'view' (automatically generated)" - - ^ view! - -view:something - "set the value of the instance variable 'view' (automatically generated)" - - view := something.! ! - -!UIPainterView::ViewProperty methodsFor:'initialization'! - -initialize - super initialize. - identifier := Identifier -! ! - -!UIPainterView::ViewProperty methodsFor:'misc'! - -extractNumberStartingAt:anIndex - "return the number from the name starting at anIndex or 0. - " - |val| - - val := 0. - - self name from:anIndex do:[:c| - c isDigit ifTrue:[val := val * 10 + c digitValue] - ifFalse:[^ 0] - ]. - ^ val - -! ! - -!UIPainterView::ViewProperty methodsFor:'spec messages'! - -doesNotUnderstand:aMessage - spec notNil ifTrue:[ - (spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] - ]. - ^ nil -! - -layout - spec layout -! - -layout:aLayout - spec layout:aLayout -! - -name - ^ spec name -! - -name:aName - spec name:aName -! ! - !UIPainterView::GroupProperties methodsFor:'accessing'! controlledObjects