Atlas - SDL_uikitclipboard.m

Home / ext / SDL / src / video / uikit Lines: 1 | Size: 3659 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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 SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal; 37 data.setting_clipboard = true; 38 if (text && *text) { 39 [UIPasteboard generalPasteboard].string = @(text); 40 } else { 41 [UIPasteboard generalPasteboard].string = nil; 42 } 43 data.setting_clipboard = false; 44 return true; 45 } 46#endif 47} 48 49char *UIKit_GetClipboardText(SDL_VideoDevice *_this) 50{ 51#ifdef SDL_PLATFORM_TVOS 52 return SDL_strdup(""); // Unsupported. 53#else 54 @autoreleasepool { 55 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 56 NSString *string = pasteboard.string; 57 58 if (string != nil) { 59 return SDL_strdup(string.UTF8String); 60 } else { 61 return SDL_strdup(""); 62 } 63 } 64#endif 65} 66 67bool UIKit_HasClipboardText(SDL_VideoDevice *_this) 68{ 69 @autoreleasepool { 70#ifndef SDL_PLATFORM_TVOS 71 if ([UIPasteboard generalPasteboard].hasStrings) { 72 return true; 73 } 74#endif 75 return false; 76 } 77} 78 79void UIKit_InitClipboard(SDL_VideoDevice *_this) 80{ 81#ifndef SDL_PLATFORM_TVOS 82 @autoreleasepool { 83 SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal; 84 NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 85 86 id observer = [center addObserverForName:UIPasteboardChangedNotification 87 object:nil 88 queue:nil 89 usingBlock:^(NSNotification *note) { 90 if (!data.setting_clipboard) { 91 // TODO: compute mime types 92 SDL_SendClipboardUpdate(false, NULL, 0); 93 } 94 }]; 95 96 data.pasteboardObserver = observer; 97 data.setting_clipboard = false; 98 } 99#endif 100} 101 102void UIKit_QuitClipboard(SDL_VideoDevice *_this) 103{ 104 @autoreleasepool { 105 SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal; 106 107 if (data.pasteboardObserver != nil) { 108 [[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver]; 109 } 110 111 data.pasteboardObserver = nil; 112 } 113} 114 115#endif // SDL_VIDEO_DRIVER_UIKIT 116
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.