1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the test suite 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 The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 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); ~QNativeEvent()63 virtual ~QNativeEvent(){}; id()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 QNativeMouseEvent()73 QNativeMouseEvent(){}; 74 QNativeMouseEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QNativeMouseEvent()75 virtual ~QNativeMouseEvent(){}; id()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 QNativeMouseMoveEvent()85 QNativeMouseMoveEvent(){}; 86 QNativeMouseMoveEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QNativeMouseMoveEvent()87 virtual ~QNativeMouseMoveEvent(){}; id()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 QNativeMouseButtonEvent()96 QNativeMouseButtonEvent(){}; 97 QNativeMouseButtonEvent(QPoint globalPos, Qt::MouseButton button, int clickCount, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QNativeMouseButtonEvent()98 virtual ~QNativeMouseButtonEvent(){}; id()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 QNativeMouseDragEvent()110 QNativeMouseDragEvent(){}; 111 QNativeMouseDragEvent(QPoint globalPos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QNativeMouseDragEvent()112 virtual ~QNativeMouseDragEvent(){}; id()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 QNativeMouseWheelEvent()121 QNativeMouseWheelEvent(){}; 122 QNativeMouseWheelEvent(QPoint globalPos, int delta, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QNativeMouseWheelEvent()123 virtual ~QNativeMouseWheelEvent(){}; id()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 QNativeKeyEvent()134 QNativeKeyEvent(){}; 135 QNativeKeyEvent(int nativeKeyCode, bool press, Qt::KeyboardModifiers modifiers = Qt::NoModifier); 136 QNativeKeyEvent(int nativeKeyCode, bool press, QChar character, Qt::KeyboardModifiers modifiers); ~QNativeKeyEvent()137 virtual ~QNativeKeyEvent(){}; id()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); ~QNativeModifierEvent()160 virtual ~QNativeModifierEvent(){}; id()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); nativeMousePressEvent(QNativeMouseButtonEvent *)204 virtual void nativeMousePressEvent(QNativeMouseButtonEvent *){}; nativeMouseReleaseEvent(QNativeMouseButtonEvent *)205 virtual void nativeMouseReleaseEvent(QNativeMouseButtonEvent *){}; nativeMouseMoveEvent(QNativeMouseMoveEvent *)206 virtual void nativeMouseMoveEvent(QNativeMouseMoveEvent *){}; nativeMouseDragEvent(QNativeMouseDragEvent *)207 virtual void nativeMouseDragEvent(QNativeMouseDragEvent *){}; nativeMouseWheelEvent(QNativeMouseWheelEvent *)208 virtual void nativeMouseWheelEvent(QNativeMouseWheelEvent *){}; nativeKeyPressEvent(QNativeKeyEvent *)209 virtual void nativeKeyPressEvent(QNativeKeyEvent *){}; nativeKeyReleaseEvent(QNativeKeyEvent *)210 virtual void nativeKeyReleaseEvent(QNativeKeyEvent *){}; nativeModifierEvent(QNativeModifierEvent *)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 229