# HG changeset patch # User ca # Date 1042897988 -3600 # Node ID ed8aa80a11a9f1f9848a318503d500b83f7f648a # Parent 5ec4b63a862aed4ca6bdbf28eb35f2a44b4c66e0 *** empty log message *** diff -r 5ec4b63a862a -r ed8aa80a11a9 UIGalleryView.st --- a/UIGalleryView.st Fri Jan 17 21:55:37 2003 +0100 +++ b/UIGalleryView.st Sat Jan 18 14:53:08 2003 +0100 @@ -22,8 +22,8 @@ ! View subclass:#Canvas - instanceVariableNames:'lockSema dragMode clientSpecHolder selection specification - lastClickPoint menuSelector uiBuilder buttonPressed' + instanceVariableNames:'dragMode clientSpecHolder selection specification lastClickPoint + menuSelector uiBuilder buttonPressed' classVariableNames:'' poolDictionaries:'' privateIn:UIGalleryView @@ -302,9 +302,14 @@ "set the holder which keeps the current selection or in case of no selection the specification under the cursor " - (clientSpecHolder := aHolder) notNil ifTrue:[ - clientSpecHolder value:selection - ]. + |spec| + + spec := clientSpecHolder value. + + aHolder notNil ifTrue:[ clientSpecHolder := aHolder ] + ifFalse:[ clientSpecHolder := nil asValue ]. + + clientSpecHolder value:spec. ! menuSelector @@ -322,9 +327,7 @@ specification "get current specification " - ^ specification - - + ^ specification ! specification:aSpecOrSpecArray @@ -333,36 +336,31 @@ |builder| self selection:nil. + self destroySubViews. - subViews size ~~ 0 ifTrue:[ - subViews copy do:[:aSubView| aSubView destroy ]. + ( aSpecOrSpecArray notNil + and:[(specification := UISpecification from:aSpecOrSpecArray) notNil + and:[specification respondsTo:#'buildViewFor:in:']] + ) ifFalse:[ + specification := nil. + ^ self ]. - aSpecOrSpecArray notNil ifTrue:[ - specification := UISpecification from:aSpecOrSpecArray. + (builder := uiBuilder) isNil ifTrue:[ + builder := UIBuilder new isEditing:true. + builder showDefaults:true. + ]. - (specification respondsTo:#buildViewFor:in:) ifFalse:[ - specification := nil. - ^ self - ]. - (builder := uiBuilder) isNil ifTrue:[ - builder := UIBuilder new isEditing:true. - builder showDefaults:true. - ]. + specification buildViewFor:builder in:self. - specification buildViewFor:builder in:self. - + subViews size ~~ 0 ifTrue:[ subViews do:[:v| (self findSpecFor:v) notNil ifTrue:[ - v borderWidth:1. + v borderWidth:1 ] ]. - self shown ifTrue:[ - self realizeAllSubViews. - ] - ] ifFalse:[ - specification := nil - ] + realized ifTrue:[ self realizeAllSubViews ]. + ]. ! ! !UIGalleryView::Canvas methodsFor:'building'! @@ -409,40 +407,34 @@ !UIGalleryView::Canvas methodsFor:'drag & drop'! -startDragFrom:aPoint +startDrag "start drag at a point " - |spec dragObj offset clickPos oldSelect| + |spec dragObj offset clickPos| clickPos := lastClickPoint. clickPos isNil ifTrue:[^ self]. lastClickPoint := nil. - oldSelect := selection. - self selection:(self findObjectAtX:(clickPos x) y:(clickPos y)). - - spec := self findSpecFor:selection. + spec := clientSpecHolder value. spec isNil ifTrue:[^ self]. - oldSelect == selection ifTrue:[ - self hideSelection - ]. + self hideSelection. + dragMode := true. spec := self buildSpecFrom:spec. - spec name:(spec copy userFriendlyName, $1). + spec name:nil. dragObj := DropSpec for:selection specification:spec. offset := clickPos - selection origin. - dragMode ifTrue:[ - DragAndDropManager startDrag:dragObj from:self offset:offset. - ]. + DragAndDropManager startDrag:dragObj from:self offset:offset. ! ! !UIGalleryView::Canvas methodsFor:'event handling'! processEvent:anEvent - |evView x y p| + |evView p| dragMode ifTrue:[ anEvent isButtonReleaseEvent ifTrue:[ @@ -457,59 +449,49 @@ evView isNil ifTrue:[ ^ false ]. evView == self ifFalse:[ - (evView isComponentOf:self) ifFalse:[ - ^ false - ]. + (evView isComponentOf:self) ifFalse:[ ^ false ]. ]. - anEvent isInputEvent ifFalse:[ + anEvent isButtonEvent ifFalse:[ + anEvent isInputEvent ifTrue:[^ true]. anEvent isDamage ifTrue:[ self invalidateSelection ]. ^ false ]. anEvent isButtonReleaseEvent ifTrue:[ - lastClickPoint notNil ifTrue:[ - x := lastClickPoint x. - y := lastClickPoint y. - lastClickPoint := nil. - self selection:(self findObjectAtX:x y:y). - ]. + lastClickPoint := nil. ^ true ]. - anEvent isButtonEvent ifFalse:[^ true]. - - x := anEvent x. - y := anEvent y. - p := device translatePoint:(x@y) fromView:evView toView:self. - x := p x. - y := p y. + anEvent isButtonMotionEvent ifTrue:[ + (lastClickPoint notNil and:[anEvent state ~~ 0]) ifTrue:[ + p := Point x:(anEvent x) y:(anEvent y). - anEvent isButtonPressEvent ifTrue:[ |button application| - button := anEvent button. - x := p x. - y := p y. - - (button == 1 or:[button == #select]) ifTrue:[ - lastClickPoint := p. - ] ifFalse:[ - lastClickPoint := nil. - - (menuSelector notNil and:[(application := self application) notNil]) ifTrue:[ - MessageNotUnderstood catch:[ - application aspectFor:menuSelector - ] + (lastClickPoint dist:p) > 10.0 ifTrue:[ + self startDrag. ] ]. ^ true ]. - anEvent isButtonMotionEvent ifTrue:[ - (lastClickPoint notNil and:[anEvent state ~~ 0]) ifTrue:[ - (lastClickPoint dist:(x@y)) > 10.0 ifTrue:[ - self startDragFrom:(x@y). - "/ self startDragWithOffset:(x@y) - lastClickPoint. - lastClickPoint := nil. + anEvent isButtonPressEvent ifTrue:[ |button application| + button := anEvent button. + lastClickPoint := nil. + + (button == 1 or:[button == #select]) ifTrue:[ + p := Point x:(anEvent x) y:(anEvent y). + p := device translatePoint:p fromView:evView toView:self. + + self selection:(self findObjectAt:p). + + selection notNil ifTrue:[ + lastClickPoint := p + ] + ] ifFalse:[ + (menuSelector notNil and:[(application := self application) notNil]) ifTrue:[ + MessageNotUnderstood catch:[ + application aspectFor:menuSelector + ] ] ]. ^ true @@ -523,9 +505,9 @@ initialize super initialize. - lockSema := RecursionLock new. - dragMode := false. - buttonPressed := false. + dragMode := false. + buttonPressed := false. + clientSpecHolder := nil asValue. ! realize @@ -544,36 +526,32 @@ (self sensor hasEvent:#redrawSelection for:self) ifTrue:[^ self]. - lockSema critical:[ - (buttonPressed or:[selection isNil ]) ifFalse:[ - self clippedByChildren:false. + (buttonPressed or:[selection isNil ]) ifFalse:[ + self clippedByChildren:false. - self handlesOf:selection do:[:aRectangle| - self fillRectangle:aRectangle - ]. - self clippedByChildren:true. + self handlesOf:selection do:[:aRectangle| + self fillRectangle:aRectangle ]. + self clippedByChildren:true. ]. ! ! !UIGalleryView::Canvas methodsFor:'searching'! -findObjectAtX:x y:y +findObjectAt:aPoint "find the origin/corner of the currentWidget " - |point p| + |p x y| subViews size == 0 ifTrue:[^ nil]. - point := Point x:x y:y. subViews do:[:v| - |pX pY| + p := device translatePoint:aPoint fromView:self toView:v. + x := p x. + y := p y. - p := device translatePoint:point fromView:self toView:v. - pX := p x. - pY := p y. - ( pX >= 0 and:[pX <= v width - and:[pY >= 0 and:[pY <= v height + ( x >= 0 and:[x <= v width + and:[y >= 0 and:[y <= v height and:[(self findSpecFor:v) notNil]]]] ) ifTrue:[ ^ v @@ -582,20 +560,18 @@ ^ nil ! -findSpecFor:anObject +findSpecFor:aView "returns subspec assigned to instance or nil " |name| - anObject notNil ifTrue:[ - name := anObject name. + aView notNil ifTrue:[ + name := aView name. specification do:[:aSpec| - aSpec notNil ifTrue:[ - aSpec name = name ifTrue:[ - aSpec canUIDrag ifTrue:[^ aSpec] - ifFalse:[^ nil] - ] + (aSpec notNil and:[aSpec name = name]) ifTrue:[ + aSpec canUIDrag ifTrue:[^ aSpec ]. + ^ nil ] ] ]. @@ -627,44 +603,39 @@ hideSelection "show unselected " - |r currSel| + |r saveSelect| - (currSel := selection) isNil ifTrue:[ + (shown and:[selection notNil]) ifFalse:[ ^ self ]. - shown ifFalse:[^ self]. + saveSelect := selection. + selection := nil. - lockSema critical:[ - selection == currSel ifTrue:[ - selection := nil. + self clippedByChildren:false. - self clippedByChildren:false. + self handlesOf:saveSelect do:[:aRectangle| + self clearRectangle:aRectangle + ]. + self clippedByChildren:true. - self handlesOf:currSel do:[:aRectangle| - self clearRectangle:aRectangle - ]. - self clippedByChildren:true. + r := saveSelect bounds. - r := currSel bounds. - - subViews do:[:sv| - |absOrg absFrame| + subViews do:[:sv| + |absOrg absFrame| - (sv bounds intersects:r) ifTrue:[ - sv borderColor:(Color white). "/ to force a redraw - sv borderColor:(Color black). + (sv bounds intersects:r) ifTrue:[ + sv borderColor:(Color white). "/ to force a redraw + sv borderColor:(Color black). - sv withAllSubViewsDo:[:v| - v realized ifTrue:[ - v fill:v viewBackground. - v exposeX:0 y:0 width:v width height:v height. - ] - ] + sv withAllSubViewsDo:[:v| + v realized ifTrue:[ + v fill:v viewBackground. + v exposeX:0 y:0 width:v width height:v height. ] ] - ]. - selection := currSel. + ] ]. + selection := saveSelect. ! invalidateSelection @@ -675,25 +646,21 @@ ]. ! -selection:anObject +selection:aView "selection changed " |spec| - selection == anObject ifTrue:[^ self]. + selection == aView ifTrue:[^ self]. - lockSema critical:[ - selection == anObject ifFalse:[ - self hideSelection. - spec := self findSpecFor:anObject. + self hideSelection. + spec := self findSpecFor:aView. - spec notNil ifTrue:[ selection := anObject ] - ifFalse:[ selection := nil ]. + spec notNil ifTrue:[ selection := aView ] + ifFalse:[ selection := nil ]. - self invalidateSelection. - clientSpecHolder notNil ifTrue:[ clientSpecHolder value:spec ]. - ] - ]. + clientSpecHolder value:spec. + self invalidateSelection. ! ! !UIGalleryView::Canvas::DropSpec class methodsFor:'instance creation'!