Commit bb2e02ab authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

winemac.drv: Use ObjC literals.

parent 8943fcbc
......@@ -78,8 +78,7 @@ int macdrv_err_on;
*/
static NSString* WineLocalizedString(unsigned int stringID)
{
NSNumber* key = [NSNumber numberWithUnsignedInt:stringID];
return [(NSDictionary*)localized_strings objectForKey:key];
return ((NSDictionary*)localized_strings)[@(stringID)];
}
......@@ -135,11 +134,13 @@ static NSString* WineLocalizedString(unsigned int stringID)
{
if (self == [WineApplicationController class])
{
NSDictionary* defaults = [NSDictionary dictionaryWithObjectsAndKeys:
@"", @"NSQuotedKeystrokeBinding",
@"", @"NSRepeatCountBinding",
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
nil];
NSDictionary<NSString *, id> *defaults =
@{
@"NSQuotedKeystrokeBinding" : @"",
@"NSRepeatCountBinding" : @"",
@"ApplePressAndHoldEnabled" : @NO
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)])
......@@ -539,7 +540,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
CGRect* rect;
NSScreen* screen;
primaryScreenHeight = NSHeight([[screens objectAtIndex:0] frame]);
primaryScreenHeight = NSHeight([screens[0] frame]);
primaryScreenHeightValid = TRUE;
size = count * sizeof(CGRect);
......@@ -577,7 +578,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
// We don't use -primaryScreenHeight here so there's no chance of having
// out-of-date cached info. This method is called infrequently enough
// that getting the screen height each time is not prohibitively expensive.
rect->origin.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - NSMaxY(*rect);
rect->origin.y = NSMaxY([[NSScreen screens][0] frame]) - NSMaxY(*rect);
}
- (WineWindow*) frontWineWindow
......@@ -835,7 +836,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
NSNumber* displayIDKey = [NSNumber numberWithUnsignedInt:displayID];
CGDisplayModeRef originalMode;
originalMode = (CGDisplayModeRef)[originalDisplayModes objectForKey:displayIDKey];
originalMode = (CGDisplayModeRef)originalDisplayModes[displayIDKey];
if (originalMode && [self mode:mode matchesMode:originalMode])
{
......@@ -866,7 +867,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
CGDisplayModeRef currentMode;
NSArray* modes;
currentMode = CGDisplayModeRetain((CGDisplayModeRef)[latentDisplayModes objectForKey:displayIDKey]);
currentMode = CGDisplayModeRetain((CGDisplayModeRef)latentDisplayModes[displayIDKey]);
if (!currentMode)
currentMode = CGDisplayCopyDisplayMode(displayID);
if (!currentMode) // Invalid display ID
......@@ -1013,11 +1014,11 @@ static NSString* WineLocalizedString(unsigned int stringID)
- (void) setCursor
{
NSDictionary* frame = [cursorFrames objectAtIndex:cursorFrame];
CGImageRef cgimage = (CGImageRef)[frame objectForKey:@"image"];
NSDictionary* frame = cursorFrames[cursorFrame];
CGImageRef cgimage = (CGImageRef)frame[@"image"];
CGSize size = CGSizeMake(CGImageGetWidth(cgimage), CGImageGetHeight(cgimage));
NSImage* image = [[NSImage alloc] initWithCGImage:cgimage size:NSSizeFromCGSize(cgsize_mac_from_win(size))];
CFDictionaryRef hotSpotDict = (CFDictionaryRef)[frame objectForKey:@"hotSpot"];
CFDictionaryRef hotSpotDict = (CFDictionaryRef)frame[@"hotSpot"];
CGPoint hotSpot;
if (!CGPointMakeWithDictionaryRepresentation(hotSpotDict, &hotSpot))
......@@ -1039,8 +1040,8 @@ static NSString* WineLocalizedString(unsigned int stringID)
cursorFrame = 0;
[self setCursor];
frame = [cursorFrames objectAtIndex:cursorFrame];
duration = [[frame objectForKey:@"duration"] doubleValue];
frame = cursorFrames[cursorFrame];
duration = [frame[@"duration"] doubleValue];
date = [[theTimer fireDate] dateByAddingTimeInterval:duration];
[cursorTimer setFireDate:date];
}
......@@ -1059,8 +1060,8 @@ static NSString* WineLocalizedString(unsigned int stringID)
{
if ([frames count] > 1)
{
NSDictionary* frame = [frames objectAtIndex:0];
NSTimeInterval duration = [[frame objectForKey:@"duration"] doubleValue];
NSDictionary* frame = frames[0];
NSTimeInterval duration = [frame[@"duration"] doubleValue];
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:duration];
self.cursorTimer = [[[NSTimer alloc] initWithFireDate:date
interval:1000000
......@@ -2140,7 +2141,7 @@ static NSString* WineLocalizedString(unsigned int stringID)
latentDisplayModes = [[NSMutableDictionary alloc] init];
for (displayID in modesToRealize)
{
CGDisplayModeRef mode = (CGDisplayModeRef)[modesToRealize objectForKey:displayID];
CGDisplayModeRef mode = (CGDisplayModeRef)modesToRealize[displayID];
[self setMode:mode forDisplay:[displayID unsignedIntValue]];
}
......@@ -2295,7 +2296,7 @@ static void PerformRequest(void *info)
dispatch_sync(controller->requestsManipQueue, ^{
if ([controller->requests count])
{
block = (dispatch_block_t)[[controller->requests objectAtIndex:0] retain];
block = (dispatch_block_t)[controller->requests[0] retain];
[controller->requests removeObjectAtIndex:0];
}
else
......
......@@ -35,8 +35,7 @@
static int owned_change_count = -1;
static int change_count = -1;
static NSArray* BitmapOutputTypes;
static NSDictionary* BitmapOutputTypeMap;
static NSDictionary<NSString *, NSNumber *> *BitmapOutputTypeMap;
static dispatch_once_t BitmapOutputTypesInitOnce;
static NSString* const OwnershipSentinel = @"org.winehq.wine.winemac.pasteboard-ownership-sentinel";
......@@ -94,19 +93,14 @@ CFArrayRef macdrv_copy_pasteboard_types(CFTypeRef pasteboard)
__block CFArrayRef ret = NULL;
dispatch_once(&BitmapOutputTypesInitOnce, ^{
NSArray* bitmapFileTypes = [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedInteger:NSBitmapImageFileTypeTIFF],
[NSNumber numberWithUnsignedInteger:NSBitmapImageFileTypePNG],
[NSNumber numberWithUnsignedInteger:NSBitmapImageFileTypeBMP],
[NSNumber numberWithUnsignedInteger:NSBitmapImageFileTypeGIF],
[NSNumber numberWithUnsignedInteger:NSBitmapImageFileTypeJPEG],
nil];
BitmapOutputTypes = [[NSArray alloc] initWithObjects:@"public.tiff", @"public.png",
@"com.microsoft.bmp", @"com.compuserve.gif", @"public.jpeg", nil];
BitmapOutputTypeMap = [[NSDictionary alloc] initWithObjects:bitmapFileTypes
forKeys:BitmapOutputTypes];
BitmapOutputTypeMap =
@{
@"public.tiff" : @(NSBitmapImageFileTypeTIFF),
@"public.png" : @(NSBitmapImageFileTypePNG),
@"com.microsoft.bmp" : @(NSBitmapImageFileTypeBMP),
@"com.compuserve.gif" : @(NSBitmapImageFileTypeGIF),
@"public.jpeg" : @(NSBitmapImageFileTypeJPEG),
};
});
OnMainThread(^{
......@@ -125,7 +119,7 @@ CFArrayRef macdrv_copy_pasteboard_types(CFTypeRef pasteboard)
if ([types firstObjectCommonWithArray:[NSBitmapImageRep imageTypes]] ||
[types firstObjectCommonWithArray:[NSBitmapImageRep imagePasteboardTypes]])
{
NSMutableArray* newTypes = [BitmapOutputTypes mutableCopy];
NSMutableArray<NSString *> *newTypes = [[BitmapOutputTypeMap allKeys] mutableCopy];
[newTypes removeObjectsInArray:types];
types = [types arrayByAddingObjectsFromArray:newTypes];
[newTypes release];
......@@ -161,11 +155,11 @@ CFDataRef macdrv_copy_pasteboard_data(CFTypeRef pasteboard, CFStringRef type)
{
NSPasteboard* local_pb = pb;
if (!local_pb) local_pb = [NSPasteboard generalPasteboard];
if ([local_pb availableTypeFromArray:[NSArray arrayWithObject:(NSString*)type]])
if ([local_pb availableTypeFromArray:@[(NSString*)type]])
ret = [[local_pb dataForType:(NSString*)type] copy];
else
{
NSNumber* bitmapType = [BitmapOutputTypeMap objectForKey:(NSString*)type];
NSNumber* bitmapType = BitmapOutputTypeMap[(NSString*)type];
if (bitmapType)
{
NSArray* reps = [NSBitmapImageRep imageRepsWithPasteboard:local_pb];
......@@ -199,7 +193,7 @@ void macdrv_clear_pasteboard(macdrv_window w)
@try
{
NSPasteboard* pb = [NSPasteboard generalPasteboard];
owned_change_count = [pb declareTypes:[NSArray arrayWithObject:OwnershipSentinel]
owned_change_count = [pb declareTypes:@[OwnershipSentinel]
owner:window];
[window.queue discardEventsMatchingMask:event_mask_for_type(LOST_PASTEBOARD_OWNERSHIP)
forWindow:window];
......@@ -230,7 +224,7 @@ int macdrv_set_pasteboard_data(CFStringRef type, CFDataRef data, macdrv_window w
@try
{
NSPasteboard* pb = [NSPasteboard generalPasteboard];
NSInteger change_count = [pb addTypes:[NSArray arrayWithObject:(NSString*)type]
NSInteger change_count = [pb addTypes:@[(NSString*)type]
owner:window];
if (change_count)
{
......
......@@ -230,7 +230,7 @@ static void scale_rect_for_retina_mode(int mode, CGRect *cursorClipRect)
for (i = 0; i < warpsFinished; i++)
{
WarpRecord* warpRecord = [warpRecords objectAtIndex:0];
WarpRecord* warpRecord = warpRecords[0];
deltaX -= warpRecord.to.x - warpRecord.from.x;
deltaY -= warpRecord.to.y - warpRecord.from.y;
[warpRecords removeObjectAtIndex:0];
......
......@@ -73,14 +73,14 @@ int macdrv_get_displays(struct macdrv_display** displays, int* count)
NSUInteger i;
for (i = 0; i < num_screens; i++)
{
NSScreen* screen = [screens objectAtIndex:i];
NSScreen* screen = screens[i];
NSRect frame = [screen frame];
NSRect visible_frame = [screen visibleFrame];
if (i == 0)
primary_frame = frame;
disps[i].displayID = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
disps[i].displayID = [[screen deviceDescription][@"NSScreenNumber"] unsignedIntValue];
convert_display_rect(&disps[i].frame, frame, primary_frame);
convert_display_rect(&disps[i].work_frame, visible_frame,
primary_frame);
......
......@@ -162,8 +162,8 @@ static const OSType WineHotKeySignature = 'Wine';
for (hotKeyMacID in hotKeysByMacID)
{
NSDictionary* hotKeyDict = [hotKeysByMacID objectForKey:hotKeyMacID];
EventHotKeyRef hotKeyRef = [[hotKeyDict objectForKey:WineHotKeyCarbonRefKey] pointerValue];
NSDictionary<NSString *, id> *hotKeyDict = hotKeysByMacID[hotKeyMacID];
EventHotKeyRef hotKeyRef = [hotKeyDict[WineHotKeyCarbonRefKey] pointerValue];
UnregisterEventHotKey(hotKeyRef);
}
[hotKeysByMacID release];
......@@ -269,7 +269,7 @@ static const OSType WineHotKeySignature = 'Wine';
index = 0;
while (index < [events count])
{
MacDrvEvent* event = [events objectAtIndex:index];
MacDrvEvent* event = events[index];
if (event_mask_for_type(event->event->type) & mask)
{
[[event retain] autorelease];
......@@ -369,15 +369,15 @@ static const OSType WineHotKeySignature = 'Wine';
- (BOOL) postHotKeyEvent:(UInt32)hotKeyNumber time:(double)time
{
NSDictionary* hotKeyDict = [hotKeysByMacID objectForKey:[NSNumber numberWithUnsignedInt:hotKeyNumber]];
NSDictionary<NSString *, id> *hotKeyDict = hotKeysByMacID[@(hotKeyNumber)];
if (hotKeyDict)
{
macdrv_event* event;
event = macdrv_create_event(HOTKEY_PRESS, nil);
event->hotkey_press.vkey = [[hotKeyDict objectForKey:WineHotKeyVkeyKey] unsignedIntValue];
event->hotkey_press.mod_flags = [[hotKeyDict objectForKey:WineHotKeyModFlagsKey] unsignedIntValue];
event->hotkey_press.keycode = [[hotKeyDict objectForKey:WineHotKeyKeyCodeKey] unsignedIntValue];
event->hotkey_press.vkey = [hotKeyDict[WineHotKeyVkeyKey] unsignedIntValue];
event->hotkey_press.mod_flags = [hotKeyDict[WineHotKeyModFlagsKey] unsignedIntValue];
event->hotkey_press.keycode = [hotKeyDict[WineHotKeyKeyCodeKey] unsignedIntValue];
event->hotkey_press.time_ms = [[WineApplicationController sharedController] ticksForEventTime:time];
[self postEvent:event];
......@@ -408,14 +408,12 @@ static const OSType WineHotKeySignature = 'Wine';
- (void) unregisterHotKey:(unsigned int)vkey modFlags:(unsigned int)modFlags
{
NSNumber* vkeyNumber = [NSNumber numberWithUnsignedInt:vkey];
NSNumber* modFlagsNumber = [NSNumber numberWithUnsignedInt:modFlags];
NSArray* winIDPair = [NSArray arrayWithObjects:vkeyNumber, modFlagsNumber, nil];
NSDictionary* hotKeyDict = [hotKeysByWinID objectForKey:winIDPair];
NSArray<NSNumber *> *winIDPair = @[@(vkey), @(modFlags)];
NSDictionary<NSString *, id> *hotKeyDict = hotKeysByWinID[winIDPair];
if (hotKeyDict)
{
EventHotKeyRef hotKeyRef = [[hotKeyDict objectForKey:WineHotKeyCarbonRefKey] pointerValue];
NSNumber* macID = [hotKeyDict objectForKey:WineHotKeyMacIDKey];
EventHotKeyRef hotKeyRef = [hotKeyDict[WineHotKeyCarbonRefKey] pointerValue];
NSNumber* macID = hotKeyDict[WineHotKeyMacIDKey];
UnregisterEventHotKey(hotKeyRef);
[hotKeysByMacID removeObjectForKey:macID];
......@@ -428,13 +426,10 @@ static const OSType WineHotKeySignature = 'Wine';
static EventHandlerRef handler;
static UInt32 hotKeyNumber;
OSStatus status;
NSNumber* vkeyNumber;
NSNumber* modFlagsNumber;
NSArray* winIDPair;
NSArray<NSNumber *> *winIDPair;
EventHotKeyID hotKeyID;
EventHotKeyRef hotKeyRef;
NSNumber* macIDNumber;
NSDictionary* hotKeyDict;
NSDictionary<NSString *, id> *hotKeyDict;
if (!handler)
{
......@@ -453,10 +448,8 @@ static const OSType WineHotKeySignature = 'Wine';
if (!hotKeysByWinID && !(hotKeysByWinID = [[NSMutableDictionary alloc] init]))
return MACDRV_HOTKEY_FAILURE;
vkeyNumber = [NSNumber numberWithUnsignedInt:vkey];
modFlagsNumber = [NSNumber numberWithUnsignedInt:modFlags];
winIDPair = [NSArray arrayWithObjects:vkeyNumber, modFlagsNumber, nil];
if ([hotKeysByWinID objectForKey:winIDPair])
winIDPair = @[@(vkey), @(modFlags)];
if (hotKeysByWinID[winIDPair])
return MACDRV_HOTKEY_ALREADY_REGISTERED;
hotKeyID.signature = WineHotKeySignature;
......@@ -472,16 +465,16 @@ static const OSType WineHotKeySignature = 'Wine';
return MACDRV_HOTKEY_FAILURE;
}
macIDNumber = [NSNumber numberWithUnsignedInt:hotKeyID.id];
hotKeyDict = [NSDictionary dictionaryWithObjectsAndKeys:
macIDNumber, WineHotKeyMacIDKey,
vkeyNumber, WineHotKeyVkeyKey,
modFlagsNumber, WineHotKeyModFlagsKey,
[NSNumber numberWithUnsignedInt:keyCode], WineHotKeyKeyCodeKey,
[NSValue valueWithPointer:hotKeyRef], WineHotKeyCarbonRefKey,
nil];
[hotKeysByMacID setObject:hotKeyDict forKey:macIDNumber];
[hotKeysByWinID setObject:hotKeyDict forKey:winIDPair];
hotKeyDict =
@{
WineHotKeyMacIDKey : @(hotKeyID.id),
WineHotKeyVkeyKey : @(vkey),
WineHotKeyModFlagsKey : @(modFlags),
WineHotKeyKeyCodeKey : @(keyCode),
WineHotKeyCarbonRefKey : [NSValue valueWithPointer:hotKeyRef]
};
hotKeysByMacID[@(hotKeyID.id)] = hotKeyDict;
hotKeysByWinID[winIDPair] = hotKeyDict;
return MACDRV_HOTKEY_SUCCESS;
}
......@@ -497,7 +490,7 @@ void OnMainThread(dispatch_block_t block)
@autoreleasepool
{
NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
WineEventQueue* queue = [threadDict objectForKey:WineEventQueueThreadDictionaryKey];
WineEventQueue* queue = threadDict[WineEventQueueThreadDictionaryKey];
dispatch_semaphore_t semaphore = NULL;
__block BOOL finished;
......@@ -561,7 +554,7 @@ macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler)
{
NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
WineEventQueue* queue = [threadDict objectForKey:WineEventQueueThreadDictionaryKey];
WineEventQueue* queue = threadDict[WineEventQueueThreadDictionaryKey];
if (!queue)
{
queue = [[[WineEventQueue alloc] initWithEventHandler:handler] autorelease];
......
......@@ -1032,9 +1032,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
window->resizable = wf->resizable;
window->_lastDisplayTime = [[NSDate distantPast] timeIntervalSinceReferenceDate];
[window registerForDraggedTypes:[NSArray arrayWithObjects:(NSString*)kUTTypeData,
(NSString*)kUTTypeContent,
nil]];
[window registerForDraggedTypes:@[(NSString*)kUTTypeData, (NSString*)kUTTypeContent]];
contentView = [[[WineContentView alloc] initWithFrame:NSZeroRect] autorelease];
if (!contentView)
......@@ -1437,7 +1435,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
limit = MIN(origChildren.count, count);
for (start = 0; start < limit; start++)
{
if ([origChildren objectAtIndex:start] != [childWindows objectAtIndex:start])
if (origChildren[start] != childWindows[start])
break;
}
......@@ -1445,12 +1443,12 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
// are in the desired order.
for (i = start; i < count; i++)
{
WineWindow* child = [childWindows objectAtIndex:i];
WineWindow* child = childWindows[i];
[self removeChildWindow:child];
}
for (i = start; i < count; i++)
{
WineWindow* child = [childWindows objectAtIndex:i];
WineWindow* child = childWindows[i];
[self addChildWindow:child ordered:NSWindowAbove];
}
}
......@@ -1507,7 +1505,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
for (i = 0; i < count; i++)
{
WineWindow* child = [latentChildWindows objectAtIndex:i];
WineWindow* child = latentChildWindows[i];
if ([child isVisible] && (self.floating || !child.floating))
{
if (child.latentParentWindow == self)
......@@ -1612,7 +1610,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
for (i = lowIndex + 1; i < highIndex; i++)
{
NSInteger interveningWindowNumber = [[windowNumbers objectAtIndex:i] integerValue];
NSInteger interveningWindowNumber = [windowNumbers[i] integerValue];
NSWindow* interveningWindow = [NSApp windowWithWindowNumber:interveningWindowNumber];
if ([interveningWindow isKindOfClass:[WineWindow class]])
return FALSE;
......@@ -1693,7 +1691,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
if (index == 0)
*ancestorOfOther = nil;
else
*ancestorOfOther = [otherAncestors objectAtIndex:index - 1];
*ancestorOfOther = otherAncestors[index - 1];
return;
}
}
......@@ -2234,8 +2232,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
if (!_lastDisplayID)
return nil;
NSMutableDictionary* displayIDToDisplayLinkMap = [self displayIDToDisplayLinkMap];
return [displayIDToDisplayLinkMap objectForKey:[NSNumber numberWithUnsignedInt:_lastDisplayID]];
return [self displayIDToDisplayLinkMap][@(_lastDisplayID)];
}
- (void) checkWineDisplayLink
......@@ -2248,7 +2245,7 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
screen = nil;
#endif
NSNumber* displayIDNumber = [screen.deviceDescription objectForKey:@"NSScreenNumber"];
NSNumber* displayIDNumber = screen.deviceDescription[@"NSScreenNumber"];
CGDirectDisplayID displayID = [displayIDNumber unsignedIntValue];
if (displayID == _lastDisplayID)
return;
......@@ -2257,12 +2254,12 @@ static CVReturn WineDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTi
if (_lastDisplayID)
{
WineDisplayLink* link = [displayIDToDisplayLinkMap objectForKey:[NSNumber numberWithUnsignedInt:_lastDisplayID]];
WineDisplayLink* link = displayIDToDisplayLinkMap[@(_lastDisplayID)];
[link removeWindow:self];
}
if (displayID)
{
WineDisplayLink* link = [displayIDToDisplayLinkMap objectForKey:displayIDNumber];
WineDisplayLink* link = displayIDToDisplayLinkMap[displayIDNumber];
if (!link)
{
link = [[[WineDisplayLink alloc] initWithDisplayID:displayID] autorelease];
......@@ -3740,9 +3737,9 @@ void macdrv_set_view_superview(macdrv_view v, macdrv_view s, macdrv_window w, ma
NSUInteger index = [subviews indexOfObjectIdenticalTo:view];
if (!prev && !next && index == [subviews count] - 1)
return;
if (prev && index + 1 < [subviews count] && [subviews objectAtIndex:index + 1] == prev)
if (prev && index + 1 < [subviews count] && subviews[index + 1] == prev)
return;
if (!prev && next && index > 0 && [subviews objectAtIndex:index - 1] == next)
if (!prev && next && index > 0 && subviews[index - 1] == next)
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment