summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/os/macosx/macos.mm4
-rw-r--r--src/os/macosx/osx_stdafx.h4
-rw-r--r--src/video/cocoa/cocoa_v.mm28
-rw-r--r--src/video/cocoa/cocoa_wnd.mm47
4 files changed, 63 insertions, 20 deletions
diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm
index 6f0ab8d63..90bcd6dc4 100644
--- a/src/os/macosx/macos.mm
+++ b/src/os/macosx/macos.mm
@@ -191,13 +191,13 @@ const char *GetCurrentLocale(const char *)
bool GetClipboardContents(char *buffer, const char *last)
{
NSPasteboard *pb = [ NSPasteboard generalPasteboard ];
- NSArray *types = [ NSArray arrayWithObject:NSStringPboardType ];
+ NSArray *types = [ NSArray arrayWithObject:NSPasteboardTypeString ];
NSString *bestType = [ pb availableTypeFromArray:types ];
/* Clipboard has no text data available. */
if (bestType == nil) return false;
- NSString *string = [ pb stringForType:NSStringPboardType ];
+ NSString *string = [ pb stringForType:NSPasteboardTypeString ];
if (string == nil || [ string length ] == 0) return false;
strecpy(buffer, [ string UTF8String ], last);
diff --git a/src/os/macosx/osx_stdafx.h b/src/os/macosx/osx_stdafx.h
index e147fcf74..9c4276d05 100644
--- a/src/os/macosx/osx_stdafx.h
+++ b/src/os/macosx/osx_stdafx.h
@@ -26,6 +26,10 @@
#define HAVE_OSX_1011_SDK
#endif
+#ifdef MAC_OS_X_VERSION_10_12
+#define HAVE_OSX_1012_SDK
+#endif
+
/* It would seem that to ensure backward compatibility we have to ensure that we have defined MAC_OS_X_VERSION_10_x everywhere */
#ifndef MAC_OS_X_VERSION_10_3
#define MAC_OS_X_VERSION_10_3 1030
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 2a8737333..f43ea9b28 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -45,6 +45,17 @@
#import <sys/time.h> /* gettimeofday */
#include <array>
+/* The 10.12 SDK added new names for some enum constants and
+ * deprecated the old ones. As there's no functional change in any
+ * way, just use a define for older SDKs to the old names. */
+#ifndef HAVE_OSX_1012_SDK
+# define NSEventModifierFlagCommand NSCommandKeyMask
+# define NSEventModifierFlagControl NSControlKeyMask
+# define NSEventModifierFlagOption NSAlternateKeyMask
+# define NSEventModifierFlagShift NSShiftKeyMask
+# define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
+#endif
+
/**
* Important notice regarding all modifications!!!!!!!
* There are certain limitations because the file is objective C++.
@@ -360,7 +371,11 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height)
NSRect contentRect = NSMakeRect(0, 0, width, height);
/* Create main window. */
+#ifdef HAVE_OSX_1012_SDK
+ unsigned int style = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskClosable;
+#else
unsigned int style = NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask;
+#endif
this->window = [ [ OTTD_CocoaWindow alloc ] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered defer:NO driver:this ];
if (this->window == nil) {
Debug(driver, 0, "Could not create the Cocoa window.");
@@ -376,7 +391,7 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height)
behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
[ this->window setCollectionBehavior:behavior ];
- NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowFullScreenButton ];
+ NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowZoomButton ];
[ fullscreenButton setAction:@selector(toggleFullScreen:) ];
[ fullscreenButton setTarget:this->window ];
}
@@ -430,7 +445,12 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height)
*/
bool VideoDriver_Cocoa::PollEvent()
{
- NSEvent *event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ];
+#ifdef HAVE_OSX_1012_SDK
+ NSEventMask mask = NSEventMaskAny;
+#else
+ NSEventMask mask = NSAnyEventMask;
+#endif
+ NSEvent *event = [ NSApp nextEventMatchingMask:mask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ];
if (event == nil) return false;
@@ -445,8 +465,8 @@ void VideoDriver_Cocoa::InputLoop()
bool old_ctrl_pressed = _ctrl_pressed;
- _ctrl_pressed = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask)) != 0;
- _shift_pressed = (cur_mods & NSShiftKeyMask) != 0;
+ _ctrl_pressed = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSEventModifierFlagControl : NSEventModifierFlagCommand)) != 0;
+ _shift_pressed = (cur_mods & NSEventModifierFlagShift) != 0;
#if defined(_DEBUG)
this->fast_forward_key_pressed = _shift_pressed;
diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm
index c0a1bb694..1f470a948 100644
--- a/src/video/cocoa/cocoa_wnd.mm
+++ b/src/video/cocoa/cocoa_wnd.mm
@@ -37,6 +37,16 @@
/* Table data for key mapping. */
#include "cocoa_keys.h"
+/* The 10.12 SDK added new names for some enum constants and
+ * deprecated the old ones. As there's no functional change in any
+ * way, just use a define for older SDKs to the old names. */
+#ifndef HAVE_OSX_1012_SDK
+# define NSEventModifierFlagCommand NSCommandKeyMask
+# define NSEventModifierFlagControl NSControlKeyMask
+# define NSEventModifierFlagOption NSAlternateKeyMask
+# define NSEventModifierFlagShift NSShiftKeyMask
+# define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
+#endif
/**
* Important notice regarding all modifications!!!!!!!
@@ -135,7 +145,12 @@ static std::vector<WChar> NSStringToUTF32(NSString *s)
[ NSApp stop:self ];
/* Send an empty event to return from the run loop. Without that, application is stuck waiting for an event. */
- NSEvent *event = [ NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0 ];
+#ifdef HAVE_OSX_1012_SDK
+ NSEventType type = NSEventTypeApplicationDefined;
+#else
+ NSEventType type = NSApplicationDefined;
+#endif
+ NSEvent *event = [ NSEvent otherEventWithType:type location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0 ];
[ NSApp postEvent:event atStart:YES ];
}
@@ -207,7 +222,7 @@ static void setApplicationMenu()
[ appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h" ];
NSMenuItem *menuItem = [ 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:@"" ];
@@ -329,7 +344,11 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
@autoreleasepool {
NSAlert *alert = [ [ NSAlert alloc ] init ];
+#ifdef HAVE_OSX_1012_SDK
+ [ alert setAlertStyle: NSAlertStyleCritical ];
+#else
[ alert setAlertStyle: NSCriticalAlertStyle ];
+#endif
[ alert setMessageText:[ NSString stringWithUTF8String:title ] ];
[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ];
[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ];
@@ -536,8 +555,8 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
- (BOOL)emulateRightButton:(NSEvent *)event
{
uint32 keymask = 0;
- if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSCommandKeyMask;
- if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSControlKeyMask;
+ if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSEventModifierFlagCommand;
+ if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSEventModifierFlagControl;
return (event.modifierFlags & keymask) != 0;
}
@@ -653,18 +672,18 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
case QZ_RETURN:
case QZ_f:
- if (down && (modifiers & NSCommandKeyMask)) {
+ if (down && (modifiers & NSEventModifierFlagCommand)) {
VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
}
break;
case QZ_v:
- if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) {
+ if (down && EditBoxInGlobalFocus() && (modifiers & (NSEventModifierFlagCommand | NSEventModifierFlagControl))) {
HandleKeypress(WKC_CTRL | 'V', unicode);
}
break;
case QZ_u:
- if (down && EditBoxInGlobalFocus() && (modifiers & (NSCommandKeyMask | NSControlKeyMask))) {
+ if (down && EditBoxInGlobalFocus() && (modifiers & (NSEventModifierFlagCommand | NSEventModifierFlagControl))) {
HandleKeypress(WKC_CTRL | 'U', unicode);
}
break;
@@ -676,10 +695,10 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
auto vk = std::find_if(std::begin(_vk_mapping), std::end(_vk_mapping), [=](const CocoaVkMapping &m) { return m.vk_from == keycode; });
uint32 pressed_key = vk != std::end(_vk_mapping) ? vk->map_to : 0;
- if (modifiers & NSShiftKeyMask) pressed_key |= WKC_SHIFT;
- if (modifiers & NSControlKeyMask) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META);
- if (modifiers & NSAlternateKeyMask) pressed_key |= WKC_ALT;
- if (modifiers & NSCommandKeyMask) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL);
+ if (modifiers & NSEventModifierFlagShift) pressed_key |= WKC_SHIFT;
+ if (modifiers & NSEventModifierFlagControl) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_CTRL : WKC_META);
+ if (modifiers & NSEventModifierFlagOption) pressed_key |= WKC_ALT;
+ if (modifiers & NSEventModifierFlagCommand) pressed_key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL);
static bool console = false;
@@ -715,7 +734,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
case QZ_q:
case QZ_h:
case QZ_m:
- if (event.modifierFlags & NSCommandKeyMask) {
+ if (event.modifierFlags & NSEventModifierFlagCommand) {
[ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
}
break;
@@ -744,7 +763,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
case QZ_q:
case QZ_h:
case QZ_m:
- if (event.modifierFlags & NSCommandKeyMask) {
+ if (event.modifierFlags & NSEventModifierFlagCommand) {
[ self interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
}
break;
@@ -765,7 +784,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
if (self->_current_mods == newMods) return;
/* Iterate through the bits, testing each against the current modifiers */
- for (unsigned int i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
+ for (unsigned int i = 0, bit = NSEventModifierFlagCapsLock; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) {
unsigned int currentMask, newMask;
currentMask = self->_current_mods & bit;