First pass at clipboard API, still very much in progress
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Jul 2010 23:24:04 -0700
changeset 4493f0b7c8d169f5
parent 4492 bff93336121e
child 4494 621dc91c7a04
First pass at clipboard API, still very much in progress
include/SDL.h
include/SDL_clipboard.h
src/video/SDL_clipboard.c
     1.1 --- a/include/SDL.h	Wed Jul 07 21:36:09 2010 -0700
     1.2 +++ b/include/SDL.h	Wed Jul 07 23:24:04 2010 -0700
     1.3 @@ -78,6 +78,7 @@
     1.4  #include "SDL_stdinc.h"
     1.5  #include "SDL_atomic.h"
     1.6  #include "SDL_audio.h"
     1.7 +#include "SDL_clipboard.h"
     1.8  #include "SDL_cpuinfo.h"
     1.9  #include "SDL_endian.h"
    1.10  #include "SDL_error.h"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/include/SDL_clipboard.h	Wed Jul 07 23:24:04 2010 -0700
     2.3 @@ -0,0 +1,125 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2009 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +
    2.26 +/**
    2.27 + * \file SDL_clipboard.h
    2.28 + *
    2.29 + * Include file for SDL clipboard handling
    2.30 + */
    2.31 +
    2.32 +#ifndef _SDL_clipboard_h
    2.33 +#define _SDL_clipboard_h
    2.34 +
    2.35 +#include "SDL_stdinc.h"
    2.36 +#include "SDL_surface.h"
    2.37 +
    2.38 +#include "begin_code.h"
    2.39 +/* Set up for C function definitions, even when using C++ */
    2.40 +#ifdef __cplusplus
    2.41 +/* *INDENT-OFF* */
    2.42 +extern "C" {
    2.43 +/* *INDENT-ON* */
    2.44 +#endif
    2.45 +
    2.46 +/* Function prototypes */
    2.47 +
    2.48 +/**
    2.49 + * \brief Put text into the clipboard
    2.50 + *
    2.51 + * \sa SDL_GetClipboardText()
    2.52 + */
    2.53 +extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
    2.54 +
    2.55 +/**
    2.56 + * \brief Get text from the clipboard, which must be freed with SDL_free()
    2.57 + *
    2.58 + * \sa SDL_SetClipboardText()
    2.59 + */
    2.60 +extern DECLSPEC char * SDLCALL SDL_GetClipboardText();
    2.61 +
    2.62 +/**
    2.63 + * \brief Returns whether the clipboard has text
    2.64 + *
    2.65 + * \sa SDL_GetClipboardText()
    2.66 + */
    2.67 +extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText();
    2.68 +
    2.69 +/**
    2.70 + * \brief Put an image into the clipboard
    2.71 + *
    2.72 + * \sa SDL_GetClipboardImage()
    2.73 + */
    2.74 +extern DECLSPEC int SDLCALL SDL_SetClipboardImage(SDL_Surface *image);
    2.75 +
    2.76 +/**
    2.77 + * \brief Get image from the clipboard, which must be freed with SDL_FreeSurface()
    2.78 + *
    2.79 + * \sa SDL_SetClipboard()
    2.80 + */
    2.81 +extern DECLSPEC SDL_Surface * SDLCALL SDL_GetClipboardImage();
    2.82 +
    2.83 +/**
    2.84 + * \brief Returns whether the clipboard has data in the specified format
    2.85 + *
    2.86 + * \sa SDL_GetClipboardImage()
    2.87 + */
    2.88 +extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardImage();
    2.89 +
    2.90 +/**
    2.91 + * \brief Set the data in the clipboard in the specified format
    2.92 + *
    2.93 + * \sa SDL_GetClipboard()
    2.94 + */
    2.95 +extern DECLSPEC int SDLCALL SDL_SetClipboard(Uint32 format, void *data, size_t length);
    2.96 +
    2.97 +/**
    2.98 + * \brief Get the data in the clipboard in the specified format, which must be
    2.99 + *        freed with SDL_free()
   2.100 + *
   2.101 + * \sa SDL_SetClipboard()
   2.102 + */
   2.103 +extern DECLSPEC int SDLCALL SDL_GetClipboard(Uint32 format, void **data, size_t *length);
   2.104 +
   2.105 +/**
   2.106 + * \brief Returns whether the clipboard has data in the specified format
   2.107 + *
   2.108 + * \sa SDL_GetClipboard()
   2.109 + */
   2.110 +extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardFormat(Uint32 format);
   2.111 +
   2.112 +/**
   2.113 + * \brief Clear any data out of the clipboard, if possible.
   2.114 + */
   2.115 +extern DECLSPEC void SDLCALL SDL_ClearClipboard(void);
   2.116 +
   2.117 +
   2.118 +/* Ends C function definitions when using C++ */
   2.119 +#ifdef __cplusplus
   2.120 +/* *INDENT-OFF* */
   2.121 +}
   2.122 +/* *INDENT-ON* */
   2.123 +#endif
   2.124 +#include "close_code.h"
   2.125 +
   2.126 +#endif /* _SDL_clipboard_h */
   2.127 +
   2.128 +/* vi: set ts=4 sw=4 expandtab: */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/SDL_clipboard.c	Wed Jul 07 23:24:04 2010 -0700
     3.3 @@ -0,0 +1,101 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2010 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#include "SDL_clipboard.h"
    3.28 +#include "SDL_sysvideo.h"
    3.29 +
    3.30 +/* FOURCC values for text and image clipboard formats */
    3.31 +#define TEXT_DATA  SDL_FOURCC('T', 'E', 'X', 'T')
    3.32 +#define IMAGE_DATA SDL_FOURCC('B', 'M', 'P', ' ')
    3.33 +
    3.34 +int
    3.35 +SDL_SetClipboardText(const char *text)
    3.36 +{
    3.37 +    return SDL_SetClipboard(TEXT_DATA, text, SDL_strlen(text)+1);
    3.38 +}
    3.39 +
    3.40 +char *
    3.41 +SDL_GetClipboardText()
    3.42 +{
    3.43 +    void *data;
    3.44 +    size_t length;
    3.45 +
    3.46 +    if (SDL_GetClipboard(TEXT_DATA, &data, &length) == 0) {
    3.47 +        return SDL_static_cast(char*, data);
    3.48 +    } else {
    3.49 +        return NULL;
    3.50 +    }
    3.51 +}
    3.52 +
    3.53 +SDL_bool
    3.54 +SDL_HasClipboardText()
    3.55 +{
    3.56 +    return SDL_HasClipboardFormat(TEXT_DATA);
    3.57 +}
    3.58 +
    3.59 +int
    3.60 +SDL_SetClipboardImage(SDL_Surface *image)
    3.61 +{
    3.62 +    SDL_Unsupported();
    3.63 +    return -1;
    3.64 +}
    3.65 +
    3.66 +SDL_Surface *
    3.67 +SDL_GetClipboardImage()
    3.68 +{
    3.69 +    SDL_Unsupported();
    3.70 +    return NULL;
    3.71 +}
    3.72 +
    3.73 +SDL_bool
    3.74 +SDL_HasClipboardImage()
    3.75 +{
    3.76 +    return SDL_FALSE;
    3.77 +}
    3.78 +
    3.79 +int
    3.80 +SDL_SetClipboard(Uint32 format, void *data, size_t length)
    3.81 +{
    3.82 +    SDL_Unsupported();
    3.83 +    return -1;
    3.84 +}
    3.85 +
    3.86 +int
    3.87 +SDL_GetClipboard(Uint32 format, void **data, size_t *length)
    3.88 +{
    3.89 +    SDL_Unsupported();
    3.90 +    return -1;
    3.91 +}
    3.92 +
    3.93 +SDL_bool
    3.94 +SDL_HasClipboardFormat(Uint32 format)
    3.95 +{
    3.96 +    return SDL_FALSE;
    3.97 +}
    3.98 +
    3.99 +void
   3.100 +SDL_ClearClipboard(void)
   3.101 +{
   3.102 +}
   3.103 +
   3.104 +/* vi: set ts=4 sw=4 expandtab: */