slouken@4493: /* slouken@5535: Simple DirectMedia Layer slouken@11811: Copyright (C) 1997-2018 Sam Lantinga slouken@4493: slouken@5535: This software is provided 'as-is', without any express or implied slouken@5535: warranty. In no event will the authors be held liable for any damages slouken@5535: arising from the use of this software. slouken@4493: slouken@5535: Permission is granted to anyone to use this software for any purpose, slouken@5535: including commercial applications, and to alter it and redistribute it slouken@5535: freely, subject to the following restrictions: slouken@4493: slouken@5535: 1. The origin of this software must not be misrepresented; you must not slouken@5535: claim that you wrote the original software. If you use this software slouken@5535: in a product, an acknowledgment in the product documentation would be slouken@5535: appreciated but is not required. slouken@5535: 2. Altered source versions must be plainly marked as such, and must not be slouken@5535: misrepresented as being the original software. slouken@5535: 3. This notice may not be removed or altered from any source distribution. slouken@4493: */ icculus@8093: #include "../SDL_internal.h" slouken@4493: slouken@4493: #include "SDL_clipboard.h" slouken@4493: #include "SDL_sysvideo.h" slouken@4493: slouken@4493: slouken@4493: int slouken@4493: SDL_SetClipboardText(const char *text) slouken@4493: { slouken@4495: SDL_VideoDevice *_this = SDL_GetVideoDevice(); slouken@4495: philipp@9349: if (!_this) { philipp@9349: return SDL_SetError("Video subsystem must be initialized to set clipboard text"); philipp@9349: } philipp@9349: slouken@4500: if (!text) { slouken@4500: text = ""; slouken@4500: } slouken@4495: if (_this->SetClipboardText) { slouken@4495: return _this->SetClipboardText(_this, text); slouken@4495: } else { slouken@7719: SDL_free(_this->clipboard_text); slouken@4495: _this->clipboard_text = SDL_strdup(text); slouken@4495: return 0; slouken@4495: } slouken@4493: } slouken@4493: slouken@4493: char * slouken@4506: SDL_GetClipboardText(void) slouken@4493: { slouken@4495: SDL_VideoDevice *_this = SDL_GetVideoDevice(); slouken@4493: philipp@9349: if (!_this) { philipp@9349: SDL_SetError("Video subsystem must be initialized to get clipboard text"); philipp@9349: return SDL_strdup(""); philipp@9349: } philipp@9349: slouken@4495: if (_this->GetClipboardText) { slouken@4495: return _this->GetClipboardText(_this); slouken@4493: } else { slouken@4495: const char *text = _this->clipboard_text; slouken@4495: if (!text) { slouken@4495: text = ""; slouken@4495: } slouken@4495: return SDL_strdup(text); slouken@4493: } slouken@4493: } slouken@4493: slouken@4493: SDL_bool slouken@4506: SDL_HasClipboardText(void) slouken@4493: { slouken@4495: SDL_VideoDevice *_this = SDL_GetVideoDevice(); slouken@4493: philipp@9349: if (!_this) { philipp@9349: SDL_SetError("Video subsystem must be initialized to check clipboard text"); philipp@9349: return SDL_FALSE; philipp@9349: } philipp@9349: slouken@4495: if (_this->HasClipboardText) { slouken@4495: return _this->HasClipboardText(_this); slouken@4495: } else { slouken@7721: if (_this->clipboard_text && _this->clipboard_text[0] != '\0') { slouken@4495: return SDL_TRUE; slouken@4495: } else { slouken@4495: return SDL_FALSE; slouken@4495: } slouken@4495: } slouken@4493: } slouken@4493: slouken@4493: /* vi: set ts=4 sw=4 expandtab: */