|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 test suite 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 |
|
42 #ifndef Q_NATIVE_INPUT |
|
43 #define Q_NATIVE_INPUT |
|
44 |
|
45 #include <QtCore> |
|
46 |
|
47 namespace Qt { |
|
48 namespace Native { |
|
49 enum Status {Success, Failure}; |
|
50 }} |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // Declare a set of native events that can be used to communicate with |
|
54 // client applications in an platform independent way |
|
55 // ---------------------------------------------------------------------------- |
|
56 |
|
57 class QNativeEvent |
|
58 { |
|
59 public: |
|
60 static const int eventId = 1; |
|
61 |
|
62 QNativeEvent(Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
63 virtual ~QNativeEvent(){}; |
|
64 virtual int id() const { return eventId; }; |
|
65 virtual QString toString() const = 0; |
|
66 Qt::KeyboardModifiers modifiers; // Yields for mouse events too. |
|
67 }; |
|
68 |
|
69 class QNativeMouseEvent : public QNativeEvent { |
|
70 public: |
|
71 static const int eventId = 2; |
|
72 |
|
73 QNativeMouseEvent(){}; |
|
74 QNativeMouseEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
75 virtual ~QNativeMouseEvent(){}; |
|
76 virtual int id() const { return eventId; }; |
|
77 |
|
78 QPoint globalPos; |
|
79 }; |
|
80 |
|
81 class QNativeMouseMoveEvent : public QNativeMouseEvent { |
|
82 public: |
|
83 static const int eventId = 4; |
|
84 |
|
85 QNativeMouseMoveEvent(){}; |
|
86 QNativeMouseMoveEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
87 virtual ~QNativeMouseMoveEvent(){}; |
|
88 virtual int id() const { return eventId; }; |
|
89 virtual QString toString() const; |
|
90 }; |
|
91 |
|
92 class QNativeMouseButtonEvent : public QNativeMouseEvent { |
|
93 public: |
|
94 static const int eventId = 8; |
|
95 |
|
96 QNativeMouseButtonEvent(){}; |
|
97 QNativeMouseButtonEvent(QPoint globalPos, Qt::MouseButton button, int clickCount, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
98 virtual ~QNativeMouseButtonEvent(){}; |
|
99 virtual int id() const { return eventId; }; |
|
100 virtual QString toString() const; |
|
101 |
|
102 Qt::MouseButton button; |
|
103 int clickCount; |
|
104 }; |
|
105 |
|
106 class QNativeMouseDragEvent : public QNativeMouseButtonEvent { |
|
107 public: |
|
108 static const int eventId = 16; |
|
109 |
|
110 QNativeMouseDragEvent(){}; |
|
111 QNativeMouseDragEvent(QPoint globalPos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
112 virtual ~QNativeMouseDragEvent(){}; |
|
113 virtual int id() const { return eventId; }; |
|
114 virtual QString toString() const; |
|
115 }; |
|
116 |
|
117 class QNativeMouseWheelEvent : public QNativeMouseEvent { |
|
118 public: |
|
119 static const int eventId = 32; |
|
120 |
|
121 QNativeMouseWheelEvent(){}; |
|
122 QNativeMouseWheelEvent(QPoint globalPos, int delta, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
123 virtual ~QNativeMouseWheelEvent(){}; |
|
124 virtual int id() const { return eventId; }; |
|
125 virtual QString toString() const; |
|
126 |
|
127 int delta; |
|
128 }; |
|
129 |
|
130 class QNativeKeyEvent : public QNativeEvent { |
|
131 public: |
|
132 static const int eventId = 64; |
|
133 |
|
134 QNativeKeyEvent(){}; |
|
135 QNativeKeyEvent(int nativeKeyCode, bool press, Qt::KeyboardModifiers modifiers = Qt::NoModifier); |
|
136 QNativeKeyEvent(int nativeKeyCode, bool press, QChar character, Qt::KeyboardModifiers modifiers); |
|
137 virtual ~QNativeKeyEvent(){}; |
|
138 virtual int id() const { return eventId; }; |
|
139 virtual QString toString() const; |
|
140 |
|
141 int nativeKeyCode; |
|
142 bool press; |
|
143 QChar character; |
|
144 |
|
145 // Some Qt to Native mappings: |
|
146 static int Key_A; |
|
147 static int Key_B; |
|
148 static int Key_C; |
|
149 static int Key_1; |
|
150 static int Key_Backspace; |
|
151 static int Key_Enter; |
|
152 static int Key_Del; |
|
153 }; |
|
154 |
|
155 class QNativeModifierEvent : public QNativeEvent { |
|
156 public: |
|
157 static const int eventId = 128; |
|
158 |
|
159 QNativeModifierEvent(Qt::KeyboardModifiers modifiers = Qt::NoModifier, int nativeKeyCode = 0); |
|
160 virtual ~QNativeModifierEvent(){}; |
|
161 virtual int id() const { return eventId; }; |
|
162 virtual QString toString() const; |
|
163 |
|
164 int nativeKeyCode; |
|
165 }; |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // Declare a set of related output / input functions for convenience: |
|
169 // ---------------------------------------------------------------------------- |
|
170 |
|
171 QDebug operator<<(QDebug d, QNativeEvent *e); |
|
172 QDebug operator<<(QDebug d, const QNativeEvent &e); |
|
173 |
|
174 QTextStream &operator<<(QTextStream &s, QNativeEvent *e); |
|
175 QTextStream &operator<<(QTextStream &s, QNativeMouseEvent *e); |
|
176 QTextStream &operator<<(QTextStream &s, QNativeMouseMoveEvent *e); |
|
177 QTextStream &operator<<(QTextStream &s, QNativeMouseButtonEvent *e); |
|
178 QTextStream &operator<<(QTextStream &s, QNativeMouseDragEvent *e); |
|
179 QTextStream &operator<<(QTextStream &s, QNativeMouseWheelEvent *e); |
|
180 QTextStream &operator<<(QTextStream &s, QNativeKeyEvent *e); |
|
181 QTextStream &operator<<(QTextStream &s, QNativeModifierEvent *e); |
|
182 |
|
183 QTextStream &operator>>(QTextStream &s, QNativeMouseMoveEvent *e); |
|
184 QTextStream &operator>>(QTextStream &s, QNativeMouseButtonEvent *e); |
|
185 QTextStream &operator>>(QTextStream &s, QNativeMouseDragEvent *e); |
|
186 QTextStream &operator>>(QTextStream &s, QNativeMouseWheelEvent *e); |
|
187 QTextStream &operator>>(QTextStream &s, QNativeKeyEvent *e); |
|
188 QTextStream &operator>>(QTextStream &s, QNativeModifierEvent *e); |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // Declare the main class that is supposed to be sub-classed by components |
|
192 // that are to receive native events |
|
193 // ---------------------------------------------------------------------------- |
|
194 |
|
195 class QNativeInput |
|
196 { |
|
197 public: |
|
198 QNativeInput(bool subscribe = true); |
|
199 virtual ~QNativeInput(); |
|
200 |
|
201 // Callback methods. Should be implemented by interested sub-classes: |
|
202 void notify(QNativeEvent *event); |
|
203 virtual void nativeEvent(QNativeEvent *event); |
|
204 virtual void nativeMousePressEvent(QNativeMouseButtonEvent *){}; |
|
205 virtual void nativeMouseReleaseEvent(QNativeMouseButtonEvent *){}; |
|
206 virtual void nativeMouseMoveEvent(QNativeMouseMoveEvent *){}; |
|
207 virtual void nativeMouseDragEvent(QNativeMouseDragEvent *){}; |
|
208 virtual void nativeMouseWheelEvent(QNativeMouseWheelEvent *){}; |
|
209 virtual void nativeKeyPressEvent(QNativeKeyEvent *){}; |
|
210 virtual void nativeKeyReleaseEvent(QNativeKeyEvent *){}; |
|
211 virtual void nativeModifierEvent(QNativeModifierEvent *){}; |
|
212 |
|
213 // The following methods will differ in implementation from OS to OS: |
|
214 static Qt::Native::Status sendNativeMouseButtonEvent(const QNativeMouseButtonEvent &event); |
|
215 static Qt::Native::Status sendNativeMouseMoveEvent(const QNativeMouseMoveEvent &event); |
|
216 static Qt::Native::Status sendNativeMouseDragEvent(const QNativeMouseDragEvent &event); |
|
217 static Qt::Native::Status sendNativeMouseWheelEvent(const QNativeMouseWheelEvent &event); |
|
218 static Qt::Native::Status sendNativeKeyEvent(const QNativeKeyEvent &event, int pid = 0); |
|
219 static Qt::Native::Status sendNativeModifierEvent(const QNativeModifierEvent &event); |
|
220 // sendNativeEvent will NOT differ from OS to OS. |
|
221 static Qt::Native::Status sendNativeEvent(const QNativeEvent &event, int pid = 0); |
|
222 |
|
223 // The following methods will differ in implementation from OS to OS: |
|
224 Qt::Native::Status subscribeForNativeEvents(); |
|
225 Qt::Native::Status unsubscribeForNativeEvents(); |
|
226 }; |
|
227 |
|
228 #endif // Q_NATIVE_INPUT |