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

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

gui: QWidgetPrivate: Declare inline methods as such upfront so that GCC compiler knows it and doesn't produce "redeclared without dllimport attribute after being referenced with dll linkage" warnings when they are defined inline later.

File size: 33.3 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#endif
239};
240
241struct QWExtra {
242 // *************************** Cross-platform variables *****************************
243
244 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
245 void *glContext; // if the widget is hijacked by QGLWindowSurface
246 QTLWExtra *topextra; // only useful for TLWs
247#ifndef QT_NO_GRAPHICSVIEW
248 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
249#endif
250#ifndef QT_NO_CURSOR
251 QCursor *curs;
252#endif
253 QPointer<QStyle> style;
254 QPointer<QWidget> focus_proxy;
255
256 // Implicit pointers (shared_empty/shared_null).
257 QRegion mask; // widget mask
258 QString styleSheet;
259
260 // Other variables.
261 qint32 minw;
262 qint32 minh; // minimum size
263 qint32 maxw;
264 qint32 maxh; // maximum size
265 quint16 customDpiX;
266 quint16 customDpiY;
267 QSize staticContentsSize;
268
269 // *************************** Cross-platform bit fields ****************************
270 uint explicitMinSize : 2;
271 uint explicitMaxSize : 2;
272 uint autoFillBackground : 1;
273 uint nativeChildrenForced : 1;
274 uint inRenderWithPainter : 1;
275 uint hasMask : 1;
276
277 // *************************** Platform specific values (bit fields first) **********
278#if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
279#ifndef QT_NO_DRAGANDDROP
280 QOleDropTarget *dropTarget; // drop target
281 QList<QPointer<QWidget> > oleDropWidgets;
282#endif
283#elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
284 uint compress_events : 1;
285 WId xDndProxy; // XDND forwarding to embedded windows
286#elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
287#ifdef QT_MAC_USE_COCOA
288 // Cocoa Mask stuff
289 QImage maskBits;
290 CGImageRef imageMask;
291#endif
292#elif defined(Q_OS_SYMBIAN) // <----------------------------------------------------- Symbian
293 uint activated : 1; // RWindowBase::Activated has been called
294
295 /**
296 * If this bit is set, each native widget receives the signals from the
297 * Symbian control immediately before and immediately after draw ops are
298 * sent to the window server for this control:
299 * void beginNativePaintEvent(const QRect &paintRect);
300 * void endNativePaintEvent(const QRect &paintRect);
301 */
302 uint receiveNativePaintEvents : 1;
303
304 /**
305 * Defines the behaviour of QSymbianControl::Draw.
306 */
307 enum NativePaintMode {
308 /**
309 * Normal drawing mode: blits the required region of the backing store
310 * via WSERV.
311 */
312 Blit,
313
314 /**
315 * Disable drawing for this widget.
316 */
317 Disable,
318
319 /**
320 * Paint zeros into the WSERV framebuffer, using BitGDI APIs. For windows
321 * with an EColor16MU display mode, zero is written only into the R, G and B
322 * channels of the pixel.
323 */
324 ZeroFill,
325
326 Default = Blit
327 };
328
329 NativePaintMode nativePaintMode;
330
331#elif defined(Q_WS_PM) // <----------------------------------------------------- PM
332 QList<QWidget::PmEventFilter*> pmEventFilters;
333#endif
334};
335
336/*!
337 \internal
338
339 Returns true if \a p or any of its parents enable the
340 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
341 QWidget::setParent() to determine whether it's necessary to embed the
342 widget into a QGraphicsProxyWidget or not.
343*/
344static inline bool bypassGraphicsProxyWidget(const QWidget *p)
345{
346 while (p) {
347 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
348 return true;
349 p = p->parentWidget();
350 }
351 return false;
352}
353
354class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
355{
356 Q_DECLARE_PUBLIC(QWidget)
357
358public:
359 // *************************** Cross-platform ***************************************
360 enum DrawWidgetFlags {
361 DrawAsRoot = 0x01,
362 DrawPaintOnScreen = 0x02,
363 DrawRecursive = 0x04,
364 DrawInvisible = 0x08,
365 DontSubtractOpaqueChildren = 0x10,
366 DontSetCompositionMode = 0x20,
367 DontDrawOpaqueChildren = 0x40
368 };
369
370 enum CloseMode {
371 CloseNoEvent,
372 CloseWithEvent,
373 CloseWithSpontaneousEvent
374 };
375
376 enum Direction {
377 DirectionNorth = 0x01,
378 DirectionEast = 0x10,
379 DirectionSouth = 0x02,
380 DirectionWest = 0x20
381 };
382
383 // Functions.
384 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
385 ~QWidgetPrivate();
386
387 inline QWExtra *extraData() const;
388 inline QTLWExtra *topData() const;
389 inline QTLWExtra *maybeTopData() const;
390 inline QPainter *sharedPainter() const;
391 inline bool pointInsideRectAndMask(const QPoint &) const;
392 inline void setSharedPainter(QPainter *painter);
393 inline QWidgetBackingStore *maybeBackingStore() const;
394
395 void init(QWidget *desktopWidget, Qt::WindowFlags f);
396 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
397 void createRecursively();
398 void createWinId(WId id = 0);
399
400 void createTLExtra();
401 void createExtra();
402 void deleteExtra();
403 void createSysExtra();
404 void deleteSysExtra();
405 void createTLSysExtra();
406 void deleteTLSysExtra();
407 void updateSystemBackground();
408 void propagatePaletteChange();
409
410 void setPalette_helper(const QPalette &);
411 void resolvePalette();
412 QPalette naturalWidgetPalette(uint inheritedMask) const;
413
414 void setMask_sys(const QRegion &);
415#ifdef Q_OS_SYMBIAN
416 void setSoftKeys_sys(const QList<QAction*> &softkeys);
417 void activateSymbianWindow(WId wid = 0);
418 void _q_delayedDestroy(WId winId);
419#endif
420
421 void raise_sys();
422 void lower_sys();
423 void stackUnder_sys(QWidget *);
424
425 void setFocus_sys();
426
427 void updateFont(const QFont &);
428 inline void setFont_helper(const QFont &font) {
429 if (data.fnt == font && data.fnt.resolve() == font.resolve())
430 return;
431 updateFont(font);
432 }
433 void resolveFont();
434 QFont naturalWidgetFont(uint inheritedMask) const;
435
436 void setLayoutDirection_helper(Qt::LayoutDirection);
437 void resolveLayoutDirection();
438
439 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
440 void resolveLocale();
441
442 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
443 void inheritStyle();
444
445 void setUpdatesEnabled_helper(bool );
446
447 void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
448 bool isAboutToShow() const;
449 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
450 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
451 QWidget::RenderFlags renderFlags);
452 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
453 QWidget::RenderFlags renderFlags, bool readyToRender);
454 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
455 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
456
457
458 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
459 const QRegion &rgn, const QPoint &offset, int flags
460#ifdef Q_BACKINGSTORE_SUBSURFACES
461 , const QWindowSurface *currentSurface
462#endif
463 , QPainter *sharedPainter, QWidgetBackingStore *backingStore);
464
465
466 QPainter *beginSharedPainter();
467 bool endSharedPainter();
468#ifndef QT_NO_GRAPHICSVIEW
469 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
470#endif
471 QWindowSurface *createDefaultWindowSurface();
472 QWindowSurface *createDefaultWindowSurface_sys();
473 void repaint_sys(const QRegion &rgn);
474
475 QRect clipRect() const;
476 QRegion clipRegion() const;
477 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
478 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
479 bool alsoNonOpaque = false) const;
480 void clipToEffectiveMask(QRegion &region) const;
481 void updateIsOpaque();
482 void setOpaque(bool opaque);
483 void updateIsTranslucent();
484 bool paintOnScreen() const;
485#ifndef QT_NO_GRAPHICSEFFECT
486 void invalidateGraphicsEffectsRecursively();
487#endif //QT_NO_GRAPHICSEFFECT
488
489 const QRegion &getOpaqueChildren() const;
490 void setDirtyOpaqueRegion();
491
492 bool close_helper(CloseMode mode);
493
494 void setWindowIcon_helper();
495 void setWindowIcon_sys(bool forceReset = false);
496 void setWindowOpacity_sys(qreal opacity);
497 void adjustQuitOnCloseAttribute();
498
499 void scrollChildren(int dx, int dy);
500 void moveRect(const QRect &, int dx, int dy);
501 void scrollRect(const QRect &, int dx, int dy);
502 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
503 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
504 void invalidateBuffer(const QRegion &);
505 void invalidateBuffer(const QRect &);
506 bool isOverlapped(const QRect&) const;
507 void syncBackingStore();
508 void syncBackingStore(const QRegion &region);
509
510 void reparentFocusWidgets(QWidget *oldtlw);
511
512 static int pointToRect(const QPoint &p, const QRect &r);
513
514 void setWinId(WId);
515 void showChildren(bool spontaneous);
516 void hideChildren(bool spontaneous);
517 void setParent_sys(QWidget *parent, Qt::WindowFlags);
518 void scroll_sys(int dx, int dy);
519 void scroll_sys(int dx, int dy, const QRect &r);
520 void deactivateWidgetCleanup();
521 void setGeometry_sys(int, int, int, int, bool);
522 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
523 void activateChildLayoutsRecursively();
524 void show_recursive();
525 void show_helper();
526 void show_sys();
527 void hide_sys();
528 void hide_helper();
529 void _q_showIfNotHidden();
530
531 void setEnabled_helper(bool);
532 void registerDropSite(bool);
533 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
534
535 void updateFrameStrut();
536 QRect frameStrut() const;
537
538#ifdef QT_KEYPAD_NAVIGATION
539 static bool navigateToDirection(Direction direction);
540 static QWidget *widgetInNavigationDirection(Direction direction);
541 static bool canKeypadNavigate(Qt::Orientation orientation);
542 static bool inTabWidget(QWidget *widget);
543#endif
544
545 void setWindowIconText_sys(const QString &cap);
546 void setWindowIconText_helper(const QString &cap);
547 void setWindowTitle_sys(const QString &cap);
548
549#ifndef QT_NO_CURSOR
550 void setCursor_sys(const QCursor &cursor);
551 void unsetCursor_sys();
552#endif
553
554 void setWindowTitle_helper(const QString &cap);
555 void setWindowFilePath_helper(const QString &filePath);
556
557 bool setMinimumSize_helper(int &minw, int &minh);
558 bool setMaximumSize_helper(int &maxw, int &maxh);
559 void setConstraints_sys();
560 QWidget *childAt_helper(const QPoint &, bool) const;
561 QWidget *childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame = false) const;
562 void updateGeometry_helper(bool forceUpdate);
563
564 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
565 void setLayoutItemMargins(int left, int top, int right, int bottom);
566 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
567
568 // aboutToDestroy() is called just before the contents of
569 // QWidget::destroy() is executed. It's used to signal QWidget
570 // sub-classes that their internals are about to be released.
571 virtual void aboutToDestroy() {}
572
573 QInputContext *inputContext() const;
574 inline QWidget *effectiveFocusWidget() {
575 QWidget *w = q_func();
576 while (w->focusProxy())
577 w = w->focusProxy();
578 return w;
579 }
580
581 void setModal_sys();
582
583 // This is an helper function that return the available geometry for
584 // a widget and takes care is this one is in QGraphicsView.
585 // If the widget is not embed in a scene then the geometry available is
586 // null, we let QDesktopWidget decide for us.
587 static QRect screenGeometry(const QWidget *widget)
588 {
589 QRect screen;
590#ifndef QT_NO_GRAPHICSVIEW
591 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
592 //It's embedded if it has an ancestor
593 if (ancestorProxy) {
594 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != 0) {
595 // One view, let be smart and return the viewport rect then the popup is aligned
596 if (ancestorProxy->scene()->views().size() == 1) {
597 QGraphicsView *view = ancestorProxy->scene()->views().at(0);
598 screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
599 } else {
600 screen = ancestorProxy->scene()->sceneRect().toRect();
601 }
602 }
603 }
604#endif
605 return screen;
606 }
607
608 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
609 {
610 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
611 redirectDev = replacement;
612 redirectOffset = offset;
613 }
614
615 inline QPaintDevice *redirected(QPoint *offset) const
616 {
617 if (offset)
618 *offset = redirectDev ? redirectOffset : QPoint();
619 return redirectDev;
620 }
621
622 inline void restoreRedirected()
623 { redirectDev = 0; }
624
625 inline void enforceNativeChildren()
626 {
627 if (!extra)
628 createExtra();
629
630 if (extra->nativeChildrenForced)
631 return;
632 extra->nativeChildrenForced = 1;
633
634 for (int i = 0; i < children.size(); ++i) {
635 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
636 child->setAttribute(Qt::WA_NativeWindow);
637 }
638 }
639
640 inline bool nativeChildrenForced() const
641 {
642 return extra ? extra->nativeChildrenForced : false;
643 }
644
645 inline QRect effectiveRectFor(const QRect &rect) const
646 {
647#ifndef QT_NO_GRAPHICSEFFECT
648 if (graphicsEffect && graphicsEffect->isEnabled())
649 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
650#endif //QT_NO_GRAPHICSEFFECT
651 return rect;
652 }
653
654 QSize adjustedSize() const;
655
656 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
657 {
658 Q_Q(QWidget);
659 if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
660 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
661 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
662 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
663 QEvent event(QEvent::RequestSoftwareInputPanel);
664 QApplication::sendEvent(q, &event);
665 }
666 }
667 }
668
669#ifndef Q_WS_QWS // Almost cross-platform :-)
670 void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
671
672 inline QPoint mapToWS(const QPoint &p) const
673 { return p - data.wrect.topLeft(); }
674
675 inline QPoint mapFromWS(const QPoint &p) const
676 { return p + data.wrect.topLeft(); }
677
678 inline QRect mapToWS(const QRect &r) const
679 { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
680
681 inline QRect mapFromWS(const QRect &r) const
682 { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
683#endif
684
685 // Variables.
686 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
687 QWExtra *extra;
688 QWidget *focus_next;
689 QWidget *focus_prev;
690 QWidget *focus_child;
691 QLayout *layout;
692 QRegion *needsFlush;
693 QPaintDevice *redirectDev;
694 QWidgetItemV2 *widgetItem;
695 QPaintEngine *extraPaintEngine;
696 mutable const QMetaObject *polished;
697 QGraphicsEffect *graphicsEffect;
698 // All widgets are added into the allWidgets set. Once
699 // they receive a window id they are also added to the mapper.
700 // This should just ensure that all widgets are deleted by QApplication
701 static QWidgetMapper *mapper;
702 static QWidgetSet *allWidgets;
703#if !defined(QT_NO_IM)
704 QPointer<QInputContext> ic;
705 Qt::InputMethodHints imHints;
706#endif
707#ifdef QT_KEYPAD_NAVIGATION
708 static QPointer<QWidget> editingWidget;
709#endif
710
711 // Implicit pointers (shared_null/shared_empty).
712 QRegion opaqueChildren;
713 QRegion dirty;
714#ifndef QT_NO_TOOLTIP
715 QString toolTip;
716#endif
717#ifndef QT_NO_STATUSTIP
718 QString statusTip;
719#endif
720#ifndef QT_NO_WHATSTHIS
721 QString whatsThis;
722#endif
723#ifndef QT_NO_ACCESSIBILITY
724 QString accessibleName;
725 QString accessibleDescription;
726#endif
727
728 // Other variables.
729 uint inheritedFontResolveMask;
730 uint inheritedPaletteResolveMask;
731 short leftmargin;
732 short topmargin;
733 short rightmargin;
734 short bottommargin;
735 signed char leftLayoutItemMargin;
736 signed char topLayoutItemMargin;
737 signed char rightLayoutItemMargin;
738 signed char bottomLayoutItemMargin;
739 static int instanceCounter; // Current number of widget instances
740 static int maxInstances; // Maximum number of widget instances
741 Qt::HANDLE hd;
742 QWidgetData data;
743 QSizePolicy size_policy;
744 QLocale locale;
745 QPoint redirectOffset;
746#ifndef QT_NO_ACTION
747 QList<QAction*> actions;
748#endif
749#ifndef QT_NO_GESTURES
750 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
751#endif
752
753 // Bit fields.
754 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
755 QPalette::ColorRole fg_role : 8;
756 QPalette::ColorRole bg_role : 8;
757 uint dirtyOpaqueChildren : 1;
758 uint isOpaque : 1;
759 uint inDirtyList : 1;
760 uint isScrolled : 1;
761 uint isMoved : 1;
762 uint isGLWidget : 1;
763 uint usesDoubleBufferedGLContext : 1;
764#ifndef QT_NO_IM
765 uint inheritsInputMethodHints : 1;
766#endif
767
768 // *************************** Platform specific ************************************
769#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
770 QX11Info xinfo;
771 Qt::HANDLE picture;
772 static QWidget *mouseGrabber;
773 static QWidget *keyboardGrabber;
774
775 void setWindowRole();
776 void sendStartupMessage(const char *message) const;
777 void setNetWmWindowTypes();
778 void x11UpdateIsOpaque();
779 bool isBackgroundInherited() const;
780 void updateX11AcceptFocus();
781#elif defined(Q_WS_PM) // <----------------------------------------------------------- PM
782 uint noPaintOnScreen : 1; // see qwidget_pm.cpp ::paintEngine()
783
784 inline HWND frameWinId() const
785 { return maybeTopData() && maybeTopData()->fId != NULLHANDLE ?
786 maybeTopData()->fId : data.winid; }
787 HWND effectiveFrameWinId() const;
788 void validateObstacles();
789 void reparentChildren();
790#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
791 uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
792#ifndef QT_NO_GESTURES
793 uint nativeGesturePanEnabled : 1;
794#endif
795 bool shouldShowMaximizeButton();
796 void winUpdateIsOpaque();
797 void reparentChildren();
798#ifndef QT_NO_DRAGANDDROP
799 QOleDropTarget *registerOleDnd(QWidget *widget);
800 void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
801#endif
802 void grabMouseWhileInWindow();
803 void registerTouchWindow();
804 void winSetupGestures();
805#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
806 // This is new stuff
807 uint needWindowChange : 1;
808 uint hasAlienChildren : 1;
809
810 // Each wiget keeps a list of all its child and grandchild OpenGL widgets.
811 // This list is used to update the gl context whenever a parent and a granparent
812 // moves, and also to check for intersections with gl widgets within the window
813 // when a widget moves.
814 struct GlWidgetInfo
815 {
816 GlWidgetInfo(QWidget *widget) : widget(widget), lastUpdateWidget(0) { }
817 bool operator==(const GlWidgetInfo &other) const { return (widget == other.widget); }
818 QWidget * widget;
819 QWidget * lastUpdateWidget;
820 };
821
822 // dirtyOnWidget contains the areas in the widget that needs to be repained,
823 // in the same way as dirtyOnScreen does for the window. Areas are added in
824 // dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
825 // this information repaint invalid areas when widgets are scrolled.
826 QRegion dirtyOnWidget;
827 EventHandlerRef window_event;
828 QList<GlWidgetInfo> glWidgets;
829
830 //these are here just for code compat (HIViews)
831 Qt::HANDLE qd_hd;
832
833 void macUpdateSizeAttribute();
834 void macUpdateHideOnSuspend();
835 void macUpdateOpaqueSizeGrip();
836 void macUpdateIgnoreMouseEvents();
837 void macUpdateMetalAttribute();
838 void macUpdateIsOpaque();
839 void setEnabled_helper_sys(bool enable);
840 bool isRealWindow() const;
841 void adjustWithinMaxAndMinSize(int &w, int &h);
842 void applyMaxAndMinSizeOnWindow();
843 void update_sys(const QRect &rect);
844 void update_sys(const QRegion &rgn);
845 void setGeometry_sys_helper(int, int, int, int, bool);
846 void setWindowModified_sys(bool b);
847 void updateMaximizeButton_sys();
848 void setWindowFilePath_sys(const QString &filePath);
849 void createWindow_sys();
850 void recreateMacWindow();
851#ifndef QT_MAC_USE_COCOA
852 void initWindowPtr();
853 void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
854#else
855 void setSubWindowStacking(bool set);
856 void setWindowLevel();
857 void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
858 void syncCocoaMask();
859 void finishCocoaMaskSetup();
860 void syncUnifiedMode();
861 // Did we add the drawRectOriginal method?
862 bool drawRectOriginalAdded;
863 // Is the original drawRect method available?
864 bool originalDrawMethod;
865 // Do we need to change the methods?
866 bool changeMethods;
867#endif
868 void determineWindowClass();
869 void transferChildren();
870 bool qt_mac_dnd_event(uint, DragRef);
871 void toggleDrawers(bool);
872 //mac event functions
873 static bool qt_create_root_win();
874 static void qt_clean_root_win();
875 static bool qt_mac_update_sizer(QWidget *, int up = 0);
876 static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
877 static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
878 static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
879 void registerTouchWindow();
880#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
881 void setMaxWindowState_helper();
882 void setFullScreenSize_helper();
883 void moveSurface(QWindowSurface *surface, const QPoint &offset);
884 QRegion localRequestedRegion() const;
885 QRegion localAllocatedRegion() const;
886
887 friend class QWSManager;
888 friend class QWSManagerPrivate;
889 friend class QDecoration;
890#ifndef QT_NO_CURSOR
891 void updateCursor() const;
892#endif
893 QScreen* getScreen() const;
894#elif defined(Q_OS_SYMBIAN) // <--------------------------------------------------------- SYMBIAN
895 static QWidget *mouseGrabber;
896 static QWidget *keyboardGrabber;
897 void s60UpdateIsOpaque();
898 void reparentChildren();
899 void registerTouchWindow();
900#endif
901
902};
903
904struct QWidgetPaintContext
905{
906 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, int f,
907 QPainter *p, QWidgetBackingStore *b)
908 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), backingStore(b), painter(0) {}
909
910 QPaintDevice *pdev;
911 QRegion rgn;
912 QPoint offset;
913 int flags;
914 QPainter *sharedPainter;
915 QWidgetBackingStore *backingStore;
916 QPainter *painter;
917};
918
919#ifndef QT_NO_GRAPHICSEFFECT
920class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
921{
922public:
923 QWidgetEffectSourcePrivate(QWidget *widget)
924 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(0), updateDueToGraphicsEffect(false)
925 {}
926
927 inline void detach()
928 { m_widget->d_func()->graphicsEffect = 0; }
929
930 inline const QGraphicsItem *graphicsItem() const
931 { return 0; }
932
933 inline const QWidget *widget() const
934 { return m_widget; }
935
936 inline void update()
937 {
938 updateDueToGraphicsEffect = true;
939 m_widget->update();
940 updateDueToGraphicsEffect = false;
941 }
942
943 inline bool isPixmap() const
944 { return false; }
945
946 inline void effectBoundingRectChanged()
947 {
948 // ### This function should take a rect parameter; then we can avoid
949 // updating too much on the parent widget.
950 if (QWidget *parent = m_widget->parentWidget())
951 parent->update();
952 else
953 update();
954 }
955
956 inline const QStyleOption *styleOption() const
957 { return 0; }
958
959 inline QRect deviceRect() const
960 { return m_widget->window()->rect(); }
961
962 QRectF boundingRect(Qt::CoordinateSystem system) const;
963 void draw(QPainter *p);
964 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
965 QGraphicsEffect::PixmapPadMode mode) const;
966
967 QWidget *m_widget;
968 QWidgetPaintContext *context;
969 QTransform lastEffectTransform;
970 bool updateDueToGraphicsEffect;
971};
972#endif //QT_NO_GRAPHICSEFFECT
973
974inline QWExtra *QWidgetPrivate::extraData() const
975{
976 return extra;
977}
978
979inline QTLWExtra *QWidgetPrivate::topData() const
980{
981 const_cast<QWidgetPrivate *>(this)->createTLExtra();
982 return extra->topextra;
983}
984
985inline QTLWExtra *QWidgetPrivate::maybeTopData() const
986{
987 return extra ? extra->topextra : 0;
988}
989
990inline QPainter *QWidgetPrivate::sharedPainter() const
991{
992 Q_Q(const QWidget);
993 QTLWExtra *x = q->window()->d_func()->maybeTopData();
994 return x ? x->sharedPainter : 0;
995}
996
997inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
998{
999 Q_Q(QWidget);
1000 QTLWExtra *x = q->window()->d_func()->topData();
1001 x->sharedPainter = painter;
1002}
1003
1004inline bool QWidgetPrivate::pointInsideRectAndMask(const QPoint &p) const
1005{
1006 Q_Q(const QWidget);
1007 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
1008 || extra->mask.contains(p));
1009}
1010
1011inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const
1012{
1013 Q_Q(const QWidget);
1014 QTLWExtra *x = q->window()->d_func()->maybeTopData();
1015 return x ? x->backingStore.data() : 0;
1016}
1017
1018QT_END_NAMESPACE
1019
1020#endif // QWIDGET_P_H
Note: See TracBrowser for help on using the repository browser.