Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoaclipboard.m @ 4499:c2ebe3e020c6
Added Mac OS X implementation of clipboard support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 08 Jul 2010 00:35:58 -0700 |
parents | |
children | 0cf025066b6f |
comparison
equal
deleted
inserted
replaced
4498:3d91e31fcf71 | 4499:c2ebe3e020c6 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2010 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 #include "SDL_config.h" | |
23 | |
24 #include "SDL_cocoavideo.h" | |
25 | |
26 | |
27 int | |
28 Cocoa_SetClipboardText(_THIS, const char *text) | |
29 { | |
30 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
31 NSAutoreleasePool *pool; | |
32 NSPasteboard *pasteboard; | |
33 NSString *format; | |
34 | |
35 if (data->osversion >= 0x1060) { | |
36 format = NSPasteboardTypeString; | |
37 } else { | |
38 format = NSStringPboardType; | |
39 } | |
40 | |
41 pool = [[NSAutoreleasePool alloc] init]; | |
42 | |
43 pasteboard = [NSPasteboard generalPasteboard]; | |
44 [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; | |
45 [pasteboard setString:[NSString stringWithUTF8String:text] forType:format]; | |
46 | |
47 [pool release]; | |
48 | |
49 return 0; | |
50 } | |
51 | |
52 char * | |
53 Cocoa_GetClipboardText(_THIS) | |
54 { | |
55 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
56 NSAutoreleasePool *pool; | |
57 NSPasteboard *pasteboard; | |
58 NSString *format; | |
59 NSString *available; | |
60 char *text; | |
61 | |
62 if (data->osversion >= 0x1060) { | |
63 format = NSPasteboardTypeString; | |
64 } else { | |
65 format = NSStringPboardType; | |
66 } | |
67 | |
68 pool = [[NSAutoreleasePool alloc] init]; | |
69 | |
70 pasteboard = [NSPasteboard generalPasteboard]; | |
71 available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; | |
72 if ([available isEqualToString:format]) { | |
73 NSString* string; | |
74 const char *utf8; | |
75 | |
76 string = [pasteboard stringForType:format]; | |
77 if (string == nil) { | |
78 utf8 = ""; | |
79 } else { | |
80 utf8 = [string UTF8String]; | |
81 } | |
82 text = SDL_strdup(utf8); | |
83 } else { | |
84 text = SDL_strdup(""); | |
85 } | |
86 | |
87 [pool release]; | |
88 | |
89 return text; | |
90 } | |
91 | |
92 SDL_bool | |
93 Cocoa_HasClipboardText(_THIS) | |
94 { | |
95 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
96 NSAutoreleasePool *pool; | |
97 NSPasteboard *pasteboard; | |
98 NSString *format; | |
99 NSString *available; | |
100 SDL_bool result; | |
101 | |
102 if (data->osversion >= 0x1060) { | |
103 format = NSPasteboardTypeString; | |
104 } else { | |
105 format = NSStringPboardType; | |
106 } | |
107 | |
108 pool = [[NSAutoreleasePool alloc] init]; | |
109 | |
110 pasteboard = [NSPasteboard generalPasteboard]; | |
111 available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; | |
112 if ([available isEqualToString:format]) { | |
113 result = SDL_TRUE; | |
114 } else { | |
115 result = SDL_FALSE; | |
116 } | |
117 | |
118 [pool release]; | |
119 | |
120 return result; | |
121 } | |
122 | |
123 /* vi: set ts=4 sw=4 expandtab: */ |