Skip to content

Commit f82b982

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 ZoomChanged listener to IconAndMessageDialogue. When a zoomChanged event is triggered, the shell size is recomputed so that the contents are fit properly and text is not clipped.
1 parent 7d4cca3 commit f82b982

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-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: 4.0.0.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: 21 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,24 @@ private Image getSWTImage(final int imageID) {
296297

297298
}
298299

300+
@Override
301+
protected void configureShell(Shell shell) {
302+
super.configureShell(shell);
303+
shell.addListener(SWT.ZoomChanged, e -> updateShellSize(shell));
304+
}
305+
306+
/**
307+
* Default behavior: recompute size based on current shell keep the maximum
308+
* among the current bounds and the computed bounds
309+
*
310+
* @since 4.0
311+
*/
312+
protected void updateShellSize(Shell shell) {
313+
Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
314+
Rectangle currentBounds = shell.getBounds();
315+
newSize.x = Math.max(currentBounds.width, newSize.x);
316+
newSize.y = Math.max(currentBounds.height, newSize.y);
317+
shell.setBounds(currentBounds.x, currentBounds.y, newSize.x, newSize.y);
318+
}
319+
299320
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import org.eclipse.swt.SWT;
2121
import org.eclipse.swt.custom.CLabel;
2222
import org.eclipse.swt.graphics.Image;
23+
import org.eclipse.swt.graphics.Point;
2324
import org.eclipse.swt.layout.GridData;
2425
import org.eclipse.swt.layout.GridLayout;
2526
import org.eclipse.swt.widgets.Button;
2627
import org.eclipse.swt.widgets.Composite;
2728
import org.eclipse.swt.widgets.Control;
29+
import org.eclipse.swt.widgets.Event;
2830
import org.eclipse.swt.widgets.Label;
31+
import org.eclipse.swt.widgets.Listener;
2932
import org.eclipse.swt.widgets.Shell;
3033

3134
/**
@@ -283,6 +286,13 @@ protected void configureShell(Shell shell) {
283286
if (titleImage != null) {
284287
shell.setImage(titleImage);
285288
}
289+
shell.addListener(SWT.ZoomChanged, new Listener() {
290+
@Override
291+
public void handleEvent(Event e) {
292+
Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
293+
shell.setBounds(shell.getBounds().x, shell.getBounds().y, newSize.x, newSize.y);
294+
}
295+
});
286296
}
287297

288298
@Override

0 commit comments

Comments
 (0)