source: trunk/src/gui/kernel/qwidget_p.h

Last change on this file was 1034, checked in by Dmitry A. Kuminov, 14 years ago

OS/2: Disable native window masking code as it is not complete.

This code is only necessary for child widgets that have native windows.
Applications using this approach are very rare (they include e.g. video
players that paint to Qt widgets on their own using native window IDs)
and they don't need masking in these widgets or their ancestors anyway.

The current implementation lacks some functionality -- in particular, it
cannot properly issue WM_VRNENABLED/WM_VRNDISABLED notifications
which breaks those video players, so that keeping it enabled makes little
to no sense.

The relevant code remains in place but guarded by the
QT_PM_NATIVEWIDGETMASK compiler macro so that it can be enabled
as needed for further experiments. See also #203 for more details.

File size: 33.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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_PM
77#include "QtCore/qt_os2.h"
78#endif
79
80#ifdef Q_WS_X11
81#include "QtGui/qx11info_x11.h"
82#endif
83
84#ifdef Q_WS_MAC
85#include <private/qt_mac_p.h>
86#endif
87
88#if defined(Q_WS_QWS)
89#include "QtGui/qinputcontext.h"
90#include "QtGui/qscreen_qws.h"
91#endif
92
93#if defined(Q_OS_SYMBIAN)
94class RDrawableWindow;
95class CCoeControl;
96#endif
97
98QT_BEGIN_NAMESPACE
99
100// Extra QWidget data
101// - to minimize memory usage for members that are seldom used.
102// - top-level widgets have extra extra data to reduce cost further
103#if defined(Q_WS_QWS)
104class QWSManager;
105#endif
106#if defined(Q_WS_MAC)
107class QCoreGraphicsPaintEnginePrivate;
108#endif
109class QPaintEngine;
110class QPixmap;
111class QWidgetBackingStore;
112class QGraphicsProxyWidget;
113class QWidgetItemV2;
114
115class QStyle;
116
117class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker
118{
119
120public:
121 QWidgetBackingStoreTracker();
122 ~QWidgetBackingStoreTracker();
123
124 void create(QWidget *tlw);
125 void destroy();
126
127 void registerWidget(QWidget *w);
128 void unregisterWidget(QWidget *w);
129 void unregisterWidgetSubtree(QWidget *w);
130
131 inline QWidgetBackingStore* data()
132 {
133 return m_ptr;
134 }
135
136 inline QWidgetBackingStore* operator->()
137 {
138 return m_ptr;
139 }
140
141 inline QWidgetBackingStore& operator*()
142 {
143 return *m_ptr;
144 }
145
146 inline operator bool() const
147 {
148 return (0 != m_ptr);
149 }
150
151private:
152 Q_DISABLE_COPY(QWidgetBackingStoreTracker)
153
154private:
155 QWidgetBackingStore* m_ptr;
156 QSet<QWidget *> m_widgets;
157};
158
159struct QTLWExtra {
160 // *************************** Cross-platform variables *****************************
161
162 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
163 QIcon *icon; // widget icon
164 QPixmap *iconPixmap;
165 QWidgetBackingStoreTracker backingStore;
166 QWindowSurface *windowSurface;
167 QPainter *sharedPainter;
168
169 // Implicit pointers (shared_null).
170 QString caption; // widget caption
171 QString iconText; // widget icon text
172 QString role; // widget role
173 QString filePath; // widget file path
174
175 // Other variables.
176 short incw, inch; // size increments
177 short basew, baseh; // base sizes
178 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
179 QRect frameStrut;
180 QRect normalGeometry; // used by showMin/maximized/FullScreen
181 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
182
183 // *************************** Cross-platform bit fields ****************************
184 uint opacity : 8;
185 uint posFromMove : 1;
186 uint sizeAdjusted : 1;
187 uint inTopLevelResize : 1;
188 uint inRepaint : 1;
189 uint embedded : 1;
190
191 // *************************** Platform specific values (bit fields first) **********
192#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
193 uint spont_unmapped: 1; // window was spontaneously unmapped
194 uint dnd : 1; // DND properties installed
195 uint validWMState : 1; // is WM_STATE valid?
196 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
197 WId parentWinId; // parent window Id (valid after reparenting)
198 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
199 QPoint fullScreenOffset;
200#ifndef QT_NO_XSYNC
201 WId syncUpdateCounter;
202 ulong syncRequestTimestamp;
203 qint32 newCounterValueHi;
204 quint32 newCounterValueLo;
205#endif
206#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
207 uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered.
208 HICON winIconBig; // internal big Windows icon
209 HICON winIconSmall; // internal small Windows icon
210#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
211 uint resizer : 4;
212 uint isSetGeometry : 1;
213 uint isMove : 1;
214 quint32 wattr;
215 quint32 wclass;
216 WindowGroupRef group;
217 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
218 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
219#ifdef QT_MAC_USE_COCOA
220 // This value is just to make sure we maximize and restore to the right location, yet we allow apps to be maximized and
221 // manually resized.
222 // The name is misleading, since this is set when maximizing the window. It is a hint to saveGeometry(..) to record the
223 // starting position as 0,0 instead of the normal starting position.
224 bool wasMaximized;
225#endif // QT_MAC_USE_COCOA
226
227#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
228#ifndef QT_NO_QWS_MANAGER
229 QWSManager *qwsManager;
230#endif
231#elif defined(Q_OS_SYMBIAN)
232 uint inExpose : 1; // Prevents drawing recursion
233 uint nativeWindowTransparencyEnabled : 1; // Tracks native window transparency
234#elif defined(Q_WS_PM)
235 HWND fId;
236 HSWITCH swEntry;
237 HPOINTER iconPointer;
238 QWidget *modalBlocker;
239#endif
240};
241
242struct QWExtra {
243 // *************************** Cross-platform variables *****************************
244
245 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
246 void *glContext; // if the widget is hijacked by QGLWindowSurface
247 QTLWExtra *topextra; // only useful for TLWs
248#ifndef QT_NO_GRAPHICSVIEW
249 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
250#endif
251#ifndef QT_NO_CURSOR
252 QCursor *curs;
253#endif
254 QPointer<QStyle> style;
255 QPointer<QWidget> focus_proxy;
256
257 // Implicit pointers (shared_empty/shared_null).
258 QRegion mask; // widget mask
259 QString styleSheet;
260
261 // Other variables.
262 qint32 minw;
263 qint32 minh; // minimum size
264 qint32 maxw;
265 qint32 maxh; // maximum size
266 quint16 customDpiX;
267 quint16 customDpiY;
268 QSize staticContentsSize;
269
270 // *************************** Cross-platform bit fields ****************************
271 uint explicitMinSize : 2;
272 uint explicitMaxSize : 2;
273 uint autoFillBackground : 1;
274 uint nativeChildrenForced : 1;
275 uint inRenderWithPainter : 1;
276 uint hasMask : 1;
277
278 // *************************** Platform specific values (bit fields first) **********
279#if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
280#ifndef QT_NO_DRAGANDDROP
281 QOleDropTarget *dropTarget; // drop target
282 QList<QPointer<QWidget> > oleDropWidgets;
283#endif
284#elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
285 uint compress_events : 1;
286 WId xDndProxy; // XDND forwarding to embedded windows
287#elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
288#ifdef QT_MAC_USE_COCOA
289 // Cocoa Mask stuff
290 QImage maskBits;
291 CGImageRef imageMask;
292#endif
293#elif defined(Q_OS_SYMBIAN) // <----------------------------------------------------- Symbian
294 uint activated : 1; // RWindowBase::Activated has been called
295
296 /**
297 * If this bit is set, each native widget receives the signals from the
298 * Symbian control immediately before and immediately after draw ops are
299 * sent to the window server for this control:
300 * void beginNativePaintEvent(const QRect &paintRect);
301 * void endNativePaintEvent(const QRect &paintRect);
302 */
303 uint receiveNativePaintEvents : 1;
304
305 /**
306 * Defines the behaviour of QSymbianControl::Draw.
307 */
308 enum NativePaintMode {
309 /**
310 * Normal drawing mode: blits the required region of the backing store
311 * via WSERV.
312 */
313 Blit,
314
315 /**
316 * Disable drawing for this widget.
317 */
318 Disable,
319
320 /**
321 * Paint zeros into the WSERV framebuffer, using BitGDI APIs. For windows
322 * with an EColor16MU display mode, zero is written only into the R, G and B
323 * channels of the pixel.
324 */
325 ZeroFill,
326
327 Default = Blit
328 };
329
330 NativePaintMode nativePaintMode;
331
332#elif defined(Q_WS_PM) // <----------------------------------------------------- PM
333 QList<QWidget::PmEventFilter*> pmEventFilters;
334#endif
335};
336
337/*!
338 \internal
339
340 Returns true if \a p or any of its parents enable the
341 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
342 QWidget::setParent() to determine whether it's necessary to embed the
343 widget into a QGraphicsProxyWidget or not.
344*/
345static inline bool bypassGraphicsProxyWidget(const QWidget *p)
346{
347 while (p) {
348 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
349 return true;
350 p = p->parentWidget();
351 }
352 return false;
353}
354
355class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
356{
357 Q_DECLARE_PUBLIC(QWidget)
358
359public:
360 // *************************** Cross-platform ***************************************
361 enum DrawWidgetFlags {
362 DrawAsRoot = 0x01,
363 DrawPaintOnScreen = 0x02,
364 DrawRecursive = 0x04,
365 DrawInvisible = 0x08,
366 DontSubtractOpaqueChildren = 0x10,
367 DontSetCompositionMode = 0x20,
368 DontDrawOpaqueChildren = 0x40
369 };
370
371 enum CloseMode {
372 CloseNoEvent,
373 CloseWithEvent,
374 CloseWithSpontaneousEvent
375 };
376
377 enum Direction {
378 DirectionNorth = 0x01,
379 DirectionEast = 0x10,
380 DirectionSouth = 0x02,
381 DirectionWest = 0x20
382 };
383
384 // Functions.
385 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
386 ~QWidgetPrivate();
387
388 inline QWExtra *extraData() const;
389 inline QTLWExtra *topData() const;
390 inline QTLWExtra *maybeTopData() const;
391 inline QPainter *sharedPainter() const;
392 inline bool pointInsideRectAndMask(const QPoint &) const;
393 inline void setSharedPainter(QPainter *painter);
394 inline QWidgetBackingStore *maybeBackingStore() const;
395
396 void init(QWidget *desktopWidget, Qt::WindowFlags f);
397 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
398 void createRecursively();
399 void createWinId(WId id = 0);
400
401 void createTLExtra();
402 void createExtra();
403 void deleteExtra();
404 void createSysExtra();
405 void deleteSysExtra();
406 void createTLSysExtra();
407 void deleteTLSysExtra();
408 void updateSystemBackground();
409 void propagatePaletteChange();
410
411 void setPalette_helper(const QPalette &);
412 void resolvePalette();
413 QPalette naturalWidgetPalette(uint inheritedMask) const;
414
415 void setMask_sys(const QRegion &);
416#ifdef Q_OS_SYMBIAN
417 void setSoftKeys_sys(const QList<QAction*> &softkeys);
418 void activateSymbianWindow(WId wid = 0);
419 void _q_delayedDestroy(WId winId);
420#endif
421
422 void raise_sys();
423 void lower_sys();
424 void stackUnder_sys(QWidget *);
425
426 void setFocus_sys();
427
428 void updateFont(const QFont &);
429 inline void setFont_helper(const QFont &font) {
430 if (data.fnt == font && data.fnt.resolve() == font.resolve())
431 return;
432 updateFont(font);
433 }
434 void resolveFont();
435 QFont naturalWidgetFont(uint inheritedMask) const;
436
437 void setLayoutDirection_helper(Qt::LayoutDirection);
438 void resolveLayoutDirection();
439
440 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
441 void resolveLocale();
442
443 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
444 void inheritStyle();
445
446 void setUpdatesEnabled_helper(bool );
447
448 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
449 bool isAboutToShow() const;
450 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
451 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
452 QWidget::RenderFlags renderFlags);
453 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
454 QWidget::RenderFlags renderFlags, bool readyToRender);
455 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
456 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
457
458
459 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
460 const QRegion &rgn, const QPoint &offset, int flags
461#ifdef Q_BACKINGSTORE_SUBSURFACES
462 , const QWindowSurface *currentSurface
463#endif
464 , QPainter *sharedPainter, QWidgetBackingStore *backingStore);
465
466
467 QPainter *beginSharedPainter();
468 bool endSharedPainter();
469#ifndef QT_NO_GRAPHICSVIEW
470 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
471#endif
472 QWindowSurface *createDefaultWindowSurface();
473 QWindowSurface *createDefaultWindowSurface_sys();
474 void repaint_sys(const QRegion &rgn);
475
476 QRect clipRect() const;
477 QRegion clipRegion() const;
478 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
479 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
480 bool alsoNonOpaque = false) const;
481 void clipToEffectiveMask(QRegion &region) const;
482 void updateIsOpaque();
483 void setOpaque(bool opaque);
484 void updateIsTranslucent();
485 bool paintOnScreen() const;
486#ifndef QT_NO_GRAPHICSEFFECT
487 void invalidateGraphicsEffectsRecursively();
488#endif //QT_NO_GRAPHICSEFFECT
489
490 const QRegion &getOpaqueChildren() const;
491 void setDirtyOpaqueRegion();
492
493 bool close_helper(CloseMode mode);
494
495 void setWindowIcon_helper();
496 void setWindowIcon_sys(bool forceReset = false);
497 void setWindowOpacity_sys(qreal opacity);
498 void adjustQuitOnCloseAttribute();
499
500 void scrollChildren(int dx, int dy);
501 void moveRect(const QRect &, int dx, int dy);
502 void scrollRect(const QRect &, int dx, int dy);
503 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
504 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
505 void invalidateBuffer(const QRegion &);
506 void invalidateBuffer(const QRect &);
507 bool isOverlapped(const QRect&) const;
508 void syncBackingStore();
509 void syncBackingStore(const QRegion &region);
510
511 void reparentFocusWidgets(QWidget *oldtlw);
512
513 static int pointToRect(const QPoint &p, const QRect &r);
514
515 void setWinId(WId);
516 void showChildren(bool spontaneous);
517 void hideChildren(bool spontaneous);
518 void setParent_sys(QWidget *parent, Qt::WindowFlags);
519 void scroll_sys(int dx, int dy);
520 void scroll_sys(int dx, int dy, const QRect &r);
521 void deactivateWidgetCleanup();
522 void setGeometry_sys(int, int, int, int, bool);
523 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
524 void activateChildLayoutsRecursively();
525 void show_recursive();
526 void show_helper();
527 void show_sys();
528 void hide_sys();
529 void hide_helper();
530 void _q_showIfNotHidden();
531
532 void setEnabled_helper(bool);
533 void registerDropSite(bool);
534 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
535
536 void updateFrameStrut();
537 QRect frameStrut() const;
538
539#ifdef QT_KEYPAD_NAVIGATION
540 static bool navigateToDirection(Direction direction);
541 static QWidget *widgetInNavigationDirection(Direction direction);
542 static bool canKeypadNavigate(Qt::Orientation orientation);
543 static bool inTabWidget(QWidget *widget);
544#endif
545
546 void setWindowIconText_sys(const QString &cap);
547 void setWindowIconText_helper(const QString &cap);
548 void setWindowTitle_sys(const QString &cap);
549
550#ifndef QT_NO_CURSOR
551 void setCursor_sys(const QCursor &cursor);
552 void unsetCursor_sys();
553#endif
554
555 void setWindowTitle_helper(const QString &cap);
556 void setWindowFilePath_helper(const QString &filePath);
557
558 bool setMinimumSize_helper(int &minw, int &minh);
559 bool setMaximumSize_helper(int &maxw, int &maxh);
560 void setConstraints_sys();
561 QWidget *childAt_helper(const QPoint &, bool) const;
562 QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
563 void updateGeometry_helper(bool forceUpdate);
564
565 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
566 void setLayoutItemMargins(int left, int top, int right, int bottom);
567 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
568
569 // aboutToDestroy() is called just before the contents of
570 // QWidget::destroy() is executed. It's used to signal QWidget
571 // sub-classes that their internals are about to be released.
572 virtual void aboutToDestroy() {}
573
574 QInputContext *inputContext() const;
575 inline QWidget *effectiveFocusWidget() {
576 QWidget *w = q_func();
577 while (w->focusProxy())
578 w = w->focusProxy();
579 return w;
580 }
581
582 void setModal_sys();
583
584 // This is an helper function that return the available geometry for
585 // a widget and takes care is this one is in QGraphicsView.
586 // If the widget is not embed in a scene then the geometry available is
587 // null, we let QDesktopWidget decide for us.
588 static QRect screenGeometry(const QWidget *widget)
589 {
590 QRect screen;
591#ifndef QT_NO_GRAPHICSVIEW
592 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
593 //It's embedded if it has an ancestor
594 if (ancestorProxy) {
595 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
596 // One view, let be smart and return the viewport rect then the popup is aligned
597 if (ancestorProxy->scene()->views().size() == 1) {
598 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
599 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
600 } else {
601 screen = ancestorProxy->scene()->sceneRect().toRect();
602 }
603 }
604 }
605#endif
606 return screen;
607 }
608
609 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
610 {
611 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
612 redirectDev = replacement;
613 redirectOffset = offset;
614 }
615
616 inline QPaintDevice *redirected(QPoint *offset) const
617 {
618 if (offset)
619 *offset = redirectDev ? redirectOffset : QPoint();
620 return redirectDev;
621 }
622
623 inline void restoreRedirected()
624 { redirectDev = 0; }
625
626 inline void enforceNativeChildren()
627 {
628 if (!extra)
629 createExtra();
630
631 if (extra->nativeChildrenForced)
632 return;
633 extra->nativeChildrenForced = 1;
634
635 for (int i = 0; i < children.size(); ++i) {
636 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
637 child->setAttribute(Qt::WA_NativeWindow);
638 }
639 }
640
641 inline bool nativeChildrenForced() const
642 {
643 return extra ? extra->nativeChildrenForced : false;
644 }
645
646 inline QRect effectiveRectFor(const QRect &rect) const
647 {
648#ifndef QT_NO_GRAPHICSEFFECT
649 if (graphicsEffect && graphicsEffect->isEnabled())
650 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
651#endif //QT_NO_GRAPHICSEFFECT
652 return rect;
653 }
654
655 QSize adjustedSize() const;
656
657 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
658 {
659 Q_Q(QWidget);
660 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
661 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
662 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
663 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
664 QEvent event(QEvent::RequestSoftwareInputPanel);
665 QApplication::sendEvent(q, &event);
666 }
667 }
668 }
669
670#ifndef Q_WS_QWS // Almost cross-platform :-)
671 void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
672
673 inline QPoint mapToWS(const QPoint &p) const
674 { return p - data.wrect.topLeft(); }
675
676 inline QPoint mapFromWS(const QPoint &p) const
677 { return p + data.wrect.topLeft(); }
678
679 inline QRect mapToWS(const QRect &r) const
680 { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
681
682 inline QRect mapFromWS(const QRect &r) const
683 { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
684#endif
685
686 // Variables.
687 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
688 QWExtra *extra;
689 QWidget *focus_next;
690 QWidget *focus_prev;
691 QWidget *focus_child;
692 QLayout *layout;
693 QRegion *needsFlush;
694 QPaintDevice *redirectDev;
695 QWidgetItemV2 *widgetItem;
696 QPaintEngine *extraPaintEngine;
697 mutable const QMetaObject *polished;
698 QGraphicsEffect *graphicsEffect;
699 // All widgets are added into the allWidgets set. Once
700 // they receive a window id they are also added to the mapper.
701 // This should just ensure that all widgets are deleted by QApplication
702 static QWidgetMapper *mapper;
703 static QWidgetSet *allWidgets;
704#if !defined(QT_NO_IM)
705 QPointer<QInputContext> ic;
706 Qt::InputMethodHints imHints;
707#endif
708#ifdef QT_KEYPAD_NAVIGATION
709 static QPointer<QWidget> editingWidget;
710#endif
711
712 // Implicit pointers (shared_null/shared_empty).
713 QRegion opaqueChildren;
714 QRegion dirty;
715#ifndef QT_NO_TOOLTIP
716 QString toolTip;
717#endif
718#ifndef QT_NO_STATUSTIP
719 QString statusTip;
720#endif
721#ifndef QT_NO_WHATSTHIS
722 QString whatsThis;
723#endif
724#ifndef QT_NO_ACCESSIBILITY
725 QString accessibleName;
726 QString accessibleDescription;
727#endif
728
729 // Other variables.
730 uint inheritedFontResolveMask;
731 uint inheritedPaletteResolveMask;
732 short leftmargin;
733 short topmargin;
734 short rightmargin;
735 short bottommargin;
736 signed char leftLayoutItemMargin;
737 signed char topLayoutItemMargin;
738 signed char rightLayoutItemMargin;
739 signed char bottomLayoutItemMargin;
740 static int instanceCounter; // Current number of widget instances
741 static int maxInstances; // Maximum number of widget instances
742 Qt::HANDLE hd;
743 QWidgetData data;
744 QSizePolicy size_policy;
745 QLocale locale;
746 QPoint redirectOffset;
747#ifndef QT_NO_ACTION
748 QList<QAction*> actions;
749#endif
750#ifndef QT_NO_GESTURES
751 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
752#endif
753
754 // Bit fields.
755 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
756 QPalette::ColorRole fg_role : 8;
757 QPalette::ColorRole bg_role : 8;
758 uint dirtyOpaqueChildren : 1;
759 uint isOpaque : 1;
760 uint inDirtyList : 1;
761 uint isScrolled : 1;
762 uint isMoved : 1;
763 uint isGLWidget : 1;
764 uint usesDoubleBufferedGLContext : 1;
765#ifndef QT_NO_IM
766 uint inheritsInputMethodHints : 1;
767#endif
768
769 // *************************** Platform specific ************************************
770#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
771 QX11Info xinfo;
772 Qt::HANDLE picture;
773 static QWidget *mouseGrabber;
774 static QWidget *keyboardGrabber;
775
776 void setWindowRole();
777 void sendStartupMessage(const char *message) const;
778 void setNetWmWindowTypes();
779 void x11UpdateIsOpaque();
780 bool isBackgroundInherited() const;
781 void updateX11AcceptFocus();
782#elif defined(Q_WS_PM) // <----------------------------------------------------------- PM
783 uint noPaintOnScreen : 1; // see qwidget_pm.cpp ::paintEngine()
784
785 inline HWND frameWinId() const;
786 HWND effectiveFrameWinId() const;
787#ifdef QT_PM_NATIVEWIDGETMASK
788 void validateObstacles();
789#endif
790 void reparentChildren();
791 void setModalBlocker (QWidget *modal);
792 QWidget *modalBlocker() const;
793#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
794 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
795#ifndef QT_NO_GESTURES
796 uint nativeGesturePanEnabled : 1;
797#endif
798 bool shouldShowMaximizeButton();
799 void winUpdateIsOpaque();
800 void reparentChildren();
801#ifndef QT_NO_DRAGANDDROP
802 QOleDropTarget *registerOleDnd(QWidget *widget);
803 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
804#endif
805 void grabMouseWhileInWindow();
806 void registerTouchWindow();
807 void winSetupGestures();
808#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
809 // This is new stuff
810 uint needWindowChange : 1;
811 uint hasAlienChildren : 1;
812
813 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
814 // This list is used to update the gl context whenever a parent and a granparent
815 // moves, and also to check for intersections with gl widgets within the window
816 // when a widget moves.
817 struct GlWidgetInfo
818 {
819 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
820 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
821 QWidget * widget;
822 QWidget * lastUpdateWidget;
823 };
824
825 // dirtyOnWidget contains the areas in the widget that needs to be repained,
826 // in the same way as dirtyOnScreen does for the window. Areas are added in
827 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
828 // this information repaint invalid areas when widgets are scrolled.
829 QRegion dirtyOnWidget;
830 EventHandlerRef window_event;
831 QList<GlWidgetInfo> glWidgets;
832
833 //these are here just for code compat (HIViews)
834 Qt::HANDLE qd_hd;
835
836 void macUpdateSizeAttribute();
837 void macUpdateHideOnSuspend();
838 void macUpdateOpaqueSizeGrip();
839 void macUpdateIgnoreMouseEvents();
840 void macUpdateMetalAttribute();
841 void macUpdateIsOpaque();
842 void setEnabled_helper_sys(bool enable);
843 bool isRealWindow() const;
844 void adjustWithinMaxAndMinSize(int &w, int &h);
845 void applyMaxAndMinSizeOnWindow();
846 void update_sys(const QRect &rect);
847 void update_sys(const QRegion &rgn);
848 void setGeometry_sys_helper(int, int, int, int, bool);
849 void setWindowModified_sys(bool b);
850 void updateMaximizeButton_sys();
851 void setWindowFilePath_sys(const QString &filePath);
852 void createWindow_sys();
853 void recreateMacWindow();
854#ifndef QT_MAC_USE_COCOA
855 void initWindowPtr();
856 void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
857#else
858 void setSubWindowStacking(bool set);
859 void setWindowLevel();
860 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
861 void syncCocoaMask();
862 void finishCocoaMaskSetup();
863 void syncUnifiedMode();
864 // Did we add the drawRectOriginal method?
865 bool drawRectOriginalAdded;
866 // Is the original drawRect method available?
867 bool originalDrawMethod;
868 // Do we need to change the methods?
869 bool changeMethods;
870#endif
871 void determineWindowClass();
872 void transferChildren();
873 bool qt_mac_dnd_event(uint, DragRef);
874 void toggleDrawers(bool);
875 //mac event functions
876 static bool qt_create_root_win();
877 static void qt_clean_root_win();
878 static bool qt_mac_update_sizer(QWidget *, int up = 0);
879 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
880 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
881 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
882 void registerTouchWindow();
883#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
884 void setMaxWindowState_helper();
885 void setFullScreenSize_helper();
886 void moveSurface(QWindowSurface *surface, const QPoint &offset);
887 QRegion localRequestedRegion() const;
888 QRegion localAllocatedRegion() const;
889
890 friend class QWSManager;
891 friend class QWSManagerPrivate;
892 friend class QDecoration;
893#ifndef QT_NO_CURSOR
894 void updateCursor() const;
895#endif
896 QScreen* getScreen() const;
897#elif defined(Q_OS_SYMBIAN) // <--------------------------------------------------------- SYMBIAN
898 static QWidget *mouseGrabber;
899 static QWidget *keyboardGrabber;
900 void s60UpdateIsOpaque();
901 void reparentChildren();
902 void registerTouchWindow();
903#endif
904
905};
906
907struct QWidgetPaintContext
908{
909 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
910 QPainter *p, QWidgetBackingStore *b)
911 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
912
913 QPaintDevice *pdev;
914 QRegion rgn;
915 QPoint offset;
916 int flags;
917 QPainter *sharedPainter;
918 QWidgetBackingStore *backingStore;
919 QPainter *painter;
920};
921
922#ifndef QT_NO_GRAPHICSEFFECT
923class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
924{
925public:
926 QWidgetEffectSourcePrivate(QWidget *widget)
927 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
928 {}
929
930 inline void detach()
931 { m_widget->d_func()->graphicsEffect = 0; }
932
933 inline const QGraphicsItem *graphicsItem() const
934 { return 0; }
935
936 inline const QWidget *widget() const
937 { return m_widget; }
938
939 inline void update()
940 {
941 updateDueToGraphicsEffect = true;
942 m_widget->update();
943 updateDueToGraphicsEffect = false;
944 }
945
946 inline bool isPixmap() const
947 { return false; }
948
949 inline void effectBoundingRectChanged()
950 {
951 // ### This function should take a rect parameter; then we can avoid
952 // updating too much on the parent widget.
953 if (QWidget *parent = m_widget->parentWidget())
954 parent->update();
955 else
956 update();
957 }
958
959 inline const QStyleOption *styleOption() const
960 { return 0; }
961
962 inline QRect deviceRect() const
963 { return m_widget->window()->rect(); }
964
965 QRectF boundingRect(Qt::CoordinateSystem system) const;
966 void draw(QPainter *p);
967 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
968 QGraphicsEffect::PixmapPadMode mode) const;
969
970 QWidget *m_widget;
971 QWidgetPaintContext *context;
972 QTransform lastEffectTransform;
973 bool updateDueToGraphicsEffect;
974};
975#endif //QT_NO_GRAPHICSEFFECT
976
977inline QWExtra *QWidgetPrivate::extraData() const
978{
979 return extra;
980}
981
982inline QTLWExtra *QWidgetPrivate::topData() const
983{
984 const_cast<QWidgetPrivate *>(this)->createTLExtra();
985 return extra->topextra;
986}
987
988inline QTLWExtra *QWidgetPrivate::maybeTopData() const
989{
990 return extra ? extra->topextra : 0;
991}
992
993inline QPainter *QWidgetPrivate::sharedPainter() const
994{
995 Q_Q(const QWidget);
996 QTLWExtra *x = q->window()->d_func()->maybeTopData();
997 return x ? x->sharedPainter : 0;
998}
999
1000inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
1001{
1002 Q_Q(QWidget);
1003 QTLWExtra *x = q->window()->d_func()->topData();
1004 x->sharedPainter = painter;
1005}
1006
1007inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
1008{
1009 Q_Q(const QWidget);
1010 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
1011 || extra->mask.contains(p));
1012}
1013
1014inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
1015{
1016 Q_Q(const QWidget);
1017 QTLWExtra *x = q->window()->d_func()->maybeTopData();
1018 return x ? x->backingStore.data() : 0;
1019}
1020
1021#if defined(Q_WS_PM)
1022
1023inline HWND QWidgetPrivate::frameWinId() const
1024{
1025 return maybeTopData() && maybeTopData()->fId != NULLHANDLE ?
1026 maybeTopData()->fId : data.winid;
1027}
1028
1029inline void QWidgetPrivate::setModalBlocker (QWidget *modal)
1030{
1031 topData()->modalBlocker = modal;
1032}
1033
1034inline QWidget *QWidgetPrivate::modalBlocker() const
1035{
1036 QTLWExtra *top = maybeTopData();
1037 return top ? top->modalBlocker : 0;
1038}
1039
1040#endif
1041
1042QT_END_NAMESPACE
1043
1044#endif // QWIDGET_P_H
Note: See TracBrowser for help on using the repository browser.