Cocoa: Make sure we can display multiple sheets for the same NSWindow

On macOS, to display a modal with Qt::WindowModality set, or of type
Qt::Sheet, we call beginSheet:completinHandler:. However, this method
won't display the specified sheet unless the current active one is
dismissed, which is a different behavior than what we expect for
this case. Use beginCriticalSheet:completionHandler: whenever we
already have an active sheet attached to the NSWindow, which allows
us to display multiple sheets for the same window.

Fixes: QTBUG-91059
Pick-to: 5.15 6.1 6.2
Change-Id: I86bdbcbd63758edbbc48a8aade0178917dcb0e5b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Doris Verria 2021-09-07 15:26:30 +02:00
parent 7dc05252a0
commit f3bc1f8500

View File

@ -368,7 +368,11 @@ void QCocoaWindow::setVisible(bool visible)
if (window()->windowState() != Qt::WindowMinimized) { if (window()->windowState() != Qt::WindowMinimized) {
if (parentCocoaWindow && (window()->modality() == Qt::WindowModal || window()->type() == Qt::Sheet)) { if (parentCocoaWindow && (window()->modality() == Qt::WindowModal || window()->type() == Qt::Sheet)) {
// Show the window as a sheet // Show the window as a sheet
[parentCocoaWindow->nativeWindow() beginSheet:m_view.window completionHandler:nil]; NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow();
if (!nativeParentWindow.attachedSheet)
[nativeParentWindow beginSheet:m_view.window completionHandler:nil];
else
[nativeParentWindow beginCriticalSheet:m_view.window completionHandler:nil];
} else if (window()->modality() == Qt::ApplicationModal) { } else if (window()->modality() == Qt::ApplicationModal) {
// Show the window as application modal // Show the window as application modal
eventDispatcher()->beginModalSession(window()); eventDispatcher()->beginModalSession(window());