SimpleView.st
branchjv
changeset 6857 a3c37c6169a2
parent 6852 a23f54ff0fd7
parent 6856 36d81d2f7228
child 6865 d68e403297d6
--- a/SimpleView.st	Mon May 04 08:53:56 2015 +0200
+++ b/SimpleView.st	Wed May 06 08:02:55 2015 +0200
@@ -6662,7 +6662,7 @@
 
 simulateButtonPress:button at:aPoint
     "simulate a button press by determining which sub-view is affected and
-     synthetically generating a buttonPressEvent for wjatever view is underneath.
+     synthetically generating a buttonPressEvent for whatever view is underneath.
      Returns the view which precessed the event or nil."
 
     |ev|
@@ -6676,7 +6676,7 @@
 
 simulateButtonRelease:button at:aPoint
     "simulate a button release by determining which sub-view is affected and
-     synthetically generating a buttonPressEvent for wjatever view is underneath.
+     synthetically generating a buttonPressEvent for whatever view is underneath.
      Returns the view which precessed the event or nil."
 
     |ev|
@@ -6688,24 +6688,107 @@
     "Created: / 12-07-2011 / 14:54:37 / cg"
 !
 
+simulateKeyPress:keyOrStringOrSymbol at:aPoint
+    "simulate a key press by determining which sub-view is affected and
+     synthetically generating a keyPressEvent for whatever view is underneath.
+     Returns the view which processed the event or nil."
+
+    |sequence ev lastView|
+
+    (keyOrStringOrSymbol isCharacter or:[keyOrStringOrSymbol isSymbol])
+        ifTrue:[ sequence := Array with:keyOrStringOrSymbol ]
+        ifFalse:[ sequence := keyOrStringOrSymbol ].
+
+    sequence do:[:each |
+        ev := WindowEvent keyPress:each x:0 y:0 view:self.
+        "/ x/y will be set in simulateUserEvent:ev at:aPoint
+        lastView := self simulateUserEvent:ev at:aPoint
+    ].
+    ^ lastView
+!
+
+simulateKeyPressRelease:keyOrStringOrSymbol at:aPoint
+    "simulate a key release by determining which sub-view is affected and
+     synthetically generating a keyPressEvent for whatever view is underneath.
+     Returns the view which processed the event or nil."
+
+    |sequence ev1 ev2 lastView|
+
+    (keyOrStringOrSymbol isCharacter or:[keyOrStringOrSymbol isSymbol])
+        ifTrue:[ sequence := Array with:keyOrStringOrSymbol ]
+        ifFalse:[ sequence := keyOrStringOrSymbol ].
+
+    sequence do:[:each |
+        ev1 := WindowEvent keyPress:each x:0 y:0 view:self.
+        "/ x/y will be set in simulateUserEvent:ev at:aPoint
+        lastView := self simulateUserEvent:ev1 at:aPoint.
+
+        ev2 := WindowEvent keyRelease:each x:0 y:0 view:self.
+        "/ x/y will be set in simulateUserEvent:ev at:aPoint
+        lastView := self simulateUserEvent:ev2 at:aPoint
+    ].
+    ^ lastView
+!
+
+simulateKeyRelease:keyOrStringOrSymbol at:aPoint
+    "simulate a key release by determining which sub-view is affected and
+     synthetically generating a keyPressEvent for whatever view is underneath.
+     Returns the view which processed the event or nil."
+
+    |sequence ev lastView|
+
+    (keyOrStringOrSymbol isCharacter or:[keyOrStringOrSymbol isSymbol])
+        ifTrue:[ sequence := Array with:keyOrStringOrSymbol ]
+        ifFalse:[ sequence := keyOrStringOrSymbol ].
+
+    sequence do:[:each |
+        ev := WindowEvent keyRelease:each x:0 y:0 view:self.
+        "/ x/y will be set in simulateUserEvent:ev at:aPoint
+        lastView := self simulateUserEvent:ev at:aPoint
+    ].
+    ^ lastView
+!
+
 simulateUserEvent:ev at:aPoint
     "simulate a button press by determining which sub-view is affected and
-     synthetically generating a buttonPressEvent for wjatever view is underneath.
+     synthetically generating a buttonPressEvent for whatever view is underneath.
+     Cares for any active grab - i.e. if some other view has grabbed the pointer or keyboard
+     the event is sent to the grabView with pointer coordinate translated as required
+     (typically these are popup views like menus)
      Returns the view which precessed the event or nil."
 
-    ((0@0 corner:self extent) containsPoint:aPoint) ifTrue:[
-	self subViews do:[:each |
-	    |whichView|
-
-	    whichView := each simulateUserEvent:ev at:(self graphicsDevice translatePoint:aPoint fromView:self toView:each).
-	    whichView notNil ifTrue:[^ whichView].
-	].
-	ev x:aPoint x.
-	ev y:aPoint y.
-	ev view:self.
-	self sensor pushEvent:ev.
-	^ self
-    ].
+    |targetView pointXLated|
+
+    (ev isButtonEvent or:[ev isPointerEnterLeaveEvent]) ifTrue:[
+        "/ if there is a pointer grab, the event has to sent to that one
+        targetView := self device activePointerGrab.
+    ] ifFalse:[
+        (ev isKeyEvent) ifTrue:[
+            "/ if there is a pointer grab, the event has to sent to that one
+            targetView := self device activeKeyboardGrab.
+        ].
+    ].
+    targetView isNil ifTrue:[
+        ((0@0 corner:self extent) containsPoint:aPoint) ifTrue:[
+            self subViews do:[:each |
+                |whichView|
+
+                whichView := each simulateUserEvent:ev at:(self graphicsDevice translatePoint:aPoint fromView:self toView:each).
+                whichView notNil ifTrue:[^ whichView].
+            ].
+            targetView := self.
+        ].
+    ].
+
+    targetView notNil ifTrue:[
+        pointXLated := self device translatePoint:aPoint fromView:self toView:targetView.
+        ev x:(pointXLated x).
+        ev y:(pointXLated y).
+        ev view:targetView.
+        targetView sensor pushEvent:ev.
+        ^ targetView
+    ].
+
     ^ nil
 
     "Created: / 12-07-2011 / 14:53:19 / cg"
@@ -8164,7 +8247,7 @@
 !
 
 pixelCorner:corner
-    "set the views corner in pixels"
+    "set the view's corner in pixels"
 
     |w h|
 
@@ -8176,53 +8259,53 @@
 !
 
 pixelExtent:extent
-    "set the views extent in pixels"
+    "set the view's extent in pixels"
 
     self pixelOrigin:(left @ top) extent:extent
 !
 
 pixelOrigin
-    "return the views origin in pixels. For subviews. the origin is relative
-     to the superviews top-left. For topViews, its the screen origin."
+    "return the view's origin in pixels. For subviews. the origin is relative
+     to the superview's top-left. For topViews, it's the screen origin."
 
     ^ self computeOrigin
 !
 
 pixelOrigin:origin
-    "set the views origin in pixels. For subviews. the origin is relative
-     to the superviews top-left. For topViews, its the screen origin."
+    "set the view's origin in pixels. For subviews. the origin is relative
+     to the superview's top-left. For topViews, it's the screen origin."
 
     |newLeft newTop|
 
     newLeft := origin x.
     newTop := origin y.
     ((newTop ~~ top) or:[newLeft ~~ left]) ifTrue:[
-	top := newTop.
-	left := newLeft.
-
-	"
-	 if the receiver is visible, or is a topView, perform the
-	 operation right away - otherwise, simply remember that the
-	 origin has changed - will tell the display once we get realized
-	"
+        top := newTop.
+        left := newLeft.
+
+        "
+         if the receiver is visible, or is a topView, perform the
+         operation right away - otherwise, simply remember that the
+         origin has changed - will tell the display once we get realized
+        "
 "/        (shown
 "/        or:[superView isNil and:[drawableId notNil]]) ifTrue:[
 
-	"/ no, have to do it if drawableId is there
-	"/ (otherwise, we could not move unmapped views around ...
-	"/
-	self drawableId notNil ifTrue:[
-	    self graphicsDevice moveWindow:self drawableId x:left y:top
-	] ifFalse:[
-	    self originChangedFlag:true
-	]
+        "/ no, have to do it if drawableId is there
+        "/ (otherwise, we could not move unmapped views around ...
+        "/
+        self drawableId notNil ifTrue:[
+            self graphicsDevice moveWindow:self drawableId x:left y:top
+        ] ifFalse:[
+            self originChangedFlag:true
+        ]
     ]
 
     "Modified: / 21-01-2011 / 13:59:08 / cg"
 !
 
 pixelOrigin:origin corner:corner
-    "set the views origin and corner in pixels"
+    "set the view's origin and corner in pixels"
 
     |w h|
 
@@ -8234,7 +8317,7 @@
 !
 
 pixelOrigin:origin extent:extent
-    "set the views origin and extent in pixels"
+    "set the view's origin and extent in pixels"
 
     |newLeft newTop newWidth newHeight how
      mustRedrawBottomEdge mustRedrawRightEdge mustRepaintBottom
@@ -8252,16 +8335,16 @@
      a dimension <= 0 ... (although I think that 0 makes sense ...)
     "
     newWidth < 1 ifTrue:[
-	newWidth := 1.
+        newWidth := 1.
     ].
     newHeight < 1 ifTrue:[
-	newHeight := 1
+        newHeight := 1
     ].
 
     ((newWidth == width) and:[newHeight == height]) ifTrue:[
-	sameOrigin ifTrue:[^ self].
-	self changed:#origin.
-	^ self pixelOrigin:origin
+        sameOrigin ifTrue:[^ self].
+        self changed:#origin.
+        ^ self pixelOrigin:origin
     ].
 
     top := newTop.
@@ -8269,142 +8352,142 @@
 
 "/    shown ifTrue:[                  "4-nov-94 actually correct,"
     self drawableId notNil ifTrue:[        "but theres a bug in menus when resized while hidden"
-	mustRedrawBottomEdge := (margin ~~ 0) and:[newHeight < height].
-	mustRedrawRightEdge := (margin ~~ 0) and:[newWidth < width].
-
-	((newHeight <= height) and:[newWidth <= width]) ifTrue:[
-	    how := #smaller
-	] ifFalse:[
-	    ((newHeight >= height) and:[newWidth >= width]) ifTrue:[
-		how := #larger
-	    ]
-	].
-
-	mustRepaintRight := false.
-	mustRepaintBottom := false.
-
-	oldWidth := width.
-	oldHeight := height.
-
-	shown ifTrue:[
-	    (margin ~~ 0) ifTrue:[
-		"clear the old edges"
-
-		oldPaint := nil.
-		newWidth > width ifTrue:[
-		    self clippingRectangle:nil.
-		    oldPaint := self paint.
-		    self paint:viewBackground.
-		    self fillDeviceRectangleX:(width - margin)
-					    y:0
-					width:margin
-				       height:height.
-		    mustRepaintRight := true.
-		].
-		newHeight > height ifTrue:[
-		    self clippingRectangle:nil.
-		    oldPaint := self paint.
-		    self paint:viewBackground.
-		    self fillDeviceRectangleX:0
-					    y:(height - margin)
-					width:width
-				       height:margin.
-		    mustRepaintBottom := true.
-		].
-		oldPaint notNil ifTrue:[ self paint:oldPaint. ]
-	    ]
-	].
-
-	width := newWidth.
-	height := newHeight.
-
-	self setInnerClip.
-
-	"if view becomes smaller, send sizeChanged first"
-	true  "(how == #smaller)" ifTrue:[
-	    self sizeChanged:how
-	].
-
-	"have to tell X, when extent of view is changed"
-	sameOrigin ifTrue:[
-	    self graphicsDevice resizeWindow:self drawableId width:width height:height.
-	] ifFalse:[
-	    "claus: some xservers seem to do better when resizing
-	     first ...."
+        mustRedrawBottomEdge := (margin ~~ 0) and:[newHeight < height].
+        mustRedrawRightEdge := (margin ~~ 0) and:[newWidth < width].
+
+        ((newHeight <= height) and:[newWidth <= width]) ifTrue:[
+            how := #smaller
+        ] ifFalse:[
+            ((newHeight >= height) and:[newWidth >= width]) ifTrue:[
+                how := #larger
+            ]
+        ].
+
+        mustRepaintRight := false.
+        mustRepaintBottom := false.
+
+        oldWidth := width.
+        oldHeight := height.
+
+        shown ifTrue:[
+            (margin ~~ 0) ifTrue:[
+                "clear the old edges"
+
+                oldPaint := nil.
+                newWidth > width ifTrue:[
+                    self clippingRectangle:nil.
+                    oldPaint := self paint.
+                    self paint:viewBackground.
+                    self fillDeviceRectangleX:(width - margin)
+                                            y:0
+                                        width:margin
+                                       height:height.
+                    mustRepaintRight := true.
+                ].
+                newHeight > height ifTrue:[
+                    self clippingRectangle:nil.
+                    oldPaint := self paint.
+                    self paint:viewBackground.
+                    self fillDeviceRectangleX:0
+                                            y:(height - margin)
+                                        width:width
+                                       height:margin.
+                    mustRepaintBottom := true.
+                ].
+                oldPaint notNil ifTrue:[ self paint:oldPaint. ]
+            ]
+        ].
+
+        width := newWidth.
+        height := newHeight.
+
+        self setInnerClip.
+
+        "if view becomes smaller, send sizeChanged first"
+        true  "(how == #smaller)" ifTrue:[
+            self sizeChanged:how
+        ].
+
+        "have to tell X, when extent of view is changed"
+        sameOrigin ifTrue:[
+            self graphicsDevice resizeWindow:self drawableId width:width height:height.
+        ] ifFalse:[
+            "claus: some xservers seem to do better when resizing
+             first ...."
 "
-	    (how == #smaller) ifTrue:[
-		self graphicsDevice resizeWindow:drawableId width:width height:height.
-		self graphicsDevice moveWindow:drawableId x:left y:top
-	    ] ifFalse:[
-		self graphicsDevice moveResizeWindow:drawableId x:left y:top width:width height:height
-	    ].
+            (how == #smaller) ifTrue:[
+                self graphicsDevice resizeWindow:drawableId width:width height:height.
+                self graphicsDevice moveWindow:drawableId x:left y:top
+            ] ifFalse:[
+                self graphicsDevice moveResizeWindow:drawableId x:left y:top width:width height:height
+            ].
 "
-	    self graphicsDevice moveResizeWindow:self drawableId x:left y:top
-					   width:width height:height.
-	].
-
-	"if view becomes bigger, send sizeChanged after"
-	false "(how ~~ #smaller)" ifTrue:[
-	    self sizeChanged:how
-	].
-
-	shown ifTrue:[
-	    (mustRedrawBottomEdge or:[mustRedrawRightEdge]) ifTrue:[
-		border notNil ifTrue:[
-		    mustRedrawBottomEdge ifTrue:[
-			self invalidateDeviceRectangle:((0 @ (height - margin)) extent:width@margin) repairNow:false.
-		    ].
-		    mustRedrawRightEdge ifTrue:[
-			self invalidateDeviceRectangle:(((width - margin) @ 0) extent:margin@height) repairNow:false.
-		    ].
-		] ifFalse:[
-		    self deviceClippingRectangle:nil.
-		    oldPaint := self paint.
-		    mustRedrawBottomEdge ifTrue:[
-			self drawBottomEdge
-		    ].
-		    mustRedrawRightEdge ifTrue:[
-			self drawRightEdge
-		    ].
-		    self paint:oldPaint.
-		    self deviceClippingRectangle:innerClipRect
-		]
-	    ].
-	].
-
-	mustRepaintRight ifTrue:[
-	    self invalidateDeviceRectangle:(((oldWidth - margin) @ 0)
-					   extent:margin@height)
-				 repairNow:false.
+            self graphicsDevice moveResizeWindow:self drawableId x:left y:top
+                                           width:width height:height.
+        ].
+
+        "if view becomes bigger, send sizeChanged after"
+        false "(how ~~ #smaller)" ifTrue:[
+            self sizeChanged:how
+        ].
+
+        shown ifTrue:[
+            (mustRedrawBottomEdge or:[mustRedrawRightEdge]) ifTrue:[
+                border notNil ifTrue:[
+                    mustRedrawBottomEdge ifTrue:[
+                        self invalidateDeviceRectangle:((0 @ (height - margin)) extent:width@margin) repairNow:false.
+                    ].
+                    mustRedrawRightEdge ifTrue:[
+                        self invalidateDeviceRectangle:(((width - margin) @ 0) extent:margin@height) repairNow:false.
+                    ].
+                ] ifFalse:[
+                    self deviceClippingRectangle:nil.
+                    oldPaint := self paint.
+                    mustRedrawBottomEdge ifTrue:[
+                        self drawBottomEdge
+                    ].
+                    mustRedrawRightEdge ifTrue:[
+                        self drawRightEdge
+                    ].
+                    self paint:oldPaint.
+                    self deviceClippingRectangle:innerClipRect
+                ]
+            ].
+        ].
+
+        mustRepaintRight ifTrue:[
+            self invalidateDeviceRectangle:(((oldWidth - margin) @ 0)
+                                           extent:margin@height)
+                                 repairNow:false.
 "/            self redrawDeviceX:(oldWidth - margin)
 "/                             y:0
 "/                         width:margin
 "/                        height:height.
-	].
-	mustRepaintBottom ifTrue:[
-	    self invalidateDeviceRectangle:((0 @ (oldHeight - margin))
-					   extent:width@margin)
-				 repairNow:false.
+        ].
+        mustRepaintBottom ifTrue:[
+            self invalidateDeviceRectangle:((0 @ (oldHeight - margin))
+                                           extent:width@margin)
+                                 repairNow:false.
 "/            self redrawDeviceX:0
 "/                             y:(oldHeight - margin)
 "/                         width:width
 "/                        height:margin.
-	].
+        ].
     ] ifFalse:[
-	"otherwise memorize the need for a sizeChanged message"
-
-	width := newWidth.
-	height := newHeight.
-	sameOrigin ifFalse:[
-	    self originChangedFlag:true.
-	].
-	self extentChangedFlag:true.
-	subViews size > 0 ifTrue:[
-	    self extentChangedBeforeCreatedFlag:true.
-	].
+        "otherwise memorize the need for a sizeChanged message"
+
+        width := newWidth.
+        height := newHeight.
+        sameOrigin ifFalse:[
+            self originChangedFlag:true.
+        ].
+        self extentChangedFlag:true.
+        subViews size > 0 ifTrue:[
+            self extentChangedBeforeCreatedFlag:true.
+        ].
     ].
     sameOrigin ifFalse:[
-	self changed:#origin.
+        self changed:#origin.
     ].
 
     "Modified: / 25.5.1999 / 14:49:56 / cg"
@@ -11389,11 +11472,11 @@
 !SimpleView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.784 2015-05-03 23:18:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.788 2015-05-05 20:59:21 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.784 2015-05-03 23:18:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.788 2015-05-05 20:59:21 cg Exp $'
 
 ! !