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