Changeset 59309 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 11, 2016 3:48:32 PM (9 years ago)
- 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 44 44 45 45 /* Qt includes: */ 46 #if def Q_WS_WIN46 #if defined(Q_WS_MAC) || defined(Q_WS_WIN) 47 47 # if QT_VERSION >= 0x050000 48 48 # include <QAbstractNativeEventFilter> 49 49 # endif /* QT_VERSION >= 0x050000 */ 50 #endif /* Q_WS_ WIN */50 #endif /* Q_WS_MAC || Q_WS_WIN */ 51 51 52 52 /* GUI includes: */ … … 82 82 83 83 84 #if def Q_WS_WIN84 #if defined(Q_WS_MAC) || defined(Q_WS_WIN) 85 85 # if QT_VERSION >= 0x050000 86 86 /** QAbstractNativeEventFilter extension 87 * allowing to handle native Windows (MSG)events.87 * allowing to handle native platform events. 88 88 * Why do we need it? It's because Qt5 have unhandled 89 89 * well .. let's call it 'a bug' about native keyboard events 90 90 * 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. */ 95 class PrivateEventFilter : public QAbstractNativeEventFilter 95 96 { 96 97 public: 97 98 98 99 /** Constructor which takes the passed @a pParent to redirect events to. */ 99 WinEventFilter(UIHostComboEditorPrivate *pParent)100 PrivateEventFilter(UIHostComboEditorPrivate *pParent) 100 101 : m_pParent(pParent) 101 102 {} … … 114 115 }; 115 116 # endif /* QT_VERSION >= 0x050000 */ 116 #endif /* Q_WS_ WIN */117 #endif /* Q_WS_MAC || Q_WS_WIN */ 117 118 118 119 … … 469 470 : m_pReleaseTimer(0) 470 471 , 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 */ 471 477 #ifdef Q_WS_WIN 472 # if QT_VERSION >= 0x050000473 , m_pWinEventFilter(0)474 # endif /* QT_VERSION >= 0x050000 */475 478 , m_pAltGrMonitor(0) 476 479 #endif /* Q_WS_WIN */ … … 487 490 connect(m_pReleaseTimer, SIGNAL(timeout()), this, SLOT(sltReleasePendingKeys())); 488 491 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 489 500 #if defined(Q_WS_MAC) 490 501 m_uDarwinKeyModifiers = 0; 502 # if QT_VERSION < 0x050000 491 503 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this); 492 504 ::DarwinGrabKeyboard(false /* just modifiers */); 505 # endif /* QT_VERSION < 0x050000 */ 493 506 #elif defined(Q_WS_WIN) 494 # if QT_VERSION >= 0x050000495 /* Prepare Windows event filter: */496 m_pWinEventFilter = new WinEventFilter(this);497 qApp->installNativeEventFilter(m_pWinEventFilter);498 # endif /* QT_VERSION >= 0x050000 */499 507 /* Prepare AltGR monitor: */ 500 508 m_pAltGrMonitor = new WinAltGrMonitor; … … 508 516 { 509 517 #if defined(Q_WS_MAC) 518 # if QT_VERSION < 0x050000 510 519 ::DarwinReleaseKeyboard(); 511 520 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 */ 512 522 #elif defined(Q_WS_WIN) 513 523 /* Cleanup AltGR monitor: */ 514 524 delete m_pAltGrMonitor; 515 525 m_pAltGrMonitor = 0; 526 #endif /* Q_WS_WIN */ 527 528 #if defined(Q_WS_MAC) || defined(Q_WS_WIN) 516 529 # if QT_VERSION >= 0x050000 517 /* Cleanup Windowsevent filter: */518 qApp->removeNativeEventFilter(m_p WinEventFilter);519 delete m_p WinEventFilter;520 m_p WinEventFilter = 0;530 /* Cleanup private event filter: */ 531 qApp->removeNativeEventFilter(m_pPrivateEventFilter); 532 delete m_pPrivateEventFilter; 533 m_pPrivateEventFilter = 0; 521 534 # endif /* QT_VERSION >= 0x050000 */ 522 #endif /* Q_WS_ WIN */535 #endif /* Q_WS_MAC || Q_WS_WIN */ 523 536 } 524 537 … … 568 581 bool UIHostComboEditorPrivate::nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult) 569 582 { 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) 571 640 572 641 /* Make sure it's generic MSG event: */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h
r59043 r59309 31 31 class QIToolButton; 32 32 class UIHostComboEditorPrivate; 33 #if defined(Q_WS_MAC) || defined(Q_WS_WIN) 34 # if QT_VERSION >= 0x050000 35 class PrivateEventFilter; 36 # endif /* QT_VERSION >= 0x050000 */ 37 #endif /* Q_WS_MAC || Q_WS_WIN */ 33 38 #ifdef Q_WS_WIN 34 # if QT_VERSION >= 0x05000035 class WinEventFilter;36 # endif /* QT_VERSION >= 0x050000 */37 39 class WinAltGrMonitor; 38 40 #endif /* Q_WS_WIN */ … … 185 187 bool m_fStartNewSequence; 186 188 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 187 199 #if defined(Q_WS_MAC) 188 /* The current modifier key mask. Used to figure out which modifier200 /** Mac: Holds the current modifier key mask. Used to figure out which modifier 189 201 * key was pressed when we get a kEventRawKeyModifiersChanged event. */ 190 202 uint32_t m_uDarwinKeyModifiers; 191 203 #elif defined(Q_WS_WIN) 192 # if QT_VERSION >= 0x050000193 /** Win: Holds the native event filter instance. */194 WinEventFilter *m_pWinEventFilter;195 /** Win: Allows the native event filter to196 * redirect events directly to nativeEvent handler. */197 friend class WinEventFilter;198 # endif /* QT_VERSION >= 0x050000 */199 204 /** Win: Holds the object monitoring key event 200 205 * stream for problematic AltGr events. */
Note:
See TracChangeset
for help on using the changeset viewer.