Bug 73422 - FocusLost event when forking UI runnable
Summary: FocusLost event when forking UI runnable
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-07 22:59 EDT by Randy Hudson CLA
Modified: 2004-10-13 13:02 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2004-09-07 22:59:28 EDT
When getWorkbenchWindow().run(false, false, IRunnableWithProgress)
is called, all of the workbench shells are temporarily disabled.

Disabling the shells causes a FocusLost event to occur, which affects the 
behavior of the application.

public class Bug68003 {

static final int INITIAL = 0;
static final int DRAGGING = 1;
static final int ABORTED = 2;

private static int state = INITIAL;
	
public static void main(String[] args) {
	Display display = new Display();
	final Shell shell = new Shell();
	shell.setLayout(new GridLayout());
	final Canvas canvas = new Canvas(shell, SWT.BORDER);
	canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
	
	//Make the canvas focusable
	canvas.addKeyListener(new KeyAdapter(){});

	final Label status = new Label(shell, SWT.BORDER);
	status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	
	canvas.addMouseListener(new MouseAdapter() {
		public void mouseDown(MouseEvent e) {
			state = DRAGGING;
			status.setText("drag in progress");
			shell.setEnabled(false);
			shell.setEnabled(true);
		}

		public void mouseUp(MouseEvent e) {
			if (state == DRAGGING) {
				status.setText("drag completed");
			}
			state = INITIAL;
		}
	});
	
	canvas.addFocusListener(new FocusAdapter() {
		public void focusLost(FocusEvent e) {
			if (state == DRAGGING) {
				state = ABORTED;
				status.setText("Drag Aborted due to FocusLost");
			}
		}
	});
	
	shell.setSize(400,300);
	shell.open();
	
	while (!shell.isDisposed())
		if (!display.readAndDispatch())
			display.sleep();
}

}


Have not tested on other platforms.  Any guesses as to whether this occurs 
across all platforms?
Comment 1 Steve Northover CLA 2004-09-09 12:59:47 EDT
Yes.  This was fixed for 3.0.  Prior to that, under some circumstances and on 
some platforms, when you disabled a shell, focus was not reassigned.  It was 
possible to type and have keys go to a child widget in a disabled shell.  This 
has been fixed.  Part of the fix means that focus out events happen because 
focus is reassigned.
Comment 2 Randy Hudson CLA 2004-10-13 13:00:07 EDT
What did you mean by focus is reassigned? to what? Reassigned to NULL?
Comment 3 Steve Northover CLA 2004-10-13 13:02:40 EDT
Yes.  Focus is reassigned to the desktop on Windows and elsewhere on the other 
platforms.