1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/video/cocoa/SDL_cocoaclipboard.m Thu Jul 08 00:35:58 2010 -0700
1.3 @@ -0,0 +1,123 @@
1.4 +/*
1.5 + SDL - Simple DirectMedia Layer
1.6 + Copyright (C) 1997-2010 Sam Lantinga
1.7 +
1.8 + This library is free software; you can redistribute it and/or
1.9 + modify it under the terms of the GNU Lesser General Public
1.10 + License as published by the Free Software Foundation; either
1.11 + version 2.1 of the License, or (at your option) any later version.
1.12 +
1.13 + This library is distributed in the hope that it will be useful,
1.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.16 + Lesser General Public License for more details.
1.17 +
1.18 + You should have received a copy of the GNU Lesser General Public
1.19 + License along with this library; if not, write to the Free Software
1.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1.21 +
1.22 + Sam Lantinga
1.23 + slouken@libsdl.org
1.24 +*/
1.25 +#include "SDL_config.h"
1.26 +
1.27 +#include "SDL_cocoavideo.h"
1.28 +
1.29 +
1.30 +int
1.31 +Cocoa_SetClipboardText(_THIS, const char *text)
1.32 +{
1.33 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
1.34 + NSAutoreleasePool *pool;
1.35 + NSPasteboard *pasteboard;
1.36 + NSString *format;
1.37 +
1.38 + if (data->osversion >= 0x1060) {
1.39 + format = NSPasteboardTypeString;
1.40 + } else {
1.41 + format = NSStringPboardType;
1.42 + }
1.43 +
1.44 + pool = [[NSAutoreleasePool alloc] init];
1.45 +
1.46 + pasteboard = [NSPasteboard generalPasteboard];
1.47 + [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
1.48 + [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
1.49 +
1.50 + [pool release];
1.51 +
1.52 + return 0;
1.53 +}
1.54 +
1.55 +char *
1.56 +Cocoa_GetClipboardText(_THIS)
1.57 +{
1.58 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
1.59 + NSAutoreleasePool *pool;
1.60 + NSPasteboard *pasteboard;
1.61 + NSString *format;
1.62 + NSString *available;
1.63 + char *text;
1.64 +
1.65 + if (data->osversion >= 0x1060) {
1.66 + format = NSPasteboardTypeString;
1.67 + } else {
1.68 + format = NSStringPboardType;
1.69 + }
1.70 +
1.71 + pool = [[NSAutoreleasePool alloc] init];
1.72 +
1.73 + pasteboard = [NSPasteboard generalPasteboard];
1.74 + available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
1.75 + if ([available isEqualToString:format]) {
1.76 + NSString* string;
1.77 + const char *utf8;
1.78 +
1.79 + string = [pasteboard stringForType:format];
1.80 + if (string == nil) {
1.81 + utf8 = "";
1.82 + } else {
1.83 + utf8 = [string UTF8String];
1.84 + }
1.85 + text = SDL_strdup(utf8);
1.86 + } else {
1.87 + text = SDL_strdup("");
1.88 + }
1.89 +
1.90 + [pool release];
1.91 +
1.92 + return text;
1.93 +}
1.94 +
1.95 +SDL_bool
1.96 +Cocoa_HasClipboardText(_THIS)
1.97 +{
1.98 + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
1.99 + NSAutoreleasePool *pool;
1.100 + NSPasteboard *pasteboard;
1.101 + NSString *format;
1.102 + NSString *available;
1.103 + SDL_bool result;
1.104 +
1.105 + if (data->osversion >= 0x1060) {
1.106 + format = NSPasteboardTypeString;
1.107 + } else {
1.108 + format = NSStringPboardType;
1.109 + }
1.110 +
1.111 + pool = [[NSAutoreleasePool alloc] init];
1.112 +
1.113 + pasteboard = [NSPasteboard generalPasteboard];
1.114 + available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
1.115 + if ([available isEqualToString:format]) {
1.116 + result = SDL_TRUE;
1.117 + } else {
1.118 + result = SDL_FALSE;
1.119 + }
1.120 +
1.121 + [pool release];
1.122 +
1.123 + return result;
1.124 +}
1.125 +
1.126 +/* vi: set ts=4 sw=4 expandtab: */