src/video/SDL_clipboard.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 29 Aug 2013 08:30:21 -0700
changeset 7721 bdf8c2c84e14
parent 7719 31b5f9ff36ca
child 8093 b43765095a6f
permissions -rw-r--r--
Christoph Mallon: Replace strlen(x) == 0 (O(n)) by x[0] == '\0' (O(1)).
slouken@4493
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 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
*/
slouken@4493
    21
#include "SDL_config.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
slouken@4500
    32
    if (!text) {
slouken@4500
    33
        text = "";
slouken@4500
    34
    }
slouken@4495
    35
    if (_this->SetClipboardText) {
slouken@4495
    36
        return _this->SetClipboardText(_this, text);
slouken@4495
    37
    } else {
slouken@7719
    38
        SDL_free(_this->clipboard_text);
slouken@4495
    39
        _this->clipboard_text = SDL_strdup(text);
slouken@4495
    40
        return 0;
slouken@4495
    41
    }
slouken@4493
    42
}
slouken@4493
    43
slouken@4493
    44
char *
slouken@4506
    45
SDL_GetClipboardText(void)
slouken@4493
    46
{
slouken@4495
    47
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@4493
    48
slouken@4495
    49
    if (_this->GetClipboardText) {
slouken@4495
    50
        return _this->GetClipboardText(_this);
slouken@4493
    51
    } else {
slouken@4495
    52
        const char *text = _this->clipboard_text;
slouken@4495
    53
        if (!text) {
slouken@4495
    54
            text = "";
slouken@4495
    55
        }
slouken@4495
    56
        return SDL_strdup(text);
slouken@4493
    57
    }
slouken@4493
    58
}
slouken@4493
    59
slouken@4493
    60
SDL_bool
slouken@4506
    61
SDL_HasClipboardText(void)
slouken@4493
    62
{
slouken@4495
    63
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@4493
    64
slouken@4495
    65
    if (_this->HasClipboardText) {
slouken@4495
    66
        return _this->HasClipboardText(_this);
slouken@4495
    67
    } else {
slouken@7721
    68
        if (_this->clipboard_text && _this->clipboard_text[0] != '\0') {
slouken@4495
    69
            return SDL_TRUE;
slouken@4495
    70
        } else {
slouken@4495
    71
            return SDL_FALSE;
slouken@4495
    72
        }
slouken@4495
    73
    }
slouken@4493
    74
}
slouken@4493
    75
slouken@4493
    76
/* vi: set ts=4 sw=4 expandtab: */