Skip to content

Commit

Permalink
Text in Dialog was cutoff due to invalid use of AdjustWindowRectEx
Browse files Browse the repository at this point in the history
AdjustWindowRectEx does not take DPI into account. So using
AdjustWindowRectExForDpi and passing the zoom level to retrieve correct
coordinates and scaling accordingly.
  • Loading branch information
ShahzaibIbrahim committed Jan 6, 2025
1 parent b35fc01 commit dfb91cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,7 @@ public static int HRESULT_FROM_WIN32(int x) {
*/
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);
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);
public static final native boolean AllowSetForegroundWindow (int dwProcessId);
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.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());

/* 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.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, hasMenu, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits1, false, bits2);
OS.AdjustWindowRectExForDpi (rect, bits1, false, bits2, getZoom());
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.AdjustWindowRectEx (rect, bits0, false, bits1);
OS.AdjustWindowRectExForDpi (rect, bits0, false, bits1, getZoom());
width = rect.right - rect.left;
height = rect.bottom - rect.top;

Expand Down

0 comments on commit dfb91cd

Please sign in to comment.