macOS: Replace uses of deprecated Cocoa enum names with modern/consistent equivalents.
authorAlex Szpakowski <slime73@gmail.com>
Thu, 13 Jul 2017 22:59:02 -0300
changeset 11144cccd37a9c28b
parent 11143 424607440631
child 11145 a0327860b8fb
macOS: Replace uses of deprecated Cocoa enum names with modern/consistent equivalents.
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoakeyboard.m
src/video/cocoa/SDL_cocoamessagebox.m
src/video/cocoa/SDL_cocoamouse.m
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoavideo.h
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Wed Jul 12 21:32:10 2017 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Thu Jul 13 22:59:02 2017 -0300
     1.3 @@ -55,22 +55,22 @@
     1.4      SDL_VideoDevice *_this = SDL_GetVideoDevice();
     1.5  
     1.6      switch ([theEvent type]) {
     1.7 -        case NSLeftMouseDown:
     1.8 -        case NSOtherMouseDown:
     1.9 -        case NSRightMouseDown:
    1.10 -        case NSLeftMouseUp:
    1.11 -        case NSOtherMouseUp:
    1.12 -        case NSRightMouseUp:
    1.13 -        case NSLeftMouseDragged:
    1.14 -        case NSRightMouseDragged:
    1.15 -        case NSOtherMouseDragged: /* usually middle mouse dragged */
    1.16 -        case NSMouseMoved:
    1.17 -        case NSScrollWheel:
    1.18 +        case NSEventTypeLeftMouseDown:
    1.19 +        case NSEventTypeOtherMouseDown:
    1.20 +        case NSEventTypeRightMouseDown:
    1.21 +        case NSEventTypeLeftMouseUp:
    1.22 +        case NSEventTypeOtherMouseUp:
    1.23 +        case NSEventTypeRightMouseUp:
    1.24 +        case NSEventTypeLeftMouseDragged:
    1.25 +        case NSEventTypeRightMouseDragged:
    1.26 +        case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */
    1.27 +        case NSEventTypeMouseMoved:
    1.28 +        case NSEventTypeScrollWheel:
    1.29              Cocoa_HandleMouseEvent(_this, theEvent);
    1.30              break;
    1.31 -        case NSKeyDown:
    1.32 -        case NSKeyUp:
    1.33 -        case NSFlagsChanged:
    1.34 +        case NSEventTypeKeyDown:
    1.35 +        case NSEventTypeKeyUp:
    1.36 +        case NSEventTypeFlagsChanged:
    1.37              Cocoa_HandleKeyEvent(_this, theEvent);
    1.38              break;
    1.39          default:
    1.40 @@ -289,7 +289,7 @@
    1.41      [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
    1.42  
    1.43      menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
    1.44 -    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
    1.45 +    [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
    1.46  
    1.47      [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
    1.48  
    1.49 @@ -335,7 +335,7 @@
    1.50  
    1.51          /* Add menu items */
    1.52          menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
    1.53 -        [menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
    1.54 +        [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
    1.55  
    1.56          /* Put menu into the menubar */
    1.57          menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
    1.58 @@ -406,7 +406,7 @@
    1.59      }
    1.60  
    1.61      for ( ; ; ) {
    1.62 -        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    1.63 +        NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    1.64          if ( event == nil ) {
    1.65              break;
    1.66          }
     2.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Wed Jul 12 21:32:10 2017 -0300
     2.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Thu Jul 13 22:59:02 2017 -0300
     2.3 @@ -460,7 +460,7 @@
     2.4      unsigned int i, bit;
     2.5  
     2.6      /* Iterate through the bits, testing each against the old modifiers */
     2.7 -    for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
     2.8 +    for (i = 0, bit = NSEventModifierFlagShift; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) {
     2.9          unsigned int oldMask, newMask;
    2.10  
    2.11          oldMask = oldMods & bit;
    2.12 @@ -581,7 +581,7 @@
    2.13      SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
    2.14  
    2.15      data->modifierFlags = [NSEvent modifierFlags];
    2.16 -    SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0);
    2.17 +    SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
    2.18  
    2.19      InitHIDCallback();
    2.20  }
    2.21 @@ -670,7 +670,7 @@
    2.22      }
    2.23  
    2.24      switch ([event type]) {
    2.25 -    case NSKeyDown:
    2.26 +    case NSEventTypeKeyDown:
    2.27          if (![event isARepeat]) {
    2.28              /* See if we need to rebuild the keyboard layout */
    2.29              UpdateKeymap(data, SDL_TRUE);
    2.30 @@ -694,10 +694,10 @@
    2.31  #endif
    2.32          }
    2.33          break;
    2.34 -    case NSKeyUp:
    2.35 +    case NSEventTypeKeyUp:
    2.36          SDL_SendKeyboardKey(SDL_RELEASED, code);
    2.37          break;
    2.38 -    case NSFlagsChanged:
    2.39 +    case NSEventTypeFlagsChanged:
    2.40          /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
    2.41          HandleModifiers(_this, scancode, [event modifierFlags]);
    2.42          break;
     3.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m	Wed Jul 12 21:32:10 2017 -0300
     3.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m	Thu Jul 13 22:59:02 2017 -0300
     3.3 @@ -86,11 +86,11 @@
     3.4      NSAlert* alert = [[[NSAlert alloc] init] autorelease];
     3.5  
     3.6      if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
     3.7 -        [alert setAlertStyle:NSCriticalAlertStyle];
     3.8 +        [alert setAlertStyle:NSAlertStyleCritical];
     3.9      } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    3.10 -        [alert setAlertStyle:NSWarningAlertStyle];
    3.11 +        [alert setAlertStyle:NSAlertStyleWarning];
    3.12      } else {
    3.13 -        [alert setAlertStyle:NSInformationalAlertStyle];
    3.14 +        [alert setAlertStyle:NSAlertStyleInformational];
    3.15      }
    3.16  
    3.17      [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
     4.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Wed Jul 12 21:32:10 2017 -0300
     4.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Thu Jul 13 22:59:02 2017 -0300
     4.3 @@ -26,6 +26,7 @@
     4.4  #include "SDL_events.h"
     4.5  #include "SDL_cocoamouse.h"
     4.6  #include "SDL_cocoamousetap.h"
     4.7 +#include "SDL_cocoavideo.h"
     4.8  
     4.9  #include "../../events/SDL_mouse_c.h"
    4.10  
    4.11 @@ -363,10 +364,10 @@
    4.12  Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
    4.13  {
    4.14      switch ([event type]) {
    4.15 -        case NSMouseMoved:
    4.16 -        case NSLeftMouseDragged:
    4.17 -        case NSRightMouseDragged:
    4.18 -        case NSOtherMouseDragged:
    4.19 +        case NSEventTypeMouseMoved:
    4.20 +        case NSEventTypeLeftMouseDragged:
    4.21 +        case NSEventTypeRightMouseDragged:
    4.22 +        case NSEventTypeOtherMouseDragged:
    4.23              break;
    4.24  
    4.25          default:
     5.1 --- a/src/video/cocoa/SDL_cocoashape.m	Wed Jul 12 21:32:10 2017 -0300
     5.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Thu Jul 13 22:59:02 2017 -0300
     5.3 @@ -35,7 +35,7 @@
     5.4      SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
     5.5      [windata->nswindow setOpaque:NO];
     5.6  
     5.7 -    [windata->nswindow setStyleMask:NSBorderlessWindowMask];
     5.8 +    [windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];
     5.9  
    5.10      SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
    5.11      result->window = window;
     6.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Wed Jul 12 21:32:10 2017 -0300
     6.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Thu Jul 13 22:59:02 2017 -0300
     6.3 @@ -40,6 +40,59 @@
     6.4  #include "SDL_cocoaopengl.h"
     6.5  #include "SDL_cocoawindow.h"
     6.6  
     6.7 +#ifndef MAC_OS_X_VERSION_10_12
     6.8 +#define DECLARE_EVENT(name) static const NSEventType NSEventType##name = NS##name
     6.9 +DECLARE_EVENT(LeftMouseDown);
    6.10 +DECLARE_EVENT(LeftMouseUp);
    6.11 +DECLARE_EVENT(RightMouseDown);
    6.12 +DECLARE_EVENT(RightMouseUp);
    6.13 +DECLARE_EVENT(OtherMouseDown);
    6.14 +DECLARE_EVENT(OtherMouseUp);
    6.15 +DECLARE_EVENT(MouseMoved);
    6.16 +DECLARE_EVENT(LeftMouseDragged);
    6.17 +DECLARE_EVENT(RightMouseDragged);
    6.18 +DECLARE_EVENT(OtherMouseDragged);
    6.19 +DECLARE_EVENT(ScrollWheel);
    6.20 +DECLARE_EVENT(KeyDown);
    6.21 +DECLARE_EVENT(KeyUp);
    6.22 +DECLARE_EVENT(FlagsChanged);
    6.23 +DECLARE_EVENT(Any);
    6.24 +#undef DECLARE_EVENT
    6.25 +
    6.26 +#define DECLARE_MODIFIER_FLAG(name) static const NSUInteger NSEventModifierFlag##name = NS##name##KeyMask
    6.27 +DECLARE_MODIFIER_FLAG(Shift);
    6.28 +DECLARE_MODIFIER_FLAG(Control);
    6.29 +DECLARE_MODIFIER_FLAG(Command);
    6.30 +DECLARE_MODIFIER_FLAG(NumericPad);
    6.31 +DECLARE_MODIFIER_FLAG(Help);
    6.32 +DECLARE_MODIFIER_FLAG(Function);
    6.33 +#undef DECLARE_MODIFIER_FLAG
    6.34 +static const unsigned int NSEventModifierFlagCapsLock = NSAlphaShiftKeyMask;
    6.35 +static const unsigned int NSEventModifierFlagOption = NSAlternateKeyMask;
    6.36 +
    6.37 +#define DECLARE_WINDOW_MASK(name) static const unsigned int NSWindowStyleMask##name = NS##name##WindowMask
    6.38 +DECLARE_WINDOW_MASK(Borderless);
    6.39 +DECLARE_WINDOW_MASK(Titled);
    6.40 +DECLARE_WINDOW_MASK(Closable);
    6.41 +DECLARE_WINDOW_MASK(Miniaturizable);
    6.42 +DECLARE_WINDOW_MASK(Resizable);
    6.43 +DECLARE_WINDOW_MASK(TexturedBackground);
    6.44 +DECLARE_WINDOW_MASK(UnifiedTitleAndToolbar);
    6.45 +DECLARE_WINDOW_MASK(Fullscreen);
    6.46 +DECLARE_WINDOW_MASK(FullSizeContentView);
    6.47 +DECLARE_WINDOW_MASK(NonactivatingPanel);
    6.48 +DECLARE_WINDOW_MASK(HUDWindow);
    6.49 +static const unsigned int NSWindowStyleMaskUtilityWindow = NSUtilityWindowMask;
    6.50 +static const unsigned int NSWindowStyleMaskDocModalWindow = NSDocModalWindowMask;
    6.51 +#undef DECLARE_WINDOW_MASK
    6.52 +
    6.53 +#define DECLARE_ALERT_STYLE(name) static NSUInteger NSAlertStyle##name = NS##name##AlertStyle
    6.54 +DECLARE_ALERT_STYLE(Warning);
    6.55 +DECLARE_ALERT_STYLE(Informational);
    6.56 +DECLARE_ALERT_STYLE(Critical);
    6.57 +#undef DECLARE_ALERT_STYLE
    6.58 +#endif
    6.59 +
    6.60  /* Private display data */
    6.61  
    6.62  @class SDLTranslatorResponder;
     7.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Wed Jul 12 21:32:10 2017 -0300
     7.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Jul 13 22:59:02 2017 -0300
     7.3 @@ -83,7 +83,7 @@
     7.4  {
     7.5      [super sendEvent:event];
     7.6  
     7.7 -    if ([event type] != NSLeftMouseUp) {
     7.8 +    if ([event type] != NSEventTypeLeftMouseUp) {
     7.9          return;
    7.10      }
    7.11  
    7.12 @@ -221,15 +221,15 @@
    7.13      NSUInteger style = 0;
    7.14  
    7.15      if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.16 -        style = NSBorderlessWindowMask;
    7.17 +        style = NSWindowStyleMaskBorderless;
    7.18      } else {
    7.19          if (window->flags & SDL_WINDOW_BORDERLESS) {
    7.20 -            style = NSBorderlessWindowMask;
    7.21 +            style = NSWindowStyleMaskBorderless;
    7.22          } else {
    7.23 -            style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
    7.24 +            style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
    7.25          }
    7.26          if (window->flags & SDL_WINDOW_RESIZABLE) {
    7.27 -            style |= NSResizableWindowMask;
    7.28 +            style |= NSWindowStyleMaskResizable;
    7.29          }
    7.30      }
    7.31      return style;
    7.32 @@ -595,8 +595,8 @@
    7.33          [NSMenu setMenuBarVisible:NO];
    7.34      }
    7.35  
    7.36 -    const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
    7.37 -    _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags;
    7.38 +    const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
    7.39 +    _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
    7.40      SDL_ToggleModState(KMOD_CAPS, newflags != 0);
    7.41  }
    7.42  
    7.43 @@ -642,7 +642,7 @@
    7.44  {
    7.45      SDL_Window *window = _data->window;
    7.46  
    7.47 -    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
    7.48 +    SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
    7.49  
    7.50      isFullscreenSpace = YES;
    7.51      inFullscreenTransition = YES;
    7.52 @@ -696,7 +696,7 @@
    7.53      /* As of OS X 10.11, the window seems to need to be resizable when exiting
    7.54         a Space, in order for it to resize back to its windowed-mode size.
    7.55       */
    7.56 -    SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask);
    7.57 +    SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
    7.58  
    7.59      isFullscreenSpace = NO;
    7.60      inFullscreenTransition = YES;
    7.61 @@ -710,7 +710,7 @@
    7.62          return;
    7.63      }
    7.64  
    7.65 -    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
    7.66 +    SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
    7.67      
    7.68      isFullscreenSpace = YES;
    7.69      inFullscreenTransition = NO;
    7.70 @@ -841,7 +841,7 @@
    7.71  
    7.72      switch ([theEvent buttonNumber]) {
    7.73      case 0:
    7.74 -        if (([theEvent modifierFlags] & NSControlKeyMask) &&
    7.75 +        if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
    7.76  		    GetHintCtrlClickEmulateRightClick()) {
    7.77              wasCtrlLeft = YES;
    7.78              button = SDL_BUTTON_RIGHT;
    7.79 @@ -1170,12 +1170,12 @@
    7.80      {
    7.81          unsigned long style = [nswindow styleMask];
    7.82  
    7.83 -        if (style == NSBorderlessWindowMask) {
    7.84 +        if (style == NSWindowStyleMaskBorderless) {
    7.85              window->flags |= SDL_WINDOW_BORDERLESS;
    7.86          } else {
    7.87              window->flags &= ~SDL_WINDOW_BORDERLESS;
    7.88          }
    7.89 -        if (style & NSResizableWindowMask) {
    7.90 +        if (style & NSWindowStyleMaskResizable) {
    7.91              window->flags |= SDL_WINDOW_RESIZABLE;
    7.92          } else {
    7.93              window->flags &= ~SDL_WINDOW_RESIZABLE;
    7.94 @@ -1536,7 +1536,7 @@
    7.95              rect.origin.y += (screenRect.size.height - rect.size.height);
    7.96          }
    7.97  
    7.98 -        [nswindow setStyleMask:NSBorderlessWindowMask];
    7.99 +        [nswindow setStyleMask:NSWindowStyleMaskBorderless];
   7.100      } else {
   7.101          rect.origin.x = window->windowed.x;
   7.102          rect.origin.y = window->windowed.y;