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