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

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

OS/2: gui: Make blocked widgets follow modal on Z-order change.

This makes sure that whenever the modal widget is brought
to front, all the ones it blocks will be placed right underneath it
keeping their original z-order at the time of blocking.

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 ([email protected])
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 [email protected].
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 void validateObstacles();
788 void reparentChildren();
789 void setModalBlocker (QWidget *modal);
790 QWidget *modalBlocker() const;
791#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
792 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
793#ifndef QT_NO_GESTURES
794 uint nativeGesturePanEnabled : 1;
795#endif
796 bool shouldShowMaximizeButton();
797 void winUpdateIsOpaque();
798 void reparentChildren();
799#ifndef QT_NO_DRAGANDDROP
800 QOleDropTarget *registerOleDnd(QWidget *widget);
801 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
802#endif
803 void grabMouseWhileInWindow();
804 void registerTouchWindow();
805 void winSetupGestures();
806#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
807 // This is new stuff
808 uint needWindowChange : 1;
809 uint hasAlienChildren : 1;
810
811 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
812 // This list is used to update the gl context whenever a parent and a granparent
813 // moves, and also to check for intersections with gl widgets within the window
814 // when a widget moves.
815 struct GlWidgetInfo
816 {
817 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
818 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
819 QWidget * widget;
820 QWidget * lastUpdateWidget;
821 };
822
823 // dirtyOnWidget contains the areas in the widget that needs to be repained,
824 // in the same way as dirtyOnScreen does for the window. Areas are added in
825 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
826 // this information repaint invalid areas when widgets are scrolled.
827 QRegion dirtyOnWidget;
828 EventHandlerRef window_event;
829 QList<GlWidgetInfo> glWidgets;
830
831 //these are here just for code compat (HIViews)
832 Qt::HANDLE qd_hd;
833
834 void macUpdateSizeAttribute();
835 void macUpdateHideOnSuspend();
836 void macUpdateOpaqueSizeGrip();
837 void macUpdateIgnoreMouseEvents();
838 void macUpdateMetalAttribute();
839 void macUpdateIsOpaque();
840 void setEnabled_helper_sys(bool enable);
841 bool isRealWindow() const;
842 void adjustWithinMaxAndMinSize(int &w, int &h);
843 void applyMaxAndMinSizeOnWindow();
844 void update_sys(const QRect &rect);
845 void update_sys(const QRegion &rgn);
846 void setGeometry_sys_helper(int, int, int, int, bool);
847 void setWindowModified_sys(bool b);
848 void updateMaximizeButton_sys();
849 void setWindowFilePath_sys(const QString &filePath);
850 void createWindow_sys();
851 void recreateMacWindow();
852#ifndef QT_MAC_USE_COCOA
853 void initWindowPtr();
854 void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
855#else
856 void setSubWindowStacking(bool set);
857 void setWindowLevel();
858 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
859 void syncCocoaMask();
860 void finishCocoaMaskSetup();
861 void syncUnifiedMode();
862 // Did we add the drawRectOriginal method?
863 bool drawRectOriginalAdded;
864 // Is the original drawRect method available?
865 bool originalDrawMethod;
866 // Do we need to change the methods?
867 bool changeMethods;
868#endif
869 void determineWindowClass();
870 void transferChildren();
871 bool qt_mac_dnd_event(uint, DragRef);
872 void toggleDrawers(bool);
873 //mac event functions
874 static bool qt_create_root_win();
875 static void qt_clean_root_win();
876 static bool qt_mac_update_sizer(QWidget *, int up = 0);
877 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
878 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
879 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
880 void registerTouchWindow();
881#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
882 void setMaxWindowState_helper();
883 void setFullScreenSize_helper();
884 void moveSurface(QWindowSurface *surface, const QPoint &offset);
885 QRegion localRequestedRegion() const;
886 QRegion localAllocatedRegion() const;
887
888 friend class QWSManager;
889 friend class QWSManagerPrivate;
890 friend class QDecoration;
891#ifndef QT_NO_CURSOR
892 void updateCursor() const;
893#endif
894 QScreen* getScreen() const;
895#elif defined(Q_OS_SYMBIAN) // <--------------------------------------------------------- SYMBIAN
896 static QWidget *mouseGrabber;
897 static QWidget *keyboardGrabber;
898 void s60UpdateIsOpaque();
899 void reparentChildren();
900 void registerTouchWindow();
901#endif
902
903};
904
905struct QWidgetPaintContext
906{
907 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
908 QPainter *p, QWidgetBackingStore *b)
909 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
910
911 QPaintDevice *pdev;
912 QRegion rgn;
913 QPoint offset;
914 int flags;
915 QPainter *sharedPainter;
916 QWidgetBackingStore *backingStore;
917 QPainter *painter;
918};
919
920#ifndef QT_NO_GRAPHICSEFFECT
921class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
922{
923public:
924 QWidgetEffectSourcePrivate(QWidget *widget)
925 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
926 {}
927
928 inline void detach()
929 { m_widget->d_func()->graphicsEffect = 0; }
930
931 inline const QGraphicsItem *graphicsItem() const
932 { return 0; }
933
934 inline const QWidget *widget() const
935 { return m_widget; }
936
937 inline void update()
938 {
939 updateDueToGraphicsEffect = true;
940 m_widget->update();
941 updateDueToGraphicsEffect = false;
942 }
943
944 inline bool isPixmap() const
945 { return false; }
946
947 inline void effectBoundingRectChanged()
948 {
949 // ### This function should take a rect parameter; then we can avoid
950 // updating too much on the parent widget.
951 if (QWidget *parent = m_widget->parentWidget())
952 parent->update();
953 else
954 update();
955 }
956
957 inline const QStyleOption *styleOption() const
958 { return 0; }
959
960 inline QRect deviceRect() const
961 { return m_widget->window()->rect(); }
962
963 QRectF boundingRect(Qt::CoordinateSystem system) const;
964 void draw(QPainter *p);
965 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
966 QGraphicsEffect::PixmapPadMode mode) const;
967
968 QWidget *m_widget;
969 QWidgetPaintContext *context;
970 QTransform lastEffectTransform;
971 bool updateDueToGraphicsEffect;
972};
973#endif //QT_NO_GRAPHICSEFFECT
974
975inline QWExtra *QWidgetPrivate::extraData() const
976{
977 return extra;
978}
979
980inline QTLWExtra *QWidgetPrivate::topData() const
981{
982 const_cast<QWidgetPrivate *>(this)->createTLExtra();
983 return extra->topextra;
984}
985
986inline QTLWExtra *QWidgetPrivate::maybeTopData() const
987{
988 return extra ? extra->topextra : 0;
989}
990
991inline QPainter *QWidgetPrivate::sharedPainter() const
992{
993 Q_Q(const QWidget);
994 QTLWExtra *x = q->window()->d_func()->maybeTopData();
995 return x ? x->sharedPainter : 0;
996}
997
998inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
999{
1000 Q_Q(QWidget);
1001 QTLWExtra *x = q->window()->d_func()->topData();
1002 x->sharedPainter = painter;
1003}
1004
1005inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
1006{
1007 Q_Q(const QWidget);
1008 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
1009 || extra->mask.contains(p));
1010}
1011
1012inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
1013{
1014 Q_Q(const QWidget);
1015 QTLWExtra *x = q->window()->d_func()->maybeTopData();
1016 return x ? x->backingStore.data() : 0;
1017}
1018
1019#if defined(Q_WS_PM)
1020
1021inline HWND QWidgetPrivate::frameWinId() const
1022{
1023 return maybeTopData() && maybeTopData()->fId != NULLHANDLE ?
1024 maybeTopData()->fId : data.winid;
1025}
1026
1027inline void QWidgetPrivate::setModalBlocker (QWidget *modal)
1028{
1029 topData()->modalBlocker = modal;
1030}
1031
1032inline QWidget *QWidgetPrivate::modalBlocker() const
1033{
1034 QTLWExtra *top = maybeTopData();
1035 return top ? top->modalBlocker : 0;
1036}
1037
1038#endif
1039
1040QT_END_NAMESPACE
1041
1042#endif // QWIDGET_P_H
Note: See TracBrowser for help on using the repository browser.