diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 3bc4b5272..f5b015ab7 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -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: @@ -289,7 +289,7 @@ CreateApplicationMenus(void) [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:@""]; @@ -335,7 +335,7 @@ CreateApplicationMenus(void) /* 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:@""]; @@ -406,7 +406,7 @@ Cocoa_PumpEvents(_THIS) } 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; } diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 5e0b4481a..16f37ba04 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -460,7 +460,7 @@ DoSidedModifiers(unsigned short scancode, 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; @@ -581,7 +581,7 @@ Cocoa_InitKeyboard(_THIS) 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(); } @@ -670,7 +670,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event) } switch ([event type]) { - case NSKeyDown: + case NSEventTypeKeyDown: if (![event isARepeat]) { /* See if we need to rebuild the keyboard layout */ UpdateKeymap(data, SDL_TRUE); @@ -694,10 +694,10 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event) #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; diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m index 136b0a91f..fc2fcb3ce 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.m +++ b/src/video/cocoa/SDL_cocoamessagebox.m @@ -86,11 +86,11 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) 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]]; diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 4d3f46180..61c19a9e1 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -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" @@ -363,10 +364,10 @@ void 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: diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index c47f52f25..32d4e9de4 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -35,7 +35,7 @@ Cocoa_CreateShaper(SDL_Window* window) 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; diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h index 22648dbca..c6ca52459 100644 --- a/src/video/cocoa/SDL_cocoavideo.h +++ b/src/video/cocoa/SDL_cocoavideo.h @@ -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; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index ac605fc94..2f3d7bfa0 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -83,7 +83,7 @@ { [super sendEvent:event]; - if ([event type] != NSLeftMouseUp) { + if ([event type] != NSEventTypeLeftMouseUp) { return; } @@ -221,15 +221,15 @@ GetWindowStyle(SDL_Window * window) 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; @@ -595,8 +595,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style) [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); } @@ -642,7 +642,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style) { SDL_Window *window = _data->window; - SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)); + SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable)); isFullscreenSpace = 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 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; @@ -710,7 +710,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style) return; } - SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)); + SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable)); isFullscreenSpace = YES; inFullscreenTransition = NO; @@ -841,7 +841,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style) switch ([theEvent buttonNumber]) { case 0: - if (([theEvent modifierFlags] & NSControlKeyMask) && + if (([theEvent modifierFlags] & NSEventModifierFlagControl) && GetHintCtrlClickEmulateRightClick()) { wasCtrlLeft = YES; button = SDL_BUTTON_RIGHT; @@ -1170,12 +1170,12 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created { 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; @@ -1536,7 +1536,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display 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;