diff -r 72af7609bb08 -r 493e0430518e UIGalleryView.st --- a/UIGalleryView.st Thu Jan 09 09:21:55 2003 +0100 +++ b/UIGalleryView.st Fri Jan 17 15:50:44 2003 +0100 @@ -22,8 +22,8 @@ ! View subclass:#Canvas - instanceVariableNames:'dragMode clientSpecHolder inputView selection specification - lastClickPoint menuSelector raiseMenuSelector uiBuilder' + instanceVariableNames:'lockSema dragMode clientSpecHolder selection specification + lastClickPoint menuSelector uiBuilder buttonPressed' classVariableNames:'' poolDictionaries:'' privateIn:UIGalleryView @@ -334,10 +334,8 @@ self selection:nil. - subViews copy do:[:aSubView| - aSubView ~~ inputView ifTrue:[ - aSubView destroy - ] + subViews size ~~ 0 ifTrue:[ + subViews copy do:[:aSubView| aSubView destroy ]. ]. aSpecOrSpecArray notNil ifTrue:[ @@ -345,7 +343,7 @@ (specification respondsTo:#buildViewFor:in:) ifFalse:[ specification := nil. - ^ self + ^ self ]. (builder := uiBuilder) isNil ifTrue:[ builder := UIBuilder new isEditing:true. @@ -355,13 +353,12 @@ specification buildViewFor:builder in:self. subViews do:[:v| - (v ~~ inputView and:[(self findSpecFor:v) notNil]) ifTrue:[ + (self findSpecFor:v) notNil ifTrue:[ v borderWidth:1. ] ]. self shown ifTrue:[ self realizeAllSubViews. - inputView raise ] ] ifFalse:[ specification := nil @@ -412,102 +409,107 @@ !UIGalleryView::Canvas methodsFor:'drag & drop'! -startDrag - "start drag of selection +startDragFrom:aPoint + "start drag at a point " - |dragObj spec name| + |spec dragObj offset clickPos| + + clickPos := lastClickPoint. + clickPos isNil ifTrue:[^ self]. + lastClickPoint := nil. + + self selection:(self findObjectAtX:(clickPos x) y:(clickPos y)). spec := self findSpecFor:selection. + spec isNil ifTrue:[^ self]. - spec notNil ifTrue:[ - spec := self buildSpecFrom:spec. - name := spec className asString. - name := name copyFrom:1 to:(name size - ('Spec' size) + 1). - name at:1 put:(name at:1) asLowercase. - name at:(name size) put:$1. - spec name:name. - - self showUnselected. - dragObj := DropSpec for:selection specification:spec. - "/ self showSelected. - DragAndDropManager startDrag:dragObj from:inputView. - ] - -! + dragMode := true. + spec := self buildSpecFrom:spec. + spec name:(spec copy userFriendlyName, $1). -startDragWithOffset:offs - "start drag of selection - " - |dragObj spec o| - - spec := self findSpecFor:selection. - - spec notNil ifTrue:[ - spec := self buildSpecFrom:spec. - spec name:(spec copy userFriendlyName, $1). + dragObj := DropSpec for:selection specification:spec. + offset := clickPos - selection origin. - self showUnselected. - dragObj := DropSpec for:selection specification:spec. - "/ self showSelected. - - o := lastClickPoint - selection origin. - - DragAndDropManager - startDrag:dragObj - from:inputView - offset:o. - ] - - "Created: 11.8.1997 / 00:44:17 / cg" - "Modified: 11.8.1997 / 00:48:35 / cg" + dragMode ifTrue:[ + DragAndDropManager startDrag:dragObj from:self offset:offset. + ]. ! ! !UIGalleryView::Canvas methodsFor:'event handling'! -buttonMotion:state x:x y:y - "start a drag on selection - " - |sensor| +processEvent:anEvent + |evView x y p| - (state ~~ 0 and:[lastClickPoint notNil and:[selection notNil]]) ifTrue:[ - sensor := self sensor. - sensor anyButtonPressed ifTrue:[ - (lastClickPoint dist:(x@y)) > 10.0 ifTrue:[ - ^ self startDragWithOffset:(x@y) - lastClickPoint - ] - ] - ] -! + dragMode ifTrue:[ + anEvent isButtonReleaseEvent ifTrue:[ + dragMode := false. + lastClickPoint := nil. + self invalidateSelection. + ]. + ^ false + ]. -buttonPress:button x:x y:y - "change selection - " - |application| + evView := anEvent view. + evView isNil ifTrue:[ ^ false ]. - (button == 1 or:[button == #select]) ifTrue:[ - lastClickPoint := Point x:x y:y. - self selection:(self findObjectAtX:x y:y). - ] ifFalse:[ - lastClickPoint := nil. + evView == self ifFalse:[ + (evView isComponentOf:self) ifFalse:[ + ^ false + ]. + ]. - (menuSelector notNil and:[(application := self application) notNil]) ifTrue:[ - MessageNotUnderstood catch:[ - application aspectFor:menuSelector - ] - ] - ] -! + anEvent isInputEvent ifFalse:[ + anEvent isDamage ifTrue:[ self invalidateSelection ]. + ^ false + ]. -exposeX:x y:y width:w height:h - "handle an expose event from device; redraw selection - " - super exposeX:x y:y width:w height:h. - - (selection notNil and:[self sensor hasExposeEventFor:selection]) ifFalse:[ - self showSelected. + anEvent isButtonReleaseEvent ifTrue:[ + lastClickPoint notNil ifTrue:[ + x := lastClickPoint x. + y := lastClickPoint y. + lastClickPoint := nil. + self selection:(self findObjectAtX:x y:y). + ]. + ^ true ]. + anEvent isButtonEvent ifFalse:[^ true]. + x := anEvent x. + y := anEvent y. + p := device translatePoint:(x@y) fromView:evView toView:self. + + 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 + ] + ] + ]. + ^ 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. + ] + ]. + ^ true + ]. + + ^ true ! ! !UIGalleryView::Canvas methodsFor:'initialization'! @@ -515,18 +517,37 @@ initialize super initialize. - inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self. - inputView eventReceiver:self. - inputView enableButtonEvents. - inputView enableButtonMotionEvents. - inputView enableMotionEvents. - - "Modified: / 20.7.1998 / 18:12:38 / cg" + lockSema := RecursionLock new. + dragMode := false. + buttonPressed := false. ! -mapped - super mapped. - inputView raise. +realize + super realize. + self windowGroup addPreEventHook:self. +! ! + +!UIGalleryView::Canvas methodsFor:'private'! + +redrawSelection + "redraw all items selected + " + (buttonPressed or:[selection isNil or:[shown not]]) ifTrue:[ + ^ self + ]. + + (self sensor hasEvent:#redrawSelection for:self) ifTrue:[^ self]. + + lockSema critical:[ + (buttonPressed or:[selection isNil ]) ifFalse:[ + self clippedByChildren:false. + + self handlesOf:selection do:[:aRectangle| + self fillRectangle:aRectangle + ]. + self clippedByChildren:true. + ]. + ]. ! ! !UIGalleryView::Canvas methodsFor:'searching'! @@ -541,21 +562,17 @@ subViews do:[:v| |pX pY| - v ~~ inputView ifTrue:[ - p := device translatePoint:point fromView:inputView toView:v. - pX := p x. - pY := p y. - ( pX >= 0 and:[pX <= v width - and:[pY >= 0 and:[pY <= v height - and:[(self findSpecFor:v) notNil]]]] - ) ifTrue:[ - ^ v - ] + 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 + and:[(self findSpecFor:v) notNil]]]] + ) ifTrue:[ + ^ v ] ]. - ^ nil - - "Modified: / 10.10.2001 / 14:02:08 / cg" + ^ nil ! findSpecFor:anObject @@ -600,47 +617,7 @@ ! -selection:anObject - "selection changed - " - |spec| - - selection ~~ anObject ifTrue:[ - self showUnselected. - spec := self findSpecFor:anObject. - - spec notNil ifTrue:[ - selection := anObject. - self showSelected - ] ifFalse:[ - selection := nil - ]. - clientSpecHolder notNil ifTrue:[ - clientSpecHolder value:spec - ] - ] - - -! - -showSelected - "show selected - " - shown ifFalse:[^ self]. - - selection notNil ifTrue:[ - self clippedByChildren:false. - - self handlesOf:selection do:[:aRectangle| - self fillRectangle:aRectangle - ]. - self clippedByChildren:true. - ]. - - -! - -showUnselected +hideSelection "show unselected " |r currSel| @@ -649,36 +626,67 @@ ^ self ]. shown ifFalse:[^ self]. - selection := nil. - self clippedByChildren:false. + lockSema critical:[ + selection == currSel ifTrue:[ + selection := nil. - self handlesOf:currSel do:[:aRectangle| - self clearRectangle:aRectangle - ]. - self clippedByChildren:true. - r := currSel bounds. + self clippedByChildren:false. + + self handlesOf:currSel do:[:aRectangle| + self clearRectangle:aRectangle + ]. + self clippedByChildren:true. - subViews do:[:sv| - |absOrg absFrame| + r := currSel bounds. + + subViews do:[:sv| + |absOrg absFrame| - sv ~~ inputView ifTrue:[ - (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. + ]. +! + +invalidateSelection + "show selected + " + (shown and:[selection notNil and:[buttonPressed not]]) ifTrue:[ + self sensor pushUserEvent:#redrawSelection for:self withArguments:nil. + ]. +! + +selection:anObject + "selection changed + " + |spec| + + selection == anObject ifTrue:[^ self]. + + lockSema critical:[ + selection == anObject ifFalse:[ + self hideSelection. + spec := self findSpecFor:anObject. + + spec notNil ifTrue:[ selection := anObject ] + ifFalse:[ selection := nil ]. + + self invalidateSelection. + clientSpecHolder notNil ifTrue:[ clientSpecHolder value:spec ]. ] ]. - selection := currSel. - - "Modified: / 9.11.1998 / 12:49:57 / cg" ! ! !UIGalleryView::Canvas::DropSpec class methodsFor:'instance creation'!