diff options
| author | Eric Williams | 2019-09-10 19:34:35 +0000 |
|---|---|---|
| committer | Eric Williams | 2019-09-11 15:25:46 +0000 |
| commit | 5562fddca07e3abaeec9be17c57902bc96842af2 (patch) | |
| tree | 1245fc97cec76a7b03ade859ed18efce7c279d2c | |
| parent | df49aebd377808395623e6b00a09cf38c17a0354 (diff) | |
| download | eclipse.platform.swt-5562fddca07e3abaeec9be17c57902bc96842af2.tar.gz eclipse.platform.swt-5562fddca07e3abaeec9be17c57902bc96842af2.tar.xz eclipse.platform.swt-5562fddca07e3abaeec9be17c57902bc96842af2.zip | |
Bug 341117: ToolItem traversal does not fire deactivate event.
Send focus[In/Out] events in the parent ToolBar, in order to ensure
traversal events get fired when traversing from a Control to an Item
(like ToolItem). Otherwise Controls won't receive Deactivate events
until the next Control has focus.
Tested on GTK3.24 and X11, using the snippet attached. No AllNonBrowser
JUnit tests fail.
Change-Id: I899195aeef939f0b68fedb34a2f5a37d6e928409
Signed-off-by: Eric Williams <ericwill@redhat.com>
3 files changed, 62 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index 7bdbd8f6fc..5208529e7a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -3828,7 +3828,6 @@ long gtk_event_after (long widget, long gdkEvent) { } } } - sendFocusEvent (focusIn[0] ? SWT.FocusIn : SWT.FocusOut); break; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java index 71a664aa24..663010be29 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java @@ -688,12 +688,14 @@ long gtk_event_after (long widget, long gdkEvent) { long gtk_focus_in_event (long widget, long event) { parent.hasChildFocus = true; parent.currentFocusItem = this; + parent.sendFocusEvent(SWT.FocusIn); return 0; } @Override long gtk_focus_out_event (long widget, long event) { parent.hasChildFocus = false; + parent.sendFocusEvent(SWT.FocusOut); return 0; } diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug341117_ToolItemDeactivateNotSent.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug341117_ToolItemDeactivateNotSent.java new file mode 100644 index 0000000000..9fff61298a --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug341117_ToolItemDeactivateNotSent.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2019 Red Hat and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; + + + +public class Bug341117_ToolItemDeactivateNotSent { + + public static void main(final String[] args) { + Display display = new Display(); + Shell shell = new Shell(display); + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + shell.setLayout(gridLayout); + shell.setSize(100, 140); + ToolBar toolBar = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT); + toolBar.addListener(SWT.Deactivate, event -> System.out.println("Toolbar deactivated")); + toolBar.addListener(SWT.Activate, event -> System.out.println("Toolbar activated")); + ToolItem button = new ToolItem(toolBar, SWT.PUSH); + button.setText("A button"); + addText("Text 1", shell); + addText("Text 2", shell); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } + + private static void addText(final String textString, final Shell shell) { + Text text = new Text(shell, SWT.NONE); + text.setText(textString); + text.addListener(SWT.Deactivate, event -> System.out.println(textString + " deactivated")); + text.addListener(SWT.Activate, event -> System.out.println(textString + " activated")); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + } + +} |
