|
24 | 24 | import org.eclipse.swt.accessibility.AccessibleEvent;
|
25 | 25 | import org.eclipse.swt.graphics.Image;
|
26 | 26 | import org.eclipse.swt.graphics.Point;
|
| 27 | +import org.eclipse.swt.graphics.Rectangle; |
27 | 28 | import org.eclipse.swt.widgets.Composite;
|
28 | 29 | import org.eclipse.swt.widgets.Control;
|
29 | 30 | import org.eclipse.swt.widgets.Display;
|
@@ -296,4 +297,36 @@ private Image getSWTImage(final int imageID) {
|
296 | 297 |
|
297 | 298 | }
|
298 | 299 |
|
| 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 | + |
299 | 332 | }
|
0 commit comments