Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 74001 - Feature request for Shell.setMaximumSize()
Summary: Feature request for Shell.setMaximumSize()
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 6 votes (vote)
Target Milestone: 4.19 M2   Edit
Assignee: Alexandra Buzila CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-15 13:45 EDT by Jens Fransson CLA
Modified: 2021-01-28 05:39 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Fransson CLA 2004-09-15 13:45:29 EDT
The class org.eclipse.swt.widgets.Shell does not allow to intercept a SWT.RESIZE
event BEFORE resizing occurs. Therefore it is not possible to prevent such an
event from being processed by the Shell. 

Such a veto-mechanism would be helpful in order to implement constraints for the
Shell's bounds. Although not commonly used, I find it useful to restict the
range of possible Shell sizes in some cases as an alternative to make the window
a fixed-size dialog. Borland Delphi's VCL also has such a mechanism. It
conveniently allows to set a maximum and a minimum width and height for a window.

Until this may become a reality, I wrote a workaround which has the disadvantage
of making the Shell flicker when the user tries to resize the window into the
forbidden range. The following example enforces a minimum width which is 25%
wider than the standard width (obtained through shell.pack()) and a fixed height:

public MyApp extends ApplicationWindow {
  
  ...

  protected Control createContents(final Composite parent) {
    ...
    constrainWindowBounds();
    return ...;
  }

  /**
   * Dirty way to enforce minimum/maximum window constraints.
   * Unfortunately this results in flickering of the window if
   * the window must be retrofitted into its constrained bounds.
   */
  private void constrainWindowBounds() {
    getShell().pack();
    final Rectangle r = getShell().getBounds();
    final Rectangle minBounds = new Rectangle(r.x, r.y, (r.width * 5) / 4,
r.height);
    getShell().setBounds(minBounds);
    getShell().addControlListener(new ControlListener() {
      public void controlMoved(final ControlEvent e) { }
      public void controlResized(final ControlEvent e) {
        final Rectangle newBounds = getShell().getBounds();
        final Rectangle constrained = new Rectangle(newBounds.x, newBounds.y,
          Math.max(minBounds.width, newBounds.width), minBounds.height);
        if ((newBounds.width != constrained.width) || (newBounds.height !=
constrained.height)) {
          getShell().setBounds(constrained);
        }
      }
    });
  }


I would love to see a way to set constraints on the bounds of a Shell as a new
high-level feature. I would also appreciate to be able to intercept SWT.RESIZE
events before they are being processed by the Shell.

Are there any supporters for this idea?
Comment 1 Steve Northover CLA 2004-09-15 17:49:49 EDT
It's not possible to intercept and veto a shell resize request on all 
platforms.  You can set the minimum size for a Shell using Shell.setMinimimSize
().  We didn't implement Shell.setMaximimSize() because no one seemed to care 
about it.  You could consider reopening this bug report and turning into a 
feature request for Shell.setMaximumSize() which can be implemented on the 
various platforms.
Comment 2 Jens Fransson CLA 2004-09-16 03:30:08 EDT
Hi Steve, 
thank you for your quick answer. I am very pleased to hear that this feature is
already implemented in the development version of SWT! I will wait for the next
stable SWT release in order to use it. Since I don't need a
Shell.setMaximumSize() yet, I leave things as they are for now.
Thank you and keep up the good work!
Regards,
Jens
Comment 3 Jens Fransson CLA 2004-09-16 07:35:43 EDT
I overlooked that I actually do need a Shell.setMaximumSize(), so I reopen this
as a new feature request as suggested.
Comment 4 Steve Northover CLA 2004-09-16 14:49:31 EDT
Ok, but this new API is low priority.
Comment 5 Markus Keller CLA 2010-10-25 20:39:05 EDT
This would also be interesting for the Find/Replace dialog in text editors. That dialog should be resizable horizontally, but since there are no elements with variable height, I'd like to restrict the maximum height.
Comment 6 Eclipse Webmaster CLA 2019-09-06 15:37:35 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 7 Oliver Geith CLA 2020-06-16 05:30:37 EDT
There still is no setMaximumSize(width,height) Method in Shell...  Would be nice to have it to avoid the bad flickering when using SWT.RESIZE event Listener on the shell....
Comment 8 Alexandra Buzila CLA 2020-09-10 06:58:25 EDT
We had a look at this and it looks like setting a maximum size should be supported by all platforms:
- in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE
- in win32: SM_CYMAXTRACK or via MINMAXINFO
- in cocoa: NSWindow#maxSize

We implemented a working POC for Linux and plan to continue with the Windows and macOS versions. If it works as expected we would like to contribute this feature. Would you be interested in the contribution?
Comment 9 Andrey Loskutov CLA 2020-09-10 12:49:17 EDT
(In reply to Alexandra Buzila from comment #8)
> We had a look at this and it looks like setting a maximum size should be
> supported by all platforms:
> - in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE
> - in win32: SM_CYMAXTRACK or via MINMAXINFO
> - in cocoa: NSWindow#maxSize
> 
> We implemented a working POC for Linux and plan to continue with the Windows
> and macOS versions. If it works as expected we would like to contribute this
> feature. Would you be interested in the contribution?

Sure, why not?
Comment 10 Eclipse Genie CLA 2020-09-11 11:13:48 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/169216
Comment 11 Stefan Dirix CLA 2021-01-11 11:18:16 EST
(In reply to Andrey Loskutov from comment #9)
> (In reply to Alexandra Buzila from comment #8)
> > We had a look at this and it looks like setting a maximum size should be
> > supported by all platforms:
> > - in gtk: GdkWindowHints#GDK_HINT_MAX_SIZE
> > - in win32: SM_CYMAXTRACK or via MINMAXINFO
> > - in cocoa: NSWindow#maxSize
> > 
> > We implemented a working POC for Linux and plan to continue with the Windows
> > and macOS versions. If it works as expected we would like to contribute this
> > feature. Would you be interested in the contribution?
> 
> Sure, why not?

As the change didn't make it into Eclipse 2020-12 it would be great if you or someone else could take a look and review the pushed Gerrit Change. It would be nice if the change could make it into 2021-03. Thanks in advance!
Comment 13 Stefan Dirix CLA 2021-01-20 11:38:17 EST
Thank you very much!
Comment 14 Andrey Loskutov CLA 2021-01-20 11:59:42 EST
Many thanks to Alexandra!
Comment 15 Andrey Loskutov CLA 2021-01-20 12:03:02 EST
Reopened : please update N&N notes about new SWT API. 
See https://git.eclipse.org/r/q/project:www.eclipse.org%252Feclipse%252Fnews
Comment 16 Eclipse Genie CLA 2021-01-22 15:54:07 EST
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/175240
Comment 18 Andrey Loskutov CLA 2021-01-28 05:39:24 EST
Thanks Alexandra & Stefan!