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 a91211133a..674fb7b1e5 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 @@ -3970,7 +3970,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().translateToDisplayCoordinates(new Point(x, y), zoom); + final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y); + return DPIUtil.scaleDown(controlPointInPixels, zoom); } Point toControlInPixels (int x, int y) { @@ -4003,9 +4005,7 @@ 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); + return toControl(point.x, point.y); } /** @@ -4031,7 +4031,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().translateFromDisplayCoordinates(displayPointInPixels, zoom); } Point toDisplayInPixels (int x, int y) { @@ -4064,9 +4065,7 @@ Point toDisplayInPixels (int x, int y) { public Point toDisplay (Point point) { checkWidget (); 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); + return toDisplay(point.x, point.y); } 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 c3549417d4..9712a06b88 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 @@ -138,6 +138,7 @@ public class Display extends Device implements Executor { EventTable eventTable, filterTable; boolean useOwnDC; boolean externalEventLoop; // events are dispatched outside SWT, e.g. TrackPopupMenu or DoDragDrop + private CoordinatSystemMapper coordinateSystemMapper; private boolean rescalingAtRuntime; /* Widget Table */ @@ -1704,7 +1705,7 @@ public Control getCursorControl () { */ public Point getCursorLocation () { checkDevice (); - return DPIUtil.autoScaleDown(getCursorLocationInPixels()); + return coordinateSystemMapper.getCursorLocation(); } Point getCursorLocationInPixels () { @@ -2183,14 +2184,16 @@ Monitor getMonitor (long hmonitor) { OS.GetMonitorInfo (hmonitor, lpmi); Monitor monitor = new Monitor (); monitor.handle = hmonitor; - Rectangle boundsInPixels = new Rectangle (lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top); - monitor.setBounds (DPIUtil.autoScaleDown (boundsInPixels)); - Rectangle clientAreaInPixels = new Rectangle (lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top); - monitor.setClientArea (DPIUtil.autoScaleDown (clientAreaInPixels)); + Rectangle boundsInPixels = new Rectangle(lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top); + Rectangle clientAreaInPixels = new Rectangle(lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top); int [] dpiX = new int[1]; int [] dpiY = new int[1]; int result = OS.GetDpiForMonitor (monitor.handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY); result = (result == OS.S_OK) ? DPIUtil.mapDPIToZoom (dpiX[0]) : 100; + + int autoscaleZoom = DPIUtil.getZoomForAutoscaleProperty(result); + monitor.setBounds(coordinateSystemMapper.mapMonitorBounds(boundsInPixels, autoscaleZoom)); + monitor.setClientArea(coordinateSystemMapper.mapMonitorBounds(clientAreaInPixels, autoscaleZoom)); if (result == 0) { System.err.println("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor."); result = 100; @@ -2769,6 +2772,7 @@ protected void init () { // Field initialization happens after super constructor controlByHandle = new HashMap<>(); this.synchronizer = new Synchronizer (this); + this.coordinateSystemMapper = new SingleZoomCoordinateSystemMapper(); super.init (); DPIUtil.setDeviceZoom (getDeviceZoom ()); @@ -2944,9 +2948,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 coordinateSystemMapper.map(from, to, point); } Point mapInPixels (Control from, Control to, Point point) { @@ -2991,10 +2993,7 @@ 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); + return coordinateSystemMapper.map(from, to, x, y); } Point mapInPixels (Control from, Control to, int x, int y) { @@ -3058,9 +3057,7 @@ 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 coordinateSystemMapper.map(from, to, rectangle); } Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) { @@ -3107,12 +3104,7 @@ 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); + return coordinateSystemMapper.map(from, to, x, y, width, height); } Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int height) { @@ -3130,6 +3122,26 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } +Point translateFromDisplayCoordinates(Point point, int zoom) { + return coordinateSystemMapper.translateFromDisplayCoordinates(point, zoom); +} + +Point translateToDisplayCoordinates(Point point, int zoom) { + return coordinateSystemMapper.translateToDisplayCoordinates(point, zoom); +} + +Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) { + return coordinateSystemMapper.translateFromDisplayCoordinates(rect, zoom); +} + +Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) { + return coordinateSystemMapper.translateToDisplayCoordinates(rect, zoom); +} + +private int getApplicableMonitorZoom(Monitor monitor) { + return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom()); +} + long messageProc (long hwnd, long msg, long wParam, long lParam) { switch ((int)msg) { case SWT_RUNASYNC: { @@ -4355,7 +4367,7 @@ public void sendPostExternalEventDispatchEvent () { */ public void setCursorLocation (int x, int y) { checkDevice (); - setCursorLocationInPixels (DPIUtil.autoScaleUp (x), DPIUtil.autoScaleUp (y)); + coordinateSystemMapper.setCursorLocation(x, y); } void setCursorLocationInPixels (int x, int y) { @@ -5359,6 +5371,7 @@ public boolean setRescalingAtRuntime(boolean activate) { int desiredApiAwareness = activate ? OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 : OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE; if (setDPIAwareness(desiredApiAwareness)) { rescalingAtRuntime = activate; + coordinateSystemMapper = activate ? new MultiZoomCoordinateSystemMapper() : new SingleZoomCoordinateSystemMapper(); // dispose a existing font registry for the default display SWTFontProvider.disposeFontRegistry(this); return true; @@ -5390,4 +5403,291 @@ private boolean setDPIAwareness(int desiredDpiAwareness) { return true; } +private interface CoordinatSystemMapper { + + Rectangle map(Control from, Control to, Rectangle rectangle); + + Rectangle map(Control from, Control to, int x, int y, int width, int height); + + Point map(Control from, Control to, Point point); + + Point map(Control from, Control to, int x, int y); + + Rectangle mapMonitorBounds(Rectangle rectangle, int zoom); + + Point translateFromDisplayCoordinates(Point point, int zoom); + + Point translateToDisplayCoordinates(Point point, int zoom); + + Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom); + + Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom); + + void setCursorLocation(int x, int y); + + Point getCursorLocation(); + +} + +private class SingleZoomCoordinateSystemMapper implements CoordinatSystemMapper { + @Override + public Point map (Control from, Control to, Point point) { + int zoom = getZoomLevelForMapping(from, to); + point = DPIUtil.scaleUp(point, zoom); + return DPIUtil.scaleDown(mapInPixels(from, to, point), zoom); + } + + @Override + public Rectangle map (Control from, Control to, Rectangle rectangle) { + int zoom = getZoomLevelForMapping(from, to); + rectangle = DPIUtil.scaleUp(rectangle, zoom); + return DPIUtil.scaleDown(mapInPixels(from, to, rectangle), zoom); + } + + @Override + public Point map (Control from, Control to, int x, int y) { + int zoom = getZoomLevelForMapping(from, to); + x = DPIUtil.scaleUp(x, zoom); + y = DPIUtil.scaleUp(y, zoom); + return DPIUtil.scaleDown(mapInPixels(from, to, x, y), zoom); + } + + @Override + public Rectangle map (Control from, Control to, int x, int y, int width, int height) { + 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); + } + + @Override + public Rectangle mapMonitorBounds(Rectangle rect, int zoom) { + return DPIUtil.autoScaleDown(rect); + } + + @Override + public Point translateFromDisplayCoordinates(Point point, int zoom) { + return DPIUtil.scaleDown(point, zoom); + } + + @Override + public Point translateToDisplayCoordinates(Point point, int zoom) { + return DPIUtil.scaleUp(point, zoom); + } + + @Override + public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) { + return DPIUtil.scaleDown(rect, zoom); + } + + @Override + public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) { + return DPIUtil.scaleUp(rect, zoom); + } + + @Override + public Point getCursorLocation () { + Point cursorLocationInPixels = getCursorLocationInPixels(); + return DPIUtil.autoScaleDown(cursorLocationInPixels); + } + + @Override + public void setCursorLocation (int x, int y) { + setCursorLocationInPixels (DPIUtil.autoScaleUp (x), DPIUtil.autoScaleUp (y)); + } +} + +private class MultiZoomCoordinateSystemMapper implements CoordinatSystemMapper { + @Override + public Point map (Control from, Control to, Point point) { + return map(from, to, point.x, point.y); + } + + @Override + public Rectangle map (Control from, Control to, Rectangle rectangle) { + return map(from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); + } + + @Override + public Point map (Control from, Control to, int x, int y) { + Point mappedPointInPoints; + if (from == null) { + Point mappedPointInpixels = mapInPixels(from, to, getPixelsFromPoint(to.getShell().getMonitor(), 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 = getPointFromPixels(from.getShell().getMonitor(), mappedPointInpixels.x, mappedPointInpixels.y); + } else { + Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom())); + mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom()); + } + return mappedPointInPoints; + } + + @Override + public Rectangle map (Control from, Control to, int x, int y, int width, int height) { + Rectangle mappedRectangleInPoints; + if (from == null) { + Rectangle mappedRectangleInPixels = mapInPixels(from, to, translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, to.getShell().getMonitor())); + 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 = translateRectangleInPointsInDisplayCoordinateSystem(mappedRectangleInPixels.x, mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height, from.getShell().getMonitor()); + } else { + Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom())); + mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom()); + } + return mappedRectangleInPoints; + } + + @Override + public Rectangle mapMonitorBounds(Rectangle rect, int zoom) { + Rectangle bounds = DPIUtil.scaleDown(rect, zoom); + bounds.x = rect.x; + bounds.y = rect.y; + return bounds; + } + + @Override + public Point translateFromDisplayCoordinates(Point point, int zoom) { + return translateLocationInPixelsFromDisplayCoordinateSystem(point.x, point.y); + } + + @Override + public Point translateToDisplayCoordinates(Point point, int zoom) { + return translateLocationInPointsToDisplayCoordinateSystem(point.x, point.y); + } + + @Override + public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) { + return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height); + } + + @Override + public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) { + return translateRectangleInPointsToDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height); + } + + @Override + public Point getCursorLocation () { + Point cursorLocationInPixels = getCursorLocationInPixels(); + return translateLocationInPixelsFromDisplayCoordinateSystem(cursorLocationInPixels.x, cursorLocationInPixels.y); + } + + @Override + public void setCursorLocation (int x, int y) { + Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem(x, y); + setCursorLocationInPixels (cursorLocationInPixels.x, cursorLocationInPixels.y); + } + + private Point translateLocationInPointsToDisplayCoordinateSystem(int x, int y) { + Monitor monitor = getContainingMonitor(x, y); + return getPixelsFromPoint(monitor, x, y); + } + + private Point translateLocationInPixelsFromDisplayCoordinateSystem(int x, int y) { + Monitor monitor = getContainingMonitorInPixelsCoordinate(x, y); + return getPointFromPixels(monitor, x, y); + } + + private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment(int x, int y, int width, int height) { + Monitor monitorByLocation = getContainingMonitor(x, y); + Monitor monitorByContainment = getContainingMonitor(x, y, width, height); + return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitorByLocation, monitorByContainment); + } + + private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitor) { + return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor, monitor); + } + + private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) { + Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y); + int zoom = getApplicableMonitorZoom(monitorOfArea); + int widthInPixels = DPIUtil.scaleUp(width, zoom); + int heightInPixels = DPIUtil.scaleUp(height, zoom); + return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels); + } + + private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels) { + Monitor monitorByLocation = getContainingMonitor(x, y); + Monitor monitorByContainment = getContainingMonitor(x, y, widthInPixels, heightInPixels); + return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitorByLocation, monitorByContainment); + } + + private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) { + return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitor, monitor); + } + + + private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) { + Point topLeft = getPointFromPixels(monitorOfLocation, x, y); + int zoom = getApplicableMonitorZoom(monitorOfArea); + int width = DPIUtil.scaleDown(widthInPixels, zoom); + int height = DPIUtil.scaleDown(heightInPixels, zoom); + return new Rectangle(topLeft.x, topLeft.y, width, height); + } + + private Monitor getContainingMonitor(int x, int y) { + Monitor[] monitors = getMonitors(); + for (Monitor currentMonitor : monitors) { + Rectangle clientArea = currentMonitor.getClientArea(); + if (clientArea.contains(x, y)) { + return currentMonitor; + } + } + return getPrimaryMonitor(); + } + + private Monitor getContainingMonitor(int x, int y, int width, int height) { + Rectangle rectangle = new Rectangle(x, y, width, height); + Monitor[] monitors = getMonitors(); + Monitor selectedMonitor = getPrimaryMonitor(); + int highestArea = 0; + for (Monitor currentMonitor : monitors) { + Rectangle clientArea = currentMonitor.getClientArea(); + Rectangle intersection = clientArea.intersection(rectangle); + int area = intersection.width * intersection.height; + if (area > highestArea) { + selectedMonitor = currentMonitor; + highestArea = area; + } + } + return selectedMonitor; + } + + private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPixels) { + Monitor[] monitors = getMonitors(); + for (Monitor current : monitors) { + Rectangle clientArea = getMonitorClientAreaInPixels(current); + if (clientArea.contains(xInPixels, yInPixels)) { + return current; + } + } + return getPrimaryMonitor(); + } + + private Rectangle getMonitorClientAreaInPixels(Monitor monitor) { + int zoom = getApplicableMonitorZoom(monitor); + int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom); + int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom); + return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels); + } + + private Point getPixelsFromPoint(Monitor monitor, int x, int y) { + int zoom = getApplicableMonitorZoom(monitor); + int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX; + int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY; + return new Point(mappedX, mappedY); + } + + private Point getPointFromPixels(Monitor monitor, int x, int y) { + int zoom = getApplicableMonitorZoom(monitor); + int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX; + int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY; + return new Point(mappedX, mappedY); + } +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java index 61e006e5c9..3a6428e4a5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java @@ -1225,8 +1225,8 @@ void setLocationInPixels (int x, int y) { public void setLocation (Point location) { checkWidget (); if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - location = getDisplay().translateLocationInPixelsInDisplayCoordinateSystem(location.x, location.y); - setLocationInPixels(location.x, location.y); + Point locationInPixels = getDisplay().translateToDisplayCoordinates(location, getZoom()); + setLocationInPixels(locationInPixels.x, locationInPixels.y); } /** 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 138d416235..ece3512f70 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 @@ -1566,6 +1566,44 @@ public void setAlpha (int alpha) { } } +@Override +public Rectangle getBounds() { + checkWidget (); + return getDisplay().translateFromDisplayCoordinates(getBoundsInPixels(), getZoom()); +} + +@Override +public Point getLocation() { + checkWidget (); + return getDisplay().translateFromDisplayCoordinates(getLocationInPixels(), getZoom()); +} + +@Override +public void setLocation(Point location) { + if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + checkWidget (); + Point locationInPixels = getDisplay().translateToDisplayCoordinates(location, getZoom()); + setLocationInPixels(locationInPixels.x, locationInPixels.y); +} + +@Override +public void setLocation(int x, int y) { + setLocation(new Point(x, y)); +} + +@Override +public void setBounds(Rectangle rect) { + if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); + checkWidget (); + Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(rect, getZoom()); + setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height); +} + +@Override +public void setBounds(int x, int y, int width, int height) { + setBounds(new Rectangle(x, y, width, height)); +} + @Override void setBoundsInPixels (int x, int y, int width, int height, int flags, boolean defer) { if (fullScreen) setFullScreen (false); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java index 4fcc69ed1e..91b2e05c0c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java @@ -1686,7 +1686,7 @@ boolean showMenu (int x, int y) { boolean showMenu (int x, int y, int detail) { Event event = new Event (); - Point mappedLocation = getDisplay().translateLocationInPointInDisplayCoordinateSystem(x, y); + Point mappedLocation = getDisplay().translateFromDisplayCoordinates(new Point(x, y), getZoom()); event.setLocation(mappedLocation.x, mappedLocation.y); event.detail = detail; if (event.detail == SWT.MENU_KEYBOARD) {