source: trunk/src/gui/kernel/qkeymapper_p.h@ 324

Last change on this file since 324 was 136, checked in by Dmitry A. Kuminov, 16 years ago

gui: Implemented QKeyMapper (#33).

File size: 6.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
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.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
62#if defined (Q_WS_MAC64)
63# include <private/qt_mac_p.h>
64#endif
65
66QT_BEGIN_NAMESPACE
67
68class QKeyMapperPrivate;
69class QKeyMapper : public QObject
70{
71 Q_OBJECT
72public:
73 explicit QKeyMapper();
74 ~QKeyMapper();
75
76 static QKeyMapper *instance();
77 static void changeKeyboard();
78 static bool sendKeyEvent(QWidget *widget, bool grab,
79 QEvent::Type type, int code, Qt::KeyboardModifiers modifiers,
80 const QString &text, bool autorepeat, int count,
81 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
82 bool *unusedExceptForCocoa = 0);
83 static QList<int> possibleKeys(QKeyEvent *e);
84
85private:
86 friend QKeyMapperPrivate *qt_keymapper_private();
87 Q_DECLARE_PRIVATE(QKeyMapper)
88 Q_DISABLE_COPY(QKeyMapper)
89};
90
91
92
93#if defined(Q_OS_WIN)
94enum WindowsNativeModifiers {
95 ShiftLeft = 0x00000001,
96 ControlLeft = 0x00000002,
97 AltLeft = 0x00000004,
98 MetaLeft = 0x00000008,
99 ShiftRight = 0x00000010,
100 ControlRight = 0x00000020,
101 AltRight = 0x00000040,
102 MetaRight = 0x00000080,
103 CapsLock = 0x00000100,
104 NumLock = 0x00000200,
105 ScrollLock = 0x00000400,
106 ExtendedKey = 0x01000000,
107
108 // Convenience mappings
109 ShiftAny = 0x00000011,
110 ControlAny = 0x00000022,
111 AltAny = 0x00000044,
112 MetaAny = 0x00000088,
113 LockAny = 0x00000700
114};
115# if !defined(tagMSG)
116 typedef struct tagMSG MSG;
117# endif
118#elif defined(Q_WS_MAC)
119QT_BEGIN_INCLUDE_NAMESPACE
120# include <private/qt_mac_p.h>
121QT_END_INCLUDE_NAMESPACE
122#elif defined(Q_WS_X11)
123
124QT_BEGIN_INCLUDE_NAMESPACE
125typedef ulong XID;
126typedef XID KeySym;
127QT_END_INCLUDE_NAMESPACE
128
129struct QXCoreDesc {
130 int min_keycode;
131 int max_keycode;
132 int keysyms_per_keycode;
133 KeySym *keysyms;
134 uchar mode_switch;
135 uchar num_lock;
136 KeySym lock_meaning;
137};
138
139#endif
140
141struct KeyboardLayoutItem;
142typedef struct __TISInputSource * TISInputSourceRef;
143class QKeyEvent;
144class QKeyMapperPrivate : public QObjectPrivate
145{
146 Q_DECLARE_PUBLIC(QKeyMapper)
147public:
148 QKeyMapperPrivate();
149 ~QKeyMapperPrivate();
150
151 void clearMappings();
152 QList<int> possibleKeys(QKeyEvent *e);
153
154 QLocale keyboardInputLocale;
155 Qt::LayoutDirection keyboardInputDirection;
156
157#if defined(Q_OS_WIN)
158 void clearRecordedKeys();
159 void updateKeyMap(const MSG &msg);
160 bool translateKeyEvent(QWidget *receiver, const MSG &msg, bool grab);
161 void updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 scancode, quint32 vk_key);
162 bool isADeadKey(unsigned int vk_key, unsigned int modifiers);
163
164 KeyboardLayoutItem *keyLayout[256];
165
166#elif defined(Q_WS_PM)
167