VirtualBox

Changeset 59309 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 11, 2016 3:48:32 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Qt5 migration (part 47): Mac OS X nativeEvent handler implementation for UIHostComboEditor.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp

    r59043 r59309  
    4444
    4545/* Qt includes: */
    46 #ifdef Q_WS_WIN
     46#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
    4747# if QT_VERSION >= 0x050000
    4848#  include <QAbstractNativeEventFilter>
    4949# endif /* QT_VERSION >= 0x050000 */
    50 #endif /* Q_WS_WIN */
     50#endif /* Q_WS_MAC || Q_WS_WIN */
    5151
    5252/* GUI includes: */
     
    8282
    8383
    84 #ifdef Q_WS_WIN
     84#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
    8585# if QT_VERSION >= 0x050000
    8686/** QAbstractNativeEventFilter extension
    87   * allowing to handle native Windows (MSG) events.
     87  * allowing to handle native platform events.
    8888  * Why do we need it? It's because Qt5 have unhandled
    8989  * well .. let's call it 'a bug' about native keyboard events
    9090  * which come to top-level widget (window) instead of focused sub-widget
    91   * which actually supposed to get them. The funny thing is that target of
    92   * those events (MSG::hwnd) is indeed top-level widget, not the sub-widget
    93   * we expect, so that's probably the reason Qt devs haven't fixed that bug. */
    94 class WinEventFilter : public QAbstractNativeEventFilter
     91  * which actually supposed to get them. The strange thing is that target of
     92  * those events on at least Windows host (MSG::hwnd) is indeed window itself,
     93  * not the sub-widget we expect, so that's probably the reason Qt devs
     94  * haven't fixed that bug so far for Windows and Mac OS X hosts. */
     95class PrivateEventFilter : public QAbstractNativeEventFilter
    9596{
    9697public:
    9798
    9899    /** Constructor which takes the passed @a pParent to redirect events to. */
    99     WinEventFilter(UIHostComboEditorPrivate *pParent)
     100    PrivateEventFilter(UIHostComboEditorPrivate *pParent)
    100101        : m_pParent(pParent)
    101102    {}
     
    114115};
    115116# endif /* QT_VERSION >= 0x050000 */
    116 #endif /* Q_WS_WIN */
     117#endif /* Q_WS_MAC || Q_WS_WIN */
    117118
    118119
     
    469470    : m_pReleaseTimer(0)
    470471    , m_fStartNewSequence(true)
     472#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     473# if QT_VERSION >= 0x050000
     474    , m_pPrivateEventFilter(0)
     475# endif /* QT_VERSION >= 0x050000 */
     476#endif /* Q_WS_MAC || Q_WS_WIN */
    471477#ifdef Q_WS_WIN
    472 # if QT_VERSION >= 0x050000
    473     , m_pWinEventFilter(0)
    474 # endif /* QT_VERSION >= 0x050000 */
    475478    , m_pAltGrMonitor(0)
    476479#endif /* Q_WS_WIN */
     
    487490    connect(m_pReleaseTimer, SIGNAL(timeout()), this, SLOT(sltReleasePendingKeys()));
    488491
     492#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     493# if QT_VERSION >= 0x050000
     494    /* Prepare private event filter: */
     495    m_pPrivateEventFilter = new PrivateEventFilter(this);
     496    qApp->installNativeEventFilter(m_pPrivateEventFilter);
     497# endif /* QT_VERSION >= 0x050000 */
     498#endif /* Q_WS_MAC || Q_WS_WIN */
     499
    489500#if defined(Q_WS_MAC)
    490501    m_uDarwinKeyModifiers = 0;
     502# if QT_VERSION < 0x050000
    491503    UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
    492504    ::DarwinGrabKeyboard(false /* just modifiers */);
     505# endif /* QT_VERSION < 0x050000 */
    493506#elif defined(Q_WS_WIN)
    494 # if QT_VERSION >= 0x050000
    495     /* Prepare Windows event filter: */
    496     m_pWinEventFilter = new WinEventFilter(this);
    497     qApp->installNativeEventFilter(m_pWinEventFilter);
    498 # endif /* QT_VERSION >= 0x050000 */
    499507    /* Prepare AltGR monitor: */
    500508    m_pAltGrMonitor = new WinAltGrMonitor;
     
    508516{
    509517#if defined(Q_WS_MAC)
     518# if QT_VERSION < 0x050000
    510519    ::DarwinReleaseKeyboard();
    511520    UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
     521# endif /* QT_VERSION < 0x050000 */
    512522#elif defined(Q_WS_WIN)
    513523    /* Cleanup AltGR monitor: */
    514524    delete m_pAltGrMonitor;
    515525    m_pAltGrMonitor = 0;
     526#endif /* Q_WS_WIN */
     527
     528#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
    516529# if QT_VERSION >= 0x050000
    517     /* Cleanup Windows event filter: */
    518     qApp->removeNativeEventFilter(m_pWinEventFilter);
    519     delete m_pWinEventFilter;
    520     m_pWinEventFilter = 0;
     530    /* Cleanup private event filter: */
     531    qApp->removeNativeEventFilter(m_pPrivateEventFilter);
     532    delete m_pPrivateEventFilter;
     533    m_pPrivateEventFilter = 0;
    521534# endif /* QT_VERSION >= 0x050000 */
    522 #endif /* Q_WS_WIN */
     535#endif /* Q_WS_MAC || Q_WS_WIN */
    523536}
    524537
     
    568581bool UIHostComboEditorPrivate::nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult)
    569582{
    570 # if defined(Q_WS_WIN)
     583# if defined(Q_WS_MAC)
     584
     585    /* Make sure it's generic NSEvent: */
     586    if (eventType != "mac_generic_NSEvent")
     587        return QLineEdit::nativeEvent(eventType, pMessage, pResult);
     588    EventRef event = (EventRef)darwinCocoaToCarbonEvent(pMessage);
     589
     590    /* Check if some NSEvent should be filtered out.
     591     * Returning @c true means filtering-out,
     592     * Returning @c false means passing event to Qt. */
     593    switch(::GetEventClass(event))
     594    {
     595        /* Watch for keyboard-events: */
     596        case kEventClassKeyboard:
     597        {
     598            switch(::GetEventKind(event))
     599            {
     600                /* Watch for keyboard-modifier-events: */
     601                case kEventRawKeyModifiersChanged:
     602                {
     603                    /* Get modifier mask: */
     604                    UInt32 modifierMask = 0;
     605                    ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32,
     606                                        NULL, sizeof(modifierMask), NULL, &modifierMask);
     607                    modifierMask = ::DarwinAdjustModifierMask(modifierMask, pMessage);
     608
     609                    /* Do not handle unchanged masks: */
     610                    UInt32 uChanged = m_uDarwinKeyModifiers ^ modifierMask;
     611                    if (!uChanged)
     612                        break;
     613
     614                    /* Convert to keycode: */
     615                    unsigned uKeyCode = ::DarwinModifierMaskToDarwinKeycode(uChanged);
     616
     617                    /* Do not handle empty and multiple modifier changes: */
     618                    if (!uKeyCode || uKeyCode == ~0U)
     619                        break;
     620
     621                    /* Handle key-event: */
     622                    if (processKeyEvent(uKeyCode, uChanged & modifierMask))
     623                    {
     624                        /* Save the new modifier mask state: */
     625                        m_uDarwinKeyModifiers = modifierMask;
     626                        return true;
     627                    }
     628                    break;
     629                }
     630                default:
     631                    break;
     632            }
     633            break;
     634        }
     635        default:
     636            break;
     637    }
     638
     639# elif defined(Q_WS_WIN)
    571640
    572641    /* Make sure it's generic MSG event: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h

    r59043 r59309  
    3131class QIToolButton;
    3232class UIHostComboEditorPrivate;
     33#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     34# if QT_VERSION >= 0x050000
     35class PrivateEventFilter;
     36# endif /* QT_VERSION >= 0x050000 */
     37#endif /* Q_WS_MAC || Q_WS_WIN */
    3338#ifdef Q_WS_WIN
    34 # if QT_VERSION >= 0x050000
    35 class WinEventFilter;
    36 # endif /* QT_VERSION >= 0x050000 */
    3739class WinAltGrMonitor;
    3840#endif /* Q_WS_WIN */
     
    185187    bool m_fStartNewSequence;
    186188
     189#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     190# if QT_VERSION >= 0x050000
     191    /** Mac, Win: Holds the native event filter instance. */
     192    PrivateEventFilter *m_pPrivateEventFilter;
     193    /** Mac, Win: Allows the native event filter to
     194      * redirect events directly to nativeEvent handler. */
     195    friend class PrivateEventFilter;
     196# endif /* QT_VERSION >= 0x050000 */
     197#endif /* Q_WS_MAC || Q_WS_WIN */
     198
    187199#if defined(Q_WS_MAC)
    188      /* The current modifier key mask. Used to figure out which modifier
     200    /** Mac: Holds the current modifier key mask. Used to figure out which modifier
    189201      * key was pressed when we get a kEventRawKeyModifiersChanged event. */
    190      uint32_t m_uDarwinKeyModifiers;
     202    uint32_t m_uDarwinKeyModifiers;
    191203#elif defined(Q_WS_WIN)
    192 # if QT_VERSION >= 0x050000
    193     /** Win: Holds the native event filter instance. */
    194     WinEventFilter *m_pWinEventFilter;
    195     /** Win: Allows the native event filter to
    196       * redirect events directly to nativeEvent handler. */
    197     friend class WinEventFilter;
    198 # endif /* QT_VERSION >= 0x050000 */
    199204    /** Win: Holds the object monitoring key event
    200205      * stream for problematic AltGr events. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette