Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qkeymapper_win.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include "qkeymapper_p.h"
    4343
    44 #include <windows.h>
     44#include <qt_windows.h>
    4545#include <qdebug.h>
    4646#include <private/qevent_p.h>
     
    5858// Implemented elsewhere
    5959extern "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
    6361extern Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id);
    6462#ifndef LANG_PASHTO
     
    436434};
    437435
     436/**
     437  Remap return or action key to select key for windows mobile.
     438*/
     439inline 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
    438453#if defined(Q_OS_WINCE)
    439454    // Use the KeyTbl to resolve a Qt::Key out of the virtual keys.
     
    468483    int code = 0;
    469484    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);
    476486    if (res)
    477487        code = unicodeBuffer[0].toUpper().unicode();
     
    480490    // proper Qt::Key_ code
    481491    if (code < 0x20 || code == 0x7f) // Handles res==0 too
    482         code = KeyTbl[vk];
     492        code = winceKeyBend(vk);
    483493
    484494    if (isDeadkey)
     
    490500Q_GUI_EXPORT int qt_translateKeyCode(int vk)
    491501{
    492     int code = (vk < 0 || vk > 255) ? 0 : KeyTbl[vk];
     502    int code = winceKeyBend((vk < 0 || vk > 255) ? 0 : vk);
    493503    return code == Qt::Key_unknown ? 0 : code;
    494504}
     
    503513    }
    504514    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     });
    537515}
    538516
     
    622600QKeyMapperPrivate::~QKeyMapperPrivate()
    623601{
    624     clearMappings();
    625 }
    626 
    627 void QKeyMapperPrivate::clearMappings()
     602    deleteLayouts();
     603}
     604
     605void QKeyMapperPrivate::deleteLayouts()
    628606{
    629607    for (int i = 0; i < 255; ++i) {
     
    633611        }
    634612    }
     613}
     614
     615void QKeyMapperPrivate::clearMappings()
     616{
     617    deleteLayouts();
    635618
    636619    /* MAKELCID()'s first argument is a WORD, and GetKeyboardLayout()
    637620     * returns a DWORD. */
    638 //    LCID newLCID = MAKELCID(DWORD(GetKeyboardLayout(0)), SORT_DEFAULT);
     621
     622    LCID newLCID = MAKELCID((DWORD)GetKeyboardLayout(0), SORT_DEFAULT);
    639623//    keyboardInputLocale = qt_localeFromLCID(newLCID);
    640      LCID newLCID = MAKELCID(
    641          reinterpret_cast<long>(GetKeyboardLayout(0)),
    642          SORT_DEFAULT
    643      );
    644      keyboardInputLocale = qt_localeFromLCID(newLCID);
     624
    645625    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))
    654629        bidi = true;
    655     } else
    656 #endif //UNICODE
    657     {
    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     }
    675630
    676631    keyboardInputDirection = bidi ? Qt::RightToLeft : Qt::LeftToRight;
     
    752707    keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x80 : 0;
    753708    // 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);
    755710    if (!fallbackKey || fallbackKey == Qt::Key_unknown) {
    756711        fallbackKey = 0;
     
    761716
    762717    // If this vk_key a Dead Key
    763     if (MapVirtualKey(vk_key, 2) & 0x80008000) { // (High-order dead key on Win 95 is 0x8000)
     718    if (MapVirtualKey(vk_key, 2) & 0x80000000) {
    764719        // Push a Space, then the original key through the low-level ToAscii functions.
    765720        // We do this because these functions (ToAscii / ToUnicode) will alter the internal state of
     
    838793    quint32 nModifiers = 0;
    839794
    840     if (QSysInfo::WindowsVersion < QSysInfo::WV_NT || QSysInfo::WindowsVersion & QSysInfo::WV_CE_based) {
     795#if defined(Q_OS_WINCE)
    841796        nModifiers |= (GetKeyState(VK_SHIFT  ) < 0 ? ShiftAny : 0);
    842797        nModifiers |= (GetKeyState(VK_CONTROL) < 0 ? ControlAny : 0);
     
    844799        nModifiers |= (GetKeyState(VK_LWIN   ) < 0 ? MetaLeft : 0);
    845800        nModifiers |= (GetKeyState(VK_RWIN   ) < 0 ? MetaRight : 0);
    846     } else {
     801#else
    847802        // Map native modifiers to some bit representation
    848803        nModifiers |= (GetKeyState(VK_LSHIFT  ) & 0x80 ? ShiftLeft : 0);
     
    858813        nModifiers |= (GetKeyState(VK_NUMLOCK ) & 0x01 ? NumLock : 0);
    859814        nModifiers |= (GetKeyState(VK_SCROLL  ) & 0x01 ? ScrollLock : 0);
    860     }
     815#endif // Q_OS_WINCE
     816
    861817    if (msg.lParam & ExtendedKey)
    862818        nModifiers |= msg.lParam & ExtendedKey;
     
    871827    // Now we know enough to either have MapVirtualKey or our own keymap tell us if it's a deadkey
    872828    bool isDeadKey = isADeadKey(msg.wParam, state)
    873                      || MapVirtualKey(msg.wParam, 2) & 0x80008000; // High-order on 95 is 0x8000
     829                     || MapVirtualKey(msg.wParam, 2) & 0x80000000;
    874830
    875831    // A multi-character key not found by our look-ahead
    876832    if (msgType == WM_CHAR) {
    877833        QString s;
    878         QChar ch = wmchar_to_unicode(msg.wParam);
     834        QChar ch = QChar((ushort)msg.wParam);
    879835        if (!ch.isNull())
    880836            s += ch;
     
    887843    else if (msgType == WM_IME_CHAR) {
    888844        QString s;
    889         QChar ch = imechar_to_unicode(msg.wParam);
     845        QChar ch = QChar((ushort)msg.wParam);
    890846        if (!ch.isNull())
    891847            s += ch;
     
    918874                } else if (msgType == WM_KEYUP) {
    919875                    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)))) {
    922878                            k0 = q->sendKeyEvent(widget, grab, QEvent::KeyPress, Qt::Key_Direction_L, 0,
    923879                                                 QString(), false, 0,
     
    928884                            dirStatus = 0;
    929885                        } 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)))) {
    932888                                k0 = q->sendKeyEvent(widget, grab, QEvent::KeyPress, Qt::Key_Direction_R,
    933889                                                     0, QString(), false, 0,
     
    950906            return true;
    951907
    952         // Ignore invalid virtual keycode (see bug 127424)
    953         if (msg.wParam == 0xFF)
     908        // Ignore invalid virtual keycodes (see bugs 127424, QTBUG-3630)
     909        if (msg.wParam == 0 || msg.wParam == 0xFF)
    954910            return true;
    955911
     
    960916        int code = 0;
    961917        if (isNumpad && (nModifiers & AltAny)) {
    962             code = KeyTbl[msg.wParam];
     918            code = winceKeyBend(msg.wParam);
    963919        } else if (!isDeadKey) {
    964920            unsigned char kbdBuffer[256]; // Will hold the complete keyboard state
     
    10511007
    10521008            QChar uch;
    1053             if (winPeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) {
     1009            if (PeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) {
    10541010                // 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);
    10581012                if (msgType == WM_SYSKEYDOWN && uch.isLetter() && (msg.lParam & KF_ALTDOWN))
    10591013                    uch = uch.toLower(); // (See doc of WM_SYSCHAR) Alt-letter
     
    10681022            if (uch.isNull() && msgType == WM_IME_KEYDOWN) {
    10691023                BYTE keyState[256];
    1070                 WCHAR newKey[3] = {0};
     1024                wchar_t newKey[3] = {0};
    10711025                GetKeyboardState(keyState);
    10721026                int val = ToUnicode(vk_key, scancode, keyState, newKey, 2,  0);
     
    10861040                } else {
    10871041                    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);
    10971043                        // If the high bit of the return value is set, it's a deadkey
    10981044                        if (!(map & 0x80000000))
    1099                             uch = wmchar_to_unicode((DWORD)map);
     1045                            uch = QChar((ushort)map);
    11001046                    }
    11011047                }
     
    12381184            return true;
    12391185    }
     1186#else
     1187    Q_UNUSED(grab);
    12401188#endif
    12411189    if (!widget->isEnabled())
Note: See TracChangeset for help on using the changeset viewer.