Bug 434772 - Coordinate mapping is inconsistent between platforms

Change-Id: Id089df3b8e081a6743459ccc5bb9136aaa7bf1d8
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
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 fafbdbd..c0aaffb 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 @@
 	}
 	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 24d2d34..d4d76ca 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
@@ -3046,32 +3046,16 @@
 	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;
 }
@@ -3187,32 +3171,16 @@
 	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 b5f235d..947e67c 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 @@
 	}
 		
 }
+@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();
+}
 }