Clean up our Objective-C usage

- 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 <jake.petroules@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Jake Petroules 2018-02-01 10:32:07 -08:00 committed by Tor Arne Vestbø
parent 34017a8c5a
commit ba871065e0
62 changed files with 600 additions and 689 deletions

View File

@ -499,7 +499,7 @@ bool QFseventsFileSystemWatcherEngine::startStream()
DEBUG() << "Starting stream with paths" << watchingState.watchedPaths.keys();
NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchingState.watchedPaths.size()];
NSMutableArray<NSString *> *pathsToWatch = [NSMutableArray<NSString *> arrayWithCapacity:watchingState.watchedPaths.size()];
for (PathRefCounts::const_iterator i = watchingState.watchedPaths.begin(), ei = watchingState.watchedPaths.end(); i != ei; ++i)
[pathsToWatch addObject:i.key().toNSString()];

View File

@ -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

View File

@ -58,18 +58,18 @@
QT_USE_NAMESPACE
@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject {
QStack<CFStringRef> m_runLoopModes;
}
@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker);
@implementation RunLoopModeTracker
@implementation RunLoopModeTracker {
QStack<CFStringRef> 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();
}

View File

@ -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<QByteArray> 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<QByteArray> QMacPasteboardMimeTiff::convertFromMime(const QString &mime, Q
QImage img = qvariant_cast<QImage>(variant);
NSDictionary *props = @{
static_cast<NSString *>(kCGImagePropertyPixelWidth) : [NSNumber numberWithInt:img.width()],
static_cast<NSString *>(kCGImagePropertyPixelHeight) : [NSNumber numberWithInt:img.height()]
static_cast<NSString *>(kCGImagePropertyPixelWidth): @(img.width()),
static_cast<NSString *>(kCGImagePropertyPixelHeight): @(img.height())
};
CGImageDestinationAddImage(imageDestination, qt_mac_toCGImage(img), static_cast<CFDictionaryRef>(props));

View File

@ -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<NSString *> *map1 = reinterpret_cast<NSArray<NSString *> *>(obj1);
NSArray<NSString *> *map2 = reinterpret_cast<NSArray<NSString *> *>(obj2);
NSArray<NSString *> *languages = reinterpret_cast<NSArray<NSString *> *>(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<CFArrayRef> familyNames = availableFamilyNames();
QCFType<CFArrayRef> familyNames = CTFontManagerCopyAvailableFontFamilyNames();
for (NSString *familyName in familyNames.as<const NSArray *>())
QPlatformFontDatabase::registerFontFamily(QString::fromNSString(familyName));
@ -220,7 +206,7 @@ bool QCoreTextFontDatabase::populateFamilyAliases()
if (m_hasPopulatedAliases)
return false;
QCFType<CFArrayRef> familyNames = availableFamilyNames();
QCFType<CFArrayRef> familyNames = CTFontManagerCopyAvailableFontFamilyNames();
for (NSString *familyName in familyNames.as<const NSArray *>()) {
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<NSString *> *languages = [defaults stringArrayForKey:@"AppleLanguages"];
NSDictionary *fallbackDict = [NSDictionary dictionaryWithContentsOfFile: @"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreText.framework/Resources/DefaultFontFallbacks.plist"];
NSDictionary<NSString *, id> *fallbackDict = [NSDictionary<NSString *, id> 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<NSArray *>(item)
sortedArrayUsingFunction:languageMapSort context:languages];
for (NSArray<NSString *> *map in langs)
fallbackList.append(familyNameFromPostScriptName([map objectAtIndex:1]));
}
else if ([item isKindOfClass: [NSString class]])
fallbackList.append(familyNameFromPostScriptName(item));

View File

@ -62,33 +62,29 @@ extern "C" { // Otherwise it won't find CWKeychain* symbols at link time
#include <ifaddrs.h>
@interface QT_MANGLE_NAMESPACE(QNSListener) : NSObject <CWEventDelegate>
{
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<NSString *> *thisSsidarray = [prefNetDict valueForKey:@"SSID_STR"];
for (NSString *ssidkey in thisSsidarray) {
QString thisSsid = QString::fromNSString(ssidkey);
if(!userProfiles.contains(thisSsid)) {

View File

@ -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<QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *> *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);

View File

@ -257,12 +257,12 @@ bool shouldBeIgnored(QAccessibleInterface *interface)
return false;
}
NSArray *unignoredChildren(QAccessibleInterface *interface)
NSArray<QMacAccessibilityElement *> *unignoredChildren(QAccessibleInterface *interface)
{
int numKids = interface->childCount();
// qDebug() << "Children for: " << axid << iface << " are: " << numKids;
NSMutableArray *kids = [NSMutableArray arrayWithCapacity:numKids];
NSMutableArray<QMacAccessibilityElement *> *kids = [NSMutableArray<QMacAccessibilityElement *> 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;

View File

@ -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

View File

@ -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<NSString *> *)accessibilityAttributeNames {
static NSArray<NSString *> *defaultAttributes = [@[
NSAccessibilityRoleAttribute,
NSAccessibilityRoleDescriptionAttribute,
NSAccessibilitySubroleAttribute,
@ -196,35 +192,36 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
NSAccessibilitySizeAttribute,
NSAccessibilityTitleAttribute,
NSAccessibilityDescriptionAttribute,
NSAccessibilityEnabledAttribute,
nil];
}
NSAccessibilityEnabledAttribute
] retain];
NSMutableArray *attributes = [[NSMutableArray alloc] initWithCapacity : [defaultAttributes count]];
[attributes addObjectsFromArray : defaultAttributes];
QAccessibleInterface *iface = QAccessible::accessibleInterface(axid);
if (!iface || !iface->isValid())
return defaultAttributes;
NSMutableArray<NSString *> *attributes = [[NSMutableArray<NSString *> 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];

View File

@ -89,8 +89,7 @@
#import <AppKit/AppKit.h>
@interface QT_MANGLE_NAMESPACE(QNSApplication) : NSApplication {
}
@interface QT_MANGLE_NAMESPACE(QNSApplication) : NSApplication
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSApplication);

View File

@ -92,18 +92,12 @@
@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader);
@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject <NSApplicationDelegate> {
bool startedQuit;
NSMenu *dockMenu;
NSObject <NSApplicationDelegate> *reflectionDelegate;
bool inLaunch;
}
+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate;
@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject <NSApplicationDelegate>
+ (instancetype)sharedDelegate;
- (void)setDockMenu:(NSMenu *)newMenu;
- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate;
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
- (void) removeAppleEventHandlers;
- (bool) inLaunch;
- (void)setReflectionDelegate:(NSObject<NSApplicationDelegate> *)oldDelegate;
- (void)removeAppleEventHandlers;
- (bool)inLaunch;
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate);

View File

@ -73,7 +73,6 @@
#import "qcocoaapplicationdelegate.h"
#import "qnswindowdelegate.h"
#import "qcocoamenuloader.h"
#include "qcocoaintegration.h"
#include <qevent.h>
@ -86,7 +85,12 @@
QT_USE_NAMESPACE
@implementation QCocoaApplicationDelegate
@implementation QCocoaApplicationDelegate {
bool startedQuit;
NSMenu *dockMenu;
NSObject <NSApplicationDelegate> *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;
}

View File

@ -50,7 +50,14 @@
QT_USE_NAMESPACE
@interface QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) : NSObject<NSWindowDelegate, QNSPanelDelegate>
{
- (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];

View File

@ -81,23 +81,6 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)
: NSObject<NSOpenSavePanelDelegate>
{
@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<QFileDialogOptions> 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;
- (id)initWithAcceptMode:
(const QString &)selectFile
options:(SharedPointerFileDialogOptions)options
helper:(QCocoaFileDialogHelper *)helper
int mReturnCode;
SharedPointerFileDialogOptions mOptions;
QString *mCurrentSelection;
QStringList *mNameFilterDropDownList;
QStringList *mSelectedNameFilter;
}
- (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<QUrl> 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<NSURL *> *array = [mOpenPanel URLs];
for (NSURL *url in array) {
QString path = QString::fromNSString(url.path).normalized(QString::NormalizationForm_C);
result << QUrl::fromLocalFile(path);
}
return result;

View File

@ -76,7 +76,15 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
@class QT_MANGLE_NAMESPACE(QNSFontPanelDelegate);
@interface QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) : NSObject<NSWindowDelegate, QNSPanelDelegate>
{
- (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;
}

View File

@ -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<NSMutableArray *>(qt_mac_QStringListToNSMutableArrayVoid(qstrlist)); }
QStringList qt_mac_NSArrayToQStringList(NSArray<NSString *> *nsarray);
NSMutableArray<NSString *> *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);

View File

@ -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<NSString *> *array)
{
QStringList result;
NSArray *array = static_cast<NSArray *>(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<NSString *> *qt_mac_QStringListToNSMutableArray(const QStringList &list)
{
NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()];
for (int i=0; i<list.size(); ++i){
[result addObject:list[i].toNSString()];
}
NSMutableArray<NSString *> *result = [NSMutableArray<NSString *> 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;

View File

@ -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<NSScreen *> *scrs = [NSScreen screens];
NSMutableArray<NSScreen *> *screens = [NSMutableArray<NSScreen *> arrayWithArray:scrs];
if ([screens count] == 0)
if ([NSScreen mainScreen])
[screens addObject:[NSScreen mainScreen]];

View File

@ -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<NSMenuItem *>([itemArray objectAtIndex:i]);
for (NSMenuItem *item in [m_nativeMenu itemArray]) {
if ([item isSeparatorItem]) {
QCocoaMenuItem *cocoaItem = reinterpret_cast<QCocoaMenuItem *>([item tag]);
if (cocoaItem)

View File

@ -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;
}
}

View File

@ -55,19 +55,6 @@
#include <QtCore/private/qcore_mac_p.h>
@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<NSMenuItem *> *)mergeable;
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuLoader);

View File

@ -50,7 +50,19 @@
#include <QtCore/qcoreapplication.h>
#include <QtGui/private/qguiapplication_p.h>
@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<NSMenuItem *>(sender);
if (item == quitItem) {
@ -363,9 +375,10 @@
}
}
- (NSArray*) mergeable
- (NSArray<NSMenuItem *> *)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];
}

View File

@ -66,7 +66,7 @@ QCocoaScreen::~QCocoaScreen()
NSScreen *QCocoaScreen::nativeScreen() const
{
NSArray *screens = [NSScreen screens];
NSArray<NSScreen *> *screens = [NSScreen screens];
// Stale reference, screen configuration has changed
if (m_screenIndex < 0 || (NSUInteger)m_screenIndex >= [screens count])

View File

@ -93,31 +93,16 @@ QT_USE_NAMESPACE
@class QT_MANGLE_NAMESPACE(QNSImageView);
@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject <NSUserNotificationCenterDelegate>
{
@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<QCocoaMenu *>(menu);
if (menu && [m_sys->item->menu->nsMenu() numberOfItems] > 0) {
m_sys->item.menu = static_cast<QCocoaMenu *>(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;
}
-(id)initWithSysTray:(QCocoaSystemTrayIcon *)sys
@synthesize menu = menu;
@synthesize icon = icon;
- (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];

View File

@ -77,26 +77,24 @@
#include <Carbon/Carbon.h>
@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);
}

View File

@ -42,52 +42,22 @@
#include <AppKit/AppKit.h>
#include <QtCore/QPointer>
#include <QtCore/QSet>
#include <QtGui/QImage>
#include <QtGui/QAccessible>
#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 <NSTextInputClient> {
QPointer<QCocoaWindow> m_platformWindow;
NSTrackingArea *m_trackingArea;
Qt::MouseButtons m_buttons;
Qt::MouseButtons m_acceptedMouseDowns;
Qt::MouseButtons m_frameStrutButtons;
QString m_composingText;
QPointer<QObject> 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<quint32> m_acceptedKeyDowns;
bool m_updateRequested;
}
@interface QT_MANGLE_NAMESPACE(QNSView) : NSView <NSTextInputClient>
@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

View File

@ -51,7 +51,11 @@
#include <qpa/qwindowsysteminterface.h>
#include <QtGui/QTextFormat>
#include <QtCore/QDebug>
#include <QtCore/QPointer>
#include <QtCore/QSet>
#include <QtCore/qsysinfo.h>
#include <QtGui/QAccessible>
#include <QtGui/QImage>
#include <private/qguiapplication_p.h>
#include <private/qcoregraphics_p.h>
#include <private/qwindow_p.h>
@ -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<QCocoaWindow> m_platformWindow;
NSTrackingArea *m_trackingArea;
Qt::MouseButtons m_buttons;
Qt::MouseButtons m_acceptedMouseDowns;
Qt::MouseButtons m_frameStrutButtons;
QString m_composingText;
QPointer<QObject> 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<quint32> 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<NSString *> *)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<NSString *> *supportedTypes = [NSMutableArray<NSString *> 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()];

View File

@ -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:

View File

@ -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<NSWindow *> *windows = [NSMutableArray<NSWindow *> 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];
}
];

View File

@ -41,20 +41,16 @@
#define QNSWINDOWDELEGATE_H
#include <AppKit/AppKit.h>
#include <QtCore/private/qcore_mac_p.h>
#include "qcocoawindow.h"
QT_BEGIN_NAMESPACE
class QCocoaWindow;
QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(QNSWindowDelegate) : NSObject <NSWindowDelegate>
{
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);

View File

@ -39,20 +39,23 @@
#include "qnswindowdelegate.h"
#include "qcocoahelpers.h"
#include "qcocoawindow.h"
#include <QDebug>
#include <QtCore/private/qcore_mac_p.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qwindowsysteminterface.h>
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;
}

View File

@ -41,8 +41,6 @@
#include "../../qiosfiledialog.h"
@interface QIOSImagePickerController : UIImagePickerController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
QIOSFileDialog *m_fileDialog;
}
- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog;
@interface QIOSImagePickerController : UIImagePickerController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
- (instancetype)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog;
@end

View File

@ -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<QUrl>() << fileUrl);
emit m_fileDialog->accept();
}

View File

@ -46,11 +46,11 @@
#include <QtGui/QGuiApplication>
@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<NSString *> *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<NSString *> *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<NSDictionary<NSString *, id> *> array];
return;
}
mimeData->deleteLater();
NSMutableDictionary *pbItem = [NSMutableDictionary dictionaryWithCapacity:mimeData->formats().size()];
NSMutableDictionary<NSString *, id> *pbItem = [NSMutableDictionary<NSString *, id> 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

View File

@ -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<NSString *> *arguments = [[NSProcessInfo processInfo] arguments];
int argc = arguments.count;
char **argv = new char*[argc];

View File

@ -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 <UIGestureRecognizerDelegate> {
@private
QT_PREPEND_NAMESPACE(QIOSInputContext) *m_context;
}
@interface QIOSKeyboardListener : UIGestureRecognizer <UIGestureRecognizerDelegate>
@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<UIWindow *> *applicationWindows = [[UIApplication sharedApplication] windows];
static QHash<UIWindow *, UIWindowLevel> originalWindowLevels;
for (UIWindow *window in applicationWindows) {
if (keyboardScrollIsActive && !originalWindowLevels.contains(window))

View File

@ -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<UIScreen *> *screens = [[[UIScreen screens] mutableCopy] autorelease];
if (![screens containsObject:mainScreen]) {
// Fallback for iOS 7.1 (QTBUG-42345)
[screens insertObject:mainScreen atIndex:0];

View File

@ -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<UIMenuItem *> *menuItemArray = [NSMutableArray<UIMenuItem *> 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 <UIPickerViewDelegate, UIPickerViewDataSource> {
QIOSMenuItemList m_visibleMenuItems;
QPointer<QObject> m_focusObjectWithPickerView;
NSInteger m_selectedRow;
}
@interface QUIPickerView : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource>
@property(retain) UIToolbar *toolbar;
@end
@implementation QUIPickerView
@implementation QUIPickerView {
QIOSMenuItemList m_visibleMenuItems;
QPointer<QObject> 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];

View File

@ -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

View File

@ -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;

View File

@ -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 <CAAnimationDelegate> {
#else
@interface QIOSHandleLayer : CALayer {
#endif
CALayer *_handleCursorLayer;
CALayer *_handleKnobLayer;
Qt::Edge _selectionEdge;
}
@interface QIOSHandleLayer : CALayer <CAAnimationDelegate>
@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 <UIGestureRecognizerDelegate> {
@public
@interface QIOSLoupeRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate>
@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;

View File

@ -49,16 +49,8 @@ class QIOSInputContext;
QT_END_NAMESPACE
@interface QIOSTextInputResponder : UIResponder <UITextInputTraits, UIKeyInput, UITextInput>
{
@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;

View File

@ -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<UIKeyCommand *> *)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<UIKeyCommand *> *)keyCommands
{
// Since keyCommands is called for every key
// press/release, we cache the result
static dispatch_once_t once;
static NSMutableArray *array;
static NSMutableArray<UIKeyCommand *> *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<UIKeyCommand *> 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<UITextSelectionRect *> *)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<UITextSelectionRect *> 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<QFont>(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

View File

@ -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

View File

@ -56,12 +56,8 @@
// -------------------------------------------------------------------------
@interface QIOSViewController () {
@public
QPointer<QT_PREPEND_NAMESPACE(QIOSScreen)> m_screen;
BOOL m_updatingProperties;
QMetaObject::Connection m_focusWindowChangeConnection;
}
@interface QIOSViewController ()
@property (nonatomic, assign) QPointer<QT_PREPEND_NAMESPACE(QIOSScreen)> 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

View File

@ -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<UIView *> *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<UIView *> *subviews = m_view.superview.subviews;
if (subviews.count == 1)
return;

View File

@ -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

View File

@ -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;

View File

@ -53,21 +53,10 @@ QT_END_NAMESPACE
@class QIOSViewController;
@interface QUIView : UIView
{
@public
QT_PREPEND_NAMESPACE(QIOSWindow) *m_qioswindow;
@private
QHash<UITouch *, QWindowSystemInterface::TouchPoint> 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)

View File

@ -55,7 +55,12 @@
Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
@implementation QUIView
@implementation QUIView {
QHash<UITouch *, QWindowSystemInterface::TouchPoint> m_activeTouches;
UITouch *m_activePencilTouch;
int m_nextTouchId;
NSMutableArray<UIAccessibilityElement *> *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<UIAccessibilityElement *> 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<CAEAGLLayer *>(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<QWindowSystemInterface::SynchronousDelivery>(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values());
QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(self.platformWindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values());
if (!static_cast<QUIWindow *>(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<QWindowSystemInterface::AsynchronousDelivery>(
m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values());
self.platformWindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values());
} else {
QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(
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<QIOSIntegration *>(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<QUIView *>(self)->m_qioswindow)
if (QT_PREPEND_NAMESPACE(QIOSWindow) *w = static_cast<QUIView *>(self).platformWindow)
return w->window();
}
return nil;

View File

@ -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];

View File

@ -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<NSSplitView *>(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<const QStyleOptionSpinBox *>(opt)) {
if (qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
const int buttonWidth = 20; // FIXME Use subControlRect()
sz += QSize(buttonWidth, -3);
}

View File

@ -52,16 +52,13 @@ QT_USE_NAMESPACE
@class QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate);
@interface QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) : NSObject
{
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
@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) {
NSPrintInfo *printInfo;
}
- (instancetype)initWithNSPrintInfo:(NSPrintInfo *)nsPrintInfo
{
self = [super init];
if (self) {

View File

@ -77,22 +77,20 @@ QT_USE_NAMESPACE
@class QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate);
@interface QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) : NSObject
{
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
@implementation QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) {
NSPrintInfo *printInfo;
}
- (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<PMPrintSession>([printInfo PMPrintSession]);
PMPrintSettings settings = static_cast<PMPrintSettings>([printInfo PMPrintSettings]);
PMPrintSession session = static_cast<PMPrintSession>(printInfo.PMPrintSession);
PMPrintSettings settings = static_cast<PMPrintSettings>(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

View File

@ -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<XCTestRun *> 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<NSString *> *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain];
if ([forcedTests containsObject:[NSString stringWithUTF8String:function]])
return true;
static NSArray *testsInScope = [[testScope componentsSeparatedByString:@","] retain];
static NSArray<NSString *> *testsInScope = [[testScope componentsSeparatedByString:@","] retain];
bool inScope = [testsInScope containsObject:[NSString stringWithFormat:@"%s/%s",
QTestResult::currentTestObjectName(), function]];

View File

@ -90,7 +90,7 @@ private:
void pushTestRunForTest(XCTest *test, bool start);
XCTestRun *popTestRun();
NSMutableArray *m_testRuns;
NSMutableArray<XCTestRun *> *m_testRuns;
static QXcodeTestLogger *s_currentTestLogger;
};

View File

@ -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;

View File

@ -28,10 +28,5 @@
#import <AppKit/AppKit.h>
@interface TestMouseMovedNSView : NSView {
NSPoint mouseMovedPoint_;
BOOL wasAcceptingMouseEvents_;
NSTrackingRectTag trackingRect_;
NSTrackingArea* trackingArea_;
}
@interface TestMouseMovedNSView : NSView
@end

View File

@ -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);

View File

@ -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);

View File

@ -50,31 +50,30 @@
}
@end
@interface AppDelegate : NSObject <NSApplicationDelegate> {
@interface AppDelegate : NSObject <NSApplicationDelegate>
@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<char **>(argv));
if ((self = [self init])) {
m_app = new QGuiApplication(argc, const_cast<char **>(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<NSView *>(childWindow->winId()) addSubview:textField];
[contentView addSubview:reinterpret_cast<NSView *>(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);
}