ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

macosx_wrapper.mm

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Disable symbol overrides so that we can use system headers.
00024 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00025 
00026 #include "backends/platform/sdl/macosx/macosx_wrapper.h"
00027 #include "common/translation.h"
00028 
00029 #include <AppKit/NSPasteboard.h>
00030 #include <Foundation/NSArray.h>
00031 #include <Foundation/NSPathUtilities.h>
00032 #include <AvailabilityMacros.h>
00033 #include <CoreFoundation/CFString.h>
00034 
00035 bool hasTextInClipboardMacOSX() {
00036     return [[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]] != nil;
00037 }
00038 
00039 Common::String getTextFromClipboardMacOSX() {
00040     if (!hasTextInClipboardMacOSX())
00041         return Common::String();
00042     // Note: on OS X 10.6 and above it is recommanded to use NSPasteboardTypeString rather than NSStringPboardType.
00043     // But since we still target older version use NSStringPboardType.
00044     NSPasteboard *pb = [NSPasteboard generalPasteboard];
00045     NSString *str = [pb  stringForType:NSStringPboardType];
00046     if (str == nil)
00047         return Common::String();
00048 
00049     // If translations are supported, use the current TranslationManager charset and otherwise
00050     // use ASCII. If the string cannot be represented using the requested encoding we get a null
00051     // pointer below, which is fine as ScummVM would not know what to do with the string anyway.
00052 #ifdef USE_TRANSLATION
00053     NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
00054     NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
00055 #else
00056     NSStringEncoding encoding = NSISOLatin1StringEncoding;
00057 #endif
00058     return Common::String([str cStringUsingEncoding:encoding]);
00059 }
00060 
00061 bool setTextInClipboardMacOSX(const Common::String &text) {
00062     NSPasteboard *pb = [NSPasteboard generalPasteboard];
00063     [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
00064 
00065 #ifdef USE_TRANSLATION
00066     NSString* encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
00067     NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr));
00068 #else
00069     NSStringEncoding encoding = NSISOLatin1StringEncoding;
00070 #endif
00071     return [pb setString:[NSString stringWithCString:text.c_str() encoding:encoding] forType:NSStringPboardType];
00072 }
00073 
00074 Common::String getDesktopPathMacOSX() {
00075     // The recommanded method is to use NSFileManager.
00076     // NSUrl *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask] firstObject];
00077     // However it is only available in OS X 10.6+. So use NSSearchPathForDirectoriesInDomains instead (available since OS X 10.0)
00078     // [NSArray firstObject] is also only available in OS X 10.6+. So we need to use [NSArray count] and [NSArray objectAtIndex:]
00079     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
00080     if ([paths count] == 0)
00081         return Common::String();
00082     NSString *path = [paths objectAtIndex:0];
00083     if (path == nil)
00084         return Common::String();
00085     return Common::String([path cStringUsingEncoding:NSASCIIStringEncoding]);
00086 }


Generated on Sat Feb 16 2019 05:00:57 for ResidualVM by doxygen 1.7.1
curved edge   curved edge