321 { 113, QT_MAC_MAP_ENUM(Qt::Key_F15) }, |
321 { 113, QT_MAC_MAP_ENUM(Qt::Key_F15) }, |
322 { 106, QT_MAC_MAP_ENUM(Qt::Key_F16) }, |
322 { 106, QT_MAC_MAP_ENUM(Qt::Key_F16) }, |
323 { 0, QT_MAC_MAP_ENUM(0) } |
323 { 0, QT_MAC_MAP_ENUM(0) } |
324 }; |
324 }; |
325 |
325 |
|
326 static qt_mac_enum_mapper qt_mac_private_unicode[] = { |
|
327 { 0xF700, QT_MAC_MAP_ENUM(Qt::Key_Up) }, //NSUpArrowFunctionKey |
|
328 { 0xF701, QT_MAC_MAP_ENUM(Qt::Key_Down) }, //NSDownArrowFunctionKey |
|
329 { 0xF702, QT_MAC_MAP_ENUM(Qt::Key_Left) }, //NSLeftArrowFunctionKey |
|
330 { 0xF703, QT_MAC_MAP_ENUM(Qt::Key_Right) }, //NSRightArrowFunctionKey |
|
331 { 0xF727, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertFunctionKey |
|
332 { 0xF728, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteFunctionKey |
|
333 { 0xF729, QT_MAC_MAP_ENUM(Qt::Key_Home) }, //NSHomeFunctionKey |
|
334 { 0xF72B, QT_MAC_MAP_ENUM(Qt::Key_End) }, //NSEndFunctionKey |
|
335 { 0xF72C, QT_MAC_MAP_ENUM(Qt::Key_PageUp) }, //NSPageUpFunctionKey |
|
336 { 0xF72D, QT_MAC_MAP_ENUM(Qt::Key_PageDown) }, //NSPageDownFunctionKey |
|
337 { 0xF72F, QT_MAC_MAP_ENUM(Qt::Key_ScrollLock) }, //NSScrollLockFunctionKey |
|
338 { 0xF730, QT_MAC_MAP_ENUM(Qt::Key_Pause) }, //NSPauseFunctionKey |
|
339 { 0xF731, QT_MAC_MAP_ENUM(Qt::Key_SysReq) }, //NSSysReqFunctionKey |
|
340 { 0xF735, QT_MAC_MAP_ENUM(Qt::Key_Menu) }, //NSMenuFunctionKey |
|
341 { 0xF738, QT_MAC_MAP_ENUM(Qt::Key_Print) }, //NSPrintFunctionKey |
|
342 { 0xF73A, QT_MAC_MAP_ENUM(Qt::Key_Clear) }, //NSClearDisplayFunctionKey |
|
343 { 0xF73D, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertCharFunctionKey |
|
344 { 0xF73E, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteCharFunctionKey |
|
345 { 0xF741, QT_MAC_MAP_ENUM(Qt::Key_Select) }, //NSSelectFunctionKey |
|
346 { 0xF742, QT_MAC_MAP_ENUM(Qt::Key_Execute) }, //NSExecuteFunctionKey |
|
347 { 0xF746, QT_MAC_MAP_ENUM(Qt::Key_Help) }, //NSHelpFunctionKey |
|
348 { 0xF747, QT_MAC_MAP_ENUM(Qt::Key_Mode_switch) }, //NSModeSwitchFunctionKey |
|
349 { 0, QT_MAC_MAP_ENUM(0) } |
|
350 }; |
|
351 |
326 static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) |
352 static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) |
327 { |
353 { |
328 #ifdef DEBUG_KEY_BINDINGS |
354 #ifdef DEBUG_KEY_BINDINGS |
329 qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); |
355 qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); |
330 #endif |
356 #endif |
375 #ifdef DEBUG_KEY_BINDINGS |
401 #ifdef DEBUG_KEY_BINDINGS |
376 qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); |
402 qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); |
377 #endif |
403 #endif |
378 return qt_mac_keyvkey_symbols[i].qt_code; |
404 return qt_mac_keyvkey_symbols[i].qt_code; |
379 } |
405 } |
|
406 } |
|
407 |
|
408 // check if they belong to key codes in private unicode range |
|
409 if (key >= 0xf700 && key <= 0xf747) { |
|
410 if (key >= 0xf704 && key <= 0xf726) { |
|
411 return Qt::Key_F1 + (key.unicode() - 0xf704) ; |
|
412 } |
|
413 for (int i = 0; qt_mac_private_unicode[i].qt_code; i++) { |
|
414 if (qt_mac_private_unicode[i].mac_code == key) { |
|
415 return qt_mac_private_unicode[i].qt_code; |
|
416 } |
|
417 } |
|
418 |
380 } |
419 } |
381 |
420 |
382 //oh well |
421 //oh well |
383 #ifdef DEBUG_KEY_BINDINGS |
422 #ifdef DEBUG_KEY_BINDINGS |
384 qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); |
423 qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); |
715 sizeof(modifiers), 0, &modifiers); |
754 sizeof(modifiers), 0, &modifiers); |
716 qt_mac_send_modifiers_changed(modifiers, widget); |
755 qt_mac_send_modifiers_changed(modifiers, widget); |
717 return true; |
756 return true; |
718 } |
757 } |
719 |
758 |
720 if (qApp->inputContext() && qApp->inputContext()->isComposing()) { |
759 QInputContext *currentContext = qApp->inputContext(); |
|
760 if (currentContext && currentContext->isComposing()) { |
721 if (ekind == kEventRawKeyDown) { |
761 if (ekind == kEventRawKeyDown) { |
722 QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext()); |
762 QMacInputContext *context = qobject_cast<QMacInputContext*>(currentContext); |
723 if (context) |
763 if (context) |
724 context->setLastKeydownEvent(event); |
764 context->setLastKeydownEvent(event); |
725 } |
765 } |
726 return false; |
766 return false; |
727 } |
767 } |
|
768 // Once we process the key down , we dont need to send the saved event again from |
|
769 // kEventTextInputUnicodeForKeyEvent, so clear it. |
|
770 if (currentContext && ekind == kEventRawKeyDown) { |
|
771 QMacInputContext *context = qobject_cast<QMacInputContext*>(currentContext); |
|
772 if (context) |
|
773 context->setLastKeydownEvent(0); |
|
774 } |
|
775 |
728 //get modifiers |
776 //get modifiers |
729 Qt::KeyboardModifiers modifiers; |
777 Qt::KeyboardModifiers modifiers; |
730 int qtKey; |
778 int qtKey; |
731 QChar ourChar; |
779 QChar ourChar; |
732 if (translateKeyEventInternal(er, event, &qtKey, &ourChar, &modifiers, |
780 if (translateKeyEventInternal(er, event, &qtKey, &ourChar, &modifiers, |
845 } |
893 } |
846 return handled_event; |
894 return handled_event; |
847 } |
895 } |
848 |
896 |
849 void |
897 void |
850 QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *) |
898 QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void * |
|
899 #if defined(QT_MAC_USE_COCOA) |
|
900 unicodeKey // unicode character from NSEvent (modifiers applied) |
|
901 #endif |
|
902 ) |
851 { |
903 { |
852 UInt32 macVirtualKey = 0; |
904 UInt32 macVirtualKey = 0; |
853 GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(macVirtualKey), 0, &macVirtualKey); |
905 GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(macVirtualKey), 0, &macVirtualKey); |
854 if (updateKeyboard()) |
906 if (updateKeyboard()) |
855 QKeyMapper::changeKeyboard(); |
907 QKeyMapper::changeKeyboard(); |
873 int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); |
925 int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); |
874 if (qtkey == Qt::Key_unknown) |
926 if (qtkey == Qt::Key_unknown) |
875 qtkey = unicode.unicode(); |
927 qtkey = unicode.unicode(); |
876 keyLayout[macVirtualKey]->qtKey[i] = qtkey; |
928 keyLayout[macVirtualKey]->qtKey[i] = qtkey; |
877 } |
929 } |
|
930 #ifndef Q_WS_MAC32 |
|
931 else { |
|
932 const QChar unicode(*((UniChar *)unicodeKey)); |
|
933 int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); |
|
934 if (qtkey == Qt::Key_unknown) |
|
935 qtkey = unicode.unicode(); |
|
936 keyLayout[macVirtualKey]->qtKey[i] = qtkey; |
|
937 } |
|
938 #endif |
878 #ifdef Q_WS_MAC32 |
939 #ifdef Q_WS_MAC32 |
879 } else { |
940 } else { |
880 const UInt32 keyModifier = (qt_mac_get_mac_modifiers(ModsTbl[i])); |
941 const UInt32 keyModifier = (qt_mac_get_mac_modifiers(ModsTbl[i])); |
881 |
942 |
882 uchar translatedChar = KeyTranslate(keyboard_layout_format.other, keyModifier | macVirtualKey, &keyboard_dead); |
943 uchar translatedChar = KeyTranslate(keyboard_layout_format.other, keyModifier | macVirtualKey, &keyboard_dead); |