macOS: Replace uses of deprecated Cocoa enum names with modern/consistent equivalents.

This commit is contained in:
Alex Szpakowski 2017-07-13 22:59:02 -03:00
parent e0ea4da4ae
commit bc3ede1ed0
7 changed files with 98 additions and 44 deletions

View File

@ -55,22 +55,22 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_VideoDevice *_this = SDL_GetVideoDevice();
switch ([theEvent type]) { switch ([theEvent type]) {
case NSLeftMouseDown: case NSEventTypeLeftMouseDown:
case NSOtherMouseDown: case NSEventTypeOtherMouseDown:
case NSRightMouseDown: case NSEventTypeRightMouseDown:
case NSLeftMouseUp: case NSEventTypeLeftMouseUp:
case NSOtherMouseUp: case NSEventTypeOtherMouseUp:
case NSRightMouseUp: case NSEventTypeRightMouseUp:
case NSLeftMouseDragged: case NSEventTypeLeftMouseDragged:
case NSRightMouseDragged: case NSEventTypeRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */ case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved: case NSEventTypeMouseMoved:
case NSScrollWheel: case NSEventTypeScrollWheel:
Cocoa_HandleMouseEvent(_this, theEvent); Cocoa_HandleMouseEvent(_this, theEvent);
break; break;
case NSKeyDown: case NSEventTypeKeyDown:
case NSKeyUp: case NSEventTypeKeyUp:
case NSFlagsChanged: case NSEventTypeFlagsChanged:
Cocoa_HandleKeyEvent(_this, theEvent); Cocoa_HandleKeyEvent(_this, theEvent);
break; break;
default: default:
@ -289,7 +289,7 @@ CreateApplicationMenus(void)
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
@ -335,7 +335,7 @@ CreateApplicationMenus(void)
/* Add menu items */ /* Add menu items */
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"]; menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask]; [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
/* Put menu into the menubar */ /* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""]; menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
@ -406,7 +406,7 @@ Cocoa_PumpEvents(_THIS)
} }
for ( ; ; ) { for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
if ( event == nil ) { if ( event == nil ) {
break; break;
} }

View File

@ -460,7 +460,7 @@ DoSidedModifiers(unsigned short scancode,
unsigned int i, bit; unsigned int i, bit;
/* Iterate through the bits, testing each against the old modifiers */ /* Iterate through the bits, testing each against the old modifiers */
for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) { for (i = 0, bit = NSEventModifierFlagShift; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) {
unsigned int oldMask, newMask; unsigned int oldMask, newMask;
oldMask = oldMods & bit; oldMask = oldMods & bit;
@ -581,7 +581,7 @@ Cocoa_InitKeyboard(_THIS)
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command"); SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
data->modifierFlags = [NSEvent modifierFlags]; data->modifierFlags = [NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0); SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
InitHIDCallback(); InitHIDCallback();
} }
@ -670,7 +670,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
} }
switch ([event type]) { switch ([event type]) {
case NSKeyDown: case NSEventTypeKeyDown:
if (![event isARepeat]) { if (![event isARepeat]) {
/* See if we need to rebuild the keyboard layout */ /* See if we need to rebuild the keyboard layout */
UpdateKeymap(data, SDL_TRUE); UpdateKeymap(data, SDL_TRUE);
@ -694,10 +694,10 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
#endif #endif
} }
break; break;
case NSKeyUp: case NSEventTypeKeyUp:
SDL_SendKeyboardKey(SDL_RELEASED, code); SDL_SendKeyboardKey(SDL_RELEASED, code);
break; break;
case NSFlagsChanged: case NSEventTypeFlagsChanged:
/* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
HandleModifiers(_this, scancode, [event modifierFlags]); HandleModifiers(_this, scancode, [event modifierFlags]);
break; break;

View File

@ -86,11 +86,11 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
NSAlert* alert = [[[NSAlert alloc] init] autorelease]; NSAlert* alert = [[[NSAlert alloc] init] autorelease];
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) { if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSCriticalAlertStyle]; [alert setAlertStyle:NSAlertStyleCritical];
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) { } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
[alert setAlertStyle:NSWarningAlertStyle]; [alert setAlertStyle:NSAlertStyleWarning];
} else { } else {
[alert setAlertStyle:NSInformationalAlertStyle]; [alert setAlertStyle:NSAlertStyleInformational];
} }
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]]; [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];

View File

@ -26,6 +26,7 @@
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_cocoamouse.h" #include "SDL_cocoamouse.h"
#include "SDL_cocoamousetap.h" #include "SDL_cocoamousetap.h"
#include "SDL_cocoavideo.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
@ -363,10 +364,10 @@ void
Cocoa_HandleMouseEvent(_THIS, NSEvent *event) Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{ {
switch ([event type]) { switch ([event type]) {
case NSMouseMoved: case NSEventTypeMouseMoved:
case NSLeftMouseDragged: case NSEventTypeLeftMouseDragged:
case NSRightMouseDragged: case NSEventTypeRightMouseDragged:
case NSOtherMouseDragged: case NSEventTypeOtherMouseDragged:
break; break;
default: default:

View File

@ -35,7 +35,7 @@ Cocoa_CreateShaper(SDL_Window* window)
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO]; [windata->nswindow setOpaque:NO];
[windata->nswindow setStyleMask:NSBorderlessWindowMask]; [windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];
SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper)); SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
result->window = window; result->window = window;

View File

@ -40,6 +40,59 @@
#include "SDL_cocoaopengl.h" #include "SDL_cocoaopengl.h"
#include "SDL_cocoawindow.h" #include "SDL_cocoawindow.h"
#ifndef MAC_OS_X_VERSION_10_12
#define DECLARE_EVENT(name) static const NSEventType NSEventType##name = NS##name
DECLARE_EVENT(LeftMouseDown);
DECLARE_EVENT(LeftMouseUp);
DECLARE_EVENT(RightMouseDown);
DECLARE_EVENT(RightMouseUp);
DECLARE_EVENT(OtherMouseDown);
DECLARE_EVENT(OtherMouseUp);
DECLARE_EVENT(MouseMoved);
DECLARE_EVENT(LeftMouseDragged);
DECLARE_EVENT(RightMouseDragged);
DECLARE_EVENT(OtherMouseDragged);
DECLARE_EVENT(ScrollWheel);
DECLARE_EVENT(KeyDown);
DECLARE_EVENT(KeyUp);
DECLARE_EVENT(FlagsChanged);
DECLARE_EVENT(Any);
#undef DECLARE_EVENT
#define DECLARE_MODIFIER_FLAG(name) static const NSUInteger NSEventModifierFlag##name = NS##name##KeyMask
DECLARE_MODIFIER_FLAG(Shift);
DECLARE_MODIFIER_FLAG(Control);
DECLARE_MODIFIER_FLAG(Command);
DECLARE_MODIFIER_FLAG(NumericPad);
DECLARE_MODIFIER_FLAG(Help);
DECLARE_MODIFIER_FLAG(Function);
#undef DECLARE_MODIFIER_FLAG
static const unsigned int NSEventModifierFlagCapsLock = NSAlphaShiftKeyMask;
static const unsigned int NSEventModifierFlagOption = NSAlternateKeyMask;
#define DECLARE_WINDOW_MASK(name) static const unsigned int NSWindowStyleMask##name = NS##name##WindowMask
DECLARE_WINDOW_MASK(Borderless);
DECLARE_WINDOW_MASK(Titled);
DECLARE_WINDOW_MASK(Closable);
DECLARE_WINDOW_MASK(Miniaturizable);
DECLARE_WINDOW_MASK(Resizable);
DECLARE_WINDOW_MASK(TexturedBackground);
DECLARE_WINDOW_MASK(UnifiedTitleAndToolbar);
DECLARE_WINDOW_MASK(Fullscreen);
DECLARE_WINDOW_MASK(FullSizeContentView);
DECLARE_WINDOW_MASK(NonactivatingPanel);
DECLARE_WINDOW_MASK(HUDWindow);
static const unsigned int NSWindowStyleMaskUtilityWindow = NSUtilityWindowMask;
static const unsigned int NSWindowStyleMaskDocModalWindow = NSDocModalWindowMask;
#undef DECLARE_WINDOW_MASK
#define DECLARE_ALERT_STYLE(name) static NSUInteger NSAlertStyle##name = NS##name##AlertStyle
DECLARE_ALERT_STYLE(Warning);
DECLARE_ALERT_STYLE(Informational);
DECLARE_ALERT_STYLE(Critical);
#undef DECLARE_ALERT_STYLE
#endif
/* Private display data */ /* Private display data */
@class SDLTranslatorResponder; @class SDLTranslatorResponder;

View File

@ -83,7 +83,7 @@
{ {
[super sendEvent:event]; [super sendEvent:event];
if ([event type] != NSLeftMouseUp) { if ([event type] != NSEventTypeLeftMouseUp) {
return; return;
} }
@ -221,15 +221,15 @@ GetWindowStyle(SDL_Window * window)
NSUInteger style = 0; NSUInteger style = 0;
if (window->flags & SDL_WINDOW_FULLSCREEN) { if (window->flags & SDL_WINDOW_FULLSCREEN) {
style = NSBorderlessWindowMask; style = NSWindowStyleMaskBorderless;
} else { } else {
if (window->flags & SDL_WINDOW_BORDERLESS) { if (window->flags & SDL_WINDOW_BORDERLESS) {
style = NSBorderlessWindowMask; style = NSWindowStyleMaskBorderless;
} else { } else {
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask); style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
} }
if (window->flags & SDL_WINDOW_RESIZABLE) { if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= NSResizableWindowMask; style |= NSWindowStyleMaskResizable;
} }
} }
return style; return style;
@ -595,8 +595,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
[NSMenu setMenuBarVisible:NO]; [NSMenu setMenuBarVisible:NO];
} }
const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask; const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
_data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags; _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
SDL_ToggleModState(KMOD_CAPS, newflags != 0); SDL_ToggleModState(KMOD_CAPS, newflags != 0);
} }
@ -642,7 +642,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
{ {
SDL_Window *window = _data->window; SDL_Window *window = _data->window;
SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)); SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
isFullscreenSpace = YES; isFullscreenSpace = YES;
inFullscreenTransition = YES; inFullscreenTransition = YES;
@ -696,7 +696,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
/* As of OS X 10.11, the window seems to need to be resizable when exiting /* As of OS X 10.11, the window seems to need to be resizable when exiting
a Space, in order for it to resize back to its windowed-mode size. a Space, in order for it to resize back to its windowed-mode size.
*/ */
SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask); SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
isFullscreenSpace = NO; isFullscreenSpace = NO;
inFullscreenTransition = YES; inFullscreenTransition = YES;
@ -710,7 +710,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
return; return;
} }
SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)); SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
isFullscreenSpace = YES; isFullscreenSpace = YES;
inFullscreenTransition = NO; inFullscreenTransition = NO;
@ -841,7 +841,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
switch ([theEvent buttonNumber]) { switch ([theEvent buttonNumber]) {
case 0: case 0:
if (([theEvent modifierFlags] & NSControlKeyMask) && if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
GetHintCtrlClickEmulateRightClick()) { GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES; wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT; button = SDL_BUTTON_RIGHT;
@ -1170,12 +1170,12 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
{ {
unsigned long style = [nswindow styleMask]; unsigned long style = [nswindow styleMask];
if (style == NSBorderlessWindowMask) { if (style == NSWindowStyleMaskBorderless) {
window->flags |= SDL_WINDOW_BORDERLESS; window->flags |= SDL_WINDOW_BORDERLESS;
} else { } else {
window->flags &= ~SDL_WINDOW_BORDERLESS; window->flags &= ~SDL_WINDOW_BORDERLESS;
} }
if (style & NSResizableWindowMask) { if (style & NSWindowStyleMaskResizable) {
window->flags |= SDL_WINDOW_RESIZABLE; window->flags |= SDL_WINDOW_RESIZABLE;
} else { } else {
window->flags &= ~SDL_WINDOW_RESIZABLE; window->flags &= ~SDL_WINDOW_RESIZABLE;
@ -1536,7 +1536,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
rect.origin.y += (screenRect.size.height - rect.size.height); rect.origin.y += (screenRect.size.height - rect.size.height);
} }
[nswindow setStyleMask:NSBorderlessWindowMask]; [nswindow setStyleMask:NSWindowStyleMaskBorderless];
} else { } else {
rect.origin.x = window->windowed.x; rect.origin.x = window->windowed.x;
rect.origin.y = window->windowed.y; rect.origin.y = window->windowed.y;