From ca1dc097c11cb3dc61bde47fc188deb8bbf21bc1 Mon Sep 17 00:00:00 2001 From: Markus Keller Date: Thu, 8 Nov 2012 21:43:06 +0100 Subject: Bug 245670: [Preferences] Regression: Preferences dialog reveals focus widget when shell is activated --- .../org/eclipse/swt/custom/ScrolledComposite.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ScrolledComposite.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ScrolledComposite.java index f115784c4b..fc7a513a0f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ScrolledComposite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ScrolledComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation 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 @@ -113,6 +113,7 @@ public class ScrolledComposite extends Composite { boolean expandVertical = false; boolean alwaysShowScroll = false; boolean showFocusedControl = false; + boolean showNextFocusedControl = true; /** * Constructs a new instance of this class given its parent @@ -173,9 +174,18 @@ public ScrolledComposite(Composite parent, int style) { filter = new Listener() { public void handleEvent(Event event) { - if (event.widget instanceof Control) { - Control control = (Control) event.widget; - if (contains(control)) showControl(control); + if (event.type == SWT.FocusIn) { + if (!showNextFocusedControl) { + showNextFocusedControl = true; + } else if (event.widget instanceof Control) { + Control control = (Control) event.widget; + if (contains(control)) showControl(control); + } + } else { + Widget w = event.widget; + if (w instanceof Control) { + showNextFocusedControl = w.getDisplay().getActiveShell() == ((Control) w).getShell(); + } } } }; @@ -183,6 +193,7 @@ public ScrolledComposite(Composite parent, int style) { addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { getDisplay().removeFilter(SWT.FocusIn, filter); + getDisplay().removeFilter(SWT.FocusOut, filter); } }); } @@ -645,9 +656,11 @@ public void setShowFocusedControl(boolean show) { if (showFocusedControl == show) return; Display display = getDisplay(); display.removeFilter(SWT.FocusIn, filter); + display.removeFilter(SWT.FocusOut, filter); showFocusedControl = show; if (!showFocusedControl) return; display.addFilter(SWT.FocusIn, filter); + display.addFilter(SWT.FocusOut, filter); Control control = display.getFocusControl(); if (contains(control)) showControl(control); } -- cgit