2016-07-28 00:20:33 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Disable symbol overrides so that we can use system headers.
|
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
|
|
|
|
|
|
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
|
2018-04-11 00:04:48 +01:00
|
|
|
#include "common/translation.h"
|
2016-07-28 00:20:33 +01:00
|
|
|
|
|
|
|
#include <AppKit/NSPasteboard.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
2017-04-24 00:30:28 +01:00
|
|
|
#include <Foundation/NSPathUtilities.h>
|
|
|
|
#include <AvailabilityMacros.h>
|
2018-04-11 00:04:48 +01:00
|
|
|
#include <CoreFoundation/CFString.h>
|
2016-07-28 00:20:33 +01:00
|
|
|
|
|
|
|
bool hasTextInClipboardMacOSX() {
|
|
|
|
return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String getTextFromClipboardMacOSX() {
|
|
|
|
if (!hasTextInClipboardMacOSX())
|
|
|
|
return Common::String();
|
|
|
|
// Note: on OS X 10.6 and above it is recommanded to use NSPasteboardTypeString rather than NSStringPboardType.
|
|
|
|
// But since we still target older version use NSStringPboardType.
|
|
|
|
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
2018-04-10 23:41:10 +01:00
|
|
|
NSString *str = [pb stringForType:NSStringPboardType];
|
2016-07-28 00:20:33 +01:00
|
|
|
if (str == nil)
|
|
|
|
return Common::String();
|
2018-04-11 00:04:48 +01:00
|
|
|
|
|
|
|
// If translations are supported, use the current TranslationManager charset and otherwise
|
|
|
|
// use ASCII. If the string cannot be represented using the requested encoding we get a null
|
|
|
|
// pointer below, which is fine as ScummVM would not know what to do with the string anyway.
|
|
|
|
#ifdef USE_TRANSLATION
|
|
|
|
NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
|
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
|
|
|
|
#else
|
|
|
|
NSStringEncoding encoding = NSISOLatin1StringEncoding;
|
|
|
|
#endif
|
|
|
|
return Common::String([str cStringUsingEncoding:encoding]);
|
2016-07-28 00:20:33 +01:00
|
|
|
}
|
2017-04-24 00:30:28 +01:00
|
|
|
|
2018-04-10 23:41:10 +01:00
|
|
|
bool setTextInClipboardMacOSX(const Common::String &text) {
|
|
|
|
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
|
|
|
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
|
2018-04-11 00:04:48 +01:00
|
|
|
|
|
|
|
#ifdef USE_TRANSLATION
|
|
|
|
NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
|
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
|
|
|
|
#else
|
|
|
|
NSStringEncoding encoding = NSISOLatin1StringEncoding;
|
|
|
|
#endif
|
|
|
|
return [pb setString:[NSString stringWithCString:text.c_str() encoding:encoding] forType:NSStringPboardType];
|
2018-04-10 23:41:10 +01:00
|
|
|
}
|
|
|
|
|
2017-04-24 00:30:28 +01:00
|
|
|
Common::String getDesktopPathMacOSX() {
|
|
|
|
// The recommanded method is to use NSFileManager.
|
|
|
|
// NSUrl *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask] firstObject];
|
|
|
|
// However it is only available in OS X 10.6+. So use NSSearchPathForDirectoriesInDomains instead (available since OS X 10.0)
|
|
|
|
// [NSArray firstObject] is also only available in OS X 10.6+. So we need to use [NSArray count] and [NSArray objectAtIndex:]
|
2017-04-26 08:38:55 +01:00
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
|
2017-04-24 00:30:28 +01:00
|
|
|
if ([paths count] == 0)
|
|
|
|
return Common::String();
|
|
|
|
NSString *path = [paths objectAtIndex:0];
|
|
|
|
if (path == nil)
|
|
|
|
return Common::String();
|
|
|
|
return Common::String([path cStringUsingEncoding:NSASCIIStringEncoding]);
|
2017-04-26 08:38:55 +01:00
|
|
|
}
|