src/gui/kernel/qwidget_p.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    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 "QtGui/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/qsizepolicy.h"
       
    63 #include "QtGui/qstyle.h"
       
    64 #include "QtGui/qapplication.h"
       
    65 #include <private/qgraphicseffect_p.h>
       
    66 #include "QtGui/qgraphicsproxywidget.h"
       
    67 #include "QtGui/qgraphicsscene.h"
       
    68 #include "QtGui/qgraphicsview.h"
       
    69 #include <private/qgesture_p.h>
       
    70 
       
    71 #ifdef Q_WS_WIN
       
    72 #include "QtCore/qt_windows.h"
       
    73 #include <private/qdnd_p.h>
       
    74 #endif // Q_WS_WIN
       
    75 
       
    76 #ifdef Q_WS_X11
       
    77 #include "QtGui/qx11info_x11.h"
       
    78 #endif
       
    79 
       
    80 #ifdef Q_WS_MAC
       
    81 #include <private/qt_mac_p.h>
       
    82 #endif
       
    83 
       
    84 #if defined(Q_WS_QWS)
       
    85 #include "QtGui/qinputcontext.h"
       
    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 class QPaintEngine;
       
   106 class QPixmap;
       
   107 class QWidgetBackingStore;
       
   108 class QGraphicsProxyWidget;
       
   109 class QWidgetItemV2;
       
   110 
       
   111 class QStyle;
       
   112 
       
   113 struct QTLWExtra {
       
   114     // *************************** Cross-platform variables *****************************
       
   115 
       
   116     // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
       
   117     QIcon *icon; // widget icon
       
   118     QPixmap *iconPixmap;
       
   119     QWidgetBackingStore *backingStore;
       
   120     QWindowSurface *windowSurface;
       
   121     QPainter *sharedPainter;
       
   122 
       
   123     // Implicit pointers (shared_null).
       
   124     QString caption; // widget caption
       
   125     QString iconText; // widget icon text
       
   126     QString role; // widget role
       
   127     QString filePath; // widget file path
       
   128 
       
   129     // Other variables.
       
   130     short incw, inch; // size increments
       
   131     short basew, baseh; // base sizes
       
   132      // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
       
   133     QRect frameStrut;
       
   134     QRect normalGeometry; // used by showMin/maximized/FullScreen
       
   135     Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
       
   136 
       
   137     // *************************** Cross-platform bit fields ****************************
       
   138     uint opacity : 8;
       
   139     uint posFromMove : 1;
       
   140     uint sizeAdjusted : 1;
       
   141     uint inTopLevelResize : 1;
       
   142     uint inRepaint : 1;
       
   143     uint embedded : 1;
       
   144 
       
   145     // *************************** Platform specific values (bit fields first) **********
       
   146 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
       
   147     uint spont_unmapped: 1; // window was spontaneously unmapped
       
   148     uint dnd : 1; // DND properties installed
       
   149     uint validWMState : 1; // is WM_STATE valid?
       
   150     uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
       
   151     WId parentWinId; // parent window Id (valid after reparenting)
       
   152     WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
       
   153     QPoint fullScreenOffset;
       
   154 #ifndef QT_NO_XSYNC
       
   155     WId syncUpdateCounter;
       
   156     ulong syncRequestTimestamp;
       
   157     qint32 newCounterValueHi;
       
   158     quint32 newCounterValueLo;
       
   159 #endif
       
   160 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
       
   161     HICON winIconBig; // internal big Windows icon
       
   162     HICON winIconSmall; // internal small Windows icon
       
   163 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
       
   164     uint resizer : 4;
       
   165     uint isSetGeometry : 1;
       
   166     uint isMove : 1;
       
   167     quint32 wattr;
       
   168     quint32 wclass;
       
   169     WindowGroupRef group;
       
   170     IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
       
   171     quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
       
   172 #elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
       
   173 #ifndef QT_NO_QWS_MANAGER
       
   174     QWSManager *qwsManager;
       
   175 #endif
       
   176 #endif
       
   177 };
       
   178 
       
   179 struct QWExtra {
       
   180     // *************************** Cross-platform variables *****************************
       
   181 
       
   182     // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
       
   183     void *glContext; // if the widget is hijacked by QGLWindowSurface
       
   184     QTLWExtra *topextra; // only useful for TLWs
       
   185 #ifndef QT_NO_GRAPHICSVIEW
       
   186     QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
       
   187 #endif
       
   188 #ifndef QT_NO_CURSOR
       
   189     QCursor *curs;
       
   190 #endif
       
   191     QPointer<QStyle> style;
       
   192     QPointer<QWidget> focus_proxy;
       
   193 
       
   194     // Implicit pointers (shared_empty/shared_null).
       
   195     QRegion mask; // widget mask
       
   196     QString styleSheet;
       
   197 
       
   198     // Other variables.
       
   199     qint32 minw;
       
   200     qint32 minh; // minimum size
       
   201     qint32 maxw;
       
   202     qint32 maxh; // maximum size
       
   203     quint16 customDpiX;
       
   204     quint16 customDpiY;
       
   205     QSize staticContentsSize;
       
   206 
       
   207     // *************************** Cross-platform bit fields ****************************
       
   208     uint explicitMinSize : 2;
       
   209     uint explicitMaxSize : 2;
       
   210     uint autoFillBackground : 1;
       
   211     uint nativeChildrenForced : 1;
       
   212     uint inRenderWithPainter : 1;
       
   213     uint hasMask : 1;
       
   214 
       
   215     // *************************** Platform specific values (bit fields first) **********
       
   216 #if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
       
   217 #ifndef QT_NO_DRAGANDDROP
       
   218     QOleDropTarget *dropTarget; // drop target
       
   219     QList<QPointer<QWidget> > oleDropWidgets;
       
   220 #endif
       
   221 #elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
       
   222     uint compress_events : 1;
       
   223     WId xDndProxy; // XDND forwarding to embedded windows
       
   224 #elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
       
   225 #ifdef QT_MAC_USE_COCOA
       
   226     // Cocoa Mask stuff
       
   227     QImage maskBits;
       
   228     CGImageRef imageMask;
       
   229 #endif
       
   230 #elif defined(Q_OS_SYMBIAN) // <----------------------------------------------------- Symbian
       
   231     uint activated : 1; // RWindowBase::Activated has been called
       
   232 
       
   233     // If set, QSymbianControl::Draw does not blit this widget
       
   234     // This is to allow, for use cases such as video, widgets which, from the Qt point
       
   235     // of view, are just placeholders in the scene.  For these widgets, any necessary
       
   236     // drawing to the UI framebuffer is done by the relevant Symbian subsystem.  For
       
   237     // video rendering, this would be an MMF controller, or MDF post-processor.
       
   238     uint disableBlit : 1;
       
   239 #endif
       
   240 };
       
   241 
       
   242 /*!
       
   243     \internal
       
   244 
       
   245     Returns true if \a p or any of its parents enable the
       
   246     Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
       
   247     QWidget::setParent() to determine whether it's necessary to embed the
       
   248     widget into a QGraphicsProxyWidget or not.
       
   249 */
       
   250 static inline bool bypassGraphicsProxyWidget(const QWidget *p)
       
   251 {
       
   252     while (p) {
       
   253         if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
       
   254             return true;
       
   255         p = p->parentWidget();
       
   256     }
       
   257     return false;
       
   258 }
       
   259 
       
   260 class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
       
   261 {
       
   262     Q_DECLARE_PUBLIC(QWidget)
       
   263 
       
   264 public:
       
   265     // *************************** Cross-platform ***************************************
       
   266     enum DrawWidgetFlags {
       
   267         DrawAsRoot = 0x01,
       
   268         DrawPaintOnScreen = 0x02,
       
   269         DrawRecursive = 0x04,
       
   270         DrawInvisible = 0x08,
       
   271         DontSubtractOpaqueChildren = 0x10,
       
   272         DontSetCompositionMode = 0x20,
       
   273         DontDrawOpaqueChildren = 0x40
       
   274     };
       
   275 
       
   276     enum CloseMode {
       
   277         CloseNoEvent,
       
   278         CloseWithEvent,
       
   279         CloseWithSpontaneousEvent
       
   280     };
       
   281 
       
   282     enum Direction {
       
   283         DirectionNorth = 0x01,
       
   284         DirectionEast = 0x10,
       
   285         DirectionSouth = 0x02,
       
   286         DirectionWest = 0x20
       
   287     };
       
   288 
       
   289     // Functions.
       
   290     explicit QWidgetPrivate(int version = QObjectPrivateVersion);
       
   291     ~QWidgetPrivate();
       
   292 
       
   293     QWExtra *extraData() const;
       
   294     QTLWExtra *topData() const;
       
   295     QTLWExtra *maybeTopData() const;
       
   296     QPainter *sharedPainter() const;
       
   297     void setSharedPainter(QPainter *painter);
       
   298     QWidgetBackingStore *maybeBackingStore() const;
       
   299     void init(QWidget *desktopWidget, Qt::WindowFlags f);
       
   300     void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
       
   301     void createRecursively();
       
   302     void createWinId(WId id = 0);
       
   303 
       
   304     void createTLExtra();
       
   305     void createExtra();
       
   306     void deleteExtra();
       
   307     void createSysExtra();
       
   308     void deleteSysExtra();
       
   309     void createTLSysExtra();
       
   310     void deleteTLSysExtra();
       
   311     void updateSystemBackground();
       
   312     void propagatePaletteChange();
       
   313 
       
   314     void setPalette_helper(const QPalette &);
       
   315     void resolvePalette();
       
   316     QPalette naturalWidgetPalette(uint inheritedMask) const;
       
   317 
       
   318     void setMask_sys(const QRegion &);
       
   319 #ifdef Q_OS_SYMBIAN
       
   320     void setSoftKeys_sys(const QList<QAction*> &softkeys);
       
   321     void activateSymbianWindow(WId wid = 0);
       
   322     void _q_delayedDestroy(WId winId);
       
   323 #endif
       
   324 
       
   325     void raise_sys();
       
   326     void lower_sys();
       
   327     void stackUnder_sys(QWidget *);
       
   328 
       
   329     void setFocus_sys();
       
   330 
       
   331     void updateFont(const QFont &);
       
   332     inline void setFont_helper(const QFont &font) {
       
   333         if (data.fnt == font && data.fnt.resolve() == font.resolve())
       
   334             return;
       
   335         updateFont(font);
       
   336     }
       
   337     void resolveFont();
       
   338     QFont naturalWidgetFont(uint inheritedMask) const;
       
   339 
       
   340     void setLayoutDirection_helper(Qt::LayoutDirection);
       
   341     void resolveLayoutDirection();
       
   342 
       
   343     void setLocale_helper(const QLocale &l, bool forceUpdate = false);
       
   344     void resolveLocale();
       
   345 
       
   346     void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
       
   347     void inheritStyle();
       
   348 
       
   349     void setUpdatesEnabled_helper(bool );
       
   350 
       
   351     void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
       
   352     bool isAboutToShow() const;
       
   353     QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
       
   354     void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
       
   355                        QWidget::RenderFlags renderFlags);
       
   356     void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
       
   357                     QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
       
   358 
       
   359 
       
   360     void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
       
   361                                 const QRegion &rgn, const QPoint &offset, int flags
       
   362 #ifdef Q_BACKINGSTORE_SUBSURFACES
       
   363                                 , const QWindowSurface *currentSurface
       
   364 #endif
       
   365                                 , QPainter *sharedPainter, QWidgetBackingStore *backingStore);
       
   366 
       
   367 
       
   368     QPainter *beginSharedPainter();
       
   369     bool endSharedPainter();
       
   370 #ifndef QT_NO_GRAPHICSVIEW
       
   371     static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
       
   372 #endif
       
   373     QWindowSurface *createDefaultWindowSurface();
       
   374     QWindowSurface *createDefaultWindowSurface_sys();
       
   375     void repaint_sys(const QRegion &rgn);
       
   376 
       
   377     QRect clipRect() const;
       
   378     QRegion clipRegion() const;
       
   379     void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
       
   380     void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
       
   381                                 bool alsoNonOpaque = false) const;
       
   382     void clipToEffectiveMask(QRegion &region) const;
       
   383     void updateIsOpaque();
       
   384     void setOpaque(bool opaque);
       
   385     void updateIsTranslucent();
       
   386     bool paintOnScreen() const;
       
   387     void invalidateGraphicsEffectsRecursively();
       
   388 
       
   389     QRegion getOpaqueRegion() const;
       
   390     const QRegion &getOpaqueChildren() const;
       
   391     void setDirtyOpaqueRegion();
       
   392 
       
   393     bool close_helper(CloseMode mode);
       
   394 
       
   395     void setWindowIcon_helper();
       
   396     void setWindowIcon_sys(bool forceReset = false);
       
   397     void setWindowOpacity_sys(qreal opacity);
       
   398     void adjustQuitOnCloseAttribute();
       
   399 
       
   400     void scrollChildren(int dx, int dy);
       
   401     void moveRect(const QRect &, int dx, int dy);
       
   402     void scrollRect(const QRect &, int dx, int dy);
       
   403     void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
       
   404     // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
       
   405     void invalidateBuffer(const QRegion &);
       
   406     void invalidateBuffer(const QRect &);
       
   407     bool isOverlapped(const QRect&) const;
       
   408     void syncBackingStore();
       
   409     void syncBackingStore(const QRegion &region);
       
   410 
       
   411     void reparentFocusWidgets(QWidget *oldtlw);
       
   412 
       
   413     static int pointToRect(const QPoint &p, const QRect &r);
       
   414 
       
   415     void setWinId(WId);
       
   416     void showChildren(bool spontaneous);
       
   417     void hideChildren(bool spontaneous);
       
   418     void setParent_sys(QWidget *parent, Qt::WindowFlags);
       
   419     void scroll_sys(int dx, int dy);
       
   420     void scroll_sys(int dx, int dy, const QRect &r);
       
   421     void deactivateWidgetCleanup();
       
   422     void setGeometry_sys(int, int, int, int, bool);
       
   423     void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
       
   424     void activateChildLayoutsRecursively();
       
   425     void show_recursive();
       
   426     void show_helper();
       
   427     void show_sys();
       
   428     void hide_sys();
       
   429     void hide_helper();
       
   430     void _q_showIfNotHidden();
       
   431 
       
   432     void setEnabled_helper(bool);
       
   433     void registerDropSite(bool);
       
   434     static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
       
   435 
       
   436     void updateFrameStrut();
       
   437     QRect frameStrut() const;
       
   438 
       
   439 #ifdef QT_KEYPAD_NAVIGATION
       
   440     static bool navigateToDirection(Direction direction);
       
   441     static QWidget *widgetInNavigationDirection(Direction direction);
       
   442 #endif
       
   443 
       
   444     void setWindowIconText_sys(const QString &cap);
       
   445     void setWindowIconText_helper(const QString &cap);
       
   446     void setWindowTitle_sys(const QString &cap);
       
   447 
       
   448 #ifndef QT_NO_CURSOR
       
   449     void setCursor_sys(const QCursor &cursor);
       
   450     void unsetCursor_sys();
       
   451 #endif
       
   452 
       
   453     void setWindowTitle_helper(const QString &cap);
       
   454     void setWindowFilePath_helper(const QString &filePath);
       
   455 
       
   456     bool setMinimumSize_helper(int &minw, int &minh);
       
   457     bool setMaximumSize_helper(int &maxw, int &maxh);
       
   458     void setConstraints_sys();
       
   459     QWidget *childAt_helper(const QPoint &, bool) const;
       
   460     void updateGeometry_helper(bool forceUpdate);
       
   461 
       
   462     void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
       
   463     void setLayoutItemMargins(int left, int top, int right, int bottom);
       
   464     void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
       
   465 
       
   466     QInputContext *inputContext() const;
       
   467 
       
   468     void setModal_sys();
       
   469 
       
   470     // This is an helper function that return the available geometry for
       
   471     // a widget and takes care is this one is in QGraphicsView.
       
   472     // If the widget is not embed in a scene then the geometry available is
       
   473     // null, we let QDesktopWidget decide for us.
       
   474     static QRect screenGeometry(const QWidget *widget)
       
   475     {
       
   476         QRect screen;
       
   477 #ifndef QT_NO_GRAPHICSVIEW
       
   478         QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
       
   479         //It's embedded if it has an ancestor
       
   480         if (ancestorProxy) {
       
   481             if (!bypassGraphicsProxyWidget(widget)) {
       
   482                 // One view, let be smart and return the viewport rect then the popup is aligned
       
   483                 if (ancestorProxy->scene()->views().size() == 1) {
       
   484                     QGraphicsView *view = ancestorProxy->scene()->views().at(0);
       
   485                     screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
       
   486                 } else {
       
   487                     screen = ancestorProxy->scene()->sceneRect().toRect();
       
   488                 }
       
   489             }
       
   490         }
       
   491 #endif
       
   492         return screen;
       
   493     }
       
   494 
       
   495     inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
       
   496     {
       
   497         Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
       
   498         redirectDev = replacement;
       
   499         redirectOffset = offset;
       
   500     }
       
   501 
       
   502     inline QPaintDevice *redirected(QPoint *offset) const
       
   503     {
       
   504         if (offset)
       
   505             *offset = redirectDev ? redirectOffset : QPoint();
       
   506         return redirectDev;
       
   507     }
       
   508 
       
   509     inline void restoreRedirected()
       
   510     { redirectDev = 0; }
       
   511 
       
   512     inline void enforceNativeChildren()
       
   513     {
       
   514         if (!extra)
       
   515             createExtra();
       
   516 
       
   517         if (extra->nativeChildrenForced)
       
   518             return;
       
   519         extra->nativeChildrenForced = 1;
       
   520 
       
   521         for (int i = 0; i < children.size(); ++i) {
       
   522             if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
       
   523                 child->setAttribute(Qt::WA_NativeWindow);
       
   524         }
       
   525     }
       
   526 
       
   527     inline bool nativeChildrenForced() const
       
   528     {
       
   529         return extra ? extra->nativeChildrenForced : false;
       
   530     }
       
   531 
       
   532     inline QRect effectiveRectFor(const QRect &rect) const
       
   533     {
       
   534         if (graphicsEffect && graphicsEffect->isEnabled())
       
   535             return graphicsEffect->boundingRectFor(rect).toAlignedRect();
       
   536         return rect;
       
   537     }
       
   538 
       
   539     QSize adjustedSize() const;
       
   540 
       
   541     inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
       
   542     {
       
   543         Q_Q(QWidget);
       
   544         if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
       
   545             QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
       
   546                     q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
       
   547             if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
       
   548                 QEvent event(QEvent::RequestSoftwareInputPanel);
       
   549                 QApplication::sendEvent(q, &event);
       
   550             }
       
   551         }
       
   552     }
       
   553 
       
   554 #ifndef Q_WS_QWS // Almost cross-platform :-)
       
   555     void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
       
   556 
       
   557     inline QPoint mapToWS(const QPoint &p) const
       
   558     { return p - data.wrect.topLeft(); }
       
   559 
       
   560     inline QPoint mapFromWS(const QPoint &p) const
       
   561     { return p + data.wrect.topLeft(); }
       
   562 
       
   563     inline QRect mapToWS(const QRect &r) const
       
   564     { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
       
   565 
       
   566     inline QRect mapFromWS(const QRect &r) const
       
   567     { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
       
   568 #endif
       
   569 
       
   570     // Variables.
       
   571     // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
       
   572     QWExtra *extra;
       
   573     QWidget *focus_next;
       
   574     QWidget *focus_prev;
       
   575     QWidget *focus_child;
       
   576     QLayout *layout;
       
   577     QRegion *needsFlush;
       
   578     QPaintDevice *redirectDev;
       
   579     QWidgetItemV2 *widgetItem;
       
   580     QPaintEngine *extraPaintEngine;
       
   581     mutable const QMetaObject *polished;
       
   582     QGraphicsEffect *graphicsEffect;
       
   583     // All widgets are added into the allWidgets set. Once
       
   584     // they receive a window id they are also added to the mapper.
       
   585     // This should just ensure that all widgets are deleted by QApplication
       
   586     static QWidgetMapper *mapper;
       
   587     static QWidgetSet *allWidgets;
       
   588 #if !defined(QT_NO_IM)
       
   589     QPointer<QInputContext> ic;
       
   590     Qt::InputMethodHints imHints;
       
   591 #endif
       
   592 #ifdef QT_KEYPAD_NAVIGATION
       
   593     static QPointer<QWidget> editingWidget;
       
   594 #endif
       
   595 
       
   596     // Implicit pointers (shared_null/shared_empty).
       
   597     QRegion opaqueChildren;
       
   598     QRegion dirty;
       
   599 #ifndef QT_NO_TOOLTIP
       
   600     QString toolTip;
       
   601 #endif
       
   602 #ifndef QT_NO_STATUSTIP
       
   603     QString statusTip;
       
   604 #endif
       
   605 #ifndef QT_NO_WHATSTHIS
       
   606     QString whatsThis;
       
   607 #endif
       
   608 #ifndef QT_NO_ACCESSIBILITY
       
   609     QString accessibleName;
       
   610     QString accessibleDescription;
       
   611 #endif
       
   612 
       
   613     // Other variables.
       
   614     uint inheritedFontResolveMask;
       
   615     uint inheritedPaletteResolveMask;
       
   616     short leftmargin;
       
   617     short topmargin;
       
   618     short rightmargin;
       
   619     short bottommargin;
       
   620     signed char leftLayoutItemMargin;
       
   621     signed char topLayoutItemMargin;
       
   622     signed char rightLayoutItemMargin;
       
   623     signed char bottomLayoutItemMargin;
       
   624     static int instanceCounter; // Current number of widget instances
       
   625     static int maxInstances; // Maximum number of widget instances
       
   626     Qt::HANDLE hd;
       
   627     QWidgetData data;
       
   628     QSizePolicy size_policy;
       
   629     QLocale locale;
       
   630     QPoint redirectOffset;
       
   631 #ifndef QT_NO_ACTION
       
   632     QList<QAction*> actions;
       
   633 #endif
       
   634     QMap<Qt::GestureType, Qt::GestureContext> gestureContext;
       
   635 
       
   636     // Bit fields.
       
   637     uint high_attributes[3]; // the low ones are in QWidget::widget_attributes
       
   638     QPalette::ColorRole fg_role : 8;
       
   639     QPalette::ColorRole bg_role : 8;
       
   640     uint dirtyOpaqueChildren : 1;
       
   641     uint isOpaque : 1;
       
   642     uint inDirtyList : 1;
       
   643     uint isScrolled : 1;
       
   644     uint isMoved : 1;
       
   645     uint usesDoubleBufferedGLContext : 1;
       
   646 
       
   647     // *************************** Platform specific ************************************
       
   648 #if defined(Q_WS_X11) // <----------------------------------------------------------- X11
       
   649     QX11Info xinfo;
       
   650     Qt::HANDLE picture;
       
   651     static QWidget *mouseGrabber;
       
   652     static QWidget *keyboardGrabber;
       
   653 
       
   654     void setWindowRole();
       
   655     void sendStartupMessage(const char *message) const;
       
   656     void setNetWmWindowTypes();
       
   657     void x11UpdateIsOpaque();
       
   658     bool isBackgroundInherited() const;
       
   659 #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
       
   660     uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
       
   661     uint nativeGesturePanEnabled : 1;
       
   662 
       
   663     bool shouldShowMaximizeButton();
       
   664     void winUpdateIsOpaque();
       
   665     void reparentChildren();
       
   666 #ifndef QT_NO_DRAGANDDROP
       
   667     QOleDropTarget *registerOleDnd(QWidget *widget);
       
   668     void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
       
   669 #endif
       
   670     void grabMouseWhileInWindow();
       
   671     void registerTouchWindow();
       
   672     void winSetupGestures();
       
   673 #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
       
   674     // This is new stuff
       
   675     uint needWindowChange : 1;
       
   676     uint isGLWidget : 1;
       
   677 
       
   678     // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
       
   679     // This list is used to update the gl context whenever a parent and a granparent
       
   680     // moves, and also to check for intersections with gl widgets within the window
       
   681     // when a widget moves.
       
   682     struct GlWidgetInfo
       
   683     {
       
   684         GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
       
   685         bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
       
   686         QWidget * widget;
       
   687         QWidget * lastUpdateWidget;
       
   688     };
       
   689 
       
   690     // dirtyOnWidget contains the areas in the widget that needs to be repained,
       
   691     // in the same way as dirtyOnScreen does for the window. Areas are added in
       
   692     // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
       
   693     // this information repaint invalid areas when widgets are scrolled.
       
   694     QRegion dirtyOnWidget;
       
   695     EventHandlerRef window_event;
       
   696     QList<GlWidgetInfo> glWidgets;
       
   697 
       
   698     //these are here just for code compat (HIViews)
       
   699     Qt::HANDLE qd_hd;
       
   700 
       
   701     void macUpdateSizeAttribute();
       
   702     void macUpdateHideOnSuspend();
       
   703     void macUpdateOpaqueSizeGrip();
       
   704     void macUpdateIgnoreMouseEvents();
       
   705     void macUpdateMetalAttribute();
       
   706     void macUpdateIsOpaque();
       
   707     void setEnabled_helper_sys(bool enable);
       
   708     bool isRealWindow() const;
       
   709     void adjustWithinMaxAndMinSize(int &w, int &h);
       
   710     void applyMaxAndMinSizeOnWindow();
       
   711     void update_sys(const QRect &rect);
       
   712     void update_sys(const QRegion &rgn);
       
   713     void setGeometry_sys_helper(int, int, int, int, bool);
       
   714     void setWindowModified_sys(bool b);
       
   715     void updateMaximizeButton_sys();
       
   716     void setWindowFilePath_sys(const QString &filePath);
       
   717     void createWindow_sys();
       
   718     void recreateMacWindow();
       
   719 #ifndef QT_MAC_USE_COCOA
       
   720     void initWindowPtr();
       
   721     void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
       
   722 #else
       
   723     void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
       
   724     void syncCocoaMask();
       
   725     void finishCocoaMaskSetup();
       
   726 #endif
       
   727     void determineWindowClass();
       
   728     void transferChildren();
       
   729     bool qt_mac_dnd_event(uint, DragRef);
       
   730     void toggleDrawers(bool);
       
   731     //mac event functions
       
   732     static bool qt_create_root_win();
       
   733     static void qt_clean_root_win();
       
   734     static bool qt_mac_update_sizer(QWidget *, int up = 0);
       
   735     static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
       
   736     static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
       
   737     static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
       
   738     void registerTouchWindow();
       
   739 #elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
       
   740     void setMaxWindowState_helper();
       
   741     void setFullScreenSize_helper();
       
   742     void moveSurface(QWindowSurface *surface, const QPoint &offset);
       
   743     QRegion localRequestedRegion() const;
       
   744     QRegion localAllocatedRegion() const;
       
   745 
       
   746     friend class QWSManager;
       
   747     friend class QWSManagerPrivate;
       
   748     friend class QDecoration;
       
   749 #ifndef QT_NO_CURSOR
       
   750     void updateCursor() const;
       
   751 #endif
       
   752     QScreen* getScreen() const;
       
   753 #elif defined(Q_OS_SYMBIAN) // <--------------------------------------------------------- SYMBIAN
       
   754     static QWidget *mouseGrabber;
       
   755     static QWidget *keyboardGrabber;
       
   756     void s60UpdateIsOpaque();
       
   757     void reparentChildren();
       
   758     void registerTouchWindow();
       
   759 #endif
       
   760 
       
   761 };
       
   762 
       
   763 struct QWidgetPaintContext
       
   764 {
       
   765     inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
       
   766                                QPainter *p, QWidgetBackingStore *b)
       
   767         : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
       
   768 
       
   769     QPaintDevice *pdev;
       
   770     QRegion rgn;
       
   771     QPoint offset;
       
   772     int flags;
       
   773     QPainter *sharedPainter;
       
   774     QWidgetBackingStore *backingStore;
       
   775     QPainter *painter;
       
   776 };
       
   777 
       
   778 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
       
   779 {
       
   780 public:
       
   781     QWidgetEffectSourcePrivate(QWidget *widget)
       
   782         : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
       
   783     {}
       
   784 
       
   785     inline void detach()
       
   786     { m_widget->setGraphicsEffect(0); }
       
   787 
       
   788     inline const QGraphicsItem *graphicsItem() const
       
   789     { return 0; }
       
   790 
       
   791     inline const QWidget *widget() const
       
   792     { return m_widget; }
       
   793 
       
   794     inline void update()
       
   795     {
       
   796         updateDueToGraphicsEffect = true;
       
   797         m_widget->update();
       
   798         updateDueToGraphicsEffect = false;
       
   799     }
       
   800 
       
   801     inline bool isPixmap() const
       
   802     { return false; }
       
   803 
       
   804     inline void effectBoundingRectChanged()
       
   805     {
       
   806         // ### This function should take a rect parameter; then we can avoid
       
   807         // updating too much on the parent widget.
       
   808         if (QWidget *parent = m_widget->parentWidget())
       
   809             parent->update();
       
   810         else
       
   811             update();
       
   812     }
       
   813 
       
   814     inline const QStyleOption *styleOption() const
       
   815     { return 0; }
       
   816 
       
   817     inline QRect deviceRect() const
       
   818     { return m_widget->window()->rect(); }
       
   819 
       
   820     QRectF boundingRect(Qt::CoordinateSystem system) const;
       
   821     void draw(QPainter *p);
       
   822     QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset) const;
       
   823 
       
   824     QWidget *m_widget;
       
   825     QWidgetPaintContext *context;
       
   826     QTransform lastEffectTransform;
       
   827     bool updateDueToGraphicsEffect;
       
   828 };
       
   829 
       
   830 inline QWExtra *QWidgetPrivate::extraData() const
       
   831 {
       
   832     return extra;
       
   833 }
       
   834 
       
   835 inline QTLWExtra *QWidgetPrivate::topData() const
       
   836 {
       
   837     const_cast<QWidgetPrivate *>(this)->createTLExtra();
       
   838     return extra->topextra;
       
   839 }
       
   840 
       
   841 inline QTLWExtra *QWidgetPrivate::maybeTopData() const
       
   842 {
       
   843     return extra ? extra->topextra : 0;
       
   844 }
       
   845 
       
   846 inline QPainter *QWidgetPrivate::sharedPainter() const
       
   847 {
       
   848     Q_Q(const QWidget);
       
   849     QTLWExtra *x = q->window()->d_func()->maybeTopData();
       
   850     return x ? x->sharedPainter : 0;
       
   851 }
       
   852 
       
   853 inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
       
   854 {
       
   855     Q_Q(QWidget);
       
   856     QTLWExtra *x = q->window()->d_func()->topData();
       
   857     x->sharedPainter = painter;
       
   858 }
       
   859 
       
   860 inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
       
   861 {
       
   862     Q_Q(const QWidget);
       
   863     QTLWExtra *x = q->window()->d_func()->maybeTopData();
       
   864     return x ? x->backingStore : 0;
       
   865 }
       
   866 
       
   867 QT_END_NAMESPACE
       
   868 
       
   869 #endif // QWIDGET_P_H