diff options
author | Xi Yan | 2018-06-13 19:28:41 +0000 |
---|---|---|
committer | Eric Williams | 2018-06-15 14:47:16 +0000 |
commit | 3a449ba573dc88c6875f0f7ccd6b3a19476b0468 (patch) | |
tree | 34caa3fa0ed8f8a8881858bf5dcf55e16040cc1c | |
parent | 8e5f991ec961e162dce01a4fa003dcd58eddc0b2 (diff) | |
download | eclipse.platform.swt-3a449ba573dc88c6875f0f7ccd6b3a19476b0468.tar.gz eclipse.platform.swt-3a449ba573dc88c6875f0f7ccd6b3a19476b0468.tar.xz eclipse.platform.swt-3a449ba573dc88c6875f0f7ccd6b3a19476b0468.zip |
Bug 209975 - On GTK PopupList throws an exception while open if the
parent window closes. PopupList also fails to gain focus on open.
Allow PopupList to take focus when it is opened in the FocusListener of
a different widget.
Change-Id: I44b297e091527b8439e867be5150e1572900421d
Signed-off-by: Xi Yan <xixiyan@redhat.com>
2 files changed, 67 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index 01d89b3dbf..21b518afd4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -1731,6 +1731,12 @@ public void open () { } } if (!restored) { + /* If a shell is opened during the FocusOut event of a widget, + * it is required to set focus to all shells except for ON_TOP + * shells in order to maintain consistency with other platforms. + */ + if ((style & SWT.ON_TOP) == 0) display.focusEvent = SWT.None; + if (defaultButton != null && !defaultButton.isDisposed ()) { defaultButton.setFocus (); } else { diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug209975_PopupListOpenFocus.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug209975_PopupListOpenFocus.java new file mode 100644 index 0000000000..1d3d9bac67 --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug209975_PopupListOpenFocus.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.PopupList; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class Bug209975_PopupListOpenFocus { + public static void main(String args[]) { + Display display = new Display(); + Shell shell = new Shell(display); + + GridLayout gridLayout = new GridLayout(2, false); + shell.setLayout(gridLayout); + + Text text1 = new Text(shell, SWT.SINGLE); + Text text2 = new Text(shell, SWT.SINGLE); + text2.setText("Text 2"); + + text1.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + PopupList popupList = new PopupList(shell); + String[] items = new String[100]; + for (int i = 0; i < 100; i++) { + items[i] = "Item " + i; + } + popupList.setItems(items); + Rectangle reactangle = new Rectangle(shell.getBounds().x, shell.getBounds().y, 300, 300); + String chosenItem = popupList.open(reactangle); + if (chosenItem != null) { + text1.setText(chosenItem); + } + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + + } +} |