summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2003-07-14 22:10:39 +0000
committerFelipe Heidrich <fheidric>2003-07-14 22:10:39 +0000
commitab71f26fec1a45ce0657bac58c38b33a315f0b0e (patch)
treea6a97e8a31f741ea5411abfe18b688adeb37f2cc
parenta8f238df882329c9d6f40cafabcea0043c35b1a1 (diff)
downloadeclipse.platform.swt-ab71f26fec1a45ce0657bac58c38b33a315f0b0e.tar.gz
eclipse.platform.swt-ab71f26fec1a45ce0657bac58c38b33a315f0b0e.tar.xz
eclipse.platform.swt-ab71f26fec1a45ce0657bac58c38b33a315f0b0e.zip
map API taking Point
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java34
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java32
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java24
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java26
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java136
5 files changed, 227 insertions, 25 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
index 41e113dcc2..df002f24a8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
@@ -1687,6 +1687,40 @@ void postEvent (Event event) {
eventQueue [index] = event;
}
+public Point map (Control from, Control to, Point point) {
+ checkDevice ();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return map (from, to, point.x, point.y);
+}
+
+public Point map (Control from, Control to, int x, int y) {
+ checkDevice ();
+ if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ Point point = new Point (x, y);
+ if (from != null) {
+ Rect rect = new Rect ();
+ OS.GetControlBounds (from.handle, rect);
+ point.x += rect.left;
+ point.y += rect.top;
+ int window = OS.GetControlOwner (from.handle);
+ OS.GetWindowBounds (window, (short) OS.kWindowContentRgn, rect);
+ point.x += rect.left;
+ point.y += rect.top;
+ }
+ if (to != null) {
+ Rect rect = new Rect ();
+ OS.GetControlBounds (to.handle, rect);
+ point.x -= rect.left;
+ point.y -= rect.top;
+ int window = OS.GetControlOwner (to.handle);
+ OS.GetWindowBounds (window, (short) OS.kWindowContentRgn, rect);
+ point.x -= rect.left;
+ point.y -= rect.top;
+ }
+ return point;
+}
+
public Rectangle map (Control from, Control to, Rectangle rectangle) {
checkDevice ();
if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 30303c63aa..8ab3d6aa1d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -1445,6 +1445,38 @@ boolean isValidThread () {
return thread == Thread.currentThread ();
}
+public Point map (Control from, Control to, Point point) {
+ checkDevice ();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return map (from, to, point.x, point.y);
+}
+
+public Point map (Control from, Control to, int x, int y) {
+ checkDevice ();
+ if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ Point point = new Point (x, y);
+ if (from != null) {
+ int eventHandle = from.eventHandle ();
+ OS.gtk_widget_realize (eventHandle);
+ int window = OS.GTK_WIDGET_WINDOW (eventHandle);
+ int [] origin_x = new int [1], origin_y = new int [1];
+ OS.gdk_window_get_origin (window, origin_x, origin_y);
+ point.x += origin_x [0];
+ point.y += origin_y [0];
+ }
+ if (to != null) {
+ int eventHandle = to.eventHandle ();
+ OS.gtk_widget_realize (eventHandle);
+ int window = OS.GTK_WIDGET_WINDOW (eventHandle);
+ int [] origin_x = new int [1], origin_y = new int [1];
+ OS.gdk_window_get_origin (window, origin_x, origin_y);
+ point.x -= origin_x [0];
+ point.y -= origin_y [0];
+ }
+ return point;
+}
+
public Rectangle map (Control from, Control to, Rectangle rectangle) {
checkDevice();
if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
index d399624efe..b352c3a06f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
@@ -1823,6 +1823,30 @@ static boolean isValidClass (Class clazz) {
int index = name.lastIndexOf ('.');
return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
}
+public Point map (Control from, Control to, Point point) {
+ checkDevice ();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return map (from, to, point.x, point.y);
+}
+public Point map (Control from, Control to, int x, int y) {
+ checkDevice ();
+ if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ Point point = new Point (x, y);
+ if (from != null) {
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (from.handle, (short) x, (short) y, root_x, root_y);
+ point.x = root_x [0];
+ point.y = root_y [0];
+ }
+ if (to != null) {
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (to.handle, (short) 0, (short) 0, root_x, root_y);
+ point.x -= root_x [0];
+ point.y -= root_y [0];
+ }
+ return point;
+}
public Rectangle map (Control from, Control to, Rectangle rectangle) {
checkDevice();
if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
index 4cfd17a16c..36ee7e0505 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
@@ -1400,6 +1400,32 @@ static boolean isValidClass (Class clazz) {
return name.substring (0, index + 1).equals (PACKAGE_NAME);
}
+public Point map (Control from, Control to, Point point) {
+ checkDevice ();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return map (from, to, point.x, point.y);
+}
+
+public Point map (Control from, Control to, int x, int y) {
+ checkDevice ();
+ if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ Point point = new Point (x, y);
+ if (from != null) {
+ short [] position_x = new short [1], position_y = new short [1];
+ OS.PtGetAbsPosition (from.handle, position_x, position_y);
+ point.x += position_x [0];
+ point.y += position_y [0];
+ }
+ if (to != null) {
+ short [] position_x = new short [1], position_y = new short [1];
+ OS.PtGetAbsPosition (to.handle, position_x, position_y);
+ point.x -= position_x [0];
+ point.y -= position_y [0];
+ }
+ return point;
+}
+
public Rectangle map (Control from, Control to, Rectangle rectangle) {
checkDevice ();
if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 996e3aeef3..f2524938ba 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -1545,19 +1545,110 @@ boolean isVirtualKey (int key) {
}
/**
- * Maps a rectangle from one coordinate system to another.
- * When the control is null, coordinates are mapped to the
- * display.
+ * Maps a point from one coordinate system to another.
+ * When the control is null, coordinates are mapped to
+ * the display.
* <p>
* NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, this method should always be used
- * to map a rectangle to ensure the resulting rectangle is
- * mirrored.
+ * systems are mirrored, special care needs to be taken
+ * when mapping coordinates from one control to another
+ * to ensure the result is correctly mirrored.
*
* Mapping a point that is the origin of a rectangle and
* then adding the width and height is not equivalent to
- * mapping the entire rectangle because only one the origin
- * is mirrored.
+ * mapping the rectangle. When one control is mirrored
+ * and the other is not, adding the width and height to a
+ * point that was mapped causes the rectangle to extend
+ * in the wrong direction. Mapping the entire rectangle
+ * instead of just one point causes both the origin and
+ * the corner of the rectangle to be mapped.
+ * </p>
+ *
+ * @param from the source <code>Control</code> or <code>null</code>
+ * @param to the destination <code>Control</code> or <code>null</code>
+ * @param point to be mapped
+ * @return point with mapped coordinates
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
+ * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
+ *
+ * @since 3.0
+ */
+public Point map (Control from, Control to, Point point) {
+ checkDevice ();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return map (from, to, point.x, point.y);
+}
+
+/**
+ * Maps a point from one coordinate system to another.
+ * When the control is null, coordinates are mapped to
+ * the display.
+ * <p>
+ * NOTE: On right-to-left platforms where the coordinate
+ * systems are mirrored, special care needs to be taken
+ * when mapping coordinates from one control to another
+ * to ensure the result is correctly mirrored.
+ *
+ * Mapping a point that is the origin of a rectangle and
+ * then adding the width and height is not equivalent to
+ * mapping the rectangle. When one control is mirrored
+ * and the other is not, adding the width and height to a
+ * point that was mapped causes the rectangle to extend
+ * in the wrong direction. Mapping the entire rectangle
+ * instead of just one point causes both the origin and
+ * the corner of the rectangle to be mapped.
+ * </p>
+ *
+ * @param from the source <code>Control</code> or <code>null</code>
+ * @param to the destination <code>Control</code> or <code>null</code>
+ * @param int x coordinates to be mapped
+ * @param int y coordinates to be mapped
+ * @return point with mapped coordinates
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
+ * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
+ *
+ * @since 3.0
+ */
+public Point map (Control from, Control to, int x, int y) {
+ checkDevice ();
+ if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ int hwndFrom = from != null ? from.handle : 0;
+ int hwndTo = to != null ? to.handle : 0;
+ POINT point = new POINT ();
+ point.x = x;
+ point.y = y;
+ OS.MapWindowPoints (hwndFrom, hwndTo, point, 1);
+ return new Point (point.x, point.y);
+}
+
+/**
+ * Maps a point from one coordinate system to another.
+ * When the control is null, coordinates are mapped to
+ * the display.
+ * <p>
+ * NOTE: On right-to-left platforms where the coordinate
+ * systems are mirrored, special care needs to be taken
+ * when mapping coordinates from one control to another
+ * to ensure the result is correctly mirrored.
+ *
+ * Mapping a point that is the origin of a rectangle and
+ * then adding the width and height is not equivalent to
+ * mapping the rectangle. When one control is mirrored
+ * and the other is not, adding the width and height to a
+ * point that was mapped causes the rectangle to extend
+ * in the wrong direction. Mapping the entire rectangle
+ * instead of just one point causes both the origin and
+ * the corner of the rectangle to be mapped.
* </p>
*
* @param from the source <code>Control</code> or <code>null</code>
@@ -1565,7 +1656,6 @@ boolean isVirtualKey (int key) {
* @param rectangle to be mapped
* @return rectangle with mapped coordinates
*
- *
* @exception SWTException <ul>
* <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -1573,9 +1663,6 @@ boolean isVirtualKey (int key) {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
- * @see Control#toDisplay
- * @see Control#toControl
- *
* @since 3.0
*/
public Rectangle map (Control from, Control to, Rectangle rectangle) {
@@ -1585,19 +1672,23 @@ public Rectangle map (Control from, Control to, Rectangle rectangle) {
}
/**
- * Maps a rectangle from one coordinate system to another.
- * When the control is null, coordinates are mapped to the
- * display.
+ * Maps a point from one coordinate system to another.
+ * When the control is null, coordinates are mapped to
+ * the display.
* <p>
* NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, this method should always be used
- * to map a rectangle to ensure the resulting rectangle is
- * mirrored.
+ * systems are mirrored, special care needs to be taken
+ * when mapping coordinates from one control to another
+ * to ensure the result is correctly mirrored.
*
* Mapping a point that is the origin of a rectangle and
* then adding the width and height is not equivalent to
- * mapping the entire rectangle because only one the origin
- * is mirrored.
+ * mapping the rectangle. When one control is mirrored
+ * and the other is not, adding the width and height to a
+ * point that was mapped causes the rectangle to extend
+ * in the wrong direction. Mapping the entire rectangle
+ * instead of just one point causes both the origin and
+ * the corner of the rectangle to be mapped.
* </p>
*
* @param from the source <code>Control</code> or <code>null</code>
@@ -1608,17 +1699,12 @@ public Rectangle map (Control from, Control to, Rectangle rectangle) {
* @param int heigth coordinates to be mapped
* @return rectangle with mapped coordinates
*
- *
* @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
- * @see Control#toDisplay
- * @see Control#toControl
- *
* @since 3.0
*/
public Rectangle map (Control from, Control to, int x, int y, int width, int height) {