| Summary: | Browser.print() steals focus | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | e fergus <efergus> | ||||
| Component: | SWT | Assignee: | Felipe Heidrich <eclipse.felipe> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | major | ||||||
| Priority: | P3 | CC: | eclipse.felipe, Silenio_Quarti | ||||
| Version: | 3.6 | ||||||
| Target Milestone: | 3.7 M5 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
e fergus
I have traced the issue down to Control.printWidget(). One of the two following sections is causing the focus change:
if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
OS.SetWindowLong (hwnd, OS.GWL_STYLE, (bits1 & ~OS.WS_CHILD) | OS.WS_POPUP);
OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE, bits2 | OS.WS_EX_TOOLWINDOW);
}
OR
if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
OS.SetWindowLong (hwnd, OS.GWL_STYLE, bits1);
OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE, bits2);
}
does the problem happen only to Browser ? does the problem happen only to Windows 7 ? (In reply to comment #2) > does the problem happen only to Browser ? > does the problem happen only to Windows 7 ? Sorry but I only have Windows XP & Windows 7 available so I cannot test on other platforms. Out of those two, I was only able to produce this issue on Windows 7. I can confirm that this is an issue for more than just the browser widget. I replaced the browser with a button and that same call to print() did steal the focus from my editor. (In reply to comment #3) > I can confirm that this is an issue for more than just the browser widget. I > replaced the browser with a button and that same call to print() did steal the > focus from my editor. thank you Works for me with this code:
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Text text = new Text(shell, SWT.SINGLE);
text.setText("text.");
final Button button = new Button(shell, SWT.PUSH);
button.setText("button.");
display.addFilter(SWT.KeyDown, new Listener() {
public void handleEvent(Event e) {
if (e.keyCode == SWT.F1) {
Image image = new Image(e.display, 200, 200);
GC gc = new GC(image);
boolean result = button.print(gc);
gc.dispose();
image.dispose();
System.out.println("Button printed okay ? " + result);
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Run the test and give the focus to text control, hit F1, note focus stayed in the text control (and the console shows that the button has printed okay).
(In reply to comment #5) > Works for me with this code: > ... > Run the test and give the focus to text control, hit F1, note focus stayed in > the text control (and the console shows that the button has printed okay). You're correct.. the code you give does not produce the issue. Here is some code that will (which I couldn't reproduce using a button either.. but hopefully it's enough for you to pinpoint the issue): public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Browser browser = new Browser(shell, SWT.NONE); browser.setText("<html><body contentEditable=true><p> </p></body></html>"); final Browser browser2 = new Browser(shell, SWT.NONE); browser2.setVisible(false); display.addFilter(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { if (e.keyCode == SWT.F1) { browser2.setText(browser.getText()); } } }); browser2.addProgressListener(new ProgressAdapter() { public void completed(ProgressEvent event) { Image image = new Image(display, 200, 200); GC gc = new GC(image); boolean result = browser2.print(gc); gc.dispose(); image.dispose(); System.out.println("Browser printed okay ? " + result); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } any idea if there are plans to fix this issue? This was caused by the fix for bug 299714, I'm looking into it. Created attachment 187242 [details]
patch
The problem is that we are reparenting the browser to the desktop and then reparenting back. This reparenting is just to work around and should not change the state of the shell, but focus events are being fired and the state of the shell is changing. The patch puts back the savedFocus control to the right control so the focus goes to the right place when all the reparenting dance is over.
Please try the patch or the next nigthly build and let me know if the case is fixed.
Fixed in HEAD |