- Timestamp:
- Dec 7, 2015 6:53:14 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 104586
- 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 90 90 QString strKeyName; 91 91 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) 93 133 94 134 /* MapVirtualKey doesn't distinguish between right and left vkeys, … … 136 176 } 137 177 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 178 178 #else 179 179 … … 187 187 bool UINativeHotKey::isValidKey(int iKeyCode) 188 188 { 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) 209 190 210 191 UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask(iKeyCode); … … 223 204 return false; 224 205 } 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 */); 225 225 226 226 #else … … 442 442 connect(m_pReleaseTimer, SIGNAL(timeout()), this, SLOT(sltReleasePendingKeys())); 443 443 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) 448 445 m_uDarwinKeyModifiers = 0; 449 446 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this); … … 452 449 /* Prepare AltGR monitor: */ 453 450 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 */ 455 455 } 456 456 457 457 UIHostComboEditorPrivate::~UIHostComboEditorPrivate() 458 458 { 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) 460 463 /* Cleanup AltGR monitor: */ 461 464 delete m_pAltGrMonitor; 462 465 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 */ 467 467 } 468 468 … … 551 551 #else /* QT_VERSION < 0x050000 */ 552 552 553 # if defined(Q_WS_WIN) 553 # if defined(Q_WS_MAC) 554 555 /* static */ 556 bool 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 566 bool 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) 554 612 555 613 bool UIHostComboEditorPrivate::winEvent(MSG *pMsg, long* /* pResult */) … … 623 681 624 682 # 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 */ 684 684 685 685 #endif /* QT_VERSION < 0x050000 */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h
r59041 r59042 144 144 145 145 #if QT_VERSION >= 0x050000 146 /** Qt5: Handles all native events. */ 146 147 bool nativeEvent(const QByteArray &eventType, void *pMessage, long *pResult); 147 148 #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. */ 149 156 bool winEvent(MSG *pMsg, long *pResult); 150 157 # elif defined(Q_WS_X11) 158 /** X11: Qt4: Handles all native events. */ 151 159 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 */ 156 161 #endif /* QT_VERSION < 0x050000 */ 157 162 … … 182 187 uint32_t m_uDarwinKeyModifiers; 183 188 #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. */ 185 191 WinAltGrMonitor *m_pAltGrMonitor; 186 192 #endif /* Q_WS_WIN */
Note:
See TracChangeset
for help on using the changeset viewer.