Index: /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp	(revision 59308)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp	(revision 59309)
@@ -44,9 +44,9 @@
 
 /* Qt includes: */
-#ifdef Q_WS_WIN
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
 # if QT_VERSION >= 0x050000
 #  include <QAbstractNativeEventFilter>
 # endif /* QT_VERSION >= 0x050000 */
-#endif /* Q_WS_WIN */
+#endif /* Q_WS_MAC || Q_WS_WIN */
 
 /* GUI includes: */
@@ -82,20 +82,21 @@
 
 
-#ifdef Q_WS_WIN
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
 # if QT_VERSION >= 0x050000
 /** QAbstractNativeEventFilter extension
-  * allowing to handle native Windows (MSG) events.
+  * allowing to handle native platform events.
   * Why do we need it? It's because Qt5 have unhandled
   * well .. let's call it 'a bug' about native keyboard events
   * which come to top-level widget (window) instead of focused sub-widget
-  * which actually supposed to get them. The funny thing is that target of
-  * those events (MSG::hwnd) is indeed top-level widget, not the sub-widget
-  * we expect, so that's probably the reason Qt devs haven't fixed that bug. */
-class WinEventFilter : public QAbstractNativeEventFilter
+  * which actually supposed to get them. The strange thing is that target of
+  * those events on at least Windows host (MSG::hwnd) is indeed window itself,
+  * not the sub-widget we expect, so that's probably the reason Qt devs
+  * haven't fixed that bug so far for Windows and Mac OS X hosts. */
+class PrivateEventFilter : public QAbstractNativeEventFilter
 {
 public:
 
     /** Constructor which takes the passed @a pParent to redirect events to. */
-    WinEventFilter(UIHostComboEditorPrivate *pParent)
+    PrivateEventFilter(UIHostComboEditorPrivate *pParent)
         : m_pParent(pParent)
     {}
@@ -114,5 +115,5 @@
 };
 # endif /* QT_VERSION >= 0x050000 */
-#endif /* Q_WS_WIN */
+#endif /* Q_WS_MAC || Q_WS_WIN */
 
 
@@ -469,8 +470,10 @@
     : m_pReleaseTimer(0)
     , m_fStartNewSequence(true)
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
+# if QT_VERSION >= 0x050000
+    , m_pPrivateEventFilter(0)
+# endif /* QT_VERSION >= 0x050000 */
+#endif /* Q_WS_MAC || Q_WS_WIN */
 #ifdef Q_WS_WIN
-# if QT_VERSION >= 0x050000
-    , m_pWinEventFilter(0)
-# endif /* QT_VERSION >= 0x050000 */
     , m_pAltGrMonitor(0)
 #endif /* Q_WS_WIN */
@@ -487,14 +490,19 @@
     connect(m_pReleaseTimer, SIGNAL(timeout()), this, SLOT(sltReleasePendingKeys()));
 
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
+# if QT_VERSION >= 0x050000
+    /* Prepare private event filter: */
+    m_pPrivateEventFilter = new PrivateEventFilter(this);
+    qApp->installNativeEventFilter(m_pPrivateEventFilter);
+# endif /* QT_VERSION >= 0x050000 */
+#endif /* Q_WS_MAC || Q_WS_WIN */
+
 #if defined(Q_WS_MAC)
     m_uDarwinKeyModifiers = 0;
+# if QT_VERSION < 0x050000
     UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
     ::DarwinGrabKeyboard(false /* just modifiers */);
+# endif /* QT_VERSION < 0x050000 */
 #elif defined(Q_WS_WIN)
-# if QT_VERSION >= 0x050000
-    /* Prepare Windows event filter: */
-    m_pWinEventFilter = new WinEventFilter(this);
-    qApp->installNativeEventFilter(m_pWinEventFilter);
-# endif /* QT_VERSION >= 0x050000 */
     /* Prepare AltGR monitor: */
     m_pAltGrMonitor = new WinAltGrMonitor;
@@ -508,17 +516,22 @@
 {
 #if defined(Q_WS_MAC)
+# if QT_VERSION < 0x050000
     ::DarwinReleaseKeyboard();
     UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
+# endif /* QT_VERSION < 0x050000 */
 #elif defined(Q_WS_WIN)
     /* Cleanup AltGR monitor: */
     delete m_pAltGrMonitor;
     m_pAltGrMonitor = 0;
+#endif /* Q_WS_WIN */
+
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
 # if QT_VERSION >= 0x050000
-    /* Cleanup Windows event filter: */
-    qApp->removeNativeEventFilter(m_pWinEventFilter);
-    delete m_pWinEventFilter;
-    m_pWinEventFilter = 0;
+    /* Cleanup private event filter: */
+    qApp->removeNativeEventFilter(m_pPrivateEventFilter);
+    delete m_pPrivateEventFilter;
+    m_pPrivateEventFilter = 0;
 # endif /* QT_VERSION >= 0x050000 */
-#endif /* Q_WS_WIN */
+#endif /* Q_WS_MAC || Q_WS_WIN */
 }
 
@@ -568,5 +581,61 @@
 bool UIHostComboEditorPrivate::nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult)
 {
-# if defined(Q_WS_WIN)
+# if defined(Q_WS_MAC)
+
+    /* Make sure it's generic NSEvent: */
+    if (eventType != "mac_generic_NSEvent")
+        return QLineEdit::nativeEvent(eventType, pMessage, pResult);
+    EventRef event = (EventRef)darwinCocoaToCarbonEvent(pMessage);
+
+    /* Check if some NSEvent should be filtered out.
+     * Returning @c true means filtering-out,
+     * Returning @c false means passing event to Qt. */
+    switch(::GetEventClass(event))
+    {
+        /* Watch for keyboard-events: */
+        case kEventClassKeyboard:
+        {
+            switch(::GetEventKind(event))
+            {
+                /* Watch for keyboard-modifier-events: */
+                case kEventRawKeyModifiersChanged:
+                {
+                    /* Get modifier mask: */
+                    UInt32 modifierMask = 0;
+                    ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32,
+                                        NULL, sizeof(modifierMask), NULL, &modifierMask);
+                    modifierMask = ::DarwinAdjustModifierMask(modifierMask, pMessage);
+
+                    /* Do not handle unchanged masks: */
+                    UInt32 uChanged = m_uDarwinKeyModifiers ^ modifierMask;
+                    if (!uChanged)
+                        break;
+
+                    /* Convert to keycode: */
+                    unsigned uKeyCode = ::DarwinModifierMaskToDarwinKeycode(uChanged);
+
+                    /* Do not handle empty and multiple modifier changes: */
+                    if (!uKeyCode || uKeyCode == ~0U)
+                        break;
+
+                    /* Handle key-event: */
+                    if (processKeyEvent(uKeyCode, uChanged & modifierMask))
+                    {
+                        /* Save the new modifier mask state: */
+                        m_uDarwinKeyModifiers = modifierMask;
+                        return true;
+                    }
+                    break;
+                }
+                default:
+                    break;
+            }
+            break;
+        }
+        default:
+            break;
+    }
+
+# elif defined(Q_WS_WIN)
 
     /* Make sure it's generic MSG event: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h	(revision 59308)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h	(revision 59309)
@@ -31,8 +31,10 @@
 class QIToolButton;
 class UIHostComboEditorPrivate;
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
+# if QT_VERSION >= 0x050000
+class PrivateEventFilter;
+# endif /* QT_VERSION >= 0x050000 */
+#endif /* Q_WS_MAC || Q_WS_WIN */
 #ifdef Q_WS_WIN
-# if QT_VERSION >= 0x050000
-class WinEventFilter;
-# endif /* QT_VERSION >= 0x050000 */
 class WinAltGrMonitor;
 #endif /* Q_WS_WIN */
@@ -185,16 +187,19 @@
     bool m_fStartNewSequence;
 
+#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
+# if QT_VERSION >= 0x050000
+    /** Mac, Win: Holds the native event filter instance. */
+    PrivateEventFilter *m_pPrivateEventFilter;
+    /** Mac, Win: Allows the native event filter to
+      * redirect events directly to nativeEvent handler. */
+    friend class PrivateEventFilter;
+# endif /* QT_VERSION >= 0x050000 */
+#endif /* Q_WS_MAC || Q_WS_WIN */
+
 #if defined(Q_WS_MAC)
-     /* The current modifier key mask. Used to figure out which modifier
+    /** Mac: Holds the current modifier key mask. Used to figure out which modifier
       * key was pressed when we get a kEventRawKeyModifiersChanged event. */
-     uint32_t m_uDarwinKeyModifiers;
+    uint32_t m_uDarwinKeyModifiers;
 #elif defined(Q_WS_WIN)
-# if QT_VERSION >= 0x050000
-    /** Win: Holds the native event filter instance. */
-    WinEventFilter *m_pWinEventFilter;
-    /** Win: Allows the native event filter to
-      * redirect events directly to nativeEvent handler. */
-    friend class WinEventFilter;
-# endif /* QT_VERSION >= 0x050000 */
     /** Win: Holds the object monitoring key event
       * stream for problematic AltGr events. */
