Skip to content

Commit 780d4b9

Browse files
committed
[Win32] Remove obsolete checks for non-supported Windows versions #2011
With introducing an explicit minimum supported OS version for Windows, all code guards for older than the minimum supported Windows version became obsolete. This change removes those guards and those OS methods that became unused. It also makes those methods, whose calls are not version-guarded anymore, statically instead of dynamically linked. This fixes some issue with wrong values returned by the AdjustWindowRectExForDpi method when used via dynamic linking. Fixes eclipse-platform/eclipse.platform.ui#2852 Fixes #2011
1 parent 24d7481 commit 780d4b9

File tree

8 files changed

+10
-86
lines changed

8 files changed

+10
-86
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c

-40
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,6 @@ JNIEXPORT jint JNICALL OS_NATIVE(AddFontResourceEx)
108108
}
109109
#endif
110110

111-
#ifndef NO_AdjustWindowRectEx
112-
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx)
113-
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3)
114-
{
115-
RECT _arg0, *lparg0=NULL;
116-
jboolean rc = 0;
117-
OS_NATIVE_ENTER(env, that, AdjustWindowRectEx_FUNC);
118-
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
119-
rc = (jboolean)AdjustWindowRectEx(lparg0, arg1, arg2, arg3);
120-
fail:
121-
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
122-
OS_NATIVE_EXIT(env, that, AdjustWindowRectEx_FUNC);
123-
return rc;
124-
}
125-
#endif
126-
127111
#ifndef NO_AdjustWindowRectExForDpi
128112
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
129113
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4)
@@ -132,15 +116,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
132116
jboolean rc = 0;
133117
OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC);
134118
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
135-
/*
136119
rc = (jboolean)AdjustWindowRectExForDpi(lparg0, arg1, arg2, arg3, arg4);
137-
*/
138-
{
139-
OS_LOAD_FUNCTION(fp, AdjustWindowRectExForDpi)
140-
if (fp) {
141-
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(RECT *, jint, jboolean, jint, jint))fp)(lparg0, arg1, arg2, arg3, arg4);
142-
}
143-
}
144120
fail:
145121
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
146122
OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC);
@@ -3320,15 +3296,7 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetSystemMetricsForDpi)
33203296
{
33213297
jint rc = 0;
33223298
OS_NATIVE_ENTER(env, that, GetSystemMetricsForDpi_FUNC);
3323-
/*
33243299
rc = (jint)GetSystemMetricsForDpi(arg0, arg1);
3325-
*/
3326-
{
3327-
OS_LOAD_FUNCTION(fp, GetSystemMetricsForDpi)
3328-
if (fp) {
3329-
rc = (jint)((jint (CALLING_CONVENTION*)(jint, jint))fp)(arg0, arg1);
3330-
}
3331-
}
33323300
OS_NATIVE_EXIT(env, that, GetSystemMetricsForDpi_FUNC);
33333301
return rc;
33343302
}
@@ -9329,15 +9297,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(SystemParametersInfoForDpi)
93299297
jboolean rc = 0;
93309298
OS_NATIVE_ENTER(env, that, SystemParametersInfoForDpi_FUNC);
93319299
if (arg2) if ((lparg2 = getNONCLIENTMETRICSFields(env, arg2, &_arg2)) == NULL) goto fail;
9332-
/*
93339300
rc = (jboolean)SystemParametersInfoForDpi(arg0, arg1, lparg2, arg3, arg4);
9334-
*/
9335-
{
9336-
OS_LOAD_FUNCTION(fp, SystemParametersInfoForDpi)
9337-
if (fp) {
9338-
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jint, jint, NONCLIENTMETRICS *, jint, jint))fp)(arg0, arg1, lparg2, arg3, arg4);
9339-
}
9340-
}
93419301
fail:
93429302
if (arg2 && lparg2) setNONCLIENTMETRICSFields(env, arg2, lparg2);
93439303
OS_NATIVE_EXIT(env, that, SystemParametersInfoForDpi_FUNC);

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h

-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222
#define GetDpiForWindow_LIB "user32.dll"
2323
#define RtlGetVersion_LIB "ntdll.dll"
2424
#define OpenThemeDataForDpi_LIB "uxtheme.dll"
25-
#define GetSystemMetricsForDpi_LIB "user32.dll"
2625
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
2726
#define SetThreadDpiAwarenessContext_LIB "user32.dll"
28-
#define SystemParametersInfoForDpi_LIB "user32.dll"
29-
#define AdjustWindowRectExForDpi_LIB "user32.dll"

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ typedef enum {
2929
ActivateActCtx_FUNC,
3030
ActivateKeyboardLayout_FUNC,
3131
AddFontResourceEx_FUNC,
32-
AdjustWindowRectEx_FUNC,
3332
AdjustWindowRectExForDpi_FUNC,
3433
AllowDarkModeForWindow_FUNC,
3534
AllowSetForegroundWindow_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public class OS extends C {
3939
/**
4040
* Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
4141
*/
42-
public static final int WIN32_BUILD_WIN8_1 = 9600; // "Windows 8.1"
43-
public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update"
4442
public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update"
4543
public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update"
4644
public static final int WIN32_BUILD_WIN11_21H2 = 22000; // Initial Windows 11 release
@@ -2353,8 +2351,6 @@ public static int HRESULT_FROM_WIN32(int x) {
23532351
* @param pdv cast=(PVOID)
23542352
*/
23552353
public static final native int AddFontResourceEx(char[] lpszFilename, int fl, long pdv);
2356-
public static final native boolean AdjustWindowRectEx (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle);
2357-
/** @method flags=dynamic */
23582354
public static final native boolean AdjustWindowRectExForDpi (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle, int dpi);
23592355
/** @method flags=no_gen */
23602356
public static final native boolean AllowDarkModeForWindow(long hWnd, boolean allow);
@@ -3006,7 +3002,6 @@ public static int HRESULT_FROM_WIN32(int x) {
30063002
/** @param hWnd cast=(HWND) */
30073003
public static final native long GetSystemMenu (long hWnd, boolean bRevert);
30083004
public static final native int GetSystemMetrics (int nIndex);
3009-
/** @method flags=dynamic */
30103005
public static final native int GetSystemMetricsForDpi (int nIndex, int dpi);
30113006
/** @param hDC cast=(HDC) */
30123007
public static final native int GetTextColor (long hDC);
@@ -4496,7 +4491,6 @@ public static int HRESULT_FROM_WIN32(int x) {
44964491
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, RECT pvParam, int fWinIni);
44974492
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni);
44984493
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, int [] pvParam, int fWinIni);
4499-
/** @method flags=dynamic */
45004494
public static final native boolean SystemParametersInfoForDpi (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni, int dpi);
45014495
/**
45024496
* @param lpKeyState cast=(PBYTE)

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,8 @@ private long createSystemFontHandle(int zoom) {
9797
}
9898

9999
private static boolean fetchSystemParametersInfo(NONCLIENTMETRICS info, int targetZoom) {
100-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
101-
return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0,
102-
DPIUtil.mapZoomToDPI(targetZoom));
103-
} else {
104-
return OS.SystemParametersInfo(OS.SPI_GETNONCLIENTMETRICS, 0, info, 0);
105-
}
100+
return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0,
101+
DPIUtil.mapZoomToDPI(targetZoom));
106102
}
107103

108104
@Override

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -2229,13 +2229,11 @@ public boolean print (GC gc) {
22292229
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22302230
OS.RedrawWindow (topHandle, null, 0, flags);
22312231
int printWindowFlags = 0;
2232-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) {
2233-
/*
2234-
* Undocumented flag in windows, which also allows the capturing
2235-
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2236-
*/
2237-
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
2238-
}
2232+
/*
2233+
* Undocumented flag in windows, which also allows the capturing
2234+
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2235+
*/
2236+
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
22392237
printWidget (topHandle, hdc, gc, printWindowFlags);
22402238
if (gdipGraphics != 0) {
22412239
OS.RestoreDC(hdc, state);

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

+1-9
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,7 @@ public class Display extends Device implements Executor {
533533
private static int ICON_SIZE_AT_100 = retrieveDefaultIconSize();
534534

535535
private static int retrieveDefaultIconSize() {
536-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
537-
return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100));
538-
} else {
539-
return 32;
540-
}
536+
return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100));
541537
}
542538

543539
/* Skinning support */
@@ -5396,10 +5392,6 @@ private boolean setMonitorSpecificScaling(boolean activate) {
53965392
}
53975393

53985394
private boolean setDPIAwareness(int desiredDpiAwareness) {
5399-
if (OS.WIN32_BUILD < OS.WIN32_BUILD_WIN10_1607) {
5400-
System.err.println("***WARNING: the OS version does not support setting DPI awareness.");
5401-
return false;
5402-
}
54035395
if (desiredDpiAwareness == OS.GetThreadDpiAwarenessContext()) {
54045396
return true;
54055397
}

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

+2-14
Original file line numberDiff line numberDiff line change
@@ -2703,23 +2703,11 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
27032703
}
27042704

27052705
int getSystemMetrics(int nIndex) {
2706-
/*
2707-
* DPI dependent metrics were introduced after 2016 version of windows 10
2708-
*/
2709-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
2710-
return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom));
2711-
}
2712-
return OS.GetSystemMetrics(nIndex);
2706+
return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom));
27132707
}
27142708

27152709
boolean adjustWindowRectEx(RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle) {
2716-
/*
2717-
* DPI-dependent version of the method was introduced with Windows 10 Version 1607
2718-
*/
2719-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
2720-
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom));
2721-
}
2722-
return OS.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
2710+
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom));
27232711
}
27242712

27252713

0 commit comments

Comments
 (0)