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
28int
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
43char *
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;
80 }
81 return result;
82}
83
84void
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: */
#define _THIS
int SDL_SendClipboardUpdate(void)
void Cocoa_CheckClipboardUpdate(struct SDL_VideoData *data)
char * Cocoa_GetClipboardText(_THIS)
int Cocoa_SetClipboardText(_THIS, const char *text)
SDL_bool Cocoa_HasClipboardText(_THIS)
#define SDL_free
#define SDL_strdup
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
GLuint64EXT * result
GLsizei const GLchar *const * string
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
static int available()
Definition: video.c:356