1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
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 | int xkb_currentGroup; |
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 | public: |
211 | QString translateKeyEvent(int keySym, Qt::KeyboardModifiers modifiers); |
212 | int mapS60KeyToQt(TUint s60key); |
213 | int mapS60ScanCodesToQt(TUint s60key); |
214 | int mapQtToS60Key(int qtKey); |
215 | int mapQtToS60ScanCodes(int qtKey); |
216 | int mapS60RemConIdToS60Key(int s60RemConId); |
217 | int mapS60RemConIdToS60ScanCodes(int s60RemConId); |
218 | void updateInputLanguage(); |
219 | #endif |
220 | }; |
221 | |
222 | QKeyMapperPrivate *qt_keymapper_private(); // from qkeymapper.cpp |
223 | |
224 | QT_END_NAMESPACE |
225 | |
226 | #endif // QKEYMAPPER_P_H |
227 | |