Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix misc MacVim warnings #1303

Merged
merged 8 commits into from
Oct 6, 2022
Merged
2 changes: 2 additions & 0 deletions src/MacVim/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
<string>public.utf8-plain-text</string>
</array>
<key>NSRequiredContext</key>
<dict></dict>
Expand All @@ -1298,6 +1299,7 @@
<string>MacVim</string>
<key>NSSendTypes</key>
<array>
<string>public.file-url</string>
<string>NSFilenamesPboardType</string>
</array>
<key>NSUserData</key>
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMAppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
- (IBAction)showVimHelp:(id)sender withCmd:(NSString *)cmd;
- (IBAction)showVimHelp:(id)sender;
- (IBAction)checkForUpdates:(id)sender;
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_13
- (IBAction)zoomAll:(id)sender;
#endif
- (IBAction)stayInFront:(id)sender;
- (IBAction)stayInBack:(id)sender;
- (IBAction)stayLevelNormal:(id)sender;
Expand Down
35 changes: 20 additions & 15 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ + (void)initialize

[[NSUserDefaults standardUserDefaults] registerDefaults:dict];

NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
NSArray *types = [NSArray arrayWithObject:NSPasteboardTypeString];
[NSApp registerServicesMenuSendTypes:types returnTypes:types];

// NOTE: Set the current directory to user's home directory, otherwise it
Expand Down Expand Up @@ -638,7 +638,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:
if ([alert runModal] != NSAlertFirstButtonReturn)
reply = NSTerminateCancel;

if ([[alert suppressionButton] state] == NSOnState) {
if ([[alert suppressionButton] state] == NSControlStateValueOn) {
[[NSUserDefaults standardUserDefaults]
setBool:YES forKey:MMSuppressTerminationAlertKey];
}
Expand Down Expand Up @@ -1315,11 +1315,19 @@ - (IBAction)checkForUpdates:(id)sender
#endif
}

// Note that the zoomAll method does not appear to be called in modern macOS versions
// as NSApplication just handles it and directly calls each window's zoom:. It's
// difficult to trace through history to see when that happened as it's not really
// documented, so we are leaving this method around in case on older macOS
// versions it's useful.
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_13
- (IBAction)zoomAll:(id)sender
{
// TODO ychin: check on 10.13 etc. This was depreacated post 10.14.
ASLogDebug(@"Zoom all windows");
[NSApp makeWindowsPerform:@selector(performZoom:) inOrder:YES];
}
#endif

- (IBAction)stayInFront:(id)sender
{
Expand All @@ -1346,7 +1354,7 @@ - (IBAction)coreTextButtonClicked:(id)sender
{
ASLogDebug(@"Toggle CoreText renderer");
NSInteger renderer = MMRendererDefault;
BOOL enable = ([sender state] == NSOnState);
BOOL enable = ([sender state] == NSControlStateValueOn);

if (enable) {
renderer = MMRendererCoreText;
Expand Down Expand Up @@ -1587,8 +1595,8 @@ @implementation MMAppController (MMServices)
- (void)openSelection:(NSPasteboard *)pboard userData:(NSString *)userData
error:(NSString **)error
{
if (![[pboard types] containsObject:NSStringPboardType]) {
ASLogNotice(@"Pasteboard contains no NSStringPboardType");
if (![[pboard types] containsObject:NSPasteboardTypeString]) {
ASLogNotice(@"Pasteboard contains no NSPasteboardTypeString");
return;
}

Expand All @@ -1600,13 +1608,13 @@ - (void)openSelection:(NSPasteboard *)pboard userData:(NSString *)userData

if (openInCurrentWindow && (vc = [self topmostVimController])) {
[vc sendMessage:AddNewTabMsgID data:nil];
[vc dropString:[pboard stringForType:NSStringPboardType]];
[vc dropString:[pboard stringForType:NSPasteboardTypeString]];
} else {
// Save the text, open a new window, and paste the text when the next
// window opens. (If this is called several times in a row, then all
// but the last call may be ignored.)
if (openSelectionString) [openSelectionString release];
openSelectionString = [[pboard stringForType:NSStringPboardType] copy];
openSelectionString = [[pboard stringForType:NSPasteboardTypeString] copy];

[self newWindow:self];
}
Expand All @@ -1615,13 +1623,13 @@ - (void)openSelection:(NSPasteboard *)pboard userData:(NSString *)userData
- (void)openFile:(NSPasteboard *)pboard userData:(NSString *)userData
error:(NSString **)error
{
if (![[pboard types] containsObject:NSStringPboardType]) {
ASLogNotice(@"Pasteboard contains no NSStringPboardType");
if (![[pboard types] containsObject:NSPasteboardTypeString]) {
ASLogNotice(@"Pasteboard contains no NSPasteboardTypeString");
return;
}

// TODO: Parse multiple filenames and create array with names.
NSString *string = [pboard stringForType:NSStringPboardType];
NSString *string = [pboard stringForType:NSPasteboardTypeString];
string = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
string = [string stringByStandardizingPath];
Expand All @@ -1647,12 +1655,9 @@ - (void)openFile:(NSPasteboard *)pboard userData:(NSString *)userData
- (void)newFileHere:(NSPasteboard *)pboard userData:(NSString *)userData
error:(NSString **)error
{
if (![[pboard types] containsObject:NSFilenamesPboardType]) {
ASLogNotice(@"Pasteboard contains no NSFilenamesPboardType");
NSArray<NSString *> *filenames = extractPasteboardFilenames(pboard);
if (filenames == nil || filenames.count == 0)
return;
}

NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
NSString *path = [filenames lastObject];

BOOL dirIndicator;
Expand Down
8 changes: 5 additions & 3 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ - (int)lookupColorWithKey:(NSString *)key
NSColor *col = [NSColor performSelector:NSSelectorFromString(obj)];
if (col) {
CGFloat r, g, b, a;
col = [col colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
col = [col colorUsingColorSpace:NSColorSpace.sRGBColorSpace];
[col getRed:&r green:&g blue:&b alpha:&a];
return (((int)(r*255+.5f) & 0xff) << 16)
+ (((int)(g*255+.5f) & 0xff) << 8)
Expand Down Expand Up @@ -1473,9 +1473,9 @@ - (BOOL)selectedTextToPasteboard:(byref NSPasteboard *)pboard

NSString *string = [[NSString alloc] initWithUTF8String:(char*)str];

NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
NSArray *types = [NSArray arrayWithObject:NSPasteboardTypeString];
[pboard declareTypes:types owner:nil];
BOOL ok = [pboard setString:string forType:NSStringPboardType];
BOOL ok = [pboard setString:string forType:NSPasteboardTypeString];

[string release];
vim_free(str);
Expand Down Expand Up @@ -2502,12 +2502,14 @@ - (void)handleScrollbarEvent:(NSData *)data
case NSScrollerIncrementPage:
value += (size > 2 ? size - 2 : 1);
break;
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
case NSScrollerDecrementLine:
--value;
break;
case NSScrollerIncrementLine:
++value;
break;
#endif
case NSScrollerKnob:
isStillDragging = YES;
// fall through ...
Expand Down
13 changes: 12 additions & 1 deletion src/MacVim/MMCoreTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
@class MMTextViewHelper;


@interface MMCoreTextView : NSView <NSTextInput> {
@interface MMCoreTextView : NSView <
NSTextInput
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
, NSFontChanging
#endif
>
{
// From MMTextStorage
int maxRows, maxColumns;
NSColor *defaultBackgroundColor;
Expand Down Expand Up @@ -51,6 +57,11 @@

- (id)initWithFrame:(NSRect)frame;

//
// NSFontChanging methods
//
- (void)changeFont:(id)sender;

//
// MMTextStorage methods
//
Expand Down
94 changes: 47 additions & 47 deletions src/MacVim/MMCoreTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ - (id)initWithFrame:(NSRect)frame
helper = [[MMTextViewHelper alloc] init];
[helper setTextView:self];

[self registerForDraggedTypes:[NSArray arrayWithObjects:
NSFilenamesPboardType, NSStringPboardType, nil]];
[self registerForDraggedTypes:@[getPasteboardFilenamesType(),
NSPasteboardTypeString]];

ligatures = NO;

Expand Down Expand Up @@ -565,51 +565,6 @@ - (void)updateCmdlineRow
[self setCmdlineRow: [[[self vimController] objectForVimStateKey:@"cmdline_row"] intValue]];
}

/// Set Vim's cmdline row number. This will mark the relevant parts to be repainted
/// if the row number has changed as we are pinning the cmdline to the bottom,
/// because otherwise we will have a gap that doesn't get cleared and leaves artifacts.
///
/// @param row The row (0-indexed) of the current cmdline in Vim.
- (void)setCmdlineRow:(int)row
{
const BOOL newAlignCmdLineToBottom = [[NSUserDefaults standardUserDefaults] boolForKey:MMCmdLineAlignBottomKey];

if (newAlignCmdLineToBottom != alignCmdLineToBottom) {
// The user settings has changed (usually through the settings panel). Just update everything.
alignCmdLineToBottom = newAlignCmdLineToBottom;
cmdlineRow = row;
[self setNeedsDisplay:YES];
return;
}

if (row != cmdlineRow) {
// The cmdline row has changed. Need to redraw the necessary parts if we
// are configured to pin cmdline to the bottom.
if (alignCmdLineToBottom) {
// Since we are changing the cmdline row, we need to repaint the
// parts where the gap changed. Just for simplicity, we repaint
// both the old/new cmdline rows and the row above them. This way
// the gap in between the top and bottom aligned rows should be
// touched in the repainting and cleared to bg.
[self setNeedsDisplayFromRow:cmdlineRow-1
column:grid.cols
toRow:cmdlineRow
column:grid.cols];

// Have to do this between the two calls as cmdlineRow would affect
// the calculation in them.
cmdlineRow = row;

[self setNeedsDisplayFromRow:cmdlineRow-1
column:grid.cols
toRow:cmdlineRow
column:grid.cols];
} else {
cmdlineRow = row;
}
}
}

- (void)setImControl:(BOOL)enable
{
[helper setImControl:enable];
Expand Down Expand Up @@ -1400,6 +1355,51 @@ - (CTLineRef)lineForCharacterString:(NSString *)string
return (CTLineRef)[(id)line autorelease];
}

/// Set Vim's cmdline row number. This will mark the relevant parts to be repainted
/// if the row number has changed as we are pinning the cmdline to the bottom,
/// because otherwise we will have a gap that doesn't get cleared and leaves artifacts.
///
/// @param row The row (0-indexed) of the current cmdline in Vim.
- (void)setCmdlineRow:(int)row
{
const BOOL newAlignCmdLineToBottom = [[NSUserDefaults standardUserDefaults] boolForKey:MMCmdLineAlignBottomKey];

if (newAlignCmdLineToBottom != alignCmdLineToBottom) {
// The user settings has changed (usually through the settings panel). Just update everything.
alignCmdLineToBottom = newAlignCmdLineToBottom;
cmdlineRow = row;
[self setNeedsDisplay:YES];
return;
}

if (row != cmdlineRow) {
// The cmdline row has changed. Need to redraw the necessary parts if we
// are configured to pin cmdline to the bottom.
if (alignCmdLineToBottom) {
// Since we are changing the cmdline row, we need to repaint the
// parts where the gap changed. Just for simplicity, we repaint
// both the old/new cmdline rows and the row above them. This way
// the gap in between the top and bottom aligned rows should be
// touched in the repainting and cleared to bg.
[self setNeedsDisplayFromRow:cmdlineRow-1
column:grid.cols
toRow:cmdlineRow
column:grid.cols];

// Have to do this between the two calls as cmdlineRow would affect
// the calculation in them.
cmdlineRow = row;

[self setNeedsDisplayFromRow:cmdlineRow-1
column:grid.cols
toRow:cmdlineRow
column:grid.cols];
} else {
cmdlineRow = row;
}
}
}

@end // MMCoreTextView (Private)


Expand Down
8 changes: 4 additions & 4 deletions src/MacVim/MMFindReplaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ - (void)showWithText:(NSString *)text flags:(int)flags
[findBox setStringValue:text];

// NOTE: The 'flags' values must match the FRD_ defines in gui.h.
[matchWordButton setState:(flags & 0x08 ? NSOnState : NSOffState)];
[ignoreCaseButton setState:(flags & 0x10 ? NSOffState : NSOnState)];
[matchWordButton setState:(flags & 0x08 ? NSControlStateValueOn : NSControlStateValueOff)];
[ignoreCaseButton setState:(flags & 0x10 ? NSControlStateValueOff : NSControlStateValueOn)];

[window makeKeyAndOrderFront:self];
}
Expand All @@ -52,12 +52,12 @@ - (NSString *)replaceString

- (BOOL)ignoreCase
{
return [ignoreCaseButton state] == NSOnState;
return [ignoreCaseButton state] == NSControlStateValueOn;
}

- (BOOL)matchWord
{
return [matchWordButton state] == NSOnState;
return [matchWordButton state] == NSControlStateValueOn;
}

@end // MMFindReplaceController
7 changes: 5 additions & 2 deletions src/MacVim/MMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ - (void)drawRect:(NSRect)rect
[super drawRect:rect];

if (invertRects) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
CGContextRef cgctx = context.CGContext;
#else
CGContextRef cgctx = (CGContextRef)[context graphicsPort];
#endif
CGContextSaveGState(cgctx);
CGContextSetBlendMode(cgctx, kCGBlendModeDifference);
CGContextSetRGBFillColor(cgctx, 1.0, 1.0, 1.0, 1.0);
Expand Down Expand Up @@ -815,8 +819,7 @@ - (NSMenu*)menuForEvent:(NSEvent *)event

- (NSArray *)acceptableDragTypes
{
return [NSArray arrayWithObjects:NSFilenamesPboardType,
NSStringPboardType, nil];
return @[getPasteboardFilenamesType(), NSPasteboardTypeString];
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
Expand Down
Loading