Skip to content

Commit

Permalink
Adding native code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahzaibIbrahim authored and HeikoKlare committed Jan 9, 2025
1 parent 4ef8a5d commit e5a2838
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 11 deletions.
27 changes: 26 additions & 1 deletion bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -124,6 +124,31 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx)
}
#endif

#ifndef NO_AdjustWindowRectExForDpi
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4)
{
RECT _arg0, *lparg0=NULL;
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);
return rc;
}
#endif

#ifndef NO_AllowSetForegroundWindow
JNIEXPORT jboolean JNICALL OS_NATIVE(AllowSetForegroundWindow)
(JNIEnv *env, jclass that, jint arg0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
#define SetThreadDpiAwarenessContext_LIB "user32.dll"
#define SystemParametersInfoForDpi_LIB "user32.dll"
#define AdjustWindowRectExForDpi_LIB "winuser.dll"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -30,6 +30,7 @@ typedef enum {
ActivateKeyboardLayout_FUNC,
AddFontResourceEx_FUNC,
AdjustWindowRectEx_FUNC,
AdjustWindowRectExForDpi_FUNC,
AllowDarkModeForWindow_FUNC,
AllowSetForegroundWindow_FUNC,
AlphaBlend_FUNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Control computeTabRoot () {
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
boolean hasMenu = OS.GetMenu (handle) != 0;
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());
adjustWindowRectEx(rect, bits1, hasMenu, bits2);

/* Get the size of the scroll bars */
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
Expand Down Expand Up @@ -472,7 +472,7 @@ void fixDecorations (Decorations newDecorations, Control control, Menu [] menus)
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
boolean hasMenu = OS.GetMenu (handle) != 0;
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());
adjustWindowRectEx(rect, bits1, hasMenu, bits2);
width = Math.max (0, width - (rect.right - rect.left));
height = Math.max (0, height - (rect.bottom - rect.top));
return new Rectangle (0, 0, width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
OS.SetRect (rect, x, y, x + width, y + height);
int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
if (verticalBar != null) rect.right += getSystemMetrics (OS.SM_CXVSCROLL);
int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ Point getMaximumSizeInPixels () {
RECT rect = new RECT ();
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
height = Math.min (height, rect.bottom - rect.top);
}
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ Point getMinimumSizeInPixels () {
RECT rect = new RECT ();
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
height = Math.max (height, rect.bottom - rect.top);
}
}
Expand Down Expand Up @@ -1815,7 +1815,7 @@ void setMaximumSizeInPixels (int width, int height) {
RECT rect = new RECT ();
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
heightLimit = rect.bottom - rect.top;
}
}
Expand Down Expand Up @@ -1861,7 +1861,7 @@ void setMinimumSizeInPixels (int width, int height) {
RECT rect = new RECT ();
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
heightLimit = rect.bottom - rect.top;
}
}
Expand Down Expand Up @@ -2671,7 +2671,7 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) {
RECT rect = new RECT ();
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
adjustWindowRectEx(rect, bits1, false, bits2);
lpwp.cy = Math.max (lpwp.cy, rect.bottom - rect.top);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void addVerifyListener (VerifyListener listener) {
bits0 &= ~OS.WS_BORDER;
bits1 |= OS.WS_EX_CLIENTEDGE;
}
OS.AdjustWindowRectExForDpi (rect, bits0, false, bits1, getZoom());
adjustWindowRectEx(rect, bits0, false, bits1);
width = rect.right - rect.left;
height = rect.bottom - rect.top;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2708,5 +2708,15 @@ int getSystemMetrics(int nIndex) {
return OS.GetSystemMetrics(nIndex);
}

boolean adjustWindowRectEx(RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle) {
/*
* DPI dependent metrics were introduced after 2016 version of windows 10
*/
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, getZoom());
}
return OS.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
}


}

0 comments on commit e5a2838

Please sign in to comment.