Remove deprecated inputItem and inputWindow from QInputMethod
[profile/ivi/qtbase.git] / src / gui / kernel / qwindowsysteminterface_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef QWINDOWSYSTEMINTERFACE_P_H
42 #define QWINDOWSYSTEMINTERFACE_P_H
43
44 #include "qwindowsysteminterface.h"
45
46 #include <QElapsedTimer>
47 #include <QPointer>
48 #include <QMutex>
49 #include <QList>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 class QWindowSystemInterfacePrivate {
56 public:
57     enum EventType {
58         Close,
59         GeometryChange,
60         Enter,
61         Leave,
62         ActivatedWindow,
63         WindowStateChanged,
64         Mouse,
65         FrameStrutMouse,
66         Wheel,
67         Key,
68         Touch,
69         ScreenOrientation,
70         ScreenGeometry,
71         ScreenAvailableGeometry,
72         ScreenLogicalDotsPerInch,
73         ScreenRefreshRate,
74         ThemeChange,
75         Expose,
76         FileOpen,
77         Tablet,
78         TabletEnterProximity,
79         TabletLeaveProximity
80     };
81
82     class WindowSystemEvent {
83     public:
84         explicit WindowSystemEvent(EventType t)
85             : type(t), synthetic(false) { }
86         virtual ~WindowSystemEvent() { }
87         EventType type;
88         bool synthetic;
89     };
90
91     class CloseEvent : public WindowSystemEvent {
92     public:
93         explicit CloseEvent(QWindow *w)
94             : WindowSystemEvent(Close), window(w) { }
95         QPointer<QWindow> window;
96     };
97
98     class GeometryChangeEvent : public WindowSystemEvent {
99     public:
100         GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
101             : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
102         { }
103         QPointer<QWindow> tlw;
104         QRect newGeometry;
105     };
106
107     class EnterEvent : public WindowSystemEvent {
108     public:
109         explicit EnterEvent(QWindow *enter)
110             : WindowSystemEvent(Enter), enter(enter)
111         { }
112         QPointer<QWindow> enter;
113     };
114
115     class LeaveEvent : public WindowSystemEvent {
116     public:
117         explicit LeaveEvent(QWindow *leave)
118             : WindowSystemEvent(Leave), leave(leave)
119         { }
120         QPointer<QWindow> leave;
121     };
122
123     class ActivatedWindowEvent : public WindowSystemEvent {
124     public:
125         explicit ActivatedWindowEvent(QWindow *activatedWindow)
126             : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
127         { }
128         QPointer<QWindow> activated;
129     };
130
131     class WindowStateChangedEvent : public WindowSystemEvent {
132     public:
133         WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
134             : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
135         { }
136
137         QPointer<QWindow> window;
138         Qt::WindowState newState;
139     };
140
141     class UserEvent : public WindowSystemEvent {
142     public:
143         UserEvent(QWindow * w, ulong time, EventType t)
144             : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
145         QPointer<QWindow> window;
146         bool nullWindow;
147         unsigned long timestamp;
148     };
149
150     class InputEvent: public UserEvent {
151     public:
152         InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods)
153             : UserEvent(w, time, t), modifiers(mods) {}
154         Qt::KeyboardModifiers modifiers;
155     };
156
157     class MouseEvent : public InputEvent {
158     public:
159         MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global,
160                    Qt::MouseButtons b, Qt::KeyboardModifiers mods)
161             : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b) { }
162         MouseEvent(QWindow * w, ulong time, EventType t, const QPointF & local, const QPointF & global,
163                    Qt::MouseButtons b, Qt::KeyboardModifiers mods)
164             : InputEvent(w, time, t, mods), localPos(local), globalPos(global), buttons(b) { }
165         QPointF localPos;
166         QPointF globalPos;
167         Qt::MouseButtons buttons;
168     };
169
170     class WheelEvent : public InputEvent {
171     public:
172         WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
173                    Qt::KeyboardModifiers mods)
174             : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global) { }
175         QPoint pixelDelta;
176         QPoint angleDelta;
177         int qt4Delta;
178         Qt::Orientation qt4Orientation;
179         QPointF localPos;
180         QPointF globalPos;
181     };
182
183     class KeyEvent : public InputEvent {
184     public:
185         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
186             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
187              repeatCount(count), keyType(t),
188              nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
189         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
190                  quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
191                  const QString & text = QString(), bool autorep = false, ushort count = 1)
192             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
193              repeatCount(count), keyType(t),
194              nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
195         int key;
196         QString unicode;
197         bool repeat;
198         ushort repeatCount;
199         QEvent::Type keyType;
200         quint32 nativeScanCode;
201         quint32 nativeVirtualKey;
202         quint32 nativeModifiers;
203     };
204
205     class TouchEvent : public InputEvent {
206     public:
207         TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev,
208                    const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
209             :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { }
210         QTouchDevice *device;
211         QList<QTouchEvent::TouchPoint> points;
212         QEvent::Type touchType;
213     };
214
215     class ScreenOrientationEvent : public WindowSystemEvent {
216     public:
217         ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
218             : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
219         QPointer<QScreen> screen;
220         Qt::ScreenOrientation orientation;
221     };
222
223     class ScreenGeometryEvent : public WindowSystemEvent {
224     public:
225         ScreenGeometryEvent(QScreen *s, const QRect &g)
226             : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
227         QPointer<QScreen> screen;
228         QRect geometry;
229     };
230
231     class ScreenAvailableGeometryEvent : public WindowSystemEvent {
232     public:
233         ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
234             : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
235         QPointer<QScreen> screen;
236         QRect availableGeometry;
237     };
238
239     class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
240     public:
241         ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
242             : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
243         QPointer<QScreen> screen;
244         qreal dpiX;
245         qreal dpiY;
246     };
247
248     class ScreenRefreshRateEvent : public WindowSystemEvent {
249     public:
250         ScreenRefreshRateEvent(QScreen *s, qreal r)
251             : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
252         QPointer<QScreen> screen;
253         qreal rate;
254     };
255
256     class ThemeChangeEvent : public WindowSystemEvent {
257     public:
258         explicit ThemeChangeEvent(QWindow * w)
259             : WindowSystemEvent(ThemeChange), window(w) { }
260         QPointer<QWindow> window;
261     };
262
263     class ExposeEvent : public WindowSystemEvent {
264     public:
265         ExposeEvent(QWindow *exposed, const QRegion &region);
266         QPointer<QWindow> exposed;
267         bool isExposed;
268         QRegion region;
269     };
270
271     class FileOpenEvent : public WindowSystemEvent {
272     public:
273         FileOpenEvent(const QString& fileName)
274             : WindowSystemEvent(FileOpen), fileName(fileName)
275         { }
276         QString fileName;
277     };
278
279     class TabletEvent : public InputEvent {
280     public:
281         static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
282                                       int device, int pointerType, qreal pressure, int xTilt, int yTilt,
283                                       qreal tangentialPressure, qreal rotation, int z, qint64 uid,
284                                       Qt::KeyboardModifiers modifiers = Qt::NoModifier);
285
286         TabletEvent(QWindow *w, ulong time, bool down, const QPointF &local, const QPointF &global,
287                     int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tpressure,
288                     qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods)
289             : InputEvent(w, time, Tablet, Qt::NoModifier),
290               down(down), local(local), global(global), device(device), pointerType(pointerType),
291               pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
292               rotation(rotation), z(z), uid(uid), mods(mods) { }
293         bool down;
294         QPointF local;
295         QPointF global;
296         int device;
297         int pointerType;
298         qreal pressure;
299         int xTilt;
300         int yTilt;
301         qreal tangentialPressure;
302         qreal rotation;
303         int z;
304         qint64 uid;
305         Qt::KeyboardModifiers mods;
306     };
307
308     class TabletEnterProximityEvent : public InputEvent {
309     public:
310         TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid)
311             : InputEvent(0, time, TabletEnterProximity, Qt::NoModifier),
312               device(device), pointerType(pointerType), uid(uid) { }
313         int device;
314         int pointerType;
315         qint64 uid;
316     };
317
318     class TabletLeaveProximityEvent : public InputEvent {
319     public:
320         TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid)
321             : InputEvent(0, time, TabletLeaveProximity, Qt::NoModifier),
322               device(device), pointerType(pointerType), uid(uid) { }
323         int device;
324         int pointerType;
325         qint64 uid;
326     };
327
328     class WindowSystemEventList {
329         QList<WindowSystemEvent *> impl;
330         mutable QMutex mutex;
331     public:
332         WindowSystemEventList() : impl(), mutex() {}
333         ~WindowSystemEventList()
334         { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
335
336         void prepend(WindowSystemEvent *e)
337         { const QMutexLocker locker(&mutex); impl.prepend(e); }
338         WindowSystemEvent *takeFirstOrReturnNull()
339         { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); }
340         void append(WindowSystemEvent *e)
341         { const QMutexLocker locker(&mutex); impl.append(e); }
342         int count() const
343         { const QMutexLocker locker(&mutex); return impl.count(); }
344     private:
345         Q_DISABLE_COPY(WindowSystemEventList);
346     };
347
348     static WindowSystemEventList windowSystemEventQueue;
349
350     static int windowSystemEventsQueued();
351     static WindowSystemEvent * getWindowSystemEvent();
352     static void queueWindowSystemEvent(WindowSystemEvent *ev);
353
354     static QElapsedTimer eventTime;
355
356     static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);
357 };
358
359 QT_END_HEADER
360 QT_END_NAMESPACE
361
362 #endif // QWINDOWSYSTEMINTERFACE_P_H