Skip to content

Commit e5a2838

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Adding native code
1 parent 4ef8a5d commit e5a2838

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -124,6 +124,31 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx)
124124
}
125125
#endif
126126

127+
#ifndef NO_AdjustWindowRectExForDpi
128+
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
129+
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4)
130+
{
131+
RECT _arg0, *lparg0=NULL;
132+
jboolean rc = 0;
133+
134+
OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC);
135+
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
136+
/*
137+
rc = (jboolean)AdjustWindowRectExForDpi(lparg0, arg1, arg2, arg3, arg4);
138+
*/
139+
{
140+
OS_LOAD_FUNCTION(fp, AdjustWindowRectExForDpi)
141+
if (fp) {
142+
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(RECT *, jint, jboolean, jint, jint))fp)(lparg0, arg1, arg2, arg3, arg4);
143+
}
144+
}
145+
fail:
146+
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
147+
OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC);
148+
return rc;
149+
}
150+
#endif
151+
127152
#ifndef NO_AllowSetForegroundWindow
128153
JNIEXPORT jboolean JNICALL OS_NATIVE(AllowSetForegroundWindow)
129154
(JNIEnv *env, jclass that, jint arg0)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
2626
#define SetThreadDpiAwarenessContext_LIB "user32.dll"
2727
#define SystemParametersInfoForDpi_LIB "user32.dll"
28+
#define AdjustWindowRectExForDpi_LIB "winuser.dll"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -30,6 +30,7 @@ typedef enum {
3030
ActivateKeyboardLayout_FUNC,
3131
AddFontResourceEx_FUNC,
3232
AdjustWindowRectEx_FUNC,
33+
AdjustWindowRectExForDpi_FUNC,
3334
AllowDarkModeForWindow_FUNC,
3435
AllowSetForegroundWindow_FUNC,
3536
AlphaBlend_FUNC,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Control computeTabRoot () {
313313
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
314314
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
315315
boolean hasMenu = OS.GetMenu (handle) != 0;
316-
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());
316+
adjustWindowRectEx(rect, bits1, hasMenu, bits2);
317317

318318
/* Get the size of the scroll bars */
319319
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
@@ -472,7 +472,7 @@ void fixDecorations (Decorations newDecorations, Control control, Menu [] menus)
472472
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
473473
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
474474
boolean hasMenu = OS.GetMenu (handle) != 0;
475-
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());
475+
adjustWindowRectEx(rect, bits1, hasMenu, bits2);
476476
width = Math.max (0, width - (rect.right - rect.left));
477477
height = Math.max (0, height - (rect.bottom - rect.top));
478478
return new Rectangle (0, 0, width, height);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
134134
OS.SetRect (rect, x, y, x + width, y + height);
135135
int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE);
136136
int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE);
137-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
137+
adjustWindowRectEx(rect, bits1, false, bits2);
138138
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
139139
if (verticalBar != null) rect.right += getSystemMetrics (OS.SM_CXVSCROLL);
140140
int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ Point getMaximumSizeInPixels () {
10681068
RECT rect = new RECT ();
10691069
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
10701070
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1071-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
1071+
adjustWindowRectEx(rect, bits1, false, bits2);
10721072
height = Math.min (height, rect.bottom - rect.top);
10731073
}
10741074
}
@@ -1109,7 +1109,7 @@ Point getMinimumSizeInPixels () {
11091109
RECT rect = new RECT ();
11101110
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
11111111
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1112-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
1112+
adjustWindowRectEx(rect, bits1, false, bits2);
11131113
height = Math.max (height, rect.bottom - rect.top);
11141114
}
11151115
}
@@ -1815,7 +1815,7 @@ void setMaximumSizeInPixels (int width, int height) {
18151815
RECT rect = new RECT ();
18161816
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
18171817
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1818-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
1818+
adjustWindowRectEx(rect, bits1, false, bits2);
18191819
heightLimit = rect.bottom - rect.top;
18201820
}
18211821
}
@@ -1861,7 +1861,7 @@ void setMinimumSizeInPixels (int width, int height) {
18611861
RECT rect = new RECT ();
18621862
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
18631863
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1864-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
1864+
adjustWindowRectEx(rect, bits1, false, bits2);
18651865
heightLimit = rect.bottom - rect.top;
18661866
}
18671867
}
@@ -2671,7 +2671,7 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) {
26712671
RECT rect = new RECT ();
26722672
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
26732673
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
2674-
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
2674+
adjustWindowRectEx(rect, bits1, false, bits2);
26752675
lpwp.cy = Math.max (lpwp.cy, rect.bottom - rect.top);
26762676
}
26772677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void addVerifyListener (VerifyListener listener) {
320320
bits0 &= ~OS.WS_BORDER;
321321
bits1 |= OS.WS_EX_CLIENTEDGE;
322322
}
323-
OS.AdjustWindowRectExForDpi (rect, bits0, false, bits1, getZoom());
323+
adjustWindowRectEx(rect, bits0, false, bits1);
324324
width = rect.right - rect.left;
325325
height = rect.bottom - rect.top;
326326

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,5 +2708,15 @@ int getSystemMetrics(int nIndex) {
27082708
return OS.GetSystemMetrics(nIndex);
27092709
}
27102710

2711+
boolean adjustWindowRectEx(RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle) {
2712+
/*
2713+
* DPI dependent metrics were introduced after 2016 version of windows 10
2714+
*/
2715+
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
2716+
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, getZoom());
2717+
}
2718+
return OS.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
2719+
}
2720+
27112721

27122722
}

0 commit comments

Comments
 (0)