Changeset 561 for trunk/src/gui/kernel/qkeymapper_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/kernel/qkeymapper_win.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 42 42 #include "qkeymapper_p.h" 43 43 44 #include < windows.h>44 #include <qt_windows.h> 45 45 #include <qdebug.h> 46 46 #include <private/qevent_p.h> … … 58 58 // Implemented elsewhere 59 59 extern "C" LRESULT CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM); 60 Q_CORE_EXPORT bool winPostMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 61 Q_CORE_EXPORT bool winPeekMessage(MSG* msg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, 62 UINT wRemoveMsg); 60 63 61 extern Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id); 64 62 #ifndef LANG_PASHTO … … 436 434 }; 437 435 436 /** 437 Remap return or action key to select key for windows mobile. 438 */ 439 inline int winceKeyBend(int keyCode) 440 { 441 #if defined(Q_OS_WINCE_WM) && defined(QT_KEYPAD_NAVIGATION) 442 // remap return or action key to select key for windows mobile. 443 // will be changed to a table remapping function in the next version (4.6/7). 444 if (keyCode == VK_RETURN && QApplication::keypadNavigationEnabled()) 445 return Qt::Key_Select; 446 else 447 return KeyTbl[keyCode]; 448 #else 449 return KeyTbl[keyCode]; 450 #endif 451 } 452 438 453 #if defined(Q_OS_WINCE) 439 454 // Use the KeyTbl to resolve a Qt::Key out of the virtual keys. … … 468 483 int code = 0; 469 484 QChar unicodeBuffer[5]; 470 int res = 0; 471 if (QSysInfo::WindowsVersion < QSysInfo::WV_NT) 472 res = ToAscii(vk, scancode, kbdBuffer, reinterpret_cast<LPWORD>(unicodeBuffer), 0); 473 else 474 res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); 475 485 int res = ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0); 476 486 if (res) 477 487 code = unicodeBuffer[0].toUpper().unicode(); … … 480 490 // proper Qt::Key_ code 481 491 if (code < 0x20 || code == 0x7f) // Handles res==0 too 482 code = KeyTbl[vk];492 code = winceKeyBend(vk); 483 493 484 494 if (isDeadkey) … … 490 500 Q_GUI_EXPORT int qt_translateKeyCode(int vk) 491 501 { 492 int code = (vk < 0 || vk > 255) ? 0 : KeyTbl[vk];502 int code = winceKeyBend((vk < 0 || vk > 255) ? 0 : vk); 493 503 return code == Qt::Key_unknown ? 0 : code; 494 504 } … … 503 513 } 504 514 return a & 0xff; 505 }506 507 static int inputcharset = CP_ACP;508 static inline QChar wmchar_to_unicode(DWORD c)509 {510 // qt_winMB2QString is the generalization of this function.511 QT_WA({512 return QChar((ushort)c);513 } , {514 char mb[2];515 mb[0] = c & 0xff;516 mb[1] = 0;517 WCHAR wc[1];518 MultiByteToWideChar(inputcharset, MB_PRECOMPOSED, mb, -1, wc, 1);519 return QChar(wc[0]);520 });521 }522 523 static inline QChar imechar_to_unicode(DWORD c)524 {525 // qt_winMB2QString is the generalization of this function.526 QT_WA({527 return QChar((ushort)c);528 } , {529 char mb[3];530 mb[0] = (c >> 8) & 0xff;531 mb[1] = c & 0xff;532 mb[2] = 0;533 WCHAR wc[1];534 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, mb, -1, wc, 1);535 return QChar(wc[0]);536 });537 515 } 538 516 … … 622 600 QKeyMapperPrivate::~QKeyMapperPrivate() 623 601 { 624 clearMappings();625 } 626 627 void QKeyMapperPrivate:: clearMappings()602 deleteLayouts(); 603 } 604 605 void QKeyMapperPrivate::deleteLayouts() 628 606 { 629 607 for (int i = 0; i < 255; ++i) { … … 633 611 } 634 612 } 613 } 614 615 void QKeyMapperPrivate::clearMappings() 616 { 617 deleteLayouts(); 635 618 636 619 /* MAKELCID()'s first argument is a WORD, and GetKeyboardLayout() 637 620 * returns a DWORD. */ 638 // LCID newLCID = MAKELCID(DWORD(GetKeyboardLayout(0)), SORT_DEFAULT); 621 622 LCID newLCID = MAKELCID((DWORD)GetKeyboardLayout(0), SORT_DEFAULT); 639 623 // keyboardInputLocale = qt_localeFromLCID(newLCID); 640 LCID newLCID = MAKELCID( 641 reinterpret_cast<long>(GetKeyboardLayout(0)), 642 SORT_DEFAULT 643 ); 644 keyboardInputLocale = qt_localeFromLCID(newLCID); 624 645 625 bool bidi = false; 646 #ifdef UNICODE 647 if (QSysInfo::WindowsVersion >= QSysInfo::WV_2000) { 648 WCHAR wchLCIDFontSig[16]; 649 if (GetLocaleInfoW(newLCID, 650 LOCALE_FONTSIGNATURE, 651 &wchLCIDFontSig[0], 652 (sizeof(wchLCIDFontSig)/sizeof(WCHAR))) 653 && (wchLCIDFontSig[7] & (WCHAR)0x0800)) 626 wchar_t LCIDFontSig[16]; 627 if (GetLocaleInfo(newLCID, LOCALE_FONTSIGNATURE, LCIDFontSig, sizeof(LCIDFontSig) / sizeof(wchar_t)) 628 && (LCIDFontSig[7] & (wchar_t)0x0800)) 654 629 bidi = true; 655 } else656 #endif //UNICODE657 {658 if (newLCID == 0x0859 || //Sindhi (Arabic script)659 newLCID == 0x0460) //Kashmiri (Arabic script)660 bidi = true;;661 662 switch (PRIMARYLANGID(newLCID))663 {664 case LANG_ARABIC:665 case LANG_HEBREW:666 case LANG_URDU:667 case LANG_FARSI:668 case LANG_PASHTO:669 //case LANG_UIGHUR:670 case LANG_SYRIAC:671 case LANG_DIVEHI:672 bidi = true;673 }674 }675 630 676 631 keyboardInputDirection = bidi ? Qt::RightToLeft : Qt::LeftToRight; … … 752 707 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x80 : 0; 753 708 // Add a fall back key for layouts which don't do composition and show non-latin1 characters 754 int fallbackKey = KeyTbl[vk_key];709 int fallbackKey = winceKeyBend(vk_key); 755 710 if (!fallbackKey || fallbackKey == Qt::Key_unknown) { 756 711 fallbackKey = 0; … … 761 716 762 717 // If this vk_key a Dead Key 763 if (MapVirtualKey(vk_key, 2) & 0x8000 8000) { // (High-order dead key on Win 95 is 0x8000)718 if (MapVirtualKey(vk_key, 2) & 0x80000000) { 764 719 // Push a Space, then the original key through the low-level ToAscii functions. 765 720 // We do this because these functions (ToAscii / ToUnicode) will alter the internal state of … … 838 793 quint32 nModifiers = 0; 839 794 840 if (QSysInfo::WindowsVersion < QSysInfo::WV_NT || QSysInfo::WindowsVersion & QSysInfo::WV_CE_based) { 795 #if defined(Q_OS_WINCE) 841 796 nModifiers |= (GetKeyState(VK_SHIFT ) < 0 ? ShiftAny : 0); 842 797 nModifiers |= (GetKeyState(VK_CONTROL) < 0 ? ControlAny : 0); … … 844 799 nModifiers |= (GetKeyState(VK_LWIN ) < 0 ? MetaLeft : 0); 845 800 nModifiers |= (GetKeyState(VK_RWIN ) < 0 ? MetaRight : 0); 846 } else { 801 #else 847 802 // Map native modifiers to some bit representation 848 803 nModifiers |= (GetKeyState(VK_LSHIFT ) & 0x80 ? ShiftLeft : 0); … … 858 813 nModifiers |= (GetKeyState(VK_NUMLOCK ) & 0x01 ? NumLock : 0); 859 814 nModifiers |= (GetKeyState(VK_SCROLL ) & 0x01 ? ScrollLock : 0); 860 } 815 #endif // Q_OS_WINCE 816 861 817 if (msg.lParam & ExtendedKey) 862 818 nModifiers |= msg.lParam & ExtendedKey; … … 871 827 // Now we know enough to either have MapVirtualKey or our own keymap tell us if it's a deadkey 872 828 bool isDeadKey = isADeadKey(msg.wParam, state) 873 || MapVirtualKey(msg.wParam, 2) & 0x8000 8000; // High-order on 95 is 0x8000829 || MapVirtualKey(msg.wParam, 2) & 0x80000000; 874 830 875 831 // A multi-character key not found by our look-ahead 876 832 if (msgType == WM_CHAR) { 877 833 QString s; 878 QChar ch = wmchar_to_unicode(msg.wParam);834 QChar ch = QChar((ushort)msg.wParam); 879 835 if (!ch.isNull()) 880 836 s += ch; … … 887 843 else if (msgType == WM_IME_CHAR) { 888 844 QString s; 889 QChar ch = imechar_to_unicode(msg.wParam);845 QChar ch = QChar((ushort)msg.wParam); 890 846 if (!ch.isNull()) 891 847 s += ch; … … 918 874 } else if (msgType == WM_KEYUP) { 919 875 if (dirStatus == VK_LSHIFT 920 && ( msg.wParam == VK_SHIFT && GetKeyState(VK_LCONTROL)921 || msg.wParam == VK_CONTROL && GetKeyState(VK_LSHIFT))) {876 && ((msg.wParam == VK_SHIFT && GetKeyState(VK_LCONTROL)) 877 || (msg.wParam == VK_CONTROL && GetKeyState(VK_LSHIFT)))) { 922 878 k0 = q->sendKeyEvent(widget, grab, QEvent::KeyPress, Qt::Key_Direction_L, 0, 923 879 QString(), false, 0, … … 928 884 dirStatus = 0; 929 885 } else if (dirStatus == VK_RSHIFT 930 && ( msg.wParam == VK_SHIFT && GetKeyState(VK_RCONTROL)931 || msg.wParam == VK_CONTROL && GetKeyState(VK_RSHIFT))) {886 && ( (msg.wParam == VK_SHIFT && GetKeyState(VK_RCONTROL)) 887 || (msg.wParam == VK_CONTROL && GetKeyState(VK_RSHIFT)))) { 932 888 k0 = q->sendKeyEvent(widget, grab, QEvent::KeyPress, Qt::Key_Direction_R, 933 889 0, QString(), false, 0, … … 950 906 return true; 951 907 952 // Ignore invalid virtual keycode (see bug 127424)953 if (msg.wParam == 0 xFF)908 // Ignore invalid virtual keycodes (see bugs 127424, QTBUG-3630) 909 if (msg.wParam == 0 || msg.wParam == 0xFF) 954 910 return true; 955 911 … … 960 916 int code = 0; 961 917 if (isNumpad && (nModifiers & AltAny)) { 962 code = KeyTbl[msg.wParam];918 code = winceKeyBend(msg.wParam); 963 919 } else if (!isDeadKey) { 964 920 unsigned char kbdBuffer[256]; // Will hold the complete keyboard state … … 1051 1007 1052 1008 QChar uch; 1053 if ( winPeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) {1009 if (PeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) { 1054 1010 // Found a ?_CHAR 1055 uch = charType == WM_IME_CHAR 1056 ? imechar_to_unicode(wm_char.wParam) 1057 : wmchar_to_unicode(wm_char.wParam); 1011 uch = QChar((ushort)wm_char.wParam); 1058 1012 if (msgType == WM_SYSKEYDOWN && uch.isLetter() && (msg.lParam & KF_ALTDOWN)) 1059 1013 uch = uch.toLower(); // (See doc of WM_SYSCHAR) Alt-letter … … 1068 1022 if (uch.isNull() && msgType == WM_IME_KEYDOWN) { 1069 1023 BYTE keyState[256]; 1070 WCHARnewKey[3] = {0};1024 wchar_t newKey[3] = {0}; 1071 1025 GetKeyboardState(keyState); 1072 1026 int val = ToUnicode(vk_key, scancode, keyState, newKey, 2, 0); … … 1086 1040 } else { 1087 1041 if (msgType != WM_SYSKEYDOWN || !code) { 1088 UINT map; 1089 QT_WA({ 1090 map = MapVirtualKey(msg.wParam, 2); 1091 } , { 1092 map = MapVirtualKeyA(msg.wParam, 2); 1093 // High-order bit is 0x8000 on '95 1094 if (map & 0x8000) 1095 map = (map^0x8000)|0x80000000; 1096 }); 1042 UINT map = MapVirtualKey(msg.wParam, 2); 1097 1043 // If the high bit of the return value is set, it's a deadkey 1098 1044 if (!(map & 0x80000000)) 1099 uch = wmchar_to_unicode((DWORD)map);1045 uch = QChar((ushort)map); 1100 1046 } 1101 1047 } … … 1238 1184 return true; 1239 1185 } 1186 #else 1187 Q_UNUSED(grab); 1240 1188 #endif 1241 1189 if (!widget->isEnabled())
Note:
See TracChangeset
for help on using the changeset viewer.