diff options
author | Sravan Kumar Lakkimsetti | 2014-08-04 13:16:51 +0000 |
---|---|---|
committer | Arun Thondapu | 2014-08-06 09:55:24 +0000 |
commit | 3d649bface4c6ff0c9af55d005bd7a2726420174 (patch) | |
tree | 3bc9ec1a925d140b49dcf76b7f843988c3810584 | |
parent | 7430285b3a6fae4ee743c775c7760d6dfdd786e8 (diff) | |
download | eclipse.platform.swt-3d649bface4c6ff0c9af55d005bd7a2726420174.tar.gz eclipse.platform.swt-3d649bface4c6ff0c9af55d005bd7a2726420174.tar.xz eclipse.platform.swt-3d649bface4c6ff0c9af55d005bd7a2726420174.zip |
Bug 434772 - Coordinate mapping is inconsistent between platforms
Change-Id: Id089df3b8e081a6743459ccc5bb9136aaa7bf1d8
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
3 files changed, 41 insertions, 49 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 045c011e18..aa42217da2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -5512,4 +5512,19 @@ long /*int*/ windowProc (long /*int*/ handle, long /*int*/ arg0, long /*int*/ us } return super.windowProc (handle, arg0, user_data); } + +/** + * Gets the coordinates for the top left position of the control with respect to parent + * + * @return Coordinates for top left position of the control + */ +Point getWindowOrigin () { + int [] x = new int [1]; + int [] y = new int [1]; + + long /*int*/ window = eventWindow (); + OS.gdk_window_get_origin (window, x, y); + + return new Point (x [0], y [0]); +} } 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 a3cfacf8f2..635a09d412 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 @@ -3044,32 +3044,16 @@ public Point map (Control from, Control to, int x, int y) { Point point = new Point (x, y); if (from == to) return point; if (from != null) { - int [] origin_x = new int [1], origin_y = new int [1]; - boolean fromIsSubshell = from instanceof Shell && from.getParent() != null; - if (fromIsSubshell) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=434772 - OS.gtk_window_get_position (((Shell) from).shellHandle, origin_x, origin_y); - } else { - long /*int*/ window = from.eventWindow (); - OS.gdk_window_get_origin (window, origin_x, origin_y); - if ((from.style & SWT.MIRRORED) != 0) point.x = from.getClientWidth() - point.x; - } - point.x += origin_x [0]; - point.y += origin_y [0]; + Point origin = from.getWindowOrigin (); + if ((from.style & SWT.MIRRORED) != 0) point.x = from.getClientWidth () - point.x; + point.x += origin.x; + point.y += origin.y; } if (to != null) { - int [] origin_x = new int [1], origin_y = new int [1]; - boolean toIsSubshell = to instanceof Shell && to.getParent() != null; - if (toIsSubshell) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=434772 - OS.gtk_window_get_position (((Shell) to).shellHandle, origin_x, origin_y); - } else { - long /*int*/ window = to.eventWindow (); - OS.gdk_window_get_origin (window, origin_x, origin_y); - } - point.x -= origin_x [0]; - point.y -= origin_y [0]; - if (!toIsSubshell) { - if ((to.style & SWT.MIRRORED) != 0) point.x = to.getClientWidth () - point.x; - } + Point origin = to.getWindowOrigin (); + point.x -= origin.x; + point.y -= origin.y; + if ((to.style & SWT.MIRRORED) != 0) point.x = to.getClientWidth () - point.x; } return point; } @@ -3185,32 +3169,16 @@ public Rectangle map (Control from, Control to, int x, int y, int width, int hei if (from == to) return rect; boolean fromRTL = false, toRTL = false; if (from != null) { - int [] origin_x = new int [1], origin_y = new int [1]; - boolean fromIsSubshell = from instanceof Shell && from.getParent() != null; - if (fromIsSubshell) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=434772 - OS.gtk_window_get_position (((Shell) from).shellHandle, origin_x, origin_y); - } else { - long /*int*/ window = from.eventWindow (); - OS.gdk_window_get_origin (window, origin_x, origin_y); - if (fromRTL = (from.style & SWT.MIRRORED) != 0) rect.x = from.getClientWidth() - rect.x; - } - rect.x += origin_x [0]; - rect.y += origin_y [0]; + Point origin = from.getWindowOrigin (); + if (fromRTL = (from.style & SWT.MIRRORED) != 0) rect.x = from.getClientWidth () - rect.x; + rect.x += origin.x; + rect.y += origin.y; } if (to != null) { - int [] origin_x = new int [1], origin_y = new int [1]; - boolean toIsSubshell = to instanceof Shell && to.getParent() != null; - if (toIsSubshell) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=434772 - OS.gtk_window_get_position (((Shell) to).shellHandle, origin_x, origin_y); - } else { - long /*int*/ window = to.eventWindow (); - OS.gdk_window_get_origin (window, origin_x, origin_y); - } - rect.x -= origin_x [0]; - rect.y -= origin_y [0]; - if (!toIsSubshell) { - if (toRTL = (to.style & SWT.MIRRORED) != 0) rect.x = to.getClientWidth () - rect.x; - } + Point origin = to.getWindowOrigin (); + rect.x -= origin.x; + rect.y -= origin.y; + if (toRTL = (to.style & SWT.MIRRORED) != 0) rect.x = to.getClientWidth () - rect.x; } if (fromRTL != toRTL) rect.x -= rect.width; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index bca5915d4d..4ea01677e8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2701,5 +2701,14 @@ void setToolTipText (long /*int*/ rootWidget, long /*int*/ tipWidget, String str } } +@Override +Point getWindowOrigin () { + /* + * Need to overide this since the handle attribute will not be intialized + * if the shell is not made visible. So need to get the location from the shell handle + * getLocation() method in shell will provide us the location of the control + */ + return getLocation(); +} } |