SDL  2.0
SDL_cocoaclipboard.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 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_internal.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 {
31  if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
32  return NSPasteboardTypeString;
33  } else {
34  return NSStringPboardType;
35  }
36 }
37 
38 int
39 Cocoa_SetClipboardText(_THIS, const char *text)
40 { @autoreleasepool
41 {
43  NSPasteboard *pasteboard;
44  NSString *format = GetTextFormat(_this);
45 
46  pasteboard = [NSPasteboard generalPasteboard];
47  data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
48  [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
49 
50  return 0;
51 }}
52 
53 char *
55 { @autoreleasepool
56 {
57  NSPasteboard *pasteboard;
58  NSString *format = GetTextFormat(_this);
59  NSString *available;
60  char *text;
61 
62  pasteboard = [NSPasteboard generalPasteboard];
63  available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
64  if ([available isEqualToString:format]) {
65  NSString* string;
66  const char *utf8;
67 
68  string = [pasteboard stringForType:format];
69  if (string == nil) {
70  utf8 = "";
71  } else {
72  utf8 = [string UTF8String];
73  }
74  text = SDL_strdup(utf8);
75  } else {
76  text = SDL_strdup("");
77  }
78 
79  return text;
80 }}
81 
84 {
86  char *text = Cocoa_GetClipboardText(_this);
87  if (text) {
88  result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
89  SDL_free(text);
90  }
91  return result;
92 }
93 
94 void
96 { @autoreleasepool
97 {
98  NSPasteboard *pasteboard;
99  NSInteger count;
100 
101  pasteboard = [NSPasteboard generalPasteboard];
102  count = [pasteboard changeCount];
103  if (count != data->clipboard_count) {
104  if (data->clipboard_count) {
106  }
107  data->clipboard_count = count;
108  }
109 }}
110 
111 #endif /* SDL_VIDEO_DRIVER_COCOA */
112 
113 /* vi: set ts=4 sw=4 expandtab: */
NSInteger clipboard_count
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
char * Cocoa_GetClipboardText(_THIS)
GLuint64EXT * result
GLsizei const GLchar *const * string
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
SDL_bool
Definition: SDL_stdinc.h:126
int Cocoa_SetClipboardText(_THIS, const char *text)
SDL_bool Cocoa_HasClipboardText(_THIS)
#define _THIS
int SDL_SendClipboardUpdate(void)
void SDL_free(void *mem)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:34
#define SDL_strdup
#define floor
Definition: math_private.h:37