Modal and Modeless Shells [message #1496819] |
Wed, 03 December 2014 09:42 |
|
Below is a snippet for RAP that creates an APPLICATION_MODAL Shell, with a Button, and when the Button is pressed, creates a child Shell from that parent, which is modeless.
Since the child is modeless, I can refocus/reactivate the parent (Modal) shell and click the Button again to get another modeless child Shell - exactly what I want... except that although I can give the parent Shell focus, it never comes to the front of the Z-Order.
I can do this no problem with a native Windows/C application - it will bring the parent window on top, which is the behaviour I'm looking for.
Please note that RAP's behaviour is the same as SWT, so it isn't a bug in RAP as such, but I'm wondering if there is anyone out there who know hows to make RAP (or SWT for that matter) bring the parent Modal Shell to the top, in the same way that Windows does?
/* DEMONSTRATES Modal-to-Modeless issue for Shells */
package bug.snippet;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class Bugsy {
Display display;
Shell shellModalParent;
public void begin() {
display = new Display();
shellModalParent = new Shell(display, SWT.APPLICATION_MODAL|SWT.CLOSE);
shellModalParent.setSize(300, 300);
shellModalParent.setLocation(20, 20);
FormLayout layout = new FormLayout();
shellModalParent.setLayout(layout);
shellModalParent.setText("Modal parent");
Button butOpen2nd = new Button(shellModalParent, SWT.PUSH);
butOpen2nd.setText("Open child");;
FormData fd = new FormData();
fd.left = new FormAttachment(0, 10);
fd.top = new FormAttachment(0, 10);
fd.right = new FormAttachment(100,-10);
fd.bottom = new FormAttachment(100,-10);
butOpen2nd.setLayoutData(fd);
butOpen2nd.addListener(SWT.Selection, buttonListener);
shellModalParent.open();
}
Listener buttonListener = new Listener() {
public void handleEvent(Event event) {
Shell shellNonModal = new Shell(shellModalParent, SWT.CLOSE);
shellNonModal.setSize(250, 250);
shellNonModal.setLocation(200, 200);
FormLayout layout = new FormLayout();
shellNonModal.setLayout(layout);
shellNonModal.setText("Modeless child");
shellNonModal.open();
}
};
}
A couple of screen shots to explain... first, when I start the application, and click the Button, the child Shell appears on top, as expected:
Now, when I refocus to the parent Shell, the title bar changes colour to show it has focus, and I can access the Button no problem, but the Shell itself remains behind the modelesss child:
Anybody with ideas, would be very useful!
Thanks, John
-
Attachment: Modal1.jpg
(Size: 13.92KB, Downloaded 368 times) -
Attachment: Modal2.jpg
(Size: 14.79KB, Downloaded 387 times)
---
Just because you can doesn't mean you should
|
|
|
Powered by
FUDForum. Page generated in 0.03145 seconds