1 | /* |
---|---|
2 | Simple DirectMedia Layer |
3 | Copyright (C) 1997-2021 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 | #include "SDL_clipboard.h" |
24 | #include "SDL_sysvideo.h" |
25 | |
26 | |
27 | int |
28 | SDL_SetClipboardText(const char *text) |
29 | { |
30 | SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
31 | |
32 | if (!_this) { |
33 | return SDL_SetError("Video subsystem must be initialized to set clipboard text"); |
34 | } |
35 | |
36 | if (!text) { |
37 | text = ""; |
38 | } |
39 | if (_this->SetClipboardText) { |
40 | return _this->SetClipboardText(_this, text); |
41 | } else { |
42 | SDL_free(_this->clipboard_text); |
43 | _this->clipboard_text = SDL_strdup(text); |
44 | return 0; |
45 | } |
46 | } |
47 | |
48 | char * |
49 | SDL_GetClipboardText(void) |
50 | { |
51 | SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
52 | |
53 | if (!_this) { |
54 | SDL_SetError("Video subsystem must be initialized to get clipboard text"); |
55 | return SDL_strdup(""); |
56 | } |
57 | |
58 | if (_this->GetClipboardText) { |
59 | return _this->GetClipboardText(_this); |
60 | } else { |
61 | const char *text = _this->clipboard_text; |
62 | if (!text) { |
63 | text = ""; |
64 | } |
65 | return SDL_strdup(text); |
66 | } |
67 | } |
68 | |
69 | SDL_bool |
70 | SDL_HasClipboardText(void) |
71 | { |
72 | SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
73 | |
74 | if (!_this) { |
75 | SDL_SetError("Video subsystem must be initialized to check clipboard text"); |
76 | return SDL_FALSE; |
77 | } |
78 | |
79 | if (_this->HasClipboardText) { |
80 | return _this->HasClipboardText(_this); |
81 | } else { |
82 | if (_this->clipboard_text && _this->clipboard_text[0] != '\0') { |
83 | return SDL_TRUE; |
84 | } else { |
85 | return SDL_FALSE; |
86 | } |
87 | } |
88 | } |
89 | |
90 | /* vi: set ts=4 sw=4 expandtab: */ |
91 |