Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoaclipboard.m @ 4501:0cf025066b6f
Updated Xcode project files for clipboard API
Fixed generation of SDL_revision.h when hg is in the path set up in .bash_profile
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 08 Jul 2010 06:16:27 -0700 |
parents | c2ebe3e020c6 |
children | 524dfefd554c |
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 |
4501
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
26 static NSString * |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
27 GetTextFormat(_THIS) |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
28 { |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
29 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
30 return NSStringPboardType; |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
31 #else |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
32 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
33 |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
34 if (data->osversion >= 0x1060) { |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
35 return NSPasteboardTypeString; |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
36 } else { |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
37 return NSStringPboardType; |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
38 } |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
39 #endif |
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
40 } |
4499
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 int |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 Cocoa_SetClipboardText(_THIS, const char *text) |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 NSAutoreleasePool *pool; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 NSPasteboard *pasteboard; |
4501
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
47 NSString *format = GetTextFormat(_this); |
4499
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 pool = [[NSAutoreleasePool alloc] init]; |
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 pasteboard = [NSPasteboard generalPasteboard]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 [pasteboard setString:[NSString stringWithUTF8String:text] forType:format]; |
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 [pool release]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 return 0; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 } |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 char * |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 Cocoa_GetClipboardText(_THIS) |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 NSAutoreleasePool *pool; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 NSPasteboard *pasteboard; |
4501
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
65 NSString *format = GetTextFormat(_this); |
4499
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 NSString *available; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 char *text; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 pool = [[NSAutoreleasePool alloc] init]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 pasteboard = [NSPasteboard generalPasteboard]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 if ([available isEqualToString:format]) { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 NSString* string; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 const char *utf8; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 string = [pasteboard stringForType:format]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 if (string == nil) { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 utf8 = ""; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } else { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 utf8 = [string UTF8String]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 text = SDL_strdup(utf8); |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 } else { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 text = SDL_strdup(""); |
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 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 [pool release]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 return text; |
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 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 SDL_bool |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 Cocoa_HasClipboardText(_THIS) |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 { |
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; |
4501
0cf025066b6f
Updated Xcode project files for clipboard API
Sam Lantinga <slouken@libsdl.org>
parents:
4499
diff
changeset
|
98 NSString *format = GetTextFormat(_this); |
4499
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 pool = [[NSAutoreleasePool alloc] init]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 pasteboard = [NSPasteboard generalPasteboard]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 if ([available isEqualToString:format]) { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 result = SDL_TRUE; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } else { |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 result = SDL_FALSE; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 [pool release]; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 return result; |
c2ebe3e020c6
Added Mac OS X implementation of clipboard support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 } |
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 /* vi: set ts=4 sw=4 expandtab: */ |