summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m')
-rw-r--r--contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m105
1 files changed, 105 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m b/contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m
new file mode 100644
index 0000000..8ed4eb0
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/uikit/SDL_uikitclipboard.m
@@ -0,0 +1,105 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 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#ifdef SDL_VIDEO_DRIVER_UIKIT
24
25#include "SDL_uikitvideo.h"
26#include "../../events/SDL_clipboardevents_c.h"
27
28#import <UIKit/UIPasteboard.h>
29
30bool UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text)
31{
32#ifdef SDL_PLATFORM_TVOS
33 return SDL_SetError("The clipboard is not available on tvOS");
34#else
35 @autoreleasepool {
36 [UIPasteboard generalPasteboard].string = @(text);
37 return true;
38 }
39#endif
40}
41
42char *UIKit_GetClipboardText(SDL_VideoDevice *_this)
43{
44#ifdef SDL_PLATFORM_TVOS
45 return SDL_strdup(""); // Unsupported.
46#else
47 @autoreleasepool {
48 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
49 NSString *string = pasteboard.string;
50
51 if (string != nil) {
52 return SDL_strdup(string.UTF8String);
53 } else {
54 return SDL_strdup("");
55 }
56 }
57#endif
58}
59
60bool UIKit_HasClipboardText(SDL_VideoDevice *_this)
61{
62 @autoreleasepool {
63#ifndef SDL_PLATFORM_TVOS
64 if ([UIPasteboard generalPasteboard].string != nil) {
65 return true;
66 }
67#endif
68 return false;
69 }
70}
71
72void UIKit_InitClipboard(SDL_VideoDevice *_this)
73{
74#ifndef SDL_PLATFORM_TVOS
75 @autoreleasepool {
76 SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal;
77 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
78
79 id observer = [center addObserverForName:UIPasteboardChangedNotification
80 object:nil
81 queue:nil
82 usingBlock:^(NSNotification *note) {
83 // TODO: compute mime types
84 SDL_SendClipboardUpdate(false, NULL, 0);
85 }];
86
87 data.pasteboardObserver = observer;
88 }
89#endif
90}
91
92void UIKit_QuitClipboard(SDL_VideoDevice *_this)
93{
94 @autoreleasepool {
95 SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal;
96
97 if (data.pasteboardObserver != nil) {
98 [[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver];
99 }
100
101 data.pasteboardObserver = nil;
102 }
103}
104
105#endif // SDL_VIDEO_DRIVER_UIKIT