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