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;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:43 +05:30
|
|
|
Common::U32String getTextFromClipboardMacOSX() {
|
2016-07-28 00:20:33 +01:00
|
|
|
if (!hasTextInClipboardMacOSX())
|
2020-06-22 23:25:43 +05:30
|
|
|
return Common::U32String();
|
2016-07-28 00:20:33 +01:00
|
|
|
// 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)
|
2020-06-22 23:25:43 +05:30
|
|
|
return Common::U32String();
|
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.
|
2020-06-22 23:25:43 +05:30
|
|
|
#ifdef SCUMM_LITTLE_ENDIAN
|
|
|
|
NSStringEncoding stringEncoding = NSUTF32LittleEndianStringEncoding;
|
2018-04-11 00:04:48 +01:00
|
|
|
#else
|
2020-06-22 23:25:43 +05:30
|
|
|
NSStringEncoding stringEncoding = NSUTF32BigEndianStringEncoding;
|
2018-04-11 00:04:48 +01:00
|
|
|
#endif
|
2020-06-22 23:25:43 +05:30
|
|
|
NSUInteger textLength = [str length];
|
|
|
|
uint32 *text = new uint32[textLength];
|
2020-08-18 00:35:52 +01:00
|
|
|
if (![str getBytes:text maxLength:4*textLength usedLength:NULL encoding: stringEncoding options:0 range:NSMakeRange(0, textLength) remainingRange:NULL]) {
|
2020-06-22 23:25:43 +05:30
|
|
|
delete[] text;
|
|
|
|
return Common::U32String();
|
|
|
|
}
|
|
|
|
Common::U32String u32String(text, textLength);
|
|
|
|
delete[] text;
|
|
|
|
|
|
|
|
return u32String;
|
2016-07-28 00:20:33 +01:00
|
|
|
}
|
2017-04-24 00:30:28 +01:00
|
|
|
|
2020-06-22 23:25:43 +05:30
|
|
|
bool setTextInClipboardMacOSX(const Common::U32String &text) {
|
2018-04-10 23:41:10 +01:00
|
|
|
NSPasteboard *pb = [NSPasteboard generalPasteboard];
|
|
|
|
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
|
2018-04-11 00:04:48 +01:00
|
|
|
|
2020-06-22 23:25:43 +05:30
|
|
|
#ifdef SCUMM_LITTLE_ENDIAN
|
|
|
|
NSStringEncoding stringEncoding = NSUTF32LittleEndianStringEncoding;
|
2018-04-11 00:04:48 +01:00
|
|
|
#else
|
2020-06-22 23:25:43 +05:30
|
|
|
NSStringEncoding stringEncoding = NSUTF32BigEndianStringEncoding;
|
2018-04-11 00:04:48 +01:00
|
|
|
#endif
|
2020-08-19 20:05:45 +01:00
|
|
|
NSString *nsstring = [[NSString alloc] initWithBytes:text.c_str() length:4*text.size() encoding: stringEncoding];
|
|
|
|
bool status = [pb setString:nsstring forType:NSStringPboardType];
|
|
|
|
[nsstring release];
|
|
|
|
return status;
|
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
|
|
|
}
|