From ba871065e0f40e9197fa4ee0ffe76530bb6fca11 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Thu, 1 Feb 2018 10:32:07 -0800 Subject: Clean up our Objective-C usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move ivars into @implementation - Use instancetype where applicable - Use dot notation for property access - Use subscript operator for dictionaries and arrays - Format selectors consistently - Use proper style for init methods - Use generics instead of void pointers where possible - Use "range for" loops instead of indexing - Replace or replace IBAction/IBOutlet with void Change-Id: I1667812a51d4dfe44ae80fe337cb1f4bc9699d92 Reviewed-by: Jake Petroules Reviewed-by: Tor Arne Vestbø --- src/corelib/io/qfilesystemwatcher_fsevents.mm | 2 +- src/corelib/kernel/qcore_mac_objc.mm | 15 ++-- src/corelib/kernel/qeventdispatcher_cf.mm | 30 ++++---- src/platformsupport/clipboard/qmacmime.mm | 12 +-- .../fontdatabases/mac/qcoretextfontdatabase.mm | 46 ++++-------- src/plugins/bearer/corewlan/qcorewlanengine.mm | 38 +++++----- src/plugins/platforms/cocoa/qcocoaaccessibility.h | 5 +- src/plugins/platforms/cocoa/qcocoaaccessibility.mm | 6 +- .../platforms/cocoa/qcocoaaccessibilityelement.h | 9 +-- .../platforms/cocoa/qcocoaaccessibilityelement.mm | 84 ++++++++++----------- src/plugins/platforms/cocoa/qcocoaapplication.h | 3 +- .../platforms/cocoa/qcocoaapplicationdelegate.h | 16 ++-- .../platforms/cocoa/qcocoaapplicationdelegate.mm | 18 +++-- .../platforms/cocoa/qcocoacolordialoghelper.mm | 21 +++--- .../platforms/cocoa/qcocoafiledialoghelper.mm | 48 ++++++------ .../platforms/cocoa/qcocoafontdialoghelper.mm | 48 ++++++------ src/plugins/platforms/cocoa/qcocoahelpers.h | 15 +--- src/plugins/platforms/cocoa/qcocoahelpers.mm | 23 +++--- src/plugins/platforms/cocoa/qcocoaintegration.mm | 6 +- src/plugins/platforms/cocoa/qcocoamenu.mm | 4 +- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 7 +- src/plugins/platforms/cocoa/qcocoamenuloader.h | 27 ++----- src/plugins/platforms/cocoa/qcocoamenuloader.mm | 21 +++++- src/plugins/platforms/cocoa/qcocoascreen.mm | 2 +- .../platforms/cocoa/qcocoasystemtrayicon.mm | 78 ++++++++++---------- src/plugins/platforms/cocoa/qcocoatheme.mm | 20 +++-- src/plugins/platforms/cocoa/qnsview.h | 38 +--------- src/plugins/platforms/cocoa/qnsview.mm | 61 ++++++++++++---- .../platforms/cocoa/qnsviewaccessibility.mm | 10 +-- src/plugins/platforms/cocoa/qnswindow.mm | 7 +- src/plugins/platforms/cocoa/qnswindowdelegate.h | 14 ++-- src/plugins/platforms/cocoa/qnswindowdelegate.mm | 11 ++- .../qiosimagepickercontroller.h | 6 +- .../qiosimagepickercontroller.mm | 14 ++-- src/plugins/platforms/ios/qiosclipboard.mm | 24 +++--- src/plugins/platforms/ios/qioseventdispatcher.mm | 2 +- src/plugins/platforms/ios/qiosinputcontext.mm | 15 ++-- src/plugins/platforms/ios/qiosintegration.mm | 2 +- src/plugins/platforms/ios/qiosmenu.mm | 32 ++++---- .../platforms/ios/qiosoptionalplugininterface.h | 4 +- src/plugins/platforms/ios/qiosscreen.mm | 14 ++-- src/plugins/platforms/ios/qiostextinputoverlay.mm | 85 +++++++++------------- src/plugins/platforms/ios/qiostextresponder.h | 10 +-- src/plugins/platforms/ios/qiostextresponder.mm | 42 ++++++----- src/plugins/platforms/ios/qiosviewcontroller.h | 2 +- src/plugins/platforms/ios/qiosviewcontroller.mm | 36 +++++---- src/plugins/platforms/ios/qioswindow.mm | 6 +- .../platforms/ios/quiaccessibilityelement.h | 7 +- .../platforms/ios/quiaccessibilityelement.mm | 13 ++-- src/plugins/platforms/ios/quiview.h | 15 +--- src/plugins/platforms/ios/quiview.mm | 74 ++++++++++--------- src/plugins/platforms/ios/quiview_accessibility.mm | 7 +- src/plugins/styles/mac/qmacstyle_mac.mm | 18 +---- src/printsupport/dialogs/qpagesetupdialog_mac.mm | 11 +-- src/printsupport/dialogs/qprintdialog_mac.mm | 19 +++-- src/testlib/qxctestlogger.mm | 10 +-- src/testlib/qxctestlogger_p.h | 2 +- .../tst_qaccessibilitymac_helpers.mm | 4 +- .../qmaccocoaviewcontainer/TestMouseMovedNSView.h | 7 +- .../qmaccocoaviewcontainer/TestMouseMovedNSView.m | 25 ++++--- tests/manual/cocoa/qmaccocoaviewcontainer/main.mm | 2 +- tests/manual/cocoa/qt_on_cocoa/main.mm | 32 ++++---- 62 files changed, 598 insertions(+), 687 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index 792ea387ac..844aa9daa7 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -499,7 +499,7 @@ bool QFseventsFileSystemWatcherEngine::startStream() DEBUG() << "Starting stream with paths" << watchingState.watchedPaths.keys(); - NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchingState.watchedPaths.size()]; + NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchingState.watchedPaths.size()]; for (PathRefCounts::const_iterator i = watchingState.watchedPaths.begin(), ei = watchingState.watchedPaths.end(); i != ei; ++i) [pathsToWatch addObject:i.key().toNSString()]; diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 24d73fa8be..b91b5e76be 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -87,19 +87,20 @@ QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TY QT_END_NAMESPACE QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) : NSObject -{ +@end + +@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) { NSAutoreleasePool **m_pool; } --(id)initWithPool:(NSAutoreleasePool**)pool; -@end -@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) --(id)initWithPool:(NSAutoreleasePool**)pool + +- (instancetype)initWithPool:(NSAutoreleasePool **)pool { - if (self = [super init]) + if ((self = [self init])) m_pool = pool; return self; } --(void)dealloc + +- (void)dealloc { if (*m_pool) { // The pool is still valid, which means we're not being drained from diff --git a/src/corelib/kernel/qeventdispatcher_cf.mm b/src/corelib/kernel/qeventdispatcher_cf.mm index 8499b3fd57..35b2390c6d 100644 --- a/src/corelib/kernel/qeventdispatcher_cf.mm +++ b/src/corelib/kernel/qeventdispatcher_cf.mm @@ -58,18 +58,18 @@ QT_USE_NAMESPACE -@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject { - QStack m_runLoopModes; -} +@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject @end QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker); -@implementation RunLoopModeTracker +@implementation RunLoopModeTracker { + QStack m_runLoopModes; +} -- (id) init +- (instancetype)init { - if (self = [super init]) { + if ((self = [super init])) { m_runLoopModes.push(kCFRunLoopDefaultMode); [[NSNotificationCenter defaultCenter] @@ -77,21 +77,21 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker); selector:@selector(receivedNotification:) name:nil #ifdef Q_OS_OSX - object:[NSApplication sharedApplication]]; + object:NSApplication.sharedApplication]; #elif defined(Q_OS_WATCHOS) - object:[WKExtension sharedExtension]]; + object:WKExtension.sharedExtension]; #else // Use performSelector so this can work in an App Extension - object:[[UIApplication class] performSelector:@selector(sharedApplication)]]; + object:[UIApplication.class performSelector:@selector(sharedApplication)]]; #endif } return self; } -- (void) dealloc +- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; + [NSNotificationCenter.defaultCenter removeObserver:self]; [super dealloc]; } @@ -100,13 +100,13 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) { for (NSString *key in dictionary) { if (CFStringHasSuffix((CFStringRef)key, CFSTR("RunLoopMode"))) - return (CFStringRef)[dictionary objectForKey: key]; + return (CFStringRef)dictionary[key]; } return nil; } -- (void) receivedNotification:(NSNotification *) notification +- (void)receivedNotification:(NSNotification *)notification { if (CFStringHasSuffix((CFStringRef)notification.name, CFSTR("RunLoopModePushNotification"))) { if (CFStringRef mode = runLoopMode(notification.userInfo)) @@ -116,7 +116,7 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) } else if (CFStringHasSuffix((CFStringRef)notification.name, CFSTR("RunLoopModePopNotification"))) { CFStringRef mode = runLoopMode(notification.userInfo); - if (CFStringCompare(mode, [self currentMode], 0) == kCFCompareEqualTo) + if (CFStringCompare(mode, self.currentMode, 0) == kCFCompareEqualTo) m_runLoopModes.pop(); else qCWarning(lcEventDispatcher) << "Tried to pop run loop mode" @@ -126,7 +126,7 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) } } -- (CFStringRef) currentMode +- (CFStringRef)currentMode { return m_runLoopModes.top(); } diff --git a/src/platformsupport/clipboard/qmacmime.mm b/src/platformsupport/clipboard/qmacmime.mm index 09901ba0a5..caa2ccc6e5 100644 --- a/src/platformsupport/clipboard/qmacmime.mm +++ b/src/platformsupport/clipboard/qmacmime.mm @@ -536,13 +536,13 @@ QVariant QMacPasteboardMimeRtfText::convertToMime(const QString &mimeType, QList // Read RTF into to NSAttributedString, then convert the string to HTML NSAttributedString *string = [[NSAttributedString alloc] initWithData:data.at(0).toNSData() - options:[NSDictionary dictionaryWithObject:NSRTFTextDocumentType forKey:NSDocumentTypeDocumentAttribute] + options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} documentAttributes:nil error:nil]; NSError *error; NSRange range = NSMakeRange(0, [string length]); - NSDictionary *dict = [NSDictionary dictionaryWithObject:NSHTMLTextDocumentType forKey:NSDocumentTypeDocumentAttribute]; + NSDictionary *dict = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSData *htmlData = [string dataFromRange:range documentAttributes:dict error:&error]; return QByteArray::fromNSData(htmlData); } @@ -554,13 +554,13 @@ QList QMacPasteboardMimeRtfText::convertFromMime(const QString &mime return ret; NSAttributedString *string = [[NSAttributedString alloc] initWithData:data.toByteArray().toNSData() - options:[NSDictionary dictionaryWithObject:NSHTMLTextDocumentType forKey:NSDocumentTypeDocumentAttribute] + options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil]; NSError *error; NSRange range = NSMakeRange(0, [string length]); - NSDictionary *dict = [NSDictionary dictionaryWithObject:NSRTFTextDocumentType forKey:NSDocumentTypeDocumentAttribute]; + NSDictionary *dict = @{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}; NSData *rtfData = [string dataFromRange:range documentAttributes:dict error:&error]; ret << QByteArray::fromNSData(rtfData); return ret; @@ -853,8 +853,8 @@ QList QMacPasteboardMimeTiff::convertFromMime(const QString &mime, Q QImage img = qvariant_cast(variant); NSDictionary *props = @{ - static_cast(kCGImagePropertyPixelWidth) : [NSNumber numberWithInt:img.width()], - static_cast(kCGImagePropertyPixelHeight) : [NSNumber numberWithInt:img.height()] + static_cast(kCGImagePropertyPixelWidth): @(img.width()), + static_cast(kCGImagePropertyPixelHeight): @(img.height()) }; CGImageDestinationAddImage(imageDestination, qt_mac_toCGImage(img), static_cast(props)); diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 5eb5cd8a30..85d213ad46 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -101,14 +101,14 @@ enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) } #ifdef Q_OS_OSX static NSInteger languageMapSort(id obj1, id obj2, void *context) { - NSArray *map1 = (NSArray *) obj1; - NSArray *map2 = (NSArray *) obj2; - NSArray *languages = (NSArray *) context; + NSArray *map1 = reinterpret_cast *>(obj1); + NSArray *map2 = reinterpret_cast *>(obj2); + NSArray *languages = reinterpret_cast *>(context); - NSString *lang1 = [map1 objectAtIndex: 0]; - NSString *lang2 = [map2 objectAtIndex: 0]; + NSString *lang1 = [map1 objectAtIndex:0]; + NSString *lang2 = [map2 objectAtIndex:0]; - return [languages indexOfObject: lang1] - [languages indexOfObject: lang2]; + return [languages indexOfObject:lang1] - [languages indexOfObject:lang2]; } #endif @@ -184,23 +184,9 @@ QCoreTextFontDatabase::~QCoreTextFontDatabase() CFRelease(ref); } -static CFArrayRef availableFamilyNames() -{ -#if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(1060, 100000, 100000, 30000) - if (&CTFontManagerCopyAvailableFontFamilyNames) - return CTFontManagerCopyAvailableFontFamilyNames(); -#endif -#if defined(QT_PLATFORM_UIKIT) - CFMutableArrayRef familyNames = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, (CFArrayRef)[UIFont familyNames]); - CFArrayAppendValue(familyNames, CFSTR(".PhoneFallback")); - return familyNames; -#endif - Q_UNREACHABLE(); -} - void QCoreTextFontDatabase::populateFontDatabase() { - QCFType familyNames = availableFamilyNames(); + QCFType familyNames = CTFontManagerCopyAvailableFontFamilyNames(); for (NSString *familyName in familyNames.as()) QPlatformFontDatabase::registerFontFamily(QString::fromNSString(familyName)); @@ -220,7 +206,7 @@ bool QCoreTextFontDatabase::populateFamilyAliases() if (m_hasPopulatedAliases) return false; - QCFType familyNames = availableFamilyNames(); + QCFType familyNames = CTFontManagerCopyAvailableFontFamilyNames(); for (NSString *familyName in familyNames.as()) { NSFontManager *fontManager = [NSFontManager sharedFontManager]; NSString *localizedFamilyName = [fontManager localizedNameForFamily:familyName face:nil]; @@ -570,21 +556,21 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo if (!didPopulateStyleFallbacks) { #if defined(Q_OS_MACX) NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; + NSArray *languages = [defaults stringArrayForKey:@"AppleLanguages"]; - NSDictionary *fallbackDict = [NSDictionary dictionaryWithContentsOfFile: @"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreText.framework/Resources/DefaultFontFallbacks.plist"]; + NSDictionary *fallbackDict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreText.framework/Resources/DefaultFontFallbacks.plist"]; for (NSString *style in [fallbackDict allKeys]) { - NSArray *list = [fallbackDict valueForKey: style]; + NSArray *list = [fallbackDict valueForKey:style]; QFont::StyleHint fallbackStyleHint = styleHintFromNSString(style); QStringList fallbackList; for (id item in list) { // sort the array based on system language preferences - if ([item isKindOfClass: [NSArray class]]) { - NSArray *langs = [(NSArray *) item sortedArrayUsingFunction: languageMapSort - context: languages]; - for (NSArray *map in langs) - fallbackList.append(familyNameFromPostScriptName([map objectAtIndex: 1])); + if ([item isKindOfClass:[NSArray class]]) { + NSArray *langs = [reinterpret_cast(item) + sortedArrayUsingFunction:languageMapSort context:languages]; + for (NSArray *map in langs) + fallbackList.append(familyNameFromPostScriptName([map objectAtIndex:1])); } else if ([item isKindOfClass: [NSString class]]) fallbackList.append(familyNameFromPostScriptName(item)); diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 341d3bccf2..c3dd49ff3e 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -62,33 +62,29 @@ extern "C" { // Otherwise it won't find CWKeychain* symbols at link time #include @interface QT_MANGLE_NAMESPACE(QNSListener) : NSObject -{ - NSNotificationCenter *notificationCenter; - CWWiFiClient *client; - QCoreWlanEngine *engine; - NSLock *locker; -} -- (void)powerStateDidChangeForWiFiInterfaceWithName:(NSString *)interfaceName; -- (void)remove; -- (void)setEngine:(QCoreWlanEngine *)coreEngine; -- (QCoreWlanEngine *)engine; -- (void)dealloc; @property (assign) QCoreWlanEngine* engine; @end -@implementation QT_MANGLE_NAMESPACE(QNSListener) +@implementation QT_MANGLE_NAMESPACE(QNSListener) { + NSNotificationCenter *notificationCenter; + CWWiFiClient *client; + QCoreWlanEngine *engine; + NSLock *locker; +} -- (id) init +- (instancetype)init { - [locker lock]; - QMacAutoReleasePool pool; - notificationCenter = [NSNotificationCenter defaultCenter]; - client = [CWWiFiClient sharedWiFiClient]; - client.delegate = self; - [client startMonitoringEventWithType:CWEventTypePowerDidChange error:nil]; - [locker unlock]; + if ((self = [super init])) { + [locker lock]; + QMacAutoReleasePool pool; + notificationCenter = [NSNotificationCenter defaultCenter]; + client = [CWWiFiClient sharedWiFiClient]; + client.delegate = self; + [client startMonitoringEventWithType:CWEventTypePowerDidChange error:nil]; + [locker unlock]; + } return self; } @@ -300,7 +296,7 @@ void QScanThread::getUserConfigurations() if(airportPlist != nil) { NSDictionary *prefNetDict = [airportPlist objectForKey:@"PreferredNetworks"]; - NSArray *thisSsidarray = [prefNetDict valueForKey:@"SSID_STR"]; + NSArray *thisSsidarray = [prefNetDict valueForKey:@"SSID_STR"]; for (NSString *ssidkey in thisSsidarray) { QString thisSsid = QString::fromNSString(ssidkey); if(!userProfiles.contains(thisSsid)) { diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.h b/src/plugins/platforms/cocoa/qcocoaaccessibility.h index e456364555..457c158ddc 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.h @@ -46,6 +46,8 @@ #ifndef QT_NO_ACCESSIBILITY +@class QT_MANGLE_NAMESPACE(QMacAccessibilityElement); + QT_BEGIN_NAMESPACE class QCocoaAccessibility : public QPlatformAccessibility @@ -82,9 +84,8 @@ namespace QCocoaAccessible { NSString *macRole(QAccessibleInterface *interface); NSString *macSubrole(QAccessibleInterface *interface); bool shouldBeIgnored(QAccessibleInterface *interface); -NSArray *unignoredChildren(QAccessibleInterface *interface); +NSArray *unignoredChildren(QAccessibleInterface *interface); NSString *getTranslatedAction(const QString &qtAction); -NSMutableArray *createTranslatedActionsList(const QStringList &qtActions); QString translateAction(NSString *nsAction, QAccessibleInterface *interface); bool hasValueAttribute(QAccessibleInterface *interface); id getValueAttribute(QAccessibleInterface *interface); diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm index 8b6dcb35a6..0a773ced29 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm @@ -257,12 +257,12 @@ bool shouldBeIgnored(QAccessibleInterface *interface) return false; } -NSArray *unignoredChildren(QAccessibleInterface *interface) +NSArray *unignoredChildren(QAccessibleInterface *interface) { int numKids = interface->childCount(); // qDebug() << "Children for: " << axid << iface << " are: " << numKids; - NSMutableArray *kids = [NSMutableArray arrayWithCapacity:numKids]; + NSMutableArray *kids = [NSMutableArray arrayWithCapacity:numKids]; for (int i = 0; i < numKids; ++i) { QAccessibleInterface *child = interface->child(i); if (!child || !child->isValid() || child->state().invalid || child->state().invisible) @@ -387,7 +387,7 @@ id getValueAttribute(QAccessibleInterface *interface) } if (interface->state().checkable) { - return [NSNumber numberWithInt: (interface->state().checked ? 1 : 0)]; + return interface->state().checked ? @(1) : @(0); } return nil; diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h index 07f3f3a99e..914aaa2b1b 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h @@ -52,13 +52,10 @@ @class QT_MANGLE_NAMESPACE(QMacAccessibilityElement); -@interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : NSObject { - NSString *role; - QAccessible::Id axid; -} +@interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : NSObject -- (id)initWithId:(QAccessible::Id)anId; -+ (QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *)elementWithId:(QAccessible::Id)anId; +- (instancetype)initWithId:(QAccessible::Id)anId; ++ (instancetype)elementWithId:(QAccessible::Id)anId; @end diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index df2336d08b..ad251a6a44 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -99,9 +99,12 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of *end = curEnd; } -@implementation QMacAccessibilityElement +@implementation QMacAccessibilityElement { + NSString *role; + QAccessible::Id axid; +} -- (id)initWithId:(QAccessible::Id)anId +- (instancetype)initWithId:(QAccessible::Id)anId { Q_ASSERT((int)anId < 0); self = [super init]; @@ -115,7 +118,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of return self; } -+ (id)elementWithId:(QAccessible::Id)anId ++ (instancetype)elementWithId:(QAccessible::Id)anId { Q_ASSERT(anId); if (!anId) @@ -168,22 +171,15 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of { QStringRef textBefore = QStringRef(&text, 0, index); int newlines = textBefore.count(QLatin1Char('\n')); - return [NSNumber numberWithInt: newlines]; + return @(newlines); } - (BOOL) accessibilityNotifiesWhenDestroyed { return YES; } -- (NSArray *)accessibilityAttributeNames { - static NSArray *defaultAttributes = nil; - - QAccessibleInterface *iface = QAccessible::accessibleInterface(axid); - if (!iface || !iface->isValid()) - return defaultAttributes; - - if (defaultAttributes == nil) { - defaultAttributes = [[NSArray alloc] initWithObjects: +- (NSArray *)accessibilityAttributeNames { + static NSArray *defaultAttributes = [@[ NSAccessibilityRoleAttribute, NSAccessibilityRoleDescriptionAttribute, NSAccessibilitySubroleAttribute, @@ -196,35 +192,36 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of NSAccessibilitySizeAttribute, NSAccessibilityTitleAttribute, NSAccessibilityDescriptionAttribute, - NSAccessibilityEnabledAttribute, - nil]; - } + NSAccessibilityEnabledAttribute + ] retain]; + + QAccessibleInterface *iface = QAccessible::accessibleInterface(axid); + if (!iface || !iface->isValid()) + return defaultAttributes; - NSMutableArray *attributes = [[NSMutableArray alloc] initWithCapacity : [defaultAttributes count]]; - [attributes addObjectsFromArray : defaultAttributes]; + NSMutableArray *attributes = [[NSMutableArray alloc] initWithCapacity:defaultAttributes.count]; + [attributes addObjectsFromArray:defaultAttributes]; if (QCocoaAccessible::hasValueAttribute(iface)) { - [attributes addObject : NSAccessibilityValueAttribute]; + [attributes addObject:NSAccessibilityValueAttribute]; } if (iface->textInterface()) { - [attributes addObjectsFromArray: [[NSArray alloc] initWithObjects: + [attributes addObjectsFromArray:@[ NSAccessibilityNumberOfCharactersAttribute, NSAccessibilitySelectedTextAttribute, NSAccessibilitySelectedTextRangeAttribute, NSAccessibilityVisibleCharacterRangeAttribute, - NSAccessibilityInsertionPointLineNumberAttribute, - nil + NSAccessibilityInsertionPointLineNumberAttribute ]]; // TODO: multi-selection: NSAccessibilitySelectedTextRangesAttribute, } if (iface->valueInterface()) { - [attributes addObjectsFromArray: [[NSArray alloc] initWithObjects: + [attributes addObjectsFromArray:@[ NSAccessibilityMinValueAttribute, - NSAccessibilityMaxValueAttribute, - nil + NSAccessibilityMaxValueAttribute ]]; } @@ -261,13 +258,13 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of - (id) minValueAttribute:(QAccessibleInterface*)iface { if (QAccessibleValueInterface *val = iface->valueInterface()) - return [NSNumber numberWithDouble: val->minimumValue().toDouble()]; + return @(val->minimumValue().toDouble()); return nil; } - (id) maxValueAttribute:(QAccessibleInterface*)iface { if (QAccessibleValueInterface *val = iface->valueInterface()) - return [NSNumber numberWithDouble: val->maximumValue().toDouble()]; + return @(val->maximumValue().toDouble()); return nil; } @@ -289,7 +286,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of } else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) { // Just check if the app thinks we're focused. id focusedElement = [NSApp accessibilityAttributeValue:NSAccessibilityFocusedUIElementAttribute]; - return [NSNumber numberWithBool:[focusedElement isEqual:self]]; + return @([focusedElement isEqual:self]); } else if ([attribute isEqualToString:NSAccessibilityParentAttribute]) { return NSAccessibilityUnignoredAncestor([self parentElement]); } else if ([attribute isEqualToString:NSAccessibilityWindowAttribute]) { @@ -312,7 +309,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of } else if ([attribute isEqualToString:NSAccessibilityDescriptionAttribute]) { return iface->text(QAccessible::Description).toNSString(); } else if ([attribute isEqualToString:NSAccessibilityEnabledAttribute]) { - return [NSNumber numberWithBool:!iface->state().disabled]; + return @(!iface->state().disabled); } else if ([attribute isEqualToString:NSAccessibilityValueAttribute]) { // VoiceOver asks for the value attribute for all elements. Return nil // if we don't want the element to have a value attribute. @@ -323,7 +320,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of } else if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute]) { if (QAccessibleTextInterface *text = iface->textInterface()) - return [NSNumber numberWithInt: text->characterCount()]; + return @(text->characterCount()); return nil; } else if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) { if (QAccessibleTextInterface *text = iface->textInterface()) { @@ -357,7 +354,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of int position = text->cursorPosition(); convertLineOffset(text, &line, &position); } - return [NSNumber numberWithInt: line]; + return @(line); } return nil; } else if ([attribute isEqualToString:NSAccessibilityMinValueAttribute]) { @@ -378,18 +375,17 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of } if (iface->textInterface()) { - return [[NSArray alloc] initWithObjects: - NSAccessibilityStringForRangeParameterizedAttribute, - NSAccessibilityLineForIndexParameterizedAttribute, - NSAccessibilityRangeForLineParameterizedAttribute, - NSAccessibilityRangeForPositionParameterizedAttribute, -// NSAccessibilityRangeForIndexParameterizedAttribute, - NSAccessibilityBoundsForRangeParameterizedAttribute, -// NSAccessibilityRTFForRangeParameterizedAttribute, - NSAccessibilityStyleRangeForIndexParameterizedAttribute, - NSAccessibilityAttributedStringForRangeParameterizedAttribute, - nil - ]; + return @[ + NSAccessibilityStringForRangeParameterizedAttribute, + NSAccessibilityLineForIndexParameterizedAttribute, + NSAccessibilityRangeForLineParameterizedAttribute, + NSAccessibilityRangeForPositionParameterizedAttribute, +// NSAccessibilityRangeForIndexParameterizedAttribute, + NSAccessibilityBoundsForRangeParameterizedAttribute, +// NSAccessibilityRTFForRangeParameterizedAttribute, + NSAccessibilityStyleRangeForIndexParameterizedAttribute, + NSAccessibilityAttributedStringForRangeParameterizedAttribute + ]; } return nil; @@ -416,7 +412,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of return nil; int line = -1; convertLineOffset(iface->textInterface(), &line, &index); - return [NSNumber numberWithInt:line]; + return @(line); } if ([attribute isEqualToString: NSAccessibilityRangeForLineParameterizedAttribute]) { int line = [parameter intValue]; diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.h b/src/plugins/platforms/cocoa/qcocoaapplication.h index 66a92686bc..15530d8281 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.h +++ b/src/plugins/platforms/cocoa/qcocoaapplication.h @@ -89,8 +89,7 @@ #import -@interface QT_MANGLE_NAMESPACE(QNSApplication) : NSApplication { -} +@interface QT_MANGLE_NAMESPACE(QNSApplication) : NSApplication @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSApplication); diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h index 59c71017e3..3073cb6b44 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h @@ -92,18 +92,12 @@ @class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); -@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject { - bool startedQuit; - NSMenu *dockMenu; - NSObject *reflectionDelegate; - bool inLaunch; -} -+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate; +@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject ++ (instancetype)sharedDelegate; - (void)setDockMenu:(NSMenu *)newMenu; -- (void)setReflectionDelegate:(NSObject *)oldDelegate; -- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; -- (void) removeAppleEventHandlers; -- (bool) inLaunch; +- (void)setReflectionDelegate:(NSObject *)oldDelegate; +- (void)removeAppleEventHandlers; +- (bool)inLaunch; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate); diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index a94e0dc517..53407d8b62 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -73,7 +73,6 @@ #import "qcocoaapplicationdelegate.h" -#import "qnswindowdelegate.h" #import "qcocoamenuloader.h" #include "qcocoaintegration.h" #include @@ -86,7 +85,12 @@ QT_USE_NAMESPACE -@implementation QCocoaApplicationDelegate +@implementation QCocoaApplicationDelegate { + bool startedQuit; + NSMenu *dockMenu; + NSObject *reflectionDelegate; + bool inLaunch; +} + (instancetype)sharedDelegate { @@ -102,7 +106,7 @@ QT_USE_NAMESPACE return shared; } -- (id)init +- (instancetype)init { self = [super init]; if (self) { @@ -151,7 +155,7 @@ QT_USE_NAMESPACE return [[dockMenu retain] autorelease]; } -- (BOOL) canQuit +- (BOOL)canQuit { [[NSApp mainMenu] cancelTracking]; @@ -219,7 +223,7 @@ QT_USE_NAMESPACE return NSTerminateCancel; } -- (void) applicationWillFinishLaunching:(NSNotification *)notification +- (void)applicationWillFinishLaunching:(NSNotification *)notification { Q_UNUSED(notification); @@ -249,14 +253,14 @@ QT_USE_NAMESPACE } // called by QCocoaIntegration's destructor before resetting the application delegate to nil -- (void) removeAppleEventHandlers +- (void)removeAppleEventHandlers { NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; } -- (bool) inLaunch +- (bool)inLaunch { return inLaunch; } diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index aa6124507d..0e127902ae 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -50,7 +50,14 @@ QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) : NSObject -{ +- (void)restoreOriginalContentView; +- (void)updateQtColor; +- (void)finishOffWithCode:(NSInteger)code; +@end + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); + +@implementation QNSColorPanelDelegate { @public NSColorPanel *mColorPanel; QCocoaColorDialogHelper *mHelper; @@ -61,17 +68,9 @@ QT_USE_NAMESPACE BOOL mDialogIsExecuting; BOOL mResultSet; BOOL mClosingDueToKnownButton; -}; -- (void)restoreOriginalContentView; -- (void)updateQtColor; -- (void)finishOffWithCode:(NSInteger)code; -@end - -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); - -@implementation QNSColorPanelDelegate +} -- (id)init +- (instancetype)init { self = [super init]; mColorPanel = [NSColorPanel sharedColorPanel]; diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 94f2125bad..55c4e51242 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -81,23 +81,6 @@ typedef QSharedPointer SharedPointerFileDialogOptions; @interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) : NSObject -{ - @public - NSOpenPanel *mOpenPanel; - NSSavePanel *mSavePanel; - NSView *mAccessoryView; - NSPopUpButton *mPopUpButton; - NSTextField *mTextField; - QCocoaFileDialogHelper *mHelper; - NSString *mCurrentDir; - - int mReturnCode; - - SharedPointerFileDialogOptions mOptions; - QString *mCurrentSelection; - QStringList *mNameFilterDropDownList; - QStringList *mSelectedNameFilter; -} - (NSString *)strip:(const QString &)label; - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url; @@ -117,12 +100,27 @@ typedef QSharedPointer SharedPointerFileDialogOptions; QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate); -@implementation QNSOpenSavePanelDelegate +@implementation QNSOpenSavePanelDelegate { + @public + NSOpenPanel *mOpenPanel; + NSSavePanel *mSavePanel; + NSView *mAccessoryView; + NSPopUpButton *mPopUpButton; + NSTextField *mTextField; + QCocoaFileDialogHelper *mHelper; + NSString *mCurrentDir; + + int mReturnCode; + + SharedPointerFileDialogOptions mOptions; + QString *mCurrentSelection; + QStringList *mNameFilterDropDownList; + QStringList *mSelectedNameFilter; +} -- (id)initWithAcceptMode: - (const QString &)selectFile - options:(SharedPointerFileDialogOptions)options - helper:(QCocoaFileDialogHelper *)helper +- (instancetype)initWithAcceptMode:(const QString &)selectFile + options:(SharedPointerFileDialogOptions)options + helper:(QCocoaFileDialogHelper *)helper { self = [super init]; mOptions = options; @@ -406,9 +404,9 @@ static QString strippedText(QString s) { if (mOpenPanel) { QList result; - NSArray* array = [mOpenPanel URLs]; - for (NSUInteger i=0; i<[array count]; ++i) { - QString path = QString::fromNSString([[array objectAtIndex:i] path]).normalized(QString::NormalizationForm_C); + NSArray *array = [mOpenPanel URLs]; + for (NSURL *url in array) { + QString path = QString::fromNSString(url.path).normalized(QString::NormalizationForm_C); result << QUrl::fromLocalFile(path); } return result; diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 9a96895d07..3010aa0870 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -76,7 +76,15 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) @class QT_MANGLE_NAMESPACE(QNSFontPanelDelegate); @interface QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) : NSObject -{ +- (void)restoreOriginalContentView; +- (void)updateQtFont; +- (void)changeFont:(id)sender; +- (void)finishOffWithCode:(NSInteger)code; +@end + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); + +@implementation QNSFontPanelDelegate { @public NSFontPanel *mFontPanel; QCocoaFontDialogHelper *mHelper; @@ -86,33 +94,25 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) NSInteger mResultCode; BOOL mDialogIsExecuting; BOOL mResultSet; -}; -- (void)restoreOriginalContentView; -- (void)updateQtFont; -- (void)changeFont:(id)sender; -- (void)finishOffWithCode:(NSInteger)code; -@end - -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); - -@implementation QNSFontPanelDelegate +} -- (id)init +- (instancetype)init { - self = [super init]; - mFontPanel = [NSFontPanel sharedFontPanel]; - mHelper = 0; - mStolenContentView = 0; - mPanelButtons = 0; - mResultCode = NSModalResponseCancel; - mDialogIsExecuting = false; - mResultSet = false; + if ((self = [super init])) { + mFontPanel = [NSFontPanel sharedFontPanel]; + mHelper = 0; + mStolenContentView = 0; + mPanelButtons = 0; + mResultCode = NSModalResponseCancel; + mDialogIsExecuting = false; + mResultSet = false; - [mFontPanel setRestorable:NO]; - [mFontPanel setDelegate:self]; - [[NSFontManager sharedFontManager] setDelegate:self]; + [mFontPanel setRestorable:NO]; + [mFontPanel setDelegate:self]; + [[NSFontManager sharedFontManager] setDelegate:self]; - [mFontPanel retain]; + [mFontPanel retain]; + } return self; } diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 84632c1487..7fd8715277 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -70,11 +70,8 @@ class QPixmap; class QString; // Conversion functions -QStringList qt_mac_NSArrayToQStringList(void *nsarray); -void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list); - -inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qstrlist) -{ return reinterpret_cast(qt_mac_QStringListToNSMutableArrayVoid(qstrlist)); } +QStringList qt_mac_NSArrayToQStringList(NSArray *nsarray); +NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &list); NSDragOperation qt_mac_mapDropAction(Qt::DropAction action); NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions); @@ -170,12 +167,7 @@ QT_END_NAMESPACE - (void)onCancelClicked; @end -@interface QT_MANGLE_NAMESPACE(QNSPanelContentsWrapper) : NSView { - NSButton *_okButton; - NSButton *_cancelButton; - NSView *_panelContents; - NSEdgeInsets _panelContentsMargins; -} +@interface QT_MANGLE_NAMESPACE(QNSPanelContentsWrapper) : NSView @property (nonatomic, readonly) NSButton *okButton; @property (nonatomic, readonly) NSButton *cancelButton; @@ -187,6 +179,7 @@ QT_END_NAMESPACE - (NSButton *)createButtonWithTitle:(const char *)title; - (void)layout; + @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSPanelContentsWrapper); diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 3b45793944..632053b0c4 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -65,21 +65,19 @@ Q_LOGGING_CATEGORY(lcQpaCocoaMouse, "qt.qpa.cocoa.mouse"); // Conversion Functions // -QStringList qt_mac_NSArrayToQStringList(void *nsarray) +QStringList qt_mac_NSArrayToQStringList(NSArray *array) { QStringList result; - NSArray *array = static_cast(nsarray); - for (NSUInteger i=0; i<[array count]; ++i) - result << QString::fromNSString([array objectAtIndex:i]); + for (NSString *string in array) + result << QString::fromNSString(string); return result; } -void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list) +NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &list) { - NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()]; - for (int i=0; i *result = [NSMutableArray arrayWithCapacity:list.size()]; + for (const QString &string : list) + [result addObject:string.toNSString()]; return result; } @@ -289,7 +287,12 @@ QT_END_NAMESPACE the target-action for the OK/Cancel buttons and making sure the layout is consistent. */ -@implementation QNSPanelContentsWrapper +@implementation QNSPanelContentsWrapper { + NSButton *_okButton; + NSButton *_cancelButton; + NSView *_panelContents; + NSEdgeInsets _panelContentsMargins; +} @synthesize okButton = _okButton; @synthesize cancelButton = _cancelButton; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 55b3805df3..60541c32d9 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -196,7 +196,7 @@ QCocoaIntegration::~QCocoaIntegration() QCocoaApplicationDelegate *delegate = [QCocoaApplicationDelegate sharedDelegate]; [delegate removeAppleEventHandlers]; // reset the application delegate - [[NSApplication sharedApplication] setDelegate: 0]; + [[NSApplication sharedApplication] setDelegate:nil]; } #ifndef QT_NO_CLIPBOARD @@ -232,8 +232,8 @@ Q_LOGGING_CATEGORY(lcCocoaScreen, "qt.qpa.cocoa.screens"); */ void QCocoaIntegration::updateScreens() { - NSArray *scrs = [NSScreen screens]; - NSMutableArray *screens = [NSMutableArray arrayWithArray:scrs]; + NSArray *scrs = [NSScreen screens]; + NSMutableArray *screens = [NSMutableArray arrayWithArray:scrs]; if ([screens count] == 0) if ([NSScreen mainScreen]) [screens addObject:[NSScreen mainScreen]]; diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index b3c2d5ae90..148dad5d6c 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -279,9 +279,7 @@ void QCocoaMenu::syncSeparatorsCollapsible(bool enable) bool previousIsSeparator = true; // setting to true kills all the separators placed at the top. NSMenuItem *previousItem = nil; - NSArray *itemArray = [m_nativeMenu itemArray]; - for (unsigned int i = 0; i < [itemArray count]; ++i) { - NSMenuItem *item = reinterpret_cast([itemArray objectAtIndex:i]); + for (NSMenuItem *item in [m_nativeMenu itemArray]) { if ([item isSeparatorItem]) { QCocoaMenuItem *cocoaItem = reinterpret_cast([item tag]); if (cocoaItem) diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index f8f9648822..59e0150168 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -331,12 +331,9 @@ NSMenuItem *QCocoaMenuItem::sync() NSFont *customMenuFont = [NSFont fontWithName:m_font.family().toNSString() size:m_font.pointSize()]; if (customMenuFont) { - NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil]; - NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil]; - NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSAttributedString *str = [[[NSAttributedString alloc] initWithString:finalString.toNSString() - attributes:attributes] autorelease]; - [m_native setAttributedTitle: str]; + attributes:@{NSFontAttributeName: customMenuFont}] autorelease]; + [m_native setAttributedTitle:str]; useAttributedTitle = true; } } diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.h b/src/plugins/platforms/cocoa/qcocoamenuloader.h index 95f347646c..3d040efa84 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.h +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.h @@ -55,19 +55,6 @@ #include @interface QT_MANGLE_NAMESPACE(QCocoaMenuLoader) : NSResponder -{ - IBOutlet NSMenu *theMenu; - IBOutlet NSMenu *appMenu; - IBOutlet NSMenuItem *quitItem; - IBOutlet NSMenuItem *preferencesItem; - IBOutlet NSMenuItem *aboutItem; - IBOutlet NSMenuItem *aboutQtItem; - IBOutlet NSMenuItem *hideItem; - NSMenuItem *lastAppSpecificItem; - NSMenuItem *servicesItem; - NSMenuItem *hideAllOthersItem; - NSMenuItem *showAllItem; -} + (instancetype)sharedMenuLoader; - (instancetype)init; - (void)ensureAppMenuInMenu:(NSMenu *)menu; @@ -80,16 +67,16 @@ - (NSMenuItem *)aboutQtMenuItem; - (NSMenuItem *)hideMenuItem; - (NSMenuItem *)appSpecificMenuItem:(NSInteger)tag; -- (IBAction)terminate:(id)sender; -- (IBAction)orderFrontStandardAboutPanel:(id)sender; -- (IBAction)hideOtherApplications:(id)sender; -- (IBAction)unhideAllApplications:(id)sender; -- (IBAction)hide:(id)sender; -- (IBAction)qtDispatcherToQPAMenuItem:(id)sender; +- (void)terminate:(id)sender; +- (void)orderFrontStandardAboutPanel:(id)sender; +- (void)hideOtherApplications:(id)sender; +- (void)unhideAllApplications:(id)sender; +- (void)hide:(id)sender; +- (void)qtDispatcherToQPAMenuItem:(id)sender; - (void)orderFrontCharacterPalette:(id)sender; - (BOOL)validateMenuItem:(NSMenuItem*)menuItem; - (void)qtTranslateApplicationMenu; -- (NSArray *)mergeable; +- (NSArray *)mergeable; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuLoader); diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index cd597da71c..d4d7bc1d7a 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -50,7 +50,19 @@ #include #include -@implementation QCocoaMenuLoader +@implementation QCocoaMenuLoader { + NSMenu *theMenu; + NSMenu *appMenu; + NSMenuItem *quitItem; + NSMenuItem *preferencesItem; + NSMenuItem *aboutItem; + NSMenuItem *aboutQtItem; + NSMenuItem *hideItem; + NSMenuItem *lastAppSpecificItem; + NSMenuItem *servicesItem; + NSMenuItem *hideAllOthersItem; + NSMenuItem *showAllItem; +} + (instancetype)sharedMenuLoader { @@ -323,7 +335,7 @@ #endif } -- (IBAction)qtDispatcherToQPAMenuItem:(id)sender +- (void)qtDispatcherToQPAMenuItem:(id)sender { NSMenuItem *item = static_cast(sender); if (item == quitItem) { @@ -363,9 +375,10 @@ } } -- (NSArray*) mergeable +- (NSArray *)mergeable { - // don't include the quitItem here, since we want it always visible and enabled regardless + // Don't include the quitItem here, since we want it always visible and enabled regardless + // Note that lastAppSpecificItem may be nil, so we can't use @[] here. return [NSArray arrayWithObjects:preferencesItem, aboutItem, aboutQtItem, lastAppSpecificItem, nil]; } diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index ed1b19cd53..049cecff54 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -66,7 +66,7 @@ QCocoaScreen::~QCocoaScreen() NSScreen *QCocoaScreen::nativeScreen() const { - NSArray *screens = [NSScreen screens]; + NSArray *screens = [NSScreen screens]; // Stale reference, screen configuration has changed if (m_screenIndex < 0 || (NSUInteger)m_screenIndex >= [screens count]) diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index f4c968ab57..0b1e186bce 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -93,31 +93,16 @@ QT_USE_NAMESPACE @class QT_MANGLE_NAMESPACE(QNSImageView); @interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject -{ -@public - QCocoaSystemTrayIcon *systray; - NSStatusItem *item; - QCocoaMenu *menu; - QIcon icon; - QT_MANGLE_NAMESPACE(QNSImageView) *imageCell; -} --(id)initWithSysTray:(QCocoaSystemTrayIcon *)systray; --(void)dealloc; --(NSStatusItem*)item; --(QRectF)geometry; +@property (nonatomic, assign) QCocoaMenu *menu; +@property (nonatomic, assign) QIcon icon; +@property (nonatomic, readonly) NSStatusItem *item; +@property (nonatomic, readonly) QRectF geometry; +- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)systray; - (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; - (void)doubleClickSelector:(id)sender; -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification; -- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification; @end -@interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView { - BOOL down; - QT_MANGLE_NAMESPACE(QNSStatusItem) *parent; -} --(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent; --(void)menuTrackingDone:(NSNotification*)notification; --(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton; +@interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSStatusItem); @@ -176,7 +161,7 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon) if (!m_sys) return; - m_sys->item->icon = icon; + m_sys->item.icon = icon; // The reccomended maximum title bar icon height is 18 points // (device independent pixels). The menu height on past and @@ -247,8 +232,8 @@ void QCocoaSystemTrayIcon::updateMenu(QPlatformMenu *menu) if (!m_sys) return; - m_sys->item->menu = static_cast(menu); - if (menu && [m_sys->item->menu->nsMenu() numberOfItems] > 0) { + m_sys->item.menu = static_cast(menu); + if (menu && [m_sys->item.menu->nsMenu() numberOfItems] > 0) { [[m_sys->item item] setHighlightMode:YES]; } else { [[m_sys->item item] setHighlightMode:NO]; @@ -287,23 +272,29 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess } QT_END_NAMESPACE -@implementation QNSImageView --(id)initWithParent:(QNSStatusItem*)myParent { +@implementation NSStatusItem (Qt) +@end + +@implementation QNSImageView { + BOOL down; + QT_MANGLE_NAMESPACE(QNSStatusItem) *parent; +} + +- (instancetype)initWithParent:(QNSStatusItem *)myParent { self = [super init]; parent = myParent; down = NO; return self; } --(void)menuTrackingDone:(NSNotification*)notification +- (void)menuTrackingDone:(NSNotification *)__unused notification { - Q_UNUSED(notification); down = NO; [self setNeedsDisplay:YES]; } --(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton +- (void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton { down = YES; int clickCount = [mouseEvent clickCount]; @@ -317,12 +308,12 @@ QT_END_NAMESPACE } } --(void)mouseDown:(NSEvent *)mouseEvent +- (void)mouseDown:(NSEvent *)mouseEvent { [self mousePressed:mouseEvent button:Qt::LeftButton]; } --(void)mouseUp:(NSEvent *)mouseEvent +- (void)mouseUp:(NSEvent *)mouseEvent { Q_UNUSED(mouseEvent); [self menuTrackingDone:nil]; @@ -333,7 +324,7 @@ QT_END_NAMESPACE [self mousePressed:mouseEvent button:Qt::RightButton]; } --(void)rightMouseUp:(NSEvent *)mouseEvent +- (void)rightMouseUp:(NSEvent *)mouseEvent { Q_UNUSED(mouseEvent); [self menuTrackingDone:nil]; @@ -344,21 +335,28 @@ QT_END_NAMESPACE [self mousePressed:mouseEvent button:cocoaButton2QtButton([mouseEvent buttonNumber])]; } --(void)otherMouseUp:(NSEvent *)mouseEvent +- (void)otherMouseUp:(NSEvent *)mouseEvent { Q_UNUSED(mouseEvent); [self menuTrackingDone:nil]; } --(void)drawRect:(NSRect)rect { +- (void)drawRect:(NSRect)rect { [[parent item] drawStatusBarBackgroundInRect:rect withHighlight:down]; [super drawRect:rect]; } @end -@implementation QNSStatusItem +@implementation QNSStatusItem { + QCocoaSystemTrayIcon *systray; + NSStatusItem *item; + QT_MANGLE_NAMESPACE(QNSImageView) *imageCell; +} + +@synthesize menu = menu; +@synthesize icon = icon; --(id)initWithSysTray:(QCocoaSystemTrayIcon *)sys +- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)sys { self = [super init]; if (self) { @@ -371,19 +369,19 @@ QT_END_NAMESPACE return self; } --(void)dealloc { +- (void)dealloc { [[NSStatusBar systemStatusBar] removeStatusItem:item]; [[NSNotificationCenter defaultCenter] removeObserver:imageCell]; [imageCell release]; [item release]; [super dealloc]; - } --(NSStatusItem*)item { +- (NSStatusItem *)item { return item; } --(QRectF)geometry { + +- (QRectF)geometry { if (NSWindow *window = [[item view] window]) { NSRect screenRect = [[window screen] frame]; NSRect windowRect = [window frame]; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 93f0400916..f73db8873b 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -77,26 +77,24 @@ #include -@interface QT_MANGLE_NAMESPACE(QCocoaThemeNotificationReceiver) : NSObject { -QCocoaTheme *mPrivate; -} -- (id)initWithPrivate:(QCocoaTheme *)priv; -- (void)systemColorsDidChange:(NSNotification *)notification; +@interface QT_MANGLE_NAMESPACE(QCocoaThemeNotificationReceiver) : NSObject @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaThemeNotificationReceiver); -@implementation QCocoaThemeNotificationReceiver -- (id)initWithPrivate:(QCocoaTheme *)priv +@implementation QCocoaThemeNotificationReceiver { + QCocoaTheme *mPrivate; +} + +- (instancetype)initWithPrivate:(QCocoaTheme *)priv { - self = [super init]; - mPrivate = priv; + if ((self = [self init])) + mPrivate = priv; return self; } -- (void)systemColorsDidChange:(NSNotification *)notification +- (void)systemColorsDidChange:(NSNotification *)__unused notification { - Q_UNUSED(notification); mPrivate->reset(); QWindowSystemInterface::handleThemeChange(nullptr); } diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index e2ea862cd5..23c3b6100e 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -42,52 +42,22 @@ #include -#include -#include -#include -#include - #include "private/qcore_mac_p.h" QT_BEGIN_NAMESPACE class QCocoaWindow; class QCocoaGLContext; +class QPointF; QT_END_NAMESPACE Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); -@interface QT_MANGLE_NAMESPACE(QNSView) : NSView { - QPointer m_platformWindow; - NSTrackingArea *m_trackingArea; - Qt::MouseButtons m_buttons; - Qt::MouseButtons m_acceptedMouseDowns; - Qt::MouseButtons m_frameStrutButtons; - QString m_composingText; - QPointer m_composingFocusObject; - bool m_sendKeyEvent; - QStringList *currentCustomDragTypes; - bool m_dontOverrideCtrlLMB; - bool m_sendUpAsRightButton; - Qt::KeyboardModifiers currentWheelModifiers; -#ifndef QT_NO_OPENGL - QCocoaGLContext *m_glContext; - bool m_shouldSetGLContextinDrawRect; -#endif - NSString *m_inputSource; - QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) *m_mouseMoveHelper; - bool m_resendKeyEvent; - bool m_scrolling; - bool m_updatingDrag; - NSEvent *m_currentlyInterpretedKeyEvent; - bool m_isMenuView; - QSet m_acceptedKeyDowns; - bool m_updateRequested; -} +@interface QT_MANGLE_NAMESPACE(QNSView) : NSView @property (nonatomic, retain) NSCursor *cursor; -- (id)init; -- (id)initWithCocoaWindow:(QCocoaWindow *)platformWindow; +- (instancetype)init; +- (instancetype)initWithCocoaWindow:(QCocoaWindow *)platformWindow; #ifndef QT_NO_OPENGL - (void)setQCocoaGLContext:(QCocoaGLContext *)context; #endif diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index fd7f216e10..6a79c76991 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -51,7 +51,11 @@ #include #include #include +#include +#include #include +#include +#include #include #include #include @@ -72,11 +76,8 @@ Q_LOGGING_CATEGORY(lcQpaGestures, "qt.qpa.input.gestures") Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") @interface QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) : NSObject -{ - QNSView *view; -} -- (id)initWithView:(QNSView *)theView; +- (instancetype)initWithView:(QNSView *)theView; - (void)mouseMoved:(NSEvent *)theEvent; - (void)mouseEntered:(NSEvent *)theEvent; @@ -85,9 +86,11 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") @end -@implementation QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) +@implementation QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) { + QNSView *view; +} -- (id)initWithView:(QNSView *)theView +- (instancetype)initWithView:(QNSView *)theView { self = [super init]; if (self) { @@ -123,9 +126,35 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") - (BOOL)isTransparentForUserInput; @end -@implementation QT_MANGLE_NAMESPACE(QNSView) +@implementation QT_MANGLE_NAMESPACE(QNSView) { + QPointer m_platformWindow; + NSTrackingArea *m_trackingArea; + Qt::MouseButtons m_buttons; + Qt::MouseButtons m_acceptedMouseDowns; + Qt::MouseButtons m_frameStrutButtons; + QString m_composingText; + QPointer m_composingFocusObject; + bool m_sendKeyEvent; + QStringList *currentCustomDragTypes; + bool m_dontOverrideCtrlLMB; + bool m_sendUpAsRightButton; + Qt::KeyboardModifiers currentWheelModifiers; +#ifndef QT_NO_OPENGL + QCocoaGLContext *m_glContext; + bool m_shouldSetGLContextinDrawRect; +#endif + NSString *m_inputSource; + QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) *m_mouseMoveHelper; + bool m_resendKeyEvent; + bool m_scrolling; + bool m_updatingDrag; + NSEvent *m_currentlyInterpretedKeyEvent; + bool m_isMenuView; + QSet m_acceptedKeyDowns; + bool m_updateRequested; +} -- (id) init +- (instancetype)init { if (self = [super initWithFrame:NSZeroRect]) { m_buttons = Qt::NoButton; @@ -168,7 +197,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") [super dealloc]; } -- (id)initWithCocoaWindow:(QCocoaWindow *)platformWindow +- (instancetype)initWithCocoaWindow:(QCocoaWindow *)platformWindow { self = [self init]; if (!self) @@ -1432,7 +1461,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) if (imEnabled && !(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText)) { // pass the key event to the input method. note that m_sendKeyEvent may be set to false during this call m_currentlyInterpretedKeyEvent = nsevent; - [self interpretKeyEvents:[NSArray arrayWithObject:nsevent]]; + [self interpretKeyEvents:@[nsevent]]; m_currentlyInterpretedKeyEvent = 0; } } @@ -1790,7 +1819,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) return NSNotFound; } -- (NSArray*)validAttributesForMarkedText +- (NSArray *)validAttributesForMarkedText { if (!m_platformWindow) return nil; @@ -1809,8 +1838,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) return nil; // Support only underline color/style. - return [NSArray arrayWithObjects:NSUnderlineColorAttributeName, - NSUnderlineStyleAttributeName, nil]; + return @[NSUnderlineColorAttributeName, NSUnderlineStyleAttributeName]; } -(void)registerDragTypes @@ -1821,8 +1849,9 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) if (currentCustomDragTypes == 0) currentCustomDragTypes = new QStringList(); *currentCustomDragTypes = customTypes; - const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; - NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType, + NSString * const mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; + NSMutableArray *supportedTypes = [NSMutableArray arrayWithArray:@[ + NSColorPboardType, NSFilenamesPboardType, NSStringPboardType, NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType, NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType, @@ -1830,7 +1859,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) NSRTFDPboardType, NSHTMLPboardType, NSURLPboardType, NSPDFPboardType, NSVCardPboardType, NSFilesPromisePboardType, NSInkTextPboardType, - NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil]; + NSMultipleTextSelectionPboardType, mimeTypeGeneric]]; // Add custom types supported by the application. for (int i = 0; i < customTypes.size(); i++) { [supportedTypes addObject:customTypes[i].toNSString()]; diff --git a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm index 645a93edf7..ab0036e175 100644 --- a/src/plugins/platforms/cocoa/qnsviewaccessibility.mm +++ b/src/plugins/platforms/cocoa/qnsviewaccessibility.mm @@ -53,14 +53,12 @@ @implementation QNSView (QNSViewAccessibility) - (id)childAccessibleElement { - if (m_platformWindow.isNull()) + QCocoaWindow *platformWindow = self.platformWindow; + if (!platformWindow || !platformWindow->window()->accessibleRoot()) return nil; - if (!m_platformWindow->window()->accessibleRoot()) - return nil; - - QAccessible::Id childId = QAccessible::uniqueId(m_platformWindow->window()->accessibleRoot()); - return [QMacAccessibilityElement elementWithId: childId]; + QAccessible::Id childId = QAccessible::uniqueId(platformWindow->window()->accessibleRoot()); + return [QMacAccessibilityElement elementWithId:childId]; } // The QNSView is a container that the user does not interact directly with: diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index cb13b7d184..086a4f8af2 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qnswindow.h" -#include "qnswindowdelegate.h" #include "qcocoawindow.h" #include "qcocoahelpers.h" #include "qcocoaeventdispatcher.h" @@ -72,7 +71,7 @@ static bool isMouseEvent(NSEvent *ev) [center addObserverForName:NSWindowDidEnterFullScreenNotification object:nil queue:nil usingBlock:^(NSNotification *notification) { objc_setAssociatedObject(notification.object, @selector(qt_fullScreen), - [NSNumber numberWithBool:YES], OBJC_ASSOCIATION_RETAIN); + @(YES), OBJC_ASSOCIATION_RETAIN); } ]; [center addObserverForName:NSWindowDidExitFullScreenNotification object:nil queue:nil @@ -267,14 +266,14 @@ static bool isMouseEvent(NSEvent *ev) if (__builtin_available(macOS 10.12, *)) { // Unfortunately there's no NSWindowListOrderedBackToFront, // so we have to manually reverse the order using an array. - NSMutableArray *windows = [[[NSMutableArray alloc] init] autorelease]; + NSMutableArray *windows = [NSMutableArray new]; [application enumerateWindowsWithOptions:NSWindowListOrderedFrontToBack usingBlock:^(NSWindow *window, BOOL *) { // For some reason AppKit will give us nil-windows, skip those if (!window) return; - [(NSMutableArray*)windows addObject:window]; + [windows addObject:window]; } ]; diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.h b/src/plugins/platforms/cocoa/qnswindowdelegate.h index d2078b5786..e71afcbb2a 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.h +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.h @@ -41,20 +41,16 @@ #define QNSWINDOWDELEGATE_H #include +#include -#include "qcocoawindow.h" +QT_BEGIN_NAMESPACE +class QCocoaWindow; +QT_END_NAMESPACE @interface QT_MANGLE_NAMESPACE(QNSWindowDelegate) : NSObject -{ - QCocoaWindow *m_cocoaWindow; -} -- (id)initWithQCocoaWindow:(QCocoaWindow *)cocoaWindow; +- (instancetype)initWithQCocoaWindow:(QT_PREPEND_NAMESPACE(QCocoaWindow) *)cocoaWindow; -- (BOOL)windowShouldClose:(NSNotification *)notification; - -- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu; -- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSWindowDelegate); diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm index 6e5623d679..1888dc1c90 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm @@ -39,20 +39,23 @@ #include "qnswindowdelegate.h" #include "qcocoahelpers.h" +#include "qcocoawindow.h" #include +#include #include #include static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*")); -@implementation QNSWindowDelegate +@implementation QNSWindowDelegate { + QCocoaWindow *m_cocoaWindow; +} -- (id)initWithQCocoaWindow:(QCocoaWindow *)cocoaWindow +- (instancetype)initWithQCocoaWindow:(QCocoaWindow *)cocoaWindow { - if (self = [super init]) + if ((self = [self init])) m_cocoaWindow = cocoaWindow; - return self; } diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h index c52d498cd4..201b277494 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h @@ -41,8 +41,6 @@ #include "../../qiosfiledialog.h" -@interface QIOSImagePickerController : UIImagePickerController { - QIOSFileDialog *m_fileDialog; -} -- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog; +@interface QIOSImagePickerController : UIImagePickerController +- (instancetype)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog; @end diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm index 78e0f00ab4..79d4ecf83f 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm @@ -41,15 +41,17 @@ #include "qiosimagepickercontroller.h" -@implementation QIOSImagePickerController +@implementation QIOSImagePickerController { + QIOSFileDialog *m_fileDialog; +} -- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog +- (instancetype)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog { self = [super init]; if (self) { m_fileDialog = fileDialog; - [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; - [self setDelegate:self]; + self.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; + self.delegate = self; } return self; } @@ -57,8 +59,8 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { Q_UNUSED(picker); - NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; - QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); + NSURL *url = info[UIImagePickerControllerReferenceURL]; + QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString(url.description)); m_fileDialog->selectedFilesChanged(QList() << fileUrl); emit m_fileDialog->accept(); } diff --git a/src/plugins/platforms/ios/qiosclipboard.mm b/src/plugins/platforms/ios/qiosclipboard.mm index 9a975eadc9..6bdbf94d3f 100644 --- a/src/plugins/platforms/ios/qiosclipboard.mm +++ b/src/plugins/platforms/ios/qiosclipboard.mm @@ -46,11 +46,11 @@ #include @interface UIPasteboard (QUIPasteboard) - + (UIPasteboard *)pasteboardWithQClipboardMode:(QClipboard::Mode)mode; ++ (instancetype)pasteboardWithQClipboardMode:(QClipboard::Mode)mode; @end @implementation UIPasteboard (QUIPasteboard) -+ (UIPasteboard *)pasteboardWithQClipboardMode:(QClipboard::Mode)mode ++ (instancetype)pasteboardWithQClipboardMode:(QClipboard::Mode)mode { NSString *name = (mode == QClipboard::Clipboard) ? UIPasteboardNameGeneral : UIPasteboardNameFind; return [UIPasteboard pasteboardWithName:name create:NO]; @@ -60,17 +60,15 @@ // -------------------------------------------------------------------- @interface QUIClipboard : NSObject -{ -@public +@end + +@implementation QUIClipboard { QIOSClipboard *m_qiosClipboard; NSInteger m_changeCountClipboard; NSInteger m_changeCountFindBuffer; } -@end - -@implementation QUIClipboard -- (id)initWithQIOSClipboard:(QIOSClipboard *)qiosClipboard +- (instancetype)initWithQIOSClipboard:(QIOSClipboard *)qiosClipboard { self = [super init]; if (self) { @@ -149,7 +147,7 @@ QStringList QIOSMimeData::formats() const { QStringList foundMimeTypes; UIPasteboard *pb = [UIPasteboard pasteboardWithQClipboardMode:m_mode]; - NSArray *pasteboardTypes = [pb pasteboardTypes]; + NSArray *pasteboardTypes = [pb pasteboardTypes]; for (NSUInteger i = 0; i < [pasteboardTypes count]; ++i) { QString uti = QString::fromNSString([pasteboardTypes objectAtIndex:i]); @@ -164,7 +162,7 @@ QStringList QIOSMimeData::formats() const QVariant QIOSMimeData::retrieveData(const QString &mimeType, QVariant::Type) const { UIPasteboard *pb = [UIPasteboard pasteboardWithQClipboardMode:m_mode]; - NSArray *pasteboardTypes = [pb pasteboardTypes]; + NSArray *pasteboardTypes = [pb pasteboardTypes]; foreach (QMacInternalPasteboardMime *converter, QMacInternalPasteboardMime::all(QMacInternalPasteboardMime::MIME_ALL)) { @@ -213,12 +211,12 @@ void QIOSClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode) UIPasteboard *pb = [UIPasteboard pasteboardWithQClipboardMode:mode]; if (!mimeData) { - pb.items = [NSArray array]; + pb.items = [NSArray *> array]; return; } mimeData->deleteLater(); - NSMutableDictionary *pbItem = [NSMutableDictionary dictionaryWithCapacity:mimeData->formats().size()]; + NSMutableDictionary *pbItem = [NSMutableDictionary dictionaryWithCapacity:mimeData->formats().size()]; foreach (const QString &mimeType, mimeData->formats()) { foreach (QMacInternalPasteboardMime *converter, @@ -246,7 +244,7 @@ void QIOSClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode) } } - pb.items = [NSArray arrayWithObject:pbItem]; + pb.items = @[pbItem]; } bool QIOSClipboard::supportsMode(QClipboard::Mode mode) const diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index a6f6a7aac9..7a2399efcd 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -245,7 +245,7 @@ extern "C" int main(int argc, char *argv[]); static void __attribute__((noinline, noreturn)) user_main_trampoline() { - NSArray *arguments = [[NSProcessInfo processInfo] arguments]; + NSArray *arguments = [[NSProcessInfo processInfo] arguments]; int argc = arguments.count; char **argv = new char*[argc]; diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index 050c592aca..3e22634071 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -67,7 +67,7 @@ static QUIView *focusView() @implementation QIOSLocaleListener -- (id)init +- (instancetype)init { if (self = [super init]) { NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; @@ -95,16 +95,15 @@ static QUIView *focusView() // ------------------------------------------------------------------------- -@interface QIOSKeyboardListener : UIGestureRecognizer { - @private - QT_PREPEND_NAMESPACE(QIOSInputContext) *m_context; -} +@interface QIOSKeyboardListener : UIGestureRecognizer @property BOOL hasDeferredScrollToCursor; @end -@implementation QIOSKeyboardListener +@implementation QIOSKeyboardListener { + QT_PREPEND_NAMESPACE(QIOSInputContext) *m_context; +} -- (id)initWithQIOSInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)context +- (instancetype)initWithQIOSInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)context { if (self = [super initWithTarget:self action:@selector(gestureStateChanged:)]) { @@ -574,7 +573,7 @@ void QIOSInputContext::scroll(int y) // Raise all known windows to above the status-bar if we're scrolling the screen, // while keeping the relative window level between the windows the same. - NSArray *applicationWindows = [[UIApplication sharedApplication] windows]; + NSArray *applicationWindows = [[UIApplication sharedApplication] windows]; static QHash originalWindowLevels; for (UIWindow *window in applicationWindows) { if (keyboardScrollIsActive && !originalWindowLevels.contains(window)) diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 92c1e39d72..5f9f7ad96d 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -97,7 +97,7 @@ QIOSIntegration::QIOSIntegration() QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String])); UIScreen *mainScreen = [UIScreen mainScreen]; - NSMutableArray *screens = [[[UIScreen screens] mutableCopy] autorelease]; + NSMutableArray *screens = [[[UIScreen screens] mutableCopy] autorelease]; if (![screens containsObject:mainScreen]) { // Fallback for iOS 7.1 (QTBUG-42345) [screens insertObject:mainScreen atIndex:0]; diff --git a/src/plugins/platforms/ios/qiosmenu.mm b/src/plugins/platforms/ios/qiosmenu.mm index 6c70676a31..74a77de757 100644 --- a/src/plugins/platforms/ios/qiosmenu.mm +++ b/src/plugins/platforms/ios/qiosmenu.mm @@ -60,14 +60,14 @@ QIOSMenu *QIOSMenu::m_currentMenu = 0; static NSString *const kSelectorPrefix = @"_qtMenuItem_"; -@interface QUIMenuController : UIResponder { - QIOSMenuItemList m_visibleMenuItems; -} +@interface QUIMenuController : UIResponder @end -@implementation QUIMenuController +@implementation QUIMenuController { + QIOSMenuItemList m_visibleMenuItems; +} -- (id)initWithVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems +- (instancetype)initWithVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems { if (self = [super init]) { [self setVisibleMenuItems:visibleMenuItems]; @@ -80,7 +80,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; return self; } --(void)dealloc +- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self @@ -91,7 +91,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; - (void)setVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems { m_visibleMenuItems = visibleMenuItems; - NSMutableArray *menuItemArray = [NSMutableArray arrayWithCapacity:m_visibleMenuItems.size()]; + NSMutableArray *menuItemArray = [NSMutableArray arrayWithCapacity:m_visibleMenuItems.size()]; // Create an array of UIMenuItems, one for each visible QIOSMenuItem. Each // UIMenuItem needs a callback assigned, so we assign one of the placeholder methods // added to UIWindow (QIOSMenuActionTargets) below. Each method knows its own index, which @@ -107,7 +107,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; [[UIMenuController sharedMenuController] setMenuVisible:YES animated:NO]; } --(void)menuClosed +- (void)menuClosed { QIOSMenu::currentMenu()->dismiss(); } @@ -141,19 +141,19 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; // ------------------------------------------------------------------------- -@interface QUIPickerView : UIPickerView { - QIOSMenuItemList m_visibleMenuItems; - QPointer m_focusObjectWithPickerView; - NSInteger m_selectedRow; -} +@interface QUIPickerView : UIPickerView @property(retain) UIToolbar *toolbar; @end -@implementation QUIPickerView +@implementation QUIPickerView { + QIOSMenuItemList m_visibleMenuItems; + QPointer m_focusObjectWithPickerView; + NSInteger m_selectedRow; +} -- (id)initWithVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems selectItem:(const QIOSMenuItem *)selectItem +- (instancetype)initWithVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems selectItem:(const QIOSMenuItem *)selectItem { if (self = [super init]) { [self setVisibleMenuItems:visibleMenuItems selectItem:selectItem]; @@ -172,7 +172,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closeMenu)] autorelease]; - [self.toolbar setItems:[NSArray arrayWithObjects:cancelButton, spaceButton, doneButton, nil]]; + [self.toolbar setItems:@[cancelButton, spaceButton, doneButton]]; [self setDelegate:self]; [self setDataSource:self]; diff --git a/src/plugins/platforms/ios/qiosoptionalplugininterface.h b/src/plugins/platforms/ios/qiosoptionalplugininterface.h index 660c74e856..bae9e5a0d8 100644 --- a/src/plugins/platforms/ios/qiosoptionalplugininterface.h +++ b/src/plugins/platforms/ios/qiosoptionalplugininterface.h @@ -44,10 +44,10 @@ #include "qiosfiledialog.h" -QT_BEGIN_NAMESPACE - Q_FORWARD_DECLARE_OBJC_CLASS(UIViewController); +QT_BEGIN_NAMESPACE + #define QIosOptionalPluginInterface_iid "org.qt-project.Qt.QPA.ios.optional" class QIosOptionalPluginInterface diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index c394592d76..91d26c88c2 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -130,16 +130,14 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) // ------------------------------------------------------------------------- -@interface QIOSOrientationListener : NSObject { - @public - QIOSScreen *m_screen; -} -- (id)initWithQIOSScreen:(QIOSScreen *)screen; +@interface QIOSOrientationListener : NSObject @end -@implementation QIOSOrientationListener +@implementation QIOSOrientationListener { + QIOSScreen *m_screen; +} -- (id)initWithQIOSScreen:(QIOSScreen *)screen +- (instancetype)initWithQIOSScreen:(QIOSScreen *)screen { self = [super init]; if (self) { @@ -193,7 +191,7 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) @implementation QUIWindow -- (id)initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) self->_sendingEvent = NO; diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index fe3c29d037..ff696f5b7f 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -96,7 +96,7 @@ static void executeBlockWithoutAnimation(Block block) @implementation QIOSEditMenu -- (id)init +- (instancetype)init { if (self = [super init]) { NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; @@ -160,7 +160,13 @@ static void executeBlockWithoutAnimation(Block block) // ------------------------------------------------------------------------- -@interface QIOSLoupeLayer : CALayer { +@interface QIOSLoupeLayer : CALayer +@property (nonatomic, retain) UIView *targetView; +@property (nonatomic, assign) CGPoint focalPoint; +@property (nonatomic, assign) BOOL visible; +@end + +@implementation QIOSLoupeLayer { UIView *_snapshotView; BOOL _pendingSnapshotUpdate; UIView *_loupeImageView; @@ -168,14 +174,8 @@ static void executeBlockWithoutAnimation(Block block) CGFloat _loupeOffset; QTimer _updateTimer; } -@property (nonatomic, retain) UIView *targetView; -@property (nonatomic, assign) CGPoint focalPoint; -@property (nonatomic, assign) BOOL visible; -@end -@implementation QIOSLoupeLayer - -- (id)initWithSize:(CGSize)size cornerRadius:(CGFloat)cornerRadius bottomOffset:(CGFloat)bottomOffset +- (instancetype)initWithSize:(CGSize)size cornerRadius:(CGFloat)cornerRadius bottomOffset:(CGFloat)bottomOffset { if (self = [super init]) { _loupeOffset = bottomOffset + (size.height / 2); @@ -301,26 +301,22 @@ static void executeBlockWithoutAnimation(Block block) // ------------------------------------------------------------------------- -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) -@interface QIOSHandleLayer : CALayer { -#else -@interface QIOSHandleLayer : CALayer { -#endif - CALayer *_handleCursorLayer; - CALayer *_handleKnobLayer; - Qt::Edge _selectionEdge; -} +@interface QIOSHandleLayer : CALayer @property (nonatomic, assign) CGRect cursorRectangle; @property (nonatomic, assign) CGFloat handleScale; @property (nonatomic, assign) BOOL visible; @property (nonatomic, copy) Block onAnimationDidStop; @end -@implementation QIOSHandleLayer +@implementation QIOSHandleLayer { + CALayer *_handleCursorLayer; + CALayer *_handleKnobLayer; + Qt::Edge _selectionEdge; +} @dynamic handleScale; -- (id)initWithKnobAtEdge:(Qt::Edge)selectionEdge +- (instancetype)initWithKnobAtEdge:(Qt::Edge)selectionEdge { if (self = [super init]) { CGColorRef bgColor = [UIColor colorWithRed:0.1 green:0.4 blue:0.9 alpha:1].CGColor; @@ -355,16 +351,8 @@ static void executeBlockWithoutAnimation(Block block) // The handle should "bounce" in when becoming visible CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:key]; [animation setDuration:0.5]; - animation.values = [NSArray arrayWithObjects: - [NSNumber numberWithFloat:0], - [NSNumber numberWithFloat:1.3], - [NSNumber numberWithFloat:1.3], - [NSNumber numberWithFloat:1], nil]; - animation.keyTimes = [NSArray arrayWithObjects: - [NSNumber numberWithFloat:0], - [NSNumber numberWithFloat:0.3], - [NSNumber numberWithFloat:0.9], - [NSNumber numberWithFloat:1], nil]; + animation.values = @[@(0.0f), @(1.3f), @(1.3f), @(1.0f)]; + animation.keyTimes = @[@(0.0f), @(0.3f), @(0.9f), @(1.0f)]; return animation; } else { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:key]; @@ -436,8 +424,13 @@ static void executeBlockWithoutAnimation(Block block) below will inherit. It takes care of creating and showing a magnifier glass depending on the current gesture state. */ -@interface QIOSLoupeRecognizer : UIGestureRecognizer { -@public +@interface QIOSLoupeRecognizer : UIGestureRecognizer +@property (nonatomic, assign) QPointF focalPoint; +@property (nonatomic, assign) BOOL dragTriggersGesture; +@property (nonatomic, readonly) UIView *focusView; +@end + +@implementation QIOSLoupeRecognizer { QIOSLoupeLayer *_loupeLayer; UIView *_desktopView; CGPoint _firstTouchPoint; @@ -445,14 +438,8 @@ static void executeBlockWithoutAnimation(Block block) QTimer _triggerStateBeganTimer; int _originalCursorFlashTime; } -@property (nonatomic, assign) QPointF focalPoint; -@property (nonatomic, assign) BOOL dragTriggersGesture; -@property (nonatomic, readonly) UIView *focusView; -@end -@implementation QIOSLoupeRecognizer - -- (id)init +- (instancetype)init { if (self = [super initWithTarget:self action:@selector(gestureStateChanged)]) { self.enabled = NO; @@ -657,7 +644,10 @@ static void executeBlockWithoutAnimation(Block block) on the sides. If the user starts dragging on a handle (or do a press and hold), it will show a magnifier glass that follows the handle as it moves. */ -@interface QIOSSelectionRecognizer : QIOSLoupeRecognizer { +@interface QIOSSelectionRecognizer : QIOSLoupeRecognizer +@end + +@implementation QIOSSelectionRecognizer { CALayer *_clipRectLayer; QIOSHandleLayer *_cursorLayer; QIOSHandleLayer *_anchorLayer; @@ -669,11 +659,8 @@ static void executeBlockWithoutAnimation(Block block) QMetaObject::Connection _anchorConnection; QMetaObject::Connection _clipRectConnection; } -@end - -@implementation QIOSSelectionRecognizer -- (id)init +- (instancetype)init { if (self = [super init]) { self.delaysTouchesBegan = YES; @@ -889,15 +876,15 @@ static void executeBlockWithoutAnimation(Block block) visibility of the edit menu will be toggled. Otherwise, if there's a selection, a first tap will close the edit menu (if any), and a second tap will remove the selection. */ -@interface QIOSTapRecognizer : UITapGestureRecognizer { +@interface QIOSTapRecognizer : UITapGestureRecognizer +@end + +@implementation QIOSTapRecognizer { int _cursorPosOnPress; UIView *_focusView; } -@end - -@implementation QIOSTapRecognizer -- (id)init +- (instancetype)init { if (self = [super initWithTarget:self action:@selector(gestureStateChanged)]) { self.enabled = NO; diff --git a/src/plugins/platforms/ios/qiostextresponder.h b/src/plugins/platforms/ios/qiostextresponder.h index 77be2cf2fe..074598c1c3 100644 --- a/src/plugins/platforms/ios/qiostextresponder.h +++ b/src/plugins/platforms/ios/qiostextresponder.h @@ -49,16 +49,8 @@ class QIOSInputContext; QT_END_NAMESPACE @interface QIOSTextInputResponder : UIResponder -{ - @private - QT_PREPEND_NAMESPACE(QIOSInputContext) *m_inputContext; - QT_PREPEND_NAMESPACE(QInputMethodQueryEvent) *m_configuredImeState; - QString m_markedText; - BOOL m_inSendEventToFocusObject; - BOOL m_inSelectionChange; -} -- (id)initWithInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)context; +- (instancetype)initWithInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)context; - (BOOL)needsKeyboardReconfigure:(Qt::InputMethodQueries)updatedProperties; - (void)notifyInputDelegate:(Qt::InputMethodQueries)updatedProperties; diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index b029c49a67..91a088ede1 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -55,13 +55,13 @@ @interface QUITextPosition : UITextPosition @property (nonatomic) NSUInteger index; -+ (QUITextPosition *)positionWithIndex:(NSUInteger)index; ++ (instancetype)positionWithIndex:(NSUInteger)index; @end @implementation QUITextPosition -+ (QUITextPosition *)positionWithIndex:(NSUInteger)index ++ (instancetype)positionWithIndex:(NSUInteger)index { QUITextPosition *pos = [[QUITextPosition alloc] init]; pos.index = index; @@ -75,15 +75,15 @@ @interface QUITextRange : UITextRange @property (nonatomic) NSRange range; -+ (QUITextRange *)rangeWithNSRange:(NSRange)range; ++ (instancetype)rangeWithNSRange:(NSRange)range; @end @implementation QUITextRange -+ (QUITextRange *)rangeWithNSRange:(NSRange)nsrange ++ (instancetype)rangeWithNSRange:(NSRange)nsrange { - QUITextRange *range = [[QUITextRange alloc] init]; + QUITextRange *range = [[self alloc] init]; range.range = nsrange; return [range autorelease]; } @@ -117,7 +117,7 @@ @implementation WrapperView -- (id)initWithView:(UIView *)view +- (instancetype)initWithView:(UIView *)view { if (self = [self init]) { [self addSubview:view]; @@ -132,7 +132,7 @@ - (void)layoutSubviews { - UIView* view = [self.subviews firstObject]; + UIView *view = [self.subviews firstObject]; view.frame = self.bounds; // FIXME: During orientation changes the size and position @@ -161,9 +161,15 @@ // ------------------------------------------------------------------------- -@implementation QIOSTextInputResponder +@implementation QIOSTextInputResponder { + QT_PREPEND_NAMESPACE(QIOSInputContext) *m_inputContext; + QT_PREPEND_NAMESPACE(QInputMethodQueryEvent) *m_configuredImeState; + QString m_markedText; + BOOL m_inSendEventToFocusObject; + BOOL m_inSelectionChange; +} -- (id)initWithInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)inputContext +- (instancetype)initWithInputContext:(QT_PREPEND_NAMESPACE(QIOSInputContext) *)inputContext { if (!(self = [self init])) return self; @@ -548,7 +554,7 @@ [self sendKeyPressRelease:key modifiers:modifiers]; } -- (void)addKeyCommandsToArray:(NSMutableArray *)array key:(NSString *)key +- (void)addKeyCommandsToArray:(NSMutableArray *)array key:(NSString *)key { SEL s = @selector(keyCommandTriggered:); [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:0 action:s]]; @@ -559,19 +565,19 @@ [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierCommand|UIKeyModifierShift action:s]]; } -- (NSArray *)keyCommands +- (NSArray *)keyCommands { // Since keyCommands is called for every key // press/release, we cache the result static dispatch_once_t once; - static NSMutableArray *array; + static NSMutableArray *array; dispatch_once(&once, ^{ // We let Qt move the cursor around when the arrow keys are being used. This // is normally implemented through UITextInput, but since IM in Qt have poor // support for moving the cursor vertically, and even less support for selecting // text across multiple paragraphs, we do this through key events. - array = [NSMutableArray new]; + array = [NSMutableArray new]; [self addKeyCommandsToArray:array key:UIKeyInputUpArrow]; [self addKeyCommandsToArray:array key:UIKeyInputDownArrow]; [self addKeyCommandsToArray:array key:UIKeyInputLeftArrow]; @@ -825,13 +831,13 @@ return startRect.united(endRect).toCGRect(); } -- (NSArray *)selectionRectsForRange:(UITextRange *)range +- (NSArray *)selectionRectsForRange:(UITextRange *)range { Q_UNUSED(range); // This method is supposed to return a rectangle for each line with selection. Since we don't // expose an API in Qt/IM for getting this information, and since we never seems to be getting // a call from UIKit for this, we return an empty array until a need arise. - return [[NSArray new] autorelease]; + return [[NSArray new] autorelease]; } - (CGRect)caretRectForPosition:(UITextPosition *)position @@ -916,7 +922,7 @@ QObject *focusObject = QGuiApplication::focusObject(); if (!focusObject) - return [NSDictionary dictionary]; + return @{}; // Assume position is the same as the cursor for now. QInputMethodQueryEvent with Qt::ImFont // needs to be extended to take an extra position argument before this can be fully correct. @@ -925,8 +931,8 @@ QFont qfont = qvariant_cast(e.value(Qt::ImFont)); UIFont *uifont = [UIFont fontWithName:qfont.family().toNSString() size:qfont.pointSize()]; if (!uifont) - return [NSDictionary dictionary]; - return [NSDictionary dictionaryWithObject:uifont forKey:NSFontAttributeName]; + return @{}; + return @{NSFontAttributeName: uifont}; } #endif diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index 07d5535e1a..7af4c83b48 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -48,7 +48,7 @@ QT_END_NAMESPACE @interface QIOSViewController : UIViewController -- (id)initWithQIOSScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen; +- (instancetype)initWithQIOSScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen; - (void)updateProperties; #ifndef Q_OS_TVOS diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index a7663b9e94..787c6b8409 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -56,12 +56,8 @@ // ------------------------------------------------------------------------- -@interface QIOSViewController () { - @public - QPointer m_screen; - BOOL m_updatingProperties; - QMetaObject::Connection m_focusWindowChangeConnection; -} +@interface QIOSViewController () +@property (nonatomic, assign) QPointer platformScreen; @property (nonatomic, assign) BOOL changingOrientation; @end @@ -72,7 +68,7 @@ @implementation QIOSDesktopManagerView -- (id)init +- (instancetype)init { if (!(self = [super init])) return nil; @@ -125,7 +121,7 @@ { Q_UNUSED(subview); - QT_PREPEND_NAMESPACE(QIOSScreen) *screen = self.qtViewController->m_screen; + QT_PREPEND_NAMESPACE(QIOSScreen) *screen = self.qtViewController.platformScreen; // The 'window' property of our view is not valid until the window // has been shown, so we have to access it through the QIOSScreen. @@ -170,7 +166,7 @@ // here. iOS will still use the latest rendered frame to create the // application switcher thumbnail, but it will be based on the last // active orientation of the application. - QIOSScreen *screen = self.qtViewController->m_screen; + QIOSScreen *screen = self.qtViewController.platformScreen; qCDebug(lcQpaWindow) << "ignoring layout of subviews while suspended," << "likely system snapshot of" << screen->screen()->primaryOrientation(); return; @@ -246,7 +242,10 @@ // ------------------------------------------------------------------------- -@implementation QIOSViewController +@implementation QIOSViewController { + BOOL m_updatingProperties; + QMetaObject::Connection m_focusWindowChangeConnection; +} #ifndef Q_OS_TVOS @synthesize prefersStatusBarHidden; @@ -254,11 +253,10 @@ @synthesize preferredStatusBarStyle; #endif -- (id)initWithQIOSScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen +- (instancetype)initWithQIOSScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen { if (self = [self init]) { - m_screen = screen; - + self.platformScreen = screen; self.changingOrientation = NO; #ifndef Q_OS_TVOS @@ -316,7 +314,7 @@ - (BOOL)shouldAutorotate { #ifndef Q_OS_TVOS - return m_screen && m_screen->uiScreen() == [UIScreen mainScreen] && !self.lockedOrientation; + return self.platformScreen && self.platformScreen->uiScreen() == [UIScreen mainScreen] && !self.lockedOrientation; #else return NO; #endif @@ -396,8 +394,8 @@ if (!QCoreApplication::instance()) return; - if (m_screen) - m_screen->updateProperties(); + if (self.platformScreen) + self.platformScreen->updateProperties(); } // ------------------------------------------------------------------------- @@ -407,12 +405,12 @@ if (!isQtApplication()) return; - if (!m_screen || !m_screen->screen()) + if (!self.platformScreen || !self.platformScreen->screen()) return; // For now we only care about the main screen, as both the statusbar // visibility and orientation is only appropriate for the main screen. - if (m_screen->uiScreen() != [UIScreen mainScreen]) + if (self.platformScreen->uiScreen() != [UIScreen mainScreen]) return; // Prevent recursion caused by updating the status bar appearance (position @@ -434,7 +432,7 @@ return; // We only care about changes to focusWindow that involves our screen - if (!focusWindow->screen() || focusWindow->screen()->handle() != m_screen) + if (!focusWindow->screen() || focusWindow->screen()->handle() != self.platformScreen) return; // All decisions are based on the the top level window diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 6ee258e363..cdec57de71 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -96,7 +96,7 @@ QIOSWindow::~QIOSWindow() [m_view touchesCancelled:[NSSet set] withEvent:0]; clearAccessibleCache(); - m_view->m_qioswindow = 0; + m_view.platformWindow = 0; [m_view removeFromSuperview]; [m_view release]; } @@ -139,7 +139,7 @@ void QIOSWindow::setVisible(bool visible) } else if (!visible && [m_view isActiveWindow]) { // Our window was active/focus window but now hidden, so relinquish // focus to the next possible window in the stack. - NSArray *subviews = m_view.viewController.view.subviews; + NSArray *subviews = m_view.viewController.view.subviews; for (int i = int(subviews.count) - 1; i >= 0; --i) { UIView *view = [subviews objectAtIndex:i]; if (view.hidden) @@ -301,7 +301,7 @@ void QIOSWindow::raiseOrLower(bool raise) if (!isQtApplication()) return; - NSArray *subviews = m_view.superview.subviews; + NSArray *subviews = m_view.superview.subviews; if (subviews.count == 1) return; diff --git a/src/plugins/platforms/ios/quiaccessibilityelement.h b/src/plugins/platforms/ios/quiaccessibilityelement.h index 03abf5407e..6b8efdcede 100644 --- a/src/plugins/platforms/ios/quiaccessibilityelement.h +++ b/src/plugins/platforms/ios/quiaccessibilityelement.h @@ -45,13 +45,12 @@ #ifndef QT_NO_ACCESSIBILITY -@interface QMacAccessibilityElement : UIAccessibilityElement -{} +@interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : UIAccessibilityElement @property (readonly) QAccessible::Id axid; -- (id)initWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view; -+ (QMacAccessibilityElement *)elementWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view; +- (instancetype)initWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view; ++ (instancetype)elementWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view; @end diff --git a/src/plugins/platforms/ios/quiaccessibilityelement.mm b/src/plugins/platforms/ios/quiaccessibilityelement.mm index a26ba61b3c..3154536aad 100644 --- a/src/plugins/platforms/ios/quiaccessibilityelement.mm +++ b/src/plugins/platforms/ios/quiaccessibilityelement.mm @@ -42,20 +42,23 @@ #ifndef QT_NO_ACCESSIBILITY #include "private/qaccessiblecache_p.h" +#include "private/qcore_mac_p.h" + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement); @implementation QMacAccessibilityElement -- (id)initWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view +- (instancetype)initWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view { Q_ASSERT((int)anId < 0); - self = [super initWithAccessibilityContainer: view]; + self = [super initWithAccessibilityContainer:view]; if (self) _axid = anId; return self; } -+ (id)elementWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view ++ (instancetype)elementWithId:(QAccessible::Id)anId withAccessibilityContainer:(id)view { Q_ASSERT(anId); if (!anId) @@ -63,10 +66,10 @@ QAccessibleCache *cache = QAccessibleCache::instance(); - QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *element = cache->elementForId(anId); + QMacAccessibilityElement *element = cache->elementForId(anId); if (!element) { Q_ASSERT(QAccessible::accessibleInterface(anId)); - element = [[self alloc] initWithId:anId withAccessibilityContainer: view]; + element = [[self alloc] initWithId:anId withAccessibilityContainer:view]; cache->insertElement(anId, element); } return element; diff --git a/src/plugins/platforms/ios/quiview.h b/src/plugins/platforms/ios/quiview.h index 3e3c579075..e1d5d5af0c 100644 --- a/src/plugins/platforms/ios/quiview.h +++ b/src/plugins/platforms/ios/quiview.h @@ -53,21 +53,10 @@ QT_END_NAMESPACE @class QIOSViewController; @interface QUIView : UIView -{ - @public - QT_PREPEND_NAMESPACE(QIOSWindow) *m_qioswindow; - @private - QHash m_activeTouches; - UITouch *m_activePencilTouch; - int m_nextTouchId; - - @private - NSMutableArray *m_accessibleElements; -}; - -- (id)initWithQIOSWindow:(QT_PREPEND_NAMESPACE(QIOSWindow) *)window; +- (instancetype)initWithQIOSWindow:(QT_PREPEND_NAMESPACE(QIOSWindow) *)window; - (void)sendUpdatedExposeEvent; - (BOOL)isActiveWindow; +@property (nonatomic, assign) QT_PREPEND_NAMESPACE(QIOSWindow) *platformWindow; @end @interface QUIView (Accessibility) diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index 584dfe9b41..53a4485609 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -55,7 +55,12 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") -@implementation QUIView +@implementation QUIView { + QHash m_activeTouches; + UITouch *m_activePencilTouch; + int m_nextTouchId; + NSMutableArray *m_accessibleElements; +} + (void)load { @@ -82,25 +87,26 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") return [CAEAGLLayer class]; } -- (id)initWithQIOSWindow:(QT_PREPEND_NAMESPACE(QIOSWindow) *)window +- (instancetype)initWithQIOSWindow:(QT_PREPEND_NAMESPACE(QIOSWindow) *)window { if (self = [self initWithFrame:window->geometry().toCGRect()]) { - m_qioswindow = window; - m_accessibleElements = [[NSMutableArray alloc] init]; + self.platformWindow = window; + m_accessibleElements = [[NSMutableArray alloc] init]; } return self; } -- (id)initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Set up EAGL layer CAEAGLLayer *eaglLayer = static_cast(self.layer); eaglLayer.opaque = TRUE; - eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking, - kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; + eaglLayer.drawableProperties = @{ + kEAGLDrawablePropertyRetainedBacking: @(YES), + kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8 + }; if (isQtApplication()) self.hidden = YES; @@ -156,7 +162,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") #ifndef QT_NO_DEBUG_STREAM QString platformWindowDescription; QDebug debug(&platformWindowDescription); - debug.nospace() << "; " << m_qioswindow << ">"; + debug.nospace() << "; " << self.platformWindow << ">"; NSRange lastCharacter = [description rangeOfComposedCharacterSequenceAtIndex:description.length - 1]; [description replaceCharactersInRange:lastCharacter withString:platformWindowDescription.toNSString()]; #endif @@ -210,10 +216,10 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") if (!CGAffineTransformIsIdentity(self.transform)) qWarning() << self << "has a transform set. This is not supported."; - QWindow *window = m_qioswindow->window(); + QWindow *window = self.platformWindow->window(); QRect lastReportedGeometry = qt_window_private(window)->geometry; QRect currentGeometry = QRectF::fromCGRect(self.frame).toRect(); - qCDebug(lcQpaWindow) << m_qioswindow << "new geometry is" << currentGeometry; + qCDebug(lcQpaWindow) << self.platformWindow << "new geometry is" << currentGeometry; QWindowSystemInterface::handleGeometryChange(window, currentGeometry); if (currentGeometry.size() != lastReportedGeometry.size()) { @@ -237,29 +243,29 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") { QRegion region; - if (m_qioswindow->isExposed()) { + if (self.platformWindow->isExposed()) { QSize bounds = QRectF::fromCGRect(self.layer.bounds).toRect().size(); - Q_ASSERT(m_qioswindow->geometry().size() == bounds); - Q_ASSERT(self.hidden == !m_qioswindow->window()->isVisible()); + Q_ASSERT(self.platformWindow->geometry().size() == bounds); + Q_ASSERT(self.hidden == !self.platformWindow->window()->isVisible()); region = QRect(QPoint(), bounds); } - qCDebug(lcQpaWindow) << m_qioswindow << region << "isExposed" << m_qioswindow->isExposed(); - QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); + qCDebug(lcQpaWindow) << self.platformWindow << region << "isExposed" << self.platformWindow->isExposed(); + QWindowSystemInterface::handleExposeEvent(self.platformWindow->window(), region); } - (void)safeAreaInsetsDidChange { - QWindowSystemInterface::handleSafeAreaMarginsChanged(m_qioswindow->window()); + QWindowSystemInterface::handleSafeAreaMarginsChanged(self.platformWindow->window()); } // ------------------------------------------------------------------------- - (BOOL)canBecomeFirstResponder { - return !(m_qioswindow->window()->flags() & Qt::WindowDoesNotAcceptFocus); + return !(self.platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus); } - (BOOL)becomeFirstResponder @@ -280,10 +286,10 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") qImDebug() << self << "became first responder"; } - if (qGuiApp->focusWindow() != m_qioswindow->window()) - QWindowSystemInterface::handleWindowActivated(m_qioswindow->window()); + if (qGuiApp->focusWindow() != self.platformWindow->window()) + QWindowSystemInterface::handleWindowActivated(self.platformWindow->window()); else - qImDebug() << m_qioswindow->window() << "already active, not sending window activation"; + qImDebug() << self.platformWindow->window() << "already active, not sending window activation"; return YES; } @@ -361,7 +367,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { - if (m_qioswindow->window()->flags() & Qt::WindowTransparentForInput) + if (self.platformWindow->window()->flags() & Qt::WindowTransparentForInput) return NO; return [super pointInside:point withEvent:event]; } @@ -378,7 +384,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") for (UITouch *cTouch in cTouches) { QPointF localViewPosition = QPointF::fromCGPoint([cTouch preciseLocationInView:self]); QPoint localViewPositionI = localViewPosition.toPoint(); - QPointF globalScreenPosition = m_qioswindow->mapToGlobal(localViewPositionI) + + QPointF globalScreenPosition = self.platformWindow->mapToGlobal(localViewPositionI) + (localViewPosition - localViewPositionI); qreal pressure = cTouch.force / cTouch.maximumPossibleForce; // azimuth unit vector: +x to the right, +y going downwards @@ -391,7 +397,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") qCDebug(lcQpaTablet) << i << ":" << timeStamp << localViewPosition << pressure << state << "azimuth" << azimuth.dx << azimuth.dy << "angle" << azimuthAngle << "altitude" << cTouch.altitudeAngle << "xTilt" << qBound(-60.0, altitudeAngle * azimuth.dx, 60.0) << "yTilt" << qBound(-60.0, altitudeAngle * azimuth.dy, 60.0); - QWindowSystemInterface::handleTabletEvent(m_qioswindow->window(), timeStamp, localViewPosition, globalScreenPosition, + QWindowSystemInterface::handleTabletEvent(self.platformWindow->window(), timeStamp, localViewPosition, globalScreenPosition, // device, pointerType, buttons QTabletEvent::RotationStylus, QTabletEvent::Pen, state == Qt::TouchPointReleased ? Qt::NoButton : Qt::LeftButton, // pressure, xTilt, yTilt @@ -415,12 +421,12 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") // just map from the local view position to global coordinates. // tvOS: all touches start at the center of the screen and move from there. QPoint localViewPosition = QPointF::fromCGPoint([uiTouch locationInView:self]).toPoint(); - QPoint globalScreenPosition = m_qioswindow->mapToGlobal(localViewPosition); + QPoint globalScreenPosition = self.platformWindow->mapToGlobal(localViewPosition); touchPoint.area = QRectF(globalScreenPosition, QSize(0, 0)); // FIXME: Do we really need to support QTouchDevice::NormalizedPosition? - QSize screenSize = m_qioswindow->screen()->geometry().size(); + QSize screenSize = self.platformWindow->screen()->geometry().size(); touchPoint.normalPosition = QPointF(globalScreenPosition.x() / screenSize.width(), globalScreenPosition.y() / screenSize.height()); @@ -439,7 +445,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") } if (m_activeTouches.isEmpty()) return; - QWindowSystemInterface::handleTouchEvent(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); + QWindowSystemInterface::handleTouchEvent(self.platformWindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); if (!static_cast(self.window).sendingEvent) { // The event is likely delivered as part of delayed touch delivery, via // _UIGestureEnvironmentSortAndSendDelayedTouches, due to one of the two @@ -450,10 +456,10 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") // alert dialog, will fail to recognize. To be on the safe side, we deliver // the event asynchronously. QWindowSystemInterface::handleTouchEvent( - m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); + self.platformWindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); } else { QWindowSystemInterface::handleTouchEvent( - m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); + self.platformWindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); } } @@ -481,8 +487,8 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") #endif } - if (m_qioswindow->shouldAutoActivateWindow() && m_activeTouches.size() == 1) { - QPlatformWindow *topLevel = m_qioswindow; + if (self.platformWindow->shouldAutoActivateWindow() && m_activeTouches.size() == 1) { + QPlatformWindow *topLevel = self.platformWindow; while (QPlatformWindow *p = topLevel->parent()) topLevel = p; if (topLevel->window() != QGuiApplication::focusWindow()) @@ -552,7 +558,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") NSTimeInterval timestamp = event ? event.timestamp : [[NSProcessInfo processInfo] systemUptime]; QIOSIntegration *iosIntegration = static_cast(QGuiApplicationPrivate::platformIntegration()); - QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); + QWindowSystemInterface::handleTouchCancelEvent(self.platformWindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); } - (int)mapPressTypeToKey:(UIPress*)press @@ -580,7 +586,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") int key = [self mapPressTypeToKey:press]; if (key == Qt::Key_unknown) continue; - if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier)) + if (QWindowSystemInterface::handleKeyEvent(self.platformWindow->window(), type, key, Qt::NoModifier)) handled = true; } @@ -634,7 +640,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") - (QWindow *)qwindow { if ([self isKindOfClass:[QUIView class]]) { - if (QT_PREPEND_NAMESPACE(QIOSWindow) *w = static_cast(self)->m_qioswindow) + if (QT_PREPEND_NAMESPACE(QIOSWindow) *w = static_cast(self).platformWindow) return w->window(); } return nil; diff --git a/src/plugins/platforms/ios/quiview_accessibility.mm b/src/plugins/platforms/ios/quiview_accessibility.mm index 69a4d375bd..a3f4156a59 100644 --- a/src/plugins/platforms/ios/quiview_accessibility.mm +++ b/src/plugins/platforms/ios/quiview_accessibility.mm @@ -49,8 +49,9 @@ if (!iface || iface->state().invisible || (iface->text(QAccessible::Name).isEmpty() && iface->text(QAccessible::Value).isEmpty() && iface->text(QAccessible::Description).isEmpty())) return; QAccessible::Id accessibleId = QAccessible::uniqueId(iface); - UIAccessibilityElement *elem = [[QMacAccessibilityElement alloc] initWithId: accessibleId withAccessibilityContainer: self]; - [m_accessibleElements addObject:[elem autorelease]]; + UIAccessibilityElement *elem = [[QT_MANGLE_NAMESPACE(QMacAccessibilityElement) alloc] initWithId:accessibleId withAccessibilityContainer:self]; + [m_accessibleElements addObject:elem]; + [elem release]; } - (void)createAccessibleContainer:(QAccessibleInterface *)iface @@ -73,7 +74,7 @@ if ([m_accessibleElements count]) return; - QWindow *win = m_qioswindow->window(); + QWindow *win = self.platformWindow->window(); QAccessibleInterface *iface = win->accessibleRoot(); if (iface) [self createAccessibleContainer: iface]; diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 9e8af78a8e..cdddf227ac 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -145,22 +145,12 @@ static QWindow *qt_getWindow(const QWidget *widget) return widget ? widget->window()->windowHandle() : 0; } -@interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject { -QMacStylePrivate *mPrivate; -} -- (id)initWithPrivate:(QMacStylePrivate *)priv; -- (void)scrollBarStyleDidChange:(NSNotification *)notification; +@interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject @end QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); @implementation NotificationReceiver -- (id)initWithPrivate:(QMacStylePrivate *)priv -{ - self = [super init]; - mPrivate = priv; - return self; -} - (void)scrollBarStyleDidChange:(NSNotification *)notification { @@ -2285,7 +2275,7 @@ QMacStyle::QMacStyle() Q_D(QMacStyle); QMacAutoReleasePool pool; - d->receiver = [[NotificationReceiver alloc] initWithPrivate:d]; + d->receiver = [[NotificationReceiver alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:d->receiver selector:@selector(scrollBarStyleDidChange:) name:NSPreferredScrollerStyleDidChangeNotification @@ -4513,7 +4503,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge); auto *sv = static_cast(d->cocoaControl(cw)); sv.frame = opt->rect.toCGRect(); - d->drawNSViewInRect(cw, sv, opt->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { + d->drawNSViewInRect(cw, sv, opt->rect, p, w != nullptr, ^(CGContextRef __unused ctx, const CGRect &rect) { [sv drawDividerInRect:rect]; }); } else { @@ -6209,7 +6199,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, switch (ct) { #if QT_CONFIG(spinbox) case CT_SpinBox: - if (const QStyleOptionSpinBox *vopt = qstyleoption_cast(opt)) { + if (qstyleoption_cast(opt)) { const int buttonWidth = 20; // FIXME Use subControlRect() sz += QSize(buttonWidth, -3); } diff --git a/src/printsupport/dialogs/qpagesetupdialog_mac.mm b/src/printsupport/dialogs/qpagesetupdialog_mac.mm index 1e398452f7..a3511fe7b6 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_mac.mm +++ b/src/printsupport/dialogs/qpagesetupdialog_mac.mm @@ -52,16 +52,13 @@ QT_USE_NAMESPACE @class QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate); @interface QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) : NSObject -{ +@end + +@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) { NSPrintInfo *printInfo; } -- (id)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo; -- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout - returnCode:(int)returnCode contextInfo:(void *)contextInfo; -@end -@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) -- (id)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo +- (instancetype)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo { self = [super init]; if (self) { diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm index 854779977c..ed2d0908c4 100644 --- a/src/printsupport/dialogs/qprintdialog_mac.mm +++ b/src/printsupport/dialogs/qprintdialog_mac.mm @@ -77,22 +77,20 @@ QT_USE_NAMESPACE @class QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate); @interface QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) : NSObject -{ +@end + +@implementation QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) { NSPrintInfo *printInfo; } -- (id)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo; -- (void)printPanelDidEnd:(NSPrintPanel *)printPanel - returnCode:(int)returnCode contextInfo:(void *)contextInfo; -@end -@implementation QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) -- (id)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo +- (instancetype)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo { - if (self = [super init]) { + if ((self = [self init])) { printInfo = nsPrintInfo; } return self; } + - (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(int)returnCode contextInfo:(void *)contextInfo { @@ -102,8 +100,8 @@ QT_USE_NAMESPACE QPrinter *printer = dialog->printer(); if (returnCode == NSModalResponseOK) { - PMPrintSession session = static_cast([printInfo PMPrintSession]); - PMPrintSettings settings = static_cast([printInfo PMPrintSettings]); + PMPrintSession session = static_cast(printInfo.PMPrintSession); + PMPrintSettings settings = static_cast(printInfo.PMPrintSettings); UInt32 frompage, topage; PMGetFirstPage(settings, &frompage); @@ -192,6 +190,7 @@ QT_USE_NAMESPACE dialog->done((returnCode == NSModalResponseOK) ? QDialog::Accepted : QDialog::Rejected); } + @end QT_BEGIN_NAMESPACE diff --git a/src/testlib/qxctestlogger.mm b/src/testlib/qxctestlogger.mm index 62fd73070f..9fa9da2fdd 100644 --- a/src/testlib/qxctestlogger.mm +++ b/src/testlib/qxctestlogger.mm @@ -200,7 +200,7 @@ private: [autoreleasepool release]; } -+ (id)defaultTestSuite ++ (QTestLibTests *)defaultTestSuite { return [[QtTestLibTests alloc] initWithName:@"QtTestLib"]; } @@ -255,7 +255,7 @@ static XCTestSuiteRun *s_qtTestSuiteRun = 0; @implementation QtTestLibTest -- (id)initWithInvocation:(NSInvocation *)invocation +- (instancetype)initWithInvocation:(NSInvocation *)invocation { if (self = [super initWithInvocation:invocation]) { // The test object name and function name are used by XCTest after QtTestLib has @@ -322,7 +322,7 @@ QXcodeTestLogger *QXcodeTestLogger::s_currentTestLogger = 0; QXcodeTestLogger::QXcodeTestLogger() : QAbstractTestLogger(0) - , m_testRuns([[NSMutableArray arrayWithCapacity:2] retain]) + , m_testRuns([[NSMutableArray arrayWithCapacity:2] retain]) { Q_ASSERT(!s_currentTestLogger); @@ -383,11 +383,11 @@ static bool isTestFunctionInActiveScope(const char *function) Q_ASSERT(activeScope == Selected); - static NSArray *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain]; + static NSArray *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain]; if ([forcedTests containsObject:[NSString stringWithUTF8String:function]]) return true; - static NSArray *testsInScope = [[testScope componentsSeparatedByString:@","] retain]; + static NSArray *testsInScope = [[testScope componentsSeparatedByString:@","] retain]; bool inScope = [testsInScope containsObject:[NSString stringWithFormat:@"%s/%s", QTestResult::currentTestObjectName(), function]]; diff --git a/src/testlib/qxctestlogger_p.h b/src/testlib/qxctestlogger_p.h index 1b641f18af..8baa5aa27f 100644 --- a/src/testlib/qxctestlogger_p.h +++ b/src/testlib/qxctestlogger_p.h @@ -90,7 +90,7 @@ private: void pushTestRunForTest(XCTest *test, bool start); XCTestRun *popTestRun(); - NSMutableArray *m_testRuns; + NSMutableArray *m_testRuns; static QXcodeTestLogger *s_currentTestLogger; }; diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm index e9407fd903..4ebf7a37f9 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm @@ -101,9 +101,9 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) @implementation TestAXObject -- (id) initWithAXUIElementRef: (AXUIElementRef) ref { +- (instancetype)initWithAXUIElementRef:(AXUIElementRef)ref { - if ( self = [super init] ) { + if ((self = [super init])) { reference = ref; } return self; diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h index be716aa582..4a145a729f 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h @@ -28,10 +28,5 @@ #import -@interface TestMouseMovedNSView : NSView { - NSPoint mouseMovedPoint_; - BOOL wasAcceptingMouseEvents_; - NSTrackingRectTag trackingRect_; - NSTrackingArea* trackingArea_; -} +@interface TestMouseMovedNSView : NSView @end diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m index 65b42dbb2f..20a3fcc513 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m @@ -28,9 +28,14 @@ #import "TestMouseMovedNSView.h" -@implementation TestMouseMovedNSView +@implementation TestMouseMovedNSView { + NSPoint mouseMovedPoint_; + BOOL wasAcceptingMouseEvents_; + NSTrackingRectTag trackingRect_; + NSTrackingArea* trackingArea_; +} -- (id)initWithFrame:(NSRect)frame +- (instancetype)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) @@ -40,13 +45,13 @@ - (void)viewDidMoveToWindow { - trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; + trackingArea_ = [[NSTrackingArea alloc] initWithRect:self.bounds options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; [self addTrackingArea:trackingArea_]; } - (void)viewWillMoveToWindow:(NSWindow *)newWindow { - if ([self window] && trackingArea_) + if (self.window && trackingArea_) [self removeTrackingArea:trackingArea_]; } @@ -54,7 +59,7 @@ { [super updateTrackingAreas]; [self removeTrackingArea: trackingArea_]; - trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; + trackingArea_ = [[NSTrackingArea alloc] initWithRect:self.bounds options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; [self addTrackingArea:trackingArea_]; } @@ -64,20 +69,20 @@ - (void)mouseEntered:(NSEvent *)theEvent { wasAcceptingMouseEvents_ = [[self window] acceptsMouseMovedEvents]; - [[self window] setAcceptsMouseMovedEvents:YES]; - [[self window] makeFirstResponder:self]; + [self.window setAcceptsMouseMovedEvents:YES]; + [self.window makeFirstResponder:self]; } - (void)mouseExited:(NSEvent *)theEvent { - [[self window] setAcceptsMouseMovedEvents:wasAcceptingMouseEvents_]; + [self.window setAcceptsMouseMovedEvents:wasAcceptingMouseEvents_]; [self setNeedsDisplay:YES]; [self displayIfNeeded]; } -(void)mouseMoved:(NSEvent *)pTheEvent { - mouseMovedPoint_ = [self convertPoint:[pTheEvent locationInWindow] fromView:nil]; + mouseMovedPoint_ = [self convertPoint:pTheEvent.locationInWindow fromView:nil]; [self setNeedsDisplay:YES]; [self displayIfNeeded]; } @@ -88,7 +93,7 @@ NSRectFill(dirtyRect); NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext]; - CGContextRef cgContextRef = (CGContextRef) [nsGraphicsContext graphicsPort]; + CGContextRef cgContextRef = nsGraphicsContext.CGContext; CGContextSetRGBStrokeColor(cgContextRef, 0, 0, 0, .5); CGContextSetLineWidth(cgContextRef, 1.0); diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm index 9cf06391ca..8b05b64a1e 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm @@ -83,7 +83,7 @@ int main(int argc, char **argv) w.resize(300, 300); w.setWindowTitle("QMacCocoaViewContainer"); NSRect r = NSMakeRect(0, 0, 100, 100); - NSView *view = [[TestMouseMovedNSView alloc] initWithFrame: r]; + NSView *view = [[TestMouseMovedNSView alloc] initWithFrame:r]; QMacCocoaViewContainer *nativeChild = new QMacCocoaViewContainer(view, &w); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(nativeChild); diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 805ef0d7c2..e6218e48ac 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -50,31 +50,30 @@ } @end -@interface AppDelegate : NSObject { +@interface AppDelegate : NSObject +@end + +@implementation AppDelegate { QGuiApplication *m_app; QWindow *m_window; } -- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv; -- (void) applicationWillFinishLaunching: (NSNotification *)notification; -- (void)applicationWillTerminate:(NSNotification *)notification; -@end - -@implementation AppDelegate -- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv +- (instancetype)initWithArgc:(int)argc argv:(const char **)argv { - m_app = new QGuiApplication(argc, const_cast(argv)); + if ((self = [self init])) { + m_app = new QGuiApplication(argc, const_cast(argv)); + } return self; } -- (void) applicationWillFinishLaunching: (NSNotification *)notification +- (void)applicationWillFinishLaunching:(NSNotification *)notification { Q_UNUSED(notification); // Create the NSWindow NSRect frame = NSMakeRect(500, 500, 500, 500); - NSWindow* window = [[NSWindow alloc] initWithContentRect:frame - styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask + NSWindow *window = [[NSWindow alloc] initWithContentRect:frame + styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:NO]; @@ -100,7 +99,7 @@ childWindow->setGeometry(50, 50, 100, 100); NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)]; - [(NSView*)childWindow->winId() addSubview:textField]; + [reinterpret_cast(childWindow->winId()) addSubview:textField]; [contentView addSubview:reinterpret_cast(m_window->winId())]; @@ -125,10 +124,7 @@ int main(int argc, const char *argv[]) { // Create NSApplicaiton with delgate - NSApplication *app =[NSApplication sharedApplication]; + NSApplication *app = [NSApplication sharedApplication]; app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv]; - return NSApplicationMain (argc, argv); + return NSApplicationMain(argc, argv); } - - - -- cgit v1.2.3