Skip to content

Latest commit

 

History

History
111 lines (93 loc) · 2.98 KB

SDL_uikitclipboard.m

File metadata and controls

111 lines (93 loc) · 2.98 KB
 
1
/*
Feb 10, 2016
Feb 10, 2016
2
Simple DirectMedia Layer
Jan 2, 2017
Jan 2, 2017
3
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
4
Feb 10, 2016
Feb 10, 2016
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
8
Feb 10, 2016
Feb 10, 2016
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
12
Feb 10, 2016
Feb 10, 2016
13
14
15
16
17
18
19
20
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
21
22
23
24
25
26
27
28
29
30
31
32
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_UIKIT
#include "SDL_uikitvideo.h"
#include "../../events/SDL_clipboardevents_c.h"
#import <UIKit/UIPasteboard.h>
int
UIKit_SetClipboardText(_THIS, const char *text)
{
Sep 14, 2016
Sep 14, 2016
33
34
35
#if TARGET_OS_TV
return SDL_SetError("The clipboard is not available on tvOS");
#else
36
37
38
39
@autoreleasepool {
[UIPasteboard generalPasteboard].string = @(text);
return 0;
}
Sep 14, 2016
Sep 14, 2016
40
#endif
41
42
43
44
45
}
char *
UIKit_GetClipboardText(_THIS)
{
Sep 14, 2016
Sep 14, 2016
46
47
48
#if TARGET_OS_TV
return SDL_strdup(""); // Unsupported.
#else
49
50
51
52
53
54
55
56
57
58
@autoreleasepool {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *string = pasteboard.string;
if (string != nil) {
return SDL_strdup(string.UTF8String);
} else {
return SDL_strdup("");
}
}
Sep 14, 2016
Sep 14, 2016
59
#endif
60
61
62
63
64
65
}
SDL_bool
UIKit_HasClipboardText(_THIS)
{
@autoreleasepool {
Sep 14, 2016
Sep 14, 2016
66
#if !TARGET_OS_TV
67
68
69
if ([UIPasteboard generalPasteboard].string != nil) {
return SDL_TRUE;
}
Sep 14, 2016
Sep 14, 2016
70
#endif
71
72
73
74
75
76
77
return SDL_FALSE;
}
}
void
UIKit_InitClipboard(_THIS)
{
Sep 14, 2016
Sep 14, 2016
78
#if !TARGET_OS_TV
79
80
81
82
83
84
85
86
87
88
89
90
91
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
id observer = [center addObserverForName:UIPasteboardChangedNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
SDL_SendClipboardUpdate();
}];
data.pasteboardObserver = observer;
}
Sep 14, 2016
Sep 14, 2016
92
#endif
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
}
void
UIKit_QuitClipboard(_THIS)
{
@autoreleasepool {
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (data.pasteboardObserver != nil) {
[[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver];
}
data.pasteboardObserver = nil;
}
}
#endif /* SDL_VIDEO_DRIVER_UIKIT */
/* vi: set ts=4 sw=4 expandtab: */