Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to prevent resize event to pass to a child(I embed a native window and I don't want it to be resized until the user finishes resizing the Shell)
How to prevent resize event to pass to a child [message #540182] Tue, 15 June 2010 10:02 Go to next message
Marton Sigmond is currently offline Marton Sigmond
Messages: 71
Registered: July 2009
Location: Hungary
Member
Hi,

I have an SWT (RCP) application.
I embed a native window into the widget hierarchy (win32):
// Remove window decoration
embedComp = new Composite(parent, SWT.EMBEDDED);
OS.SetParent(winHandle, embedComp.handle);

Since the embedded native window is heavyweight, I do not want it to be resized as the user drags the border of the SWT Shell (only when the user finally releases the mouse button).

I tried to filter the Resize events on the embedding Composite, but did not help:
display.addFilter(SWT.Resize, new Listener() {
  @Override
  public void handleEvent(final Event event) {
    if (embedComp == event.widget) {
      event.doit = false;
      event.type = SWT.None;
    }
  }
});
The native window still gets resized as the user drags the Shell border.

Please let me know if you have any suggestion.

Thanks,
Marton
Re: How to prevent resize event to pass to a child [message #540188 is a reply to message #540182] Tue, 15 June 2010 10:36 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
display filters work only at the SWT level ,they dont block the native events like resize...

whats the layout of your shell on which you are placing your win32 window.

one thing you can do is add a control listener on the shell and on controlresized apply the layout on the shell and do a .layout

and may be remove the layout after done.


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: How to prevent resize event to pass to a child [message #540236 is a reply to message #540182] Tue, 15 June 2010 13:06 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra Niculai
Messages: 84
Registered: July 2009
Member
Maybe you could override the resize method on the child.
Re: How to prevent resize event to pass to a child [message #540290 is a reply to message #540188] Tue, 15 June 2010 14:32 Go to previous message
Marton Sigmond is currently offline Marton Sigmond
Messages: 71
Registered: July 2009
Location: Hungary
Member
Thanks for the idea, I could use it successfully.

I created a custom Layout, and a shell control listener within it.
When a resize event came in, I set a flag to forbid the layout() method to change anything:
public class MyLayout extends Layout {
	public MyLayout(final Composite composite) {
		final Shell shell = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell();
		final ControlListener ctrlListener = new ControlAdapter() {
			@Override
			public void controlResized(final ControlEvent event) {
				resizeForbidden = true;
				scheduleDoLayout(DO_LAYOUT_DELAY);
			}
		};
		shell.addControlListener(ctrlListener);
		composite.addDisposeListener(new DisposeListener() {
			@Override
			public void widgetDisposed(DisposeEvent e) {
				shell.removeControlListener(ctrlListener);
			}
		});
	}

	@Override
	protected void layout(final Composite composite, final boolean flushCache) {
		if (resizeForbidden) {
			return;
		}

When no more resize events came for 2 secs, I reset the flag, and invoke the composite's layout() method.

Thanks again!
Marton
Previous Topic:Canvas border blinking on resize
Next Topic:Adding animation to Button
Goto Forum:
  


Current Time: Sat Oct 25 16:03:57 GMT 2014

Powered by FUDForum. Page generated in 0.12359 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software