diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DPITestUtil.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DPITestUtil.java index f105f6bec1..b9bb707e12 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DPITestUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DPITestUtil.java @@ -28,7 +28,8 @@ private DPITestUtil() { public static void changeDPIZoom (Shell shell, int nativeZoom) { DPIUtil.setDeviceZoom(nativeZoom); - Event event = shell.createZoomChangedEvent(nativeZoom, true); + DPIChangeExecution dpiChangeExecution = new DPIChangeExecution(true, null); + Event event = shell.createZoomChangedEvent(nativeZoom, dpiChangeExecution); shell.sendZoomChangedEvent(event, shell); DPIChangeExecution data = (DPIChangeExecution) event.data; waitForDPIChange(shell, TIMEOUT_MILLIS, data.taskCount); 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 f183ced0f2..abfa93c329 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 @@ -4791,7 +4791,8 @@ public boolean setParent (Composite parent) { // If parent changed, zoom level might need to be adjusted int newZoom = parent.nativeZoom; if (newZoom != nativeZoom) { - Event zoomChangedEvent = createZoomChangedEvent(newZoom, false); + DPIChangeExecution dpiChangeExecution = new DPIChangeExecution(false, null); + Event zoomChangedEvent = createZoomChangedEvent(newZoom, dpiChangeExecution); sendZoomChangedEvent(zoomChangedEvent, getShell()); } int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE; @@ -5009,14 +5010,12 @@ LRESULT WM_DESTROY (long wParam, long lParam) { return null; } -Event createZoomChangedEvent(int zoom, boolean asyncExec) { +Event createZoomChangedEvent(int zoom, DPIChangeExecution dpiChangeExecution) { Event event = new Event(); event.type = SWT.ZoomChanged; event.widget = this; event.detail = zoom; event.doit = true; - DPIChangeExecution dpiChangeExecution = new DPIChangeExecution(); - dpiChangeExecution.asyncExec = asyncExec; event.data = dpiChangeExecution; return event; } @@ -5905,7 +5904,13 @@ LRESULT wmScrollChild (long wParam, long lParam) { static class DPIChangeExecution { AtomicInteger taskCount = new AtomicInteger(); - private boolean asyncExec = true; + boolean asyncExec = true; + Rectangle shellBounds; + + public DPIChangeExecution(boolean asyncExec, Rectangle shellBounds) { + this.asyncExec = asyncExec; + this.shellBounds = shellBounds; + } private void process(Control control, Runnable operation) { boolean currentAsyncExec = asyncExec; @@ -5948,6 +5953,9 @@ void sendZoomChangedEvent(Event event, Shell shell) { } if (dpiExecData.decrement()) { if (event.doit) { + if (dpiExecData.shellBounds != null) { + shell.setSizeInPixels(dpiExecData.shellBounds.width, dpiExecData.shellBounds.height); + } shell.layout(true, true); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index 11ee977882..311cbf35d7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -2489,13 +2489,13 @@ private void handleMonitorSpecificDpiChange(int newNativeZoom, Rectangle newBoun // Do not process DPI change for child shells asynchronous to avoid relayouting when // repositioning the child shell to a different monitor upon opening boolean processDpiChangeAsynchronous = getParent() == null; - Event zoomChangedEvent = createZoomChangedEvent(newNativeZoom, processDpiChangeAsynchronous); + DPIChangeExecution dpiChangeExecution = new DPIChangeExecution(processDpiChangeAsynchronous, newBoundsInPixels); + Event zoomChangedEvent = createZoomChangedEvent(newNativeZoom, dpiChangeExecution); if (lastDpiChangeEvent != null) { lastDpiChangeEvent.doit = false; } lastDpiChangeEvent = zoomChangedEvent; notifyListeners(SWT.ZoomChanged, zoomChangedEvent); - this.setBoundsInPixels(newBoundsInPixels.x, newBoundsInPixels.y, newBoundsInPixels.width, newBoundsInPixels.height); } @Override