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