| 1 | // Copyright (C) 2016 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 QAPPLICATION_P_H |
| 5 | #define QAPPLICATION_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp |
| 13 | // and many other. This header file may change from version to version |
| 14 | // without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 20 | #include "QtWidgets/qapplication.h" |
| 21 | #include "QtGui/qevent.h" |
| 22 | #include "QtGui/qfont.h" |
| 23 | #include "QtGui/qcursor.h" |
| 24 | #include "QtGui/qregion.h" |
| 25 | #include "QtGui/qwindow.h" |
| 26 | #include "qwidget.h" |
| 27 | #include <qpa/qplatformnativeinterface.h> |
| 28 | #include "QtCore/qmutex.h" |
| 29 | #include "QtCore/qtranslator.h" |
| 30 | #include "QtCore/qbasictimer.h" |
| 31 | #include "QtCore/qhash.h" |
| 32 | #include "QtCore/qpointer.h" |
| 33 | #include "private/qcoreapplication_p.h" |
| 34 | #include "QtCore/qpoint.h" |
| 35 | #include <QTime> |
| 36 | #include <qpa/qwindowsysteminterface.h> |
| 37 | #include <qpa/qwindowsysteminterface_p.h> |
| 38 | #include <qpa/qplatformintegration.h> |
| 39 | #include "private/qguiapplication_p.h" |
| 40 | |
| 41 | QT_BEGIN_NAMESPACE |
| 42 | |
| 43 | class QClipboard; |
| 44 | class QGraphicsScene; |
| 45 | class QObject; |
| 46 | class QWidget; |
| 47 | class QSocketNotifier; |
| 48 | class QPointingDevice; |
| 49 | #ifndef QT_NO_GESTURES |
| 50 | class QGestureManager; |
| 51 | #endif |
| 52 | |
| 53 | extern Q_GUI_EXPORT bool qt_is_tty_app; |
| 54 | #ifndef QT_NO_CLIPBOARD |
| 55 | extern QClipboard *qt_clipboard; |
| 56 | #endif |
| 57 | |
| 58 | typedef QHash<QByteArray, QFont> FontHash; |
| 59 | Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash(); |
| 60 | |
| 61 | class Q_WIDGETS_EXPORT QApplicationPrivate : public QGuiApplicationPrivate |
| 62 | { |
| 63 | Q_DECLARE_PUBLIC(QApplication) |
| 64 | public: |
| 65 | QApplicationPrivate(int &argc, char **argv); |
| 66 | ~QApplicationPrivate(); |
| 67 | |
| 68 | virtual void notifyLayoutDirectionChange() override; |
| 69 | virtual void notifyActiveWindowChange(QWindow *) override; |
| 70 | |
| 71 | static bool autoSipEnabled; |
| 72 | static QString desktopStyleKey(); |
| 73 | |
| 74 | void createEventDispatcher() override; |
| 75 | static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF); |
| 76 | static QWidget *desktop(); |
| 77 | void notifyWindowIconChanged() override; |
| 78 | |
| 79 | #ifndef QT_NO_ACTION |
| 80 | QActionPrivate *createActionPrivate() const override; |
| 81 | #endif |
| 82 | #ifndef QT_NO_SHORTCUT |
| 83 | QShortcutPrivate *createShortcutPrivate() const override; |
| 84 | #endif |
| 85 | |
| 86 | //modality |
| 87 | Qt::WindowModality defaultModality() const override; |
| 88 | bool windowNeverBlocked(QWindow *window) const override; |
| 89 | static bool isBlockedByModal(QWidget *widget); |
| 90 | static bool modalState(); |
| 91 | static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr); |
| 92 | |
| 93 | #ifdef QT_KEYPAD_NAVIGATION |
| 94 | static bool keypadNavigationEnabled() |
| 95 | { |
| 96 | return navigationMode == Qt::NavigationModeKeypadTabOrder || |
| 97 | navigationMode == Qt::NavigationModeKeypadDirectional; |
| 98 | } |
| 99 | #endif |
| 100 | |
| 101 | bool notify_helper(QObject *receiver, QEvent * e); |
| 102 | |
| 103 | void init(); |
| 104 | void initialize(); |
| 105 | void process_cmdline(); |
| 106 | |
| 107 | static void setActiveWindow(QWidget* act); |
| 108 | |
| 109 | static bool (); |
| 110 | void (QWidget *); |
| 111 | void (QWidget *); |
| 112 | static bool replayMousePress; |
| 113 | |
| 114 | static void setFocusWidget(QWidget *focus, Qt::FocusReason reason); |
| 115 | static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next, |
| 116 | bool *wrappingOccurred = nullptr); |
| 117 | |
| 118 | #if QT_CONFIG(graphicsview) |
| 119 | // Maintain a list of all scenes to ensure font and palette propagation to |
| 120 | // all scenes. |
| 121 | QList<QGraphicsScene *> scene_list; |
| 122 | #endif |
| 123 | |
| 124 | QBasicTimer toolTipWakeUp, toolTipFallAsleep; |
| 125 | QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos; |
| 126 | QPointer<QWidget> toolTipWidget; |
| 127 | |
| 128 | static QSize app_strut; |
| 129 | static QWidgetList *; |
| 130 | static QStyle *app_style; |
| 131 | |
| 132 | protected: |
| 133 | void handleThemeChanged() override; |
| 134 | |
| 135 | QPalette basePalette() const override; |
| 136 | void handlePaletteChanged(const char *className = nullptr) override; |
| 137 | |
| 138 | #if QT_CONFIG(draganddrop) |
| 139 | void notifyDragStarted(const QDrag *) override; |
| 140 | #endif // QT_CONFIG(draganddrop) |
| 141 | |
| 142 | public: |
| 143 | static QFont *sys_font; |
| 144 | static QFont *set_font; |
| 145 | static QWidget *main_widget; |
| 146 | static QWidget *focus_widget; |
| 147 | static QWidget *hidden_focus_widget; |
| 148 | #if QT_CONFIG(wheelevent) |
| 149 | static QPointer<QWidget> wheel_widget; |
| 150 | #endif |
| 151 | |
| 152 | static int enabledAnimations; // Combination of QPlatformTheme::UiEffect |
| 153 | static bool widgetCount; // Coupled with -widgetcount switch |
| 154 | |
| 155 | static void initializeWidgetPalettesFromTheme(); |
| 156 | static void initializeWidgetFontHash(); |
| 157 | static void setSystemFont(const QFont &font); |
| 158 | |
| 159 | using PaletteHash = QHash<QByteArray, QPalette>; |
| 160 | static PaletteHash widgetPalettes; |
| 161 | |
| 162 | static QApplicationPrivate *instance() { return self; } |
| 163 | |
| 164 | #ifdef QT_KEYPAD_NAVIGATION |
| 165 | static QWidget *oldEditFocus; |
| 166 | static Qt::NavigationMode navigationMode; |
| 167 | #endif |
| 168 | |
| 169 | #ifndef QT_NO_STYLE_STYLESHEET |
| 170 | static QString styleSheet; |
| 171 | #endif |
| 172 | static QPointer<QWidget> leaveAfterRelease; |
| 173 | static QWidget *pickMouseReceiver(QWidget *candidate, const QPointF &windowPos, QPointF *pos, |
| 174 | QEvent::Type type, Qt::MouseButtons buttons, |
| 175 | QWidget *buttonDown, QWidget *alienWidget); |
| 176 | static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, |
| 177 | QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver, |
| 178 | bool spontaneous = true, bool onlyDispatchEnterLeave = false); |
| 179 | void sendSyntheticEnterLeave(QWidget *widget); |
| 180 | |
| 181 | static QWindow *windowForWidget(const QWidget *widget) |
| 182 | { |
| 183 | if (QWindow *window = widget->windowHandle()) |
| 184 | return window; |
| 185 | if (const QWidget *nativeParent = widget->nativeParentWidget()) |
| 186 | return nativeParent->windowHandle(); |
| 187 | return nullptr; |
| 188 | } |
| 189 | |
| 190 | #ifdef Q_OS_WIN |
| 191 | static HWND getHWNDForWidget(const QWidget *widget) |
| 192 | { |
| 193 | if (QWindow *window = windowForWidget(widget)) |
| 194 | if (window->handle() && QGuiApplication::platformNativeInterface()) |
| 195 | return static_cast<HWND> (QGuiApplication::platformNativeInterface()-> |
| 196 | nativeResourceForWindow(QByteArrayLiteral("handle" ), window)); |
| 197 | return 0; |
| 198 | } |
| 199 | #endif |
| 200 | |
| 201 | #ifndef QT_NO_GESTURES |
| 202 | QGestureManager *gestureManager; |
| 203 | QWidget *gestureWidget; |
| 204 | #endif |
| 205 | |
| 206 | static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent); |
| 207 | void initializeMultitouch(); |
| 208 | void initializeMultitouch_sys(); |
| 209 | void cleanupMultitouch(); |
| 210 | void cleanupMultitouch_sys(); |
| 211 | QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint); |
| 212 | void appendTouchPoint(const QEventPoint &touchPoint); |
| 213 | void removeTouchPoint(int touchPointId); |
| 214 | enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints }; |
| 215 | void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent, |
| 216 | ImplicitTouchGrabMode grabMode = GrabAcceptedPoints); |
| 217 | static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent); |
| 218 | static void translateTouchCancel(const QPointingDevice *device, ulong timestamp); |
| 219 | |
| 220 | QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override; |
| 221 | |
| 222 | private: |
| 223 | static QApplicationPrivate *self; |
| 224 | static bool tryCloseAllWidgetWindows(QWindowList *processedWindows); |
| 225 | |
| 226 | static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos); |
| 227 | static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy); |
| 228 | |
| 229 | static QWidget *active_window; |
| 230 | |
| 231 | static bool isAlien(QWidget *); |
| 232 | }; |
| 233 | |
| 234 | extern void qt_qpa_set_cursor(QWidget * w, bool force); |
| 235 | |
| 236 | QT_END_NAMESPACE |
| 237 | |
| 238 | #endif // QAPPLICATION_P_H |
| 239 | |