Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    324324};
    325325
     326static 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
    326352static int qt_mac_get_key(int modif, const QChar &key, int virtualKey)
    327353{
     
    378404            return qt_mac_keyvkey_symbols[i].qt_code;
    379405        }
     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
    380419    }
    381420
     
    634673    if (iso639Code) {
    635674        keyboardInputLocale = QLocale(QCFString::toQString(iso639Code));
    636         QString monday = keyboardInputLocale.dayName(1);
    637         bool rtl = false;
    638         for (int i = 0; i < monday.length(); ++i) {
    639             switch (monday.at(i).direction()) {
    640             default:
    641                 break;
    642             case QChar::DirR:
    643             case QChar::DirAL:
    644             case QChar::DirRLE:
    645             case QChar::DirRLO:
    646                 rtl = true;
    647                 break;
    648             }
    649             if (rtl)
    650                 break;
    651         }
    652         keyboardInputDirection = rtl ? Qt::RightToLeft : Qt::LeftToRight;
     675        keyboardInputDirection = keyboardInputLocale.textDirection();
    653676    } else {
    654677        keyboardInputLocale = QLocale::c();
     
    718741    }
    719742
    720     if (qApp->inputContext() && qApp->inputContext()->isComposing()) {
     743    QInputContext *currentContext = qApp->inputContext();
     744    if (currentContext && currentContext->isComposing()) {
    721745        if (ekind == kEventRawKeyDown) {
    722             QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext());
     746            QMacInputContext *context = qobject_cast<QMacInputContext*>(currentContext);
    723747            if (context)
    724748                context->setLastKeydownEvent(event);
     
    726750        return false;
    727751    }
     752    // Once we process the key down , we don't need to send the saved event again from
     753    // kEventTextInputUnicodeForKeyEvent, so clear it.
     754    if (currentContext && ekind == kEventRawKeyDown) {
     755        QMacInputContext *context = qobject_cast<QMacInputContext*>(currentContext);
     756        if (context)
     757            context->setLastKeydownEvent(0);
     758    }
     759
    728760    //get modifiers
    729761    Qt::KeyboardModifiers modifiers;
     
    734766        return handled_event;
    735767    QString text(ourChar);
    736     /* This is actually wrong - but unfortunatly it is the best that can be
     768    /* This is actually wrong - but unfortunately it is the best that can be
    737769       done for now because of the Control/Meta mapping problems */
    738770    if (modifiers & (Qt::ControlModifier | Qt::MetaModifier)
     
    835867        GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0,
    836868                          sizeof(macModifiers), 0, &macModifiers);
     869#ifdef QT_MAC_USE_COCOA
     870        // The unicode characters in the range 0xF700-0xF747 are reserved
     871        // by Mac OS X for transient use as keyboard function keys. We
     872        // wont send 'text' for such key events. This is done to match
     873        // behavior on other platforms.
     874        unsigned int *unicodeKey = (unsigned int*)info;
     875        if (*unicodeKey >= 0xf700 && *unicodeKey <= 0xf747)
     876            text = QString();
     877        bool isAccepted;
     878#endif
    837879        handled_event = QKeyMapper::sendKeyEvent(widget, grab,
    838880                                                 (ekind == kEventRawKeyUp) ? QEvent::KeyRelease : QEvent::KeyPress,
     
    840882                                                 macScanCode, macVirtualKey, macModifiers
    841883#ifdef QT_MAC_USE_COCOA
    842                                                  ,static_cast<bool *>(info)
     884                                                 ,&isAccepted
    843885#endif
    844886                                                 );
     887#ifdef QT_MAC_USE_COCOA
     888        *unicodeKey = (unsigned int)isAccepted;
     889#endif
    845890    }
    846891    return handled_event;
     
    848893
    849894void
    850 QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *)
     895QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *
     896#if defined(QT_MAC_USE_COCOA)
     897                                unicodeKey // unicode character from NSEvent (modifiers applied)
     898#endif
     899                                )
    851900{
    852901    UInt32 macVirtualKey = 0;
     
    876925                keyLayout[macVirtualKey]->qtKey[i] = qtkey;
    877926            }
     927#ifndef Q_WS_MAC32
     928            else {
     929                const QChar unicode(*((UniChar *)unicodeKey));
     930                int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey);
     931                if (qtkey == Qt::Key_unknown)
     932                    qtkey = unicode.unicode();
     933                keyLayout[macVirtualKey]->qtKey[i] = qtkey;
     934            }
     935#endif
    878936#ifdef Q_WS_MAC32           
    879937        } else {
Note: See TracChangeset for help on using the changeset viewer.