src/video/SDL_clipboard.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 07 Jul 2010 23:54:03 -0700
changeset 4495 dbbfdb9ea716
parent 4493 f0b7c8d169f5
child 4500 eff4e88cc1e8
permissions -rw-r--r--
Simplified clipboard API for sanity's sake.

A complete clipboard implementation would support multiple formats that could be queried at runtime, events for when the clipboard contents changed, support for HTML, images, etc. We're not going that crazy, at least for now. :)
slouken@4493
     1
/*
slouken@4493
     2
    SDL - Simple DirectMedia Layer
slouken@4493
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@4493
     4
slouken@4493
     5
    This library is free software; you can redistribute it and/or
slouken@4493
     6
    modify it under the terms of the GNU Lesser General Public
slouken@4493
     7
    License as published by the Free Software Foundation; either
slouken@4493
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@4493
     9
slouken@4493
    10
    This library is distributed in the hope that it will be useful,
slouken@4493
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@4493
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@4493
    13
    Lesser General Public License for more details.
slouken@4493
    14
slouken@4493
    15
    You should have received a copy of the GNU Lesser General Public
slouken@4493
    16
    License along with this library; if not, write to the Free Software
slouken@4493
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@4493
    18
slouken@4493
    19
    Sam Lantinga
slouken@4493
    20
    slouken@libsdl.org
slouken@4493
    21
*/
slouken@4493
    22
#include "SDL_config.h"
slouken@4493
    23
slouken@4493
    24
#include "SDL_clipboard.h"
slouken@4493
    25
#include "SDL_sysvideo.h"
slouken@4493
    26
slouken@4493
    27
slouken@4493
    28
int
slouken@4493
    29
SDL_SetClipboardText(const char *text)
slouken@4493
    30
{
slouken@4495
    31
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@4495
    32
slouken@4495
    33
    if (_this->SetClipboardText) {
slouken@4495
    34
        return _this->SetClipboardText(_this, text);
slouken@4495
    35
    } else {
slouken@4495
    36
        _this->clipboard_text = SDL_strdup(text);
slouken@4495
    37
        return 0;
slouken@4495
    38
    }
slouken@4493
    39
}
slouken@4493
    40
slouken@4493
    41
char *
slouken@4493
    42
SDL_GetClipboardText()
slouken@4493
    43
{
slouken@4495
    44
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@4493
    45
slouken@4495
    46
    if (_this->GetClipboardText) {
slouken@4495
    47
        return _this->GetClipboardText(_this);
slouken@4493
    48
    } else {
slouken@4495
    49
        const char *text = _this->clipboard_text;
slouken@4495
    50
        if (!text) {
slouken@4495
    51
            text = "";
slouken@4495
    52
        }
slouken@4495
    53
        return SDL_strdup(text);
slouken@4493
    54
    }
slouken@4493
    55
}
slouken@4493
    56
slouken@4493
    57
SDL_bool
slouken@4493
    58
SDL_HasClipboardText()
slouken@4493
    59
{
slouken@4495
    60
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@4493
    61
slouken@4495
    62
    if (_this->HasClipboardText) {
slouken@4495
    63
        return _this->HasClipboardText(_this);
slouken@4495
    64
    } else {
slouken@4495
    65
        if (_this->clipboard_text) {
slouken@4495
    66
            return SDL_TRUE;
slouken@4495
    67
        } else {
slouken@4495
    68
            return SDL_FALSE;
slouken@4495
    69
        }
slouken@4495
    70
    }
slouken@4493
    71
}
slouken@4493
    72
slouken@4493
    73
/* vi: set ts=4 sw=4 expandtab: */