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