Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335566 - Disposing a shell when it's deactivated fails to grant focus to its parent shell even though an event is sent
Summary: Disposing a shell when it's deactivated fails to grant focus to its parent sh...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 332644
  Show dependency tree
 
Reported: 2011-01-27 08:06 EST by Remy Suen CLA
Modified: 2019-09-24 13:49 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2011-01-27 08:06:17 EST
I20110124-1800

1. Run the snippet. You will get one focus print statement.
2. Hit 'Space' to create the popup.
3. Try Alt+Tabbing to another window or clicking somewhere else.
4. The popup disappears and you will get a second focus print statement. However, the focus is not actually on the button. Tabbing to try to iterate over controls does not work. To get the shell working again, you can Alt+Tab to another window and then back to it, then the button will have the proper focus rectangle again.

Display display = new Display();
Shell master = new Shell(display, SWT.SHELL_TRIM);
master.setSize(300, 200);
master.setLayout(new GridLayout());
final Shell popup = new Shell(master, SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM);
popup.setSize(200, 100);
popup.addListener(SWT.Deactivate, new Listener() {
  public void handleEvent(Event event) {
    popup.dispose();
  }
});

Button b = new Button(master, SWT.PUSH);
b.setText("Popup"); //$NON-NLS-1$
b.addFocusListener(new FocusAdapter() {
  public void focusGained(FocusEvent e) {
    System.out.println("focusGained"); //$NON-NLS-1$
  }
});
b.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event event) {
    popup.setVisible(true);
    popup.setFocus();
  }
});

master.open();

while (!master.isDisposed()) {
  if (!display.readAndDispatch())
    display.sleep();
}
display.dispose();
Comment 1 Dani Megert CLA 2011-01-27 08:11:01 EST
*** Bug 332644 has been marked as a duplicate of this bug. ***
Comment 2 Remy Suen CLA 2011-01-27 09:20:34 EST
I considered working around the problem by listening for a FocusOut event instead but that ended disastrously in an NPE.

Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.swt.widgets.Decorations.saveFocus(Decorations.java:834)
	at org.eclipse.swt.widgets.Decorations.WM_KILLFOCUS(Decorations.java:1709)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4541)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4946)
	at org.eclipse.swt.internal.win32.OS.PeekMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.PeekMessage(OS.java:3088)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3710)
	at Main.main(Main.java:169)

Display display = new Display();
Shell master = new Shell(display, SWT.SHELL_TRIM);
master.setSize(300, 200);
master.setLayout(new GridLayout());
final Shell popup = new Shell(master, SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM);
popup.setSize(200, 100);
popup.addListener(SWT.FocusOut, new Listener() {
  public void handleEvent(Event event) {
    popup.dispose();
  }
});

Button b = new Button(master, SWT.PUSH);
b.setText("Popup"); //$NON-NLS-1$
b.addFocusListener(new FocusAdapter() {
  public void focusGained(FocusEvent e) {
    System.out.println("focusGained"); //$NON-NLS-1$
  }
});
b.addListener(SWT.Selection, new Listener() {
  public void handleEvent(Event event) {
    popup.setVisible(true);
    popup.setFocus();
  }
});

master.open();

while (!master.isDisposed()) {
  if (!display.readAndDispatch())
    display.sleep();
}
display.dispose();
Comment 3 Lars Vogel CLA 2019-09-24 13:49:55 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.