diff options
author | Neil Hodgson <nyamatongwe@gmail.com> | 2017-06-07 16:23:06 +1000 |
---|---|---|
committer | Neil Hodgson <nyamatongwe@gmail.com> | 2017-06-07 16:23:06 +1000 |
commit | 7401309e8c5e8caa1e8ce4d1872cb70030fc7f64 (patch) | |
tree | b81231fd2812837015b5d74a10ccd5a7365ad326 | |
parent | 74977b1699cdf34bf8146b65a6daf7c48b288ee5 (diff) | |
download | scintilla-mirror-7401309e8c5e8caa1e8ce4d1872cb70030fc7f64.tar.gz |
Using modern Objective C literals and indexing.
-rw-r--r-- | cocoa/InfoBar.mm | 2 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 8 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 29 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 25 |
4 files changed, 31 insertions, 33 deletions
diff --git a/cocoa/InfoBar.mm b/cocoa/InfoBar.mm index 6004e15cc..5ca010af8 100644 --- a/cocoa/InfoBar.mm +++ b/cocoa/InfoBar.mm @@ -166,7 +166,7 @@ static float BarFontSize = 10.0; [mZoomPopup addItemWithTitle: NSLocalizedStringFromTable(DefaultScaleMenuLabels[count], @"ZoomValues", nil)]; id currentItem = [mZoomPopup itemAtIndex: count]; if (DefaultScaleMenuFactors[count] != 0.0) - [currentItem setRepresentedObject: [NSNumber numberWithFloat: DefaultScaleMenuFactors[count]]]; + [currentItem setRepresentedObject: @(DefaultScaleMenuFactors[count])]; } [mZoomPopup selectItemAtIndex: DefaultScaleMenuSelectedItemIndex]; diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 238e1c741..aaf714e52 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -1315,7 +1315,7 @@ void Window::SetTitle(const char* s) if ([idWin isKindOfClass: [NSWindow class]]) { NSWindow* win = idWin; - NSString* sTitle = [NSString stringWithUTF8String:s]; + NSString* sTitle = @(s); [win setTitle:sTitle]; } } @@ -1829,7 +1829,7 @@ void ListBoxImpl::RegisterImage(int type, const char* xpm_data) { XPM xpm(xpm_data); NSImage* img = ImageFromXPM(&xpm); - [images setObject:img forKey:@(type)]; + images[@(type)] = img; } void ListBoxImpl::RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) @@ -1837,7 +1837,7 @@ void ListBoxImpl::RegisterRGBAImage(int type, int width, int height, const unsig CGImageRef imageRef = ImageCreateFromRGBA(width, height, pixelsImage, false); NSImage *img = [[NSImage alloc] initWithCGImage:imageRef size: NSZeroSize]; CGImageRelease(imageRef); - [images setObject:img forKey:@(type)]; + images[@(type)] = img; } void ListBoxImpl::ClearRegisteredImages() @@ -1860,7 +1860,7 @@ NSString* ListBoxImpl::TextForRow(NSInteger row) const char* textString = ld.GetString(row); NSString* sTitle; if (unicodeMode) - sTitle = [NSString stringWithUTF8String:textString]; + sTitle = @(textString); else sTitle = [NSString stringWithCString:textString encoding:NSWindowsCP1252StringEncoding]; return sTitle; diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index afa05a186..eb871f448 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -179,7 +179,7 @@ static const KeyToCommand macMapDefault[] = // A gold to slightly redder gradient to match other applications CGColorRef colGold = CGColorCreateGenericRGB(1.0, 1.0, 0, 1.0); CGColorRef colGoldRed = CGColorCreateGenericRGB(1.0, 0.8, 0, 1.0); - self.colors = [NSArray arrayWithObjects:(__bridge id)colGoldRed, (__bridge id)colGold, nil]; + self.colors = @[(__bridge id)colGoldRed, (__bridge id)colGold]; CGColorRelease(colGoldRed); CGColorRelease(colGold); @@ -249,7 +249,7 @@ const CGFloat paddingHighlightY = 2; ptText.y -= flipper * height / 2.0; [CATransaction begin]; - [CATransaction setValue:[NSNumber numberWithFloat:0.0] forKey:kCATransactionAnimationDuration]; + [CATransaction setValue:@0.0f forKey:kCATransactionAnimationDuration]; self.bounds = CGRectMake(0,0, width, height); self.position = ptText; if (bounce) { @@ -265,8 +265,8 @@ const CGFloat paddingHighlightY = 2; animBounce.duration = 0.15; animBounce.autoreverses = YES; animBounce.removedOnCompletion = NO; - animBounce.fromValue = [NSNumber numberWithFloat: 1.0]; - animBounce.toValue = [NSNumber numberWithFloat: 1.25]; + animBounce.fromValue = @1.0f; + animBounce.toValue = @1.25f; if (self.retaining) { @@ -278,14 +278,14 @@ const CGFloat paddingHighlightY = 2; animFade.duration = 0.1; animFade.beginTime = 0.4; animFade.removedOnCompletion = NO; - animFade.fromValue = [NSNumber numberWithFloat: 1.0]; - animFade.toValue = [NSNumber numberWithFloat: 0.0]; + animFade.fromValue = @1.0f; + animFade.toValue = @0.0f; CAAnimationGroup *group = [CAAnimationGroup animation]; [group setDuration:0.5]; group.removedOnCompletion = NO; group.fillMode = kCAFillModeForwards; - [group setAnimations:[NSArray arrayWithObjects:animBounce, animFade, nil]]; + [group setAnimations:@[animBounce, animFade]]; [self addAnimation:group forKey:@"animateFound"]; } @@ -1182,7 +1182,7 @@ void ScintillaCocoa::AddToPopUp(const char *label, int cmd, bool enabled) item = [NSMenuItem separatorItem]; } else { item = [[NSMenuItem alloc] init]; - [item setTitle: [NSString stringWithUTF8String: label]]; + [item setTitle: @(label)]; } [item setTarget: menu]; [item setAction: @selector(handleCommand:)]; @@ -1580,8 +1580,8 @@ void ScintillaCocoa::SetPasteboardData(NSPasteboard* board, const SelectionText CFStringRef cfsVal = CFStringFromString(selectedText.Data(), selectedText.Length(), encoding); NSArray *pbTypes = selectedText.rectangular ? - [NSArray arrayWithObjects: NSStringPboardType, ScintillaRecPboardType, nil] : - [NSArray arrayWithObjects: NSStringPboardType, nil]; + @[NSStringPboardType, ScintillaRecPboardType] : + @[NSStringPboardType]; [board declareTypes:pbTypes owner:nil]; if (selectedText.rectangular) @@ -1603,9 +1603,8 @@ void ScintillaCocoa::SetPasteboardData(NSPasteboard* board, const SelectionText */ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selectedText) { - NSArray* supportedTypes = [NSArray arrayWithObjects: ScintillaRecPboardType, - NSStringPboardType, - nil]; + NSArray* supportedTypes = @[ScintillaRecPboardType, + NSStringPboardType]; NSString *bestType = [board availableTypeFromArray: supportedTypes]; NSString* data = [board stringForType: bestType]; @@ -1676,7 +1675,7 @@ NSString *ScintillaCocoa::RangeTextAsString(NSRange rangePositions) const { static_cast<int>(NSMaxRange(rangePositions))); if (IsUnicodeMode()) { - return [NSString stringWithUTF8String: text.c_str()]; + return @(text.c_str()); } else { @@ -2612,7 +2611,7 @@ void ScintillaCocoa::ShowFindIndicatorForRange(NSRange charRange, BOOL retaining const long style = static_cast<unsigned char>(styleByte); std::vector<char> bufferFontName(WndProc(SCI_STYLEGETFONT, style, 0) + 1); WndProc(SCI_STYLEGETFONT, style, (sptr_t)&bufferFontName[0]); - layerFindIndicator.sFont = [NSString stringWithUTF8String: &bufferFontName[0]]; + layerFindIndicator.sFont = @(&bufferFontName[0]); layerFindIndicator.fontSize = WndProc(SCI_STYLEGETSIZEFRACTIONAL, style, 0) / (float)SC_FONT_SIZE_MULTIPLIER; diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index abc7346f8..26e04e649 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -177,7 +177,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) long cursType = owner.backend->WndProc(SCI_GETMARGINCURSORN, i, 0); long width =owner.backend->WndProc(SCI_GETMARGINWIDTHN, i, 0); NSCursor *cc = cursorFromEnum(static_cast<Window::Cursor>(cursType)); - [currentCursors replaceObjectAtIndex:i withObject: cc]; + currentCursors[i] = cc; marginRect.origin.x = x; marginRect.size.width = width; [self addCursorRect: marginRect cursor: cc]; @@ -217,8 +217,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) trackingArea = nil; mMarkedTextRange = NSMakeRange(NSNotFound, 0); - [self registerForDraggedTypes: [NSArray arrayWithObjects: - NSStringPboardType, ScintillaRecPboardType, NSFilenamesPboardType, nil]]; + [self registerForDraggedTypes: @[NSStringPboardType, ScintillaRecPboardType, NSFilenamesPboardType]]; // Set up accessibility in the text role if ([self respondsToSelector: @selector(setAccessibilityElement:)]) @@ -434,7 +433,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) std::string text([mOwner message: SCI_TARGETASUTF8] + 1, 0); [mOwner message: SCI_TARGETASUTF8 wParam: 0 lParam: reinterpret_cast<sptr_t>(&text[0])]; text = FixInvalidUTF8(text); - NSString *result = [NSString stringWithUTF8String: text.c_str()]; + NSString *result = @(text.c_str()); NSMutableAttributedString *asResult = [[NSMutableAttributedString alloc] initWithString:result]; const NSRange rangeAS = NSMakeRange(0, [asResult length]); @@ -444,7 +443,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) std::string fontName([mOwner message: SCI_STYLEGETFONT wParam:style lParam:0] + 1, 0); [mOwner message: SCI_STYLEGETFONT wParam:style lParam:(sptr_t)&fontName[0]]; const CGFloat fontSize = [mOwner message: SCI_STYLEGETSIZEFRACTIONAL wParam:style] / 100.0f; - NSString *sFontName = [NSString stringWithUTF8String: fontName.c_str()]; + NSString *sFontName = @(fontName.c_str()); NSFont *font = [NSFont fontWithName:sFontName size:fontSize]; [asResult addAttribute:NSFontAttributeName value:font range:rangeAS]; @@ -720,7 +719,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) { if (mMarkedTextRange.length == 0) mOwner.backend->KeyboardInput(theEvent); - NSArray* events = [NSArray arrayWithObject: theEvent]; + NSArray* events = @[theEvent]; [self interpretKeyEvents: events]; } @@ -1692,7 +1691,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context { mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) &buffer[0]); - result = [NSString stringWithUTF8String: buffer.c_str()]; + result = @(buffer.c_str()); } catch (...) { @@ -1734,7 +1733,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context { mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) &buffer[0]); - result = [NSString stringWithUTF8String: buffer.c_str()]; + result = @(buffer.c_str()); } catch (...) { @@ -1929,7 +1928,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context value[1] = value[0]; unsigned rawRed; - [[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawRed]; + [[NSScanner scannerWithString: @(value)] scanHexInt: &rawRed]; value[0] = static_cast<char>([fromHTML characterAtIndex: index++]); if (longVersion) @@ -1938,7 +1937,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context value[1] = value[0]; unsigned rawGreen; - [[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawGreen]; + [[NSScanner scannerWithString: @(value)] scanHexInt: &rawGreen]; value[0] = static_cast<char>([fromHTML characterAtIndex: index++]); if (longVersion) @@ -1947,7 +1946,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context value[1] = value[0]; unsigned rawBlue; - [[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawBlue]; + [[NSScanner scannerWithString: @(value)] scanHexInt: &rawBlue]; long color = (rawBlue << 16) + (rawGreen << 8) + rawRed; mBackend->WndProc(property, parameter, color); @@ -2009,7 +2008,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context - (NSString*) getStringProperty: (int) property parameter: (long) parameter { const char* rawValue = (const char*) mBackend->WndProc(property, parameter, 0); - return [NSString stringWithUTF8String: rawValue]; + return @(rawValue); } //-------------------------------------------------------------------------------------------------- @@ -2033,7 +2032,7 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context { const char* rawName = [name UTF8String]; const char* result = (const char*) mBackend->WndProc(SCI_SETPROPERTY, (sptr_t) rawName, 0); - return [NSString stringWithUTF8String: result]; + return @(result); } //-------------------------------------------------------------------------------------------------- |