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);
91 class QUpdateLaterEvent : public QEvent
94 explicit QUpdateLaterEvent(const QRegion& paintRegion)
95 : QEvent(UpdateLater), m_region(paintRegion)
103 inline const QRegion ®ion() const { return m_region; }
111 class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker
115 QWidgetBackingStoreTracker();
116 ~QWidgetBackingStoreTracker();
118 void create(QWidget *tlw);
121 void registerWidget(QWidget *w);
122 void unregisterWidget(QWidget *w);
123 void unregisterWidgetSubtree(QWidget *w);
125 inline QWidgetBackingStore* data()
130 inline QWidgetBackingStore* operator->()
135 inline QWidgetBackingStore& operator*()
140 inline operator bool() const
146 Q_DISABLE_COPY(QWidgetBackingStoreTracker)
149 QWidgetBackingStore* m_ptr;
150 QSet<QWidget *> m_widgets;
154 // *************************** Cross-platform variables *****************************
156 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
157 QIcon *icon; // widget icon
158 QWidgetBackingStoreTracker backingStoreTracker;
159 QBackingStore *backingStore;
160 QPainter *sharedPainter;
162 // Implicit pointers (shared_null).
163 QString caption; // widget caption
164 QString iconText; // widget icon text
165 QString role; // widget role
166 QString filePath; // widget file path
169 short incw, inch; // size increments
170 short basew, baseh; // base sizes
171 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
173 QRect normalGeometry; // used by showMin/maximized/FullScreen
174 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
176 // *************************** Cross-platform bit fields ****************************
178 uint posIncludesFrame : 1;
179 uint sizeAdjusted : 1;
180 uint inTopLevelResize : 1;
184 // *************************** Platform specific values (bit fields first) **********
185 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
186 uint spont_unmapped: 1; // window was spontaneously unmapped
187 uint dnd : 1; // DND properties installed
188 uint validWMState : 1; // is WM_STATE valid?
189 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
190 WId parentWinId; // parent window Id (valid after reparenting)
191 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
192 QPoint fullScreenOffset;
194 WId syncUpdateCounter;
195 ulong syncRequestTimestamp;
196 qint32 newCounterValueHi;
197 quint32 newCounterValueLo;
199 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
200 uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered.
201 HICON winIconBig; // internal big Windows icon
202 HICON winIconSmall; // internal small Windows icon
203 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
205 uint isSetGeometry : 1;
209 WindowGroupRef group;
210 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
211 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
212 // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and
214 // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the
215 // starting position as 0,0 instead of the normal starting position.
218 QWidgetWindow *window;
219 quint32 screenIndex; // index in qplatformscreenlist
223 // *************************** Cross-platform variables *****************************
225 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
226 void *glContext; // if the widget is hijacked by QGLWindowSurface
227 QTLWExtra *topextra; // only useful for TLWs
228 #ifndef QT_NO_GRAPHICSVIEW
229 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
234 QPointer<QStyle> style;
235 QPointer<QWidget> focus_proxy;
237 // Implicit pointers (shared_empty/shared_null).
238 QRegion mask; // widget mask
243 qint32 minh; // minimum size
245 qint32 maxh; // maximum size
248 QSize staticContentsSize;
250 // *************************** Cross-platform bit fields ****************************
251 uint explicitMinSize : 2;
252 uint explicitMaxSize : 2;
253 uint autoFillBackground : 1;
254 uint nativeChildrenForced : 1;
255 uint inRenderWithPainter : 1;
258 // *************************** Platform specific values (bit fields first) **********
259 #if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
260 #ifndef QT_NO_DRAGANDDROP
261 QOleDropTarget *dropTarget; // drop target
262 QList<QPointer<QWidget> > oleDropWidgets;
264 #elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
265 uint compress_events : 1;
266 WId xDndProxy; // XDND forwarding to embedded windows
267 #elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
270 CGImageRef imageMask;
277 Returns true if \a p or any of its parents enable the
278 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
279 QWidget::setParent() to determine whether it's necessary to embed the
280 widget into a QGraphicsProxyWidget or not.
282 static inline bool bypassGraphicsProxyWidget(const QWidget *p)
285 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
287 p = p->parentWidget();
292 class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
294 Q_DECLARE_PUBLIC(QWidget)
297 // *************************** Cross-platform ***************************************
298 enum DrawWidgetFlags {
300 DrawPaintOnScreen = 0x02,
301 DrawRecursive = 0x04,
302 DrawInvisible = 0x08,
303 DontSubtractOpaqueChildren = 0x10,
304 DontDrawOpaqueChildren = 0x20,
305 DontDrawNativeChildren = 0x40,
306 DontSetCompositionMode = 0x80
312 CloseWithSpontaneousEvent
316 DirectionNorth = 0x01,
317 DirectionEast = 0x10,
318 DirectionSouth = 0x02,
323 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
326 QWExtra *extraData() const;
327 QTLWExtra *topData() const;
328 QTLWExtra *maybeTopData() const;
329 QPainter *sharedPainter() const;
330 void setSharedPainter(QPainter *painter);
331 QWidgetBackingStore *maybeBackingStore() const;
332 void init(QWidget *desktopWidget, Qt::WindowFlags f);
333 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
334 void createRecursively();
335 void createWinId(WId id = 0);
337 void createTLExtra();
340 void createSysExtra();
341 void deleteSysExtra();
342 void createTLSysExtra();
343 void deleteTLSysExtra();
344 void updateSystemBackground();
345 void propagatePaletteChange();
347 void setPalette_helper(const QPalette &);
348 void resolvePalette();
349 QPalette naturalWidgetPalette(uint inheritedMask) const;
351 void setMask_sys(const QRegion &);
355 void stackUnder_sys(QWidget *);
358 void updateFocusChild();
360 void updateFont(const QFont &);
361 inline void setFont_helper(const QFont &font) {
362 if (data.fnt == font && data.fnt.resolve() == font.resolve())
367 QFont naturalWidgetFont(uint inheritedMask) const;
369 void setLayoutDirection_helper(Qt::LayoutDirection);
370 void resolveLayoutDirection();
372 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
373 void resolveLocale();
375 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
378 void setUpdatesEnabled_helper(bool );
380 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
381 bool isAboutToShow() const;
382 QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags);
383 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
384 QWidget::RenderFlags renderFlags);
385 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
386 QWidget::RenderFlags renderFlags, bool readyToRender);
387 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
388 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
391 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
392 const QRegion &rgn, const QPoint &offset, int flags,
393 QPainter *sharedPainter, QWidgetBackingStore *backingStore);
396 QPainter *beginSharedPainter();
397 bool endSharedPainter();
398 #ifndef QT_NO_GRAPHICSVIEW
399 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
401 void repaint_sys(const QRegion &rgn);
403 QRect clipRect() const;
404 QRegion clipRegion() const;
405 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
406 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
407 bool alsoNonOpaque = false) const;
408 void clipToEffectiveMask(QRegion ®ion) const;
409 void updateIsOpaque();
410 void setOpaque(bool opaque);
411 void updateIsTranslucent();
412 bool paintOnScreen() const;
413 #ifndef QT_NO_GRAPHICSEFFECT
414 void invalidateGraphicsEffectsRecursively();
415 #endif //QT_NO_GRAPHICSEFFECT
417 const QRegion &getOpaqueChildren() const;
418 void setDirtyOpaqueRegion();
420 bool close_helper(CloseMode mode);
422 void setWindowIcon_helper();
423 void setWindowIcon_sys();
424 void setWindowOpacity_sys(qreal opacity);
425 void adjustQuitOnCloseAttribute();
427 void scrollChildren(int dx, int dy);
428 void moveRect(const QRect &, int dx, int dy);
429 void scrollRect(const QRect &, int dx, int dy);
430 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
431 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
432 void invalidateBuffer(const QRegion &);
433 void invalidateBuffer(const QRect &);
434 bool isOverlapped(const QRect&) const;
435 void syncBackingStore();
436 void syncBackingStore(const QRegion ®ion);
438 // tells the input method about the widgets transform
439 void updateWidgetTransform();
441 void reparentFocusWidgets(QWidget *oldtlw);
443 static int pointToRect(const QPoint &p, const QRect &r);
446 void showChildren(bool spontaneous);
447 void hideChildren(bool spontaneous);
448 void setParent_sys(QWidget *parent, Qt::WindowFlags);
449 void scroll_sys(int dx, int dy);
450 void scroll_sys(int dx, int dy, const QRect &r);
451 void deactivateWidgetCleanup();
452 void setGeometry_sys(int, int, int, int, bool);
453 void fixPosIncludesFrame();
454 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
455 void activateChildLayoutsRecursively();
456 void show_recursive();
461 void _q_showIfNotHidden();
463 void setEnabled_helper(bool);
464 void registerDropSite(bool);
465 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
467 void updateFrameStrut();
468 QRect frameStrut() const;
470 #ifdef QT_KEYPAD_NAVIGATION
471 static bool navigateToDirection(Direction direction);
472 static QWidget *widgetInNavigationDirection(Direction direction);
473 static bool canKeypadNavigate(Qt::Orientation orientation);
474 static bool inTabWidget(QWidget *widget);
477 void setWindowIconText_sys(const QString &cap);
478 void setWindowIconText_helper(const QString &cap);
479 void setWindowTitle_sys(const QString &cap);
482 void setCursor_sys(const QCursor &cursor);
483 void unsetCursor_sys();
486 void setWindowTitle_helper(const QString &cap);
487 void setWindowFilePath_helper(const QString &filePath);
488 void setWindowModified_helper();
490 bool setMinimumSize_helper(int &minw, int &minh);
491 bool setMaximumSize_helper(int &maxw, int &maxh);
492 void setConstraints_sys();
493 bool pointInsideRectAndMask(const QPoint &) const;
494 QWidget *childAt_helper(const QPoint &, bool) const;
495 QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
496 void updateGeometry_helper(bool forceUpdate);
498 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
499 void setLayoutItemMargins(int left, int top, int right, int bottom);
500 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
502 // aboutToDestroy() is called just before the contents of
503 // QWidget::destroy() is executed. It's used to signal QWidget
504 // sub-classes that their internals are about to be released.
505 virtual void aboutToDestroy() {}
507 inline QWidget *effectiveFocusWidget() {
508 QWidget *w = q_func();
509 while (w->focusProxy())
516 // This is an helper function that return the available geometry for
517 // a widget and takes care is this one is in QGraphicsView.
518 // If the widget is not embed in a scene then the geometry available is
519 // null, we let QDesktopWidget decide for us.
520 static QRect screenGeometry(const QWidget *widget)
523 #ifndef QT_NO_GRAPHICSVIEW
524 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
525 //It's embedded if it has an ancestor
527 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
528 // One view, let be smart and return the viewport rect then the popup is aligned
529 if (ancestorProxy->scene()->views().size() == 1) {
530 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
531 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
533 screen = ancestorProxy->scene()->sceneRect().toRect();
541 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
543 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
544 redirectDev = replacement;
545 redirectOffset = offset;
548 inline QPaintDevice *redirected(QPoint *offset) const
551 *offset = redirectDev ? redirectOffset : QPoint();
555 inline void restoreRedirected()
558 inline void enforceNativeChildren()
563 if (extra->nativeChildrenForced)
565 extra->nativeChildrenForced = 1;
567 for (int i = 0; i < children.size(); ++i) {
568 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
569 child->setAttribute(Qt::WA_NativeWindow);
573 inline bool nativeChildrenForced() const
575 return extra ? extra->nativeChildrenForced : false;
578 inline QRect effectiveRectFor(const QRect &rect) const
580 #ifndef QT_NO_GRAPHICSEFFECT
581 if (graphicsEffect && graphicsEffect->isEnabled())
582 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
583 #endif //QT_NO_GRAPHICSEFFECT
587 QSize adjustedSize() const;
589 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
592 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
593 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
594 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
595 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
596 qApp->inputMethod()->show();
601 void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
603 inline QPoint mapToWS(const QPoint &p) const
604 { return p - data.wrect.topLeft(); }
606 inline QPoint mapFromWS(const QPoint &p) const
607 { return p + data.wrect.topLeft(); }
609 inline QRect mapToWS(const QRect &r) const
610 { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
612 inline QRect mapFromWS(const QRect &r) const
613 { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
616 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
620 QWidget *focus_child;
623 QPaintDevice *redirectDev;
624 QWidgetItemV2 *widgetItem;
625 QPaintEngine *extraPaintEngine;
626 mutable const QMetaObject *polished;
627 QGraphicsEffect *graphicsEffect;
628 // All widgets are added into the allWidgets set. Once
629 // they receive a window id they are also added to the mapper.
630 // This should just ensure that all widgets are deleted by QApplication
631 static QWidgetMapper *mapper;
632 static QWidgetSet *allWidgets;
633 #if !defined(QT_NO_IM)
634 Qt::InputMethodHints imHints;
636 #ifdef QT_KEYPAD_NAVIGATION
637 static QPointer<QWidget> editingWidget;
640 // Implicit pointers (shared_null/shared_empty).
641 QRegion opaqueChildren;
643 #ifndef QT_NO_TOOLTIP
646 #ifndef QT_NO_STATUSTIP
649 #ifndef QT_NO_WHATSTHIS
652 #ifndef QT_NO_ACCESSIBILITY
653 QString accessibleName;
654 QString accessibleDescription;
658 uint inheritedFontResolveMask;
659 uint inheritedPaletteResolveMask;
664 signed char leftLayoutItemMargin;
665 signed char topLayoutItemMargin;
666 signed char rightLayoutItemMargin;
667 signed char bottomLayoutItemMargin;
668 static int instanceCounter; // Current number of widget instances
669 static int maxInstances; // Maximum number of widget instances
672 QSizePolicy size_policy;
674 QPoint redirectOffset;
676 QList<QAction*> actions;
678 #ifndef QT_NO_GESTURES
679 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
683 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
684 QPalette::ColorRole fg_role : 8;
685 QPalette::ColorRole bg_role : 8;
686 uint dirtyOpaqueChildren : 1;
688 uint inDirtyList : 1;
691 uint usesDoubleBufferedGLContext : 1;
693 uint inheritsInputMethodHints : 1;
695 uint inSetParent : 1;
697 // *************************** Platform specific ************************************
698 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
700 static QWidget *mouseGrabber;
701 static QWidget *keyboardGrabber;
703 void setWindowRole();
704 void sendStartupMessage(const char *message) const;
705 void setNetWmWindowTypes();
706 void x11UpdateIsOpaque();
707 bool isBackgroundInherited() const;
708 void updateX11AcceptFocus();
709 QPoint mapToGlobal(const QPoint &pos) const;
710 QPoint mapFromGlobal(const QPoint &pos) const;
711 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
712 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
713 #ifndef QT_NO_GESTURES
714 uint nativeGesturePanEnabled : 1;
716 bool shouldShowMaximizeButton();
717 void winUpdateIsOpaque();
718 void reparentChildren();
719 #ifndef QT_NO_DRAGANDDROP
720 QOleDropTarget *registerOleDnd(QWidget *widget);
721 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
723 void grabMouseWhileInWindow();
724 void registerTouchWindow();
725 void winSetupGestures();
726 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
728 uint needWindowChange : 1;
730 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
731 // This list is used to update the gl context whenever a parent and a granparent
732 // moves, and also to check for intersections with gl widgets within the window
733 // when a widget moves.
736 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
737 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
739 QWidget * lastUpdateWidget;
742 // dirtyOnWidget contains the areas in the widget that needs to be repained,
743 // in the same way as dirtyOnScreen does for the window. Areas are added in
744 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
745 // this information repaint invalid areas when widgets are scrolled.
746 QRegion dirtyOnWidget;
747 EventHandlerRef window_event;
748 QList<GlWidgetInfo> glWidgets;
750 //these are here just for code compat (HIViews)
753 void macUpdateSizeAttribute();
754 void macUpdateHideOnSuspend();
755 void macUpdateOpaqueSizeGrip();
756 void macUpdateIgnoreMouseEvents();
757 void macUpdateMetalAttribute();
758 void macUpdateIsOpaque();
759 void macSetNeedsDisplay(QRegion region);
760 void setEnabled_helper_sys(bool enable);
761 bool isRealWindow() const;
762 void adjustWithinMaxAndMinSize(int &w, int &h);
763 void applyMaxAndMinSizeOnWindow();
764 void update_sys(const QRect &rect);
765 void update_sys(const QRegion &rgn);
766 void setGeometry_sys_helper(int, int, int, int, bool);
767 void updateMaximizeButton_sys();
768 void setWindowFilePath_sys(const QString &filePath);
769 void createWindow_sys();
770 void recreateMacWindow();
771 void setSubWindowStacking(bool set);
772 void setWindowLevel();
773 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
774 void syncCocoaMask();
775 void finishCocoaMaskSetup();
776 void syncUnifiedMode();
777 // Did we add the drawRectOriginal method?
778 bool drawRectOriginalAdded;
779 // Is the original drawRect method available?
780 bool originalDrawMethod;
781 // Do we need to change the methods?
784 // Unified toolbar variables
785 bool isInUnifiedToolbar;
786 QUnifiedToolbarSurface *unifiedSurface;
787 QPoint toolbar_offset;
788 QWidget *toolbar_ancestor;
790 bool touchEventsEnabled;
791 void determineWindowClass();
792 void transferChildren();
793 bool qt_mac_dnd_event(uint, DragRef);
794 void toggleDrawers(bool);
795 //mac event functions
796 static bool qt_create_root_win();
797 static void qt_clean_root_win();
798 static bool qt_mac_update_sizer(QWidget *, int up = 0);
799 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
800 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
801 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
802 void registerTouchWindow(bool enable = true);
804 void setMaxWindowState_helper();
805 void setFullScreenSize_helper();
806 bool stealKeyboardGrab(bool grab);
807 bool stealMouseGrab(bool grab);
810 struct QWidgetPaintContext
812 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
813 QPainter *p, QWidgetBackingStore *b)
814 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
820 QPainter *sharedPainter;
821 QWidgetBackingStore *backingStore;
825 #ifndef QT_NO_GRAPHICSEFFECT
826 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
829 QWidgetEffectSourcePrivate(QWidget *widget)
830 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
834 { m_widget->d_func()->graphicsEffect = 0; }
836 inline const QGraphicsItem *graphicsItem() const
839 inline const QWidget *widget() const
844 updateDueToGraphicsEffect = true;
846 updateDueToGraphicsEffect = false;
849 inline bool isPixmap() const
852 inline void effectBoundingRectChanged()
854 // ### This function should take a rect parameter; then we can avoid
855 // updating too much on the parent widget.
856 if (QWidget *parent = m_widget->parentWidget())
862 inline const QStyleOption *styleOption() const
865 inline QRect deviceRect() const
866 { return m_widget->window()->rect(); }
868 QRectF boundingRect(Qt::CoordinateSystem system) const;
869 void draw(QPainter *p);
870 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
871 QGraphicsEffect::PixmapPadMode mode) const;
874 QWidgetPaintContext *context;
875 QTransform lastEffectTransform;
876 bool updateDueToGraphicsEffect;
878 #endif //QT_NO_GRAPHICSEFFECT
880 inline QWExtra *QWidgetPrivate::extraData() const
885 inline QTLWExtra *QWidgetPrivate::topData() const
887 const_cast<QWidgetPrivate *>(this)->createTLExtra();
888 return extra->topextra;
891 inline QTLWExtra *QWidgetPrivate::maybeTopData() const
893 return extra ? extra->topextra : 0;
896 inline QPainter *QWidgetPrivate::sharedPainter() const
899 QTLWExtra *x = q->window()->d_func()->maybeTopData();
900 return x ? x->sharedPainter : 0;
903 inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
906 QTLWExtra *x = q->window()->d_func()->topData();
907 x->sharedPainter = painter;
910 inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
913 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
914 || extra->mask.contains(p));
917 inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
920 QTLWExtra *x = q->window()->d_func()->maybeTopData();
921 return x ? x->backingStoreTracker.data() : 0;
926 #endif // QWIDGET_P_H