cocoa: don't override NSApplication-sendEvent if configured as AA_MacPluginApplication

Change-Id: I48cebbcb814ee8e97583c3165e7cb668077cfbad
Task-number: QTBUG-40409
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
bb10
Tim Blechmann 2014-09-01 14:53:14 +02:00 committed by Morten Johan Sørvig
parent c8d2514347
commit 1126701f8c
3 changed files with 19 additions and 1 deletions

View File

@ -125,7 +125,7 @@
to author a plugin. This includes avoiding loading our nib for the main
menu and not taking possession of the native menu bar. When setting this
attribute to true will also set the AA_DontUseNativeMenuBar attribute
to true.
to true. It also disables native event filters.
\value AA_DontUseNativeMenuBar All menubars created while this attribute is
set to true won't be used as a native menubar (e.g, the menubar at

View File

@ -2528,6 +2528,9 @@ void QCoreApplication::removeLibraryPath(const QString &path)
\note The filter function set here receives native messages,
i.e. MSG or XCB event structs.
\note Native event filters will be disabled when the application the
Qt::AA_MacPluginApplication attribute is set.
For maximum portability, you should always try to use QEvents
and QObject::installEventFilter() whenever possible.
@ -2537,6 +2540,11 @@ void QCoreApplication::removeLibraryPath(const QString &path)
*/
void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
{
if (QCoreApplication::testAttribute(Qt::AA_MacPluginApplication)) {
qWarning("Native event filters are not applied when the Qt::AA_MacPluginApplication attribute is set");
return;
}
QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(QCoreApplicationPrivate::theMainThread);
if (!filterObj || !eventDispatcher)
return;

View File

@ -189,6 +189,12 @@ QT_BEGIN_NAMESPACE
void qt_redirectNSApplicationSendEvent()
{
if (QCoreApplication::testAttribute(Qt::AA_MacPluginApplication))
// In a plugin we cannot chain sendEvent hooks: a second plugin could
// store the implementation of the first, which during the program flow
// can be unloaded.
return;
if ([NSApp isMemberOfClass:[QNSApplication class]]) {
// No need to change implementation since Qt
// already controls a subclass of NSApplication
@ -209,6 +215,10 @@ void qt_redirectNSApplicationSendEvent()
void qt_resetNSApplicationSendEvent()
{
if (QCoreApplication::testAttribute(Qt::AA_MacPluginApplication))
return;
qt_cocoa_change_back_implementation([NSApplication class],
@selector(sendEvent:),
@selector(QT_MANGLE_NAMESPACE(qt_sendEvent_original):));