author | Sam Lantinga |
Fri, 04 Jan 2019 22:01:14 -0800 | |
changeset 12503 | 806492103856 |
parent 11811 | 5d94cb6b24d3 |
child 13422 | fd6a12de91c7 |
permissions | -rw-r--r-- |
slouken@4493 | 1 |
/* |
slouken@5535 | 2 |
Simple DirectMedia Layer |
slouken@12503 | 3 |
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org> |
slouken@4493 | 4 |
|
slouken@5535 | 5 |
This software is provided 'as-is', without any express or implied |
slouken@5535 | 6 |
warranty. In no event will the authors be held liable for any damages |
slouken@5535 | 7 |
arising from the use of this software. |
slouken@4493 | 8 |
|
slouken@5535 | 9 |
Permission is granted to anyone to use this software for any purpose, |
slouken@5535 | 10 |
including commercial applications, and to alter it and redistribute it |
slouken@5535 | 11 |
freely, subject to the following restrictions: |
slouken@4493 | 12 |
|
slouken@5535 | 13 |
1. The origin of this software must not be misrepresented; you must not |
slouken@5535 | 14 |
claim that you wrote the original software. If you use this software |
slouken@5535 | 15 |
in a product, an acknowledgment in the product documentation would be |
slouken@5535 | 16 |
appreciated but is not required. |
slouken@5535 | 17 |
2. Altered source versions must be plainly marked as such, and must not be |
slouken@5535 | 18 |
misrepresented as being the original software. |
slouken@5535 | 19 |
3. This notice may not be removed or altered from any source distribution. |
slouken@4493 | 20 |
*/ |
icculus@8093 | 21 |
#include "../SDL_internal.h" |
slouken@4493 | 22 |
|
slouken@4493 | 23 |
#include "SDL_clipboard.h" |
slouken@4493 | 24 |
#include "SDL_sysvideo.h" |
slouken@4493 | 25 |
|
slouken@4493 | 26 |
|
slouken@4493 | 27 |
int |
slouken@4493 | 28 |
SDL_SetClipboardText(const char *text) |
slouken@4493 | 29 |
{ |
slouken@4495 | 30 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
slouken@4495 | 31 |
|
philipp@9349 | 32 |
if (!_this) { |
philipp@9349 | 33 |
return SDL_SetError("Video subsystem must be initialized to set clipboard text"); |
philipp@9349 | 34 |
} |
philipp@9349 | 35 |
|
slouken@4500 | 36 |
if (!text) { |
slouken@4500 | 37 |
text = ""; |
slouken@4500 | 38 |
} |
slouken@4495 | 39 |
if (_this->SetClipboardText) { |
slouken@4495 | 40 |
return _this->SetClipboardText(_this, text); |
slouken@4495 | 41 |
} else { |
slouken@7719 | 42 |
SDL_free(_this->clipboard_text); |
slouken@4495 | 43 |
_this->clipboard_text = SDL_strdup(text); |
slouken@4495 | 44 |
return 0; |
slouken@4495 | 45 |
} |
slouken@4493 | 46 |
} |
slouken@4493 | 47 |
|
slouken@4493 | 48 |
char * |
slouken@4506 | 49 |
SDL_GetClipboardText(void) |
slouken@4493 | 50 |
{ |
slouken@4495 | 51 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
slouken@4493 | 52 |
|
philipp@9349 | 53 |
if (!_this) { |
philipp@9349 | 54 |
SDL_SetError("Video subsystem must be initialized to get clipboard text"); |
philipp@9349 | 55 |
return SDL_strdup(""); |
philipp@9349 | 56 |
} |
philipp@9349 | 57 |
|
slouken@4495 | 58 |
if (_this->GetClipboardText) { |
slouken@4495 | 59 |
return _this->GetClipboardText(_this); |
slouken@4493 | 60 |
} else { |
slouken@4495 | 61 |
const char *text = _this->clipboard_text; |
slouken@4495 | 62 |
if (!text) { |
slouken@4495 | 63 |
text = ""; |
slouken@4495 | 64 |
} |
slouken@4495 | 65 |
return SDL_strdup(text); |
slouken@4493 | 66 |
} |
slouken@4493 | 67 |
} |
slouken@4493 | 68 |
|
slouken@4493 | 69 |
SDL_bool |
slouken@4506 | 70 |
SDL_HasClipboardText(void) |
slouken@4493 | 71 |
{ |
slouken@4495 | 72 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
slouken@4493 | 73 |
|
philipp@9349 | 74 |
if (!_this) { |
philipp@9349 | 75 |
SDL_SetError("Video subsystem must be initialized to check clipboard text"); |
philipp@9349 | 76 |
return SDL_FALSE; |
philipp@9349 | 77 |
} |
philipp@9349 | 78 |
|
slouken@4495 | 79 |
if (_this->HasClipboardText) { |
slouken@4495 | 80 |
return _this->HasClipboardText(_this); |
slouken@4495 | 81 |
} else { |
slouken@7721 | 82 |
if (_this->clipboard_text && _this->clipboard_text[0] != '\0') { |
slouken@4495 | 83 |
return SDL_TRUE; |
slouken@4495 | 84 |
} else { |
slouken@4495 | 85 |
return SDL_FALSE; |
slouken@4495 | 86 |
} |
slouken@4495 | 87 |
} |
slouken@4493 | 88 |
} |
slouken@4493 | 89 |
|
slouken@4493 | 90 |
/* vi: set ts=4 sw=4 expandtab: */ |