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

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

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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