diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index 9c1f6c9e5c..7183cf6ec5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -3969,8 +3969,9 @@ void subclass () { */ public Point toControl (int x, int y) { checkWidget (); - int zoom = getZoom(); - return DPIUtil.scaleDown(toControlInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom); + Point displayPointInPixels = getDisplay().getLocationInPixelsInDisplayCoordinateSystem(x, y); + final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y); + return DPIUtil.scaleDown(controlPointInPixels, getZoom()); } Point toControlInPixels (int x, int y) { @@ -4003,9 +4004,9 @@ Point toControlInPixels (int x, int y) { public Point toControl (Point point) { checkWidget (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - int zoom = getZoom(); - point = DPIUtil.scaleUp(point, zoom); - return DPIUtil.scaleDown(toControlInPixels(point.x, point.y), zoom); + point = getDisplay().getLocationInPixelsInDisplayCoordinateSystem(point.x, point.y); + final Point controlInPixels = toControlInPixels(point.x, point.y); + return DPIUtil.scaleDown(controlInPixels, getZoom()); } /** @@ -4031,7 +4032,8 @@ public Point toControl (Point point) { public Point toDisplay (int x, int y) { checkWidget (); int zoom = getZoom(); - return DPIUtil.scaleDown(toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom); + Point displayPointInPixels = toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)); + return getDisplay().getLocationInPointInDisplayCoordinateSystem(displayPointInPixels); } Point toDisplayInPixels (int x, int y) { @@ -4066,7 +4068,8 @@ public Point toDisplay (Point point) { if (point == null) error (SWT.ERROR_NULL_ARGUMENT); int zoom = getZoom(); point = DPIUtil.scaleUp(point, zoom); - return DPIUtil.scaleDown(toDisplayInPixels(point.x, point.y), zoom); + Point displayPointInPixels = toDisplayInPixels(point.x, point.y); + return getDisplay().getLocationInPointInDisplayCoordinateSystem(displayPointInPixels); } long topHandle () { 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 98b397797d..e3d75b7b24 100644 --- 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 @@ -1691,8 +1691,8 @@ public Control getCursorControl () { */ public Point getCursorLocation () { checkDevice (); - Point pt = getCursorLocationInPixels(); - return getLocationInPointWithMonitorOffset(pt.x, pt.y); + Point cursorLocationInPixels = getCursorLocationInPixels(); + return getLocationInPointInDisplayCoordinateSystem(cursorLocationInPixels.x, cursorLocationInPixels.y); } Point getCursorLocationInPixels () { @@ -1701,15 +1701,23 @@ Point getCursorLocationInPixels () { return new Point (pt.x, pt.y); } -Point getLocationInPixelsWithMonitorOffset(int x, int y) { +Point getLocationInPixelsInDisplayCoordinateSystem(Point point) { + return getLocationInPixelsInDisplayCoordinateSystem(point.x, point.y); +} + +Point getLocationInPixelsInDisplayCoordinateSystem(int x, int y) { Monitor monitor = getContainingMonitor(x, y); int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); - x = DPIUtil.autoScaleUp(x - monitor.clientX, zoom) + monitor.clientX; - y = DPIUtil.autoScaleUp(y - monitor.clientY, zoom) + monitor.clientY; + x = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX; + y = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY; return new Point(x, y); } -Point getLocationInPointWithMonitorOffset(int x, int y) { +Point getLocationInPointInDisplayCoordinateSystem(Point point) { + return getLocationInPointInDisplayCoordinateSystem(point.x, point.y); +} + +Point getLocationInPointInDisplayCoordinateSystem(int x, int y) { Monitor monitor = getContainingMonitorInPixelsCoordiate(x, y); int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); x = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX; @@ -2204,8 +2212,8 @@ Monitor getMonitor (long hmonitor) { System.err.println("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor."); result = 100; } - monitor.setBounds(getBoundsInPointsWithMonitorOffset(boundsInPixels, autoscaleZoom)); - monitor.setClientArea(getBoundsInPointsWithMonitorOffset(clientAreaInPixels, autoscaleZoom)); + monitor.setBounds(getMonitorBoundsInPointsInDisplayCoordinateSystem(boundsInPixels, autoscaleZoom)); + monitor.setClientArea(getMonitorBoundsInPointsInDisplayCoordinateSystem(clientAreaInPixels, autoscaleZoom)); /* * Always return true monitor zoom value as fetched from native, else will lead * to scaling issue on OS Win8.1 and above, for more details refer bug 537614. @@ -2214,7 +2222,7 @@ Monitor getMonitor (long hmonitor) { return monitor; } -private Rectangle getBoundsInPointsWithMonitorOffset(Rectangle boundsInPixels, int zoom) { +private Rectangle getMonitorBoundsInPointsInDisplayCoordinateSystem(Rectangle boundsInPixels, int zoom) { Rectangle bounds = DPIUtil.scaleDown(boundsInPixels, zoom); bounds.x = boundsInPixels.x; bounds.y = boundsInPixels.y; @@ -3000,9 +3008,7 @@ boolean isValidThread () { public Point map (Control from, Control to, Point point) { checkDevice (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - int zoom = getZoomLevelForMapping(from, to); - point = DPIUtil.scaleUp(point, zoom); - return DPIUtil.scaleDown(mapInPixels(from, to, point), zoom); + return map(from, to, point.x, point.y); } Point mapInPixels (Control from, Control to, Point point) { @@ -3047,10 +3053,18 @@ Point mapInPixels (Control from, Control to, Point point) { */ public Point map (Control from, Control to, int x, int y) { checkDevice (); - int zoom = getZoomLevelForMapping(from, to); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - return DPIUtil.scaleDown(mapInPixels(from, to, x, y), zoom); + Point mappedPointInPoints; + if (from == null) { + Point mappedPointInpixels = mapInPixels(from, to, getLocationInPixelsInDisplayCoordinateSystem(x, y)); + mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom()); + } else if (to == null) { + Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom())); + mappedPointInPoints = getLocationInPointInDisplayCoordinateSystem(mappedPointInpixels); + } else { + Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom())); + mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom()); + } + return mappedPointInPoints; } Point mapInPixels (Control from, Control to, int x, int y) { @@ -3114,9 +3128,25 @@ private int getZoomLevelForMapping(Control from, Control to) { public Rectangle map (Control from, Control to, Rectangle rectangle) { checkDevice (); if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT); - int zoom = getZoomLevelForMapping(from, to); - rectangle = DPIUtil.scaleUp(rectangle, zoom); - return DPIUtil.scaleDown(mapInPixels(from, to, rectangle), zoom); + return map(from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); +} + +private Rectangle getRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height) { + Point topLeft = getLocationInPixelsInDisplayCoordinateSystem(x, y); + Monitor monitor = getContainingMonitor(x, y); + int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); + int widthInPixels = DPIUtil.scaleUp(width, zoom); + int heightInPixels = DPIUtil.scaleUp(height, zoom); + return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels); +} + +private Rectangle getRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels) { + Point topLeft = getLocationInPointInDisplayCoordinateSystem(x, y); + Monitor monitor = getContainingMonitorInPixelsCoordiate(x, y); + int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); + int width = DPIUtil.scaleDown(widthInPixels, zoom); + int height = DPIUtil.scaleDown(heightInPixels, zoom); + return new Rectangle(topLeft.x, topLeft.y, width, height); } Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) { @@ -3163,12 +3193,18 @@ Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) { */ public Rectangle map (Control from, Control to, int x, int y, int width, int height) { checkDevice (); - int zoom = getZoomLevelForMapping(from, to); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - width = DPIUtil.scaleUp(width, zoom); - height = DPIUtil.scaleUp(height, zoom); - return DPIUtil.scaleDown(mapInPixels(from, to, x, y, width, height), zoom); + Rectangle mappedRectangleInPoints; + if (from == null) { + Rectangle mappedRectangleInPixels = mapInPixels(from, to, getRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height)); + mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom()); + } else if (to == null) { + Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom())); + mappedRectangleInPoints = getRectangleInPointsInDisplayCoordinateSystem(mappedRectangleInPixels.x, mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height); + } else { + Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom())); + mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom()); + } + return mappedRectangleInPoints; } Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int height) { @@ -4411,7 +4447,8 @@ public void sendPostExternalEventDispatchEvent () { */ public void setCursorLocation (int x, int y) { checkDevice (); - setCursorLocationInPixels (DPIUtil.autoScaleUp (x), DPIUtil.autoScaleUp (y)); + Point cursorLocationInPixels = getLocationInPixelsInDisplayCoordinateSystem(x, y); + setCursorLocationInPixels (cursorLocationInPixels.x, cursorLocationInPixels.y); } void setCursorLocationInPixels (int x, int y) { @@ -5339,10 +5376,10 @@ private void setProperDPIAwareness() { Monitor getContainingMonitor(int x, int y) { Monitor[] monitors = getMonitors(); - for (Monitor current : monitors) { - Rectangle clientArea = current.getClientArea(); + for (Monitor currentMonitor : monitors) { + Rectangle clientArea = currentMonitor.getClientArea(); if (clientArea.contains(x, y)) { - return current; + return currentMonitor; } } return getPrimaryMonitor(); @@ -5351,7 +5388,7 @@ Monitor getContainingMonitor(int x, int y) { Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels) { Monitor[] monitors = getMonitors(); for (Monitor current : monitors) { - Rectangle clientArea = DPIUtil.autoScaleUp(current.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(current.zoom)); + Rectangle clientArea = DPIUtil.scaleUp(current.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(current.zoom)); clientArea.x = current.clientX; clientArea.y = current.clientY; if (clientArea.contains(xInPixels, yInPixels)) { @@ -5360,5 +5397,4 @@ Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels) { } return getPrimaryMonitor(); } - } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index 243b4e4d60..61aeaf88be 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1571,19 +1571,11 @@ public void setAlpha (int alpha) { } } -private void updateNativeZoomBeforePositionChange(int x, int y) { - if (DPIUtil.isAutoScaleOnRuntimeActive()) { - Monitor monitor = display.getContainingMonitor(x, y); - this.nativeZoom = monitor.zoom; - System.out.println("Update shell zoom (" + handle + ") " + monitor.zoom); - } -} - @Override public Rectangle getBounds() { Rectangle boundsInPixels = getBoundsInPixels (); Rectangle bounds = DPIUtil.scaleDown(boundsInPixels, getZoom()); - Point pointWithMonitorOffset = display.getLocationInPointWithMonitorOffset(boundsInPixels.x, boundsInPixels.y); + Point pointWithMonitorOffset = display.getLocationInPointInDisplayCoordinateSystem(boundsInPixels.x, boundsInPixels.y); bounds.x = pointWithMonitorOffset.x; bounds.y = pointWithMonitorOffset.y; return bounds; @@ -1592,48 +1584,35 @@ public Rectangle getBounds() { @Override public Point getLocation() { Point locationInPixels = getLocationInPixels(); - Point location = display.getLocationInPointWithMonitorOffset(locationInPixels.x, locationInPixels.y); + Point location = display.getLocationInPointInDisplayCoordinateSystem(locationInPixels.x, locationInPixels.y); return location; } @Override public void setLocation(Point location) { if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - updateNativeZoomBeforePositionChange(location.x, location.y); - location = display.getLocationInPixelsWithMonitorOffset(location.x, location.y); + location = display.getLocationInPixelsInDisplayCoordinateSystem(location.x, location.y); setLocationInPixels(location.x, location.y); } @Override public void setLocation(int x, int y) { - updateNativeZoomBeforePositionChange(x, y); - Point location = display.getLocationInPixelsWithMonitorOffset(x, y); - x = location.x; - y = location.y; - setLocationInPixels(x, y); + Point location = display.getLocationInPixelsInDisplayCoordinateSystem(x, y); + setLocationInPixels(location.x, location.y); } @Override public void setBounds(Rectangle rect) { if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - updateNativeZoomBeforePositionChange(rect.x, rect.y); - Rectangle scaledBounds = DPIUtil.autoScaleUp(rect, getZoom()); - Point topLeft = display.getLocationInPixelsWithMonitorOffset(rect.x, rect.y); - scaledBounds.x = topLeft.x; - scaledBounds.y = topLeft.y; - setBoundsInPixels(scaledBounds); + setBounds(rect.x, rect.y, rect.width, rect.height); } @Override -public void setBounds(int x, int y, int width, int height) { - updateNativeZoomBeforePositionChange(x, y); - int zoom = getZoom(); - Point topLeft = display.getLocationInPixelsWithMonitorOffset(x, y); - x = topLeft.x; - y = topLeft.y; - width = DPIUtil.autoScaleUp(width, zoom); - height = DPIUtil.autoScaleUp(height, zoom); - setBoundsInPixels(x, y, width, height); +public void setBounds(int x, int y, int width2, int height2) { + Point topLeft = display.getLocationInPixelsInDisplayCoordinateSystem(x, y); + int width = DPIUtil.scaleUp(width2, getZoom()); + int height = DPIUtil.scaleUp(height2, getZoom()); + setBoundsInPixels(topLeft.x, topLeft.y, width, height); } @Override