From 55008d5a76133714fe8618ba30a2504a715bfa3d Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Fri, 12 Jul 2024 16:51:56 +0200 Subject: [PATCH] Replaced the DPIUtil scale by scale with zoom call This commit replaces the DPIUtil calls from clients in win32 which are still using DPIUtil autoScale calls, with scale calls utilizing the zoom available within the clients. contributes to #62 and #127 --- .../win32/org/eclipse/swt/awt/SWT_AWT.java | 2 +- .../win32/org/eclipse/swt/dnd/DragSource.java | 5 +++-- .../win32/org/eclipse/swt/dnd/DropTarget.java | 15 +++++++++------ .../eclipse/swt/dnd/TableDropTargetEffect.java | 2 +- .../eclipse/swt/dnd/TreeDropTargetEffect.java | 2 +- .../eclipse/swt/ole/win32/OleClientSite.java | 17 +++++++++-------- .../win32/org/eclipse/swt/graphics/Device.java | 4 ++-- .../win32/org/eclipse/swt/graphics/Image.java | 5 +++-- .../win32/org/eclipse/swt/widgets/Widget.java | 2 +- 9 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java index 0d792489772..20dfbd5f2ad 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java @@ -250,7 +250,7 @@ public static Frame new_Frame (final Composite parent) { parent.getDisplay().asyncExec(() -> { if (parent.isDisposed()) return; - final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea()); // To Pixels + final Rectangle clientArea = DPIUtil.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels EventQueue.invokeLater(() -> { frame.setSize (clientArea.width, clientArea.height); frame.validate (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java index 4de5e1132bc..63152aaed45 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java @@ -530,9 +530,10 @@ private void drag(Event dragEvent) { */ int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; OS.RedrawWindow (topControl.handle, null, 0, flags); + int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); POINT pt = new POINT (); - pt.x = DPIUtil.autoScaleUp(dragEvent.x);// To Pixels - pt.y = DPIUtil.autoScaleUp(dragEvent.y);// To Pixels + pt.x = DPIUtil.scaleUp(dragEvent.x, zoom);// To Pixels + pt.y = DPIUtil.scaleUp(dragEvent.y, zoom);// To Pixels OS.MapWindowPoints (control.handle, 0, pt, 1); RECT rect = new RECT (); OS.GetWindowRect (hwndDrag, rect); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java index 0358c3d313c..0d3f32e137e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java @@ -281,8 +281,9 @@ int DragEnter_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) { } int DragEnter(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) { - pt_x = DPIUtil.autoScaleDown(pt_x);// To Points - pt_y = DPIUtil.autoScaleDown(pt_y);// To Points + int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); + pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points + pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points selectedDataType = null; selectedOperation = DND.DROP_NONE; if (iDataObject != null) iDataObject.Release(); @@ -348,8 +349,9 @@ int DragOver_64(int grfKeyState, long pt, long pdwEffect) { } int DragOver(int grfKeyState, int pt_x, int pt_y, long pdwEffect) { - pt_x = DPIUtil.autoScaleDown(pt_x);// To Points - pt_y = DPIUtil.autoScaleDown(pt_y);// To Points + int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); + pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points + pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points if (iDataObject == null) return COM.S_FALSE; int oldKeyOperation = keyOperation; @@ -403,8 +405,9 @@ int Drop_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) { int Drop(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) { try { - pt_x = DPIUtil.autoScaleDown(pt_x);// To Points - pt_y = DPIUtil.autoScaleDown(pt_y);// To Points + int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); + pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points + pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points DNDEvent event = new DNDEvent(); event.widget = this; event.time = OS.GetMessageTime(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDropTargetEffect.java index 42cb9d6b8fb..a9faebd531c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TableDropTargetEffect.java @@ -151,7 +151,7 @@ public void dragOver(DropTargetEvent event) { int effect = checkEffect(event.feedback); long handle = table.handle; Point coordinates = new Point(event.x, event.y); - coordinates = DPIUtil.autoScaleUp(table.toControl(coordinates)); // To Pixels + coordinates = DPIUtil.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels LVHITTESTINFO pinfo = new LVHITTESTINFO(); pinfo.x = coordinates.x; pinfo.y = coordinates.y; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDropTargetEffect.java index 87385adfdd1..1da890787a3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/TreeDropTargetEffect.java @@ -165,7 +165,7 @@ public void dragOver(DropTargetEvent event) { int effect = checkEffect(event.feedback); long handle = tree.handle; Point coordinates = new Point(event.x, event.y); - coordinates = DPIUtil.autoScaleUp(tree.toControl(coordinates)); // To Pixels + coordinates = DPIUtil.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels TVHITTESTINFO lpht = new TVHITTESTINFO (); lpht.x = coordinates.x; lpht.y = coordinates.y; diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java index 9d1d1a7980d..dc40d634afb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java @@ -810,7 +810,7 @@ protected int GetWindow(long phwnd) { return COM.S_OK; } RECT getRect() { - Rectangle area = DPIUtil.autoScaleUp(getClientArea()); // To Pixels + Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels RECT rect = new RECT(); rect.left = area.x; rect.top = area.y; @@ -987,14 +987,14 @@ private int OnInPlaceDeactivate() { return COM.S_OK; } private int OnPosRectChange(long lprcPosRect) { - Point size = DPIUtil.autoScaleUp(getSize()); // To Pixels + Point size = DPIUtil.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels setExtent(size.x, size.y); return COM.S_OK; } private void onPaint(Event e) { if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) { SIZE size = getExtent(); - Rectangle area = DPIUtil.autoScaleUp(getClientArea()); // To Pixels + Rectangle area = DPIUtil.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels RECT rect = new RECT(); if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$ rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy); @@ -1369,11 +1369,12 @@ void setBorderSpace(RECT newBorderwidth) { setBounds(); } void setBounds() { - Rectangle area = DPIUtil.autoScaleUp(frame.getClientArea()); // To Pixels - setBounds(DPIUtil.autoScaleDown(borderWidths.left), - DPIUtil.autoScaleDown(borderWidths.top), - DPIUtil.autoScaleDown(area.width - borderWidths.left - borderWidths.right), - DPIUtil.autoScaleDown(area.height - borderWidths.top - borderWidths.bottom)); + int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); + Rectangle area = DPIUtil.scaleDown(frame.getClientArea(), zoom); // To Pixels + setBounds(DPIUtil.scaleDown(borderWidths.left, zoom), + DPIUtil.scaleDown(borderWidths.top, zoom), + DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, zoom), + DPIUtil.scaleDown(area.height - borderWidths.top - borderWidths.bottom, zoom)); setObjectRects(); } private void setExtent(int width, int height){ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java index 9e83aa6ee0e..dc6e344d7f7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java @@ -410,7 +410,7 @@ long EnumFontFamProc (long lpelfe, long lpntme, long FontType, long lParam) { */ public Rectangle getBounds() { checkDevice (); - return DPIUtil.autoScaleDown(getBoundsInPixels()); + return DPIUtil.scaleDown(getBoundsInPixels(), getDeviceZoom()); } private Rectangle getBoundsInPixels () { @@ -517,7 +517,7 @@ public Point getDPI () { int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX); int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY); internal_dispose_GC (hDC, null); - return DPIUtil.autoScaleDown(new Point (dpiX, dpiY)); + return DPIUtil.scaleDown(new Point (dpiX, dpiY), getDeviceZoom()); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 47b6ac2a3a7..0e6e7ab01c4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -204,8 +204,9 @@ public final class Image extends Resource implements Drawable { public Image(Device device, int width, int height) { super(device); initialNativeZoom = DPIUtil.getNativeDeviceZoom(); - width = DPIUtil.autoScaleUp (width); - height = DPIUtil.autoScaleUp (height); + final int zoom = getZoom(); + width = DPIUtil.scaleUp (width, zoom); + height = DPIUtil.scaleUp (height, zoom); init(width, height); init(); } 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 5533fc13888..c0f5a7ae046 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 @@ -64,7 +64,7 @@ public abstract class Widget { * * @noreference This field is not intended to be referenced by clients. */ - protected int nativeZoom; + public int nativeZoom; int style, state; Display display; EventTable eventTable;