~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/widgets/kernel/qwidget_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtGui module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QWIDGET_P_H
 
43
#define QWIDGET_P_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
49
// This file is not part of the Qt API.  It exists for the convenience
 
50
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp.  This header
 
51
// file may change from version to version without notice, or even be removed.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
56
#include "QtWidgets/qwidget.h"
 
57
#include "private/qobject_p.h"
 
58
#include "QtCore/qrect.h"
 
59
#include "QtCore/qlocale.h"
 
60
#include "QtCore/qset.h"
 
61
#include "QtGui/qregion.h"
 
62
#include "QtGui/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>
 
71
 
 
72
QT_BEGIN_NAMESPACE
 
73
 
 
74
// Extra QWidget data
 
75
//  - to minimize memory usage for members that are seldom used.
 
76
//  - top-level widgets have extra extra data to reduce cost further
 
77
class QWidgetWindow;
 
78
class QPaintEngine;
 
79
class QPixmap;
 
80
class QWidgetBackingStore;
 
81
class QGraphicsProxyWidget;
 
82
class QWidgetItemV2;
 
83
 
 
84
class QStyle;
 
85
 
 
86
class QUnifiedToolbarSurface;
 
87
 
 
88
// implemented in qshortcut.cpp
 
89
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context);
 
90
 
 
91
class QUpdateLaterEvent : public QEvent
 
92
{
 
93
public:
 
94
    explicit QUpdateLaterEvent(const QRegion& paintRegion)
 
95
        : QEvent(UpdateLater), m_region(paintRegion)
 
96
    {
 
97
    }
 
98
 
 
99
    ~QUpdateLaterEvent()
 
100
    {
 
101
    }
 
102
 
 
103
    inline const QRegion &region() const { return m_region; }
 
104
 
 
105
protected:
 
106
    QRegion m_region;
 
107
};
 
108
 
 
109
 
 
110
 
 
111
class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker
 
112
{
 
113
 
 
114
public:
 
115
    QWidgetBackingStoreTracker();
 
116
    ~QWidgetBackingStoreTracker();
 
117
 
 
118
    void create(QWidget *tlw);
 
119
    void destroy();
 
120
 
 
121
    void registerWidget(QWidget *w);
 
122
    void unregisterWidget(QWidget *w);
 
123
    void unregisterWidgetSubtree(QWidget *w);
 
124
 
 
125
    inline QWidgetBackingStore* data()
 
126
    {
 
127
        return m_ptr;
 
128
    }
 
129
 
 
130
    inline QWidgetBackingStore* operator->()
 
131
    {
 
132
        return m_ptr;
 
133
    }
 
134
 
 
135
    inline QWidgetBackingStore& operator*()
 
136
    {
 
137
        return *m_ptr;
 
138
    }
 
139
 
 
140
    inline operator bool() const
 
141
    {
 
142
        return (0 != m_ptr);
 
143
    }
 
144
 
 
145
private:
 
146
    Q_DISABLE_COPY(QWidgetBackingStoreTracker)
 
147
 
 
148
private:
 
149
    QWidgetBackingStore* m_ptr;
 
150
    QSet<QWidget *> m_widgets;
 
151
};
 
152
 
 
153
struct QTLWExtra {
 
154
    // *************************** Cross-platform variables *****************************
 
155
 
 
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;
 
161
 
 
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
 
167
 
 
168
    // Other variables.
 
169
    short incw, inch; // size increments
 
170
    short basew, baseh; // base sizes
 
171
     // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
 
172
    QRect frameStrut;
 
173
    QRect normalGeometry; // used by showMin/maximized/FullScreen
 
174
    Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
 
175
 
 
176
    // *************************** Cross-platform bit fields ****************************
 
177
    uint opacity : 8;
 
178
    uint posIncludesFrame : 1;
 
179
    uint sizeAdjusted : 1;
 
180
    uint inTopLevelResize : 1;
 
181
    uint inRepaint : 1;
 
182
    uint embedded : 1;
 
183
 
 
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;
 
193
#ifndef QT_NO_XSYNC
 
194
    WId syncUpdateCounter;
 
195
    ulong syncRequestTimestamp;
 
196
    qint32 newCounterValueHi;
 
197
    quint32 newCounterValueLo;
 
198
#endif
 
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
 
204
    uint resizer : 4;
 
205
    uint isSetGeometry : 1;
 
206
    uint isMove : 1;
 
207
    quint32 wattr;
 
208
    quint32 wclass;
 
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
 
213
    // manually resized.
 
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.
 
216
    bool wasMaximized;
 
217
#endif
 
218
    QWidgetWindow *window;
 
219
    quint32 screenIndex; // index in qplatformscreenlist
 
220
};
 
221
 
 
222
struct QWExtra {
 
223
    // *************************** Cross-platform variables *****************************
 
224
 
 
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
 
230
#endif
 
231
#ifndef QT_NO_CURSOR
 
232
    QCursor *curs;
 
233
#endif
 
234
    QPointer<QStyle> style;
 
235
    QPointer<QWidget> focus_proxy;
 
236
 
 
237
    // Implicit pointers (shared_empty/shared_null).
 
238
    QRegion mask; // widget mask
 
239
    QString styleSheet;
 
240
 
 
241
    // Other variables.
 
242
    qint32 minw;
 
243
    qint32 minh; // minimum size
 
244
    qint32 maxw;
 
245
    qint32 maxh; // maximum size
 
246
    quint16 customDpiX;
 
247
    quint16 customDpiY;
 
248
    QSize staticContentsSize;
 
249
 
 
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;
 
256
    uint hasMask : 1;
 
257
 
 
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;
 
263
#endif
 
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
 
268
    // Cocoa Mask stuff
 
269
    QImage maskBits;
 
270
    CGImageRef imageMask;
 
271
#endif
 
272
};
 
273
 
 
274
/*!
 
275
    \internal
 
276
 
 
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.
 
281
*/
 
282
static inline bool bypassGraphicsProxyWidget(const QWidget *p)
 
283
{
 
284
    while (p) {
 
285
        if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
 
286
            return true;
 
287
        p = p->parentWidget();
 
288
    }
 
289
    return false;
 
290
}
 
291
 
 
292
class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
 
293
{
 
294
    Q_DECLARE_PUBLIC(QWidget)
 
295
 
 
296
public:
 
297
    // *************************** Cross-platform ***************************************
 
298
    enum DrawWidgetFlags {
 
299
        DrawAsRoot = 0x01,
 
300
        DrawPaintOnScreen = 0x02,
 
301
        DrawRecursive = 0x04,
 
302
        DrawInvisible = 0x08,
 
303
        DontSubtractOpaqueChildren = 0x10,
 
304
        DontDrawOpaqueChildren = 0x20,
 
305
        DontDrawNativeChildren = 0x40,
 
306
        DontSetCompositionMode = 0x80
 
307
    };
 
308
 
 
309
    enum CloseMode {
 
310
        CloseNoEvent,
 
311
        CloseWithEvent,
 
312
        CloseWithSpontaneousEvent
 
313
    };
 
314
 
 
315
    enum Direction {
 
316
        DirectionNorth = 0x01,
 
317
        DirectionEast = 0x10,
 
318
        DirectionSouth = 0x02,
 
319
        DirectionWest = 0x20
 
320
    };
 
321
 
 
322
    // Functions.
 
323
    explicit QWidgetPrivate(int version = QObjectPrivateVersion);
 
324
    ~QWidgetPrivate();
 
325
 
 
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);
 
336
 
 
337
    void createTLExtra();
 
338
    void createExtra();
 
339
    void deleteExtra();
 
340
    void createSysExtra();
 
341
    void deleteSysExtra();
 
342
    void createTLSysExtra();
 
343
    void deleteTLSysExtra();
 
344
    void updateSystemBackground();
 
345
    void propagatePaletteChange();
 
346
 
 
347
    void setPalette_helper(const QPalette &);
 
348
    void resolvePalette();
 
349
    QPalette naturalWidgetPalette(uint inheritedMask) const;
 
350
 
 
351
    void setMask_sys(const QRegion &);
 
352
 
 
353
    void raise_sys();
 
354
    void lower_sys();
 
355
    void stackUnder_sys(QWidget *);
 
356
 
 
357
    void setFocus_sys();
 
358
    void updateFocusChild();
 
359
 
 
360
    void updateFont(const QFont &);
 
361
    inline void setFont_helper(const QFont &font) {
 
362
        if (data.fnt == font && data.fnt.resolve() == font.resolve())
 
363
            return;
 
364
        updateFont(font);
 
365
    }
 
366
    void resolveFont();
 
367
    QFont naturalWidgetFont(uint inheritedMask) const;
 
368
 
 
369
    void setLayoutDirection_helper(Qt::LayoutDirection);
 
370
    void resolveLayoutDirection();
 
371
 
 
372
    void setLocale_helper(const QLocale &l, bool forceUpdate = false);
 
373
    void resolveLocale();
 
374
 
 
375
    void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
 
376
    void inheritStyle();
 
377
 
 
378
    void setUpdatesEnabled_helper(bool );
 
379
 
 
380
    void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
 
381
    bool isAboutToShow() const;
 
382
    QRegion prepareToRender(const QRegion &region, 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);
 
389
 
 
390
 
 
391
    void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
 
392
                                const QRegion &rgn, const QPoint &offset, int flags,
 
393
                                QPainter *sharedPainter, QWidgetBackingStore *backingStore);
 
394
 
 
395
 
 
396
    QPainter *beginSharedPainter();
 
397
    bool endSharedPainter();
 
398
#ifndef QT_NO_GRAPHICSVIEW
 
399
    static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
 
400
#endif
 
401
    void repaint_sys(const QRegion &rgn);
 
402
 
 
403
    QRect clipRect() const;
 
404
    QRegion clipRegion() const;
 
405
    void setSystemClip(QPaintDevice *paintDevice, const QRegion &region);
 
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 &region) 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
 
417
 
 
418
    const QRegion &getOpaqueChildren() const;
 
419
    void setDirtyOpaqueRegion();
 
420
 
 
421
    bool close_helper(CloseMode mode);
 
422
 
 
423
    void setWindowIcon_helper();
 
424
    void setWindowIcon_sys();
 
425
    void setWindowOpacity_sys(qreal opacity);
 
426
    void adjustQuitOnCloseAttribute();
 
427
 
 
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 &region);
 
438
 
 
439
    // tells the input method about the widgets transform
 
440
    void updateWidgetTransform();
 
441
 
 
442
    void reparentFocusWidgets(QWidget *oldtlw);
 
443
 
 
444
    static int pointToRect(const QPoint &p, const QRect &r);
 
445
 
 
446
    void setWinId(WId);
 
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();
 
458
    void show_helper();
 
459
    void show_sys();
 
460
    void hide_sys();
 
461
    void hide_helper();
 
462
    void _q_showIfNotHidden();
 
463
 
 
464
    void setEnabled_helper(bool);
 
465
    void registerDropSite(bool);
 
466
    static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
 
467
 
 
468
    void updateFrameStrut();
 
469
    QRect frameStrut() const;
 
470
 
 
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);
 
476
#endif
 
477
 
 
478
    void setWindowIconText_sys(const QString &cap);
 
479
    void setWindowIconText_helper(const QString &cap);
 
480
    void setWindowTitle_sys(const QString &cap);
 
481
    void setWindowFilePath_sys(const QString &filePath);
 
482
 
 
483
#ifndef QT_NO_CURSOR
 
484
    void setCursor_sys(const QCursor &cursor);
 
485
    void unsetCursor_sys();
 
486
#endif
 
487
 
 
488
    void setWindowTitle_helper(const QString &cap);
 
489
    void setWindowFilePath_helper(const QString &filePath);
 
490
    void setWindowModified_helper();
 
491
 
 
492
    bool setMinimumSize_helper(int &minw, int &minh);
 
493
    bool setMaximumSize_helper(int &maxw, int &maxh);
 
494
    void setConstraints_sys();
 
495
    bool pointInsideRectAndMask(const QPoint &) const;
 
496
    QWidget *childAt_helper(const QPoint &, bool) const;
 
497
    QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
 
498
    void updateGeometry_helper(bool forceUpdate);
 
499
 
 
500
    void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
 
501
    void setLayoutItemMargins(int left, int top, int right, int bottom);
 
502
    void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
 
503
 
 
504
    // aboutToDestroy() is called just before the contents of
 
505
    // QWidget::destroy() is executed. It's used to signal QWidget
 
506
    // sub-classes that their internals are about to be released.
 
507
    virtual void aboutToDestroy() {}
 
508
 
 
509
    inline QWidget *effectiveFocusWidget() {
 
510
        QWidget *w = q_func();
 
511
        while (w->focusProxy())
 
512
            w = w->focusProxy();
 
513
        return w;
 
514
    }
 
515
 
 
516
    void setModal_sys();
 
517
 
 
518
    // This is an helper function that return the available geometry for
 
519
    // a widget and takes care is this one is in QGraphicsView.
 
520
    // If the widget is not embed in a scene then the geometry available is
 
521
    // null, we let QDesktopWidget decide for us.
 
522
    static QRect screenGeometry(const QWidget *widget)
 
523
    {
 
524
        QRect screen;
 
525
#ifndef QT_NO_GRAPHICSVIEW
 
526
        QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
 
527
        //It's embedded if it has an ancestor
 
528
        if (ancestorProxy) {
 
529
            if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
 
530
                // One view, let be smart and return the viewport rect then the popup is aligned
 
531
                if (ancestorProxy->scene()->views().size() == 1) {
 
532
                    QGraphicsView *view = ancestorProxy->scene()->views().at(0);
 
533
                    screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
 
534
                } else {
 
535
                    screen = ancestorProxy->scene()->sceneRect().toRect();
 
536
                }
 
537
            }
 
538
        }
 
539
#endif
 
540
        return screen;
 
541
    }
 
542
 
 
543
    inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
 
544
    {
 
545
        Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
 
546
        redirectDev = replacement;
 
547
        redirectOffset = offset;
 
548
    }
 
549
 
 
550
    inline QPaintDevice *redirected(QPoint *offset) const
 
551
    {
 
552
        if (offset)
 
553
            *offset = redirectDev ? redirectOffset : QPoint();
 
554
        return redirectDev;
 
555
    }
 
556
 
 
557
    inline void restoreRedirected()
 
558
    { redirectDev = 0; }
 
559
 
 
560
    inline void enforceNativeChildren()
 
561
    {
 
562
        if (!extra)
 
563
            createExtra();
 
564
 
 
565
        if (extra->nativeChildrenForced)
 
566
            return;
 
567
        extra->nativeChildrenForced = 1;
 
568
 
 
569
        for (int i = 0; i < children.size(); ++i) {
 
570
            if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
 
571
                child->setAttribute(Qt::WA_NativeWindow);
 
572
        }
 
573
    }
 
574
 
 
575
    inline bool nativeChildrenForced() const
 
576
    {
 
577
        return extra ? extra->nativeChildrenForced : false;
 
578
    }
 
579
 
 
580
    inline QRect effectiveRectFor(const QRect &rect) const
 
581
    {
 
582
#ifndef QT_NO_GRAPHICSEFFECT
 
583
        if (graphicsEffect && graphicsEffect->isEnabled())
 
584
            return graphicsEffect->boundingRectFor(rect).toAlignedRect();
 
585
#endif //QT_NO_GRAPHICSEFFECT
 
586
        return rect;
 
587
    }
 
588
 
 
589
    QSize adjustedSize() const;
 
590
 
 
591
    inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
 
592
    {
 
593
        Q_Q(QWidget);
 
594
        if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
 
595
            QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
 
596
                    q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
 
597
            if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
 
598
                qApp->inputMethod()->show();
 
599
            }
 
600
        }
 
601
    }
 
602
 
 
603
    void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
 
604
 
 
605
    inline QPoint mapToWS(const QPoint &p) const
 
606
    { return p - data.wrect.topLeft(); }
 
607
 
 
608
    inline QPoint mapFromWS(const QPoint &p) const
 
609
    { return p + data.wrect.topLeft(); }
 
610
 
 
611
    inline QRect mapToWS(const QRect &r) const
 
612
    { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
 
613
 
 
614
    inline QRect mapFromWS(const QRect &r) const
 
615
    { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
 
616
 
 
617
    // Variables.
 
618
    // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
 
619
    QWExtra *extra;
 
620
    QWidget *focus_next;
 
621
    QWidget *focus_prev;
 
622
    QWidget *focus_child;
 
623
    QLayout *layout;
 
624
    QRegion *needsFlush;
 
625
    QPaintDevice *redirectDev;
 
626
    QWidgetItemV2 *widgetItem;
 
627
    QPaintEngine *extraPaintEngine;
 
628
    mutable const QMetaObject *polished;
 
629
    QGraphicsEffect *graphicsEffect;
 
630
    // All widgets are added into the allWidgets set. Once
 
631
    // they receive a window id they are also added to the mapper.
 
632
    // This should just ensure that all widgets are deleted by QApplication
 
633
    static QWidgetMapper *mapper;
 
634
    static QWidgetSet *allWidgets;
 
635
#if !defined(QT_NO_IM)
 
636
    Qt::InputMethodHints imHints;
 
637
#endif
 
638
#ifdef QT_KEYPAD_NAVIGATION
 
639
    static QPointer<QWidget> editingWidget;
 
640
#endif
 
641
 
 
642
    // Implicit pointers (shared_null/shared_empty).
 
643
    QRegion opaqueChildren;
 
644
    QRegion dirty;
 
645
#ifndef QT_NO_TOOLTIP
 
646
    QString toolTip;
 
647
#endif
 
648
#ifndef QT_NO_STATUSTIP
 
649
    QString statusTip;
 
650
#endif
 
651
#ifndef QT_NO_WHATSTHIS
 
652
    QString whatsThis;
 
653
#endif
 
654
#ifndef QT_NO_ACCESSIBILITY
 
655
    QString accessibleName;
 
656
    QString accessibleDescription;
 
657
#endif
 
658
 
 
659
    // Other variables.
 
660
    uint inheritedFontResolveMask;
 
661
    uint inheritedPaletteResolveMask;
 
662
    short leftmargin;
 
663
    short topmargin;
 
664
    short rightmargin;
 
665
    short bottommargin;
 
666
    signed char leftLayoutItemMargin;
 
667
    signed char topLayoutItemMargin;
 
668
    signed char rightLayoutItemMargin;
 
669
    signed char bottomLayoutItemMargin;
 
670
    static int instanceCounter; // Current number of widget instances
 
671
    static int maxInstances; // Maximum number of widget instances
 
672
    Qt::HANDLE hd;
 
673
    QWidgetData data;
 
674
    QSizePolicy size_policy;
 
675
    QLocale locale;
 
676
    QPoint redirectOffset;
 
677
#ifndef QT_NO_ACTION
 
678
    QList<QAction*> actions;
 
679
#endif
 
680
#ifndef QT_NO_GESTURES
 
681
    QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
 
682
#endif
 
683
 
 
684
    // Bit fields.
 
685
    uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
 
686
    QPalette::ColorRole fg_role : 8;
 
687
    QPalette::ColorRole bg_role : 8;
 
688
    uint dirtyOpaqueChildren : 1;
 
689
    uint isOpaque : 1;
 
690
    uint inDirtyList : 1;
 
691
    uint isScrolled : 1;
 
692
    uint isMoved : 1;
 
693
    uint usesDoubleBufferedGLContext : 1;
 
694
#ifndef QT_NO_IM
 
695
    uint inheritsInputMethodHints : 1;
 
696
#endif
 
697
 
 
698
    // *************************** Platform specific ************************************
 
699
#if defined(Q_OS_WIN)
 
700
    uint noPaintOnScreen : 1; // see qwidget_qpa.cpp ::paintEngine()
 
701
#endif
 
702
#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
 
703
    Qt::HANDLE picture;
 
704
    static QWidget *mouseGrabber;
 
705
    static QWidget *keyboardGrabber;
 
706
 
 
707
    void setWindowRole();
 
708
    void sendStartupMessage(const char *message) const;
 
709
    void setNetWmWindowTypes();
 
710
    void x11UpdateIsOpaque();
 
711
    bool isBackgroundInherited() const;
 
712
    void updateX11AcceptFocus();
 
713
    QPoint mapToGlobal(const QPoint &pos) const;
 
714
    QPoint mapFromGlobal(const QPoint &pos) const;
 
715
#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
 
716
#ifndef QT_NO_GESTURES
 
717
    uint nativeGesturePanEnabled : 1;
 
718
#endif
 
719
    bool shouldShowMaximizeButton();
 
720
    void winUpdateIsOpaque();
 
721
    void reparentChildren();
 
722
#ifndef QT_NO_DRAGANDDROP
 
723
    QOleDropTarget *registerOleDnd(QWidget *widget);
 
724
    void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
 
725
#endif
 
726
    void grabMouseWhileInWindow();
 
727
    void registerTouchWindow();
 
728
    void winSetupGestures();
 
729
#elif defined(Q_OS_MAC) // <--------------------------------------------------------- MAC
 
730
    void macUpdateSizeAttribute();
 
731
#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC (old stuff)
 
732
    // This is new stuff
 
733
    uint needWindowChange : 1;
 
734
 
 
735
    // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
 
736
    // This list is used to update the gl context whenever a parent and a granparent
 
737
    // moves, and also to check for intersections with gl widgets within the window
 
738
    // when a widget moves.
 
739
    struct GlWidgetInfo
 
740
    {
 
741
        GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
 
742
        bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
 
743
        QWidget * widget;
 
744
        QWidget * lastUpdateWidget;
 
745
    };
 
746
 
 
747
    // dirtyOnWidget contains the areas in the widget that needs to be repained,
 
748
    // in the same way as dirtyOnScreen does for the window. Areas are added in
 
749
    // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
 
750
    // this information repaint invalid areas when widgets are scrolled.
 
751
    QRegion dirtyOnWidget;
 
752
    EventHandlerRef window_event;
 
753
    QList<GlWidgetInfo> glWidgets;
 
754
 
 
755
    //these are here just for code compat (HIViews)
 
756
    Qt::HANDLE qd_hd;
 
757
 
 
758
    void macUpdateHideOnSuspend();
 
759
    void macUpdateOpaqueSizeGrip();
 
760
    void macUpdateIgnoreMouseEvents();
 
761
    void macUpdateMetalAttribute();
 
762
    void macUpdateIsOpaque();
 
763
    void macSetNeedsDisplay(QRegion region);
 
764
    void setEnabled_helper_sys(bool enable);
 
765
    bool isRealWindow() const;
 
766
    void adjustWithinMaxAndMinSize(int &w, int &h);
 
767
    void applyMaxAndMinSizeOnWindow();
 
768
    void update_sys(const QRect &rect);
 
769
    void update_sys(const QRegion &rgn);
 
770
    void setGeometry_sys_helper(int, int, int, int, bool);
 
771
    void updateMaximizeButton_sys();
 
772
    void createWindow_sys();
 
773
    void recreateMacWindow();
 
774
    void setSubWindowStacking(bool set);
 
775
    void setWindowLevel();
 
776
    void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
 
777
    void syncCocoaMask();
 
778
    void finishCocoaMaskSetup();
 
779
    void syncUnifiedMode();
 
780
    // Did we add the drawRectOriginal method?
 
781
    bool drawRectOriginalAdded;
 
782
    // Is the original drawRect method available?
 
783
    bool originalDrawMethod;
 
784
    // Do we need to change the methods?
 
785
    bool changeMethods;
 
786
 
 
787
    // Unified toolbar variables
 
788
    bool isInUnifiedToolbar;
 
789
    QUnifiedToolbarSurface *unifiedSurface;
 
790
    QPoint toolbar_offset;
 
791
    QWidget *toolbar_ancestor;
 
792
    bool flushRequested;
 
793
    bool touchEventsEnabled;
 
794
    void determineWindowClass();
 
795
    void transferChildren();
 
796
    bool qt_mac_dnd_event(uint, DragRef);
 
797
    void toggleDrawers(bool);
 
798
    //mac event functions
 
799
    static bool qt_create_root_win();
 
800
    static void qt_clean_root_win();
 
801
    static bool qt_mac_update_sizer(QWidget *, int up = 0);
 
802
    static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
 
803
    static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
 
804
    static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
 
805
    void registerTouchWindow(bool enable = true);
 
806
#endif
 
807
    bool stealKeyboardGrab(bool grab);
 
808
    bool stealMouseGrab(bool grab);
 
809
};
 
810
 
 
811
struct QWidgetPaintContext
 
812
{
 
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) {}
 
816
 
 
817
    QPaintDevice *pdev;
 
818
    QRegion rgn;
 
819
    QPoint offset;
 
820
    int flags;
 
821
    QPainter *sharedPainter;
 
822
    QWidgetBackingStore *backingStore;
 
823
    QPainter *painter;
 
824
};
 
825
 
 
826
#ifndef QT_NO_GRAPHICSEFFECT
 
827
class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
 
828
{
 
829
public:
 
830
    QWidgetEffectSourcePrivate(QWidget *widget)
 
831
        : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
 
832
    {}
 
833
 
 
834
    inline void detach()
 
835
    { m_widget->d_func()->graphicsEffect = 0; }
 
836
 
 
837
    inline const QGraphicsItem *graphicsItem() const
 
838
    { return 0; }
 
839
 
 
840
    inline const QWidget *widget() const
 
841
    { return m_widget; }
 
842
 
 
843
    inline void update()
 
844
    {
 
845
        updateDueToGraphicsEffect = true;
 
846
        m_widget->update();
 
847
        updateDueToGraphicsEffect = false;
 
848
    }
 
849
 
 
850
    inline bool isPixmap() const
 
851
    { return false; }
 
852
 
 
853
    inline void effectBoundingRectChanged()
 
854
    {
 
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())
 
858
            parent->update();
 
859
        else
 
860
            update();
 
861
    }
 
862
 
 
863
    inline const QStyleOption *styleOption() const
 
864
    { return 0; }
 
865
 
 
866
    inline QRect deviceRect() const
 
867
    { return m_widget->window()->rect(); }
 
868
 
 
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;
 
873
 
 
874
    QWidget *m_widget;
 
875
    QWidgetPaintContext *context;
 
876
    QTransform lastEffectTransform;
 
877
    bool updateDueToGraphicsEffect;
 
878
};
 
879
#endif //QT_NO_GRAPHICSEFFECT
 
880
 
 
881
inline QWExtra *QWidgetPrivate::extraData() const
 
882
{
 
883
    return extra;
 
884
}
 
885
 
 
886
inline QTLWExtra *QWidgetPrivate::topData() const
 
887
{
 
888
    const_cast<QWidgetPrivate *>(this)->createTLExtra();
 
889
    return extra->topextra;
 
890
}
 
891
 
 
892
inline QTLWExtra *QWidgetPrivate::maybeTopData() const
 
893
{
 
894
    return extra ? extra->topextra : 0;
 
895
}
 
896
 
 
897
inline QPainter *QWidgetPrivate::sharedPainter() const
 
898
{
 
899
    Q_Q(const QWidget);
 
900
    QTLWExtra *x = q->window()->d_func()->maybeTopData();
 
901
    return x ? x->sharedPainter : 0;
 
902
}
 
903
 
 
904
inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
 
905
{
 
906
    Q_Q(QWidget);
 
907
    QTLWExtra *x = q->window()->d_func()->topData();
 
908
    x->sharedPainter = painter;
 
909
}
 
910
 
 
911
inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
 
912
{
 
913
    Q_Q(const QWidget);
 
914
    return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
 
915
                                     || extra->mask.contains(p));
 
916
}
 
917
 
 
918
inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
 
919
{
 
920
    Q_Q(const QWidget);
 
921
    QTLWExtra *x = q->window()->d_func()->maybeTopData();
 
922
    return x ? x->backingStoreTracker.data() : 0;
 
923
}
 
924
 
 
925
QT_END_NAMESPACE
 
926
 
 
927
#endif // QWIDGET_P_H