added translatePoint methods with view argument (instead of id-arg)
authorClaus Gittinger <cg@exept.de>
Wed, 10 Oct 2001 15:06:38 +0200
changeset 3517 f0e11daf1d3a
parent 3516 6b4bc198c7f1
child 3518 983e7730a905
added translatePoint methods with view argument (instead of id-arg)
DeviceWorkstation.st
--- a/DeviceWorkstation.st	Mon Oct 08 14:45:54 2001 +0200
+++ b/DeviceWorkstation.st	Wed Oct 10 15:06:38 2001 +0200
@@ -1360,33 +1360,75 @@
     "
 !
 
-viewFromPoint:aPoint
+translatePoint:aPoint fromView:window1 toView:window2
+    "given a point in window1, return the coordinate of aPoint in window2.
+     Either window argument may be nil to specify the root window (screen)
+     Use to xlate points from a window to another window (or from a window
+     to the rootwindow), mainly for rubber-line drawing on the displays root window."
+
+    |w1 w2|
+
+    w1 := window1 ? self rootView.
+    w2 := window2 ? self rootView.
+
+    (w1 device == self and:[w2 device == self]) ifFalse:[
+        self error:'Huh - Cross device translation' mayProceed:true.
+        ^ aPoint
+    ].
+
+    ^ self translatePoint:aPoint from:(w1 id) to:(w2 id).
+
+    "Modified: / 10.10.2001 / 14:08:34 / cg"
+!
+
+translatePointFromRoot:aPoint toView:window
+    "given a point as absolute root-window coordinate, return the coordinate within the window.
+     Use to xlate points from the rootWindow to a window."
+
+    ^ self translatePoint:aPoint fromView:nil toView:window
+
+    "Modified: / 10.10.2001 / 14:09:05 / cg"
+!
+
+translatePointToRoot:aPoint fromView:window1
+    "given a point in window1, return the absolute root-window coordinate.
+     Use to xlate points from a window to the rootwindow, 
+     mainly for rubber-line drawing on the displays root window."
+
+    ^ self translatePoint:aPoint fromView:window1 toView:nil
+
+    "Modified: / 10.10.2001 / 14:09:22 / cg"
+!
+
+viewFromPoint:aScreenPoint
     "given a point on the screen, return the ST/X view in which that
-     point is (this may be a subview). Return nil, if its not an ST/X view
-     or if the point is on the background"
+     point is (this may be a subview). 
+     Return nil, if its not an ST/X view or if the point is on the background"
 
     |view id|
 
-    id := self viewIdFromPoint:aPoint.
+    id := self viewIdFromPoint:aScreenPoint.
     view := self viewFromId:id.
     view isNil ifTrue:[
-	"/ search on other devices (if present).
-	"/ This may find the view, in case another device
-	"/ has its views on the same display screen
-	Screen allScreens do:[:aScreen |
-	    |v|
-
-	    aScreen ~~ self ifTrue:[
-		(v := aScreen viewFromId:id) notNil ifTrue:[
-		    ^ v
-		]
-	    ]
-	]
+        "/ search on other devices (if present).
+        "/ This may find the view, in case another device
+        "/ has its views on the same display screen
+        "/ (i.e. under X, if its another display connection to the same
+        "/  X-server)
+        Screen allScreens do:[:aScreen |
+            |v|
+
+            aScreen ~~ self ifTrue:[
+                (v := aScreen viewFromId:id) notNil ifTrue:[
+                    ^ v
+                ]
+            ]
+        ]
     ].
     ^ view
 !
 
-viewIdFromPoint:aPoint
+viewIdFromPoint:aScreenPoint
     "given a point on the screen, return the id of the ST/X view in which that
      point is (this may be a subview). Return nil, if its not an ST/X view
      or if the point is on the background"
@@ -1409,7 +1451,7 @@
                 ^ nil
             ].
             foundId := searchId.
-            searchId := self viewIdFromPoint:aPoint in:searchId.
+            searchId := self viewIdFromPoint:aScreenPoint in:searchId.
         ]
     ].
     ^ foundId
@@ -1427,13 +1469,13 @@
     ^ nil
 !
 
-windowAt:aPoint
+windowAt:aScreenPoint
     "given a point on the screen, return the ST/X topview in which that
      point is. 
      Return nil, if its not an ST/X view or if the point is on the background.
-     Alias for viewFromPoint: - ST-80 compatibility"
-
-    ^ self viewFromPoint:aPoint
+     Alias for viewFromPoint: for ST-80 compatibility"
+
+    ^ self viewFromPoint:aScreenPoint
 ! !
 
 !DeviceWorkstation methodsFor:'accessing-display attributes'!
@@ -7342,6 +7384,6 @@
 !DeviceWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.402 2001-09-28 07:08:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.403 2001-10-10 13:06:38 cg Exp $'
 ! !
 DeviceWorkstation initialize!