diff -r 995078a58977 -r d80b3c6a4373 UIPainterView.st --- a/UIPainterView.st Mon Aug 18 13:08:22 1997 +0200 +++ b/UIPainterView.st Mon Aug 18 13:09:23 1997 +0200 @@ -280,17 +280,14 @@ withArgs:(newSel collect:[:v|(self propertyOfView:v) identifier]) ]. - newSel size == 1 ifTrue:[ - newSel := newSel at:1 - ]. self realizeAllSubViews. + newSel do:[:v| v raise]. inputView raise. self elementChangedSize:frame. + + newSel size == 1 ifTrue:[newSel := newSel at:1]. ]. ^ newSel - - "Created: 11.8.1997 / 00:59:38 / cg" - "Modified: 11.8.1997 / 01:05:27 / cg" ! pasteWithLayout @@ -315,6 +312,13 @@ ^ false ! +canPaste + "returns true if something to be past exists and can be paste into + the selection if exists + " + ^ self canPaste:(self getSelection) +! + canPaste:something "returns true if something could be paste " @@ -340,13 +344,13 @@ canPasteInto:aView "can paste into a view " - |spec| + |prop| aView notNil ifTrue:[ - spec := self specFor:aView. - - spec isNil ifTrue:[^ aView specClass supportsSubComponents] - ifFalse:[^ spec class supportsSubComponents] + (prop := self propertyRespondsToView:aView) notNil ifTrue:[ + ^ prop spec class supportsSubComponents + ]. + ^ aView specClass supportsSubComponents. ]. ^ false @@ -571,6 +575,7 @@ self addSpec:(spec component) builder:builder in:self. self realizeAllSubViews. inputView raise. + treeView canvasNameChanged:(spec window name). ] ! @@ -583,17 +588,8 @@ showMiddleButtonMenu "show the middle button menu; this returns nil " - |menu| - self enabled ifTrue:[ - menu := MenuPanel fromSpec:(UIPainter menuCanvas) receiver:self. - - self hasSelection ifFalse:[ - menu disableAll - ]. - menu enabledAt:#paste put:(self canPaste:(self getSelection)). - menu enabledAt:#undo put:(undoHistory isEmpty not). - menu startUp. + (MenuPanel fromSpec:(UIPainter menuCanvas) receiver:self) startUp ]. ^ nil @@ -623,39 +619,27 @@ !UIPainterView methodsFor:'searching'! -findContainerViewAt:aPoint - "find container view responds to aPoint. +findContainerOfView:aView + "returns the super view assigned to a view " - |view| + |p| - (view := self findObjectAt:aPoint) isNil ifTrue:[ + (p := self propertyOfParentForView:aView) isNil ifTrue:[ ^ self ]. - - [(view specClass supportsSubComponents or:[(view := view superView) == self]) - ] whileFalse:[ - [(self propertyOfView:view) isNil] whileTrue:[ - (view := view superView) == self ifTrue:[^ self] - ]. - ]. - ^ view + ^ p view ! findObjectAt:aPoint "find the origin/corner of the currentWidget " - |view| + |view prop| view := super findObjectAt:aPoint. + prop := self propertyRespondsToView:view. - view notNil ifTrue:[ - "can be a view within a view not visible - " - [ (self propertyOfView:view) isNil ] whileTrue:[ - (view := view superView) == self ifTrue:[^ nil] - ] - ]. - ^ view + prop notNil ifTrue:[^ prop view]. + ^ nil ! findViewWithId:aViewId @@ -690,6 +674,17 @@ ^ nil ! +propertyOfParentForView:aSubView + "returns the property of the parent or nil + " + |item| + + (item := treeView detectItemRespondsToView:aSubView) notNil ifTrue:[ + (item := item parent) notNil ifTrue:[^ item contents] + ]. + ^ nil +! + propertyOfView:aView "returns property assigned to view " @@ -699,6 +694,21 @@ ^ nil ! +propertyRespondsToView:aView + "detect the property responding to the argument a view. The property of the view or + the first subview providing the properties is returned. If no property is detected + nil is returned. + " + |item| + + item := treeView detectItemRespondsToView:aView. + + (item notNil and:[item parent notNil]) ifTrue:[ + ^ item contents + ]. + ^ nil +! + uniqueNameFor:aSpecOrString "generate and return an unique name for a class " @@ -794,25 +804,19 @@ ! -updateSelectionFromModel:aSel +updateSelectionFromModel:aSelOrNil "update selection from a new selection " - |sel| - selectionHiddenLevel == 0 ifTrue:[ - self selectionDo:[:el| (aSel includes:el) ifFalse:[self showUnselected:el] ] + aSelOrNil size ~~ 0 ifTrue:[ + self selectionDo:[:el| (aSelOrNil includes:el) ifFalse:[self showUnselected:el] ] + ] ifFalse:[ + self selectionDo:[:el| self showUnselected:el ] + ] ]. - - (aSel indexOf:self) ~~ 0 ifTrue:[ - aSel size > 1 ifTrue:[sel := aSel copyWithout:self] - ] ifFalse:[ - aSel size ~~ 0 ifTrue:[sel := aSel] - ]. - - self setSelection:sel withRedraw:false. + self setSelection:aSelOrNil withRedraw:false. self showSelection - ! ! !UIPainterView methodsFor:'specification'! @@ -881,6 +885,24 @@ ! +rebuildView:aView fromSpec:aSpec withBuilder:aBuilder + |v| + + aSpec needsRebuildForAttributes ifTrue:[ + v := aSpec buildViewWithLayoutFor:aBuilder in:(self findContainerOfView:aView). + v realize. + aView destroy. + device sync. + device flush. + aView becomeSameAs:v. + inputView raise. + ] ifFalse:[ + aSpec setAttributesIn:aView with:aBuilder. + self elementChangedSize:aView. + ]. + +! + specFor:anObject "returns spec assigned to an object " @@ -931,18 +953,7 @@ ]. aSpec name:name. self createUndoSpecModify:props. - - aSpec needsRebuildForAttributes ifTrue:[ - v := aSpec buildViewWithLayoutFor:builder in:aView superView. - v realize. - aView destroy. - device sync. device flush. - aView becomeSameAs:v. - inputView raise. - ] ifFalse:[ - aSpec setAttributesIn:aView with:builder. - self elementChangedSize:aView. - ]. + self rebuildView:aView fromSpec:aSpec withBuilder:builder. props spec:(aSpec copy). treeView propertyChanged:props. ] @@ -952,6 +963,52 @@ "Modified: 4.7.1997 / 23:49:44 / cg" ! ! +!UIPainterView methodsFor:'testing'! + +canChangeLayoutOfView:aView + "returns true if the view can change its layout which is dependant on + its parent view. + " + |item prnt| + + ( (item := treeView itemOfView:aView) isNil + or:[(prnt := item parent) isNil] + ) ifTrue:[ + ^ false + ]. + ^ (prnt parent isNil or:[prnt contents spec class isLayoutContainer not]) +! + +canKeepLayoutInSelection + "returns true if layout can be kept during a paste operation + " + |prop| + + prop := self propertyOfView:(self singleSelection). + ^ (prop isNil or:[prop spec class isLayoutContainer not]) +! + +canMove:something + "checks whether something is not nil and if all widgets derived from + something can change their layout ( move, align, ... operation ). + " + something notNil ifTrue:[ + self forEach:something do:[:aView| + (self canChangeLayoutOfView:aView) ifFalse:[^ false] + ]. + ^ true + ]. + ^ false +! + +canMoveOrAlignSelection + "returns true if a selection exists and all elements in the selection + can be moved or aligned + " + ^ self canMove:(self selection) + +! ! + !UIPainterView methodsFor:'transaction'! transaction:aType objects:something do:aOneArgBlock @@ -1019,19 +1076,17 @@ createUndoRemove:aView "create undo method before deleting views " - |frame prop pId spec| + |prop pid| (prop := self propertyOfView:aView) notNil ifTrue:[ - spec := self fullSpecFor:aView. - frame := aView superView. + (pid := self propertyOfParentForView:aView) notNil ifTrue:[ + pid := pid identifier + ]. - (self canPasteInto:frame) ifTrue:[ - (frame := self propertyOfView:frame) notNil ifTrue:[ - pId := frame identifier - ] - ]. undoHistory addUndoSelector:#undoRemove: - withArgs:(Array with:spec with:(prop identifier) with:pId) + withArgs:(Array with:(self fullSpecFor:aView) + with:(prop identifier) + with:pid) ] ! @@ -1096,16 +1151,7 @@ builder applicationClass:(Smalltalk classNamed:className). ]. props spec:spec. - - spec needsRebuildForAttributes ifTrue:[ - v := spec buildViewWithLayoutFor:builder in:view superView. - v realize. - view destroy. - view become:v - ] ifFalse:[ - spec setAttributesIn:view with:builder. - self elementChangedSize:view. - ]. + self rebuildView:view fromSpec:spec withBuilder:builder. treeView propertyChanged:props. ] ! !