1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
56 #include "QtWidgets/qwidget.h"
57 #include "private/qobject_p.h"
58 #include "QtCore/qrect.h"
59 #include "QtCore/qlocale.h"
60 #include "QtCore/qset.h"
61 #include "QtGui/qregion.h"
62 #include "QtGui/qinputmethod.h"
63 #include "QtWidgets/qsizepolicy.h"
64 #include "QtWidgets/qstyle.h"
65 #include "QtWidgets/qapplication.h"
66 #include <private/qgraphicseffect_p.h>
67 #include "QtWidgets/qgraphicsproxywidget.h"
68 #include "QtWidgets/qgraphicsscene.h"
69 #include "QtWidgets/qgraphicsview.h"
70 #include <private/qgesture_p.h>
75 // - to minimize memory usage for members that are seldom used.
76 // - top-level widgets have extra extra data to reduce cost further
80 class QWidgetBackingStore;
81 class QGraphicsProxyWidget;
86 class QUnifiedToolbarSurface;
88 // implemented in qshortcut.cpp
89 bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context);
92 class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker
96 QWidgetBackingStoreTracker();
97 ~QWidgetBackingStoreTracker();
99 void create(QWidget *tlw);
102 void registerWidget(QWidget *w);
103 void unregisterWidget(QWidget *w);
104 void unregisterWidgetSubtree(QWidget *w);
106 inline QWidgetBackingStore* data()
111 inline QWidgetBackingStore* operator->()
116 inline QWidgetBackingStore& operator*()
121 inline operator bool() const
127 Q_DISABLE_COPY(QWidgetBackingStoreTracker)
130 QWidgetBackingStore* m_ptr;
131 QSet<QWidget *> m_widgets;
135 // *************************** Cross-platform variables *****************************
137 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
138 QIcon *icon; // widget icon
140 QWidgetBackingStoreTracker backingStoreTracker;
141 QBackingStore *backingStore;
142 QPainter *sharedPainter;
144 // Implicit pointers (shared_null).
145 QString caption; // widget caption
146 QString iconText; // widget icon text
147 QString role; // widget role
148 QString filePath; // widget file path
151 short incw, inch; // size increments
152 short basew, baseh; // base sizes
153 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
155 QRect normalGeometry; // used by showMin/maximized/FullScreen
156 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
158 // *************************** Cross-platform bit fields ****************************
160 uint posFromMove : 1;
161 uint sizeAdjusted : 1;
162 uint inTopLevelResize : 1;
166 // *************************** Platform specific values (bit fields first) **********
167 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
168 uint spont_unmapped: 1; // window was spontaneously unmapped
169 uint dnd : 1; // DND properties installed
170 uint validWMState : 1; // is WM_STATE valid?
171 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
172 WId parentWinId; // parent window Id (valid after reparenting)
173 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
174 QPoint fullScreenOffset;
176 WId syncUpdateCounter;
177 ulong syncRequestTimestamp;
178 qint32 newCounterValueHi;
179 quint32 newCounterValueLo;
181 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
182 uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered.
183 HICON winIconBig; // internal big Windows icon
184 HICON winIconSmall; // internal small Windows icon
185 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
187 uint isSetGeometry : 1;
191 WindowGroupRef group;
192 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
193 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
194 // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and
196 // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the
197 // starting position as 0,0 instead of the normal starting position.
200 QWidgetWindow *window;
201 quint32 screenIndex; // index in qplatformscreenlist
205 // *************************** Cross-platform variables *****************************
207 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
208 void *glContext; // if the widget is hijacked by QGLWindowSurface
209 QTLWExtra *topextra; // only useful for TLWs
210 #ifndef QT_NO_GRAPHICSVIEW
211 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
216 QPointer<QStyle> style;
217 QPointer<QWidget> focus_proxy;
219 // Implicit pointers (shared_empty/shared_null).
220 QRegion mask; // widget mask
225 qint32 minh; // minimum size
227 qint32 maxh; // maximum size
230 QSize staticContentsSize;
232 // *************************** Cross-platform bit fields ****************************
233 uint explicitMinSize : 2;
234 uint explicitMaxSize : 2;
235 uint autoFillBackground : 1;
236 uint nativeChildrenForced : 1;
237 uint inRenderWithPainter : 1;
240 // *************************** Platform specific values (bit fields first) **********
241 #if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
242 #ifndef QT_NO_DRAGANDDROP
243 QOleDropTarget *dropTarget; // drop target
244 QList<QPointer<QWidget> > oleDropWidgets;
246 #elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
247 uint compress_events : 1;
248 WId xDndProxy; // XDND forwarding to embedded windows
249 #elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
252 CGImageRef imageMask;
259 Returns true if \a p or any of its parents enable the
260 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
261 QWidget::setParent() to determine whether it's necessary to embed the
262 widget into a QGraphicsProxyWidget or not.
264 static inline bool bypassGraphicsProxyWidget(const QWidget *p)
267 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
269 p = p->parentWidget();
274 class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
276 Q_DECLARE_PUBLIC(QWidget)
279 // *************************** Cross-platform ***************************************
280 enum DrawWidgetFlags {
282 DrawPaintOnScreen = 0x02,
283 DrawRecursive = 0x04,
284 DrawInvisible = 0x08,
285 DontSubtractOpaqueChildren = 0x10,
286 DontDrawOpaqueChildren = 0x20,
287 DontDrawNativeChildren = 0x40,
288 DontSetCompositionMode = 0x80
294 CloseWithSpontaneousEvent
298 DirectionNorth = 0x01,
299 DirectionEast = 0x10,
300 DirectionSouth = 0x02,
305 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
308 QWExtra *extraData() const;
309 QTLWExtra *topData() const;
310 QTLWExtra *maybeTopData() const;
311 QPainter *sharedPainter() const;
312 void setSharedPainter(QPainter *painter);
313 QWidgetBackingStore *maybeBackingStore() const;
314 void init(QWidget *desktopWidget, Qt::WindowFlags f);
315 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
316 void createRecursively();
317 void createWinId(WId id = 0);
319 void createTLExtra();
322 void createSysExtra();
323 void deleteSysExtra();
324 void createTLSysExtra();
325 void deleteTLSysExtra();
326 void updateSystemBackground();
327 void propagatePaletteChange();
329 void setPalette_helper(const QPalette &);
330 void resolvePalette();
331 QPalette naturalWidgetPalette(uint inheritedMask) const;
333 void setMask_sys(const QRegion &);
337 void stackUnder_sys(QWidget *);
340 void updateFocusChild();
342 void updateFont(const QFont &);
343 inline void setFont_helper(const QFont &font) {
344 if (data.fnt == font && data.fnt.resolve() == font.resolve())
349 QFont naturalWidgetFont(uint inheritedMask) const;
351 void setLayoutDirection_helper(Qt::LayoutDirection);
352 void resolveLayoutDirection();
354 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
355 void resolveLocale();
357 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
360 void setUpdatesEnabled_helper(bool );
362 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
363 bool isAboutToShow() const;
364 QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags);
365 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
366 QWidget::RenderFlags renderFlags);
367 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
368 QWidget::RenderFlags renderFlags, bool readyToRender);
369 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
370 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
373 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
374 const QRegion &rgn, const QPoint &offset, int flags,
375 QPainter *sharedPainter, QWidgetBackingStore *backingStore);
378 QPainter *beginSharedPainter();
379 bool endSharedPainter();
380 #ifndef QT_NO_GRAPHICSVIEW
381 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
383 void repaint_sys(const QRegion &rgn);
385 QRect clipRect() const;
386 QRegion clipRegion() const;
387 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
388 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
389 bool alsoNonOpaque = false) const;
390 void clipToEffectiveMask(QRegion ®ion) const;
391 void updateIsOpaque();
392 void setOpaque(bool opaque);
393 void updateIsTranslucent();
394 bool paintOnScreen() const;
395 #ifndef QT_NO_GRAPHICSEFFECT
396 void invalidateGraphicsEffectsRecursively();
397 #endif //QT_NO_GRAPHICSEFFECT
399 const QRegion &getOpaqueChildren() const;
400 void setDirtyOpaqueRegion();
402 bool close_helper(CloseMode mode);
404 void setWindowIcon_helper();
405 void setWindowIcon_sys(bool forceReset = false);
406 void setWindowOpacity_sys(qreal opacity);
407 void adjustQuitOnCloseAttribute();
409 void scrollChildren(int dx, int dy);
410 void moveRect(const QRect &, int dx, int dy);
411 void scrollRect(const QRect &, int dx, int dy);
412 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
413 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
414 void invalidateBuffer(const QRegion &);
415 void invalidateBuffer(const QRect &);
416 bool isOverlapped(const QRect&) const;
417 void syncBackingStore();
418 void syncBackingStore(const QRegion ®ion);
420 // tells the input method about the widgets transform
421 void updateWidgetTransform();
423 void reparentFocusWidgets(QWidget *oldtlw);
425 static int pointToRect(const QPoint &p, const QRect &r);
428 void showChildren(bool spontaneous);
429 void hideChildren(bool spontaneous);
430 void setParent_sys(QWidget *parent, Qt::WindowFlags);
431 void scroll_sys(int dx, int dy);
432 void scroll_sys(int dx, int dy, const QRect &r);
433 void deactivateWidgetCleanup();
434 void setGeometry_sys(int, int, int, int, bool);
435 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
436 void activateChildLayoutsRecursively();
437 void show_recursive();
442 void _q_showIfNotHidden();
444 void setEnabled_helper(bool);
445 void registerDropSite(bool);
446 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
448 void updateFrameStrut();
449 QRect frameStrut() const;
451 #ifdef QT_KEYPAD_NAVIGATION
452 static bool navigateToDirection(Direction direction);
453 static QWidget *widgetInNavigationDirection(Direction direction);
454 static bool canKeypadNavigate(Qt::Orientation orientation);
455 static bool inTabWidget(QWidget *widget);
458 void setWindowIconText_sys(const QString &cap);
459 void setWindowIconText_helper(const QString &cap);
460 void setWindowTitle_sys(const QString &cap);
463 void setCursor_sys(const QCursor &cursor);
464 void unsetCursor_sys();
467 void setWindowTitle_helper(const QString &cap);
468 void setWindowFilePath_helper(const QString &filePath);
470 bool setMinimumSize_helper(int &minw, int &minh);
471 bool setMaximumSize_helper(int &maxw, int &maxh);
472 void setConstraints_sys();
473 bool pointInsideRectAndMask(const QPoint &) const;
474 QWidget *childAt_helper(const QPoint &, bool) const;
475 QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
476 void updateGeometry_helper(bool forceUpdate);
478 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
479 void setLayoutItemMargins(int left, int top, int right, int bottom);
480 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
482 // aboutToDestroy() is called just before the contents of
483 // QWidget::destroy() is executed. It's used to signal QWidget
484 // sub-classes that their internals are about to be released.
485 virtual void aboutToDestroy() {}
487 inline QWidget *effectiveFocusWidget() {
488 QWidget *w = q_func();
489 while (w->focusProxy())
496 // This is an helper function that return the available geometry for
497 // a widget and takes care is this one is in QGraphicsView.
498 // If the widget is not embed in a scene then the geometry available is
499 // null, we let QDesktopWidget decide for us.
500 static QRect screenGeometry(const QWidget *widget)
503 #ifndef QT_NO_GRAPHICSVIEW
504 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
505 //It's embedded if it has an ancestor
507 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
508 // One view, let be smart and return the viewport rect then the popup is aligned
509 if (ancestorProxy->scene()->views().size() == 1) {
510 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
511 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
513 screen = ancestorProxy->scene()->sceneRect().toRect();
521 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
523 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
524 redirectDev = replacement;
525 redirectOffset = offset;
528 inline QPaintDevice *redirected(QPoint *offset) const
531 *offset = redirectDev ? redirectOffset : QPoint();
535 inline void restoreRedirected()
538 inline void enforceNativeChildren()
543 if (extra->nativeChildrenForced)
545 extra->nativeChildrenForced = 1;
547 for (int i = 0; i < children.size(); ++i) {
548 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
549 child->setAttribute(Qt::WA_NativeWindow);
553 inline bool nativeChildrenForced() const
555 return extra ? extra->nativeChildrenForced : false;
558 inline QRect effectiveRectFor(const QRect &rect) const
560 #ifndef QT_NO_GRAPHICSEFFECT
561 if (graphicsEffect && graphicsEffect->isEnabled())
562 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
563 #endif //QT_NO_GRAPHICSEFFECT
567 QSize adjustedSize() const;
569 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
572 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
573 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
574 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
575 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
576 qApp->inputMethod()->show();
581 void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
583 inline QPoint mapToWS(const QPoint &p) const
584 { return p - data.wrect.topLeft(); }
586 inline QPoint mapFromWS(const QPoint &p) const
587 { return p + data.wrect.topLeft(); }
589 inline QRect mapToWS(const QRect &r) const
590 { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
592 inline QRect mapFromWS(const QRect &r) const
593 { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
596 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
600 QWidget *focus_child;
603 QPaintDevice *redirectDev;
604 QWidgetItemV2 *widgetItem;
605 QPaintEngine *extraPaintEngine;
606 mutable const QMetaObject *polished;
607 QGraphicsEffect *graphicsEffect;
608 // All widgets are added into the allWidgets set. Once
609 // they receive a window id they are also added to the mapper.
610 // This should just ensure that all widgets are deleted by QApplication
611 static QWidgetMapper *mapper;
612 static QWidgetSet *allWidgets;
613 #if !defined(QT_NO_IM)
614 Qt::InputMethodHints imHints;
616 #ifdef QT_KEYPAD_NAVIGATION
617 static QPointer<QWidget> editingWidget;
620 // Implicit pointers (shared_null/shared_empty).
621 QRegion opaqueChildren;
623 #ifndef QT_NO_TOOLTIP
626 #ifndef QT_NO_STATUSTIP
629 #ifndef QT_NO_WHATSTHIS
632 #ifndef QT_NO_ACCESSIBILITY
633 QString accessibleName;
634 QString accessibleDescription;
638 uint inheritedFontResolveMask;
639 uint inheritedPaletteResolveMask;
644 signed char leftLayoutItemMargin;
645 signed char topLayoutItemMargin;
646 signed char rightLayoutItemMargin;
647 signed char bottomLayoutItemMargin;
648 static int instanceCounter; // Current number of widget instances
649 static int maxInstances; // Maximum number of widget instances
652 QSizePolicy size_policy;
654 QPoint redirectOffset;
656 QList<QAction*> actions;
658 #ifndef QT_NO_GESTURES
659 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
663 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
664 QPalette::ColorRole fg_role : 8;
665 QPalette::ColorRole bg_role : 8;
666 uint dirtyOpaqueChildren : 1;
668 uint inDirtyList : 1;
672 uint usesDoubleBufferedGLContext : 1;
674 uint inheritsInputMethodHints : 1;
676 uint inSetParent : 1;
678 // *************************** Platform specific ************************************
679 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
681 static QWidget *mouseGrabber;
682 static QWidget *keyboardGrabber;
684 void setWindowRole();
685 void sendStartupMessage(const char *message) const;
686 void setNetWmWindowTypes();
687 void x11UpdateIsOpaque();
688 bool isBackgroundInherited() const;
689 void updateX11AcceptFocus();
690 QPoint mapToGlobal(const QPoint &pos) const;
691 QPoint mapFromGlobal(const QPoint &pos) const;
692 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
693 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
694 #ifndef QT_NO_GESTURES
695 uint nativeGesturePanEnabled : 1;
697 bool shouldShowMaximizeButton();
698 void winUpdateIsOpaque();
699 void reparentChildren();
700 #ifndef QT_NO_DRAGANDDROP
701 QOleDropTarget *registerOleDnd(QWidget *widget);
702 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
704 void grabMouseWhileInWindow();
705 void registerTouchWindow();
706 void winSetupGestures();
707 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
709 uint needWindowChange : 1;
711 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
712 // This list is used to update the gl context whenever a parent and a granparent
713 // moves, and also to check for intersections with gl widgets within the window
714 // when a widget moves.
717 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
718 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
720 QWidget * lastUpdateWidget;
723 // dirtyOnWidget contains the areas in the widget that needs to be repained,
724 // in the same way as dirtyOnScreen does for the window. Areas are added in
725 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
726 // this information repaint invalid areas when widgets are scrolled.
727 QRegion dirtyOnWidget;
728 EventHandlerRef window_event;
729 QList<GlWidgetInfo> glWidgets;
731 //these are here just for code compat (HIViews)
734 void macUpdateSizeAttribute();
735 void macUpdateHideOnSuspend();
736 void macUpdateOpaqueSizeGrip();
737 void macUpdateIgnoreMouseEvents();
738 void macUpdateMetalAttribute();
739 void macUpdateIsOpaque();
740 void macSetNeedsDisplay(QRegion region);
741 void setEnabled_helper_sys(bool enable);
742 bool isRealWindow() const;
743 void adjustWithinMaxAndMinSize(int &w, int &h);
744 void applyMaxAndMinSizeOnWindow();
745 void update_sys(const QRect &rect);
746 void update_sys(const QRegion &rgn);
747 void setGeometry_sys_helper(int, int, int, int, bool);
748 void setWindowModified_sys(bool b);
749 void updateMaximizeButton_sys();
750 void setWindowFilePath_sys(const QString &filePath);
751 void createWindow_sys();
752 void recreateMacWindow();
753 void setSubWindowStacking(bool set);
754 void setWindowLevel();
755 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
756 void syncCocoaMask();
757 void finishCocoaMaskSetup();
758 void syncUnifiedMode();
759 // Did we add the drawRectOriginal method?
760 bool drawRectOriginalAdded;
761 // Is the original drawRect method available?
762 bool originalDrawMethod;
763 // Do we need to change the methods?
766 // Unified toolbar variables
767 bool isInUnifiedToolbar;
768 QUnifiedToolbarSurface *unifiedSurface;
769 QPoint toolbar_offset;
770 QWidget *toolbar_ancestor;
772 bool touchEventsEnabled;
773 void determineWindowClass();
774 void transferChildren();
775 bool qt_mac_dnd_event(uint, DragRef);
776 void toggleDrawers(bool);
777 //mac event functions
778 static bool qt_create_root_win();
779 static void qt_clean_root_win();
780 static bool qt_mac_update_sizer(QWidget *, int up = 0);
781 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
782 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
783 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
784 void registerTouchWindow(bool enable = true);
786 void setMaxWindowState_helper();
787 void setFullScreenSize_helper();
788 bool stealKeyboardGrab(bool grab);
789 bool stealMouseGrab(bool grab);
792 struct QWidgetPaintContext
794 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
795 QPainter *p, QWidgetBackingStore *b)
796 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
802 QPainter *sharedPainter;
803 QWidgetBackingStore *backingStore;
807 #ifndef QT_NO_GRAPHICSEFFECT
808 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
811 QWidgetEffectSourcePrivate(QWidget *widget)
812 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
816 { m_widget->d_func()->graphicsEffect = 0; }
818 inline const QGraphicsItem *graphicsItem() const
821 inline const QWidget *widget() const
826 updateDueToGraphicsEffect = true;
828 updateDueToGraphicsEffect = false;
831 inline bool isPixmap() const
834 inline void effectBoundingRectChanged()
836 // ### This function should take a rect parameter; then we can avoid
837 // updating too much on the parent widget.
838 if (QWidget *parent = m_widget->parentWidget())
844 inline const QStyleOption *styleOption() const
847 inline QRect deviceRect() const
848 { return m_widget->window()->rect(); }
850 QRectF boundingRect(Qt::CoordinateSystem system) const;
851 void draw(QPainter *p);
852 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
853 QGraphicsEffect::PixmapPadMode mode) const;
856 QWidgetPaintContext *context;
857 QTransform lastEffectTransform;
858 bool updateDueToGraphicsEffect;
860 #endif //QT_NO_GRAPHICSEFFECT
862 inline QWExtra *QWidgetPrivate::extraData() const
867 inline QTLWExtra *QWidgetPrivate::topData() const
869 const_cast<QWidgetPrivate *>(this)->createTLExtra();
870 return extra->topextra;
873 inline QTLWExtra *QWidgetPrivate::maybeTopData() const
875 return extra ? extra->topextra : 0;
878 inline QPainter *QWidgetPrivate::sharedPainter() const
881 QTLWExtra *x = q->window()->d_func()->maybeTopData();
882 return x ? x->sharedPainter : 0;
885 inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
888 QTLWExtra *x = q->window()->d_func()->topData();
889 x->sharedPainter = painter;
892 inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
895 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
896 || extra->mask.contains(p));
899 inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
902 QTLWExtra *x = q->window()->d_func()->maybeTopData();
903 return x ? x->backingStoreTracker.data() : 0;
908 #endif // QWIDGET_P_H