4#include "private/qwindow_p.h"
8#include "private/qwidget_p.h"
9#include "private/qapplication_p.h"
10#if QT_CONFIG(accessibility)
11#include <QtGui/qaccessible.h>
13#include <private/qwidgetrepaintmanager_p.h>
14#include <qpa/qwindowsysteminterface_p.h>
15#include <qpa/qplatformtheme.h>
16#include <qpa/qplatformwindow.h>
17#include <private/qgesturemanager_p.h>
18#include <private/qhighdpiscaling_p.h>
50 if (wasExplicitShowHide) {
62 while (
w->parent() && qobject_cast<QWidgetWindow *>(
w) && qobject_cast<QWidgetWindow *>(
w->parent())) {
95 const QSize oldSize =
rect.size().toSize();
97 if (newSize == oldSize)
99 const int dw = newSize.
width() - oldSize.
width();
105 if (
qAbs(topOffset) >
qAbs(bottomOffset))
128 setSurfaceType(
type);
139#if QT_CONFIG(accessibility)
143 return QAccessible::queryAccessibleInterface(m_widget);
150 QWidget *windowWidget = m_widget;
176 d->QWindowPrivate::setVisible(
visible);
181 switch (
event->type()) {
202 switch (
event->type()) {
214#if QT_CONFIG(accessibility)
217 QAccessibleStateChangeEvent ev(m_widget,
state);
218 QAccessible::updateAccessibility(&ev);
266#if QT_CONFIG(wheelevent)
268 handleWheelEvent(
static_cast<QWheelEvent *
>(
event));
272#if QT_CONFIG(draganddrop)
274 handleDragEnterEvent(
static_cast<QDragEnterEvent *
>(
event));
277 handleDragMoveEvent(
static_cast<QDragMoveEvent *
>(
event));
280 handleDragLeaveEvent(
static_cast<QDragLeaveEvent *
>(
event));
283 handleDropEvent(
static_cast<QDropEvent *
>(
event));
298 QCoreApplication::forwardEvent(m_widget, &widgetEvent,
event);
302#if QT_CONFIG(tabletevent)
306 handleTabletEvent(
static_cast<QTabletEvent *
>(
event));
310#ifndef QT_NO_GESTURES
316#ifndef QT_NO_CONTEXTMENU
333 handleDevicePixelRatioChange();
370 QWindow *enterParent = enterWindow;
371 while (thisParent->parent())
372 thisParent = thisParent->parent();
373 while (enterParent->parent())
374 enterParent = enterParent->parent();
375 if (thisParent == enterParent) {
377 enter = enterWindow->widget();
410QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
421 if (((
w->focusPolicy() & focus_flag) == focus_flag)
422 &&
w->isVisibleTo(m_widget) &&
w->isEnabled())
425 if (fw == FirstFocusWidget)
428 w =
w->nextInFocusChain();
436 QWidget *focusWidget =
nullptr;
438 focusWidget = getFocusWidget(LastFocusWidget);
440 focusWidget = getFocusWidget(FirstFocusWidget);
442 if (focusWidget !=
nullptr)
448 QApplication::forwardEvent(m_widget,
e);
458 QPoint mapped =
event->position().toPoint();
459 if (activePopupWidget != m_widget)
460 mapped = activePopupWidget->mapFromGlobal(
event->globalPosition().toPoint());
461 bool releaseAfter =
false;
462 QWidget *popupChild = activePopupWidget->childAt(mapped);
469 switch (
event->type()) {
485 if (activePopupWidget->isEnabled()) {
489 QPoint widgetPos = mapped;
493 receiver = popupChild;
494 if (receiver != activePopupWidget)
495 widgetPos = receiver->mapFromGlobal(
event->globalPosition().toPoint());
497 const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped);
498 const bool underMouse = activePopupWidget->underMouse();
499 if (underMouse != reallyUnderMouse) {
500 if (reallyUnderMouse) {
501 const QPoint receiverMapped = receiver->mapFromGlobal(
event->globalPosition().toPoint());
504 if (receiverMapped.
x() >= 0 && receiverMapped.
y() >= 0) {
511 receiver = activePopupWidget;
522 e.setTimestamp(
event->timestamp());
528 switch (
event->type()) {
532 activePopupWidget->close();
549 if (!
w->isActiveWindow()) {
551 w->window()->raise();
555 const QRect globalGeometry =
win->isTopLevel()
558 if (globalGeometry.
contains(
event->globalPosition().toPoint())) {
564 e->setTimestamp(
event->timestamp());
571#ifndef QT_NO_CONTEXTMENU
572 }
else if (
event->type() == contextMenuTrigger
575 QWidget *receiver = activePopupWidget;
579 receiver = popupChild;
582 QApplication::forwardEvent(receiver, &
e,
event);
605 QPoint mapped =
event->position().toPoint();
610 const bool initialPress =
event->buttons() ==
event->button();
626 translated.setTimestamp(
event->timestamp());
629 event->setAccepted(translated.isAccepted());
631#ifndef QT_NO_CONTEXTMENU
633 && m_widget->rect().contains(
event->position().toPoint())) {
635 QGuiApplication::forwardEvent(receiver, &
e,
event);
665 receiver = popupFocusWidget ? popupFocusWidget : popup;
669 QGuiApplication::forwardEvent(receiver,
event);
672bool QWidgetWindow::updateSize()
674 bool changed =
false;
680 if (m_widget->data->crect.
size() != geometry().
size()) {
682 m_widget->data->crect.setSize(geometry().
size());
689void QWidgetWindow::updateMargins()
693 QTLWExtra *te = m_widget->d_func()->topData();
694 if (te->
window ==
nullptr || te->
window->handle() ==
nullptr)
696 const QMargins margins = frameMargins();
699 m_widget->data->fstrut_dirty =
false;
707 for (
int i = 0;
i <
d->children.size(); ++
i) {
714void QWidgetWindow::handleScreenChange()
724void QWidgetWindow::handleDevicePixelRatioChange()
734void QWidgetWindow::repaintWindow()
746void QWidgetWindow::updateNormalGeometry()
748 QTLWExtra *tle = m_widget->d_func()->maybeTopData();
752 QRect normalGeometry;
756 normalGeometry = m_widget->
geometry();
768 auto oldPosition = m_widget->data->crect.topLeft();
769 auto newPosition = geometry().topLeft();
779 m_widget->data->crect.moveTopLeft(newPosition);
785 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
791 auto oldRect = m_widget->
rect();
794 QGuiApplication::forwardEvent(m_widget,
event);
796 if (m_widget->d_func()->shouldPaintOnScreen()) {
799 dirtyRegion -= oldRect;
800 m_widget->d_func()->syncBackingStore(dirtyRegion);
802 m_widget->d_func()->syncBackingStore();
812 event->setAccepted(accepted);
838 return q->widget()->isVisible();
841#if QT_CONFIG(wheelevent)
843void QWidgetWindow::handleWheelEvent(QWheelEvent *
event)
848 QWidget *rootWidget = m_widget;
854 if (activePopupWidget && activePopupWidget != m_widget) {
855 rootWidget = activePopupWidget;
867 QWheelEvent translated(mapped,
event->globalPosition(),
event->pixelDelta(),
event->angleDelta(),
870 translated.setTimestamp(
event->timestamp());
871 QGuiApplication::forwardEvent(
widget, &translated,
event);
876#if QT_CONFIG(draganddrop)
894 widget = findDnDTarget(m_widget,
event->position().toPoint());
902 QDragEnterEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
904 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
905 event->setAccepted(translated.isAccepted());
906 event->setDropAction(translated.dropAction());
909void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *
event)
915 QDragLeaveEvent leaveEvent;
916 QWidget *dragTarget = m_dragTarget;
917 m_dragTarget =
nullptr;
918 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
922 QDragMoveEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
925 if (
widget == m_dragTarget) {
926 translated.setDropAction(
event->dropAction());
927 translated.setAccepted(
event->isAccepted());
928 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
931 QDragLeaveEvent leaveEvent;
932 QWidget *dragTarget = m_dragTarget;
933 m_dragTarget =
nullptr;
934 QGuiApplication::forwardEvent(dragTarget, &leaveEvent,
event);
939 handleDragEnterEvent(
static_cast<QDragEnterEvent*
>(
event),
widget);
941 translated.setDropAction(
event->dropAction());
942 translated.setAccepted(
event->isAccepted());
946 QGuiApplication::forwardEvent(m_dragTarget, &translated,
event);
949 event->setAccepted(translated.isAccepted());
950 event->setDropAction(translated.dropAction());
954void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *
event)
957 QWidget *dragTarget = m_dragTarget;
958 m_dragTarget =
nullptr;
959 QGuiApplication::forwardEvent(dragTarget,
event);
963void QWidgetWindow::handleDropEvent(QDropEvent *
event)
966 qWarning() << m_widget <<
": No drag target set.";
971 QDropEvent translated(mapped,
event->possibleActions(),
event->mimeData(),
event->buttons(),
event->modifiers());
972 QWidget *dragTarget = m_dragTarget;
973 m_dragTarget =
nullptr;
974 QGuiApplication::forwardEvent(dragTarget, &translated,
event);
975 event->setAccepted(translated.isAccepted());
976 event->setDropAction(translated.dropAction());
987 const bool exposed = isExposed();
1021 if (!
event->m_region.isNull())
1031 Qt::WindowStates eventState =
event->oldState();
1032 Qt::WindowStates widgetState = m_widget->
windowState();
1033 Qt::WindowStates windowState = windowStates();
1044 updateNormalGeometry();
1049 if (widgetState != Qt::WindowStates::Int(m_widget->data->window_state)) {
1050 m_widget->data->window_state =
uint(widgetState);
1052 QGuiApplication::forwardEvent(m_widget, &widgetEvent,
event);
1061#if QT_CONFIG(tabletevent)
1062void QWidgetWindow::handleTabletEvent(QTabletEvent *
event)
1073 qt_tablet_target =
widget;
1077 QPointF delta =
event->globalPosition() -
event->globalPosition().
toPoint();
1079 QTabletEvent ev(
event->type(),
event->pointingDevice(), mapped,
event->globalPosition(),
1082 ev.setTimestamp(
event->timestamp());
1083 ev.setAccepted(
false);
1084 QGuiApplication::forwardEvent(
widget, &ev,
event);
1085 event->setAccepted(ev.isAccepted());
1089 qt_tablet_target =
nullptr;
1093#ifndef QT_NO_GESTURES
1101 receiver = popupFocusWidget ? popupFocusWidget : popup;
1106 receiver = m_widget;
1108 QApplication::forwardEvent(receiver,
e);
1112#ifndef QT_NO_CONTEXTMENU
1136 QGuiApplication::forwardEvent(fw, &widgetEvent,
e);
1141void QWidgetWindow::updateObjectName()
1146 name +=
"Window"_L1;
1152#include "moc_qwidgetwindow_p.cpp"
static QWidget * pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos, QEvent::Type type, Qt::MouseButtons buttons, QWidget *buttonDown, QWidget *alienWidget)
static QApplicationPrivate * instance()
static QWidget * focus_widget
static bool inPopupMode()
static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF)
static bool isBlockedByModal(QWidget *widget)
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent)
static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, QWidget *native, QWidget **buttonDown, QPointer< QWidget > &lastMouseReceiver, bool spontaneous=true, bool onlyDispatchEnterLeave=false)
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp)
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QWidget * activePopupWidget()
Returns the active popup widget.
The QCloseEvent class contains parameters that describe a close event.
static void setEventSpontaneous(QEvent *e, bool spontaneous)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
Type
This enum type defines the valid event types in Qt.
@ NonClientAreaMouseButtonDblClick
@ NonClientAreaMouseButtonRelease
@ NonClientAreaMouseButtonPress
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
The QFocusEvent class contains event parameters for widget focus events.
static QPlatformIntegration * platformIntegration()
static QWindow * currentMouseWindow
static struct QGuiApplicationPrivate::QLastCursorPosition lastCursorPosition
static QPlatformTheme * platformTheme()
static QInputMethod * inputMethod()
returns the input method.
The QHideEvent class provides an event which is sent after a widget is hidden.
The QKeyEvent class describes a key event.
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
The QMoveEvent class contains event parameters for move events.
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QString objectName
the name of this object
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
void objectNameChanged(const QString &objectName, QPrivateSignal)
This signal is emitted after the object's name has been changed.
\inmodule QtCore\reentrant
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\inmodule QtCore\reentrant
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
\inmodule QtCore\reentrant
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr void setCoords(int x1, int y1, int x2, int y2) noexcept
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its botto...
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
The QRegion class specifies a clip region for a painter.
The QResizeEvent class contains event parameters for resize events.
The QShowEvent class provides an event that is sent when a widget is shown.
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SurfaceType
The SurfaceType enum describes what type of surface this is.
The QTouchEvent class contains parameters that describe a touch event.
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
QRect toRect() const
Returns the variant as a QRect if the variant has userType() \l QMetaType::QRect; otherwise returns a...
virtual void setVisible(bool visible)
virtual bool participatesInLastWindowClosed() const
QPointer< QWindow > enter
static void removeWindowSystemEvent(WindowSystemEvent *event)
static WindowSystemEvent * peekWindowSystemEvent(EventType t)
virtual QAccessibleInterface * accessibleRoot() const
Returns the accessibility interface for the object that the window represents.
bool visible
whether the window is visible or not
QSize size() const override
Returns the size of the window excluding any window frame.
virtual bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
virtual void hideEvent(QHideEvent *)
Override this to handle hide events (ev).
void screenChanged(QScreen *screen)
This signal is emitted when a window's screen changes, either by being set explicitly with setScreen(...
virtual void showEvent(QShowEvent *)
Override this to handle show events (ev).
T fromNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
@ WA_WState_ExplicitShowHide
bool qt_replay_popup_mouse_event
bool qt_popup_down_closed
Q_WIDGETS_EXPORT QWidget * qt_button_down
bool qt_try_modal(QWidget *widget, QEvent::Type type)
static const double leftOffset
static const double rightOffset
constexpr T qAbs(const T &t)
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
QPointer< QWindow > qt_last_mouse_receiver
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
QT_BEGIN_NAMESPACE bool toBool(const QString &str)