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

Last change on this file since 138 was 130, checked in by Dmitry A. Kuminov, 16 years ago

gui: Implemented QWidget::grabMouse/Keyboard(), releaseMouse/Keyboard(), activateWindow().

File size: 22.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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 "QtGui/qregion.h"
61#include "QtGui/qsizepolicy.h"
62#include "QtGui/qstyle.h"
63
64#ifdef Q_WS_WIN
65#include "QtCore/qt_windows.h"
66#include <private/qdnd_p.h>
67#endif // Q_WS_WIN
68
69#ifdef Q_WS_PM
70#include "QtCore/qt_os2.h"
71#endif
72
73#ifdef Q_WS_X11
74#include "QtGui/qx11info_x11.h"
75#endif
76
77#ifdef Q_WS_MAC
78#include <private/qt_mac_p.h>
79#endif
80
81#if defined(Q_WS_QWS)
82#include "QtGui/qinputcontext.h"
83#include "QtGui/qscreen_qws.h"
84#endif
85
86QT_BEGIN_NAMESPACE
87
88// Extra QWidget data
89// - to minimize memory usage for members that are seldom used.
90// - top-level widgets have extra extra data to reduce cost further
91#if defined(Q_WS_QWS)
92class QWSManager;
93#endif
94#if defined(Q_WS_MAC)
95class QCoreGraphicsPaintEnginePrivate;
96#endif
97class QPaintEngine;
98class QPixmap;
99class QWidgetBackingStore;
100class QGraphicsProxyWidget;
101class QWidgetItemV2;
102
103class QStyle;
104
105struct QTLWExtra {
106 QString caption; // widget caption
107 QString iconText; // widget icon text
108 QString role; // widget role
109 QString filePath; // widget file path
110 QIcon *icon; // widget icon
111 QPixmap *iconPixmap;
112 short incw, inch; // size increments
113 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
114 QRect frameStrut;
115 uint opacity : 8;
116 uint posFromMove : 1;
117 uint sizeAdjusted : 1;
118 uint inTopLevelResize : 1;
119 uint inRepaint : 1;
120 QWidgetBackingStore *backingStore;
121#if defined(Q_WS_WIN)
122 ulong savedFlags; // Save window flags while showing fullscreen
123 uint embedded : 1; // window is embedded in another application
124#else
125 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
126#endif
127 short basew, baseh; // base sizes
128#if defined(Q_WS_X11)
129 WId parentWinId; // parent window Id (valid after reparenting)
130 uint embedded : 1; // window is embedded in another Qt application
131 uint spont_unmapped: 1; // window was spontaneously unmapped
132 uint dnd : 1; // DND properties installed
133 uint validWMState : 1; // is WM_STATE valid?
134 uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
135 WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
136 QPoint fullScreenOffset;
137#endif
138#if defined(Q_WS_MAC)
139 quint32 wattr;
140 quint32 wclass;
141 WindowGroupRef group;
142 IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
143 quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
144 uint resizer : 4;
145 uint isSetGeometry : 1;
146 uint isMove : 1;
147 uint embedded : 1;
148#endif
149#if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER)
150 QWSManager *qwsManager;
151#endif
152#if defined(Q_WS_WIN)
153 HICON winIconBig; // internal big Windows icon
154 HICON winIconSmall; // internal small Windows icon
155#endif
156#if defined(Q_WS_PM)
157 HWND fId;
158 HSWITCH swEntry;
159#endif
160 QRect normalGeometry; // used by showMin/maximized/FullScreen
161 QWindowSurface *windowSurface;
162 QPainter *sharedPainter;
163};
164
165struct QWExtra {
166 qint32 minw, minh; // minimum size
167 qint32 maxw, maxh; // maximum size
168 QPointer<QWidget> focus_proxy;
169#ifndef QT_NO_CURSOR
170 QCursor *curs;
171#endif
172 QTLWExtra *topextra; // only useful for TLWs
173 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
174 void *glContext; // if the widget is hijacked by QGLWindowSurface
175#if defined(Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP)
176 QOleDropTarget *dropTarget; // drop target
177 QList<QPointer<QWidget> > oleDropWidgets;
178#endif
179#if defined(Q_WS_X11)
180 WId xDndProxy; // XDND forwarding to embedded windows
181#endif
182 QRegion mask; // widget mask
183 QSize staticContentsSize;
184
185//bit flags at the end to improve packing
186#if defined(Q_WS_WIN)
187 uint shown_mode : 8; // widget show mode
188#ifndef QT_NO_DIRECT3D
189 uint had_paint_on_screen : 1;
190 uint had_no_system_bg : 1;
191 uint had_auto_fill_bg : 1;
192#endif
193#endif
194#if defined(Q_WS_X11)
195 uint compress_events : 1;
196#endif
197 uint explicitMinSize : 2;
198 uint explicitMaxSize : 2;
199 uint autoFillBackground : 1;
200 uint nativeChildrenForced : 1;
201 uint inRenderWithPainter : 1;
202 uint hasMask : 1;
203
204 QPointer<QStyle> style;
205 QString styleSheet;
206
207 quint16 customDpiX;
208 quint16 customDpiY;
209#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
210 // Cocoa Mask stuff
211 QImage maskBits;
212 CGImageRef imageMask;
213#endif
214};
215
216class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
217{
218 Q_DECLARE_PUBLIC(QWidget)
219
220public:
221 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
222 ~QWidgetPrivate();
223
224 QWExtra *extraData() const;
225 QTLWExtra *topData() const;
226 QTLWExtra *maybeTopData() const;
227 QPainter *sharedPainter() const;
228 void setSharedPainter(QPainter *painter);
229 QWidgetBackingStore *maybeBackingStore() const;
230#ifdef Q_WS_QWS
231 void setMaxWindowState_helper();
232 void setFullScreenSize_helper();
233#endif
234 void init(QWidget *desktopWidget, Qt::WindowFlags f);
235 void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
236 void createRecursively();
237 void createWinId(WId id = 0);
238
239 void createTLExtra();
240 void createExtra();
241 void deleteExtra();
242 void createSysExtra();
243 void deleteSysExtra();
244 void createTLSysExtra();
245 void deleteTLSysExtra();
246 void updateSystemBackground();
247 void propagatePaletteChange();
248
249 void setPalette_helper(const QPalette &);
250 void resolvePalette();
251 QPalette naturalWidgetPalette(uint inheritedMask) const;
252
253 void setMask_sys(const QRegion &);
254#ifdef Q_WS_WIN
255 bool shouldShowMaximizeButton();
256 void winUpdateIsOpaque();
257#endif
258
259#ifdef Q_WS_MAC
260 void macUpdateSizeAttribute();
261 void macUpdateHideOnSuspend();
262 void macUpdateOpaqueSizeGrip();
263 void macUpdateIgnoreMouseEvents();
264 void macUpdateMetalAttribute();
265 void macUpdateIsOpaque();
266 void setEnabled_helper_sys(bool enable);
267 bool isRealWindow() const;
268#endif
269
270 void raise_sys();
271 void lower_sys();
272 void stackUnder_sys(QWidget *);
273
274 void setFocus_sys();
275
276 void updateFont(const QFont &);
277 inline void setFont_helper(const QFont &font) {
278 if (data.fnt == font && data.fnt.resolve() == font.resolve())
279 return;
280 updateFont(font);
281 }
282 void resolveFont();
283 QFont naturalWidgetFont(uint inheritedMask) const;
284
285 void setLayoutDirection_helper(Qt::LayoutDirection);
286 void resolveLayoutDirection();
287
288 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
289 void resolveLocale();
290
291 void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
292 void inheritStyle();
293
294 bool isBackgroundInherited() const;
295
296 void setUpdatesEnabled_helper(bool );
297
298 void paintBackground(QPainter *, const QRegion &, const QPoint & = QPoint(), int flags = DrawAsRoot) const;
299 enum DrawWidgetFlags {
300 DrawAsRoot = 0x01,
301 DrawPaintOnScreen = 0x02,
302 DrawRecursive = 0x04,
303 DrawInvisible = 0x08,
304 DontSubtractOpaqueChildren = 0x10,
305 DontSetCompositionMode = 0x20,
306 DontDrawOpaqueChildren = 0x40
307 };
308 bool isAboutToShow() const;
309 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
310 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
311 QWidget::RenderFlags renderFlags);
312 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
313 QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0);
314
315
316 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
317 const QRegion &rgn, const QPoint &offset, int flags
318#ifdef Q_BACKINGSTORE_SUBSURFACES
319 , const QWindowSurface *currentSurface
320#endif
321 , QPainter *sharedPainter, QWidgetBackingStore *backingStore);
322
323
324 QPainter *beginSharedPainter();
325 bool endSharedPainter();
326 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(QWidget *origin);
327 QWindowSurface *createDefaultWindowSurface();
328 QWindowSurface *createDefaultWindowSurface_sys();
329 void repaint_sys(const QRegion &rgn);
330#ifdef Q_WS_MAC
331 void update_sys(const QRect &rect);
332 void update_sys(const QRegion &rgn);
333#endif
334
335 QRect clipRect() const;
336 QRegion clipRegion() const;
337 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
338 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = 0,
339 bool alsoNonOpaque = false) const;
340 void clipToEffectiveMask(QRegion &region) const;
341 void updateIsOpaque();
342 void setOpaque(bool opaque);
343 void updateIsTranslucent();
344 bool hasBackground() const;
345 bool paintOnScreen() const;
346
347 QRegion getOpaqueRegion() const;
348 const QRegion &getOpaqueChildren() const;
349 void setDirtyOpaqueRegion();
350
351 QRegion opaqueChildren;
352
353 enum CloseMode {
354 CloseNoEvent,
355 CloseWithEvent,
356 CloseWithSpontaneousEvent
357 };
358 bool close_helper(CloseMode mode);
359
360 bool compositeEvent(QEvent *e);
361 void setWindowIcon_helper();
362 void setWindowIcon_sys(bool forceReset = false);
363 void setWindowOpacity_sys(qreal opacity);
364
365 void adjustQuitOnCloseAttribute();
366
367#if defined(Q_WS_X11)
368 void setWindowRole();
369 void sendStartupMessage(const char *message) const;
370 void setNetWmWindowTypes();
371 void x11UpdateIsOpaque();
372#endif
373
374#if defined(Q_WS_WIN) || defined(Q_WS_PM)
375 void reparentChildren();
376#endif
377
378 void scrollChildren(int dx, int dy);
379
380 void moveRect(const QRect &, int dx, int dy);
381 void scrollRect(const QRect &, int dx, int dy);
382 void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
383 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
384 void invalidateBuffer(const QRegion &);
385 void invalidateBuffer(const QRect &);
386 bool isOverlapped(const QRect&) const;
387 void syncBackingStore();
388 void syncBackingStore(const QRegion &region);
389
390 void reparentFocusWidgets(QWidget *oldtlw);
391
392 static int pointToRect(const QPoint &p, const QRect &r);
393 QRect fromOrToLayoutItemRect(const QRect &rect, int sign) const;
394
395 void setWinId(WId);
396 void showChildren(bool spontaneous);
397 void hideChildren(bool spontaneous);
398 void setParent_sys(QWidget *parent, Qt::WindowFlags);
399 void scroll_sys(int dx, int dy);