SDL  2.0
SDL_cocoaclipboard.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2019 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 {
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: */
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:381
Cocoa_SetClipboardText
int Cocoa_SetClipboardText(_THIS, const char *text)
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
SDL_cocoavideo.h
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
Cocoa_GetClipboardText
char * Cocoa_GetClipboardText(_THIS)
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_SendClipboardUpdate
int SDL_SendClipboardUpdate(void)
Definition: SDL_clipboardevents.c:31
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
available
static int available()
Definition: video.c:356
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
Cocoa_CheckClipboardUpdate
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
Cocoa_HasClipboardText
SDL_bool Cocoa_HasClipboardText(_THIS)
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:688
SDL_VideoData
Definition: SDL_androidvideo.h:36
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161