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