From fc0098cf99d18494baf49bb1653cfcf743228172 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Tue, 23 Jul 2024 14:09:22 +0200 Subject: [PATCH] Removed and replaced autoScaleUpUsingNativeDPI This commit replaces the DPIUtil.autoScaleUpUsingNativeDPI calls from clients in win32 with DPIUtil.scaleUp utilizing the zoom available within the clients. It additionally removes the method DPIUtil.autoScaleUpUsingNativeDPI since it's not used anymore. contributes to #62 and #127 --- .../common/org/eclipse/swt/internal/DPIUtil.java | 9 --------- .../win32/org/eclipse/swt/widgets/Button.java | 2 +- .../win32/org/eclipse/swt/widgets/MenuItem.java | 2 +- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java | 2 +- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 592d5ac01dd..8d631342e8d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -393,15 +393,6 @@ public static int scaleUp(int size, int zoom) { return Math.round (size * scaleFactor); } -/** - * Auto-scale up int dimensions using Native DPI - */ -public static int autoScaleUpUsingNativeDPI (int size) { - if (nativeDeviceZoom == 100 || size == SWT.DEFAULT) return size; - float nativeScaleFactor = nativeDeviceZoom / 100f; - return Math.round (size * nativeScaleFactor); -} - /** * Auto-scale up int dimensions if enabled for Drawable class. */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index 08d97c8b443..230653fa4e2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -1314,7 +1314,7 @@ private int getCheckboxTextOffset(long hdc) { OS.GetThemePartSize(display.hButtonTheme(), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size); result += size.cx; } else { - result += DPIUtil.autoScaleUpUsingNativeDPI(13); + result += DPIUtil.scaleUp(13, nativeZoom); } // Windows uses half width of '0' as checkbox-to-text distance. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index d193c028f13..1105dea32c7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -1161,7 +1161,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) { * NOTE: autoScaleUpUsingNativeDPI() is used to avoid problems * with applications that disable automatic scaling. */ - struct.itemWidth = DPIUtil.autoScaleUpUsingNativeDPI(5); + struct.itemWidth = DPIUtil.scaleUp(5, nativeZoom); OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof); return null; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 1c8e63d156c..9a1b5e5c94c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -6915,7 +6915,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { * Sort indicator size needs to scale as per the Native Windows OS DPI level * when header is custom drawn. For more details refer bug 537097. */ - int leg = DPIUtil.autoScaleUpUsingNativeDPI(3); + int leg = DPIUtil.scaleUp(3, nativeZoom); if (sortDirection == SWT.UP) { OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2); OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index e86675701ab..b87b42087f0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -7884,7 +7884,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { * Sort indicator size needs to scale as per the Native Windows OS DPI level * when header is custom drawn. For more details refer bug 537097. */ - int leg = DPIUtil.autoScaleUpUsingNativeDPI(3); + int leg = DPIUtil.scaleUp(3, nativeZoom); if (sortDirection == SWT.UP) { OS.Polyline(nmcd.hdc, new int[] {center-leg, 1+leg, center+1, 0}, 2); OS.Polyline(nmcd.hdc, new int[] {center+leg, 1+leg, center-1, 0}, 2);