UIGalleryView.st
changeset 2495 ead2b25a2c63
parent 2359 d3f8b2492371
child 2502 c27a926cbe67
--- a/UIGalleryView.st	Fri May 08 13:52:41 2009 +0200
+++ b/UIGalleryView.st	Fri May 08 13:53:41 2009 +0200
@@ -291,6 +291,17 @@
     super release.
 ! !
 
+!UIGalleryView::Canvas class methodsFor:'documentation'!
+
+documentation
+"
+    I am the canvas of a gallery. Most of what I do is to allow dragging of widget out
+    of myself and to care for the drawing of the selection.
+    The arrangement into multiple pages is done by my container, which holds me
+    in a subcanvas.
+"
+! !
+
 !UIGalleryView::Canvas methodsFor:'accessing'!
 
 builder
@@ -388,50 +399,46 @@
 !UIGalleryView::Canvas methodsFor:'building'!
 
 buildSpecFrom:aSpec
-    "build spec out of spec
-    "
+    "build spec out of spec"
+
     |spec comp coll|
 
     (aSpec notNil and:[aSpec canUIDrag]) ifFalse:[
-	^ nil
+        ^ nil
     ].
 
     spec := aSpec copy.
 
     (aSpec class supportsSubComponents and:[aSpec component notNil]) ifFalse:[
-	^ spec
+        ^ spec
     ].
     comp := aSpec component.
     spec component:nil.
 
     comp canUIDrag ifFalse:[
-      ^ spec
+        ^ spec
     ].
     coll := OrderedCollection new.
 
     comp do:[:anEntry||spc|
-	(spc := self buildSpecFrom:anEntry) notNil ifTrue:[
-	    coll add:spc
-	]
+        (spc := self buildSpecFrom:anEntry) notNil ifTrue:[
+            coll add:spc
+        ]
     ].
     coll isEmpty ifTrue:[
-      ^ spec
+        ^ spec
     ].
     comp := comp copy.
     comp collection:coll.
     spec component:comp.
-  ^ spec
-
-
-
-
+    ^ spec
 ! !
 
 !UIGalleryView::Canvas methodsFor:'drag & drop'!
 
 startDragFrom:evView
-    "start drag at a point
-    "
+    "start drag at lastClickPoint"
+
     |spec dragObj offset clickPos dragAndDropManager|
 
     clickPos := lastClickPoint.
@@ -441,7 +448,7 @@
     spec := clientSpecHolder value.
     spec isNil ifTrue:[^ self].
 
-    self selectionHiddenDo:[
+    self withSelectionHiddenDo:[
         spec := self buildSpecFrom:spec.
         spec name:nil.
 
@@ -452,11 +459,12 @@
     dragAndDropManager := DragAndDropManager new.
     dragAndDropManager giveFocusToTargetWidget:false.
 
-    dragAndDropManager startDrag:dragObj
-                 from:self
-               offset:offset
-                atEnd:nil
-              display:nil.
+    dragAndDropManager 
+        startDrag:dragObj
+        from:self
+        offset:offset
+        atEnd:nil
+        display:nil.
 ! !
 
 !UIGalleryView::Canvas methodsFor:'event handling'!
@@ -499,7 +507,9 @@
         ^ true
     ].
 
-    anEvent isButtonPressEvent ifTrue:[ |button application|
+    anEvent isButtonPressEvent ifTrue:[
+        |button application|
+
         button := anEvent button.
 
         (button == 1 or:[button == #select]) ifTrue:[
@@ -564,32 +574,34 @@
 !UIGalleryView::Canvas methodsFor:'searching'!
 
 findObjectAt:aPoint
-    |p x y|
+    |seeIfWidgetIsHit p x y|
 
-    subViews size == 0 ifTrue:[^ nil].
+    seeIfWidgetIsHit := 
+        [:v |
+            p := device translatePoint:aPoint fromView:self toView:v.
+            x := p x.
+            y := p y.
 
-    subViews do:[:v|
-        p := device translatePoint:aPoint fromView:self toView:v.
-        x := p x.
-        y := p y.
+            (     x >= 0 and:[x <= v width
+             and:[y >= 0 and:[y <= v height
+             and:[(self findSpecFor:v) notNil]]]]
+            ) ifTrue:[
+                ^ v
+            ]
+        ].
 
-        (     x >= 0 and:[x <= v width
-         and:[y >= 0 and:[y <= v height
-         and:[(self findSpecFor:v) notNil]]]]
-        ) ifTrue:[
-            ^ v
-        ]
-    ].
+    subViews notNil ifTrue:[ subViews do:seeIfWidgetIsHit ].
+    components notNil ifTrue:[ components do:seeIfWidgetIsHit ].
     ^ nil
 !
 
-findSpecFor:aView
-    "returns subspec assigned to instance or nil
-    "
+findSpecFor:aWidget
+    "returns the spec which is assigned to aWidget or nil"
+
     |name|
 
-    aView notNil ifTrue:[
-        name := aView name.
+    aWidget notNil ifTrue:[
+        name := aWidget name.
 
         specification do:[:aSpec|
             (aSpec notNil and:[aSpec name = name]) ifTrue:[
@@ -624,8 +636,8 @@
 !
 
 redrawSelection
-    "redraw all items selected
-    "
+    "redraw all items selected"
+
     (shown and:[selection notNil and:[hiddenCounter == 0]]) ifTrue:[
         self clippedByChildren:false.
 
@@ -637,57 +649,58 @@
 !
 
 selection:aView
-    "selection changed
-    "
+    "selection changed"
+
     |spec|
 
     selection == aView ifTrue:[^ self].
 
-    self selectionHiddenDo:[
+    self withSelectionHiddenDo:[
         spec := self findSpecFor:aView.
-
-        spec notNil ifTrue:[ selection := aView ]
-                   ifFalse:[ selection := nil ].
-
+        selection := (spec isNil) ifTrue:[nil] ifFalse:[aView].
         clientSpecHolder value:spec.
     ].
 !
 
-selectionHiddenDo:aOneArgBlock
+withSelectionHiddenDo:aOneArgBlock
     |r|
 
-    [   hiddenCounter :=  hiddenCounter + 1.
-
+    [   
+        hiddenCounter :=  hiddenCounter + 1.
         hiddenCounter == 1 ifTrue:[
             (shown and:[selection notNil]) ifTrue:[
                 self clippedByChildren:false.
 
                 self handlesOf:selection do:[:aRectangle|
-                    self clearRectangle:aRectangle
+                    self clearRectangle:aRectangle.
+                    self invalidateRectangle:aRectangle repairNow:false.
                 ].
                 self clippedByChildren:true.
 
                 r := selection bounds.
-
-                subViews do:[:sv|
-                    |absOrg absFrame|
+                subViews notNil ifTrue:[
+                    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.
+                                ]
                             ]
                         ]
                     ]
-                ]
+                ].
             ].
         ].
         aOneArgBlock value.
     ] ensure:[
+        self repairDamage.  "/ ensure that any outstanding clear/redraw of the unselect are done before
+
         hiddenCounter := hiddenCounter - 1.
         self redrawSelection.
     ].
@@ -695,24 +708,29 @@
 
 !UIGalleryView::Canvas::DropSpec class methodsFor:'instance creation'!
 
-for:aView specification:aSpec
-    "create drop object for a view derived from a specification
-    "
-    |point extent rootView device inst displayObject|
+for:aWidget specification:aSpec
+    "create drop object for a widget derived from a specification"
+
+    |point extent rootView device inst displayObject view|
 
-    device   := aView device.
+    device   := aWidget device.
     rootView := device rootView.
-    extent   := aView extent.
-    point    := device translatePoint:0@0 fromView:aView toView:rootView.
-
+    extent   := aWidget extent.
+    aWidget isView ifTrue:[
+        view := aWidget.
+        point := device translatePoint:0@0 fromView:aWidget toView:rootView.
+    ] ifFalse:[
+        view := aWidget container.
+        point := device translatePoint:(aWidget origin) fromView:view toView:rootView.
+    ].
     (point x > 0 and:[point y > 0]) ifTrue:[
         point := point + extent.
         (point x < rootView width and:[point y < rootView height]) ifTrue:[
-            aView topView raise.
+            aWidget topView raise.
             device flush.
-            aView invalidate.
-            aView windowGroup processExposeEvents.
-            displayObject := Image fromView:aView grab:false.
+            aWidget invalidate.
+            aWidget windowGroup processExposeEvents.
+            displayObject := Image fromView:aWidget grab:false.
         ]
     ].
     displayObject isNil ifTrue:[
@@ -720,7 +738,7 @@
         displayObject colorMap:(Array with:Color white with:Color black).
         displayObject fill:(Color colorId:0).
         displayObject paint:(Color colorId:1).
-        displayObject displayRectangleX:0 y:0 width:aView extent x height:aView extent y.
+        displayObject displayRectangleX:0 y:0 width:aWidget extent x height:aWidget extent y.
     ].
     aSpec class == UISubSpecification ifTrue:[
         aSpec layout:(LayoutOrigin fromPoint:0@0)
@@ -729,7 +747,7 @@
     inst := self new.
     inst displayObject:displayObject.
     inst theObject:aSpec.
-  ^ inst.
+    ^ inst.
 
     "Modified: / 10.10.2001 / 14:03:00 / cg"
 ! !