diff options
Diffstat (limited to 'src/widgets/kernel/qwidget_p.h')
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 308 |
1 files changed, 66 insertions, 242 deletions
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 3dccd00b8b..698928b0b0 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -75,15 +75,20 @@ #include <private/qgesture_p.h> #include <qpa/qplatformbackingstore.h> +#include <vector> +#include <memory> + QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcWidgetPainting); + // Extra QWidget data // - to minimize memory usage for members that are seldom used. // - top-level widgets have extra extra data to reduce cost further class QWidgetWindow; class QPaintEngine; class QPixmap; -class QWidgetBackingStore; +class QWidgetRepaintManager; class QGraphicsProxyWidget; class QWidgetItemV2; class QOpenGLContext; @@ -113,60 +118,18 @@ protected: QRegion m_region; }; - - -class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker -{ - -public: - QWidgetBackingStoreTracker(); - ~QWidgetBackingStoreTracker(); - - void create(QWidget *tlw); - void destroy(); - - void registerWidget(QWidget *w); - void unregisterWidget(QWidget *w); - void unregisterWidgetSubtree(QWidget *w); - - inline QWidgetBackingStore* data() - { - return m_ptr; - } - - inline QWidgetBackingStore* operator->() - { - return m_ptr; - } - - inline QWidgetBackingStore& operator*() - { - return *m_ptr; - } - - inline operator bool() const - { - return (0 != m_ptr); - } - -private: - Q_DISABLE_COPY_MOVE(QWidgetBackingStoreTracker) - -private: - QWidgetBackingStore* m_ptr; - QSet<QWidget *> m_widgets; -}; - struct QTLWExtra { // *************************** Cross-platform variables ***************************** // Regular pointers (keep them together to avoid gaps on 64 bits architectures). - QIcon *icon; // widget icon - QWidgetBackingStoreTracker backingStoreTracker; + std::unique_ptr<QIcon> icon; // widget icon + std::unique_ptr<QWidgetRepaintManager> repaintManager; QBackingStore *backingStore; QPainter *sharedPainter; QWidgetWindow *window; - QOpenGLContext *shareContext; +#ifndef QT_NO_OPENGL + mutable std::unique_ptr<QOpenGLContext> shareContext; +#endif // Implicit pointers (shared_null). QString caption; // widget caption @@ -184,7 +147,9 @@ struct QTLWExtra { // ### TODO replace initialScreenIndex with QScreen *, in case the screens change at runtime int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent. - QVector<QPlatformTextureList *> widgetTextures; +#ifndef QT_NO_OPENGL + std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures; +#endif // *************************** Cross-platform bit fields **************************** uint opacity : 8; @@ -192,41 +157,6 @@ struct QTLWExtra { uint sizeAdjusted : 1; uint inTopLevelResize : 1; uint embedded : 1; - - // *************************** Platform specific values (bit fields first) ********** -#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11 - uint spont_unmapped: 1; // window was spontaneously unmapped - uint dnd : 1; // DND properties installed - uint validWMState : 1; // is WM_STATE valid? - uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet - WId parentWinId; // parent window Id (valid after reparenting) - WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom - QPoint fullScreenOffset; -#ifndef QT_NO_XSYNC - WId syncUpdateCounter; - ulong syncRequestTimestamp; - qint32 newCounterValueHi; - quint32 newCounterValueLo; -#endif -#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN - uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered. - HICON winIconBig; // internal big Windows icon - HICON winIconSmall; // internal small Windows icon -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC - uint resizer : 4; - uint isSetGeometry : 1; - uint isMove : 1; - quint32 wattr; - quint32 wclass; - WindowGroupRef group; - IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys. - quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys() - // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and - // manually resized. - // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the - // starting position as 0,0 instead of the normal starting position. - bool wasMaximized; -#endif }; struct QWExtra { @@ -234,12 +164,12 @@ struct QWExtra { // Regular pointers (keep them together to avoid gaps on 64 bits architectures). void *glContext; // if the widget is hijacked by QGLWindowSurface - QTLWExtra *topextra; // only useful for TLWs + std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs #if QT_CONFIG(graphicsview) QGraphicsProxyWidget *proxyWidget; // if the widget is embedded #endif #ifndef QT_NO_CURSOR - QCursor *curs; + std::unique_ptr<QCursor> curs; #endif QPointer<QStyle> style; QPointer<QWidget> focus_proxy; @@ -265,21 +195,6 @@ struct QWExtra { uint inRenderWithPainter : 1; uint hasMask : 1; uint hasWindowContainer : 1; - - // *************************** Platform specific values (bit fields first) ********** -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <----------------------------------------------------------- WIN -#if QT_CONFIG(draganddrop) - QOleDropTarget *dropTarget; // drop target - QList<QPointer<QWidget> > oleDropWidgets; -#endif -#elif 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <--------------------------------------------------------- X11 - uint compress_events : 1; - WId xDndProxy; // XDND forwarding to embedded windows -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <------------------------------------------------------ MAC - // Cocoa Mask stuff - QImage maskBits; - CGImageRef imageMask; -#endif }; /*! @@ -303,10 +218,11 @@ static inline bool bypassGraphicsProxyWidget(const QWidget *p) class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QWidget) + Q_GADGET public: // *************************** Cross-platform *************************************** - enum DrawWidgetFlags { + enum DrawWidgetFlag { DrawAsRoot = 0x01, DrawPaintOnScreen = 0x02, DrawRecursive = 0x04, @@ -316,12 +232,15 @@ public: DontDrawNativeChildren = 0x40, DontSetCompositionMode = 0x80 }; + Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag) + Q_FLAG(DrawWidgetFlags) enum CloseMode { CloseNoEvent, CloseWithEvent, CloseWithSpontaneousEvent }; + Q_ENUM(CloseMode) enum Direction { DirectionNorth = 0x01, @@ -329,6 +248,7 @@ public: DirectionSouth = 0x02, DirectionWest = 0x20 }; + Q_ENUM(Direction) // Functions. explicit QWidgetPrivate(int version = QObjectPrivateVersion); @@ -342,8 +262,16 @@ public: QTLWExtra *maybeTopData() const; QPainter *sharedPainter() const; void setSharedPainter(QPainter *painter); - QWidgetBackingStore *maybeBackingStore() const; - QWidgetWindow *windowHandle() const; + QWidgetRepaintManager *maybeRepaintManager() const; + + enum class WindowHandleMode { + Direct, + Closest, + TopLevel + }; + QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const; + + QScreen *associatedScreen() const; template <typename T> void repaint(T t); @@ -405,38 +333,38 @@ public: void setUpdatesEnabled_helper(bool ); bool updateBrushOrigin(QPainter *, const QBrush &brush) const; - void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const; + void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const; bool isAboutToShow() const; QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags); void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags); void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags); - void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, - QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0); + void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, + QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr); void sendPaintEvent(const QRegion &toBePainted); void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index, - const QRegion &rgn, const QPoint &offset, int flags, - QPainter *sharedPainter, QWidgetBackingStore *backingStore); + const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, + QPainter *sharedPainter, QWidgetRepaintManager *repaintManager); #if QT_CONFIG(graphicsview) static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin); #endif - void repaint_sys(const QRegion &rgn); + bool shouldPaintOnScreen() const; + void paintOnScreen(const QRegion &rgn); QRect clipRect() const; QRegion clipRegion() const; void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion ®ion); void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const; - void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0, + void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr, bool alsoNonOpaque = false) const; void clipToEffectiveMask(QRegion ®ion) const; void updateIsOpaque(); void setOpaque(bool opaque); void updateIsTranslucent(); - bool paintOnScreen() const; #if QT_CONFIG(graphicseffect) void invalidateGraphicsEffectsRecursively(); #endif // QT_CONFIG(graphicseffect) @@ -463,6 +391,8 @@ public: void syncBackingStore(); void syncBackingStore(const QRegion ®ion); + bool shouldDiscardSyncRequest() const; + // tells the input method about the widgets transform void updateWidgetTransform(QEvent *event); @@ -527,7 +457,7 @@ public: void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const; void setLayoutItemMargins(int left, int top, int right, int bottom); - void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0); + void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr); void updateContentsRect(); QMargins safeAreaMargins() const; @@ -557,7 +487,7 @@ public: QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget); //It's embedded if it has an ancestor if (ancestorProxy) { - if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) { + if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) { // One view, let be smart and return the viewport rect then the popup is aligned if (ancestorProxy->scene()->views().size() == 1) { QGraphicsView *view = ancestorProxy->scene()->views().at(0); @@ -588,7 +518,7 @@ public: } inline void restoreRedirected() - { redirectDev = 0; } + { redirectDev = nullptr; } inline void enforceNativeChildren() { @@ -654,7 +584,7 @@ public: QOpenGLContext *shareContext() const; - virtual QObject *focusObject() { return 0; } + virtual QObject *focusObject() { return nullptr; } #ifndef QT_NO_OPENGL virtual GLuint textureId() const { return 0; } @@ -662,7 +592,7 @@ public: Q_Q(QWidget); return q->testAttribute(Qt::WA_AlwaysStackOnTop) ? QPlatformTextureList::StacksOnTop - : QPlatformTextureList::Flags(0); + : QPlatformTextureList::Flags(nullptr); } virtual QImage grabFramebuffer() { return QImage(); } virtual void beginBackingStorePainting() { } @@ -698,7 +628,7 @@ public: // Variables. // Regular pointers (keep them together to avoid gaps on 64 bit architectures). - QWExtra *extra; + std::unique_ptr<QWExtra> extra; QWidget *focus_next; QWidget *focus_prev; QWidget *focus_child; @@ -792,109 +722,8 @@ public: // *************************** Platform specific ************************************ #if defined(Q_OS_WIN) uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine() -#endif -#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11 - Qt::HANDLE picture; - static QWidget *mouseGrabber; - static QWidget *keyboardGrabber; - - void setWindowRole(); - void sendStartupMessage(const char *message) const; - void x11UpdateIsOpaque(); - bool isBackgroundInherited() const; - void updateX11AcceptFocus(); - QPoint mapToGlobal(const QPoint &pos) const; - QPoint mapFromGlobal(const QPoint &pos) const; -#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN -#ifndef QT_NO_GESTURES - uint nativeGesturePanEnabled : 1; -#endif - bool shouldShowMaximizeButton(); - void winUpdateIsOpaque(); - void reparentChildren(); -#if QT_CONFIG(draganddrop) - QOleDropTarget *registerOleDnd(QWidget *widget); - void unregisterOleDnd(QWidget *widget, QOleDropTarget *target); -#endif - void grabMouseWhileInWindow(); - void registerTouchWindow(); - void winSetupGestures(); -#elif defined(Q_OS_MAC) // <--------------------------------------------------------- MAC +#elif defined(Q_OS_MAC) void macUpdateSizeAttribute(); -#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC (old stuff) - // This is new stuff - uint needWindowChange : 1; - - // Each wiget keeps a list of all its child and grandchild OpenGL widgets. - // This list is used to update the gl context whenever a parent and a granparent - // moves, and also to check for intersections with gl widgets within the window - // when a widget moves. - struct GlWidgetInfo - { - GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { } - bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); } - QWidget * widget; - QWidget * lastUpdateWidget; - }; - - // dirtyOnWidget contains the areas in the widget that needs to be repained, - // in the same way as dirtyOnScreen does for the window. Areas are added in - // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use - // this information repaint invalid areas when widgets are scrolled. - QRegion dirtyOnWidget; - EventHandlerRef window_event; - QList<GlWidgetInfo> glWidgets; - - //these are here just for code compat (HIViews) - Qt::HANDLE qd_hd; - - void macUpdateHideOnSuspend(); - void macUpdateOpaqueSizeGrip(); - void macUpdateIgnoreMouseEvents(); - void macUpdateMetalAttribute(); - void macUpdateIsOpaque(); - void macSetNeedsDisplay(QRegion region); - void setEnabled_helper_sys(bool enable); - bool isRealWindow() const; - void adjustWithinMaxAndMinSize(int &w, int &h); - void applyMaxAndMinSizeOnWindow(); - void update_sys(const QRect &rect); - void update_sys(const QRegion &rgn); - void setGeometry_sys_helper(int, int, int, int, bool); - void updateMaximizeButton_sys(); - void createWindow_sys(); - void recreateMacWindow(); - void setSubWindowStacking(bool set); - void setWindowLevel(); - void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef); - void syncCocoaMask(); - void finishCocoaMaskSetup(); - // Did we add the drawRectOriginal method? - bool drawRectOriginalAdded; - // Is the original drawRect method available? - bool originalDrawMethod; - // Do we need to change the methods? - bool changeMethods; - - // Unified toolbar variables - bool isInUnifiedToolbar; - QUnifiedToolbarSurface *unifiedSurface; - QPoint toolbar_offset; - QWidget *toolbar_ancestor; - bool flushRequested; - bool touchEventsEnabled; - void determineWindowClass(); - void transferChildren(); - bool qt_mac_dnd_event(uint, DragRef); - void toggleDrawers(bool); - //mac event functions - static bool qt_create_root_win(); - static void qt_clean_root_win(); - static bool qt_mac_update_sizer(QWidget *, int up = 0); - static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *); - static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *); - static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool); - void registerTouchWindow(bool enable = true); #endif void setNetWmWindowTypes(bool skipIfMissing = false); @@ -902,18 +731,20 @@ public: bool stealMouseGrab(bool grab); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags) + struct QWidgetPaintContext { - inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f, - QPainter *p, QWidgetBackingStore *b) - : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {} + inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f, + QPainter *p, QWidgetRepaintManager *rpm) + : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {} QPaintDevice *pdev; QRegion rgn; QPoint offset; - int flags; + QWidgetPrivate::DrawWidgetFlags flags; QPainter *sharedPainter; - QWidgetBackingStore *backingStore; + QWidgetRepaintManager *repaintManager; QPainter *painter; }; @@ -922,14 +753,14 @@ class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate { public: QWidgetEffectSourcePrivate(QWidget *widget) - : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false) + : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false) {} void detach() override - { m_widget->d_func()->graphicsEffect = 0; } + { m_widget->d_func()->graphicsEffect = nullptr; } const QGraphicsItem *graphicsItem() const override - { return 0; } + { return nullptr; } const QWidget *widget() const override { return m_widget; } @@ -955,7 +786,7 @@ public: } const QStyleOption *styleOption() const override - { return 0; } + { return nullptr; } QRect deviceRect() const override { return m_widget->window()->rect(); } @@ -974,25 +805,25 @@ public: inline QWExtra *QWidgetPrivate::extraData() const { - return extra; + return extra.get(); } inline QTLWExtra *QWidgetPrivate::topData() const { const_cast<QWidgetPrivate *>(this)->createTLExtra(); - return extra->topextra; + return extra->topextra.get(); } inline QTLWExtra *QWidgetPrivate::maybeTopData() const { - return extra ? extra->topextra : 0; + return extra ? extra->topextra.get() : nullptr; } inline QPainter *QWidgetPrivate::sharedPainter() const { Q_Q(const QWidget); QTLWExtra *x = q->window()->d_func()->maybeTopData(); - return x ? x->sharedPainter : 0; + return x ? x->sharedPainter : nullptr; } inline void QWidgetPrivate::setSharedPainter(QPainter *painter) @@ -1009,18 +840,11 @@ inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const || extra->mask.contains(p)); } -inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const +inline QWidgetRepaintManager *QWidgetPrivate::maybeRepaintManager() const { Q_Q(const QWidget); QTLWExtra *x = q->window()->d_func()->maybeTopData(); - return x ? x->backingStoreTracker.data() : 0; -} - -inline QWidgetWindow *QWidgetPrivate::windowHandle() const -{ - if (QTLWExtra *x = maybeTopData()) - return x->window; - return nullptr; + return x ? x->repaintManager.get() : nullptr; } QT_END_NAMESPACE |