From 36ddfb6cc1bb4ece153e19d86e0175cbb7052310 Mon Sep 17 00:00:00 2001 From: Pavol Markovic Date: Thu, 25 May 2017 16:53:53 +1200 Subject: macOS: Replace category methods with functions Objective-C category methods prohibit safe unloading of dynamic libraries / plugins statically linked to Qt. Although they can be called in convenient way they can be replaced with standalone functions without noticeable drawback. Remove unused qt_validModesForFontPanel category method. Remove empty NSStatusItem (Qt) category. Task-number: QTBUG-59884 Change-Id: I69503a115b1177623da91c67b62d72e56f43ffcf Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoaapplication.h | 12 --------- src/plugins/platforms/cocoa/qcocoaapplication.mm | 30 ++++------------------ .../platforms/cocoa/qcocoanativeinterface.mm | 4 +-- .../platforms/cocoa/qcocoasystemtrayicon.mm | 3 --- 4 files changed, 7 insertions(+), 42 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.h b/src/plugins/platforms/cocoa/qcocoaapplication.h index 7bd3c8c76c..66a92686bc 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.h +++ b/src/plugins/platforms/cocoa/qcocoaapplication.h @@ -83,23 +83,11 @@ // We mean it. // -/* - Cocoa Application Categories -*/ #include "qglobal.h" #include "private/qcore_mac_p.h" #import -@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); - -@interface NSApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration)) -- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu; -- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel; - -- (void)QT_MANGLE_NAMESPACE(qt_sendPostedMessage):(NSEvent *)event; -- (BOOL)QT_MANGLE_NAMESPACE(qt_filterEvent):(NSEvent *)event; -@end @interface QT_MANGLE_NAMESPACE(QNSApplication) : NSApplication { } diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.mm b/src/plugins/platforms/cocoa/qcocoaapplication.mm index 3b950efa55..d0f27795b6 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplication.mm @@ -82,25 +82,7 @@ QT_USE_NAMESPACE -@implementation NSApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration)) - -- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu -{ - [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] setDockMenu:newMenu]; -} - -- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel -{ - Q_UNUSED(fontPanel); - // only display those things that QFont can handle - return NSFontPanelFaceModeMask - | NSFontPanelSizeModeMask - | NSFontPanelCollectionModeMask - | NSFontPanelUnderlineEffectModeMask - | NSFontPanelStrikethroughEffectModeMask; -} - -- (void)QT_MANGLE_NAMESPACE(qt_sendPostedMessage):(NSEvent *)event +static void qt_sendPostedMessage(NSEvent *event) { // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5! // That is why we need to split the address in two parts: @@ -128,7 +110,7 @@ QT_USE_NAMESPACE static const QByteArray q_macLocalEventType = QByteArrayLiteral("mac_generic_NSEvent"); -- (BOOL)QT_MANGLE_NAMESPACE(qt_filterEvent):(NSEvent *)event +static bool qt_filterEvent(NSEvent *event) { if (qApp && qApp->eventDispatcher()-> filterNativeEvent(q_macLocalEventType, static_cast(event), 0)) @@ -137,7 +119,7 @@ static const QByteArray q_macLocalEventType = QByteArrayLiteral("mac_generic_NSE if ([event type] == NSApplicationDefined) { switch (static_cast([event subtype])) { case QtCocoaEventSubTypePostMessage: - [NSApp QT_MANGLE_NAMESPACE(qt_sendPostedMessage):event]; + qt_sendPostedMessage(event); return true; default: break; @@ -147,8 +129,6 @@ static const QByteArray q_macLocalEventType = QByteArrayLiteral("mac_generic_NSE return false; } -@end - static void qt_maybeSendKeyEquivalentUpEvent(NSEvent *event) { // Cocoa is known for not sending key up events for key @@ -180,7 +160,7 @@ static void qt_maybeSendKeyEquivalentUpEvent(NSEvent *event) // be called instead of sendEvent if redirection occurs. // 'self' will then be an instance of NSApplication // (and not QNSApplication) - if (![NSApp QT_MANGLE_NAMESPACE(qt_filterEvent):event]) { + if (!qt_filterEvent(event)) { [self QT_MANGLE_NAMESPACE(qt_sendEvent_original):event]; qt_maybeSendKeyEquivalentUpEvent(event); } @@ -190,7 +170,7 @@ static void qt_maybeSendKeyEquivalentUpEvent(NSEvent *event) { // This method will be called if // no redirection occurs - if (![NSApp QT_MANGLE_NAMESPACE(qt_filterEvent):event]) { + if (!qt_filterEvent(event)) { [super sendEvent:event]; qt_maybeSendKeyEquivalentUpEvent(event); } diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 26ab07ffaf..5504c2427f 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -42,7 +42,7 @@ #include "qcocoamenu.h" #include "qcocoamenubar.h" #include "qcocoahelpers.h" -#include "qcocoaapplication.h" +#include "qcocoaapplicationdelegate.h" #include "qcocoaintegration.h" #include "qcocoaeventdispatcher.h" @@ -256,7 +256,7 @@ void QCocoaNativeInterface::setDockMenu(QPlatformMenu *platformMenu) QMacAutoReleasePool pool; QCocoaMenu *cocoaPlatformMenu = static_cast(platformMenu); NSMenu *menu = cocoaPlatformMenu->nsMenu(); - [NSApp QT_MANGLE_NAMESPACE(qt_setDockMenu): menu]; + [[QCocoaApplicationDelegate sharedDelegate] setDockMenu:menu]; } void *QCocoaNativeInterface::qMenuToNSMenu(QPlatformMenu *platformMenu) diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index 13e9d8809e..e756f0aeb0 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -289,9 +289,6 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess } QT_END_NAMESPACE -@implementation NSStatusItem (Qt) -@end - @implementation QNSImageView -(id)initWithParent:(QNSStatusItem*)myParent { self = [super init]; -- cgit v1.2.3 From 3f6bc9a9838e1bf27c10a01cfb2237afb60afe70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 9 Jan 2018 18:13:14 +0100 Subject: macOS: Namespace QNSWindowProtocol when building with -qtnamespace Otherwise the protocol name might clash with existing protocols when using Qt as a plugin, and those existing protocols may have lived in images that since have been unloaded, causing crashes. Change-Id: I68fbe290bcbf2fabf463647c960f686971e066dd Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoawindow.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index deba861fcc..aa8fffdf7e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -56,6 +56,9 @@ QT_FORWARD_DECLARE_CLASS(QCocoaWindow) @class QT_MANGLE_NAMESPACE(QNSWindowHelper); +// @compatibility_alias doesn't work with protocols +#define QNSWindowProtocol QT_MANGLE_NAMESPACE(QNSWindowProtocol) + @protocol QNSWindowProtocol @property (nonatomic, readonly) QT_MANGLE_NAMESPACE(QNSWindowHelper) *helper; -- cgit v1.2.3 From 841542225bf5d3f1c4b3fd4c24adf4201f3a131f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 9 Jan 2018 18:19:26 +0100 Subject: macOS: Simplify mangling of QNSPanelDelegate protocol Change-Id: If29bc36ecab2feb4ce3372153d0d1566cdffc719 Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm | 2 +- src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 2 +- src/plugins/platforms/cocoa/qcocoahelpers.h | 7 +++++-- src/plugins/platforms/cocoa/qcocoahelpers.mm | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 5d331c0e96..aa6124507d 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -49,7 +49,7 @@ QT_USE_NAMESPACE -@interface QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) : NSObject +@interface QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) : NSObject { @public NSColorPanel *mColorPanel; diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index dbd7e90dba..9a96895d07 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -75,7 +75,7 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) @class QT_MANGLE_NAMESPACE(QNSFontPanelDelegate); -@interface QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) : NSObject +@interface QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) : NSObject { @public NSFontPanel *mFontPanel; diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 4478895538..0cf9cc0aff 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -161,7 +161,10 @@ T qt_mac_resolveOption(const T &fallback, QWindow *window, const QByteArray &pro QT_END_NAMESPACE -@protocol QT_MANGLE_NAMESPACE(QNSPanelDelegate) +// @compatibility_alias doesn't work with protocols +#define QNSPanelDelegate QT_MANGLE_NAMESPACE(QNSPanelDelegate) + +@protocol QNSPanelDelegate @required - (void)onOkClicked; - (void)onCancelClicked; @@ -179,7 +182,7 @@ QT_END_NAMESPACE @property (nonatomic, readonly) NSView *panelContents; // ARC: unretained, make it weak @property (nonatomic, assign) NSEdgeInsets panelContentsMargins; -- (instancetype)initWithPanelDelegate:(id)panelDelegate; +- (instancetype)initWithPanelDelegate:(id)panelDelegate; - (void)dealloc; - (NSButton *)createButtonWithTitle:(const char *)title; diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 5d0f13c5a9..c3efe158c7 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -308,7 +308,7 @@ QT_END_NAMESPACE @synthesize panelContents = _panelContents; @synthesize panelContentsMargins = _panelContentsMargins; -- (instancetype)initWithPanelDelegate:(id)panelDelegate +- (instancetype)initWithPanelDelegate:(id)panelDelegate { if ((self = [super initWithFrame:NSZeroRect])) { // create OK and Cancel buttons and add these as subviews -- cgit v1.2.3 From 0c5953fd4edbb8e6495aaf288186dbd6737fb8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 9 Jan 2018 18:26:18 +0100 Subject: macOS: Namespace FullScreenProperty category on NSWindow Change-Id: I48e1bf91ebcfe10bd8b6a2df510c8b6a3e19e1d9 Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoawindow.mm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5cd4beb4f0..aeeef55598 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -89,6 +89,11 @@ static void qt_closePopups() } } + +// @compatibility_alias doesn't work with categories or their methods +#define FullScreenProperty QT_MANGLE_NAMESPACE(FullScreenProperty) +#define qt_fullScreen QT_MANGLE_NAMESPACE(qt_fullScreen) + @interface NSWindow (FullScreenProperty) @property(readonly) BOOL qt_fullScreen; @end -- cgit v1.2.3