From 08e86836650364b61f55f12686ea123d37836d96 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Fri, 22 Aug 2025 17:26:43 +0200 Subject: [PATCH] Add ZoomChanged listener to MessageDialogue When a zoom change occurs, the OS automatically scales the window based on the scale factor. However, since fonts do not always scale linearly, this can cause text in dialogues to be cut off. This change adds a flag shouldRecomputeSizeOnDpiChange if true would add a ZoomChanged listener to IconAndMessageDialogue . With this listener When a zoomChanged event is triggered, the shell size is recomputed so that the contents are fit properly and text is not clipped. The concrete dialogues can set this flag to true if they would need to recompute bounds on DPI change --- .../org.eclipse.jface/META-INF/MANIFEST.MF | 2 +- .../jface/dialogs/IconAndMessageDialog.java | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF index b2c427bf1af..81de89277b6 100644 --- a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface;singleton:=true -Bundle-Version: 3.38.100.qualifier +Bundle-Version: 3.38.200.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.jface, diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IconAndMessageDialog.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IconAndMessageDialog.java index d080c155b97..d19b3e14942 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IconAndMessageDialog.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IconAndMessageDialog.java @@ -24,6 +24,7 @@ import org.eclipse.swt.accessibility.AccessibleEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -296,4 +297,36 @@ private Image getSWTImage(final int imageID) { } + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + if (shouldRecomputeSizeOnDpiChange()) { + shell.addListener(SWT.ZoomChanged, e -> recomputeShellSize(shell)); + } + } + + /** + * Default behavior: recompute size based on current shell keep the maximum + * among the current bounds and the computed bounds + * + */ + private void recomputeShellSize(Shell shell) { + Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false); + Rectangle currentBounds = shell.getBounds(); + newSize.x = Math.max(currentBounds.width, newSize.x); + newSize.y = Math.max(currentBounds.height, newSize.y); + shell.setBounds(currentBounds.x, currentBounds.y, newSize.x, newSize.y); + } + + /** + * This flag should be set to true if the size of this dialogue has to be + * recomputed on DPI change + * + * @return boolean + * @since 3.38 + */ + public boolean shouldRecomputeSizeOnDpiChange() { + return false; + } + }