From cd325778997b794cecd643343129375e6de11661 Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Wed, 5 Oct 2022 02:25:10 -0700 Subject: [PATCH] Fix MacVim warnings: enum renames, graphicsPort, setcmdheight The list of warnings fixed: - Fix misc AppKit control states enums that got renamed and deprecated. - NSFindPboardType -> NSPasteboardTypeFind deprecation. - Fix usage of deprecated "graphicsPort" API to use CGContext instead. - Use NSFontChanging protocol if it's available. - Move MMCoreTextView's setcmdheight to the correct section in the private implementation category. --- src/MacVim/MMAppController.m | 4 +- src/MacVim/MMCoreTextView.h | 13 +++- src/MacVim/MMCoreTextView.m | 90 ++++++++++++++-------------- src/MacVim/MMFindReplaceController.m | 8 +-- src/MacVim/MMTextView.m | 4 ++ src/MacVim/MMWindowController.m | 2 +- src/MacVim/MacVim.h | 7 +++ src/MacVim/Miscellaneous.m | 2 +- 8 files changed, 76 insertions(+), 54 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index d32fc5da62..7094d24f3f 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -638,7 +638,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, if ([alert runModal] != NSAlertFirstButtonReturn) reply = NSTerminateCancel; - if ([[alert suppressionButton] state] == NSOnState) { + if ([[alert suppressionButton] state] == NSControlStateValueOn) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:MMSuppressTerminationAlertKey]; } @@ -1346,7 +1346,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, { ASLogDebug(@"Toggle CoreText renderer"); NSInteger renderer = MMRendererDefault; - BOOL enable = ([sender state] == NSOnState); + BOOL enable = ([sender state] == NSControlStateValueOn); if (enable) { renderer = MMRendererCoreText; diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index 470425336a..5c7c6e3f68 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -13,7 +13,13 @@ @class MMTextViewHelper; -@interface MMCoreTextView : NSView { +@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; @@ -51,6 +57,11 @@ - (id)initWithFrame:(NSRect)frame; +// +// NSFontChanging methods +// +- (void)changeFont:(id)sender; + // // MMTextStorage methods // diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 2ad82be8cf..65dfdf2f6a 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -565,51 +565,6 @@ static void grid_free(Grid *grid) { [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]; @@ -1400,6 +1355,51 @@ static void grid_free(Grid *grid) { 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) diff --git a/src/MacVim/MMFindReplaceController.m b/src/MacVim/MMFindReplaceController.m index d8b511e0b3..64e349b98c 100644 --- a/src/MacVim/MMFindReplaceController.m +++ b/src/MacVim/MMFindReplaceController.m @@ -34,8 +34,8 @@ [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]; } @@ -52,12 +52,12 @@ - (BOOL)ignoreCase { - return [ignoreCaseButton state] == NSOnState; + return [ignoreCaseButton state] == NSControlStateValueOn; } - (BOOL)matchWord { - return [matchWordButton state] == NSOnState; + return [matchWordButton state] == NSControlStateValueOn; } @end // MMFindReplaceController diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 44a31d72bf..a4bcbf79ba 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -545,7 +545,11 @@ [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); diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index e4f3396abf..e3b43a6ee6 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -1764,7 +1764,7 @@ if (!query) { // Use find pasteboard for next query. - NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSFindPboard]; + NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSPasteboardNameFind]; NSArray *supportedTypes = [NSArray arrayWithObjects:VimFindPboardType, NSPasteboardTypeString, nil]; NSString *bestType = [pb availableTypeFromArray:supportedTypes]; diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 0a88ad3c79..e549b436e3 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -72,6 +72,7 @@ # define NSAlertStyleCritical NSCriticalAlertStyle # define NSAlertStyleInformational NSInformationalAlertStyle # define NSAlertStyleWarning NSWarningAlertStyle +# define NSButtonTypeSwitch NSSwitchButton # define NSCompositingOperationSourceOver NSCompositeSourceOver # define NSCompositingOperationDifference NSCompositeDifference # define NSControlSizeRegular NSRegularControlSize @@ -100,6 +101,12 @@ # define NSWindowStyleMaskUnifiedTitleAndToolbar NSUnifiedTitleAndToolbarWindowMask #endif +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13 +// Deprecated constants in 10.13 SDK +#define NSControlStateValueOn NSOnState +#define NSControlStateValueOff NSOffState +#endif + // Deprecated runtime values. Since these are runtime values, we need to use the // minimum required OS as determining factor. Otherwise it would crash. diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index b8fedd15f1..98a0aad1ea 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -267,7 +267,7 @@ showHiddenFilesView() initWithFrame:NSMakeRect(0, 0, 140, 18)] autorelease]; [button setTitle: NSLocalizedString(@"Show Hidden Files", @"Show Hidden Files Checkbox")]; - [button setButtonType:NSSwitchButton]; + [button setButtonType:NSButtonTypeSwitch]; [button setTarget:nil]; [button setAction:@selector(hiddenFilesButtonToggled:)];