VirtualBox

Changeset 59042 in vbox for trunk


Ignore:
Timestamp:
Dec 7, 2015 6:53:14 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
104586
Message:

FE/Qt: Qt5 migration (part 33): Reordering native stuff in 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

    r59041 r59042  
    9090    QString strKeyName;
    9191
    92 #if defined(Q_WS_WIN)
     92#if defined(Q_WS_MAC)
     93
     94    UInt32 modMask = DarwinKeyCodeToDarwinModifierMask(iKeyCode);
     95    switch (modMask)
     96    {
     97        case shiftKey:
     98        case optionKey:
     99        case controlKey:
     100        case cmdKey:
     101            strKeyName = UIHostComboEditor::tr("Left ");
     102            break;
     103        case rightShiftKey:
     104        case rightOptionKey:
     105        case rightControlKey:
     106        case kEventKeyModifierRightCmdKeyMask:
     107            strKeyName = UIHostComboEditor::tr("Right ");
     108            break;
     109        default:
     110            AssertMsgFailedReturn(("modMask=%#x\n", modMask), QString());
     111    }
     112    switch (modMask)
     113    {
     114        case shiftKey:
     115        case rightShiftKey:
     116            strKeyName += QChar(kShiftUnicode);
     117            break;
     118        case optionKey:
     119        case rightOptionKey:
     120            strKeyName += QChar(kOptionUnicode);
     121            break;
     122        case controlKey:
     123        case rightControlKey:
     124            strKeyName += QChar(kControlUnicode);
     125            break;
     126        case cmdKey:
     127        case kEventKeyModifierRightCmdKeyMask:
     128            strKeyName += QChar(kCommandUnicode);
     129            break;
     130    }
     131
     132#elif defined(Q_WS_WIN)
    93133
    94134    /* MapVirtualKey doesn't distinguish between right and left vkeys,
     
    136176    }
    137177
    138 #elif defined(Q_WS_MAC)
    139 
    140     UInt32 modMask = DarwinKeyCodeToDarwinModifierMask(iKeyCode);
    141     switch (modMask)
    142     {
    143         case shiftKey:
    144         case optionKey:
    145         case controlKey:
    146         case cmdKey:
    147             strKeyName = UIHostComboEditor::tr("Left ");
    148             break;
    149         case rightShiftKey:
    150         case rightOptionKey:
    151         case rightControlKey:
    152         case kEventKeyModifierRightCmdKeyMask:
    153             strKeyName = UIHostComboEditor::tr("Right ");
    154             break;
    155         default:
    156             AssertMsgFailedReturn(("modMask=%#x\n", modMask), QString());
    157     }
    158     switch (modMask)
    159     {
    160         case shiftKey:
    161         case rightShiftKey:
    162             strKeyName += QChar(kShiftUnicode);
    163             break;
    164         case optionKey:
    165         case rightOptionKey:
    166             strKeyName += QChar(kOptionUnicode);
    167             break;
    168         case controlKey:
    169         case rightControlKey:
    170             strKeyName += QChar(kControlUnicode);
    171             break;
    172         case cmdKey:
    173         case kEventKeyModifierRightCmdKeyMask:
    174             strKeyName += QChar(kCommandUnicode);
    175             break;
    176     }
    177 
    178178#else
    179179
     
    187187bool UINativeHotKey::isValidKey(int iKeyCode)
    188188{
    189 #if defined(Q_WS_WIN)
    190 
    191     return ((iKeyCode >= VK_SHIFT && iKeyCode <= VK_CAPITAL) ||
    192             (iKeyCode >= VK_LSHIFT && iKeyCode <= VK_RMENU) ||
    193             (iKeyCode >= VK_F1 && iKeyCode <= VK_F24) ||
    194             iKeyCode == VK_NUMLOCK || iKeyCode == VK_SCROLL ||
    195             iKeyCode == VK_LWIN || iKeyCode == VK_RWIN ||
    196             iKeyCode == VK_APPS ||
    197             iKeyCode == VK_PRINT);
    198 
    199 #elif defined(Q_WS_X11)
    200 
    201     return (IsModifierKey(iKeyCode) /* allow modifiers */ ||
    202             IsFunctionKey(iKeyCode) /* allow function keys */ ||
    203             IsMiscFunctionKey(iKeyCode) /* allow miscellaneous function keys */ ||
    204             iKeyCode == XK_Scroll_Lock /* allow 'Scroll Lock' missed in IsModifierKey() */) &&
    205            (iKeyCode != NoSymbol /* ignore some special symbol */ &&
    206             iKeyCode != XK_Insert /* ignore 'insert' included into IsMiscFunctionKey */);
    207 
    208 #elif defined(Q_WS_MAC)
     189#if defined(Q_WS_MAC)
    209190
    210191    UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask(iKeyCode);
     
    223204            return false;
    224205    }
     206
     207#elif defined(Q_WS_WIN)
     208
     209    return ((iKeyCode >= VK_SHIFT && iKeyCode <= VK_CAPITAL) ||
     210            (iKeyCode >= VK_LSHIFT && iKeyCode <= VK_RMENU) ||
     211            (iKeyCode >= VK_F1 && iKeyCode <= VK_F24) ||
     212            iKeyCode == VK_NUMLOCK || iKeyCode == VK_SCROLL ||
     213            iKeyCode == VK_LWIN || iKeyCode == VK_RWIN ||
     214            iKeyCode == VK_APPS ||
     215            iKeyCode == VK_PRINT);
     216
     217#elif defined(Q_WS_X11)
     218
     219    return (IsModifierKey(iKeyCode) /* allow modifiers */ ||
     220            IsFunctionKey(iKeyCode) /* allow function keys */ ||
     221            IsMiscFunctionKey(iKeyCode) /* allow miscellaneous function keys */ ||
     222            iKeyCode == XK_Scroll_Lock /* allow 'Scroll Lock' missed in IsModifierKey() */) &&
     223           (iKeyCode != NoSymbol /* ignore some special symbol */ &&
     224            iKeyCode != XK_Insert /* ignore 'insert' included into IsMiscFunctionKey */);
    225225
    226226#else
     
    442442    connect(m_pReleaseTimer, SIGNAL(timeout()), this, SLOT(sltReleasePendingKeys()));
    443443
    444 #if defined(Q_WS_X11)
    445      /* Initialize the X keyboard subsystem: */
    446      initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes"));
    447 #elif defined(Q_WS_MAC)
     444#if defined(Q_WS_MAC)
    448445     m_uDarwinKeyModifiers = 0;
    449446     UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
     
    452449    /* Prepare AltGR monitor: */
    453450    m_pAltGrMonitor = new WinAltGrMonitor;
    454 #endif /* Q_WS_WIN */
     451#elif defined(Q_WS_X11)
     452     /* Initialize the X keyboard subsystem: */
     453     initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes"));
     454#endif /* Q_WS_X11 */
    455455}
    456456
    457457UIHostComboEditorPrivate::~UIHostComboEditorPrivate()
    458458{
    459 #if defined(Q_WS_WIN)
     459#if defined(Q_WS_MAC)
     460    ::DarwinReleaseKeyboard();
     461    UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
     462#elif defined(Q_WS_WIN)
    460463    /* Cleanup AltGR monitor: */
    461464    delete m_pAltGrMonitor;
    462465    m_pAltGrMonitor = 0;
    463 #elif defined(Q_WS_MAC)
    464     ::DarwinReleaseKeyboard();
    465     UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
    466 #endif /* Q_WS_MAC */
     466#endif /* Q_WS_WIN */
    467467}
    468468
     
    551551#else /* QT_VERSION < 0x050000 */
    552552
    553 # if defined(Q_WS_WIN)
     553# if defined(Q_WS_MAC)
     554
     555/* static */
     556bool UIHostComboEditorPrivate::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
     557{
     558    UIHostComboEditorPrivate *pEditor = static_cast<UIHostComboEditorPrivate*>(pvUser);
     559    EventRef inEvent = (EventRef)pvCarbonEvent;
     560    UInt32 EventClass = ::GetEventClass(inEvent);
     561    if (EventClass == kEventClassKeyboard)
     562        return pEditor->darwinKeyboardEvent(pvCocoaEvent, inEvent);
     563    return false;
     564}
     565
     566bool UIHostComboEditorPrivate::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
     567{
     568    /* Ignore key changes unless we're the focus widget: */
     569    if (!hasFocus())
     570        return false;
     571
     572    UInt32 eventKind = ::GetEventKind(inEvent);
     573    switch (eventKind)
     574    {
     575        //case kEventRawKeyDown:
     576        //case kEventRawKeyUp:
     577        //case kEventRawKeyRepeat:
     578        case kEventRawKeyModifiersChanged:
     579        {
     580            /* Get modifier mask: */
     581            UInt32 modifierMask = 0;
     582            ::GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
     583                                sizeof(modifierMask), NULL, &modifierMask);
     584            modifierMask = ::DarwinAdjustModifierMask(modifierMask, pvCocoaEvent);
     585            UInt32 changed = m_uDarwinKeyModifiers ^ modifierMask;
     586
     587            if (!changed)
     588                break;
     589
     590            /* Convert to keycode: */
     591            unsigned uKeyCode = ::DarwinModifierMaskToDarwinKeycode(changed);
     592
     593            if (!uKeyCode || uKeyCode == ~0U)
     594                return false;
     595
     596            /* Process the key event: */
     597            if (processKeyEvent(uKeyCode, changed & modifierMask))
     598            {
     599                /* Save the new modifier mask state. */
     600                m_uDarwinKeyModifiers = modifierMask;
     601                return true;
     602            }
     603            break;
     604        }
     605        default:
     606            break;
     607    }
     608    return false;
     609}
     610
     611# elif defined(Q_WS_WIN)
    554612
    555613bool UIHostComboEditorPrivate::winEvent(MSG *pMsg, long* /* pResult */)
     
    623681
    624682#  pragma GCC diagnostic pop
    625 # elif defined(Q_WS_MAC)
    626 
    627 /* static */
    628 bool UIHostComboEditorPrivate::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
    629 {
    630     UIHostComboEditorPrivate *pEditor = static_cast<UIHostComboEditorPrivate*>(pvUser);
    631     EventRef inEvent = (EventRef)pvCarbonEvent;
    632     UInt32 EventClass = ::GetEventClass(inEvent);
    633     if (EventClass == kEventClassKeyboard)
    634         return pEditor->darwinKeyboardEvent(pvCocoaEvent, inEvent);
    635     return false;
    636 }
    637 
    638 bool UIHostComboEditorPrivate::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
    639 {
    640     /* Ignore key changes unless we're the focus widget: */
    641     if (!hasFocus())
    642         return false;
    643 
    644     UInt32 eventKind = ::GetEventKind(inEvent);
    645     switch (eventKind)
    646     {
    647         //case kEventRawKeyDown:
    648         //case kEventRawKeyUp:
    649         //case kEventRawKeyRepeat:
    650         case kEventRawKeyModifiersChanged:
    651         {
    652             /* Get modifier mask: */
    653             UInt32 modifierMask = 0;
    654             ::GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
    655                                 sizeof(modifierMask), NULL, &modifierMask);
    656             modifierMask = ::DarwinAdjustModifierMask(modifierMask, pvCocoaEvent);
    657             UInt32 changed = m_uDarwinKeyModifiers ^ modifierMask;
    658 
    659             if (!changed)
    660                 break;
    661 
    662             /* Convert to keycode: */
    663             unsigned uKeyCode = ::DarwinModifierMaskToDarwinKeycode(changed);
    664 
    665             if (!uKeyCode || uKeyCode == ~0U)
    666                 return false;
    667 
    668             /* Process the key event: */
    669             if (processKeyEvent(uKeyCode, changed & modifierMask))
    670             {
    671                 /* Save the new modifier mask state. */
    672                 m_uDarwinKeyModifiers = modifierMask;
    673                 return true;
    674             }
    675             break;
    676         }
    677         default:
    678             break;
    679     }
    680     return false;
    681 }
    682 
    683 # endif /* Q_WS_MAC */
     683# endif /* Q_WS_X11 */
    684684
    685685#endif /* QT_VERSION < 0x050000 */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h

    r59041 r59042  
    144144
    145145#if QT_VERSION >= 0x050000
     146    /** Qt5: Handles all native events. */
    146147    bool nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult);
    147148#else /* QT_VERSION < 0x050000 */
    148 # if defined(Q_WS_WIN)
     149# if defined(Q_WS_MAC)
     150    /** Mac: Qt4: Handles all native events (static callback). */
     151    static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
     152    /** Mac: Qt4: Handles all native events. */
     153    bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
     154# elif defined(Q_WS_WIN)
     155    /** Win: Qt4: Handles all native events. */
    149156    bool winEvent(MSG *pMsg, long *pResult);
    150157# elif defined(Q_WS_X11)
     158    /** X11: Qt4: Handles all native events. */
    151159    bool x11Event(XEvent *pEvent);
    152 # elif defined(Q_WS_MAC)
    153     static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
    154     bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
    155 # endif /* Q_WS_MAC */
     160# endif /* Q_WS_X11 */
    156161#endif /* QT_VERSION < 0x050000 */
    157162
     
    182187     uint32_t m_uDarwinKeyModifiers;
    183188#elif defined(Q_WS_WIN)
    184     /** Holds the object monitoring key event stream for problematic AltGr events. */
     189    /** Win: Holds the object monitoring key event
     190      * stream for problematic AltGr events. */
    185191    WinAltGrMonitor *m_pAltGrMonitor;
    186192#endif /* Q_WS_WIN */
Note: See TracChangeset for help on using the changeset viewer.

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