src/gui/kernel/qkeymapper_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    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 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #ifndef QKEYMAPPER_P_H
       
    42 #define QKEYMAPPER_P_H
       
    43 
       
    44 //
       
    45 //  W A R N I N G
       
    46 //  -------------
       
    47 //
       
    48 // This file is not part of the Qt API.  It exists purely as an
       
    49 // implementation detail.  This header file may change from version to
       
    50 // version without notice, or even be removed.
       
    51 //
       
    52 // We mean it.
       
    53 //
       
    54 
       
    55 #include <qobject.h>
       
    56 #include <private/qobject_p.h>
       
    57 #include <qkeysequence.h>
       
    58 #include <qlist.h>
       
    59 #include <qlocale.h>
       
    60 #include <qevent.h>
       
    61 #include <qhash.h>
       
    62 
       
    63 #if defined (Q_WS_MAC64)
       
    64 # include <private/qt_mac_p.h>
       
    65 #endif
       
    66 
       
    67 QT_BEGIN_NAMESPACE
       
    68 
       
    69 class QKeyMapperPrivate;
       
    70 class QKeyMapper : public QObject
       
    71 {
       
    72     Q_OBJECT
       
    73 public:
       
    74     explicit QKeyMapper();
       
    75     ~QKeyMapper();
       
    76 
       
    77     static QKeyMapper *instance();
       
    78     static void changeKeyboard();
       
    79     static bool sendKeyEvent(QWidget *widget, bool grab,
       
    80                              QEvent::Type type, int code, Qt::KeyboardModifiers modifiers,
       
    81                              const QString &text, bool autorepeat, int count,
       
    82                              quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
       
    83                              bool *unusedExceptForCocoa = 0);
       
    84     static QList<int> possibleKeys(QKeyEvent *e);
       
    85 
       
    86 private:
       
    87     friend QKeyMapperPrivate *qt_keymapper_private();
       
    88     Q_DECLARE_PRIVATE(QKeyMapper)
       
    89     Q_DISABLE_COPY(QKeyMapper)
       
    90 };
       
    91 
       
    92 
       
    93 
       
    94 #if defined(Q_OS_WIN)
       
    95 enum WindowsNativeModifiers {
       
    96     ShiftLeft            = 0x00000001,
       
    97     ControlLeft          = 0x00000002,
       
    98     AltLeft              = 0x00000004,
       
    99     MetaLeft             = 0x00000008,
       
   100     ShiftRight           = 0x00000010,
       
   101     ControlRight         = 0x00000020,
       
   102     AltRight             = 0x00000040,
       
   103     MetaRight            = 0x00000080,
       
   104     CapsLock             = 0x00000100,
       
   105     NumLock              = 0x00000200,
       
   106     ScrollLock           = 0x00000400,
       
   107     ExtendedKey          = 0x01000000,
       
   108 
       
   109     // Convenience mappings
       
   110     ShiftAny             = 0x00000011,
       
   111     ControlAny           = 0x00000022,
       
   112     AltAny               = 0x00000044,
       
   113     MetaAny              = 0x00000088,
       
   114     LockAny              = 0x00000700
       
   115 };
       
   116 # if !defined(tagMSG)
       
   117     typedef struct tagMSG MSG;
       
   118 # endif
       
   119 #elif defined(Q_WS_MAC)
       
   120 QT_BEGIN_INCLUDE_NAMESPACE
       
   121 # include <private/qt_mac_p.h>
       
   122 QT_END_INCLUDE_NAMESPACE
       
   123 #elif defined(Q_WS_X11)
       
   124 
       
   125 QT_BEGIN_INCLUDE_NAMESPACE
       
   126 typedef ulong XID;
       
   127 typedef XID KeySym;
       
   128 QT_END_INCLUDE_NAMESPACE
       
   129 
       
   130 struct QXCoreDesc {
       
   131     int min_keycode;
       
   132     int max_keycode;
       
   133     int keysyms_per_keycode;
       
   134     KeySym *keysyms;
       
   135     uchar mode_switch;
       
   136     uchar num_lock;
       
   137     KeySym lock_meaning;
       
   138 };
       
   139 
       
   140 #endif
       
   141 
       
   142 struct KeyboardLayoutItem;
       
   143 typedef struct __TISInputSource * TISInputSourceRef;
       
   144 class QKeyEvent;
       
   145 class QKeyMapperPrivate : public QObjectPrivate
       
   146 {
       
   147     Q_DECLARE_PUBLIC(QKeyMapper)
       
   148 public:
       
   149     QKeyMapperPrivate();
       
   150     ~QKeyMapperPrivate();
       
   151 
       
   152     void clearMappings();
       
   153     QList<int> possibleKeys(QKeyEvent *e);
       
   154 
       
   155     QLocale keyboardInputLocale;
       
   156     Qt::LayoutDirection keyboardInputDirection;
       
   157 
       
   158 #if defined(Q_OS_WIN)
       
   159     void clearRecordedKeys();
       
   160     void updateKeyMap(const MSG &msg);
       
   161     bool translateKeyEvent(QWidget *receiver, const MSG &msg, bool grab);
       
   162     void updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 scancode, quint32 vk_key);
       
   163     bool isADeadKey(unsigned int vk_key, unsigned int modifiers);
       
   164     void deleteLayouts();
       
   165 
       
   166     KeyboardLayoutItem *keyLayout[256];
       
   167 
       
   168 #elif defined(Q_WS_X11)
       
   169 
       
   170     QList<int> possibleKeysXKB(QKeyEvent *event);
       
   171     QList<int> possibleKeysCore(QKeyEvent *event);
       
   172 
       
   173     bool translateKeyEventInternal(QWidget *keywidget,
       
   174                                    const XEvent *,
       
   175                                    KeySym &keysym,
       
   176                                    int& count,
       
   177                                    QString& text,
       
   178                                    Qt::KeyboardModifiers& modifiers,
       
   179                                    int &code,
       
   180                                    QEvent::Type &type,
       
   181                                    bool statefulTranslation = true);
       
   182     bool translateKeyEvent(QWidget *keywidget,
       
   183                            const XEvent *,
       
   184                            bool grab);
       
   185 
       
   186     bool useXKB;
       
   187     QXCoreDesc coreDesc;
       
   188 
       
   189 #elif defined(Q_WS_MAC)
       
   190     bool updateKeyboard();
       
   191     void updateKeyMap(EventHandlerCallRef, EventRef, void *);
       
   192     bool translateKeyEvent(QWidget *, EventHandlerCallRef, EventRef, void *, bool);
       
   193     void deleteLayouts();
       
   194 
       
   195     enum { NullMode, UnicodeMode, OtherMode } keyboard_mode;
       
   196     union {
       
   197         const UCKeyboardLayout *unicode;
       
   198         void *other;
       
   199     } keyboard_layout_format;
       
   200 #ifdef Q_WS_MAC64
       
   201     QCFType<TISInputSourceRef> currentInputSource;
       
   202 #else
       
   203     KeyboardLayoutRef currentKeyboardLayout;
       
   204 #endif
       
   205     KeyboardLayoutKind keyboard_kind;
       
   206     UInt32 keyboard_dead;
       
   207     KeyboardLayoutItem *keyLayout[256];
       
   208 #elif defined(Q_WS_QWS)
       
   209 #elif defined(Q_OS_SYMBIAN)
       
   210 private:
       
   211     QHash<TUint, int> s60ToQtKeyMap;
       
   212     void fillKeyMap();
       
   213 public:
       
   214     QString translateKeyEvent(int keySym, Qt::KeyboardModifiers modifiers);
       
   215     int mapS60KeyToQt(TUint s60key);
       
   216 #endif
       
   217 };
       
   218 
       
   219 QKeyMapperPrivate *qt_keymapper_private(); // from qkeymapper.cpp
       
   220 
       
   221 QT_END_NAMESPACE
       
   222 
       
   223 #endif // QKEYMAPPER_P_H