Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRolf Theunissen2019-03-27 19:56:16 +0000
committerLars Vogel2019-04-02 07:36:51 +0000
commita352fe3d2cc4c9803306f45213aea789cf998600 (patch)
tree6228d4d6ba1dcd74fbb707ff4a9c7c3b4027aa80
parent7f8c58240779633cf9da3c223f3c63c8b98da68c (diff)
downloadeclipse.platform.swt-a352fe3d2cc4c9803306f45213aea789cf998600.tar.gz
eclipse.platform.swt-a352fe3d2cc4c9803306f45213aea789cf998600.tar.xz
eclipse.platform.swt-a352fe3d2cc4c9803306f45213aea789cf998600.zip
Bug 297510 - [Widgets] Calling Composite#setFocus() before shell is
opened sets focus to nowhere Instead of calling forceFocus, call setFocus on when the focus is restored, GTK already uses this behavior. This will propagate the focus to a child of a Container, when a shell becomes visible and active. Change-Id: I1dccdf08820342d6d6253d50ac76e5c41ff0d76b Signed-off-by: Rolf Theunissen <rolf.theunissen@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java4
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java16
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_TableTree.java21
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Composite.java19
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java3
8 files changed, 57 insertions, 32 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java
index 8563ddaf91..d889e35811 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -440,7 +440,7 @@ void reskinChildren (int flags) {
boolean restoreFocus () {
if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
if (savedFocus == null) return false;
- return savedFocus.forceFocus ();
+ return savedFocus.setFocus ();
}
void saveFocus () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
index 166c532d33..3761ba2ce6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -987,20 +987,6 @@ boolean setRadioSelection (boolean value) {
return true;
}
-@Override
-boolean setSavedFocus () {
- /*
- * Feature in Windows. When a radio button gets focus,
- * it selects the button in WM_SETFOCUS. If the previous
- * saved focus widget was a radio button, allowing the shell
- * to automatically restore the focus to the previous radio
- * button will unexpectedly check that button. The fix is to
- * not assign focus to an unselected radio button.
- */
- if ((style & SWT.RADIO) != 0 && !getSelection ()) return false;
- return super.setSavedFocus ();
-}
-
/**
* Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
* <code>RADIO</code>, or <code>TOGGLE</code>.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
index 743540a039..c0ef868153 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3742,10 +3742,6 @@ public void setRegion (Region region) {
this.region = region;
}
-boolean setSavedFocus () {
- return forceFocus ();
-}
-
/**
* Sets the receiver's size to the point specified by the arguments.
* <p>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
index 84fea42667..54269f2c65 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -778,7 +778,7 @@ void reskinChildren (int flags) {
boolean restoreFocus () {
if (display.ignoreRestoreFocus) return true;
if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- if (savedFocus != null && savedFocus.setSavedFocus ()) return true;
+ if (savedFocus != null && savedFocus.setFocus ()) return true;
return false;
}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java
index 6f74ff0994..3430946c55 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CCombo.java
@@ -116,12 +116,6 @@ public void test_computeSizeIIZ() {
public void test_getChildren() {
}
-@Override
-@Test
-public void test_isFocusControl() {
- assertTrue(!ccombo.isFocusControl());
-}
-
@Test
public void test_paste() {
if (SwtTestUtil.isCocoa) {
@@ -213,6 +207,16 @@ public void test_setFocus() {
@Override
@Test
+public void test_setFocus_toChild_afterOpen() {
+}
+
+@Override
+@Test
+public void test_setFocus_toChild_beforeOpen() {
+}
+
+@Override
+@Test
public void test_setFontLorg_eclipse_swt_graphics_Font() {
}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_TableTree.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_TableTree.java
index 492adae203..1801b195ea 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_TableTree.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_TableTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,7 @@ package org.eclipse.swt.tests.junit;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -107,6 +108,24 @@ public void test_selectAll() {
selectAll_helper("selectAll()", new TableTreeItem[] {});
}
+@Override
+@Test
+public void test_setFocus_toChild_afterOpen() {
+ shell.open();
+ composite.setFocus();
+ shell.forceActive();
+ assertTrue("First child widget should have focus", tableTree.getTable().isFocusControl());
+}
+
+@Override
+@Test
+public void test_setFocus_toChild_beforeOpen() {
+ composite.setFocus();
+ shell.open();
+ shell.forceActive();
+ assertTrue("First child widget should have focus", tableTree.getTable().isFocusControl());
+}
+
@Test
public void test_setSelection$Lorg_eclipse_swt_custom_TableTreeItem() {
/* FUTURE: Should also add sub-nodes, and test both single and multi with those.
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Composite.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Composite.java
index 0d1b6bc884..cba3712644 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Composite.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Composite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -115,6 +115,23 @@ public void test_setVisibility_and_sizing() {
compSize.x > 100 && compSize.y > 100); // If this is 1x1 or 0x0 then there was some fault in layout.
}
+@Test
+public void test_setFocus_toChild_afterOpen() {
+ Button focusChild = new Button(composite, SWT.PUSH);
+ shell.open();
+ shell.forceActive();
+ composite.setFocus();
+ assertTrue("First child widget should have focus", focusChild.isFocusControl());
+}
+
+@Test
+public void test_setFocus_toChild_beforeOpen() {
+ Button focusChild = new Button(composite, SWT.PUSH);
+ composite.setFocus();
+ shell.open();
+ shell.forceActive();
+ assertTrue("First child widget should have focus", focusChild.isFocusControl());
+}
@Test
public void test_setTabList$Lorg_eclipse_swt_widgets_Control() {
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java
index 6ec23321b3..17312a4ba6 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java
@@ -522,6 +522,9 @@ public void test_isEnabled() {
@Test
public void test_isFocusControl() {
assertFalse(control.isFocusControl());
+ shell.open();
+ shell.forceActive();
+ assertEquals("Unexpected focus", control.forceFocus(), control.isFocusControl());
}
@Test
public void test_isReparentable() {

Back to the top