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