diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.properties b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.properties index 7b85efdb120..d7982f1b9f9 100644 --- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.properties +++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/org.eclipse.swt.internal.properties @@ -20,9 +20,6 @@ swt_copyright=/***************************************************************** * https://www.eclipse.org/legal/epl-2.0/\n \ *\n \ * SPDX-License-Identifier: EPL-2.0\n \ -*\n \ -* Contributors:\n \ -* IBM Corporation - initial API and implementation\n \ *******************************************************************************/\n swt_properties_copyright=###############################################################################\n\ # Copyright (c) 2000, %END_YEAR IBM Corporation and others.\n\ @@ -33,9 +30,6 @@ swt_properties_copyright=####################################################### # https://www.eclipse.org/legal/epl-2.0/\n\ #\n\ # SPDX-License-Identifier: EPL-2.0\n\ -#\n\ -# Contributors:\n\ -# IBM Corporation - initial API and implementation\n\ ############################################################################### swt_main_classes=\ org.eclipse.swt.internal.accessibility.gtk.ATK,../org.eclipse.swt/Eclipse SWT PI/gtk/library/,\ @@ -44,6 +38,7 @@ org.eclipse.swt.internal.gtk3.GTK3,../org.eclipse.swt/Eclipse SWT PI/gtk/library org.eclipse.swt.internal.gtk4.GTK4,../org.eclipse.swt/Eclipse SWT PI/gtk/library/,\ org.eclipse.swt.internal.ole.win32.COM,../org.eclipse.swt/Eclipse SWT PI/win32/library/,\ org.eclipse.swt.internal.win32.OS,../org.eclipse.swt/Eclipse SWT PI/win32/library/,\ +org.eclipse.swt.internal.win32.version.OsVersion,../org.eclipse.swt/Eclipse SWT PI/win32/library/,\ org.eclipse.swt.internal.gdip.Gdip,../org.eclipse.swt/Eclipse SWT PI/win32/library/,\ org.eclipse.swt.internal.cairo.Cairo,../org.eclipse.swt/Eclipse SWT PI/cairo/library/,\ org.eclipse.swt.internal.opengl.glx.GLX,../org.eclipse.swt/Eclipse SWT OpenGL/glx/library/,\ diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java index 06cf11fdb28..dbf7dbc102e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/Platform.java @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.swt.internal; - public class Platform { public static final String PLATFORM = "cocoa"; //$NON-NLS-1$ @@ -21,4 +20,11 @@ public static boolean isLoadable () { return Library.isLoadable (); } +public static void exitIfNotLoadable() { + if (!Library.isLoadable ()) { + System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment"); + System.exit(1); + } +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java index 1abd49ca477..df91aef01a6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java @@ -16,6 +16,7 @@ public class C extends Platform { static { + exitIfNotLoadable(); Library.loadLibrary ("swt"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java index 3b6c5e72589..af2f17d7b92 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/Platform.java @@ -14,7 +14,6 @@ *******************************************************************************/ package org.eclipse.swt.internal; - public class Platform { public static final String PLATFORM = "gtk"; //$NON-NLS-1$ @@ -22,4 +21,11 @@ public static boolean isLoadable () { return Library.isLoadable (); } +public static void exitIfNotLoadable() { + if (!Library.isLoadable ()) { + System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment"); + System.exit(1); + } +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/make_win32.mak b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/make_win32.mak index bc458f60731..0f19029181c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/make_win32.mak +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/make_win32.mak @@ -31,6 +31,10 @@ SWT_OBJS = swt.obj callback.obj c.obj c_stats.obj \ os.obj os_structs.obj os_custom.obj os_stats.obj \ com_structs.obj com.obj com_stats.obj com_custom.obj +OSVERSION_PREFIX = swt-osversion +OSVERSION_LIB = $(OSVERSION_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).dll +OSVERSION_OBJS = osversion.obj osversion_structs.obj osversion_stats.obj + GDIP_PREFIX = swt-gdip GDIP_LIB = $(GDIP_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).dll GDIP_LIBS = gdiplus.lib @@ -57,7 +61,7 @@ dlllflags = -dll /WX guilibsmt = kernel32.lib ws2_32.lib mswsock.lib advapi32.lib bufferoverflowu.lib user32.lib gdi32.lib comdlg32.lib winspool.lib olelibsmt = ole32.lib uuid.lib oleaut32.lib $(guilibsmt) -all: make_swt make_awt make_gdip make_wgl +all: make_osversion make_swt make_awt make_gdip make_wgl .c.obj: cl $(CFLAGS) $*.c @@ -74,6 +78,14 @@ make_swt: $(SWT_OBJS) swt.res link @templrf del templrf +make_osversion: $(OSVERSION_OBJS) swt_osversion.res + echo $(ldebug) $(dlllflags) $(guilibsmt) >templrf + echo $(OSVERSION_OBJS) >>templrf + echo swt_osversion.res >>templrf + echo -out:$(OSVERSION_LIB) >>templrf + link @templrf + del templrf + make_gdip: $(GDIP_OBJS) swt_gdip.res echo $(ldebug) $(dlllflags) $(guilibsmt) >templrf echo $(GDIP_LIBS) >>templrf @@ -104,6 +116,9 @@ make_wgl: $(WGL_OBJS) swt_wgl.res swt.res: rc $(RCFLAGS) -DSWT_ORG_FILENAME=\"$(SWT_LIB)\" -r -fo swt.res swt.rc +swt_osversion.res: + rc $(RCFLAGS) -DSWT_ORG_FILENAME=\"$(OSVERSION_LIB)\" -r -fo swt_osversion.res swt_osversion.rc + swt_gdip.res: rc $(RCFLAGS) -DSWT_ORG_FILENAME=\"$(GDIP_LIB)\" -r -fo swt_gdip.res swt_gdip.rc diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c index ceb19ea77eb..495e6a69ac5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c @@ -108,22 +108,6 @@ JNIEXPORT jint JNICALL OS_NATIVE(AddFontResourceEx) } #endif -#ifndef NO_AdjustWindowRectEx -JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx) - (JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3) -{ - RECT _arg0, *lparg0=NULL; - jboolean rc = 0; - OS_NATIVE_ENTER(env, that, AdjustWindowRectEx_FUNC); - if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail; - rc = (jboolean)AdjustWindowRectEx(lparg0, arg1, arg2, arg3); -fail: - if (arg0 && lparg0) setRECTFields(env, arg0, lparg0); - OS_NATIVE_EXIT(env, that, AdjustWindowRectEx_FUNC); - return rc; -} -#endif - #ifndef NO_AdjustWindowRectExForDpi JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4) @@ -132,15 +116,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi) jboolean rc = 0; OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC); if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail; -/* rc = (jboolean)AdjustWindowRectExForDpi(lparg0, arg1, arg2, arg3, arg4); -*/ - { - OS_LOAD_FUNCTION(fp, AdjustWindowRectExForDpi) - if (fp) { - rc = (jboolean)((jboolean (CALLING_CONVENTION*)(RECT *, jint, jboolean, jint, jint))fp)(lparg0, arg1, arg2, arg3, arg4); - } - } fail: if (arg0 && lparg0) setRECTFields(env, arg0, lparg0); OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC); @@ -3320,15 +3296,7 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetSystemMetricsForDpi) { jint rc = 0; OS_NATIVE_ENTER(env, that, GetSystemMetricsForDpi_FUNC); -/* rc = (jint)GetSystemMetricsForDpi(arg0, arg1); -*/ - { - OS_LOAD_FUNCTION(fp, GetSystemMetricsForDpi) - if (fp) { - rc = (jint)((jint (CALLING_CONVENTION*)(jint, jint))fp)(arg0, arg1); - } - } OS_NATIVE_EXIT(env, that, GetSystemMetricsForDpi_FUNC); return rc; } @@ -9329,15 +9297,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(SystemParametersInfoForDpi) jboolean rc = 0; OS_NATIVE_ENTER(env, that, SystemParametersInfoForDpi_FUNC); if (arg2) if ((lparg2 = getNONCLIENTMETRICSFields(env, arg2, &_arg2)) == NULL) goto fail; -/* rc = (jboolean)SystemParametersInfoForDpi(arg0, arg1, lparg2, arg3, arg4); -*/ - { - OS_LOAD_FUNCTION(fp, SystemParametersInfoForDpi) - if (fp) { - rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jint, jint, NONCLIENTMETRICS *, jint, jint))fp)(arg0, arg1, lparg2, arg3, arg4); - } - } fail: if (arg2 && lparg2) setNONCLIENTMETRICSFields(env, arg2, lparg2); OS_NATIVE_EXIT(env, that, SystemParametersInfoForDpi_FUNC); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h index f26e394844f..594aa2c27cb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h @@ -22,8 +22,5 @@ #define GetDpiForWindow_LIB "user32.dll" #define RtlGetVersion_LIB "ntdll.dll" #define OpenThemeDataForDpi_LIB "uxtheme.dll" -#define GetSystemMetricsForDpi_LIB "user32.dll" #define GetThreadDpiAwarenessContext_LIB "user32.dll" #define SetThreadDpiAwarenessContext_LIB "user32.dll" -#define SystemParametersInfoForDpi_LIB "user32.dll" -#define AdjustWindowRectExForDpi_LIB "user32.dll" diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h index 4175ca4a320..16ce626c546 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h @@ -29,7 +29,6 @@ typedef enum { ActivateActCtx_FUNC, ActivateKeyboardLayout_FUNC, AddFontResourceEx_FUNC, - AdjustWindowRectEx_FUNC, AdjustWindowRectExForDpi_FUNC, AllowDarkModeForWindow_FUNC, AllowSetForegroundWindow_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.c new file mode 100644 index 00000000000..babc08e1135 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.c @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2025 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */ +/* DO NOT EDIT - your changes will be lost. */ + +#include "swt.h" +#include "osversion_structs.h" +#include "osversion_stats.h" + +#ifndef OsVersion_NATIVE +#define OsVersion_NATIVE(func) Java_org_eclipse_swt_internal_win32_version_OsVersion_##func +#endif + +#ifdef _WIN32 + /* Many methods don't use their 'env' and 'that' arguments */ + #pragma warning (disable: 4100) +#endif + +#ifndef NO_OSVERSIONINFOEX_1sizeof +JNIEXPORT jint JNICALL OsVersion_NATIVE(OSVERSIONINFOEX_1sizeof) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OsVersion_NATIVE_ENTER(env, that, OSVERSIONINFOEX_1sizeof_FUNC); + rc = (jint)OSVERSIONINFOEX_sizeof(); + OsVersion_NATIVE_EXIT(env, that, OSVERSIONINFOEX_1sizeof_FUNC); + return rc; +} +#endif + +#ifndef NO_RtlGetVersion +JNIEXPORT jint JNICALL OsVersion_NATIVE(RtlGetVersion) + (JNIEnv *env, jclass that, jobject arg0) +{ + OSVERSIONINFOEX _arg0, *lparg0=NULL; + jint rc = 0; + OsVersion_NATIVE_ENTER(env, that, RtlGetVersion_FUNC); + if (arg0) if ((lparg0 = getOSVERSIONINFOEXFields(env, arg0, &_arg0)) == NULL) goto fail; +/* + rc = (jint)RtlGetVersion(lparg0); +*/ + { + OsVersion_LOAD_FUNCTION(fp, RtlGetVersion) + if (fp) { + rc = (jint)((jint (CALLING_CONVENTION*)(OSVERSIONINFOEX *))fp)(lparg0); + } + } +fail: + if (arg0 && lparg0) setOSVERSIONINFOEXFields(env, arg0, lparg0); + OsVersion_NATIVE_EXIT(env, that, RtlGetVersion_FUNC); + return rc; +} +#endif + diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.h new file mode 100644 index 00000000000..135e715071b --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2025 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +#ifndef INC_osversion_H +#define INC_osversion_H + +/* + * Windows headers will sometimes have warnings above level 2, just + * ignore all of them, we can't do anything about it anyway. + */ +#pragma warning(push, 2) + +#include + +/* Restore warnings */ +#pragma warning(pop) + +/* Optional custom definitions to exclude some types */ +#include "defines.h" + +#define OsVersion_LOAD_FUNCTION LOAD_FUNCTION + +/* Libraries for dynamic loaded functions */ +#define RtlGetVersion_LIB "ntdll.dll" + +#endif /* INC_osversion_H */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.c new file mode 100644 index 00000000000..8fa86d83225 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.c @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2000, 2025 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */ +/* DO NOT EDIT - your changes will be lost. */ + +#include "swt.h" +#include "osversion_stats.h" + diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.h new file mode 100644 index 00000000000..79fae4e1061 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_stats.h @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2000, 2025 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */ +/* DO NOT EDIT - your changes will be lost. */ + +#ifndef OsVersion_NATIVE_ENTER +#define OsVersion_NATIVE_ENTER(env, that, func) +#endif +#ifndef OsVersion_NATIVE_EXIT +#define OsVersion_NATIVE_EXIT(env, that, func) +#endif + +typedef enum { + OSVERSIONINFOEX_1sizeof_FUNC, + RtlGetVersion_FUNC, +} OsVersion_FUNCS; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.c new file mode 100644 index 00000000000..40fa0586643 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.c @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2000, 2025 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */ +/* DO NOT EDIT - your changes will be lost. */ + +#include "swt.h" +#include "osversion_structs.h" + +#ifndef NO_OSVERSIONINFOEX +typedef struct OSVERSIONINFOEX_FID_CACHE { + int cached; + jclass clazz; + jfieldID dwOSVersionInfoSize, dwMajorVersion, dwMinorVersion, dwBuildNumber, dwPlatformId, szCSDVersion, wServicePackMajor, wServicePackMinor, wSuiteMask, wProductType, wReserved; +} OSVERSIONINFOEX_FID_CACHE; + +OSVERSIONINFOEX_FID_CACHE OSVERSIONINFOEXFc; + +void cacheOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject) +{ + if (OSVERSIONINFOEXFc.cached) return; + OSVERSIONINFOEXFc.clazz = (*env)->GetObjectClass(env, lpObject); + OSVERSIONINFOEXFc.dwOSVersionInfoSize = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwOSVersionInfoSize", "I"); + OSVERSIONINFOEXFc.dwMajorVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwMajorVersion", "I"); + OSVERSIONINFOEXFc.dwMinorVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwMinorVersion", "I"); + OSVERSIONINFOEXFc.dwBuildNumber = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwBuildNumber", "I"); + OSVERSIONINFOEXFc.dwPlatformId = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "dwPlatformId", "I"); + OSVERSIONINFOEXFc.szCSDVersion = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "szCSDVersion", "[C"); + OSVERSIONINFOEXFc.wServicePackMajor = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wServicePackMajor", "I"); + OSVERSIONINFOEXFc.wServicePackMinor = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wServicePackMinor", "I"); + OSVERSIONINFOEXFc.wSuiteMask = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wSuiteMask", "I"); + OSVERSIONINFOEXFc.wProductType = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wProductType", "I"); + OSVERSIONINFOEXFc.wReserved = (*env)->GetFieldID(env, OSVERSIONINFOEXFc.clazz, "wReserved", "I"); + OSVERSIONINFOEXFc.cached = 1; +} + +OSVERSIONINFOEX *getOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct) +{ + if (!OSVERSIONINFOEXFc.cached) cacheOSVERSIONINFOEXFields(env, lpObject); + lpStruct->dwOSVersionInfoSize = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwOSVersionInfoSize); + lpStruct->dwMajorVersion = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMajorVersion); + lpStruct->dwMinorVersion = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMinorVersion); + lpStruct->dwBuildNumber = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwBuildNumber); + lpStruct->dwPlatformId = (*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.dwPlatformId); + { + jcharArray lpObject1 = (jcharArray)(*env)->GetObjectField(env, lpObject, OSVERSIONINFOEXFc.szCSDVersion); + (*env)->GetCharArrayRegion(env, lpObject1, 0, sizeof(lpStruct->szCSDVersion) / sizeof(jchar), (jchar *)lpStruct->szCSDVersion); + } + lpStruct->wServicePackMajor = (WORD)(*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMajor); + lpStruct->wServicePackMinor = (WORD)(*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMinor); + lpStruct->wSuiteMask = (WORD)(*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wSuiteMask); + lpStruct->wProductType = (BYTE)(*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wProductType); + lpStruct->wReserved = (BYTE)(*env)->GetIntField(env, lpObject, OSVERSIONINFOEXFc.wReserved); + return lpStruct; +} + +void setOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct) +{ + if (!OSVERSIONINFOEXFc.cached) cacheOSVERSIONINFOEXFields(env, lpObject); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwOSVersionInfoSize, (jint)lpStruct->dwOSVersionInfoSize); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMajorVersion, (jint)lpStruct->dwMajorVersion); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwMinorVersion, (jint)lpStruct->dwMinorVersion); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwBuildNumber, (jint)lpStruct->dwBuildNumber); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.dwPlatformId, (jint)lpStruct->dwPlatformId); + { + jcharArray lpObject1 = (jcharArray)(*env)->GetObjectField(env, lpObject, OSVERSIONINFOEXFc.szCSDVersion); + (*env)->SetCharArrayRegion(env, lpObject1, 0, sizeof(lpStruct->szCSDVersion) / sizeof(jchar), (jchar *)lpStruct->szCSDVersion); + } + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMajor, (jint)lpStruct->wServicePackMajor); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wServicePackMinor, (jint)lpStruct->wServicePackMinor); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wSuiteMask, (jint)lpStruct->wSuiteMask); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wProductType, (jint)lpStruct->wProductType); + (*env)->SetIntField(env, lpObject, OSVERSIONINFOEXFc.wReserved, (jint)lpStruct->wReserved); +} +#endif + diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.h new file mode 100644 index 00000000000..0ec38f360cb --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/osversion_structs.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2000, 2025 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */ +/* DO NOT EDIT - your changes will be lost. */ + +#include "osversion.h" + +#ifndef NO_OSVERSIONINFOEX +void cacheOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject); +OSVERSIONINFOEX *getOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct); +void setOSVERSIONINFOEXFields(JNIEnv *env, jobject lpObject, OSVERSIONINFOEX *lpStruct); +#define OSVERSIONINFOEX_sizeof() sizeof(OSVERSIONINFOEX) +#else +#define cacheOSVERSIONINFOEXFields(a,b) +#define getOSVERSIONINFOEXFields(a,b,c) NULL +#define setOSVERSIONINFOEXFields(a,b,c) +#define OSVERSIONINFOEX_sizeof() 0 +#endif + diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/swt_osversion.rc b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/swt_osversion.rc new file mode 100644 index 00000000000..aff3e580931 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/swt_osversion.rc @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +#include "windows.h" + +VS_VERSION_INFO VERSIONINFO + PRODUCTVERSION 0,0,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40000L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Eclipse Foundation\0" + VALUE "FileDescription", "SWT for Windows native library\0" + VALUE "InternalName", "SWT\0" + VALUE "LegalCopyright", "Copyright (c) 2000, 2025 IBM Corp. All Rights Reserved.\0" + VALUE "OriginalFilename", SWT_ORG_FILENAME + VALUE "ProductName", "Standard Widget Toolkit\0" + VALUE "ProductVersion", "0,0,0,0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java index 7ae0c40f7aa..0d2b3d46dd6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/Platform.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.swt.internal; +import org.eclipse.swt.internal.win32.version.*; public class Platform { public static final String PLATFORM = "win32"; //$NON-NLS-1$ @@ -21,4 +22,11 @@ public static boolean isLoadable () { return Library.isLoadable (); } +public static void exitIfNotLoadable() { + if (!Library.isLoadable ()) { + System.err.println("Libraries for platform " + Platform.PLATFORM + " cannot be loaded because of incompatible environment"); + System.exit(1); + } + OsVersion.checkCompatibleWindowsVersion(); +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java index 267573ed8a2..75e6f4da1c0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java @@ -39,8 +39,6 @@ public class OS extends C { /** * Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions */ - public static final int WIN32_BUILD_WIN8_1 = 9600; // "Windows 8.1" - public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update" public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update" public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update" 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) { * @param pdv cast=(PVOID) */ public static final native int AddFontResourceEx(char[] lpszFilename, int fl, long pdv); -public static final native boolean AdjustWindowRectEx (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle); -/** @method flags=dynamic */ public static final native boolean AdjustWindowRectExForDpi (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle, int dpi); /** @method flags=no_gen */ public static final native boolean AllowDarkModeForWindow(long hWnd, boolean allow); @@ -3006,7 +3002,6 @@ public static int HRESULT_FROM_WIN32(int x) { /** @param hWnd cast=(HWND) */ public static final native long GetSystemMenu (long hWnd, boolean bRevert); public static final native int GetSystemMetrics (int nIndex); -/** @method flags=dynamic */ public static final native int GetSystemMetricsForDpi (int nIndex, int dpi); /** @param hDC cast=(HDC) */ public static final native int GetTextColor (long hDC); @@ -4496,7 +4491,6 @@ public static int HRESULT_FROM_WIN32(int x) { public static final native boolean SystemParametersInfo (int uiAction, int uiParam, RECT pvParam, int fWinIni); public static final native boolean SystemParametersInfo (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni); public static final native boolean SystemParametersInfo (int uiAction, int uiParam, int [] pvParam, int fWinIni); -/** @method flags=dynamic */ public static final native boolean SystemParametersInfoForDpi (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni, int dpi); /** * @param lpKeyState cast=(PBYTE) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OSVERSIONINFOEX.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OSVERSIONINFOEX.java new file mode 100644 index 00000000000..7156e8d4a46 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OSVERSIONINFOEX.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2021 Syntevo and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Syntevo - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.internal.win32.version; + +public class OSVERSIONINFOEX { + public int dwOSVersionInfoSize; + public int dwMajorVersion; + public int dwMinorVersion; + public int dwBuildNumber; + public int dwPlatformId; + public char[] szCSDVersion = new char[128]; + /** @field cast=(WORD) */ + public int wServicePackMajor; + /** @field cast=(WORD) */ + public int wServicePackMinor; + /** @field cast=(WORD) */ + public int wSuiteMask; + /** @field cast=(BYTE) */ + public int wProductType; + /** @field cast=(BYTE) */ + public int wReserved; + + public static final int sizeof = OsVersion.OSVERSIONINFOEX_sizeof (); +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OsVersion.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OsVersion.java new file mode 100644 index 00000000000..e02be241ec7 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/version/OsVersion.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2025 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.swt.internal.win32.version; + +import org.eclipse.swt.internal.*; + +/** + * A separate library only for checking the Windows build version. Required as the general + * OS library may not be loadable with linkage errors when executed on an unsupported Windows + * build, such that a version check cannot be performed successfully, but a a linkage error + * will occur instead. This library only adapts a single OS method that can always be loaded, + * thus ensuring that the version check can always be executed. + * + * @jniclass flags=c + * */ +public class OsVersion extends Platform { + static { + Library.loadLibrary ("swt-osversion"); //$NON-NLS-1$ + } + + /** + * Always reports the correct build number, regardless of manifest and + * compatibility GUIDs. Note that build number alone is sufficient to + * identify Windows version. + */ + public static final int WIN32_BUILD; + /** + * Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions + */ + public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update" + + /** + * The minimum supported Windows build version for using this SWT version + */ + public static final int WIN32_MINIMUM_COMPATIBLE_BUILD = WIN32_BUILD_WIN10_1607; + + private static final String DISABLE_WINDOWS_VERSION_CHECK_PROPERTY = "swt.disableWindowsVersionCheck"; + + static { + /* + * Starting with Windows 10, GetVersionEx() lies about version unless + * application manifest has a proper entry. RtlGetVersion() always + * reports true version. + */ + OSVERSIONINFOEX osVersionInfoEx = new OSVERSIONINFOEX (); + osVersionInfoEx.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof; + if (0 == OsVersion.RtlGetVersion (osVersionInfoEx)) { + WIN32_BUILD = osVersionInfoEx.dwBuildNumber; + } else { + System.err.println ("SWT: OS: Failed to detect Windows build number"); + WIN32_BUILD = 0; + } + } + + public static void checkCompatibleWindowsVersion() { + String disableVersionCheckPropertyValue = System.getProperty(DISABLE_WINDOWS_VERSION_CHECK_PROPERTY, Boolean.FALSE.toString()); + boolean versionCheckDisabled = "".equals(disableVersionCheckPropertyValue) || Boolean.TRUE.toString().equalsIgnoreCase(disableVersionCheckPropertyValue); + if (!versionCheckDisabled && WIN32_BUILD < WIN32_MINIMUM_COMPATIBLE_BUILD) { + System.err.println(String.format("Incompatible OS: Minimum Windows build version is %s but current is %s", + WIN32_MINIMUM_COMPATIBLE_BUILD, WIN32_BUILD)); + System.exit(1); + } + } + + public static final native int OSVERSIONINFOEX_sizeof (); + + /** @method flags=dynamic */ + public static final native int RtlGetVersion (OSVERSIONINFOEX lpVersionInformation); +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java index fa67ea09f3b..55dc435c004 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java @@ -97,12 +97,8 @@ private long createSystemFontHandle(int zoom) { } private static boolean fetchSystemParametersInfo(NONCLIENTMETRICS info, int targetZoom) { - if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) { - return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0, - DPIUtil.mapZoomToDPI(targetZoom)); - } else { - return OS.SystemParametersInfo(OS.SPI_GETNONCLIENTMETRICS, 0, info, 0); - } + return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0, + DPIUtil.mapZoomToDPI(targetZoom)); } @Override 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 cf98f3bf2b4..7d4ef4988ea 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 @@ -2229,13 +2229,11 @@ public boolean print (GC gc) { int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; OS.RedrawWindow (topHandle, null, 0, flags); int printWindowFlags = 0; - if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) { - /* - * Undocumented flag in windows, which also allows the capturing - * of GPU-drawn areas, e.g. an embedded Edge WebView2. - */ - printWindowFlags |= OS.PW_RENDERFULLCONTENT; - } + /* + * Undocumented flag in windows, which also allows the capturing + * of GPU-drawn areas, e.g. an embedded Edge WebView2. + */ + printWindowFlags |= OS.PW_RENDERFULLCONTENT; printWidget (topHandle, hdc, gc, printWindowFlags); if (gdipGraphics != 0) { OS.RestoreDC(hdc, state); 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 5d2c82aadc4..38775af168e 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 @@ -533,11 +533,7 @@ public class Display extends Device implements Executor { private static int ICON_SIZE_AT_100 = retrieveDefaultIconSize(); private static int retrieveDefaultIconSize() { - if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) { - return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100)); - } else { - return 32; - } + return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100)); } /* Skinning support */ @@ -5396,10 +5392,6 @@ private boolean setMonitorSpecificScaling(boolean activate) { } private boolean setDPIAwareness(int desiredDpiAwareness) { - if (OS.WIN32_BUILD < OS.WIN32_BUILD_WIN10_1607) { - System.err.println("***WARNING: the OS version does not support setting DPI awareness."); - return false; - } if (desiredDpiAwareness == OS.GetThreadDpiAwarenessContext()) { return true; } 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 605afbf781a..c663b92740b 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 @@ -2703,23 +2703,11 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac } int getSystemMetrics(int nIndex) { - /* - * DPI dependent metrics were introduced after 2016 version of windows 10 - */ - if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) { - return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom)); - } - return OS.GetSystemMetrics(nIndex); + return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom)); } boolean adjustWindowRectEx(RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle) { - /* - * DPI-dependent version of the method was introduced with Windows 10 Version 1607 - */ - if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) { - return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom)); - } - return OS.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle); + return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom)); }