| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QAPPLICATION_P_H |
| 41 | #define QAPPLICATION_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists for the convenience |
| 48 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp |
| 49 | // and many other. This header file may change from version to version |
| 50 | // without notice, or even be removed. |
| 51 | // |
| 52 | // We mean it. |
| 53 | // |
| 54 | |
| 55 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 56 | #include "QtWidgets/qapplication.h" |
| 57 | #include "QtGui/qevent.h" |
| 58 | #include "QtGui/qfont.h" |
| 59 | #include "QtGui/qcursor.h" |
| 60 | #include "QtGui/qregion.h" |
| 61 | #include "QtGui/qwindow.h" |
| 62 | #include "qwidget.h" |
| 63 | #include <qpa/qplatformnativeinterface.h> |
| 64 | #include "QtCore/qmutex.h" |
| 65 | #include "QtCore/qtranslator.h" |
| 66 | #include "QtCore/qbasictimer.h" |
| 67 | #include "QtCore/qhash.h" |
| 68 | #include "QtCore/qpointer.h" |
| 69 | #include "private/qcoreapplication_p.h" |
| 70 | #include "QtCore/qpoint.h" |
| 71 | #include <QTime> |
| 72 | #include <qpa/qwindowsysteminterface.h> |
| 73 | #include <qpa/qwindowsysteminterface_p.h> |
| 74 | #include <qpa/qplatformintegration.h> |
| 75 | #include "private/qguiapplication_p.h" |
| 76 | |
| 77 | QT_BEGIN_NAMESPACE |
| 78 | |
| 79 | class QClipboard; |
| 80 | class QGraphicsScene; |
| 81 | class QObject; |
| 82 | class QWidget; |
| 83 | class QSocketNotifier; |
| 84 | class QPointingDevice; |
| 85 | #ifndef QT_NO_GESTURES |
| 86 | class QGestureManager; |
| 87 | #endif |
| 88 | |
| 89 | extern Q_GUI_EXPORT bool qt_is_gui_used; |
| 90 | #ifndef QT_NO_CLIPBOARD |
| 91 | extern QClipboard *qt_clipboard; |
| 92 | #endif |
| 93 | |
| 94 | typedef QHash<QByteArray, QFont> FontHash; |
| 95 | Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash(); |
| 96 | |
| 97 | #define QApplicationPrivateBase QGuiApplicationPrivate |
| 98 | |
| 99 | class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase |
| 100 | { |
| 101 | Q_DECLARE_PUBLIC(QApplication) |
| 102 | public: |
| 103 | QApplicationPrivate(int &argc, char **argv, int flags); |
| 104 | ~QApplicationPrivate(); |
| 105 | |
| 106 | virtual void notifyLayoutDirectionChange() override; |
| 107 | virtual void notifyActiveWindowChange(QWindow *) override; |
| 108 | |
| 109 | virtual bool shouldQuit() override; |
| 110 | |
| 111 | static bool autoSipEnabled; |
| 112 | static QString desktopStyleKey(); |
| 113 | |
| 114 | void createEventDispatcher() override; |
| 115 | static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF); |
| 116 | static QWidget *desktop(); |
| 117 | void notifyWindowIconChanged() override; |
| 118 | |
| 119 | #ifndef QT_NO_ACTION |
| 120 | QActionPrivate *createActionPrivate() const override; |
| 121 | #endif |
| 122 | #ifndef QT_NO_SHORTCUT |
| 123 | QShortcutPrivate *createShortcutPrivate() const override; |
| 124 | #endif |
| 125 | |
| 126 | //modality |
| 127 | bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const override; |
| 128 | static bool isBlockedByModal(QWidget *widget); |
| 129 | static bool modalState(); |
| 130 | static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr); |
| 131 | |
| 132 | #ifdef QT_KEYPAD_NAVIGATION |
| 133 | static bool keypadNavigationEnabled() |
| 134 | { |
| 135 | return navigationMode == Qt::NavigationModeKeypadTabOrder || |
| 136 | navigationMode == Qt::NavigationModeKeypadDirectional; |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | bool notify_helper(QObject *receiver, QEvent * e); |
| 141 | |
| 142 | void init(); |
| 143 | void initialize(); |
| 144 | void process_cmdline(); |
| 145 | |
| 146 | static bool (); |
| 147 | bool () override { return inPopupMode(); } |
| 148 | void (QWidget *); |
| 149 | void (QWidget *); |
| 150 | static void setFocusWidget(QWidget *focus, Qt::FocusReason reason); |
| 151 | static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next, |
| 152 | bool *wrappingOccurred = nullptr); |
| 153 | |
| 154 | #if QT_CONFIG(graphicsview) |
| 155 | // Maintain a list of all scenes to ensure font and palette propagation to |
| 156 | // all scenes. |
| 157 | QList<QGraphicsScene *> scene_list; |
| 158 | #endif |
| 159 | |
| 160 | QBasicTimer toolTipWakeUp, toolTipFallAsleep; |
| 161 | QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos; |
| 162 | QPointer<QWidget> toolTipWidget; |
| 163 | |
| 164 | static QSize app_strut; |
| 165 | static QWidgetList *; |
| 166 | static QStyle *app_style; |
| 167 | |
| 168 | protected: |
| 169 | void notifyThemeChanged() override; |
| 170 | |
| 171 | QPalette basePalette() const override; |
| 172 | void handlePaletteChanged(const char *className = nullptr) override; |
| 173 | |
| 174 | #if QT_CONFIG(draganddrop) |
| 175 | void notifyDragStarted(const QDrag *) override; |
| 176 | #endif // QT_CONFIG(draganddrop) |
| 177 | |
| 178 | public: |
| 179 | static QFont *sys_font; |
| 180 | static QFont *set_font; |
| 181 | static QWidget *main_widget; |
| 182 | static QWidget *focus_widget; |
| 183 | static QWidget *hidden_focus_widget; |
| 184 | static QWidget *active_window; |
| 185 | #if QT_CONFIG(wheelevent) |
| 186 | static int wheel_scroll_lines; |
| 187 | static QPointer<QWidget> wheel_widget; |
| 188 | #endif |
| 189 | |
| 190 | static int enabledAnimations; // Combination of QPlatformTheme::UiEffect |
| 191 | static bool widgetCount; // Coupled with -widgetcount switch |
| 192 | |
| 193 | static void initializeWidgetPalettesFromTheme(); |
| 194 | static void initializeWidgetFontHash(); |
| 195 | static void setSystemFont(const QFont &font); |
| 196 | |
| 197 | using PaletteHash = QHash<QByteArray, QPalette>; |
| 198 | static PaletteHash widgetPalettes; |
| 199 | |
| 200 | static QApplicationPrivate *instance() { return self; } |
| 201 | |
| 202 | #ifdef QT_KEYPAD_NAVIGATION |
| 203 | static QWidget *oldEditFocus; |
| 204 | static Qt::NavigationMode navigationMode; |
| 205 | #endif |
| 206 | |
| 207 | #ifndef QT_NO_STYLE_STYLESHEET |
| 208 | static QString styleSheet; |
| 209 | #endif |
| 210 | static QPointer<QWidget> leaveAfterRelease; |
| 211 | static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos, |
| 212 | QEvent::Type type, Qt::MouseButtons buttons, |
| 213 | QWidget *buttonDown, QWidget *alienWidget); |
| 214 | static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, |
| 215 | QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver, |
| 216 | bool spontaneous = true, bool onlyDispatchEnterLeave = false); |
| 217 | void sendSyntheticEnterLeave(QWidget *widget); |
| 218 | |
| 219 | static QWindow *windowForWidget(const QWidget *widget) |
| 220 | { |
| 221 | if (QWindow *window = widget->windowHandle()) |
| 222 | return window; |
| 223 | if (const QWidget *nativeParent = widget->nativeParentWidget()) |
| 224 | return nativeParent->windowHandle(); |
| 225 | return nullptr; |
| 226 | } |
| 227 | |
| 228 | #ifdef Q_OS_WIN |
| 229 | static HWND getHWNDForWidget(const QWidget *widget) |
| 230 | { |
| 231 | if (QWindow *window = windowForWidget(widget)) |
| 232 | if (window->handle() && QGuiApplication::platformNativeInterface()) |
| 233 | return static_cast<HWND> (QGuiApplication::platformNativeInterface()-> |
| 234 | nativeResourceForWindow(QByteArrayLiteral("handle" ), window)); |
| 235 | return 0; |
| 236 | } |
| 237 | #endif |
| 238 | |
| 239 | #ifndef QT_NO_GESTURES |
| 240 | QGestureManager *gestureManager; |
| 241 | QWidget *gestureWidget; |
| 242 | #endif |
| 243 | |
| 244 | static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent); |
| 245 | void initializeMultitouch(); |
| 246 | void initializeMultitouch_sys(); |
| 247 | void cleanupMultitouch(); |
| 248 | void cleanupMultitouch_sys(); |
| 249 | QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint); |
| 250 | void appendTouchPoint(const QEventPoint &touchPoint); |
| 251 | void removeTouchPoint(int touchPointId); |
| 252 | void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent); |
| 253 | static bool translateRawTouchEvent(QWidget *widget, |
| 254 | const QPointingDevice *device, |
| 255 | QList<QEventPoint> &touchPoints, |
| 256 | ulong timestamp); |
| 257 | static void translateTouchCancel(const QPointingDevice *device, ulong timestamp); |
| 258 | |
| 259 | QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override; |
| 260 | |
| 261 | QEvent *cloneEvent(QEvent *e) override; |
| 262 | |
| 263 | private: |
| 264 | static QApplicationPrivate *self; |
| 265 | static bool tryCloseAllWidgetWindows(QWindowList *processedWindows); |
| 266 | |
| 267 | static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos); |
| 268 | static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy); |
| 269 | |
| 270 | |
| 271 | static bool isAlien(QWidget *); |
| 272 | }; |
| 273 | |
| 274 | extern void qt_qpa_set_cursor(QWidget * w, bool force); |
| 275 | |
| 276 | QT_END_NAMESPACE |
| 277 | |
| 278 | #endif // QAPPLICATION_P_H |
| 279 | |