Skip to content

Commit 08e8683

Browse files
committed
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
1 parent 7d4cca3 commit 08e8683

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

bundles/org.eclipse.jface/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jface;singleton:=true
5-
Bundle-Version: 3.38.100.qualifier
5+
Bundle-Version: 3.38.200.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.jface,

bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/IconAndMessageDialog.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.eclipse.swt.accessibility.AccessibleEvent;
2525
import org.eclipse.swt.graphics.Image;
2626
import org.eclipse.swt.graphics.Point;
27+
import org.eclipse.swt.graphics.Rectangle;
2728
import org.eclipse.swt.widgets.Composite;
2829
import org.eclipse.swt.widgets.Control;
2930
import org.eclipse.swt.widgets.Display;
@@ -296,4 +297,36 @@ private Image getSWTImage(final int imageID) {
296297

297298
}
298299

300+
@Override
301+
protected void configureShell(Shell shell) {
302+
super.configureShell(shell);
303+
if (shouldRecomputeSizeOnDpiChange()) {
304+
shell.addListener(SWT.ZoomChanged, e -> recomputeShellSize(shell));
305+
}
306+
}
307+
308+
/**
309+
* Default behavior: recompute size based on current shell keep the maximum
310+
* among the current bounds and the computed bounds
311+
*
312+
*/
313+
private void recomputeShellSize(Shell shell) {
314+
Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
315+
Rectangle currentBounds = shell.getBounds();
316+
newSize.x = Math.max(currentBounds.width, newSize.x);
317+
newSize.y = Math.max(currentBounds.height, newSize.y);
318+
shell.setBounds(currentBounds.x, currentBounds.y, newSize.x, newSize.y);
319+
}
320+
321+
/**
322+
* This flag should be set to true if the size of this dialogue has to be
323+
* recomputed on DPI change
324+
*
325+
* @return boolean
326+
* @since 3.38
327+
*/
328+
public boolean shouldRecomputeSizeOnDpiChange() {
329+
return false;
330+
}
331+
299332
}

0 commit comments

Comments
 (0)