| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QCOREEVENT_H |
| 5 | #define QCOREEVENT_H |
| 6 | |
| 7 | #include <QtCore/qnamespace.h> |
| 8 | #include <QtCore/qbytearray.h> |
| 9 | #include <QtCore/qobjectdefs.h> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | #define Q_EVENT_DISABLE_COPY(Class) \ |
| 14 | protected: \ |
| 15 | Class(const Class &) = default; \ |
| 16 | Class(Class &&) = delete; \ |
| 17 | Class &operator=(const Class &other) = default; \ |
| 18 | Class &operator=(Class &&) = delete |
| 19 | |
| 20 | #define Q_DECL_EVENT_COMMON(Class) \ |
| 21 | protected: \ |
| 22 | Class(const Class &); \ |
| 23 | Class(Class &&) = delete; \ |
| 24 | Class &operator=(const Class &other) = default; \ |
| 25 | Class &operator=(Class &&) = delete; \ |
| 26 | public: \ |
| 27 | Class* clone() const override; \ |
| 28 | ~Class() override; \ |
| 29 | private: |
| 30 | |
| 31 | #define Q_IMPL_EVENT_COMMON(Class) \ |
| 32 | Class::Class(const Class &) = default; \ |
| 33 | Class::~Class() = default; \ |
| 34 | Class* Class::clone() const \ |
| 35 | { \ |
| 36 | auto c = new Class(*this); \ |
| 37 | [[maybe_unused]] QEvent *e = c; \ |
| 38 | /* check that covariant return is safe to add */ \ |
| 39 | Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e)); \ |
| 40 | return c; \ |
| 41 | } |
| 42 | |
| 43 | class QEventPrivate; |
| 44 | class Q_CORE_EXPORT QEvent // event base class |
| 45 | { |
| 46 | Q_GADGET |
| 47 | QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) |
| 48 | |
| 49 | Q_EVENT_DISABLE_COPY(QEvent); |
| 50 | public: |
| 51 | enum Type { |
| 52 | /* |
| 53 | If you get a strange compiler error on the line with None, |
| 54 | it's probably because you're also including X11 headers, |
| 55 | which #define the symbol None. Put the X11 includes after |
| 56 | the Qt includes to solve this problem. |
| 57 | */ |
| 58 | None = 0, // invalid event |
| 59 | Timer = 1, // timer event |
| 60 | MouseButtonPress = 2, // mouse button pressed |
| 61 | MouseButtonRelease = 3, // mouse button released |
| 62 | MouseButtonDblClick = 4, // mouse button double click |
| 63 | MouseMove = 5, // mouse move |
| 64 | KeyPress = 6, // key pressed |
| 65 | KeyRelease = 7, // key released |
| 66 | FocusIn = 8, // keyboard focus received |
| 67 | FocusOut = 9, // keyboard focus lost |
| 68 | FocusAboutToChange = 23, // keyboard focus is about to be lost |
| 69 | Enter = 10, // mouse enters widget |
| 70 | Leave = 11, // mouse leaves widget |
| 71 | Paint = 12, // paint widget |
| 72 | Move = 13, // move widget |
| 73 | Resize = 14, // resize widget |
| 74 | Create = 15, // after widget creation |
| 75 | Destroy = 16, // during widget destruction |
| 76 | Show = 17, // widget is shown |
| 77 | Hide = 18, // widget is hidden |
| 78 | Close = 19, // request to close widget |
| 79 | Quit = 20, // request to quit application |
| 80 | ParentChange = 21, // object has been reparented |
| 81 | ParentAboutToChange = 131, // sent just before the parent change is done |
| 82 | ThreadChange = 22, // object has changed threads |
| 83 | WindowActivate = 24, // window was activated |
| 84 | WindowDeactivate = 25, // window was deactivated |
| 85 | ShowToParent = 26, // widget is shown to parent |
| 86 | HideToParent = 27, // widget is hidden to parent |
| 87 | Wheel = 31, // wheel event |
| 88 | WindowTitleChange = 33, // window title changed |
| 89 | WindowIconChange = 34, // icon changed |
| 90 | ApplicationWindowIconChange = 35, // application icon changed |
| 91 | ApplicationFontChange = 36, // application font changed |
| 92 | ApplicationLayoutDirectionChange = 37, // application layout direction changed |
| 93 | ApplicationPaletteChange = 38, // application palette changed |
| 94 | PaletteChange = 39, // widget palette changed |
| 95 | Clipboard = 40, // internal clipboard event |
| 96 | Speech = 42, // reserved for speech input |
| 97 | MetaCall = 43, // meta call event |
| 98 | SockAct = 50, // socket activation |
| 99 | WinEventAct = 132, // win event activation |
| 100 | DeferredDelete = 52, // deferred delete event |
| 101 | DragEnter = 60, // drag moves into widget |
| 102 | DragMove = 61, // drag moves in widget |
| 103 | DragLeave = 62, // drag leaves or is cancelled |
| 104 | Drop = 63, // actual drop |
| 105 | DragResponse = 64, // drag accepted/rejected |
| 106 | ChildAdded = 68, // new child widget |
| 107 | ChildPolished = 69, // polished child widget |
| 108 | ChildRemoved = 71, // deleted child widget |
| 109 | ShowWindowRequest = 73, // widget's window should be mapped |
| 110 | PolishRequest = 74, // widget should be polished |
| 111 | Polish = 75, // widget is polished |
| 112 | LayoutRequest = 76, // widget should be relayouted |
| 113 | UpdateRequest = 77, // widget should be repainted |
| 114 | UpdateLater = 78, // request update() later |
| 115 | |
| 116 | EmbeddingControl = 79, // ActiveX embedding |
| 117 | ActivateControl = 80, // ActiveX activation |
| 118 | DeactivateControl = 81, // ActiveX deactivation |
| 119 | = 82, // context popup menu |
| 120 | InputMethod = 83, // input method |
| 121 | TabletMove = 87, // Wacom tablet event |
| 122 | LocaleChange = 88, // the system locale changed |
| 123 | LanguageChange = 89, // the application language changed |
| 124 | LayoutDirectionChange = 90, // the layout direction changed |
| 125 | Style = 91, // internal style event |
| 126 | TabletPress = 92, // tablet press |
| 127 | TabletRelease = 93, // tablet release |
| 128 | OkRequest = 94, // CE (Ok) button pressed |
| 129 | HelpRequest = 95, // CE (?) button pressed |
| 130 | |
| 131 | IconDrag = 96, // proxy icon dragged |
| 132 | |
| 133 | FontChange = 97, // font has changed |
| 134 | EnabledChange = 98, // enabled state has changed |
| 135 | ActivationChange = 99, // window activation has changed |
| 136 | StyleChange = 100, // style has changed |
| 137 | IconTextChange = 101, // icon text has changed. Deprecated. |
| 138 | ModifiedChange = 102, // modified state has changed |
| 139 | MouseTrackingChange = 109, // mouse tracking state has changed |
| 140 | |
| 141 | WindowBlocked = 103, // window is about to be blocked modally |
| 142 | WindowUnblocked = 104, // windows modal blocking has ended |
| 143 | WindowStateChange = 105, |
| 144 | |
| 145 | ReadOnlyChange = 106, // readonly state has changed |
| 146 | |
| 147 | ToolTip = 110, |
| 148 | WhatsThis = 111, |
| 149 | StatusTip = 112, |
| 150 | |
| 151 | ActionChanged = 113, |
| 152 | ActionAdded = 114, |
| 153 | ActionRemoved = 115, |
| 154 | |
| 155 | FileOpen = 116, // file open request |
| 156 | |
| 157 | Shortcut = 117, // shortcut triggered |
| 158 | ShortcutOverride = 51, // shortcut override request |
| 159 | |
| 160 | WhatsThisClicked = 118, |
| 161 | |
| 162 | ToolBarChange = 120, // toolbar visibility toggled |
| 163 | |
| 164 | ApplicationActivate = 121, // deprecated. Use ApplicationStateChange instead. |
| 165 | ApplicationActivated = ApplicationActivate, // deprecated |
| 166 | ApplicationDeactivate = 122, // deprecated. Use ApplicationStateChange instead. |
| 167 | ApplicationDeactivated = ApplicationDeactivate, // deprecated |
| 168 | |
| 169 | QueryWhatsThis = 123, // query what's this widget help |
| 170 | EnterWhatsThisMode = 124, |
| 171 | LeaveWhatsThisMode = 125, |
| 172 | |
| 173 | ZOrderChange = 126, // child widget has had its z-order changed |
| 174 | |
| 175 | HoverEnter = 127, // mouse cursor enters a hover widget |
| 176 | HoverLeave = 128, // mouse cursor leaves a hover widget |
| 177 | HoverMove = 129, // mouse cursor move inside a hover widget |
| 178 | |
| 179 | // last event id used = 132 |
| 180 | |
| 181 | #ifdef QT_KEYPAD_NAVIGATION |
| 182 | EnterEditFocus = 150, // enter edit mode in keypad navigation |
| 183 | LeaveEditFocus = 151, // enter edit mode in keypad navigation |
| 184 | #endif |
| 185 | AcceptDropsChange = 152, |
| 186 | |
| 187 | ZeroTimerEvent = 154, // Used for Windows Zero timer events |
| 188 | |
| 189 | GraphicsSceneMouseMove = 155, // GraphicsView |
| 190 | GraphicsSceneMousePress = 156, |
| 191 | GraphicsSceneMouseRelease = 157, |
| 192 | GraphicsSceneMouseDoubleClick = 158, |
| 193 | = 159, |
| 194 | GraphicsSceneHoverEnter = 160, |
| 195 | GraphicsSceneHoverMove = 161, |
| 196 | GraphicsSceneHoverLeave = 162, |
| 197 | GraphicsSceneHelp = 163, |
| 198 | GraphicsSceneDragEnter = 164, |
| 199 | GraphicsSceneDragMove = 165, |
| 200 | GraphicsSceneDragLeave = 166, |
| 201 | GraphicsSceneDrop = 167, |
| 202 | GraphicsSceneWheel = 168, |
| 203 | GraphicsSceneLeave = 220, |
| 204 | |
| 205 | KeyboardLayoutChange = 169, // keyboard layout changed |
| 206 | |
| 207 | DynamicPropertyChange = 170, // A dynamic property was changed through setProperty/property |
| 208 | |
| 209 | TabletEnterProximity = 171, |
| 210 | TabletLeaveProximity = 172, |
| 211 | |
| 212 | NonClientAreaMouseMove = 173, |
| 213 | NonClientAreaMouseButtonPress = 174, |
| 214 | NonClientAreaMouseButtonRelease = 175, |
| 215 | NonClientAreaMouseButtonDblClick = 176, |
| 216 | |
| 217 | MacSizeChange = 177, // when the Qt::WA_Mac{Normal,Small,Mini}Size changes |
| 218 | |
| 219 | ContentsRectChange = 178, // sent by QWidget::setContentsMargins (internal) |
| 220 | |
| 221 | MacGLWindowChange = 179, // Internal! the window of the GLWidget has changed |
| 222 | |
| 223 | FutureCallOut = 180, |
| 224 | |
| 225 | GraphicsSceneResize = 181, |
| 226 | GraphicsSceneMove = 182, |
| 227 | |
| 228 | CursorChange = 183, |
| 229 | ToolTipChange = 184, |
| 230 | |
| 231 | NetworkReplyUpdated = 185, // Internal for QNetworkReply |
| 232 | |
| 233 | GrabMouse = 186, |
| 234 | UngrabMouse = 187, |
| 235 | GrabKeyboard = 188, |
| 236 | UngrabKeyboard = 189, |
| 237 | |
| 238 | StateMachineSignal = 192, |
| 239 | StateMachineWrapped = 193, |
| 240 | |
| 241 | TouchBegin = 194, |
| 242 | TouchUpdate = 195, |
| 243 | TouchEnd = 196, |
| 244 | |
| 245 | #ifndef QT_NO_GESTURES |
| 246 | NativeGesture = 197, // QtGui native gesture |
| 247 | #endif |
| 248 | RequestSoftwareInputPanel = 199, |
| 249 | CloseSoftwareInputPanel = 200, |
| 250 | |
| 251 | WinIdChange = 203, |
| 252 | #ifndef QT_NO_GESTURES |
| 253 | Gesture = 198, |
| 254 | GestureOverride = 202, |
| 255 | #endif |
| 256 | ScrollPrepare = 204, |
| 257 | Scroll = 205, |
| 258 | |
| 259 | Expose = 206, |
| 260 | |
| 261 | InputMethodQuery = 207, |
| 262 | OrientationChange = 208, // Screen orientation has changed |
| 263 | |
| 264 | TouchCancel = 209, |
| 265 | |
| 266 | ThemeChange = 210, |
| 267 | |
| 268 | SockClose = 211, // socket closed |
| 269 | |
| 270 | PlatformPanel = 212, |
| 271 | |
| 272 | StyleAnimationUpdate = 213, // style animation target should be updated |
| 273 | ApplicationStateChange = 214, |
| 274 | |
| 275 | WindowChangeInternal = 215, // internal for QQuickWidget and texture-based widgets |
| 276 | ScreenChangeInternal = 216, |
| 277 | |
| 278 | PlatformSurface = 217, // Platform surface created or about to be destroyed |
| 279 | |
| 280 | Pointer = 218, // Qt 5: QQuickPointerEvent; Qt 6: unused so far |
| 281 | |
| 282 | TabletTrackingChange = 219, // tablet tracking state has changed |
| 283 | |
| 284 | // GraphicsSceneLeave = 220, |
| 285 | WindowAboutToChangeInternal = 221, // internal for QQuickWidget and texture-based widgets |
| 286 | |
| 287 | DevicePixelRatioChange = 222, |
| 288 | |
| 289 | ChildWindowAdded = 223, |
| 290 | ChildWindowRemoved = 224, |
| 291 | ParentWindowAboutToChange = 225, |
| 292 | ParentWindowChange = 226, |
| 293 | |
| 294 | // 512 reserved for Qt Jambi's MetaCall event |
| 295 | // 513 reserved for Qt Jambi's DeleteOnMainThread event |
| 296 | |
| 297 | User = 1000, // first user event id |
| 298 | MaxUser = 65535 // last user event id |
| 299 | }; |
| 300 | Q_ENUM(Type) |
| 301 | |
| 302 | explicit QEvent(Type type); |
| 303 | virtual ~QEvent(); |
| 304 | inline Type type() const { return static_cast<Type>(t); } |
| 305 | inline bool spontaneous() const { return m_spont; } |
| 306 | |
| 307 | inline virtual void setAccepted(bool accepted) { m_accept = accepted; } |
| 308 | inline bool isAccepted() const { return m_accept; } |
| 309 | |
| 310 | inline void accept() { m_accept = true; } |
| 311 | inline void ignore() { m_accept = false; } |
| 312 | |
| 313 | inline bool isInputEvent() const noexcept { return m_inputEvent; } |
| 314 | inline bool isPointerEvent() const noexcept { return m_pointerEvent; } |
| 315 | inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; } |
| 316 | |
| 317 | static int registerEventType(int hint = -1) noexcept; |
| 318 | |
| 319 | virtual QEvent *clone() const; |
| 320 | |
| 321 | protected: |
| 322 | QT_DEFINE_TAG_STRUCT(InputEventTag); |
| 323 | QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; } |
| 324 | QT_DEFINE_TAG_STRUCT(PointerEventTag); |
| 325 | QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; } |
| 326 | QT_DEFINE_TAG_STRUCT(SinglePointEventTag); |
| 327 | QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; } |
| 328 | quint16 t; |
| 329 | |
| 330 | private: |
| 331 | /* |
| 332 | We can assume that C++ types are 8-byte aligned, and we can't assume that compilers |
| 333 | coalesce data members from subclasses. Use bitfields to fill up to next 8-byte |
| 334 | aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room |
| 335 | for future flags. |
| 336 | Don't use bitfields for the most important flags, as that would generate more code, and |
| 337 | access is always inline. Bytes used are: |
| 338 | 8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word- |
| 339 | align the quint16s after the bools, so add another unused bool to fill that gap, which |
| 340 | leaves us with 16 bits. |
| 341 | */ |
| 342 | bool m_posted = false; |
| 343 | bool m_spont = false; |
| 344 | bool m_accept = true; |
| 345 | bool m_unused = false; |
| 346 | quint16 m_reserved : 13; |
| 347 | quint16 m_inputEvent : 1; |
| 348 | quint16 m_pointerEvent : 1; |
| 349 | quint16 m_singlePointEvent : 1; |
| 350 | |
| 351 | friend class QCoreApplication; |
| 352 | friend class QCoreApplicationPrivate; |
| 353 | friend class QThreadData; |
| 354 | friend class QApplication; |
| 355 | friend class QGraphicsScenePrivate; |
| 356 | // from QtTest: |
| 357 | // QtWebEngine event handling requires forwarding events as spontaneous. |
| 358 | // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases. |
| 359 | friend class QSpontaneKeyEvent; |
| 360 | // needs this: |
| 361 | Q_ALWAYS_INLINE |
| 362 | void setSpontaneous() { m_spont = true; } |
| 363 | }; |
| 364 | |
| 365 | class Q_CORE_EXPORT QTimerEvent : public QEvent |
| 366 | { |
| 367 | Q_DECL_EVENT_COMMON(QTimerEvent) |
| 368 | public: |
| 369 | explicit QTimerEvent(int timerId); |
| 370 | explicit QTimerEvent(Qt::TimerId timerId); |
| 371 | |
| 372 | int timerId() const { return qToUnderlying(e: id()); } |
| 373 | Qt::TimerId id() const { return m_id; } |
| 374 | |
| 375 | protected: |
| 376 | Qt::TimerId m_id; |
| 377 | }; |
| 378 | |
| 379 | class QObject; |
| 380 | |
| 381 | class Q_CORE_EXPORT QChildEvent : public QEvent |
| 382 | { |
| 383 | Q_DECL_EVENT_COMMON(QChildEvent) |
| 384 | public: |
| 385 | QChildEvent(Type type, QObject *child); |
| 386 | |
| 387 | QObject *child() const { return c; } |
| 388 | bool added() const { return type() == ChildAdded; } |
| 389 | bool polished() const { return type() == ChildPolished; } |
| 390 | bool removed() const { return type() == ChildRemoved; } |
| 391 | |
| 392 | protected: |
| 393 | QObject *c; |
| 394 | }; |
| 395 | |
| 396 | class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent |
| 397 | { |
| 398 | Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent) |
| 399 | public: |
| 400 | explicit QDynamicPropertyChangeEvent(const QByteArray &name); |
| 401 | |
| 402 | inline QByteArray propertyName() const { return n; } |
| 403 | |
| 404 | private: |
| 405 | QByteArray n; |
| 406 | }; |
| 407 | |
| 408 | QT_END_NAMESPACE |
| 409 | |
| 410 | #endif // QCOREEVENT_H |
| 411 | |