From cb2d1f4bceec1a63b916f82f3dbd850085b7f005 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 27 Mar 2017 17:13:07 +0000 Subject: [PATCH] Mac: Address deprecation warnings with the latest Xcode and macOS. git-svn-id: https://svn.eduke32.com/eduke32@6109 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/osxbits.mm | 20 ++++++++++++++++-- source/build/src/startosx.editor.mm | 32 ++++++++++++++++++----------- source/duke3d/src/startosx.game.mm | 30 +++++++++++++++++++-------- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/source/build/src/osxbits.mm b/source/build/src/osxbits.mm index d5818c513..613d6b554 100644 --- a/source/build/src/osxbits.mm +++ b/source/build/src/osxbits.mm @@ -3,6 +3,22 @@ #import #import +#ifndef MAC_OS_X_VERSION_10_5 +# define NSImageScaleNone NSScaleNone +#endif + +#ifndef MAC_OS_X_VERSION_10_12 +# define NSEventModifierFlagOption NSAlternateKeyMask +# define NSEventModifierFlagCommand NSCommandKeyMask +# define NSEventMaskAny NSAnyEventMask +# define NSWindowStyleMaskTitled NSTitledWindowMask +# define NSWindowStyleMaskClosable NSClosableWindowMask +# define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask +# define NSWindowStyleMaskResizable NSResizableWindowMask +# define NSAlertStyleInformational NSInformationalAlertStyle +# define NSControlSizeSmall NSSmallControlSize +#endif + #ifndef MAC_OS_VERSION_10_3 # define MAC_OS_VERSION_10_3 1030 #endif @@ -15,7 +31,7 @@ int osx_msgbox(const char *name, const char *msg) NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle: @"OK"]; [alert setInformativeText: mmsg]; - [alert setAlertStyle: NSInformationalAlertStyle]; + [alert setAlertStyle: NSAlertStyleInformational]; [alert runModal]; @@ -43,7 +59,7 @@ int osx_ynbox(const char *name, const char *msg) [alert addButtonWithTitle:@"Yes"]; [alert addButtonWithTitle:@"No"]; [alert setInformativeText: mmsg]; - [alert setAlertStyle: NSInformationalAlertStyle]; + [alert setAlertStyle: NSAlertStyleInformational]; r = ([alert runModal] == NSAlertFirstButtonReturn); diff --git a/source/build/src/startosx.editor.mm b/source/build/src/startosx.editor.mm index 18802bf40..cf51f1ab0 100644 --- a/source/build/src/startosx.editor.mm +++ b/source/build/src/startosx.editor.mm @@ -6,6 +6,22 @@ #include "build.h" #include "editor.h" +#ifndef MAC_OS_X_VERSION_10_5 +# define NSImageScaleNone NSScaleNone +#endif + +#ifndef MAC_OS_X_VERSION_10_12 +# define NSEventModifierFlagOption NSAlternateKeyMask +# define NSEventModifierFlagCommand NSCommandKeyMask +# define NSEventMaskAny NSAnyEventMask +# define NSWindowStyleMaskTitled NSTitledWindowMask +# define NSWindowStyleMaskClosable NSClosableWindowMask +# define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask +# define NSWindowStyleMaskResizable NSResizableWindowMask +# define NSAlertStyleInformational NSInformationalAlertStyle +# define NSControlSizeSmall NSSmallControlSize +#endif + static NSRect NSRectChangeXY(NSRect const rect, CGFloat const x, CGFloat const y) { return NSMakeRect(x, y, rect.size.width, rect.size.height); @@ -32,11 +48,7 @@ static void setFontToSmall(id control) static void setControlToSmall(id control) { -#ifdef MAC_OS_X_VERSION_10_12 [control setControlSize:NSControlSizeSmall]; -#else - [control setControlSize:NSSmallControlSize]; -#endif } static NSTextField * makeLabel(NSString * labelText) @@ -134,7 +146,7 @@ static void CreateApplicationMenus(void) [rootMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; menuItem = (NSMenuItem *)[rootMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)]; [rootMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; @@ -200,7 +212,7 @@ static struct { - (StartupWindow *)init { - NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; + NSUInteger const style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; NSRect const windowFrame = NSMakeRect(0, 0, 480, 280); self = [super initWithContentRect:windowFrame styleMask:style backing:NSBackingStoreBuffered defer:NO]; @@ -219,11 +231,7 @@ static struct { // image on the left NSRect const imageFrame = NSMakeRect(0, 0, 100, 280); NSImageView * imageView = [[NSImageView alloc] initWithFrame:imageFrame]; -#ifdef MAC_OS_X_VERSION_10_5 [imageView setImageScaling:NSImageScaleNone]; -#else - [imageView setImageScaling:NSScaleNone]; -#endif [imageView setImage:[NSImage imageNamed:@"build"]]; [[self contentView] addSubview:imageView]; [imageView setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable]; @@ -640,7 +648,7 @@ int startwin_idle(void *v) NSEvent *event; do { - event = [nsapp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate date] inMode:NSDefaultRunLoopMode dequeue:YES]; + event = [nsapp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate date] inMode:NSDefaultRunLoopMode dequeue:YES]; [nsapp sendEvent:event]; } while (event != nil); @@ -669,7 +677,7 @@ int startwin_run(void) do { - NSEvent *event = [nsapp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; + NSEvent *event = [nsapp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; [nsapp sendEvent:event]; [nsapp updateWindows]; } diff --git a/source/duke3d/src/startosx.game.mm b/source/duke3d/src/startosx.game.mm index d7e91c3c5..c785f6f99 100644 --- a/source/duke3d/src/startosx.game.mm +++ b/source/duke3d/src/startosx.game.mm @@ -13,6 +13,22 @@ #import "GrpFile.game.h" #import "GameListSource.game.h" +#ifndef MAC_OS_X_VERSION_10_5 +# define NSImageScaleNone NSScaleNone +#endif + +#ifndef MAC_OS_X_VERSION_10_12 +# define NSEventModifierFlagOption NSAlternateKeyMask +# define NSEventModifierFlagCommand NSCommandKeyMask +# define NSEventMaskAny NSAnyEventMask +# define NSWindowStyleMaskTitled NSTitledWindowMask +# define NSWindowStyleMaskClosable NSClosableWindowMask +# define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask +# define NSWindowStyleMaskResizable NSResizableWindowMask +# define NSAlertStyleInformational NSInformationalAlertStyle +# define NSControlSizeSmall NSSmallControlSize +#endif + static NSRect NSRectChangeXY(NSRect const rect, CGFloat const x, CGFloat const y) { return NSMakeRect(x, y, rect.size.width, rect.size.height); @@ -42,7 +58,7 @@ static void setControlToSmall(id control) #ifdef MAC_OS_X_VERSION_10_12 [control setControlSize:NSControlSizeSmall]; #else - [control setControlSize:NSSmallControlSize]; + [control setControlSize:NSControlSizeSmall]; #endif } @@ -141,7 +157,7 @@ static void CreateApplicationMenus(void) [rootMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; menuItem = (NSMenuItem *)[rootMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)]; [rootMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; @@ -207,7 +223,7 @@ static struct { - (StartupWindow *)init { - NSUInteger const style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; + NSUInteger const style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; NSRect const windowFrame = NSMakeRect(0, 0, 480, 280); self = [super initWithContentRect:windowFrame styleMask:style backing:NSBackingStoreBuffered defer:NO]; @@ -226,11 +242,7 @@ static struct { // image on the left NSRect const imageFrame = NSMakeRect(0, 0, 100, 280); NSImageView * imageView = [[NSImageView alloc] initWithFrame:imageFrame]; -#ifdef MAC_OS_X_VERSION_10_5 [imageView setImageScaling:NSImageScaleNone]; -#else - [imageView setImageScaling:NSScaleNone]; -#endif [imageView setImage:[NSImage imageNamed:@"game"]]; [[self contentView] addSubview:imageView]; [imageView setAutoresizingMask:NSViewMaxXMargin | NSViewHeightSizable]; @@ -647,7 +659,7 @@ int startwin_idle(void *v) NSEvent *event; do { - event = [nsapp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate date] inMode:NSDefaultRunLoopMode dequeue:YES]; + event = [nsapp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate date] inMode:NSDefaultRunLoopMode dequeue:YES]; [nsapp sendEvent:event]; } while (event != nil); @@ -675,7 +687,7 @@ int startwin_run(void) do { - NSEvent *event = [nsapp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; + NSEvent *event = [nsapp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; [nsapp sendEvent:event]; [nsapp updateWindows]; }