zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_cocoaclipboard.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22 
23 #if SDL_VIDEO_DRIVER_COCOA
24 
25 #include "SDL_cocoavideo.h"
26 #include "../../events/SDL_clipboardevents_c.h"
27 
28 static NSString *
29 GetTextFormat(_THIS)
30 {
32 
33  if (data->osversion >= 0x1060) {
34  return NSPasteboardTypeString;
35  } else {
36  return NSStringPboardType;
37  }
38 }
39 
40 int
41 Cocoa_SetClipboardText(_THIS, const char *text)
42 {
44  NSAutoreleasePool *pool;
45  NSPasteboard *pasteboard;
46  NSString *format = GetTextFormat(_this);
47 
48  pool = [[NSAutoreleasePool alloc] init];
49 
50  pasteboard = [NSPasteboard generalPasteboard];
51  data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
52  [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
53 
54  [pool release];
55 
56  return 0;
57 }
58 
59 char *
61 {
62  NSAutoreleasePool *pool;
63  NSPasteboard *pasteboard;
64  NSString *format = GetTextFormat(_this);
65  NSString *available;
66  char *text;
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 
94 {
96  char *text = Cocoa_GetClipboardText(_this);
97  if (text) {
98  result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
99  SDL_free(text);
100  }
101  return result;
102 }
103 
104 void
106 {
107  NSAutoreleasePool *pool;
108  NSPasteboard *pasteboard;
109  NSInteger count;
110 
111  pool = [[NSAutoreleasePool alloc] init];
112 
113  pasteboard = [NSPasteboard generalPasteboard];
114  count = [pasteboard changeCount];
115  if (count != data->clipboard_count) {
116  if (data->clipboard_count) {
118  }
119  data->clipboard_count = count;
120  }
121 
122  [pool release];
123 }
124 
125 #endif /* SDL_VIDEO_DRIVER_COCOA */
126 
127 /* vi: set ts=4 sw=4 expandtab: */
NSInteger clipboard_count
char * Cocoa_GetClipboardText(_THIS)
SDL_bool
Definition: SDL_stdinc.h:116
DECLSPEC void SDLCALL SDL_free(void *mem)
if(!yyg->yy_init)
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
int Cocoa_SetClipboardText(_THIS, const char *text)
SDL_bool Cocoa_HasClipboardText(_THIS)
GLuint64EXT * result
Definition: glew.h:12708
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
#define _THIS
int SDL_SendClipboardUpdate(void)
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
Definition: SDL_string.c:511
GLint GLsizei count
Definition: gl2ext.h:1011
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
GLsizei const GLcharARB ** string
Definition: glew.h:5638