From 6c6da5758ad9259cf872589456c996e2834fbe4f Mon Sep 17 00:00:00 2001 From: Silenio Quarti Date: Fri, 20 Apr 2007 19:03:56 +0000 Subject: fix Combo focus when popping up list --- .../motif/org/eclipse/swt/widgets/Combo.java | 9 +++++++ .../motif/org/eclipse/swt/widgets/Control.java | 30 ++++++++++------------ .../motif/org/eclipse/swt/widgets/Display.java | 17 ++++++++++++ .../motif/org/eclipse/swt/widgets/Shell.java | 6 +++++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java index e30abdb34c..2c6d800280 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java @@ -993,6 +993,7 @@ void register () { } void releaseWidget () { super.releaseWidget (); + if (display.focusedCombo == this) display.focusedCombo = null; /* * Bug in Motif. Disposing a Combo while its list is visible * causes Motif to crash. The fix is to hide the drop down @@ -1167,6 +1168,14 @@ public void select (int index) { ignoreSelect = false; } } +void sendFocusEvent (int type) { + Display display = this.display; + Control focusedCombo = display.focusedCombo; + if (type == SWT.FocusIn && focusedCombo != this) { + super.sendFocusEvent (type); + if (!isDisposed ()) display.focusedCombo = this; + } +} boolean sendIMKeyEvent (int type, XKeyEvent xEvent) { int [] argList = {OS.XmNtextField, 0}; OS.XtGetValues (handle, argList, argList.length / 2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java index eb6cedc647..b6c20e9862 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java @@ -1939,6 +1939,17 @@ boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateM if (isDisposed ()) return false; return event.doit; } +void sendFocusEvent (int type) { + Display display = this.display; + if (type == SWT.FocusIn) { + Control focusedCombo = display.focusedCombo; + display.focusedCombo = null; + if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) { + display.sendFocusEvent (focusedCombo, SWT.FocusOut); + } + } + display.sendFocusEvent (this, type); +} void sendHelpEvent (int callData) { Control control = this; while (control != null) { @@ -3383,11 +3394,7 @@ int xFocusIn (XFocusChangeEvent xEvent) { int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window); OS.XmImSetFocusValues (focusHandle, null, 0); } - Display display = this.display; - display.focusEvent = SWT.FocusIn; - sendEvent (SWT.FocusIn); - // widget could be disposed at this point - display.focusEvent = SWT.None; + sendFocusEvent (SWT.FocusIn); return 0; } int xFocusOut (XFocusChangeEvent xEvent) { @@ -3417,17 +3424,8 @@ int xFocusOut (XFocusChangeEvent xEvent) { OS.XmImSetValues (focusHandle, argList2, argList2.length / 2); } } - - /* Issue the focus out event */ - if (display.postFocusOut) { - postEvent (SWT.FocusOut); - } else { - Display display = this.display; - display.focusEvent = SWT.FocusOut; - sendEvent (SWT.FocusOut); - // widget could be disposed at this point - display.focusEvent = SWT.None; - } + + sendFocusEvent (SWT.FocusOut); /* Restore XmNtraversalOn if it was focus was forced */ if (handle == 0) return 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java index 77185c7bb9..942517e214 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java @@ -117,6 +117,7 @@ public class Display extends Device { /* Focus */ int focusEvent; boolean postFocusOut; + Combo focusedCombo; /* Default Fonts, Colors, Insets, Widths and Heights. */ Font defaultFont; @@ -2976,6 +2977,7 @@ void releaseDisplay () { COLOR_INFO_BACKGROUND = null; popups = null; + focusedCombo = null; } void releaseToolTipHandle (int handle) { if (mouseHoverHandle == handle) removeMouseHoverTimeOut (); @@ -3176,6 +3178,21 @@ void sendEvent (int eventType, Event event) { if (eventTable != null) eventTable.sendEvent (event); } } +void sendFocusEvent (Control control, int type) { + if (type == SWT.FocusIn) { + focusEvent = SWT.FocusIn; + control.sendEvent (SWT.FocusIn); + focusEvent = SWT.None; + } else { + if (postFocusOut) { + control.postEvent (SWT.FocusOut); + } else { + focusEvent = SWT.FocusOut; + control.sendEvent (SWT.FocusOut); + focusEvent = SWT.None; + } + } +} /** * Sets the location of the on-screen pointer relative to the top left corner * of the screen. Note: It is typically considered bad practice for a diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java index 9e48374a86..de1b250e77 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java @@ -1814,11 +1814,17 @@ int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatc } break; case OS.FocusOut: + Display display = this.display; if (display.postFocusOut) { postEvent (SWT.Deactivate); } else { sendEvent (SWT.Deactivate); } + Control focusedCombo = display.focusedCombo; + display.focusedCombo = null; + if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) { + display.sendFocusEvent (focusedCombo, SWT.FocusOut); + } break; } } -- cgit