[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Composite.setBounds always send controlMoved event

Hi all,

in SWT version 3.4RC3 (win32/x86) was added the Composite.setBounds(int x, int y, int width, int height, int flags, boolean defer) method override.

In source Composite.java:889, there's the following line:

  state &= ~RESIZE_OCCURRED | MOVE_OCCURRED;

It seems is missing parentheses, and at every setBounds this produces a controlMoved event, even if a move doesn't happened.
The line should looks like:


  state &= ~(RESIZE_OCCURRED | MOVE_OCCURRED);


The following code snippet show the problem, turning CPU usage at 100% until shell is closed:


----------------------------------------------------------------------
public static void main(String[] args) {
  Display d = Display.getDefault();
  final Shell s = new Shell(d, SWT.CLOSE | SWT.TITLE | SWT.MIN);

  s.addControlListener(new ControlListener() {
    private void setFixedBounds() {
      Rectangle r = s.getMonitor().getClientArea();
      r.height = 100;
      s.setBounds(r);
    }

    @Override
    public void controlMoved(ControlEvent e) {
      s.getDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {
          setFixedBounds();
        }
      });
    }

    @Override
    public void controlResized(ControlEvent e) {
      setFixedBounds();
    }
  });

  s.open();
  s.layout();
  while(!s.isDisposed()) {
    if(!d.readAndDispatch())
      d.sleep();
  }
}
----------------------------------------------------------------------

Thanks,
Enrico