| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| | ** | |
| | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | |
| | ** Contact: http://www.qt-project.org/legal | |
| | ** | |
| | ** This file is part of the QtGui module of the Qt Toolkit. | |
| | ** | |
| | ** $QT_BEGIN_LICENSE:LGPL$ | |
| | ** Commercial License Usage | |
| | ** Licensees holding valid commercial Qt licenses may use this file in | |
| | ** accordance with the commercial license agreement provided with the | |
| | ** Software or, alternatively, in accordance with the terms contained in | |
| | ** a written agreement between you and Digia. For licensing terms and | |
| | ** conditions see http://qt.digia.com/licensing. For further information | |
| | ** use the contact form at http://qt.digia.com/contact-us. | |
| | ** | |
| | ** GNU Lesser General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU Lesser | |
| | ** General Public License version 2.1 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU Lesser General Public License version 2.1 requirements | |
| | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
| | ** | |
| | ** In addition, as a special exception, Digia gives you certain additional | |
| | ** rights. These rights are described in the Digia Qt LGPL Exception | |
| | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
| | ** | |
| | ** GNU General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU | |
| | ** General Public License version 3.0 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.GPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU General Public License version 3.0 requirements will be | |
| | ** met: http://www.gnu.org/copyleft/gpl.html. | |
| | ** | |
| | ** | |
| | ** $QT_END_LICENSE$ | |
| | ** | |
| | ****************************************************************************/**************************************************************************** | |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "private/qwindow_p.h" | - |
| 43 | #include "qwidgetwindow_qpa_p.h" | - |
| 44 | | - |
| 45 | #include "private/qwidget_p.h" | - |
| 46 | #include "private/qapplication_p.h" | - |
| 47 | #ifndef QT_NO_ACCESSIBILITY | - |
| 48 | #include <QtGui/qaccessible.h> | - |
| 49 | #endif | - |
| 50 | #include <private/qwidgetbackingstore_p.h> | - |
| 51 | #include <qpa/qwindowsysteminterface_p.h> | - |
| 52 | | - |
| 53 | QT_BEGIN_NAMESPACE | - |
| 54 | | - |
| 55 | QWidget *qt_button_down = 0; // widget got last button-down | - |
| 56 | static QWidget *qt_tablet_target = 0; | - |
| 57 | | - |
| 58 | // popup control | - |
| 59 | QWidget *qt_popup_down = 0; // popup that contains the pressed widget | - |
| 60 | extern int openPopupCount; | - |
| 61 | bool qt_replay_popup_mouse_event = false; | - |
| 62 | extern bool qt_try_modal(QWidget *widget, QEvent::Type type); | - |
| 63 | | - |
| 64 | class QWidgetWindowPrivate : public QWindowPrivate | - |
| 65 | { | - |
| 66 | Q_DECLARE_PUBLIC(QWidgetWindow) | - |
| 67 | public: | - |
| 68 | QWindow *eventReceiver() { | - |
| 69 | Q_Q(QWidgetWindow); executed (the execution status of this line is deduced): QWidgetWindow * const q = q_func(); | - |
| 70 | QWindow *w = q; executed (the execution status of this line is deduced): QWindow *w = q; | - |
| 71 | while (w->parent() && qobject_cast<QWidgetWindow *>(w) && qobject_cast<QWidgetWindow *>(w->parent())) { partially evaluated: w->parent()| no Evaluation Count:0 | yes Evaluation Count:1812 |
never evaluated: qobject_cast<QWidgetWindow *>(w) never evaluated: qobject_cast<QWidgetWindow *>(w->parent()) | 0-1812 |
| 72 | w = w->parent(); never executed (the execution status of this line is deduced): w = w->parent(); | - |
| 73 | } | 0 |
| 74 | return w; executed: return w;Execution Count:1812 | 1812 |
| 75 | } | - |
| 76 | }; | - |
| 77 | | - |
| 78 | QWidgetWindow::QWidgetWindow(QWidget *widget) | - |
| 79 | : QWindow(*new QWidgetWindowPrivate(), 0) | - |
| 80 | , m_widget(widget) | - |
| 81 | { | - |
| 82 | updateObjectName(); executed (the execution status of this line is deduced): updateObjectName(); | - |
| 83 | connect(m_widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName); executed (the execution status of this line is deduced): connect(m_widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName); | - |
| 84 | } executed: }Execution Count:3470 | 3470 |
| 85 | | - |
| 86 | #ifndef QT_NO_ACCESSIBILITY | - |
| 87 | QAccessibleInterface *QWidgetWindow::accessibleRoot() const | - |
| 88 | { | - |
| 89 | if (m_widget) | - |
| 90 | return QAccessible::queryAccessibleInterface(m_widget); | - |
| 91 | return 0; | - |
| 92 | } | - |
| 93 | #endif | - |
| 94 | | - |
| 95 | QObject *QWidgetWindow::focusObject() const | - |
| 96 | { | - |
| 97 | QWidget *widget = m_widget->focusWidget(); | - |
| 98 | | - |
| 99 | if (!widget) | - |
| 100 | widget = m_widget; | - |
| 101 | | - |
| 102 | return widget; | - |
| 103 | } | - |
| 104 | | - |
| 105 | bool QWidgetWindow::event(QEvent *event) | - |
| 106 | { | - |
| 107 | if (m_widget->testAttribute(Qt::WA_DontShowOnScreen)) { | - |
| 108 | // \a event is uninteresting for QWidgetWindow, the event was probably | - |
| 109 | // generated before WA_DontShowOnScreen was set | - |
| 110 | return m_widget->event(event); | - |
| 111 | } | - |
| 112 | | - |
| 113 | switch (event->type()) { | - |
| 114 | case QEvent::Close: | - |
| 115 | handleCloseEvent(static_cast<QCloseEvent *>(event)); | - |
| 116 | return true; | - |
| 117 | | - |
| 118 | case QEvent::Enter: | - |
| 119 | case QEvent::Leave: | - |
| 120 | handleEnterLeaveEvent(event); | - |
| 121 | return true; | - |
| 122 | | - |
| 123 | // these should not be sent to QWidget, the corresponding events | - |
| 124 | // are sent by QApplicationPrivate::notifyActiveWindowChange() | - |
| 125 | case QEvent::FocusIn: | - |
| 126 | case QEvent::FocusOut: { | - |
| 127 | #ifndef QT_NO_ACCESSIBILITY | - |
| 128 | QAccessible::State state; | - |
| 129 | state.active = true; | - |
| 130 | QAccessibleStateChangeEvent ev(widget(), state); | - |
| 131 | QAccessible::updateAccessibility(&ev); | - |
| 132 | #endif | - |
| 133 | return false; } | - |
| 134 | | - |
| 135 | case QEvent::FocusAboutToChange: | - |
| 136 | if (QApplicationPrivate::focus_widget) { | - |
| 137 | if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled)) | - |
| 138 | qApp->inputMethod()->commit(); | - |
| 139 | | - |
| 140 | QGuiApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, event); | - |
| 141 | } | - |
| 142 | return true; | - |
| 143 | | - |
| 144 | case QEvent::KeyPress: | - |
| 145 | case QEvent::KeyRelease: | - |
| 146 | case QEvent::ShortcutOverride: | - |
| 147 | handleKeyEvent(static_cast<QKeyEvent *>(event)); | - |
| 148 | return true; | - |
| 149 | | - |
| 150 | case QEvent::MouseMove: | - |
| 151 | case QEvent::MouseButtonPress: | - |
| 152 | case QEvent::MouseButtonRelease: | - |
| 153 | case QEvent::MouseButtonDblClick: | - |
| 154 | handleMouseEvent(static_cast<QMouseEvent *>(event)); | - |
| 155 | return true; | - |
| 156 | | - |
| 157 | case QEvent::NonClientAreaMouseMove: | - |
| 158 | case QEvent::NonClientAreaMouseButtonPress: | - |
| 159 | case QEvent::NonClientAreaMouseButtonRelease: | - |
| 160 | case QEvent::NonClientAreaMouseButtonDblClick: | - |
| 161 | handleNonClientAreaMouseEvent(static_cast<QMouseEvent *>(event)); | - |
| 162 | return true; | - |
| 163 | | - |
| 164 | case QEvent::TouchBegin: | - |
| 165 | case QEvent::TouchUpdate: | - |
| 166 | case QEvent::TouchEnd: | - |
| 167 | case QEvent::TouchCancel: | - |
| 168 | handleTouchEvent(static_cast<QTouchEvent *>(event)); | - |
| 169 | return true; | - |
| 170 | | - |
| 171 | case QEvent::Move: | - |
| 172 | handleMoveEvent(static_cast<QMoveEvent *>(event)); | - |
| 173 | return true; | - |
| 174 | | - |
| 175 | case QEvent::Resize: | - |
| 176 | handleResizeEvent(static_cast<QResizeEvent *>(event)); | - |
| 177 | return true; | - |
| 178 | | - |
| 179 | #ifndef QT_NO_WHEELEVENT | - |
| 180 | case QEvent::Wheel: | - |
| 181 | handleWheelEvent(static_cast<QWheelEvent *>(event)); | - |
| 182 | return true; | - |
| 183 | #endif | - |
| 184 | | - |
| 185 | #ifndef QT_NO_DRAGANDDROP | - |
| 186 | case QEvent::DragEnter: | - |
| 187 | case QEvent::DragMove: | - |
| 188 | handleDragEnterMoveEvent(static_cast<QDragMoveEvent *>(event)); | - |
| 189 | return true; | - |
| 190 | case QEvent::DragLeave: | - |
| 191 | handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event)); | - |
| 192 | return true; | - |
| 193 | case QEvent::Drop: | - |
| 194 | handleDropEvent(static_cast<QDropEvent *>(event)); | - |
| 195 | return true; | - |
| 196 | #endif | - |
| 197 | | - |
| 198 | case QEvent::Expose: | - |
| 199 | handleExposeEvent(static_cast<QExposeEvent *>(event)); | - |
| 200 | return true; | - |
| 201 | | - |
| 202 | case QEvent::WindowStateChange: | - |
| 203 | handleWindowStateChangedEvent(static_cast<QWindowStateChangeEvent *>(event)); | - |
| 204 | return true; | - |
| 205 | | - |
| 206 | case QEvent::ThemeChange: { | - |
| 207 | QEvent widgetEvent(QEvent::ThemeChange); | - |
| 208 | QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent); | - |
| 209 | } | - |
| 210 | return true; | - |
| 211 | | - |
| 212 | #ifndef QT_NO_TABLETEVENT | - |
| 213 | case QEvent::TabletPress: | - |
| 214 | case QEvent::TabletMove: | - |
| 215 | case QEvent::TabletRelease: | - |
| 216 | handleTabletEvent(static_cast<QTabletEvent *>(event)); | - |
| 217 | return true; | - |
| 218 | #endif | - |
| 219 | #ifndef QT_NO_CONTEXTMENU | - |
| 220 | case QEvent::ContextMenu: | - |
| 221 | handleContextMenuEvent(static_cast<QContextMenuEvent *>(event)); | - |
| 222 | return true; | - |
| 223 | #endif | - |
| 224 | | - |
| 225 | // Handing show events to widgets (see below) here would cause them to be triggered twice | - |
| 226 | case QEvent::Show: | - |
| 227 | case QEvent::Hide: | - |
| 228 | return QWindow::event(event); | - |
| 229 | | - |
| 230 | default: | - |
| 231 | break; | - |
| 232 | } | - |
| 233 | | - |
| 234 | return m_widget->event(event) || QWindow::event(event); | - |
| 235 | } | - |
| 236 | | - |
| 237 | QPointer<QWidget> qt_last_mouse_receiver = 0; | - |
| 238 | | - |
| 239 | void QWidgetWindow::handleEnterLeaveEvent(QEvent *event) | - |
| 240 | { | - |
| 241 | if (event->type() == QEvent::Leave) { | - |
| 242 | QWidget *enter = 0; | - |
| 243 | // Check from window system event queue if the next queued enter targets a window | - |
| 244 | // in the same window hierarchy (e.g. enter a child of this window). If so, | - |
| 245 | // remove the enter event from queue and handle both in single dispatch. | - |
| 246 | QWindowSystemInterfacePrivate::EnterEvent *systemEvent = | - |
| 247 | static_cast<QWindowSystemInterfacePrivate::EnterEvent *> | - |
| 248 | (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter)); | - |
| 249 | const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition; | - |
| 250 | if (systemEvent) { | - |
| 251 | if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter)) | - |
| 252 | { | - |
| 253 | QWindow *thisParent = this; | - |
| 254 | QWindow *enterParent = enterWindow; | - |
| 255 | while (thisParent->parent()) | - |
| 256 | thisParent = thisParent->parent(); | - |
| 257 | while (enterParent->parent()) | - |
| 258 | enterParent = enterParent->parent(); | - |
| 259 | if (thisParent == enterParent) { | - |
| 260 | QGuiApplicationPrivate::currentMouseWindow = enterWindow; | - |
| 261 | enter = enterWindow->widget(); | - |
| 262 | QWindowSystemInterfacePrivate::removeWindowSystemEvent(systemEvent); | - |
| 263 | } | - |
| 264 | } | - |
| 265 | } | - |
| 266 | // Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes | - |
| 267 | // both native and non-native widgets work similarly. | - |
| 268 | // When mousegrabbing, leaves are only generated if leaving the parent window. | - |
| 269 | if (!enter || !QWidget::mouseGrabber()) { | - |
| 270 | // Preferred leave target is the last mouse receiver, unless it has native window, | - |
| 271 | // in which case it is assumed to receive it's own leave event when relevant. | - |
| 272 | QWidget *leave = m_widget; | - |
| 273 | if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId()) | - |
| 274 | leave = qt_last_mouse_receiver.data(); | - |
| 275 | QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF); | - |
| 276 | qt_last_mouse_receiver = enter; | - |
| 277 | } | - |
| 278 | } else { | - |
| 279 | const QEnterEvent *ee = static_cast<QEnterEvent *>(event); | - |
| 280 | QWidget *child = m_widget->childAt(ee->pos()); | - |
| 281 | QWidget *receiver = child ? child : m_widget; | - |
| 282 | QApplicationPrivate::dispatchEnterLeave(receiver, 0, ee->screenPos()); | - |
| 283 | qt_last_mouse_receiver = receiver; | - |
| 284 | } | - |
| 285 | } | - |
| 286 | | - |
| 287 | void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e) | - |
| 288 | { | - |
| 289 | QApplication::sendSpontaneousEvent(m_widget, e); | - |
| 290 | } | - |
| 291 | | - |
| 292 | void QWidgetWindow::handleMouseEvent(QMouseEvent *event) | - |
| 293 | { | - |
| 294 | if (qApp->d_func()->inPopupMode()) { | - |
| 295 | QWidget *activePopupWidget = qApp->activePopupWidget(); | - |
| 296 | QWidget *popup = activePopupWidget; | - |
| 297 | QPoint mapped = event->pos(); | - |
| 298 | if (popup != m_widget) | - |
| 299 | mapped = popup->mapFromGlobal(event->globalPos()); | - |
| 300 | bool releaseAfter = false; | - |
| 301 | QWidget *popupChild = popup->childAt(mapped); | - |
| 302 | | - |
| 303 | if (popup != qt_popup_down) { | - |
| 304 | qt_button_down = 0; | - |
| 305 | qt_popup_down = 0; | - |
| 306 | } | - |
| 307 | | - |
| 308 | switch (event->type()) { | - |
| 309 | case QEvent::MouseButtonPress: | - |
| 310 | case QEvent::MouseButtonDblClick: | - |
| 311 | qt_button_down = popupChild; | - |
| 312 | qt_popup_down = popup; | - |
| 313 | break; | - |
| 314 | case QEvent::MouseButtonRelease: | - |
| 315 | releaseAfter = true; | - |
| 316 | break; | - |
| 317 | default: | - |
| 318 | break; // nothing for mouse move | - |
| 319 | } | - |
| 320 | | - |
| 321 | int oldOpenPopupCount = openPopupCount; | - |
| 322 | | - |
| 323 | if (popup->isEnabled()) { | - |
| 324 | // deliver event | - |
| 325 | qt_replay_popup_mouse_event = false; | - |
| 326 | QWidget *receiver = popup; | - |
| 327 | QPoint widgetPos = mapped; | - |
| 328 | if (qt_button_down) | - |
| 329 | receiver = qt_button_down; | - |
| 330 | else if (popupChild) | - |
| 331 | receiver = popupChild; | - |
| 332 | if (receiver != popup) | - |
| 333 | widgetPos = receiver->mapFromGlobal(event->globalPos()); | - |
| 334 | QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos())); | - |
| 335 | QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); | - |
| 336 | e.setTimestamp(event->timestamp()); | - |
| 337 | QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver); | - |
| 338 | } else { | - |
| 339 | // close disabled popups when a mouse button is pressed or released | - |
| 340 | switch (event->type()) { | - |
| 341 | case QEvent::MouseButtonPress: | - |
| 342 | case QEvent::MouseButtonDblClick: | - |
| 343 | case QEvent::MouseButtonRelease: | - |
| 344 | popup->close(); | - |
| 345 | break; | - |
| 346 | default: | - |
| 347 | break; | - |
| 348 | } | - |
| 349 | } | - |
| 350 | | - |
| 351 | if (qApp->activePopupWidget() != activePopupWidget | - |
| 352 | && qt_replay_popup_mouse_event) { | - |
| 353 | if (m_widget->windowType() != Qt::Popup) | - |
| 354 | qt_button_down = 0; | - |
| 355 | qt_replay_popup_mouse_event = false; | - |
| 356 | #ifndef QT_NO_CONTEXTMENU | - |
| 357 | } else if (event->type() == QEvent::MouseButtonPress | - |
| 358 | && event->button() == Qt::RightButton | - |
| 359 | && (openPopupCount == oldOpenPopupCount)) { | - |
| 360 | QWidget *popupEvent = popup; | - |
| 361 | if (qt_button_down) | - |
| 362 | popupEvent = qt_button_down; | - |
| 363 | else if(popupChild) | - |
| 364 | popupEvent = popupChild; | - |
| 365 | QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); | - |
| 366 | QApplication::sendSpontaneousEvent(popupEvent, &e); | - |
| 367 | #endif | - |
| 368 | } | - |
| 369 | | - |
| 370 | if (releaseAfter) { | - |
| 371 | qt_button_down = 0; | - |
| 372 | qt_popup_down = 0; | - |
| 373 | } | - |
| 374 | return; | - |
| 375 | } | - |
| 376 | | - |
| 377 | // modal event handling | - |
| 378 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) | - |
| 379 | return; | - |
| 380 | | - |
| 381 | // which child should have it? | - |
| 382 | QWidget *widget = m_widget->childAt(event->pos()); | - |
| 383 | QPoint mapped = event->pos(); | - |
| 384 | | - |
| 385 | if (!widget) | - |
| 386 | widget = m_widget; | - |
| 387 | | - |
| 388 | if (event->type() == QEvent::MouseButtonPress && !qt_button_down) | - |
| 389 | qt_button_down = widget; | - |
| 390 | | - |
| 391 | QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(), | - |
| 392 | qt_button_down, widget); | - |
| 393 | | - |
| 394 | if (!receiver) { | - |
| 395 | if (event->type() == QEvent::MouseButtonRelease) | - |
| 396 | QApplicationPrivate::mouse_buttons &= ~event->button(); | - |
| 397 | return; | - |
| 398 | } | - |
| 399 | | - |
| 400 | QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); | - |
| 401 | translated.setTimestamp(event->timestamp()); | - |
| 402 | QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down, | - |
| 403 | qt_last_mouse_receiver); | - |
| 404 | | - |
| 405 | #ifndef QT_NO_CONTEXTMENU | - |
| 406 | if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::RightButton) { | - |
| 407 | QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); | - |
| 408 | QGuiApplication::sendSpontaneousEvent(receiver, &e); | - |
| 409 | } | - |
| 410 | #endif | - |
| 411 | } | - |
| 412 | | - |
| 413 | void QWidgetWindow::handleTouchEvent(QTouchEvent *event) | - |
| 414 | { | - |
| 415 | if (event->type() == QEvent::TouchCancel) | - |
| 416 | QApplicationPrivate::translateTouchCancel(event->device(), event->timestamp()); | - |
| 417 | else | - |
| 418 | QApplicationPrivate::translateRawTouchEvent(m_widget, event->device(), event->touchPoints(), event->timestamp()); | - |
| 419 | } | - |
| 420 | | - |
| 421 | void QWidgetWindow::handleKeyEvent(QKeyEvent *event) | - |
| 422 | { | - |
| 423 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) | - |
| 424 | return; | - |
| 425 | | - |
| 426 | QObject *receiver = 0; | - |
| 427 | if (QApplicationPrivate::inPopupMode()) { | - |
| 428 | QWidget *popup = QApplication::activePopupWidget(); | - |
| 429 | QWidget *popupFocusWidget = popup->focusWidget(); | - |
| 430 | receiver = popupFocusWidget ? popupFocusWidget : popup; | - |
| 431 | } | - |
| 432 | if (!receiver) | - |
| 433 | receiver = QWidget::keyboardGrabber(); | - |
| 434 | if (!receiver) | - |
| 435 | receiver = focusObject(); | - |
| 436 | QGuiApplication::sendSpontaneousEvent(receiver, event); | - |
| 437 | } | - |
| 438 | | - |
| 439 | void QWidgetWindow::updateGeometry() | - |
| 440 | { | - |
| 441 | if (m_widget->testAttribute(Qt::WA_OutsideWSRange)) | - |
| 442 | return; | - |
| 443 | | - |
| 444 | const QMargins margins = frameMargins(); | - |
| 445 | | - |
| 446 | m_widget->data->crect = geometry(); | - |
| 447 | QTLWExtra *te = m_widget->d_func()->topData(); | - |
| 448 | te->posIncludesFrame= false; | - |
| 449 | te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom()); | - |
| 450 | m_widget->data->fstrut_dirty = false; | - |
| 451 | } | - |
| 452 | | - |
| 453 | void QWidgetWindow::handleMoveEvent(QMoveEvent *event) | - |
| 454 | { | - |
| 455 | updateGeometry(); | - |
| 456 | QGuiApplication::sendSpontaneousEvent(m_widget, event); | - |
| 457 | } | - |
| 458 | | - |
| 459 | void QWidgetWindow::handleResizeEvent(QResizeEvent *event) | - |
| 460 | { | - |
| 461 | QSize oldSize = m_widget->data->crect.size(); | - |
| 462 | | - |
| 463 | updateGeometry(); | - |
| 464 | QGuiApplication::sendSpontaneousEvent(m_widget, event); | - |
| 465 | | - |
| 466 | if (m_widget->d_func()->paintOnScreen()) { | - |
| 467 | QRegion updateRegion(geometry()); | - |
| 468 | if (m_widget->testAttribute(Qt::WA_StaticContents)) | - |
| 469 | updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height()); | - |
| 470 | m_widget->d_func()->syncBackingStore(updateRegion); | - |
| 471 | } else { | - |
| 472 | m_widget->d_func()->syncBackingStore(); | - |
| 473 | } | - |
| 474 | } | - |
| 475 | | - |
| 476 | void QWidgetWindow::handleCloseEvent(QCloseEvent *) | - |
| 477 | { | - |
| 478 | m_widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); | - |
| 479 | } | - |
| 480 | | - |
| 481 | #ifndef QT_NO_WHEELEVENT | - |
| 482 | | - |
| 483 | void QWidgetWindow::handleWheelEvent(QWheelEvent *event) | - |
| 484 | { | - |
| 485 | if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type())) | - |
| 486 | return; | - |
| 487 | | - |
| 488 | // which child should have it? | - |
| 489 | QWidget *widget = m_widget->childAt(event->pos()); | - |
| 490 | | - |
| 491 | if (!widget) | - |
| 492 | widget = m_widget; | - |
| 493 | | - |
| 494 | QPoint mapped = widget->mapFrom(m_widget, event->pos()); | - |
| 495 | | - |
| 496 | QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers()); | - |
| 497 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - |
| 498 | } | - |
| 499 | | - |
| 500 | #endif // QT_NO_WHEELEVENT | - |
| 501 | | - |
| 502 | #ifndef QT_NO_DRAGANDDROP | - |
| 503 | | - |
| 504 | void QWidgetWindow::handleDragEnterMoveEvent(QDragMoveEvent *event) | - |
| 505 | { | - |
| 506 | Q_ASSERT(event->type() ==QEvent::DragMove || !m_dragTarget); | - |
| 507 | // Find a target widget under mouse that accepts drops (QTBUG-22987). | - |
| 508 | QWidget *widget = m_widget->childAt(event->pos()); | - |
| 509 | if (!widget) | - |
| 510 | widget = m_widget; | - |
| 511 | for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ; | - |
| 512 | if (widget && !widget->acceptDrops()) | - |
| 513 | widget = 0; | - |
| 514 | // Target widget unchanged: DragMove | - |
| 515 | if (widget && widget == m_dragTarget.data()) { | - |
| 516 | Q_ASSERT(event->type() == QEvent::DragMove); | - |
| 517 | const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - |
| 518 | QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - |
| 519 | translated.setDropAction(event->dropAction()); | - |
| 520 | if (event->isAccepted()) { // Handling 'DragEnter' should suffice for the application. | - |
| 521 | translated.accept(); | - |
| 522 | translated.setDropAction(event->dropAction()); | - |
| 523 | } | - |
| 524 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - |
| 525 | if (translated.isAccepted()) { | - |
| 526 | event->accept(); | - |
| 527 | } else { | - |
| 528 | event->ignore(); | - |
| 529 | } | - |
| 530 | event->setDropAction(translated.dropAction()); | - |
| 531 | return; | - |
| 532 | } | - |
| 533 | // Target widget changed: Send DragLeave to previous, DragEnter to new if there is any | - |
| 534 | if (m_dragTarget.data()) { | - |
| 535 | QDragLeaveEvent le; | - |
| 536 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &le); | - |
| 537 | m_dragTarget = 0; | - |
| 538 | } | - |
| 539 | if (!widget) { | - |
| 540 | event->ignore(); | - |
| 541 | return; | - |
| 542 | } | - |
| 543 | m_dragTarget = widget; | - |
| 544 | const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - |
| 545 | QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - |
| 546 | QGuiApplication::sendSpontaneousEvent(widget, &translated); | - |
| 547 | if (translated.isAccepted()) { | - |
| 548 | event->accept(); | - |
| 549 | } else { | - |
| 550 | event->ignore(); | - |
| 551 | } | - |
| 552 | event->setDropAction(translated.dropAction()); | - |
| 553 | } | - |
| 554 | | - |
| 555 | void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *event) | - |
| 556 | { | - |
| 557 | if (m_dragTarget) | - |
| 558 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), event); | - |
| 559 | m_dragTarget = 0; | - |
| 560 | } | - |
| 561 | | - |
| 562 | void QWidgetWindow::handleDropEvent(QDropEvent *event) | - |
| 563 | { | - |
| 564 | const QPoint mapped = m_dragTarget.data()->mapFromGlobal(m_widget->mapToGlobal(event->pos())); | - |
| 565 | QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); | - |
| 566 | QGuiApplication::sendSpontaneousEvent(m_dragTarget.data(), &translated); | - |
| 567 | if (translated.isAccepted()) | - |
| 568 | event->accept(); | - |
| 569 | event->setDropAction(translated.dropAction()); | - |
| 570 | m_dragTarget = 0; | - |
| 571 | } | - |
| 572 | | - |
| 573 | #endif // QT_NO_DRAGANDDROP | - |
| 574 | | - |
| 575 | void QWidgetWindow::handleExposeEvent(QExposeEvent *event) | - |
| 576 | { | - |
| 577 | if (isExposed()) { | - |
| 578 | m_widget->setAttribute(Qt::WA_Mapped); | - |
| 579 | if (!event->region().isNull()) { | - |
| 580 | // Exposed native widgets need to be marked dirty to get them repainted correctly. | - |
| 581 | if (m_widget->internalWinId() && !m_widget->isWindow() && m_widget->isVisible() && m_widget->updatesEnabled()) { | - |
| 582 | if (QWidgetBackingStore *bs = m_widget->d_func()->maybeBackingStore()) | - |
| 583 | bs->markDirty(event->region(), m_widget); | - |
| 584 | } | - |
| 585 | m_widget->d_func()->syncBackingStore(event->region()); | - |
| 586 | } | - |
| 587 | } else { | - |
| 588 | m_widget->setAttribute(Qt::WA_Mapped, false); | - |
| 589 | } | - |
| 590 | } | - |
| 591 | | - |
| 592 | Qt::WindowState effectiveState(Qt::WindowStates state); | - |
| 593 | | - |
| 594 | void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event) | - |
| 595 | { | - |
| 596 | // QWindow does currently not know 'active'. | - |
| 597 | Qt::WindowStates eventState = event->oldState(); | - |
| 598 | Qt::WindowStates widgetState = m_widget->windowState(); | - |
| 599 | if (widgetState & Qt::WindowActive) | - |
| 600 | eventState |= Qt::WindowActive; | - |
| 601 | | - |
| 602 | // Determine the new widget state, remember maximized/full screen | - |
| 603 | // during minimized. | - |
| 604 | switch (windowState()) { | - |
| 605 | case Qt::WindowNoState: | - |
| 606 | widgetState &= ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen); | - |
| 607 | break; | - |
| 608 | case Qt::WindowMinimized: | - |
| 609 | widgetState |= Qt::WindowMinimized; | - |
| 610 | break; | - |
| 611 | case Qt::WindowMaximized: | - |
| 612 | if (effectiveState(widgetState) == Qt::WindowNoState) | - |
| 613 | if (QTLWExtra *tle = m_widget->d_func()->maybeTopData()) | - |
| 614 | tle->normalGeometry = m_widget->geometry(); | - |
| 615 | widgetState |= Qt::WindowMaximized; | - |
| 616 | widgetState &= ~(Qt::WindowMinimized | Qt::WindowFullScreen); | - |
| 617 | break; | - |
| 618 | case Qt::WindowFullScreen: | - |
| 619 | if (effectiveState(widgetState) == Qt::WindowNoState) | - |
| 620 | if (QTLWExtra *tle = m_widget->d_func()->maybeTopData()) | - |
| 621 | tle->normalGeometry = m_widget->geometry(); | - |
| 622 | widgetState |= Qt::WindowFullScreen; | - |
| 623 | widgetState &= ~(Qt::WindowMinimized); | - |
| 624 | break; | - |
| 625 | case Qt::WindowActive: // Not handled by QWindow | - |
| 626 | break; | - |
| 627 | } | - |
| 628 | | - |
| 629 | // Sent event if the state changed (that is, it is not triggered by | - |
| 630 | // QWidget::setWindowState(), which also sends an event to the widget). | - |
| 631 | if (widgetState != int(m_widget->data->window_state)) { | - |
| 632 | m_widget->data->window_state = widgetState; | - |
| 633 | QWindowStateChangeEvent widgetEvent(eventState); | - |
| 634 | QGuiApplication::sendSpontaneousEvent(m_widget, &widgetEvent); | - |
| 635 | } | - |
| 636 | } | - |
| 637 | | - |
| 638 | bool QWidgetWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) | - |
| 639 | { | - |
| 640 | return m_widget->nativeEvent(eventType, message, result); | - |
| 641 | } | - |
| 642 | | - |
| 643 | #ifndef QT_NO_TABLETEVENT | - |
| 644 | void QWidgetWindow::handleTabletEvent(QTabletEvent *event) | - |
| 645 | { | - |
| 646 | if (event->type() == QEvent::TabletPress) { | - |
| 647 | QWidget *widget = m_widget->childAt(event->pos()); | - |
| 648 | if (!widget) | - |
| 649 | widget = m_widget; | - |
| 650 | | - |
| 651 | qt_tablet_target = widget; | - |
| 652 | } | - |
| 653 | | - |
| 654 | if (qt_tablet_target) { | - |
| 655 | QPointF delta = event->globalPosF() - event->globalPos(); | - |
| 656 | QPointF mapped = qt_tablet_target->mapFromGlobal(event->globalPos()) + delta; | - |
| 657 | QTabletEvent ev(event->type(), mapped, event->globalPosF(), event->device(), event->pointerType(), | - |
| 658 | event->pressure(), event->xTilt(), event->yTilt(), event->tangentialPressure(), | - |
| 659 | event->rotation(), event->z(), event->modifiers(), event->uniqueId()); | - |
| 660 | ev.setTimestamp(event->timestamp()); | - |
| 661 | QGuiApplication::sendSpontaneousEvent(qt_tablet_target, &ev); | - |
| 662 | } | - |
| 663 | | - |
| 664 | if (event->type() == QEvent::TabletRelease) | - |
| 665 | qt_tablet_target = 0; | - |
| 666 | } | - |
| 667 | #endif // QT_NO_TABLETEVENT | - |
| 668 | | - |
| 669 | #ifndef QT_NO_CONTEXTMENU | - |
| 670 | void QWidgetWindow::handleContextMenuEvent(QContextMenuEvent *e) | - |
| 671 | { | - |
| 672 | // We are only interested in keyboard originating context menu events here, | - |
| 673 | // mouse originated context menu events for widgets are generated in mouse handling methods. | - |
| 674 | if (e->reason() != QContextMenuEvent::Keyboard) | - |
| 675 | return; | - |
| 676 | | - |
| 677 | QWidget *fw = QWidget::keyboardGrabber(); | - |
| 678 | if (!fw) { | - |
| 679 | if (QApplication::activePopupWidget()) { | - |
| 680 | fw = (QApplication::activePopupWidget()->focusWidget() | - |
| 681 | ? QApplication::activePopupWidget()->focusWidget() | - |
| 682 | : QApplication::activePopupWidget()); | - |
| 683 | } else if (QApplication::focusWidget()) { | - |
| 684 | fw = QApplication::focusWidget(); | - |
| 685 | } else { | - |
| 686 | fw = m_widget; | - |
| 687 | } | - |
| 688 | } | - |
| 689 | if (fw && fw->isEnabled()) { | - |
| 690 | QPoint pos = fw->inputMethodQuery(Qt::ImMicroFocus).toRect().center(); | - |
| 691 | QContextMenuEvent widgetEvent(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos), | - |
| 692 | e->modifiers()); | - |
| 693 | QGuiApplication::sendSpontaneousEvent(fw, &widgetEvent); | - |
| 694 | } | - |
| 695 | } | - |
| 696 | #endif // QT_NO_CONTEXTMENU | - |
| 697 | | - |
| 698 | void QWidgetWindow::updateObjectName() | - |
| 699 | { | - |
| 700 | QString name = m_widget->objectName(); | - |
| 701 | if (name.isEmpty()) | - |
| 702 | name = QString::fromUtf8(m_widget->metaObject()->className()) + QStringLiteral("Class"); | - |
| 703 | name += QStringLiteral("Window"); | - |
| 704 | setObjectName(name); | - |
| 705 | } | - |
| 706 | | - |
| 707 | QT_END_NAMESPACE | - |
| 708 | | - |
| | |