Windows: handle multiple transient children when closing windows

On Windows, we must update the transient children of a window that's
about to be destroyed or its transient children will be destroyed as
well. This is already being done in the case of a single transient
child, but there are still problems when there are more than one.

Change-Id: Ib0de6767bf43dca508ecdb87cbdfedb59e9146e8
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Mauro Persano 2018-03-29 10:37:25 -03:00
parent ee6164942d
commit 2e496e9322

View File

@ -1161,23 +1161,19 @@ void QWindowsWindow::fireExpose(const QRegion &region, bool force)
QWindowSystemInterface::handleExposeEvent(window(), region);
}
static inline QWindow *findTransientChild(const QWindow *parent)
{
foreach (QWindow *w, QGuiApplication::topLevelWindows())
if (w->transientParent() == parent)
return w;
return 0;
}
void QWindowsWindow::destroyWindow()
{
qCDebug(lcQpaWindows) << __FUNCTION__ << this << window() << m_data.hwnd;
if (m_data.hwnd) { // Stop event dispatching before Window is destroyed.
setFlag(WithinDestroy);
// Clear any transient child relationships as Windows will otherwise destroy them (QTBUG-35499, QTBUG-36666)
if (QWindow *transientChild = findTransientChild(window()))
if (QWindowsWindow *tw = QWindowsWindow::windowsWindowOf(transientChild))
tw->updateTransientParent();
const auto tlw = QGuiApplication::topLevelWindows();
for (QWindow *w : tlw) {
if (w->transientParent() == window()) {
if (QWindowsWindow *tw = QWindowsWindow::windowsWindowOf(w))
tw->updateTransientParent();
}
}
QWindowsContext *context = QWindowsContext::instance();
if (context->windowUnderMouse() == window())
context->clearWindowUnderMouse();