Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qwindowcontainer_p.h" | - |
41 | #include "qwidget_p.h" | - |
42 | #include <QtGui/qwindow.h> | - |
43 | #include <QtGui/private/qguiapplication_p.h> | - |
44 | #include <qpa/qplatformintegration.h> | - |
45 | #include <QDebug> | - |
46 | | - |
47 | #include <QMdiSubWindow> | - |
48 | #include <QAbstractScrollArea> | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | class QWindowContainerPrivate : public QWidgetPrivate | - |
53 | { | - |
54 | public: | - |
55 | Q_DECLARE_PUBLIC(QWindowContainer) | - |
56 | | - |
57 | QWindowContainerPrivate() | - |
58 | : window(0) | - |
59 | , oldFocusWindow(0) | - |
60 | , usesNativeWidgets(false) | - |
61 | { | - |
62 | } | - |
63 | | - |
64 | ~QWindowContainerPrivate() { } | - |
65 | | - |
66 | static QWindowContainerPrivate *get(QWidget *w) { | - |
67 | QWindowContainer *wc = qobject_cast<QWindowContainer *>(w); | - |
68 | if (wc) | - |
69 | return wc->d_func(); | - |
70 | return 0; | - |
71 | } | - |
72 | | - |
73 | void updateGeometry() { | - |
74 | Q_Q(QWindowContainer); | - |
75 | if (!q->isWindow() && (q->geometry().bottom() <= 0 || q->geometry().right() <= 0)) | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | window->setGeometry(q->geometry()); | - |
82 | else if (usesNativeWidgets) | - |
83 | window->setGeometry(q->rect()); | - |
84 | else | - |
85 | window->setGeometry(QRect(q->mapTo(q->window(), QPoint()), q->size())); | - |
86 | } | - |
87 | | - |
88 | void updateUsesNativeWidgets() | - |
89 | { | - |
90 | if (usesNativeWidgets || window->parent() == 0) | - |
91 | return; | - |
92 | Q_Q(QWindowContainer); | - |
93 | if (q->internalWinId()) { | - |
94 | | - |
95 | usesNativeWidgets = true; | - |
96 | return; | - |
97 | } | - |
98 | QWidget *p = q->parentWidget(); | - |
99 | while (p) { | - |
100 | if ( | - |
101 | #ifndef QT_NO_MDIAREA | - |
102 | qobject_cast<QMdiSubWindow *>(p) != 0 || | - |
103 | #endif | - |
104 | qobject_cast<QAbstractScrollArea *>(p) != 0) { | - |
105 | q->winId(); | - |
106 | usesNativeWidgets = true; | - |
107 | break; | - |
108 | } | - |
109 | p = p->parentWidget(); | - |
110 | } | - |
111 | } | - |
112 | | - |
113 | void markParentChain() { | - |
114 | Q_Q(QWindowContainer); | - |
115 | QWidget *p = q; | - |
116 | while (p) { | - |
117 | QWidgetPrivate *d = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(p)); | - |
118 | d->createExtra(); | - |
119 | d->extra->hasWindowContainer = true; | - |
120 | p = p->parentWidget(); | - |
121 | } | - |
122 | } | - |
123 | | - |
124 | bool isStillAnOrphan() const { | - |
125 | return window->parent() == &fakeParent; | - |
126 | } | - |
127 | | - |
128 | QPointer<QWindow> window; | - |
129 | QWindow *oldFocusWindow; | - |
130 | QWindow fakeParent; | - |
131 | | - |
132 | uint usesNativeWidgets : 1; | - |
133 | }; | - |
134 | | - |
135 | | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | QWidget *QWidget::createWindowContainer(QWindow *window, QWidget *parent, Qt::WindowFlags flags) | - |
195 | { | - |
196 | return new QWindowContainer(window, parent, flags); | - |
197 | } | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt::WindowFlags flags) | - |
206 | : QWidget(*new QWindowContainerPrivate, parent, flags) | - |
207 | { | - |
208 | Q_D(QWindowContainer); | - |
209 | if (Q_UNLIKELY(!embeddedWindow))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
210 | qWarning("QWindowContainer: embedded window cannot be null"); | - |
211 | return; never executed: return; | 0 |
212 | } | - |
213 | | - |
214 | | - |
215 | | - |
216 | if (embeddedWindow->surfaceType() == QSurface::RasterSurfaceTRUE | never evaluated | FALSE | never evaluated |
| 0 |
217 | && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
218 | && !QApplication::testAttribute(Qt::AA_ForceRasterWidgets))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
219 | embeddedWindow->setSurfaceType(QSurface::RasterGLSurface); never executed: embeddedWindow->setSurfaceType(QSurface::RasterGLSurface); | 0 |
220 | | - |
221 | d->window = embeddedWindow; | - |
222 | d->window->setParent(&d->fakeParent); | - |
223 | setAcceptDrops(true); | - |
224 | | - |
225 | connect(QGuiApplication::instance(), SIGNAL(focusWindowChanged(QWindow*)), this, SLOT(focusWindowChanged(QWindow*))); | - |
226 | } never executed: end of block | 0 |
227 | | - |
228 | QWindow *QWindowContainer::containedWindow() const | - |
229 | { | - |
230 | Q_D(const QWindowContainer); | - |
231 | return d->window; | - |
232 | } | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | QWindowContainer::~QWindowContainer() | - |
239 | { | - |
240 | Q_D(QWindowContainer); | - |
241 | delete d->window; | - |
242 | } | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | | - |
248 | | - |
249 | | - |
250 | void QWindowContainer::focusWindowChanged(QWindow *focusWindow) | - |
251 | { | - |
252 | Q_D(QWindowContainer); | - |
253 | d->oldFocusWindow = focusWindow; | - |
254 | if (focusWindow == d->window) { | - |
255 | QWidget *widget = QApplication::focusWidget(); | - |
256 | if (widget) | - |
257 | widget->clearFocus(); | - |
258 | } | - |
259 | } | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | bool QWindowContainer::event(QEvent *e) | - |
266 | { | - |
267 | Q_D(QWindowContainer); | - |
268 | if (!d->window) | - |
269 | return QWidget::event(e); | - |
270 | | - |
271 | QEvent::Type type = e->type(); | - |
272 | switch (type) { | - |
273 | case QEvent::ChildRemoved: { | - |
274 | QChildEvent *ce = static_cast<QChildEvent *>(e); | - |
275 | if (ce->child() == d->window) | - |
276 | d->window = 0; | - |
277 | break; | - |
278 | } | - |
279 | | - |
280 | | - |
281 | case QEvent::Resize: | - |
282 | d->updateGeometry(); | - |
283 | break; | - |
284 | case QEvent::Move: | - |
285 | d->updateGeometry(); | - |
286 | break; | - |
287 | case QEvent::PolishRequest: | - |
288 | d->updateGeometry(); | - |
289 | break; | - |
290 | case QEvent::Show: | - |
291 | d->updateUsesNativeWidgets(); | - |
292 | if (d->isStillAnOrphan()) { | - |
293 | d->window->setParent(d->usesNativeWidgets | - |
294 | ? windowHandle() | - |
295 | : window()->windowHandle()); | - |
296 | } | - |
297 | if (d->window->parent()) { | - |
298 | d->markParentChain(); | - |
299 | d->window->show(); | - |
300 | } | - |
301 | break; | - |
302 | case QEvent::Hide: | - |
303 | if (d->window->parent()) | - |
304 | d->window->hide(); | - |
305 | break; | - |
306 | case QEvent::FocusIn: | - |
307 | if (d->window->parent()) { | - |
308 | if (d->oldFocusWindow != d->window) { | - |
309 | d->window->requestActivate(); | - |
310 | } else { | - |
311 | QWidget *next = nextInFocusChain(); | - |
312 | next->setFocus(); | - |
313 | } | - |
314 | } | - |
315 | break; | - |
316 | #ifndef QT_NO_DRAGANDDROP | - |
317 | case QEvent::Drop: | - |
318 | case QEvent::DragMove: | - |
319 | case QEvent::DragLeave: | - |
320 | QCoreApplication::sendEvent(d->window, e); | - |
321 | return e->isAccepted(); | - |
322 | case QEvent::DragEnter: | - |
323 | | - |
324 | | - |
325 | QCoreApplication::sendEvent(d->window, e); | - |
326 | e->accept(); | - |
327 | return true; | - |
328 | #endif | - |
329 | default: | - |
330 | break; | - |
331 | } | - |
332 | | - |
333 | return QWidget::event(e); | - |
334 | } | - |
335 | | - |
336 | typedef void (*qwindowcontainer_traverse_callback)(QWidget *parent); | - |
337 | static void qwindowcontainer_traverse(QWidget *parent, qwindowcontainer_traverse_callback callback) | - |
338 | { | - |
339 | const QObjectList &children = parent->children(); | - |
340 | for (int i=0; i<children.size(); ++i) { | - |
341 | QWidget *w = qobject_cast<QWidget *>(children.at(i)); | - |
342 | if (w) { | - |
343 | QWidgetPrivate *wd = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(w)); | - |
344 | if (wd->extra && wd->extra->hasWindowContainer) | - |
345 | callback(w); | - |
346 | } | - |
347 | } | - |
348 | } | - |
349 | | - |
350 | void QWindowContainer::toplevelAboutToBeDestroyed(QWidget *parent) | - |
351 | { | - |
352 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
353 | d->window->setParent(&d->fakeParent); | - |
354 | } | - |
355 | qwindowcontainer_traverse(parent, toplevelAboutToBeDestroyed); | - |
356 | } | - |
357 | | - |
358 | void QWindowContainer::parentWasChanged(QWidget *parent) | - |
359 | { | - |
360 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
361 | if (d->window->parent()) { | - |
362 | d->updateUsesNativeWidgets(); | - |
363 | d->markParentChain(); | - |
364 | QWidget *toplevel = d->usesNativeWidgets ? parent : parent->window(); | - |
365 | if (!toplevel->windowHandle()) { | - |
366 | QWidgetPrivate *tld = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(toplevel)); | - |
367 | tld->createTLExtra(); | - |
368 | tld->createTLSysExtra(); | - |
369 | Q_ASSERT(toplevel->windowHandle()); | - |
370 | } | - |
371 | d->window->setParent(toplevel->windowHandle()); | - |
372 | d->updateGeometry(); | - |
373 | } | - |
374 | } | - |
375 | qwindowcontainer_traverse(parent, parentWasChanged); | - |
376 | } | - |
377 | | - |
378 | void QWindowContainer::parentWasMoved(QWidget *parent) | - |
379 | { | - |
380 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
381 | if (d->window->parent()) | - |
382 | d->updateGeometry(); | - |
383 | } | - |
384 | qwindowcontainer_traverse(parent, parentWasMoved); | - |
385 | } | - |
386 | | - |
387 | void QWindowContainer::parentWasRaised(QWidget *parent) | - |
388 | { | - |
389 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
390 | if (d->window->parent()) | - |
391 | d->window->raise(); | - |
392 | } | - |
393 | qwindowcontainer_traverse(parent, parentWasRaised); | - |
394 | } | - |
395 | | - |
396 | void QWindowContainer::parentWasLowered(QWidget *parent) | - |
397 | { | - |
398 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
399 | if (d->window->parent()) | - |
400 | d->window->lower(); | - |
401 | } | - |
402 | qwindowcontainer_traverse(parent, parentWasLowered); | - |
403 | } | - |
404 | | - |
405 | QT_END_NAMESPACE | - |
406 | | - |
407 | #include "moc_qwindowcontainer_p.cpp" | - |
| | |