Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | class QWindowContainerPrivate : public QWidgetPrivate | - |
6 | { | - |
7 | public: | - |
8 | inline QWindowContainer* q_func() { return static_cast<QWindowContainer *>(q_ptr); } inline const QWindowContainer* q_func() const { return static_cast<const QWindowContainer *>(q_ptr); } friend class QWindowContainer; | - |
9 | | - |
10 | QWindowContainerPrivate() | - |
11 | : window(0) | - |
12 | , oldFocusWindow(0) | - |
13 | , usesNativeWidgets(false) | - |
14 | { | - |
15 | } | - |
16 | | - |
17 | ~QWindowContainerPrivate() { } | - |
18 | | - |
19 | static QWindowContainerPrivate *get(QWidget *w) { | - |
20 | QWindowContainer *wc = qobject_cast<QWindowContainer *>(w); | - |
21 | if (wc) | - |
22 | return wc->d_func(); | - |
23 | return 0; | - |
24 | } | - |
25 | | - |
26 | void updateGeometry() { | - |
27 | QWindowContainer * const q = q_func(); | - |
28 | if (!q->isWindow() && (q->geometry().bottom() <= 0 || q->geometry().right() <= 0)) | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | window->setGeometry(q->geometry()); | - |
35 | else if (usesNativeWidgets) | - |
36 | window->setGeometry(q->rect()); | - |
37 | else | - |
38 | window->setGeometry(QRect(q->mapTo(q->window(), QPoint()), q->size())); | - |
39 | } | - |
40 | | - |
41 | void updateUsesNativeWidgets() | - |
42 | { | - |
43 | if (usesNativeWidgets || window->parent() == 0) | - |
44 | return; | - |
45 | QWindowContainer * const q = q_func(); | - |
46 | if (q->internalWinId()) { | - |
47 | | - |
48 | usesNativeWidgets = true; | - |
49 | return; | - |
50 | } | - |
51 | QWidget *p = q->parentWidget(); | - |
52 | while (p) { | - |
53 | if ( | - |
54 | | - |
55 | qobject_cast<QMdiSubWindow *>(p) != 0 || | - |
56 | | - |
57 | qobject_cast<QAbstractScrollArea *>(p) != 0) { | - |
58 | q->winId(); | - |
59 | usesNativeWidgets = true; | - |
60 | break; | - |
61 | } | - |
62 | p = p->parentWidget(); | - |
63 | } | - |
64 | } | - |
65 | | - |
66 | void markParentChain() { | - |
67 | QWindowContainer * const q = q_func(); | - |
68 | QWidget *p = q; | - |
69 | while (p) { | - |
70 | QWidgetPrivate *d = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(p)); | - |
71 | d->createExtra(); | - |
72 | d->extra->hasWindowContainer = true; | - |
73 | p = p->parentWidget(); | - |
74 | } | - |
75 | } | - |
76 | | - |
77 | bool isStillAnOrphan() const { | - |
78 | return window->parent() == &fakeParent; | - |
79 | } | - |
80 | | - |
81 | QPointer<QWindow> window; | - |
82 | QWindow *oldFocusWindow; | - |
83 | QWindow fakeParent; | - |
84 | | - |
85 | uint usesNativeWidgets : 1; | - |
86 | }; | - |
87 | QWidget *QWidget::createWindowContainer(QWindow *window, QWidget *parent, Qt::WindowFlags flags) | - |
88 | { | - |
89 | return new QWindowContainer(window, parent, flags); | - |
90 | } | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt::WindowFlags flags) | - |
99 | : QWidget(*new QWindowContainerPrivate, parent, flags) | - |
100 | { | - |
101 | QWindowContainerPrivate * const d = d_func(); | - |
102 | if (!(__builtin_expect(!!(!TRUE | never evaluated | FALSE | never evaluated |
embeddedWindow)), false)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
103 | QMessageLogger(__FILE__, 204210, __PRETTY_FUNCTION__).warning("QWindowContainer: embedded window cannot be null"); | - |
104 | return; never executed: return; | 0 |
105 | } | - |
106 | | - |
107 | | - |
108 | | - |
109 | if (embeddedWindow->surfaceType() == QSurface::RasterSurfaceTRUE | never evaluated | FALSE | never evaluated |
| 0 |
110 | && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
111 | && !QApplication::testAttribute(Qt::AA_ForceRasterWidgets)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
112 | embeddedWindow->setSurfaceType(QSurface::RasterGLSurface); never executed: embeddedWindow->setSurfaceType(QSurface::RasterGLSurface); | 0 |
113 | | - |
114 | d->window = embeddedWindow; | - |
115 | d->window->setParent(&d->fakeParent); | - |
116 | setAcceptDrops(true); | - |
117 | | - |
118 | connect(QGuiApplication::instance(), qFlagLocation("2""focusWindowChanged(QWindow*)" "\0" __FILE__ ":" "219""225"), this, qFlagLocation("1""focusWindowChanged(QWindow*)" "\0" __FILE__ ":" "219""225")); | - |
119 | } never executed: end of block | 0 |
120 | | - |
121 | QWindow *QWindowContainer::containedWindow() const | - |
122 | { | - |
123 | const QWindowContainerPrivate * const d = d_func(); | - |
124 | return d->window; | - |
125 | } | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | QWindowContainer::~QWindowContainer() | - |
132 | { | - |
133 | QWindowContainerPrivate * const d = d_func(); | - |
134 | delete d->window; | - |
135 | } | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | void QWindowContainer::focusWindowChanged(QWindow *focusWindow) | - |
144 | { | - |
145 | QWindowContainerPrivate * const d = d_func(); | - |
146 | d->oldFocusWindow = focusWindow; | - |
147 | if (focusWindow == d->window) { | - |
148 | QWidget *widget = QApplication::focusWidget(); | - |
149 | if (widget) | - |
150 | widget->clearFocus(); | - |
151 | } | - |
152 | } | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | bool QWindowContainer::event(QEvent *e) | - |
159 | { | - |
160 | QWindowContainerPrivate * const d = d_func(); | - |
161 | if (!d->window) | - |
162 | return QWidget::event(e); | - |
163 | | - |
164 | QEvent::Type type = e->type(); | - |
165 | switch (type) { | - |
166 | case QEvent::ChildRemoved: { | - |
167 | QChildEvent *ce = static_cast<QChildEvent *>(e); | - |
168 | if (ce->child() == d->window) | - |
169 | d->window = 0; | - |
170 | break; | - |
171 | } | - |
172 | | - |
173 | | - |
174 | case QEvent::Resize: | - |
175 | d->updateGeometry(); | - |
176 | break; | - |
177 | case QEvent::Move: | - |
178 | d->updateGeometry(); | - |
179 | break; | - |
180 | case QEvent::PolishRequest: | - |
181 | d->updateGeometry(); | - |
182 | break; | - |
183 | case QEvent::Show: | - |
184 | d->updateUsesNativeWidgets(); | - |
185 | if (d->isStillAnOrphan()) { | - |
186 | d->window->setParent(d->usesNativeWidgets | - |
187 | ? windowHandle() | - |
188 | : window()->windowHandle()); | - |
189 | } | - |
190 | if (d->window->parent()) { | - |
191 | d->markParentChain(); | - |
192 | d->window->show(); | - |
193 | } | - |
194 | break; | - |
195 | case QEvent::Hide: | - |
196 | if (d->window->parent()) | - |
197 | d->window->hide(); | - |
198 | break; | - |
199 | case QEvent::FocusIn: | - |
200 | if (d->window->parent()) { | - |
201 | if (d->oldFocusWindow != d->window) { | - |
202 | d->window->requestActivate(); | - |
203 | } else { | - |
204 | QWidget *next = nextInFocusChain(); | - |
205 | next->setFocus(); | - |
206 | } | - |
207 | } | - |
208 | break; | - |
209 | | - |
210 | case QEvent::Drop: | - |
211 | case QEvent::DragMove: | - |
212 | case QEvent::DragLeave: | - |
213 | QCoreApplication::sendEvent(d->window, e); | - |
214 | return e->isAccepted(); | - |
215 | case QEvent::DragEnter: | - |
216 | | - |
217 | | - |
218 | QCoreApplication::sendEvent(d->window, e); | - |
219 | e->accept(); | - |
220 | return true; | - |
221 | | - |
222 | default: | - |
223 | break; | - |
224 | } | - |
225 | | - |
226 | return QWidget::event(e); | - |
227 | } | - |
228 | | - |
229 | typedef void (*qwindowcontainer_traverse_callback)(QWidget *parent); | - |
230 | static void qwindowcontainer_traverse(QWidget *parent, qwindowcontainer_traverse_callback callback) | - |
231 | { | - |
232 | const QObjectList &children = parent->children(); | - |
233 | for (int i=0; i<children.size(); ++i) { | - |
234 | QWidget *w = qobject_cast<QWidget *>(children.at(i)); | - |
235 | if (w) { | - |
236 | QWidgetPrivate *wd = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(w)); | - |
237 | if (wd->extra && wd->extra->hasWindowContainer) | - |
238 | callback(w); | - |
239 | } | - |
240 | } | - |
241 | } | - |
242 | | - |
243 | void QWindowContainer::toplevelAboutToBeDestroyed(QWidget *parent) | - |
244 | { | - |
245 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
246 | d->window->setParent(&d->fakeParent); | - |
247 | } | - |
248 | qwindowcontainer_traverse(parent, toplevelAboutToBeDestroyed); | - |
249 | } | - |
250 | | - |
251 | void QWindowContainer::parentWasChanged(QWidget *parent) | - |
252 | { | - |
253 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
254 | if (d->window->parent()) { | - |
255 | d->updateUsesNativeWidgets(); | - |
256 | d->markParentChain(); | - |
257 | QWidget *toplevel = d->usesNativeWidgets ? parent : parent->window(); | - |
258 | if (!toplevel->windowHandle()) { | - |
259 | QWidgetPrivate *tld = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(toplevel)); | - |
260 | tld->createTLExtra(); | - |
261 | tld->createTLSysExtra(); | - |
262 | ((!(toplevel->windowHandle())) ? qt_assert("toplevel->windowHandle()",__FILE__,363369) : qt_noop()); | - |
263 | } | - |
264 | d->window->setParent(toplevel->windowHandle()); | - |
265 | d->updateGeometry(); | - |
266 | } | - |
267 | } | - |
268 | qwindowcontainer_traverse(parent, parentWasChanged); | - |
269 | } | - |
270 | | - |
271 | void QWindowContainer::parentWasMoved(QWidget *parent) | - |
272 | { | - |
273 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
274 | if (d->window->parent()) | - |
275 | d->updateGeometry(); | - |
276 | } | - |
277 | qwindowcontainer_traverse(parent, parentWasMoved); | - |
278 | } | - |
279 | | - |
280 | void QWindowContainer::parentWasRaised(QWidget *parent) | - |
281 | { | - |
282 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
283 | if (d->window->parent()) | - |
284 | d->window->raise(); | - |
285 | } | - |
286 | qwindowcontainer_traverse(parent, parentWasRaised); | - |
287 | } | - |
288 | | - |
289 | void QWindowContainer::parentWasLowered(QWidget *parent) | - |
290 | { | - |
291 | if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { | - |
292 | if (d->window->parent()) | - |
293 | d->window->lower(); | - |
294 | } | - |
295 | qwindowcontainer_traverse(parent, parentWasLowered); | - |
296 | } | - |
297 | | - |
298 | | - |
299 | | - |
| | |