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