Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-28 09:22:45

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QCOREEVENT_H
0006 #define QCOREEVENT_H
0007 
0008 #include <QtCore/qbasictimer.h>
0009 #include <QtCore/qnamespace.h>
0010 #include <QtCore/qbytearray.h>
0011 #include <QtCore/qobjectdefs.h>
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 template <typename Event> class QEventStorage;
0016 
0017 #define Q_EVENT_DISABLE_COPY(Class) \
0018 protected: \
0019     Class(const Class &) = default; \
0020     Class(Class &&) = delete; \
0021     Class &operator=(const Class &other) = default; \
0022     Class &operator=(Class &&) = delete
0023 
0024 #define Q_DECL_EVENT_COMMON(Class) \
0025         friend class QEventStorage<Class>; \
0026     protected: \
0027         Class(const Class &); \
0028         Class(Class &&) = delete; \
0029         Class &operator=(const Class &other) = default; \
0030         Class &operator=(Class &&) = delete; \
0031     public: \
0032         Class* clone() const override; \
0033         ~Class() override; \
0034     private:
0035 
0036 #define Q_IMPL_EVENT_COMMON(Class) \
0037     Class::Class(const Class &) = default; \
0038     Class::~Class() = default; \
0039     Class* Class::clone() const \
0040     { \
0041         auto c = new Class(*this); \
0042         [[maybe_unused]] QEvent *e = c; \
0043         /* check that covariant return is safe to add */ \
0044         Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e)); \
0045         return c; \
0046     }
0047 
0048 class QEventPrivate;
0049 class Q_CORE_EXPORT QEvent           // event base class
0050 {
0051     Q_GADGET
0052     QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
0053 
0054     Q_EVENT_DISABLE_COPY(QEvent);
0055 public:
0056     enum Type {
0057         /*
0058           If you get a strange compiler error on the line with None,
0059           it's probably because you're also including X11 headers,
0060           which #define the symbol None. Put the X11 includes after
0061           the Qt includes to solve this problem.
0062         */
0063         None = 0,                               // invalid event
0064         Timer = 1,                              // timer event
0065         MouseButtonPress = 2,                   // mouse button pressed
0066         MouseButtonRelease = 3,                 // mouse button released
0067         MouseButtonDblClick = 4,                // mouse button double click
0068         MouseMove = 5,                          // mouse move
0069         KeyPress = 6,                           // key pressed
0070         KeyRelease = 7,                         // key released
0071         FocusIn = 8,                            // keyboard focus received
0072         FocusOut = 9,                           // keyboard focus lost
0073         FocusAboutToChange = 23,                // keyboard focus is about to be lost
0074         Enter = 10,                             // mouse enters widget
0075         Leave = 11,                             // mouse leaves widget
0076         Paint = 12,                             // paint widget
0077         Move = 13,                              // move widget
0078         Resize = 14,                            // resize widget
0079         Create = 15,                            // after widget creation
0080         Destroy = 16,                           // during widget destruction
0081         Show = 17,                              // widget is shown
0082         Hide = 18,                              // widget is hidden
0083         Close = 19,                             // request to close widget
0084         Quit = 20,                              // request to quit application
0085         ParentChange = 21,                      // object has been reparented
0086         ParentAboutToChange = 131,              // sent just before the parent change is done
0087         ThreadChange = 22,                      // object has changed threads
0088         WindowActivate = 24,                    // window was activated
0089         WindowDeactivate = 25,                  // window was deactivated
0090         ShowToParent = 26,                      // widget is shown to parent
0091         HideToParent = 27,                      // widget is hidden to parent
0092         Wheel = 31,                             // wheel event
0093         WindowTitleChange = 33,                 // window title changed
0094         WindowIconChange = 34,                  // icon changed
0095         ApplicationWindowIconChange = 35,       // application icon changed
0096         ApplicationFontChange = 36,             // application font changed
0097         ApplicationLayoutDirectionChange = 37,  // application layout direction changed
0098         ApplicationPaletteChange = 38,          // application palette changed
0099         PaletteChange = 39,                     // widget palette changed
0100         Clipboard = 40,                         // internal clipboard event
0101         Speech = 42,                            // reserved for speech input
0102         MetaCall =  43,                         // meta call event
0103         SockAct = 50,                           // socket activation
0104         WinEventAct = 132,                      // win event activation
0105         DeferredDelete = 52,                    // deferred delete event
0106         DragEnter = 60,                         // drag moves into widget
0107         DragMove = 61,                          // drag moves in widget
0108         DragLeave = 62,                         // drag leaves or is cancelled
0109         Drop = 63,                              // actual drop
0110         DragResponse = 64,                      // drag accepted/rejected
0111         ChildAdded = 68,                        // new child widget
0112         ChildPolished = 69,                     // polished child widget
0113         ChildRemoved = 71,                      // deleted child widget
0114         ShowWindowRequest = 73,                 // widget's window should be mapped
0115         PolishRequest = 74,                     // widget should be polished
0116         Polish = 75,                            // widget is polished
0117         LayoutRequest = 76,                     // widget should be relayouted
0118         UpdateRequest = 77,                     // widget should be repainted
0119         UpdateLater = 78,                       // request update() later
0120 
0121         EmbeddingControl = 79,                  // ActiveX embedding
0122         ActivateControl = 80,                   // ActiveX activation
0123         DeactivateControl = 81,                 // ActiveX deactivation
0124         ContextMenu = 82,                       // context popup menu
0125         InputMethod = 83,                       // input method
0126         TabletMove = 87,                        // Wacom tablet event
0127         LocaleChange = 88,                      // the system locale changed
0128         LanguageChange = 89,                    // the application language changed
0129         LayoutDirectionChange = 90,             // the layout direction changed
0130         Style = 91,                             // internal style event
0131         TabletPress = 92,                       // tablet press
0132         TabletRelease = 93,                     // tablet release
0133         OkRequest = 94,                         // CE (Ok) button pressed
0134         HelpRequest = 95,                       // CE (?)  button pressed
0135 
0136         IconDrag = 96,                          // proxy icon dragged
0137 
0138         FontChange = 97,                        // font has changed
0139         EnabledChange = 98,                     // enabled state has changed
0140         ActivationChange = 99,                  // window activation has changed
0141         StyleChange = 100,                      // style has changed
0142         IconTextChange = 101,                   // icon text has changed.  Deprecated.
0143         ModifiedChange = 102,                   // modified state has changed
0144         MouseTrackingChange = 109,              // mouse tracking state has changed
0145 
0146         WindowBlocked = 103,                    // window is about to be blocked modally
0147         WindowUnblocked = 104,                  // windows modal blocking has ended
0148         WindowStateChange = 105,
0149 
0150         ReadOnlyChange = 106,                   // readonly state has changed
0151 
0152         ToolTip = 110,
0153         WhatsThis = 111,
0154         StatusTip = 112,
0155 
0156         ActionChanged = 113,
0157         ActionAdded = 114,
0158         ActionRemoved = 115,
0159 
0160         FileOpen = 116,                         // file open request
0161 
0162         Shortcut = 117,                         // shortcut triggered
0163         ShortcutOverride = 51,                  // shortcut override request
0164 
0165         WhatsThisClicked = 118,
0166 
0167         ToolBarChange = 120,                    // toolbar visibility toggled
0168 
0169         ApplicationActivate = 121,              // deprecated. Use ApplicationStateChange instead.
0170         ApplicationActivated = ApplicationActivate, // deprecated
0171         ApplicationDeactivate = 122,            // deprecated. Use ApplicationStateChange instead.
0172         ApplicationDeactivated = ApplicationDeactivate, // deprecated
0173 
0174         QueryWhatsThis = 123,                   // query what's this widget help
0175         EnterWhatsThisMode = 124,
0176         LeaveWhatsThisMode = 125,
0177 
0178         ZOrderChange = 126,                     // child widget has had its z-order changed
0179 
0180         HoverEnter = 127,                       // mouse cursor enters a hover widget
0181         HoverLeave = 128,                       // mouse cursor leaves a hover widget
0182         HoverMove = 129,                        // mouse cursor move inside a hover widget
0183 
0184         // last event id used = 132
0185 
0186 #ifdef QT_KEYPAD_NAVIGATION
0187         EnterEditFocus = 150,                   // enter edit mode in keypad navigation
0188         LeaveEditFocus = 151,                   // enter edit mode in keypad navigation
0189 #endif
0190         AcceptDropsChange = 152,
0191 
0192         ZeroTimerEvent = 154,                   // Used for Windows Zero timer events
0193 
0194         GraphicsSceneMouseMove = 155,           // GraphicsView
0195         GraphicsSceneMousePress = 156,
0196         GraphicsSceneMouseRelease = 157,
0197         GraphicsSceneMouseDoubleClick = 158,
0198         GraphicsSceneContextMenu = 159,
0199         GraphicsSceneHoverEnter = 160,
0200         GraphicsSceneHoverMove = 161,
0201         GraphicsSceneHoverLeave = 162,
0202         GraphicsSceneHelp = 163,
0203         GraphicsSceneDragEnter = 164,
0204         GraphicsSceneDragMove = 165,
0205         GraphicsSceneDragLeave = 166,
0206         GraphicsSceneDrop = 167,
0207         GraphicsSceneWheel = 168,
0208         GraphicsSceneLeave = 220,
0209 
0210         KeyboardLayoutChange = 169,             // keyboard layout changed
0211 
0212         DynamicPropertyChange = 170,            // A dynamic property was changed through setProperty/property
0213 
0214         TabletEnterProximity = 171,
0215         TabletLeaveProximity = 172,
0216 
0217         NonClientAreaMouseMove = 173,
0218         NonClientAreaMouseButtonPress = 174,
0219         NonClientAreaMouseButtonRelease = 175,
0220         NonClientAreaMouseButtonDblClick = 176,
0221 
0222         MacSizeChange = 177,                    // when the Qt::WA_Mac{Normal,Small,Mini}Size changes
0223 
0224         ContentsRectChange = 178,               // sent by QWidget::setContentsMargins (internal)
0225 
0226         MacGLWindowChange = 179,                // Internal! the window of the GLWidget has changed
0227 
0228         FutureCallOut = 180,
0229 
0230         GraphicsSceneResize  = 181,
0231         GraphicsSceneMove  = 182,
0232 
0233         CursorChange = 183,
0234         ToolTipChange = 184,
0235 
0236         NetworkReplyUpdated = 185,              // Internal for QNetworkReply
0237 
0238         GrabMouse = 186,
0239         UngrabMouse = 187,
0240         GrabKeyboard = 188,
0241         UngrabKeyboard = 189,
0242 
0243         StateMachineSignal = 192,
0244         StateMachineWrapped = 193,
0245 
0246         TouchBegin = 194,
0247         TouchUpdate = 195,
0248         TouchEnd = 196,
0249 
0250 #ifndef QT_NO_GESTURES
0251         NativeGesture = 197,                    // QtGui native gesture
0252 #endif
0253         RequestSoftwareInputPanel = 199,
0254         CloseSoftwareInputPanel = 200,
0255 
0256         WinIdChange = 203,
0257 #ifndef QT_NO_GESTURES
0258         Gesture = 198,
0259         GestureOverride = 202,
0260 #endif
0261         ScrollPrepare = 204,
0262         Scroll = 205,
0263 
0264         Expose = 206,
0265 
0266         InputMethodQuery = 207,
0267         OrientationChange = 208,                // Screen orientation has changed
0268 
0269         TouchCancel = 209,
0270 
0271         ThemeChange = 210,
0272 
0273         SockClose = 211,                        // socket closed
0274 
0275         PlatformPanel = 212,
0276 
0277         StyleAnimationUpdate = 213,             // style animation target should be updated
0278         ApplicationStateChange = 214,
0279 
0280         WindowChangeInternal = 215,             // internal for QQuickWidget and texture-based widgets
0281         ScreenChangeInternal = 216,
0282 
0283         PlatformSurface = 217,                  // Platform surface created or about to be destroyed
0284 
0285         Pointer = 218,                          // Qt 5: QQuickPointerEvent; Qt 6: unused so far
0286 
0287         TabletTrackingChange = 219,             // tablet tracking state has changed
0288 
0289         // GraphicsSceneLeave = 220,
0290         WindowAboutToChangeInternal = 221,      // internal for QQuickWidget and texture-based widgets
0291 
0292         DevicePixelRatioChange = 222,
0293 
0294         ChildWindowAdded = 223,
0295         ChildWindowRemoved = 224,
0296         ParentWindowAboutToChange = 225,
0297         ParentWindowChange = 226,
0298 
0299         SafeAreaMarginsChange = 227,
0300 
0301         // 512 reserved for Qt Jambi's MetaCall event
0302         // 513 reserved for Qt Jambi's DeleteOnMainThread event
0303 
0304         User = 1000,                            // first user event id
0305         MaxUser = 65535                         // last user event id
0306     };
0307     Q_ENUM(Type)
0308 
0309     explicit QEvent(Type type);
0310     virtual ~QEvent();
0311     inline Type type() const { return static_cast<Type>(t); }
0312     inline bool spontaneous() const { return m_spont; }
0313 
0314     inline virtual void setAccepted(bool accepted) { m_accept = accepted; }
0315     inline bool isAccepted() const { return m_accept; }
0316 
0317     inline void accept() { m_accept = true; }
0318     inline void ignore() { m_accept = false; }
0319 
0320     inline bool isInputEvent() const noexcept { return m_inputEvent; }
0321     inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
0322     inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; }
0323 
0324     static int registerEventType(int hint = -1) noexcept;
0325 
0326     virtual QEvent *clone() const;
0327 
0328 protected:
0329     QT_DEFINE_TAG_STRUCT(InputEventTag);
0330     QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
0331     QT_DEFINE_TAG_STRUCT(PointerEventTag);
0332     QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
0333     QT_DEFINE_TAG_STRUCT(SinglePointEventTag);
0334     QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
0335     quint16 t;
0336 
0337 private:
0338     /*
0339         We can assume that C++ types are 8-byte aligned, and we can't assume that compilers
0340         coalesce data members from subclasses. Use bitfields to fill up to next 8-byte
0341         aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room
0342         for future flags.
0343         Don't use bitfields for the most important flags, as that would generate more code, and
0344         access is always inline. Bytes used are:
0345         8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
0346         align the quint16s after the bools, so add another unused bool to fill that gap, which
0347         leaves us with 16 bits.
0348     */
0349     bool m_posted = false;
0350     bool m_spont = false;
0351     bool m_accept = true;
0352     bool m_unused = false;
0353     quint16 m_reserved : 13;
0354     quint16 m_inputEvent : 1;
0355     quint16 m_pointerEvent : 1;
0356     quint16 m_singlePointEvent : 1;
0357 
0358     friend class QCoreApplication;
0359     friend class QCoreApplicationPrivate;
0360     friend class QThreadData;
0361     friend class QApplication;
0362     friend class QGraphicsScenePrivate;
0363     // from QtTest:
0364     // QtWebEngine event handling requires forwarding events as spontaneous.
0365     // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases.
0366     friend class QSpontaneKeyEvent;
0367     // needs this:
0368     Q_ALWAYS_INLINE
0369     void setSpontaneous() { m_spont = true; }
0370 };
0371 
0372 class Q_CORE_EXPORT QTimerEvent : public QEvent
0373 {
0374     Q_DECL_EVENT_COMMON(QTimerEvent)
0375 public:
0376     explicit QTimerEvent(int timerId);
0377     explicit QTimerEvent(Qt::TimerId timerId);
0378 
0379     int timerId() const { return qToUnderlying(id()); }
0380     Qt::TimerId id() const { return m_id; }
0381     bool matches(const QBasicTimer &timer) const noexcept
0382     { return m_id == timer.id(); }
0383 
0384 protected:
0385     Qt::TimerId m_id;
0386 };
0387 
0388 class QObject;
0389 
0390 class Q_CORE_EXPORT QChildEvent : public QEvent
0391 {
0392     Q_DECL_EVENT_COMMON(QChildEvent)
0393 public:
0394     QChildEvent(Type type, QObject *child);
0395 
0396     QObject *child() const { return c; }
0397     bool added() const { return type() == ChildAdded; }
0398     bool polished() const { return type() == ChildPolished; }
0399     bool removed() const { return type() == ChildRemoved; }
0400 
0401 protected:
0402     QObject *c;
0403 };
0404 
0405 class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
0406 {
0407     Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent)
0408 public:
0409     explicit QDynamicPropertyChangeEvent(const QByteArray &name);
0410 
0411     inline QByteArray propertyName() const { return n; }
0412 
0413 private:
0414     QByteArray n;
0415 };
0416 
0417 QT_END_NAMESPACE
0418 
0419 #endif // QCOREEVENT_H