Skip to content

Commit 9771e17

Browse files
akoch-yattafedejeanne
authored andcommitted
[win32] Revert 4f60cb6 and 7a04f7a
1 parent d9d9bf0 commit 9771e17

File tree

3 files changed

+40
-201
lines changed

3 files changed

+40
-201
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,9 +3969,8 @@ void subclass () {
39693969
*/
39703970
public Point toControl (int x, int y) {
39713971
checkWidget ();
3972-
Point displayPointInPixels = getDisplay().translateLocationInPixelsInDisplayCoordinateSystem(x, y);
3973-
final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y);
3974-
return DPIUtil.scaleDown(controlPointInPixels, getZoom());
3972+
int zoom = getZoom();
3973+
return DPIUtil.scaleDown(toControlInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom);
39753974
}
39763975

39773976
Point toControlInPixels (int x, int y) {
@@ -4004,7 +4003,9 @@ Point toControlInPixels (int x, int y) {
40044003
public Point toControl (Point point) {
40054004
checkWidget ();
40064005
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
4007-
return toControl(point.x, point.y);
4006+
int zoom = getZoom();
4007+
point = DPIUtil.scaleUp(point, zoom);
4008+
return DPIUtil.scaleDown(toControlInPixels(point.x, point.y), zoom);
40084009
}
40094010

40104011
/**
@@ -4030,8 +4031,7 @@ public Point toControl (Point point) {
40304031
public Point toDisplay (int x, int y) {
40314032
checkWidget ();
40324033
int zoom = getZoom();
4033-
Point displayPointInPixels = toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom));
4034-
return getDisplay().translateLocationInPointInDisplayCoordinateSystem(displayPointInPixels.x, displayPointInPixels.y);
4034+
return DPIUtil.scaleDown(toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom);
40354035
}
40364036

40374037
Point toDisplayInPixels (int x, int y) {
@@ -4064,7 +4064,9 @@ Point toDisplayInPixels (int x, int y) {
40644064
public Point toDisplay (Point point) {
40654065
checkWidget ();
40664066
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
4067-
return toDisplay(point.x, point.y);
4067+
int zoom = getZoom();
4068+
point = DPIUtil.scaleUp(point, zoom);
4069+
return DPIUtil.scaleDown(toDisplayInPixels(point.x, point.y), zoom);
40684070
}
40694071

40704072
long topHandle () {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 31 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,7 @@ public Control getCursorControl () {
17041704
*/
17051705
public Point getCursorLocation () {
17061706
checkDevice ();
1707-
Point cursorLocationInPixels = getCursorLocationInPixels();
1708-
return translateLocationInPointInDisplayCoordinateSystem(cursorLocationInPixels.x, cursorLocationInPixels.y);
1707+
return DPIUtil.autoScaleDown(getCursorLocationInPixels());
17091708
}
17101709

17111710
Point getCursorLocationInPixels () {
@@ -2184,25 +2183,18 @@ Monitor getMonitor (long hmonitor) {
21842183
OS.GetMonitorInfo (hmonitor, lpmi);
21852184
Monitor monitor = new Monitor ();
21862185
monitor.handle = hmonitor;
2187-
Rectangle boundsInPixels = new Rectangle(lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
2188-
Rectangle clientAreaInPixels = new Rectangle(lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
2186+
Rectangle boundsInPixels = new Rectangle (lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
2187+
monitor.setBounds (DPIUtil.autoScaleDown (boundsInPixels));
2188+
Rectangle clientAreaInPixels = new Rectangle (lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
2189+
monitor.setClientArea (DPIUtil.autoScaleDown (clientAreaInPixels));
21892190
int [] dpiX = new int[1];
21902191
int [] dpiY = new int[1];
21912192
int result = OS.GetDpiForMonitor (monitor.handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY);
21922193
result = (result == OS.S_OK) ? DPIUtil.mapDPIToZoom (dpiX[0]) : 100;
2193-
2194-
int autoscaleZoom;
2195-
if (DPIUtil.isAutoScaleOnRuntimeActive()) {
2196-
autoscaleZoom = DPIUtil.getZoomForAutoscaleProperty(result);
2197-
} else {
2198-
autoscaleZoom = DPIUtil.getDeviceZoom();
2199-
}
22002194
if (result == 0) {
22012195
System.err.println("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor.");
22022196
result = 100;
22032197
}
2204-
monitor.setBounds(getMonitorBoundsInPointsInDisplayCoordinateSystem(boundsInPixels, autoscaleZoom));
2205-
monitor.setClientArea(getMonitorBoundsInPointsInDisplayCoordinateSystem(clientAreaInPixels, autoscaleZoom));
22062198
/*
22072199
* Always return true monitor zoom value as fetched from native, else will lead
22082200
* to scaling issue on OS Win8.1 and above, for more details refer bug 537614.
@@ -2211,13 +2203,6 @@ Monitor getMonitor (long hmonitor) {
22112203
return monitor;
22122204
}
22132205

2214-
private Rectangle getMonitorBoundsInPointsInDisplayCoordinateSystem(Rectangle boundsInPixels, int zoom) {
2215-
Rectangle bounds = DPIUtil.scaleDown(boundsInPixels, zoom);
2216-
bounds.x = boundsInPixels.x;
2217-
bounds.y = boundsInPixels.y;
2218-
return bounds;
2219-
}
2220-
22212206
/**
22222207
* Returns an array of monitors attached to the device.
22232208
*
@@ -2959,7 +2944,9 @@ boolean isValidThread () {
29592944
public Point map (Control from, Control to, Point point) {
29602945
checkDevice ();
29612946
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
2962-
return map(from, to, point.x, point.y);
2947+
int zoom = getZoomLevelForMapping(from, to);
2948+
point = DPIUtil.scaleUp(point, zoom);
2949+
return DPIUtil.scaleDown(mapInPixels(from, to, point), zoom);
29632950
}
29642951

29652952
Point mapInPixels (Control from, Control to, Point point) {
@@ -3004,18 +2991,10 @@ Point mapInPixels (Control from, Control to, Point point) {
30042991
*/
30052992
public Point map (Control from, Control to, int x, int y) {
30062993
checkDevice ();
3007-
Point mappedPointInPoints;
3008-
if (from == null) {
3009-
Point mappedPointInpixels = mapInPixels(from, to, getPixelsFromPoint(to.getShell().getMonitor(), x, y));
3010-
mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
3011-
} else if (to == null) {
3012-
Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
3013-
mappedPointInPoints = getPointFromPixels(from.getShell().getMonitor(), mappedPointInpixels.x, mappedPointInpixels.y);
3014-
} else {
3015-
Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
3016-
mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
3017-
}
3018-
return mappedPointInPoints;
2994+
int zoom = getZoomLevelForMapping(from, to);
2995+
x = DPIUtil.scaleUp(x, zoom);
2996+
y = DPIUtil.scaleUp(y, zoom);
2997+
return DPIUtil.scaleDown(mapInPixels(from, to, x, y), zoom);
30192998
}
30202999

30213000
Point mapInPixels (Control from, Control to, int x, int y) {
@@ -3031,6 +3010,15 @@ Point mapInPixels (Control from, Control to, int x, int y) {
30313010
return new Point (point.x, point.y);
30323011
}
30333012

3013+
private int getZoomLevelForMapping(Control from, Control to) {
3014+
if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
3015+
if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
3016+
if (to != null) {
3017+
return to.getZoom();
3018+
}
3019+
return from.getZoom();
3020+
}
3021+
30343022
/**
30353023
* Maps a point from one coordinate system to another.
30363024
* When the control is null, coordinates are mapped to
@@ -3070,7 +3058,9 @@ Point mapInPixels (Control from, Control to, int x, int y) {
30703058
public Rectangle map (Control from, Control to, Rectangle rectangle) {
30713059
checkDevice ();
30723060
if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
3073-
return map(from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
3061+
int zoom = getZoomLevelForMapping(from, to);
3062+
rectangle = DPIUtil.scaleUp(rectangle, zoom);
3063+
return DPIUtil.scaleDown(mapInPixels(from, to, rectangle), zoom);
30743064
}
30753065

30763066
Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) {
@@ -3117,18 +3107,12 @@ Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) {
31173107
*/
31183108
public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
31193109
checkDevice ();
3120-
Rectangle mappedRectangleInPoints;
3121-
if (from == null) {
3122-
Rectangle mappedRectangleInPixels = mapInPixels(from, to, translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, to.getShell().getMonitor()));
3123-
mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
3124-
} else if (to == null) {
3125-
Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
3126-
mappedRectangleInPoints = translateRectangleInPointsInDisplayCoordinateSystem(mappedRectangleInPixels.x, mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height, from.getShell().getMonitor());
3127-
} else {
3128-
Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
3129-
mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
3130-
}
3131-
return mappedRectangleInPoints;
3110+
int zoom = getZoomLevelForMapping(from, to);
3111+
x = DPIUtil.scaleUp(x, zoom);
3112+
y = DPIUtil.scaleUp(y, zoom);
3113+
width = DPIUtil.scaleUp(width, zoom);
3114+
height = DPIUtil.scaleUp(height, zoom);
3115+
return DPIUtil.scaleDown(mapInPixels(from, to, x, y, width, height), zoom);
31323116
}
31333117

31343118
Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int height) {
@@ -3146,57 +3130,6 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he
31463130
return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
31473131
}
31483132

3149-
Point translateLocationInPixelsInDisplayCoordinateSystem(int x, int y) {
3150-
Monitor monitor = getContainingMonitor(x, y);
3151-
return getPixelsFromPoint(monitor, x, y);
3152-
}
3153-
3154-
Point translateLocationInPointInDisplayCoordinateSystem(int x, int y) {
3155-
Monitor monitor = getContainingMonitorInPixelsCoordinate(x, y);
3156-
return getPointFromPixels(monitor, x, y);
3157-
}
3158-
3159-
Rectangle translateRectangleInPixelsInDisplayCoordinateSystemByContainment(int x, int y, int width, int height) {
3160-
Monitor monitorByLocation = getContainingMonitor(x, y);
3161-
Monitor monitorByContainment = getContainingMonitor(x, y, width, height);
3162-
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitorByLocation, monitorByContainment);
3163-
}
3164-
3165-
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitor) {
3166-
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor, monitor);
3167-
}
3168-
3169-
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
3170-
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
3171-
int zoom = getApplicableMonitorZoom(monitorOfArea);
3172-
int widthInPixels = DPIUtil.scaleUp(width, zoom);
3173-
int heightInPixels = DPIUtil.scaleUp(height, zoom);
3174-
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
3175-
}
3176-
3177-
Rectangle translateRectangleInPointsInDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels) {
3178-
Monitor monitorByLocation = getContainingMonitor(x, y);
3179-
Monitor monitorByContainment = getContainingMonitor(x, y, widthInPixels, heightInPixels);
3180-
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitorByLocation, monitorByContainment);
3181-
}
3182-
3183-
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
3184-
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitor, monitor);
3185-
}
3186-
3187-
3188-
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) {
3189-
Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
3190-
int zoom = getApplicableMonitorZoom(monitorOfArea);
3191-
int width = DPIUtil.scaleDown(widthInPixels, zoom);
3192-
int height = DPIUtil.scaleDown(heightInPixels, zoom);
3193-
return new Rectangle(topLeft.x, topLeft.y, width, height);
3194-
}
3195-
3196-
private int getApplicableMonitorZoom(Monitor monitor) {
3197-
return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom());
3198-
}
3199-
32003133
long messageProc (long hwnd, long msg, long wParam, long lParam) {
32013134
switch ((int)msg) {
32023135
case SWT_RUNASYNC: {
@@ -4422,8 +4355,7 @@ public void sendPostExternalEventDispatchEvent () {
44224355
*/
44234356
public void setCursorLocation (int x, int y) {
44244357
checkDevice ();
4425-
Point cursorLocationInPixels = translateLocationInPixelsInDisplayCoordinateSystem(x, y);
4426-
setCursorLocationInPixels (cursorLocationInPixels.x, cursorLocationInPixels.y);
4358+
setCursorLocationInPixels (DPIUtil.autoScaleUp (x), DPIUtil.autoScaleUp (y));
44274359
}
44284360

44294361
void setCursorLocationInPixels (int x, int y) {
@@ -5458,63 +5390,4 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
54585390
return true;
54595391
}
54605392

5461-
private Monitor getContainingMonitor(int x, int y) {
5462-
Monitor[] monitors = getMonitors();
5463-
for (Monitor currentMonitor : monitors) {
5464-
Rectangle clientArea = currentMonitor.getClientArea();
5465-
if (clientArea.contains(x, y)) {
5466-
return currentMonitor;
5467-
}
5468-
}
5469-
return getPrimaryMonitor();
5470-
}
5471-
5472-
private Monitor getContainingMonitor(int x, int y, int width, int height) {
5473-
Rectangle rectangle = new Rectangle(x, y, width, height);
5474-
Monitor[] monitors = getMonitors();
5475-
Monitor selectedMonitor = getPrimaryMonitor();
5476-
int highestArea = 0;
5477-
for (Monitor currentMonitor : monitors) {
5478-
Rectangle clientArea = currentMonitor.getClientArea();
5479-
Rectangle intersection = clientArea.intersection(rectangle);
5480-
int area = intersection.width * intersection.height;
5481-
if (area > highestArea) {
5482-
selectedMonitor = currentMonitor;
5483-
highestArea = area;
5484-
}
5485-
}
5486-
return selectedMonitor;
5487-
}
5488-
5489-
private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPixels) {
5490-
Monitor[] monitors = getMonitors();
5491-
for (Monitor current : monitors) {
5492-
Rectangle clientArea = getMonitorClientAreaInPixels(current);
5493-
if (clientArea.contains(xInPixels, yInPixels)) {
5494-
return current;
5495-
}
5496-
}
5497-
return getPrimaryMonitor();
5498-
}
5499-
5500-
private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
5501-
int zoom = getApplicableMonitorZoom(monitor);
5502-
int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom);
5503-
int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom);
5504-
return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels);
5505-
}
5506-
5507-
private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
5508-
int zoom = getApplicableMonitorZoom(monitor);
5509-
int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
5510-
int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
5511-
return new Point(mappedX, mappedY);
5512-
}
5513-
5514-
private Point getPointFromPixels(Monitor monitor, int x, int y) {
5515-
int zoom = getApplicableMonitorZoom(monitor);
5516-
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
5517-
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
5518-
return new Point(mappedX, mappedY);
5519-
}
55205393
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,42 +1566,6 @@ public void setAlpha (int alpha) {
15661566
}
15671567
}
15681568

1569-
@Override
1570-
public Rectangle getBounds() {
1571-
Rectangle boundsInPixels = getBoundsInPixels();
1572-
return display.translateRectangleInPointsInDisplayCoordinateSystemByContainment(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
1573-
}
1574-
1575-
@Override
1576-
public Point getLocation() {
1577-
Point locationInPixels = getLocationInPixels();
1578-
return display.translateLocationInPointInDisplayCoordinateSystem(locationInPixels.x, locationInPixels.y);
1579-
}
1580-
1581-
@Override
1582-
public void setLocation(Point location) {
1583-
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
1584-
setLocation(location.x, location.y);
1585-
}
1586-
1587-
@Override
1588-
public void setLocation(int x, int y) {
1589-
Point location = display.translateLocationInPixelsInDisplayCoordinateSystem(x, y);
1590-
setLocationInPixels(location.x, location.y);
1591-
}
1592-
1593-
@Override
1594-
public void setBounds(Rectangle rect) {
1595-
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
1596-
setBounds(rect.x, rect.y, rect.width, rect.height);
1597-
}
1598-
1599-
@Override
1600-
public void setBounds(int x, int y, int width, int height) {
1601-
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(x, y, width, height);
1602-
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
1603-
}
1604-
16051569
@Override
16061570
void setBoundsInPixels (int x, int y, int width, int height, int flags, boolean defer) {
16071571
if (fullScreen) setFullScreen (false);

0 commit comments

Comments
 (0)