Merge remote-tracking branch 'gerrit/master' into containers
[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 posFromMove : 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     };
289
290     enum CloseMode {
291         CloseNoEvent,
292         CloseWithEvent,
293         CloseWithSpontaneousEvent
294     };
295
296     enum Direction {
297         DirectionNorth = 0x01,
298         DirectionEast = 0x10,
299         DirectionSouth = 0x02,
300         DirectionWest = 0x20
301     };
302
303     // Functions.
304     explicit QWidgetPrivate(int version = QObjectPrivateVersion);
305     ~QWidgetPrivate();
306
307     QWExtra *extraData() const;
308     QTLWExtra *topData() const;
309     QTLWExtra *maybeTopData() const;
310     QPainter *sharedPainter() const;
311     void setSharedPainter(QPainter *painter);
312     QWidgetBackingStore *maybeBackingStore() const;
313     void init(QWidget *desktopWidget, Qt::WindowFlags f);
314     void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
315     void createRecursively();
316     void createWinId(WId id = 0);
317
318     void createTLExtra();
319     void createExtra();
320     void deleteExtra();
321     void createSysExtra();
322     void deleteSysExtra();
323     void createTLSysExtra();
324     void deleteTLSysExtra();
325     void updateSystemBackground();
326     void propagatePaletteChange();
327
328     void setPalette_helper(const QPalette &);
329     void resolvePalette();
330     QPalette naturalWidgetPalette(uint inheritedMask) const;
331
332     void setMask_sys(const QRegion &);
333
334     void raise_sys();
335     void lower_sys();
336     void stackUnder_sys(QWidget *);
337
338     void setFocus_sys();
339
340     void updateFont(const QFont &);
341     inline void setFont_helper(const QFont &font) {
342         if (data.fnt == font && data.fnt.resolve() == font.resolve())
343             return;
344         updateFont(font);
345     }
346     void resolveFont();
347     QFont naturalWidgetFont(uint inheritedMask) const;
348
349     void setLayoutDirection_helper(Qt::LayoutDirection);
350     void resolveLayoutDirection();
351
352     void setLocale_helper(const QLocale &l, bool forceUpdate = false);
353     void resolveLocale();
354
355     void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
356     void inheritStyle();
357
358     void setUpdatesEnabled_helper(bool );
359
360     void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
361     bool isAboutToShow() const;
362     QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
363     void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
364                        QWidget::RenderFlags renderFlags);
365     void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
366                 QWidget::RenderFlags renderFlags, bool readyToRender);
367     void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
368                     QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
369
370
371     void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
372                                 const QRegion &rgn, const QPoint &offset, int flags,
373                                 QPainter *sharedPainter, QWidgetBackingStore *backingStore);
374
375
376     QPainter *beginSharedPainter();
377     bool endSharedPainter();
378 #ifndef QT_NO_GRAPHICSVIEW
379     static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
380 #endif
381     void repaint_sys(const QRegion &rgn);
382
383     QRect clipRect() const;
384     QRegion clipRegion() const;
385     void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
386     void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
387                                 bool alsoNonOpaque = false) const;
388     void clipToEffectiveMask(QRegion &region) const;
389     void updateIsOpaque();
390     void setOpaque(bool opaque);
391     void updateIsTranslucent();
392     bool paintOnScreen() const;
393 #ifndef QT_NO_GRAPHICSEFFECT
394     void invalidateGraphicsEffectsRecursively();
395 #endif //QT_NO_GRAPHICSEFFECT
396
397     const QRegion &getOpaqueChildren() const;
398     void setDirtyOpaqueRegion();
399
400     bool close_helper(CloseMode mode);
401
402     void setWindowIcon_helper();
403     void setWindowIcon_sys(bool forceReset = false);
404     void setWindowOpacity_sys(qreal opacity);
405     void adjustQuitOnCloseAttribute();
406
407     void scrollChildren(int dx, int dy);
408     void moveRect(const QRect &, int dx, int dy);
409     void scrollRect(const QRect &, int dx, int dy);
410     void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
411     // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
412     void invalidateBuffer(const QRegion &);
413     void invalidateBuffer(const QRect &);
414     bool isOverlapped(const QRect&) const;
415     void syncBackingStore();
416     void syncBackingStore(const QRegion &region);
417
418     // tells the input method about the widgets transform
419     void updateWidgetTransform();
420
421     void reparentFocusWidgets(QWidget *oldtlw);
422
423     static int pointToRect(const QPoint &p, const QRect &r);
424
425     void setWinId(WId);
426     void showChildren(bool spontaneous);
427     void hideChildren(bool spontaneous);
428     void setParent_sys(QWidget *parent, Qt::WindowFlags);
429     void scroll_sys(int dx, int dy);
430     void scroll_sys(int dx, int dy, const QRect &r);
431     void deactivateWidgetCleanup();
432     void setGeometry_sys(int, int, int, int, bool);
433     void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
434     void activateChildLayoutsRecursively();
435     void show_recursive();
436     void show_helper();
437     void show_sys();
438     void hide_sys();
439     void hide_helper();
440     void _q_showIfNotHidden();
441
442     void setEnabled_helper(bool);
443     void registerDropSite(bool);
444     static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
445
446     void updateFrameStrut();
447     QRect frameStrut() const;
448
449 #ifdef QT_KEYPAD_NAVIGATION
450     static bool navigateToDirection(Direction direction);
451     static QWidget *widgetInNavigationDirection(Direction direction);
452     static bool canKeypadNavigate(Qt::Orientation orientation);
453     static bool inTabWidget(QWidget *widget);
454 #endif
455
456     void setWindowIconText_sys(const QString &cap);
457     void setWindowIconText_helper(const QString &cap);
458     void setWindowTitle_sys(const QString &cap);
459
460 #ifndef QT_NO_CURSOR
461     void setCursor_sys(const QCursor &cursor);
462     void unsetCursor_sys();
463 #endif
464
465     void setWindowTitle_helper(const QString &cap);
466     void setWindowFilePath_helper(const QString &filePath);
467
468     bool setMinimumSize_helper(int &minw, int &minh);
469     bool setMaximumSize_helper(int &maxw, int &maxh);
470     void setConstraints_sys();
471     bool pointInsideRectAndMask(const QPoint &) const;
472     QWidget *childAt_helper(const QPoint &, bool) const;
473     QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
474     void updateGeometry_helper(bool forceUpdate);
475
476     void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
477     void setLayoutItemMargins(int left, int top, int right, int bottom);
478     void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
479
480     // aboutToDestroy() is called just before the contents of
481     // QWidget::destroy() is executed. It's used to signal QWidget
482     // sub-classes that their internals are about to be released.
483     virtual void aboutToDestroy() {}
484
485     inline QWidget *effectiveFocusWidget() {
486         QWidget *w = q_func();
487         while (w->focusProxy())
488             w = w->focusProxy();
489         return w;
490     }
491
492     void setModal_sys();
493
494     // This is an helper function that return the available geometry for
495     // a widget and takes care is this one is in QGraphicsView.
496     // If the widget is not embed in a scene then the geometry available is
497     // null, we let QDesktopWidget decide for us.
498     static QRect screenGeometry(const QWidget *widget)
499     {
500         QRect screen;
501 #ifndef QT_NO_GRAPHICSVIEW
502         QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
503         //It's embedded if it has an ancestor
504         if (ancestorProxy) {
505             if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
506                 // One view, let be smart and return the viewport rect then the popup is aligned
507                 if (ancestorProxy->scene()->views().size() == 1) {
508                     QGraphicsView *view = ancestorProxy->scene()->views().at(0);
509                     screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
510                 } else {
511                     screen = ancestorProxy->scene()->sceneRect().toRect();
512                 }
513             }
514         }
515 #endif
516         return screen;
517     }
518
519     inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
520     {
521         Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
522         redirectDev = replacement;
523         redirectOffset = offset;
524     }
525
526     inline QPaintDevice *redirected(QPoint *offset) const
527     {
528         if (offset)
529             *offset = redirectDev ? redirectOffset : QPoint();
530         return redirectDev;
531     }
532
533     inline void restoreRedirected()
534     { redirectDev = 0; }
535
536     inline void enforceNativeChildren()
537     {
538         if (!extra)
539             createExtra();
540
541         if (extra->nativeChildrenForced)
542             return;
543         extra->nativeChildrenForced = 1;
544
545         for (int i = 0; i < children.size(); ++i) {
546             if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
547                 child->setAttribute(Qt::WA_NativeWindow);
548         }
549     }
550
551     inline bool nativeChildrenForced() const
552     {
553         return extra ? extra->nativeChildrenForced : false;
554     }
555
556     inline QRect effectiveRectFor(const QRect &rect) const
557     {
558 #ifndef QT_NO_GRAPHICSEFFECT
559         if (graphicsEffect && graphicsEffect->isEnabled())
560             return graphicsEffect->boundingRectFor(rect).toAlignedRect();
561 #endif //QT_NO_GRAPHICSEFFECT
562         return rect;
563     }
564
565     QSize adjustedSize() const;
566
567     inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
568     {
569         Q_Q(QWidget);
570         if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
571             QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
572                     q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
573             if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
574                 qApp->inputMethod()->show();
575             }
576         }
577     }
578
579     void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
580
581     inline QPoint mapToWS(const QPoint &p) const
582     { return p - data.wrect.topLeft(); }
583
584     inline QPoint mapFromWS(const QPoint &p) const
585     { return p + data.wrect.topLeft(); }
586
587     inline QRect mapToWS(const QRect &r) const
588     { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
589
590     inline QRect mapFromWS(const QRect &r) const
591     { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
592
593     // Variables.
594     // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
595     QWExtra *extra;
596     QWidget *focus_next;
597     QWidget *focus_prev;
598     QWidget *focus_child;
599     QLayout *layout;
600     QRegion *needsFlush;
601     QPaintDevice *redirectDev;
602     QWidgetItemV2 *widgetItem;
603     QPaintEngine *extraPaintEngine;
604     mutable const QMetaObject *polished;
605     QGraphicsEffect *graphicsEffect;
606     // All widgets are added into the allWidgets set. Once
607     // they receive a window id they are also added to the mapper.
608     // This should just ensure that all widgets are deleted by QApplication
609     static QWidgetMapper *mapper;
610     static QWidgetSet *allWidgets;
611 #if !defined(QT_NO_IM)
612     Qt::InputMethodHints imHints;
613 #endif
614 #ifdef QT_KEYPAD_NAVIGATION
615     static QPointer<QWidget> editingWidget;
616 #endif
617
618     // Implicit pointers (shared_null/shared_empty).
619     QRegion opaqueChildren;
620     QRegion dirty;
621 #ifndef QT_NO_TOOLTIP
622     QString toolTip;
623 #endif
624 #ifndef QT_NO_STATUSTIP
625     QString statusTip;
626 #endif
627 #ifndef QT_NO_WHATSTHIS
628     QString whatsThis;
629 #endif
630 #ifndef QT_NO_ACCESSIBILITY
631     QString accessibleName;
632     QString accessibleDescription;
633 #endif
634
635     // Other variables.
636     uint inheritedFontResolveMask;
637     uint inheritedPaletteResolveMask;
638     short leftmargin;
639     short topmargin;
640     short rightmargin;
641     short bottommargin;
642     signed char leftLayoutItemMargin;
643     signed char topLayoutItemMargin;
644     signed char rightLayoutItemMargin;
645     signed char bottomLayoutItemMargin;
646     static int instanceCounter; // Current number of widget instances
647     static int maxInstances; // Maximum number of widget instances
648     Qt::HANDLE hd;
649     QWidgetData data;
650     QSizePolicy size_policy;
651     QLocale locale;
652     QPoint redirectOffset;
653 #ifndef QT_NO_ACTION
654     QList<QAction*> actions;
655 #endif
656 #ifndef QT_NO_GESTURES
657     QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
658 #endif
659
660     // Bit fields.
661     uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
662     QPalette::ColorRole fg_role : 8;
663     QPalette::ColorRole bg_role : 8;
664     uint dirtyOpaqueChildren : 1;
665     uint isOpaque : 1;
666     uint inDirtyList : 1;
667     uint isScrolled : 1;
668     uint isMoved : 1;
669     uint isGLWidget : 1;
670     uint usesDoubleBufferedGLContext : 1;
671 #ifndef QT_NO_IM
672     uint inheritsInputMethodHints : 1;
673 #endif
674     uint inSetParent : 1;
675
676     // *************************** Platform specific ************************************
677 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
678     Qt::HANDLE picture;
679     static QWidget *mouseGrabber;
680     static QWidget *keyboardGrabber;
681
682     void setWindowRole();
683     void sendStartupMessage(const char *message) const;
684     void setNetWmWindowTypes();
685     void x11UpdateIsOpaque();
686     bool isBackgroundInherited() const;
687     void updateX11AcceptFocus();
688     QPoint mapToGlobal(const QPoint &pos) const;
689     QPoint mapFromGlobal(const QPoint &pos) const;
690 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
691     uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
692 #ifndef QT_NO_GESTURES
693     uint nativeGesturePanEnabled : 1;
694 #endif
695     bool shouldShowMaximizeButton();
696     void winUpdateIsOpaque();
697     void reparentChildren();
698 #ifndef QT_NO_DRAGANDDROP
699     QOleDropTarget *registerOleDnd(QWidget *widget);
700     void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
701 #endif
702     void grabMouseWhileInWindow();
703     void registerTouchWindow();
704     void winSetupGestures();
705 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
706     // This is new stuff
707     uint needWindowChange : 1;
708
709     // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
710     // This list is used to update the gl context whenever a parent and a granparent
711     // moves, and also to check for intersections with gl widgets within the window
712     // when a widget moves.
713     struct GlWidgetInfo
714     {
715         GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
716         bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
717         QWidget * widget;
718         QWidget * lastUpdateWidget;
719     };
720
721     // dirtyOnWidget contains the areas in the widget that needs to be repained,
722     // in the same way as dirtyOnScreen does for the window. Areas are added in
723     // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
724     // this information repaint invalid areas when widgets are scrolled.
725     QRegion dirtyOnWidget;
726     EventHandlerRef window_event;
727     QList<GlWidgetInfo> glWidgets;
728
729     //these are here just for code compat (HIViews)
730     Qt::HANDLE qd_hd;
731
732     void macUpdateSizeAttribute();
733     void macUpdateHideOnSuspend();
734     void macUpdateOpaqueSizeGrip();
735     void macUpdateIgnoreMouseEvents();
736     void macUpdateMetalAttribute();
737     void macUpdateIsOpaque();
738     void macSetNeedsDisplay(QRegion region);
739     void setEnabled_helper_sys(bool enable);
740     bool isRealWindow() const;
741     void adjustWithinMaxAndMinSize(int &w, int &h);
742     void applyMaxAndMinSizeOnWindow();
743     void update_sys(const QRect &rect);
744     void update_sys(const QRegion &rgn);
745     void setGeometry_sys_helper(int, int, int, int, bool);
746     void setWindowModified_sys(bool b);
747     void updateMaximizeButton_sys();
748     void setWindowFilePath_sys(const QString &filePath);
749     void createWindow_sys();
750     void recreateMacWindow();
751     void setSubWindowStacking(bool set);
752     void setWindowLevel();
753     void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
754     void syncCocoaMask();
755     void finishCocoaMaskSetup();
756     void syncUnifiedMode();
757     // Did we add the drawRectOriginal method?
758     bool drawRectOriginalAdded;
759     // Is the original drawRect method available?
760     bool originalDrawMethod;
761     // Do we need to change the methods?
762     bool changeMethods;
763
764     // Unified toolbar variables
765     bool isInUnifiedToolbar;
766     QUnifiedToolbarSurface *unifiedSurface;
767     QPoint toolbar_offset;
768     QWidget *toolbar_ancestor;
769     bool flushRequested;
770     bool touchEventsEnabled;
771     void determineWindowClass();
772     void transferChildren();
773     bool qt_mac_dnd_event(uint, DragRef);
774     void toggleDrawers(bool);
775     //mac event functions
776     static bool qt_create_root_win();
777     static void qt_clean_root_win();
778     static bool qt_mac_update_sizer(QWidget *, int up = 0);
779     static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
780     static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
781     static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
782     void registerTouchWindow(bool enable = true);
783 #endif
784     void setMaxWindowState_helper();
785     void setFullScreenSize_helper();
786     bool stealKeyboardGrab(bool grab);
787     bool stealMouseGrab(bool grab);
788 };
789
790 struct QWidgetPaintContext
791 {
792     inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
793                                QPainter *p, QWidgetBackingStore *b)
794         : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
795
796     QPaintDevice *pdev;
797     QRegion rgn;
798     QPoint offset;
799     int flags;
800     QPainter *sharedPainter;
801     QWidgetBackingStore *backingStore;
802     QPainter *painter;
803 };
804
805 #ifndef QT_NO_GRAPHICSEFFECT
806 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
807 {
808 public:
809     QWidgetEffectSourcePrivate(QWidget *widget)
810         : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
811     {}
812
813     inline void detach()
814     { m_widget->d_func()->graphicsEffect = 0; }
815
816     inline const QGraphicsItem *graphicsItem() const
817     { return 0; }
818
819     inline const QWidget *widget() const
820     { return m_widget; }
821
822     inline void update()
823     {
824         updateDueToGraphicsEffect = true;
825         m_widget->update();
826         updateDueToGraphicsEffect = false;
827     }
828
829     inline bool isPixmap() const
830     { return false; }
831
832     inline void effectBoundingRectChanged()
833     {
834         // ### This function should take a rect parameter; then we can avoid
835         // updating too much on the parent widget.
836         if (QWidget *parent = m_widget->parentWidget())
837             parent->update();
838         else
839             update();
840     }
841
842     inline const QStyleOption *styleOption() const
843     { return 0; }
844
845     inline QRect deviceRect() const
846     { return m_widget->window()->rect(); }
847
848     QRectF boundingRect(Qt::CoordinateSystem system) const;
849     void draw(QPainter *p);
850     QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
851                    QGraphicsEffect::PixmapPadMode mode) const;
852
853     QWidget *m_widget;
854     QWidgetPaintContext *context;
855     QTransform lastEffectTransform;
856     bool updateDueToGraphicsEffect;
857 };
858 #endif //QT_NO_GRAPHICSEFFECT
859
860 inline QWExtra *QWidgetPrivate::extraData() const
861 {
862     return extra;
863 }
864
865 inline QTLWExtra *QWidgetPrivate::topData() const
866 {
867     const_cast<QWidgetPrivate *>(this)->createTLExtra();
868     return extra->topextra;
869 }
870
871 inline QTLWExtra *QWidgetPrivate::maybeTopData() const
872 {
873     return extra ? extra->topextra : 0;
874 }
875
876 inline QPainter *QWidgetPrivate::sharedPainter() const
877 {
878     Q_Q(const QWidget);
879     QTLWExtra *x = q->window()->d_func()->maybeTopData();
880     return x ? x->sharedPainter : 0;
881 }
882
883 inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
884 {
885     Q_Q(QWidget);
886     QTLWExtra *x = q->window()->d_func()->topData();
887     x->sharedPainter = painter;
888 }
889
890 inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
891 {
892     Q_Q(const QWidget);
893     return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
894                                      || extra->mask.contains(p));
895 }
896
897 inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
898 {
899     Q_Q(const QWidget);
900     QTLWExtra *x = q->window()->d_func()->maybeTopData();
901     return x ? x->backingStoreTracker.data() : 0;
902 }
903
904 QT_END_NAMESPACE
905
906 #endif // QWIDGET_P_H