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