Skip to content

Commit ad438ae

Browse files
committed
[Win32] Correct bounds/size value of child shells #2862
In point/pixel conversions for bounds/sizes of controls, the parent control's zoom is used to adhere to the most appropriate context when having auto-scale disabled controls. This, however, leads to child shells using the zoom of the parent shells, which can be placed on a different monitor with a different zoom, such that the bounds/sizes of such child shells are wrongly scaled. With this change, shells always use their own zoom for bounds/sizes calculations instead of the one of a potential parent shell. Fixes #2862
1 parent 833d748 commit ad438ae

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,16 @@ void testChildFillsScrollableWithBadlyRoundedClientArea() {
356356
assertTrue(clientAreaInPixels.height <= childBoundsInPixels.y + childBoundsInPixels.height);
357357
}
358358

359+
@Test
360+
void testChildShellGetSize() {
361+
Win32DPIUtils.setMonitorSpecificScaling(true);
362+
Display display = Display.getDefault();
363+
Shell shell = new Shell(display);
364+
shell.nativeZoom = 150;
365+
Shell childShell = new Shell(shell);
366+
childShell.nativeZoom = 100;
367+
childShell.setSize(300, 300);
368+
assertEquals(300, childShell.getSizeInPixels().x);
369+
}
370+
359371
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4886,7 +4886,7 @@ int getShellZoom() {
48864886
return nativeZoom;
48874887
}
48884888

4889-
private int computeGetBoundsZoom() {
4889+
int computeGetBoundsZoom() {
48904890
if (parent != null && !autoScaleDisabled) {
48914891
return parent.getZoom();
48924892
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,4 +2787,14 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) {
27872787
return result;
27882788
}
27892789

2790+
@Override
2791+
int computeBoundsZoom() {
2792+
return getZoom();
2793+
}
2794+
2795+
@Override
2796+
int computeGetBoundsZoom() {
2797+
return getZoom();
2798+
}
2799+
27902800
}

0 commit comments

Comments
 (0)