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 QWIDGET_P_H
41#define QWIDGET_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 and qfiledialog.cpp. This header
49// file may change from version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtWidgets/private/qtwidgetsglobal_p.h>
55#include "QtWidgets/qwidget.h"
56#include "private/qobject_p.h"
57#include "QtCore/qrect.h"
58#include "QtCore/qlocale.h"
59#include "QtCore/qset.h"
60#include "QtGui/qregion.h"
61#include "QtGui/qinputmethod.h"
62#include "QtGui/qopengl.h"
63#include "QtGui/qsurfaceformat.h"
64#include "QtWidgets/qsizepolicy.h"
65#include "QtWidgets/qstyle.h"
66#include "QtWidgets/qapplication.h"
67#if QT_CONFIG(graphicseffect)
68#include <private/qgraphicseffect_p.h>
69#endif
70#if QT_CONFIG(graphicsview)
71#include "QtWidgets/qgraphicsproxywidget.h"
72#include "QtWidgets/qgraphicsscene.h"
73#include "QtWidgets/qgraphicsview.h"
74#endif
75#include <private/qgesture_p.h>
76#include <qpa/qplatformbackingstore.h>
77
78QT_BEGIN_NAMESPACE
79
80// Extra QWidget data
81// - to minimize memory usage for members that are seldom used.
82// - top-level widgets have extra extra data to reduce cost further
83class QWidgetWindow;
84class QPaintEngine;
85class QPixmap;
86class QWidgetBackingStore;
87class QGraphicsProxyWidget;
88class QWidgetItemV2;
89class QOpenGLContext;
90
91class QStyle;
92
93class QUnifiedToolbarSurface;
94
95// implemented in qshortcut.cpp
96bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context);
97
98class QUpdateLaterEvent : public QEvent
99{
100public:
101 explicit QUpdateLaterEvent(const QRegion& paintRegion)
102 : QEvent(UpdateLater), m_region(paintRegion)
103 {
104 }
105
106 ~QUpdateLaterEvent()
107 {
108 }
109
110 inline const QRegion &region() const { return m_region; }
111
112protected:
113 QRegion m_region;
114};
115
116
117
118class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker
119{
120
121public:
122 QWidgetBackingStoreTracker();
123 ~QWidgetBackingStoreTracker();
124
125 void create(QWidget *tlw);
126 void destroy();
127
128 void registerWidget(QWidget *w);
129 void unregisterWidget(QWidget *w);
130 void unregisterWidgetSubtree(QWidget *w);
131
132 inline QWidgetBackingStore* data()
133 {
134 return m_ptr;
135 }
136
137 inline QWidgetBackingStore* operator->()
138 {
139 return m_ptr;
140 }
141
142 inline QWidgetBackingStore& operator*()
143 {
144 return *m_ptr;
145 }
146
147 inline operator bool() const
148 {
149 return (0 != m_ptr);
150 }
151
152private:
153 Q_DISABLE_COPY_MOVE(QWidgetBackingStoreTracker)
154
155private:
156 QWidgetBackingStore* m_ptr;
157 QSet<QWidget *> m_widgets;
158};
159
160struct QTLWExtra {
161 // *************************** Cross-platform variables *****************************
162
163 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
164 QIcon *icon; // widget icon
165 QWidgetBackingStoreTracker backingStoreTracker;
166 QBackingStore *backingStore;
167 QPainter *sharedPainter;
168 QWidgetWindow *window;
169 QOpenGLContext *shareContext;
170
171 // Implicit pointers (shared_null).
172 QString caption; // widget caption
173 QString iconText; // widget icon text
174 QString role; // widget role
175 QString filePath; // widget file path
176
177 // Other variables.
178 short incw, inch; // size increments
179 short basew, baseh; // base sizes
180 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
181 QRect frameStrut;
182 QRect normalGeometry; // used by showMin/maximized/FullScreen
183 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
184 int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent.
185
186 QVector<QPlatformTextureList *> widgetTextures;
187
188 // *************************** Cross-platform bit fields ****************************
189 uint opacity : 8;
190 uint posIncludesFrame : 1;
191 uint sizeAdjusted : 1;
192 uint inTopLevelResize : 1;
193 uint embedded : 1;
194
195 // *************************** Platform specific values (bit fields first) **********
196#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11
197 uint spont_unmapped: 1; // window was spontaneously unmapped
198 uint dnd : 1; // DND properties installed
199 uint validWMState : 1; // is WM_STATE valid?
200 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
201 WId parentWinId; // parent window Id (valid after reparenting)
202 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
203 QPoint fullScreenOffset;
204#ifndef QT_NO_XSYNC
205 WId syncUpdateCounter;
206 ulong syncRequestTimestamp;
207 qint32 newCounterValueHi;
208 quint32 newCounterValueLo;
209#endif
210#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN
211 uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered.
212 HICON winIconBig; // internal big Windows icon
213 HICON winIconSmall; // internal small Windows icon
214#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC
215 uint resizer : 4;
216 uint isSetGeometry : 1;
217 uint isMove : 1;
218 quint32 wattr;
219 quint32 wclass;
220 WindowGroupRef group;
221 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
222 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
223 // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and
224 // manually resized.
225 // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the
226 // starting position as 0,0 instead of the normal starting position.
227 bool wasMaximized;
228#endif
229};
230
231struct QWExtra {
232 // *************************** Cross-platform variables *****************************
233
234 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
235 void *glContext; // if the widget is hijacked by QGLWindowSurface
236 QTLWExtra *topextra; // only useful for TLWs
237#if QT_CONFIG(graphicsview)
238 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
239#endif
240#ifndef QT_NO_CURSOR
241 QCursor *curs;
242#endif
243 QPointer<QStyle> style;
244 QPointer<QWidget> focus_proxy;
245
246 // Implicit pointers (shared_empty/shared_null).
247 QRegion mask; // widget mask
248 QString styleSheet;
249
250 // Other variables.
251 qint32 minw;
252 qint32 minh; // minimum size
253 qint32 maxw;
254 qint32 maxh; // maximum size
255 quint16 customDpiX;
256 quint16 customDpiY;
257 QSize staticContentsSize;
258
259 // *************************** Cross-platform bit fields ****************************
260 uint explicitMinSize : 2;
261 uint explicitMaxSize : 2;
262 uint autoFillBackground : 1;
263 uint nativeChildrenForced : 1;
264 uint inRenderWithPainter : 1;
265 uint hasMask : 1;
266 uint hasWindowContainer : 1;
267
268 // *************************** Platform specific values (bit fields first) **********
269#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <----------------------------------------------------------- WIN
270#if QT_CONFIG(draganddrop)
271 QOleDropTarget *dropTarget; // drop target
272 QList<QPointer<QWidget> > oleDropWidgets;
273#endif
274#elif 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <--------------------------------------------------------- X11
275 uint compress_events : 1;
276 WId xDndProxy; // XDND forwarding to embedded windows
277#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <------------------------------------------------------ MAC
278 // Cocoa Mask stuff
279 QImage maskBits;
280 CGImageRef imageMask;
281#endif
282};
283
284/*!
285 \internal
286
287 Returns \c true if \a p or any of its parents enable the
288 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
289 QWidget::setParent() to determine whether it's necessary to embed the
290 widget into a QGraphicsProxyWidget or not.
291*/
292static inline bool bypassGraphicsProxyWidget(const QWidget *p)
293{
294 while (p) {
295 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
296 return true;
297 p = p->parentWidget();
298 }
299 return false;
300}
301
302class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
303{
304 Q_DECLARE_PUBLIC(QWidget)
305
306public:
307 // *************************** Cross-platform ***************************************
308 enum DrawWidgetFlags {
309 DrawAsRoot = 0x01,
310 DrawPaintOnScreen = 0x02,
311 DrawRecursive = 0x04,
312 DrawInvisible = 0x08,
313 DontSubtractOpaqueChildren = 0x10,
314 DontDrawOpaqueChildren = 0x20,
315 DontDrawNativeChildren = 0x40,
316 DontSetCompositionMode = 0x80
317 };
318
319 enum CloseMode {
320 CloseNoEvent,
321 CloseWithEvent,
322 CloseWithSpontaneousEvent
323 };
324
325 enum Direction {
326 DirectionNorth = 0x01,
327 DirectionEast = 0x10,
328 DirectionSouth = 0x02,
329 DirectionWest = 0x20
330 };
331
332 // Functions.
333 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
334 ~QWidgetPrivate();
335
336 static QWidgetPrivate *get(QWidget *w) { return w->d_func(); }
337 static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); }
338
339 QWExtra *extraData() const;
340 QTLWExtra *topData() const;
341 QTLWExtra *maybeTopData() const;
342 QPainter *sharedPainter() const;
343 void setSharedPainter(QPainter *painter);
344 QWidgetBackingStore *maybeBackingStore() const;
345 QWidgetWindow *windowHandle() const;
346
347 template <typename T>
348 void repaint(T t);
349
350 template <typename T>
351 void update(T t);
352
353 void init(QWidget *desktopWidget, Qt::WindowFlags f);
354 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
355 void createRecursively();
356 void createWinId();
357
358 void setScreenForPoint(const QPoint &pos);
359
360 void createTLExtra();
361 void createExtra();
362 void deleteExtra();
363 void createSysExtra();
364 void deleteSysExtra();
365 void createTLSysExtra();
366 void deleteTLSysExtra();
367 void updateSystemBackground();
368 void propagatePaletteChange();
369
370 void setPalette_helper(const QPalette &);
371 void resolvePalette();
372 QPalette naturalWidgetPalette(uint inheritedMask) const;
373
374 void setMask_sys(const QRegion &);
375
376 void raise_sys();
377 void lower_sys();
378 void stackUnder_sys(QWidget *);
379
380 QWidget *deepestFocusProxy() const;
381 void setFocus_sys();
382 void updateFocusChild();
383
384 void updateFont(const QFont &);
385 inline void setFont_helper(const QFont &font) {
386 if (directFontResolveMask == font.resolve() && data.fnt == font)
387 return;
388 updateFont(font);
389 }
390 QFont localFont() const;
391 void resolveFont();
392 QFont naturalWidgetFont(uint inheritedMask) const;
393
394 void setLayoutDirection_helper(Qt::LayoutDirection);
395 void resolveLayoutDirection();
396
397 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
398 void resolveLocale();
399
400 void setStyle_helper(QStyle *newStyle, bool propagate);
401 void inheritStyle();
402
403 void setUpdatesEnabled_helper(bool );
404
405 bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
406 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
407 bool isAboutToShow() const;
408 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
409 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
410 QWidget::RenderFlags renderFlags);
411 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
412 QWidget::RenderFlags renderFlags);
413 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
414 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
415 void sendPaintEvent(const QRegion &toBePainted);
416
417
418 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
419 const QRegion &rgn, const QPoint &offset, int flags,
420 QPainter *sharedPainter, QWidgetBackingStore *backingStore);
421
422#if QT_CONFIG(graphicsview)
423 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
424#endif
425 void repaint_sys(const QRegion &rgn);
426
427 QRect clipRect() const;
428 QRegion clipRegion() const;
429 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region);
430 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
431 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
432 bool alsoNonOpaque = false) const;
433 void clipToEffectiveMask(QRegion &region) const;
434 void updateIsOpaque();
435 void setOpaque(bool opaque);
436 void updateIsTranslucent();
437 bool paintOnScreen() const;
438#if QT_CONFIG(graphicseffect)
439 void invalidateGraphicsEffectsRecursively();
440#endif // QT_CONFIG(graphicseffect)
441
442 const QRegion &getOpaqueChildren() const;
443 void setDirtyOpaqueRegion();
444
445 bool close_helper(CloseMode mode);
446
447 void setWindowIcon_helper();
448 void setWindowIcon_sys();
449 void setWindowOpacity_sys(qreal opacity);
450 void adjustQuitOnCloseAttribute();
451
452 void scrollChildren(int dx, int dy);
453 void moveRect(const QRect &, int dx, int dy);
454 void scrollRect(const QRect &, int dx, int dy);
455 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
456 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
457 void invalidateBuffer(const QRegion &);
458 void invalidateBuffer(const QRect &);
459 QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
460 void syncBackingStore();
461 void syncBackingStore(const QRegion &region);
462
463 // tells the input method about the widgets transform
464 void updateWidgetTransform(QEvent *event);
465
466 void reparentFocusWidgets(QWidget *oldtlw);
467
468 static int pointToRect(const QPoint &p, const QRect &r);
469
470 void setWinId(WId);
471 void showChildren(bool spontaneous);
472 void hideChildren(bool spontaneous);
473 void setParent_sys(QWidget *parent, Qt::WindowFlags);
474 void scroll_sys(int dx, int dy);
475 void scroll_sys(int dx, int dy, const QRect &r);
476 void deactivateWidgetCleanup();
477 void setGeometry_sys(int, int, int, int, bool);
478 void fixPosIncludesFrame();
479 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
480 void activateChildLayoutsRecursively();
481 void show_recursive();
482 void show_helper();
483 void show_sys();
484 void hide_sys();
485 void hide_helper();
486 void _q_showIfNotHidden();
487
488 void setEnabled_helper(bool);
489 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
490
491 void updateFrameStrut();
492 QRect frameStrut() const;
493
494#ifdef QT_KEYPAD_NAVIGATION
495 static bool navigateToDirection(Direction direction);
496 static QWidget *widgetInNavigationDirection(Direction direction);
497 static bool canKeypadNavigate(Qt::Orientation orientation);
498 static bool inTabWidget(QWidget *widget);
499#endif
500
501 void setWindowIconText_sys(const QString &cap);
502 void setWindowIconText_helper(const QString &cap);
503 void setWindowTitle_sys(const QString &cap);
504 void setWindowFilePath_sys(const QString &filePath);
505
506#ifndef QT_NO_CURSOR
507 void setCursor_sys(const QCursor &cursor);
508 void unsetCursor_sys();
509#endif
510
511 void setWindowTitle_helper(const QString &cap);
512 void setWindowFilePath_helper(const QString &filePath);
513 void setWindowModified_helper();
514 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
515
516 bool setMinimumSize_helper(int &minw, int &minh);
517 bool setMaximumSize_helper(int &maxw, int &maxh);
518 void setConstraints_sys();
519 bool pointInsideRectAndMask(const QPoint &) const;
520 QWidget *childAt_helper(const QPoint &, bool) const;
521 QWidget *childAtRecursiveHelper(const QPoint &p, bool) const;
522 void updateGeometry_helper(bool forceUpdate);
523
524 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
525 void setLayoutItemMargins(int left, int top, int right, int bottom);
526 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
527
528 void updateContentsRect();
529 QMargins safeAreaMargins() const;
530
531 // aboutToDestroy() is called just before the contents of
532 // QWidget::destroy() is executed. It's used to signal QWidget
533 // sub-classes that their internals are about to be released.
534 virtual void aboutToDestroy() {}
535
536 inline QWidget *effectiveFocusWidget() {
537 QWidget *w = q_func();
538 while (w->focusProxy())
539 w = w->focusProxy();
540 return w;
541 }
542
543 void setModal_sys();
544
545 // This is an helper function that return the available geometry for
546 // a widget and takes care is this one is in QGraphicsView.
547 // If the widget is not embed in a scene then the geometry available is
548 // null, we let QDesktopWidget decide for us.
549 static QRect screenGeometry(const QWidget *widget)
550 {
551 QRect screen;
552#if QT_CONFIG(graphicsview)
553 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
554 //It's embedded if it has an ancestor
555 if (ancestorProxy) {
556 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
557 // One view, let be smart and return the viewport rect then the popup is aligned
558 if (ancestorProxy->scene()->views().size() == 1) {
559 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
560 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
561 } else {
562 screen = ancestorProxy->scene()->sceneRect().toRect();
563 }
564 }
565 }
566#else
567 Q_UNUSED(widget);
568#endif
569 return screen;
570 }
571
572 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
573 {
574 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
575 redirectDev = replacement;
576 redirectOffset = offset;
577 }
578
579 inline QPaintDevice *redirected(QPoint *offset) const
580 {
581 if (offset)
582 *offset = redirectDev ? redirectOffset : QPoint();
583 return redirectDev;
584 }
585
586 inline void restoreRedirected()
587 { redirectDev = 0; }
588
589 inline void enforceNativeChildren()
590 {
591 if (!extra)
592 createExtra();
593
594 if (extra->nativeChildrenForced)
595 return;
596 extra->nativeChildrenForced = 1;
597
598 for (int i = 0; i < children.size(); ++i) {
599 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
600 child->setAttribute(Qt::WA_NativeWindow);
601 }
602 }
603
604 inline bool nativeChildrenForced() const
605 {
606 return extra ? extra->nativeChildrenForced : false;
607 }
608
609 inline QRect effectiveRectFor(const QRect &rect) const
610 {
611#if QT_CONFIG(graphicseffect)
612 if (graphicsEffect && graphicsEffect->isEnabled())
613 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
614#endif // QT_CONFIG(graphicseffect)
615 return rect;
616 }
617
618 QSize adjustedSize() const;
619
620 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
621 {
622 Q_Q(QWidget);
623 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
624 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
625 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
626 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
627 QGuiApplication::inputMethod()->show();
628 }
629 }
630 }
631
632 void setWSGeometry();
633
634 inline QPoint mapToWS(const QPoint &p) const
635 { return p - data.wrect.topLeft(); }
636
637 inline QPoint mapFromWS(const QPoint &p) const
638 { return p + data.wrect.topLeft(); }
639
640 inline QRect mapToWS(const QRect &r) const
641 { return r.translated(-data.wrect.topLeft()); }
642
643 inline QRect mapFromWS(const QRect &r) const
644 { return r.translated(data.wrect.topLeft()); }
645
646 QOpenGLContext *shareContext() const;
647
648 virtual QObject *focusObject() { return 0; }
649
650#ifndef QT_NO_OPENGL
651 virtual GLuint textureId() const { return 0; }
652 virtual QPlatformTextureList::Flags textureListFlags() {
653 Q_Q(QWidget);
654 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
655 ? QPlatformTextureList::StacksOnTop
656 : QPlatformTextureList::Flags(0);
657 }
658 virtual QImage grabFramebuffer() { return QImage(); }
659 virtual void beginBackingStorePainting() { }
660 virtual void endBackingStorePainting() { }
661 virtual void beginCompose() { }
662 virtual void endCompose() { }
663 void setRenderToTexture() { renderToTexture = true; setTextureChildSeen(); }
664 void setTextureChildSeen()
665 {
666 Q_Q(QWidget);
667 if (textureChildSeen)
668 return;
669 textureChildSeen = 1;
670
671 if (!q->isWindow()) {
672 QWidget *parent = q->parentWidget();
673 if (parent)
674 get(parent)->setTextureChildSeen();
675 }
676 }
677 static void sendComposeStatus(QWidget *w, bool end);
678 // Called on setViewport().
679 virtual void initializeViewportFramebuffer() { }
680 // When using a QOpenGLWidget as viewport with QAbstractScrollArea, resize events are
681 // filtered away from the widget. This is fine for QGLWidget but bad for QOpenGLWidget
682 // since the fbo must be resized. We need an alternative way to notify.
683 virtual void resizeViewportFramebuffer() { }
684 // Called after each paint event.
685 virtual void resolveSamples() { }
686#endif
687
688 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
689
690 // Variables.
691 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
692 QWExtra *extra;
693 QWidget *focus_next;
694 QWidget *focus_prev;
695 QWidget *focus_child;
696 QLayout *layout;
697 QRegion *needsFlush;
698 QPaintDevice *redirectDev;
699 QWidgetItemV2 *widgetItem;
700 QPaintEngine *extraPaintEngine;
701 mutable const QMetaObject *polished;
702 QGraphicsEffect *graphicsEffect;
703 // All widgets are added into the allWidgets set. Once
704 // they receive a window id they are also added to the mapper.
705 // This should just ensure that all widgets are deleted by QApplication
706 static QWidgetMapper *mapper;
707 static QWidgetSet *allWidgets;
708#if !defined(QT_NO_IM)
709 Qt::InputMethodHints imHints;
710#endif
711#ifdef QT_KEYPAD_NAVIGATION
712 static QPointer<QWidget> editingWidget;
713#endif
714
715 // Implicit pointers (shared_null/shared_empty).
716 QRegion opaqueChildren;
717 QRegion dirty;
718#ifndef QT_NO_TOOLTIP
719 QString toolTip;
720 int toolTipDuration;
721#endif
722#if QT_CONFIG(statustip)
723 QString statusTip;
724#endif
725#if QT_CONFIG(whatsthis)
726 QString whatsThis;
727#endif
728#ifndef QT_NO_ACCESSIBILITY
729 QString accessibleName;
730 QString accessibleDescription;
731#endif
732
733 // Other variables.
734 uint directFontResolveMask;
735 uint inheritedFontResolveMask;
736 uint inheritedPaletteResolveMask;
737 short leftmargin;
738 short topmargin;
739 short rightmargin;
740 short bottommargin;
741 signed char leftLayoutItemMargin;
742 signed char topLayoutItemMargin;
743 signed char rightLayoutItemMargin;
744 signed char bottomLayoutItemMargin;
745 static int instanceCounter; // Current number of widget instances
746 static int maxInstances; // Maximum number of widget instances
747 Qt::HANDLE hd;
748 QWidgetData data;
749 QSizePolicy size_policy;
750 QLocale locale;
751 QPoint redirectOffset;
752#ifndef QT_NO_ACTION
753 QList<QAction*> actions;
754#endif
755#ifndef QT_NO_GESTURES
756 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
757#endif
758
759 // Bit fields.
760 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
761 QPalette::ColorRole fg_role : 8;
762 QPalette::ColorRole bg_role : 8;
763 uint dirtyOpaqueChildren : 1;
764 uint isOpaque : 1;
765 uint retainSizeWhenHiddenChanged : 1;
766 uint inDirtyList : 1;
767 uint isScrolled : 1;
768 uint isMoved : 1;
769 uint usesDoubleBufferedGLContext : 1;
770 uint mustHaveWindowHandle : 1;
771 uint renderToTexture : 1;
772 uint textureChildSeen : 1;
773#ifndef QT_NO_IM
774 uint inheritsInputMethodHints : 1;
775#endif
776#ifndef QT_NO_OPENGL
777 uint renderToTextureReallyDirty : 1;
778 uint renderToTextureComposeActive : 1;
779#endif
780 uint childrenHiddenByWState : 1;
781 uint childrenShownByExpose : 1;
782
783 // *************************** Platform specific ************************************
784#if defined(Q_OS_WIN)
785 uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
786#endif
787#if 0 /* Used to be included in Qt4 for Q_WS_X11 */ // <----------------------------------------------------------- X11
788 Qt::HANDLE picture;
789 static QWidget *mouseGrabber;
790 static QWidget *keyboardGrabber;
791
792 void setWindowRole();
793 void sendStartupMessage(const char *message) const;
794 void x11UpdateIsOpaque();
795 bool isBackgroundInherited() const;
796 void updateX11AcceptFocus();
797 QPoint mapToGlobal(const QPoint &pos) const;
798 QPoint mapFromGlobal(const QPoint &pos) const;
799#elif 0 /* Used to be included in Qt4 for Q_WS_WIN */ // <--------------------------------------------------------- WIN
800#ifndef QT_NO_GESTURES
801 uint nativeGesturePanEnabled : 1;
802#endif
803 bool shouldShowMaximizeButton();
804 void winUpdateIsOpaque();
805 void reparentChildren();
806#if QT_CONFIG(draganddrop)
807 QOleDropTarget *registerOleDnd(QWidget *widget);
808 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
809#endif
810 void grabMouseWhileInWindow();
811 void registerTouchWindow();
812 void winSetupGestures();
813#elif defined(Q_OS_MAC) // <--------------------------------------------------------- MAC
814 void macUpdateSizeAttribute();
815#elif 0 /* Used to be included in Qt4 for Q_WS_MAC */ // <--------------------------------------------------------- MAC (old stuff)
816 // This is new stuff
817 uint needWindowChange : 1;
818
819 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
820 // This list is used to update the gl context whenever a parent and a granparent
821 // moves, and also to check for intersections with gl widgets within the window
822 // when a widget moves.
823 struct GlWidgetInfo
824 {
825 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
826 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
827 QWidget * widget;
828 QWidget * lastUpdateWidget;
829 };
830
831 // dirtyOnWidget contains the areas in the widget that needs to be repained,
832 // in the same way as dirtyOnScreen does for the window. Areas are added in
833 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
834 // this information repaint invalid areas when widgets are scrolled.
835 QRegion dirtyOnWidget;
836 EventHandlerRef window_event;
837 QList<GlWidgetInfo> glWidgets;
838
839 //these are here just for code compat (HIViews)
840 Qt::HANDLE qd_hd;
841
842 void macUpdateHideOnSuspend();
843 void macUpdateOpaqueSizeGrip();
844 void macUpdateIgnoreMouseEvents();
845 void macUpdateMetalAttribute();
846 void macUpdateIsOpaque();
847 void macSetNeedsDisplay(QRegion region);
848 void setEnabled_helper_sys(bool enable);
849 bool isRealWindow() const;
850 void adjustWithinMaxAndMinSize(int &w, int &h);
851 void applyMaxAndMinSizeOnWindow();
852 void update_sys(const QRect &rect);
853 void update_sys(const QRegion &rgn);
854 void setGeometry_sys_helper(int, int, int, int, bool);
855 void updateMaximizeButton_sys();
856 void createWindow_sys();
857 void recreateMacWindow();
858 void setSubWindowStacking(bool set);
859 void setWindowLevel();
860 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
861 void syncCocoaMask();
862 void finishCocoaMaskSetup();
863 // Did we add the drawRectOriginal method?
864 bool drawRectOriginalAdded;
865 // Is the original drawRect method available?
866 bool originalDrawMethod;
867 // Do we need to change the methods?
868 bool changeMethods;
869
870 // Unified toolbar variables
871 bool isInUnifiedToolbar;
872 QUnifiedToolbarSurface *unifiedSurface;
873 QPoint toolbar_offset;
874 QWidget *toolbar_ancestor;
875 bool flushRequested;
876 bool touchEventsEnabled;
877 void determineWindowClass();
878 void transferChildren();
879 bool qt_mac_dnd_event(uint, DragRef);
880 void toggleDrawers(bool);
881 //mac event functions
882 static bool qt_create_root_win();
883 static void qt_clean_root_win();
884 static bool qt_mac_update_sizer(QWidget *, int up = 0);
885 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
886 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
887 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
888 void registerTouchWindow(bool enable = true);
889#endif
890 void setNetWmWindowTypes(bool skipIfMissing = false);
891
892 bool stealKeyboardGrab(bool grab);
893 bool stealMouseGrab(bool grab);
894};
895
896struct QWidgetPaintContext
897{
898 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
899 QPainter *p, QWidgetBackingStore *b)
900 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
901
902 QPaintDevice *pdev;
903 QRegion rgn;
904 QPoint offset;
905 int flags;
906 QPainter *sharedPainter;
907 QWidgetBackingStore *backingStore;
908 QPainter *painter;
909};
910
911#if QT_CONFIG(graphicseffect)
912class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
913{
914public:
915 QWidgetEffectSourcePrivate(QWidget *widget)
916 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
917 {}
918
919 void detach() override
920 { m_widget->d_func()->graphicsEffect = 0; }
921
922 const QGraphicsItem *graphicsItem() const override
923 { return 0; }
924
925 const QWidget *widget() const override
926 { return m_widget; }
927
928 void update() override
929 {
930 updateDueToGraphicsEffect = true;
931 m_widget->update();
932 updateDueToGraphicsEffect = false;
933 }
934
935 bool isPixmap() const override
936 { return false; }
937
938 void effectBoundingRectChanged() override
939 {
940 // ### This function should take a rect parameter; then we can avoid
941 // updating too much on the parent widget.
942 if (QWidget *parent = m_widget->parentWidget())
943 parent->update();
944 else
945 update();
946 }
947
948 const QStyleOption *styleOption() const override
949 { return 0; }
950
951 QRect deviceRect() const override
952 { return m_widget->window()->rect(); }
953
954 QRectF boundingRect(Qt::CoordinateSystem system) const override;
955 void draw(QPainter *p) override;
956 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
957 QGraphicsEffect::PixmapPadMode mode) const override;
958
959 QWidget *m_widget;
960 QWidgetPaintContext *context;
961 QTransform lastEffectTransform;
962 bool updateDueToGraphicsEffect;
963};
964#endif // QT_CONFIG(graphicseffect)
965
966inline QWExtra *QWidgetPrivate::extraData() const
967{
968 return extra;
969}
970
971inline QTLWExtra *QWidgetPrivate::topData() const
972{
973 const_cast<QWidgetPrivate *>(this)->createTLExtra();
974 return extra->topextra;
975}
976
977inline QTLWExtra *QWidgetPrivate::maybeTopData() const
978{
979 return extra ? extra->topextra : 0;
980}
981
982inline QPainter *QWidgetPrivate::sharedPainter() const
983{
984 Q_Q(const QWidget);
985 QTLWExtra *x = q->window()->d_func()->maybeTopData();
986 return x ? x->sharedPainter : 0;
987}
988
989inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
990{
991 Q_Q(QWidget);
992 QTLWExtra *x = q->window()->d_func()->topData();
993 x->sharedPainter = painter;
994}
995
996inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
997{
998 Q_Q(const QWidget);
999 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
1000 || extra->mask.contains(p));
1001}
1002
1003inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
1004{
1005 Q_Q(const QWidget);
1006 QTLWExtra *x = q->window()->d_func()->maybeTopData();
1007 return x ? x->backingStoreTracker.data() : 0;
1008}
1009
1010inline QWidgetWindow *QWidgetPrivate::windowHandle() const
1011{
1012 if (QTLWExtra *x = maybeTopData())
1013 return x->window;
1014 return nullptr;
1015}
1016
1017QT_END_NAMESPACE
1018
1019#endif // QWIDGET_P_H
1020