macOS: Mark the widget's container as embedded when placed into NSMenuItem

Otherwise we'll end up creating a NSPanel for the QMacNativeWidget which is
never closed, even if the backing NSView is moved to a new superview.

Ideally this would be based on [NSView viewDidMoveToSuperview] and
[NSView viewDidMoveToWindow], with retain/releases of the corresponding
NSWindow, but that needs more research, especially as AppKit on macOS
10.13 will always keep a strong reference to the NSWindow.

Task-number: QTBUG-63443
Change-Id: I9eec5ea871373d00dedf154600bf7005898cf37a
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-10-06 15:50:29 +02:00
parent ed9340a926
commit ac35f9c44c
2 changed files with 6 additions and 1 deletions

View File

@ -1240,7 +1240,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
if (m_windowModality != window()->modality())
recreateReason |= WindowModalityChanged;
const bool shouldBeContentView = !parentWindow && !m_viewIsEmbedded;
const bool shouldBeContentView = !parentWindow && !(m_viewIsToBeEmbedded || m_viewIsEmbedded);
if (isContentView() != shouldBeContentView)
recreateReason |= ContentViewChanged;

View File

@ -135,6 +135,11 @@ void QMenuPrivate::moveWidgetToPlatformItem(QWidget *widget, QPlatformMenuItem*
containerWindow->setFlags(wf | Qt::SubWindow);
[(NSView *)widget->winId() setAutoresizingMask:NSViewWidthSizable];
if (QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setEmbeddedInForeignView")) {
typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded);
reinterpret_cast<SetEmbeddedInForeignViewFunction>(function)(containerWindow->handle(), true);
}
item->setNativeContents((WId)containerView);
container->show();
}