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
159 QWidgetBackingStoreTracker backingStoreTracker;
160 QBackingStore *backingStore;
161 QPainter *sharedPainter;
163 // Implicit pointers (shared_null).
164 QString caption; // widget caption
165 QString iconText; // widget icon text
166 QString role; // widget role
167 QString filePath; // widget file path
170 short incw, inch; // size increments
171 short basew, baseh; // base sizes
172 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
174 QRect normalGeometry; // used by showMin/maximized/FullScreen
175 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
177 // *************************** Cross-platform bit fields ****************************
179 uint posIncludesFrame : 1;
180 uint sizeAdjusted : 1;
181 uint inTopLevelResize : 1;
185 // *************************** Platform specific values (bit fields first) **********
186 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
187 uint spont_unmapped: 1; // window was spontaneously unmapped
188 uint dnd : 1; // DND properties installed
189 uint validWMState : 1; // is WM_STATE valid?
190 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
191 WId parentWinId; // parent window Id (valid after reparenting)
192 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
193 QPoint fullScreenOffset;
195 WId syncUpdateCounter;
196 ulong syncRequestTimestamp;
197 qint32 newCounterValueHi;
198 quint32 newCounterValueLo;
200 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
201 uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered.
202 HICON winIconBig; // internal big Windows icon
203 HICON winIconSmall; // internal small Windows icon
204 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
206 uint isSetGeometry : 1;
210 WindowGroupRef group;
211 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
212 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
213 // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and
215 // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the
216 // starting position as 0,0 instead of the normal starting position.
219 QWidgetWindow *window;
220 quint32 screenIndex; // index in qplatformscreenlist
224 // *************************** Cross-platform variables *****************************
226 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
227 void *glContext; // if the widget is hijacked by QGLWindowSurface
228 QTLWExtra *topextra; // only useful for TLWs
229 #ifndef QT_NO_GRAPHICSVIEW
230 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
235 QPointer<QStyle> style;
236 QPointer<QWidget> focus_proxy;
238 // Implicit pointers (shared_empty/shared_null).
239 QRegion mask; // widget mask
244 qint32 minh; // minimum size
246 qint32 maxh; // maximum size
249 QSize staticContentsSize;
251 // *************************** Cross-platform bit fields ****************************
252 uint explicitMinSize : 2;
253 uint explicitMaxSize : 2;
254 uint autoFillBackground : 1;
255 uint nativeChildrenForced : 1;
256 uint inRenderWithPainter : 1;
259 // *************************** Platform specific values (bit fields first) **********
260 #if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
261 #ifndef QT_NO_DRAGANDDROP
262 QOleDropTarget *dropTarget; // drop target
263 QList<QPointer<QWidget> > oleDropWidgets;
265 #elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
266 uint compress_events : 1;
267 WId xDndProxy; // XDND forwarding to embedded windows
268 #elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
271 CGImageRef imageMask;
278 Returns true if \a p or any of its parents enable the
279 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
280 QWidget::setParent() to determine whether it's necessary to embed the
281 widget into a QGraphicsProxyWidget or not.
283 static inline bool bypassGraphicsProxyWidget(const QWidget *p)
286 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
288 p = p->parentWidget();
293 class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
295 Q_DECLARE_PUBLIC(QWidget)
298 // *************************** Cross-platform ***************************************
299 enum DrawWidgetFlags {
301 DrawPaintOnScreen = 0x02,
302 DrawRecursive = 0x04,
303 DrawInvisible = 0x08,
304 DontSubtractOpaqueChildren = 0x10,
305 DontDrawOpaqueChildren = 0x20,
306 DontDrawNativeChildren = 0x40,
307 DontSetCompositionMode = 0x80
313 CloseWithSpontaneousEvent
317 DirectionNorth = 0x01,
318 DirectionEast = 0x10,
319 DirectionSouth = 0x02,
324 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
327 QWExtra *extraData() const;
328 QTLWExtra *topData() const;
329 QTLWExtra *maybeTopData() const;
330 QPainter *sharedPainter() const;
331 void setSharedPainter(QPainter *painter);
332 QWidgetBackingStore *maybeBackingStore() const;
333 void init(QWidget *desktopWidget, Qt::WindowFlags f);
334 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
335 void createRecursively();
336 void createWinId(WId id = 0);
338 void createTLExtra();
341 void createSysExtra();
342 void deleteSysExtra();
343 void createTLSysExtra();
344 void deleteTLSysExtra();
345 void updateSystemBackground();
346 void propagatePaletteChange();
348 void setPalette_helper(const QPalette &);
349 void resolvePalette();
350 QPalette naturalWidgetPalette(uint inheritedMask) const;
352 void setMask_sys(const QRegion &);
356 void stackUnder_sys(QWidget *);
359 void updateFocusChild();
361 void updateFont(const QFont &);
362 inline void setFont_helper(const QFont &font) {
363 if (data.fnt == font && data.fnt.resolve() == font.resolve())
368 QFont naturalWidgetFont(uint inheritedMask) const;
370 void setLayoutDirection_helper(Qt::LayoutDirection);
371 void resolveLayoutDirection();
373 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
374 void resolveLocale();
376 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
379 void setUpdatesEnabled_helper(bool );
381 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
382 bool isAboutToShow() const;
383 QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags);
384 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
385 QWidget::RenderFlags renderFlags);
386 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
387 QWidget::RenderFlags renderFlags, bool readyToRender);
388 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
389 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
392 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
393 const QRegion &rgn, const QPoint &offset, int flags,
394 QPainter *sharedPainter, QWidgetBackingStore *backingStore);
397 QPainter *beginSharedPainter();
398 bool endSharedPainter();
399 #ifndef QT_NO_GRAPHICSVIEW
400 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
402 void repaint_sys(const QRegion &rgn);
404 QRect clipRect() const;
405 QRegion clipRegion() const;
406 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
407 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
408 bool alsoNonOpaque = false) const;
409 void clipToEffectiveMask(QRegion ®ion) const;
410 void updateIsOpaque();
411 void setOpaque(bool opaque);
412 void updateIsTranslucent();
413 bool paintOnScreen() const;
414 #ifndef QT_NO_GRAPHICSEFFECT
415 void invalidateGraphicsEffectsRecursively();
416 #endif //QT_NO_GRAPHICSEFFECT
418 const QRegion &getOpaqueChildren() const;
419 void setDirtyOpaqueRegion();
421 bool close_helper(CloseMode mode);
423 void setWindowIcon_helper();
424 void setWindowIcon_sys(bool forceReset = false);
425 void setWindowOpacity_sys(qreal opacity);
426 void adjustQuitOnCloseAttribute();
428 void scrollChildren(int dx, int dy);
429 void moveRect(const QRect &, int dx, int dy);
430 void scrollRect(const QRect &, int dx, int dy);
431 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
432 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
433 void invalidateBuffer(const QRegion &);
434 void invalidateBuffer(const QRect &);
435 bool isOverlapped(const QRect&) const;
436 void syncBackingStore();
437 void syncBackingStore(const QRegion ®ion);
439 // tells the input method about the widgets transform
440 void updateWidgetTransform();
442 void reparentFocusWidgets(QWidget *oldtlw);
444 static int pointToRect(const QPoint &p, const QRect &r);
447 void showChildren(bool spontaneous);
448 void hideChildren(bool spontaneous);
449 void setParent_sys(QWidget *parent, Qt::WindowFlags);
450 void scroll_sys(int dx, int dy);
451 void scroll_sys(int dx, int dy, const QRect &r);
452 void deactivateWidgetCleanup();
453 void setGeometry_sys(int, int, int, int, bool);
454 void fixPosIncludesFrame();
455 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
456 void activateChildLayoutsRecursively();
457 void show_recursive();
462 void _q_showIfNotHidden();
464 void setEnabled_helper(bool);
465 void registerDropSite(bool);
466 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
468 void updateFrameStrut();
469 QRect frameStrut() const;
471 #ifdef QT_KEYPAD_NAVIGATION
472 static bool navigateToDirection(Direction direction);
473 static QWidget *widgetInNavigationDirection(Direction direction);
474 static bool canKeypadNavigate(Qt::Orientation orientation);
475 static bool inTabWidget(QWidget *widget);
478 void setWindowIconText_sys(const QString &cap);
479 void setWindowIconText_helper(const QString &cap);
480 void setWindowTitle_sys(const QString &cap);
483 void setCursor_sys(const QCursor &cursor);
484 void unsetCursor_sys();
487 void setWindowTitle_helper(const QString &cap);
488 void setWindowFilePath_helper(const QString &filePath);
489 void setWindowModified_helper();
491 bool setMinimumSize_helper(int &minw, int &minh);
492 bool setMaximumSize_helper(int &maxw, int &maxh);
493 void setConstraints_sys();
494 bool pointInsideRectAndMask(const QPoint &) const;
495 QWidget *childAt_helper(const QPoint &, bool) const;
496 QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
497 void updateGeometry_helper(bool forceUpdate);
499 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
500 void setLayoutItemMargins(int left, int top, int right, int bottom);
501 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
503 // aboutToDestroy() is called just before the contents of
504 // QWidget::destroy() is executed. It's used to signal QWidget
505 // sub-classes that their internals are about to be released.
506 virtual void aboutToDestroy() {}
508 inline QWidget *effectiveFocusWidget() {
509 QWidget *w = q_func();
510 while (w->focusProxy())
517 // This is an helper function that return the available geometry for
518 // a widget and takes care is this one is in QGraphicsView.
519 // If the widget is not embed in a scene then the geometry available is
520 // null, we let QDesktopWidget decide for us.
521 static QRect screenGeometry(const QWidget *widget)
524 #ifndef QT_NO_GRAPHICSVIEW
525 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
526 //It's embedded if it has an ancestor
528 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
529 // One view, let be smart and return the viewport rect then the popup is aligned
530 if (ancestorProxy->scene()->views().size() == 1) {
531 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
532 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
534 screen = ancestorProxy->scene()->sceneRect().toRect();
542 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
544 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
545 redirectDev = replacement;
546 redirectOffset = offset;
549 inline QPaintDevice *redirected(QPoint *offset) const
552 *offset = redirectDev ? redirectOffset : QPoint();
556 inline void restoreRedirected()
559 inline void enforceNativeChildren()
564 if (extra->nativeChildrenForced)
566 extra->nativeChildrenForced = 1;
568 for (int i = 0; i < children.size(); ++i) {
569 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
570 child->setAttribute(Qt::WA_NativeWindow);
574 inline bool nativeChildrenForced() const
576 return extra ? extra->nativeChildrenForced : false;
579 inline QRect effectiveRectFor(const QRect &rect) const
581 #ifndef QT_NO_GRAPHICSEFFECT
582 if (graphicsEffect && graphicsEffect->isEnabled())
583 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
584 #endif //QT_NO_GRAPHICSEFFECT
588 QSize adjustedSize() const;
590 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
593 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
594 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
595 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
596 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
597 qApp->inputMethod()->show();
602 void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
604 inline QPoint mapToWS(const QPoint &p) const
605 { return p - data.wrect.topLeft(); }
607 inline QPoint mapFromWS(const QPoint &p) const
608 { return p + data.wrect.topLeft(); }
610 inline QRect mapToWS(const QRect &r) const
611 { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
613 inline QRect mapFromWS(const QRect &r) const
614 { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
617 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
621 QWidget *focus_child;
624 QPaintDevice *redirectDev;
625 QWidgetItemV2 *widgetItem;
626 QPaintEngine *extraPaintEngine;
627 mutable const QMetaObject *polished;
628 QGraphicsEffect *graphicsEffect;
629 // All widgets are added into the allWidgets set. Once
630 // they receive a window id they are also added to the mapper.
631 // This should just ensure that all widgets are deleted by QApplication
632 static QWidgetMapper *mapper;
633 static QWidgetSet *allWidgets;
634 #if !defined(QT_NO_IM)
635 Qt::InputMethodHints imHints;
637 #ifdef QT_KEYPAD_NAVIGATION
638 static QPointer<QWidget> editingWidget;
641 // Implicit pointers (shared_null/shared_empty).
642 QRegion opaqueChildren;
644 #ifndef QT_NO_TOOLTIP
647 #ifndef QT_NO_STATUSTIP
650 #ifndef QT_NO_WHATSTHIS
653 #ifndef QT_NO_ACCESSIBILITY
654 QString accessibleName;
655 QString accessibleDescription;
659 uint inheritedFontResolveMask;
660 uint inheritedPaletteResolveMask;
665 signed char leftLayoutItemMargin;
666 signed char topLayoutItemMargin;
667 signed char rightLayoutItemMargin;
668 signed char bottomLayoutItemMargin;
669 static int instanceCounter; // Current number of widget instances
670 static int maxInstances; // Maximum number of widget instances
673 QSizePolicy size_policy;
675 QPoint redirectOffset;
677 QList<QAction*> actions;
679 #ifndef QT_NO_GESTURES
680 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
684 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
685 QPalette::ColorRole fg_role : 8;
686 QPalette::ColorRole bg_role : 8;
687 uint dirtyOpaqueChildren : 1;
689 uint inDirtyList : 1;
692 uint usesDoubleBufferedGLContext : 1;
694 uint inheritsInputMethodHints : 1;
696 uint inSetParent : 1;
698 // *************************** Platform specific ************************************
699 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
701 static QWidget *mouseGrabber;
702 static QWidget *keyboardGrabber;
704 void setWindowRole();
705 void sendStartupMessage(const char *message) const;
706 void setNetWmWindowTypes();
707 void x11UpdateIsOpaque();
708 bool isBackgroundInherited() const;
709 void updateX11AcceptFocus();
710 QPoint mapToGlobal(const QPoint &pos) const;
711 QPoint mapFromGlobal(const QPoint &pos) const;
712 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
713 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
714 #ifndef QT_NO_GESTURES
715 uint nativeGesturePanEnabled : 1;
717 bool shouldShowMaximizeButton();
718 void winUpdateIsOpaque();
719 void reparentChildren();
720 #ifndef QT_NO_DRAGANDDROP
721 QOleDropTarget *registerOleDnd(QWidget *widget);
722 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
724 void grabMouseWhileInWindow();
725 void registerTouchWindow();
726 void winSetupGestures();
727 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
729 uint needWindowChange : 1;
731 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
732 // This list is used to update the gl context whenever a parent and a granparent
733 // moves, and also to check for intersections with gl widgets within the window
734 // when a widget moves.
737 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
738 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
740 QWidget * lastUpdateWidget;
743 // dirtyOnWidget contains the areas in the widget that needs to be repained,
744 // in the same way as dirtyOnScreen does for the window. Areas are added in
745 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
746 // this information repaint invalid areas when widgets are scrolled.
747 QRegion dirtyOnWidget;
748 EventHandlerRef window_event;
749 QList<GlWidgetInfo> glWidgets;
751 //these are here just for code compat (HIViews)
754 void macUpdateSizeAttribute();
755 void macUpdateHideOnSuspend();
756 void macUpdateOpaqueSizeGrip();
757 void macUpdateIgnoreMouseEvents();
758 void macUpdateMetalAttribute();
759 void macUpdateIsOpaque();
760 void macSetNeedsDisplay(QRegion region);
761 void setEnabled_helper_sys(bool enable);
762 bool isRealWindow() const;
763 void adjustWithinMaxAndMinSize(int &w, int &h);
764 void applyMaxAndMinSizeOnWindow();
765 void update_sys(const QRect &rect);
766 void update_sys(const QRegion &rgn);
767 void setGeometry_sys_helper(int, int, int, int, bool);
768 void updateMaximizeButton_sys();
769 void setWindowFilePath_sys(const QString &filePath);
770 void createWindow_sys();
771 void recreateMacWindow();
772 void setSubWindowStacking(bool set);
773 void setWindowLevel();
774 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
775 void syncCocoaMask();
776 void finishCocoaMaskSetup();
777 void syncUnifiedMode();
778 // Did we add the drawRectOriginal method?
779 bool drawRectOriginalAdded;
780 // Is the original drawRect method available?
781 bool originalDrawMethod;
782 // Do we need to change the methods?
785 // Unified toolbar variables
786 bool isInUnifiedToolbar;
787 QUnifiedToolbarSurface *unifiedSurface;
788 QPoint toolbar_offset;
789 QWidget *toolbar_ancestor;
791 bool touchEventsEnabled;
792 void determineWindowClass();
793 void transferChildren();
794 bool qt_mac_dnd_event(uint, DragRef);
795 void toggleDrawers(bool);
796 //mac event functions
797 static bool qt_create_root_win();
798 static void qt_clean_root_win();
799 static bool qt_mac_update_sizer(QWidget *, int up = 0);
800 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
801 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
802 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
803 void registerTouchWindow(bool enable = true);
805 void setMaxWindowState_helper();
806 void setFullScreenSize_helper();
807 bool stealKeyboardGrab(bool grab);
808 bool stealMouseGrab(bool grab);
811 struct QWidgetPaintContext
813 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
814 QPainter *p, QWidgetBackingStore *b)
815 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
821 QPainter *sharedPainter;
822 QWidgetBackingStore *backingStore;
826 #ifndef QT_NO_GRAPHICSEFFECT
827 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
830 QWidgetEffectSourcePrivate(QWidget *widget)
831 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
835 { m_widget->d_func()->graphicsEffect = 0; }
837 inline const QGraphicsItem *graphicsItem() const
840 inline const QWidget *widget() const
845 updateDueToGraphicsEffect = true;
847 updateDueToGraphicsEffect = false;
850 inline bool isPixmap() const
853 inline void effectBoundingRectChanged()
855 // ### This function should take a rect parameter; then we can avoid
856 // updating too much on the parent widget.
857 if (QWidget *parent = m_widget->parentWidget())
863 inline const QStyleOption *styleOption() const
866 inline QRect deviceRect() const
867 { return m_widget->window()->rect(); }
869 QRectF boundingRect(Qt::CoordinateSystem system) const;
870 void draw(QPainter *p);
871 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
872 QGraphicsEffect::PixmapPadMode mode) const;
875 QWidgetPaintContext *context;
876 QTransform lastEffectTransform;
877 bool updateDueToGraphicsEffect;
879 #endif //QT_NO_GRAPHICSEFFECT
881 inline QWExtra *QWidgetPrivate::extraData() const
886 inline QTLWExtra *QWidgetPrivate::topData() const
888 const_cast<QWidgetPrivate *>(this)->createTLExtra();
889 return extra->topextra;
892 inline QTLWExtra *QWidgetPrivate::maybeTopData() const
894 return extra ? extra->topextra : 0;
897 inline QPainter *QWidgetPrivate::sharedPainter() const
900 QTLWExtra *x = q->window()->d_func()->maybeTopData();
901 return x ? x->sharedPainter : 0;
904 inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
907 QTLWExtra *x = q->window()->d_func()->topData();
908 x->sharedPainter = painter;
911 inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
914 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
915 || extra->mask.contains(p));
918 inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
921 QTLWExtra *x = q->window()->d_func()->maybeTopData();
922 return x ? x->backingStoreTracker.data() : 0;
927 #endif // QWIDGET_P_H