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