From e9024966202f6bd2eaef5f6ebebe83ee37dcb74e Mon Sep 17 00:00:00 2001 From: Silenio Quarti Date: Fri, 28 Sep 2012 10:09:15 -0400 Subject: Bug 385253 - SWT does not send SWT.KeyDown event when pressing down key in combo control --- .../cocoa/org/eclipse/swt/widgets/Combo.java | 27 ++++++++++++++++++++-- .../cocoa/org/eclipse/swt/widgets/Display.java | 15 ++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java index fb7606e78d..b37b1245d1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java @@ -457,12 +457,12 @@ void createWidget() { } void comboBoxWillDismiss(long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { - display.comboPoppedUp = false; + display.currentCombo = null; listVisible = false; } void comboBoxWillPopUp(long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { - display.comboPoppedUp = true; + display.currentCombo = this; listVisible = true; } @@ -1089,6 +1089,9 @@ void register() { } void releaseWidget () { + if (display.currentCombo == this) { + display.currentCombo = null; + } super.releaseWidget (); if ((style & SWT.READ_ONLY) == 0) { ((NSControl)view).abortEditing(); @@ -1344,6 +1347,26 @@ boolean sendKeyEvent (NSEvent nsEvent, int type) { return result; } +boolean sendTrackingKeyEvent (NSEvent nsEvent, int type) { + /* + * Feature in Cocoa. Combo does not send arrow down/up + * key down events while the list is showing. The fix is + * to send these events when the event is removed from the + * queue. + */ + long /*int*/ modifiers = nsEvent.modifierFlags(); + if ((modifiers & OS.NSShiftKeyMask) == 0) { + short keyCode = nsEvent.keyCode (); + switch (keyCode) { + case 125: /* Arrow Down */ + case 126: /* Arrow Up */ + sendKeyEvent(nsEvent, type); + return true; + } + } + return false; +} + void setBackgroundColor(NSColor nsColor) { if ((style & SWT.READ_ONLY) != 0) { //TODO diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index c128986f69..4c066e658a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -176,7 +176,7 @@ public class Display extends Device { long /*int*/ oldCursorSetProc; Callback cursorSetCallback; - boolean comboPoppedUp = false; + Combo currentCombo; boolean mozillaRunning; static final String MOZILLA_RUNNING = "org.eclipse.swt.internal.mozillaRunning"; //$NON-NLS-1$ @@ -4892,10 +4892,15 @@ long /*int*/ applicationNextEventMatchingMask (long /*int*/ id, long /*int*/ sel * workaround is to detect this case and to not return the event that would trigger * this to happen. */ - if (comboPoppedUp && mozillaRunning && dequeue != 0) { - NSEvent event = new NSEvent(result); - if (event.type() == OS.NSApplicationDefined) { - return 0; + if (dequeue != 0 && currentCombo != null && !currentCombo.isDisposed()) { + NSEvent nsEvent = new NSEvent(result); + if (mozillaRunning) { + if (nsEvent.type() == OS.NSApplicationDefined) { + return 0; + } + } + if (nsEvent.type() == OS.NSKeyDown) { + currentCombo.sendTrackingKeyEvent(nsEvent, SWT.KeyDown); } } if (dequeue != 0 && trackingControl != null && !trackingControl.isDisposed()) { -- cgit