Skip to content

Commit

Permalink
macOS: Replace uses of deprecated Cocoa enum names with modern/consis…
Browse files Browse the repository at this point in the history
…tent equivalents.
  • Loading branch information
slime73 committed Jul 14, 2017
1 parent e0ea4da commit bc3ede1
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 44 deletions.
34 changes: 17 additions & 17 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -55,22 +55,22 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
SDL_VideoDevice *_this = SDL_GetVideoDevice();

switch ([theEvent type]) {
case NSLeftMouseDown:
case NSOtherMouseDown:
case NSRightMouseDown:
case NSLeftMouseUp:
case NSOtherMouseUp:
case NSRightMouseUp:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved:
case NSScrollWheel:
case NSEventTypeLeftMouseDown:
case NSEventTypeOtherMouseDown:
case NSEventTypeRightMouseDown:
case NSEventTypeLeftMouseUp:
case NSEventTypeOtherMouseUp:
case NSEventTypeRightMouseUp:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */
case NSEventTypeMouseMoved:
case NSEventTypeScrollWheel:
Cocoa_HandleMouseEvent(_this, theEvent);
break;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
case NSEventTypeKeyDown:
case NSEventTypeKeyUp:
case NSEventTypeFlagsChanged:
Cocoa_HandleKeyEvent(_this, theEvent);
break;
default:
Expand Down Expand Up @@ -289,7 +289,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
[appleMenu addItemWithTitle:title action:@selector(hide:) 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:@""];

Expand Down Expand Up @@ -335,7 +335,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam

/* Add menu items */
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];

/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
Expand Down Expand Up @@ -406,7 +406,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
}

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 ) {
break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -460,7 +460,7 @@ - (NSArray *)validAttributesForMarkedText
unsigned int i, bit;

/* 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;

oldMask = oldMods & bit;
Expand Down Expand Up @@ -581,7 +581,7 @@ - (NSArray *)validAttributesForMarkedText
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");

data->modifierFlags = [NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSAlphaShiftKeyMask) != 0);
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);

InitHIDCallback();
}
Expand Down Expand Up @@ -670,7 +670,7 @@ - (NSArray *)validAttributesForMarkedText
}

switch ([event type]) {
case NSKeyDown:
case NSEventTypeKeyDown:
if (![event isARepeat]) {
/* See if we need to rebuild the keyboard layout */
UpdateKeymap(data, SDL_TRUE);
Expand All @@ -694,10 +694,10 @@ - (NSArray *)validAttributesForMarkedText
#endif
}
break;
case NSKeyUp:
case NSEventTypeKeyUp:
SDL_SendKeyboardKey(SDL_RELEASED, code);
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 */
HandleModifiers(_this, scancode, [event modifierFlags]);
break;
Expand Down
6 changes: 3 additions & 3 deletions src/video/cocoa/SDL_cocoamessagebox.m
Expand Up @@ -86,11 +86,11 @@ - (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextIn
NSAlert* alert = [[[NSAlert alloc] init] autorelease];

if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSCriticalAlertStyle];
[alert setAlertStyle:NSAlertStyleCritical];
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
[alert setAlertStyle:NSWarningAlertStyle];
[alert setAlertStyle:NSAlertStyleWarning];
} else {
[alert setAlertStyle:NSInformationalAlertStyle];
[alert setAlertStyle:NSAlertStyleInformational];
}

[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
Expand Down
9 changes: 5 additions & 4 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -26,6 +26,7 @@
#include "SDL_events.h"
#include "SDL_cocoamouse.h"
#include "SDL_cocoamousetap.h"
#include "SDL_cocoavideo.h"

#include "../../events/SDL_mouse_c.h"

Expand Down Expand Up @@ -363,10 +364,10 @@ + (NSCursor *)invisibleCursor
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{
switch ([event type]) {
case NSMouseMoved:
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
case NSEventTypeMouseMoved:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged:
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/video/cocoa/SDL_cocoashape.m
Expand Up @@ -35,7 +35,7 @@
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO];

[windata->nswindow setStyleMask:NSBorderlessWindowMask];
[windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];

SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
result->window = window;
Expand Down
53 changes: 53 additions & 0 deletions src/video/cocoa/SDL_cocoavideo.h
Expand Up @@ -40,6 +40,59 @@
#include "SDL_cocoaopengl.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 */

@class SDLTranslatorResponder;
Expand Down
28 changes: 14 additions & 14 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -83,7 +83,7 @@ - (void)sendEvent:(NSEvent *)event
{
[super sendEvent:event];

if ([event type] != NSLeftMouseUp) {
if ([event type] != NSEventTypeLeftMouseUp) {
return;
}

Expand Down Expand Up @@ -221,15 +221,15 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
NSUInteger style = 0;

if (window->flags & SDL_WINDOW_FULLSCREEN) {
style = NSBorderlessWindowMask;
style = NSWindowStyleMaskBorderless;
} else {
if (window->flags & SDL_WINDOW_BORDERLESS) {
style = NSBorderlessWindowMask;
style = NSWindowStyleMaskBorderless;
} else {
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
}
if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= NSResizableWindowMask;
style |= NSWindowStyleMaskResizable;
}
}
return style;
Expand Down Expand Up @@ -595,8 +595,8 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification
[NSMenu setMenuBarVisible:NO];
}

const unsigned int newflags = [NSEvent modifierFlags] & NSAlphaShiftKeyMask;
_data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSAlphaShiftKeyMask) | newflags;
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
_data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
SDL_ToggleModState(KMOD_CAPS, newflags != 0);
}

Expand Down Expand Up @@ -642,7 +642,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)aNotification
{
SDL_Window *window = _data->window;

SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));

isFullscreenSpace = YES;
inFullscreenTransition = YES;
Expand Down Expand Up @@ -696,7 +696,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)aNotification
/* 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.
*/
SetWindowStyle(window, GetWindowStyle(window) | NSResizableWindowMask);
SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);

isFullscreenSpace = NO;
inFullscreenTransition = YES;
Expand All @@ -710,7 +710,7 @@ - (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
return;
}

SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));

isFullscreenSpace = YES;
inFullscreenTransition = NO;
Expand Down Expand Up @@ -841,7 +841,7 @@ - (void)mouseDown:(NSEvent *)theEvent

switch ([theEvent buttonNumber]) {
case 0:
if (([theEvent modifierFlags] & NSControlKeyMask) &&
if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT;
Expand Down Expand Up @@ -1170,12 +1170,12 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
unsigned long style = [nswindow styleMask];

if (style == NSBorderlessWindowMask) {
if (style == NSWindowStyleMaskBorderless) {
window->flags |= SDL_WINDOW_BORDERLESS;
} else {
window->flags &= ~SDL_WINDOW_BORDERLESS;
}
if (style & NSResizableWindowMask) {
if (style & NSWindowStyleMaskResizable) {
window->flags |= SDL_WINDOW_RESIZABLE;
} else {
window->flags &= ~SDL_WINDOW_RESIZABLE;
Expand Down Expand Up @@ -1536,7 +1536,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
rect.origin.y += (screenRect.size.height - rect.size.height);
}

[nswindow setStyleMask:NSBorderlessWindowMask];
[nswindow setStyleMask:NSWindowStyleMaskBorderless];
} else {
rect.origin.x = window->windowed.x;
rect.origin.y = window->windowed.y;
Expand Down

0 comments on commit bc3ede1

Please sign in to comment.