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