Commit c2c15058 authored by Sam Lantinga's avatar Sam Lantinga

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. :)
parent b4ac7a28
......@@ -30,7 +30,6 @@
#define _SDL_clipboard_h
#include "SDL_stdinc.h"
#include "SDL_surface.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
......@@ -43,14 +42,14 @@ extern "C" {
/* Function prototypes */
/**
* \brief Put text into the clipboard
* \brief Put UTF-8 text into the clipboard
*
* \sa SDL_GetClipboardText()
*/
extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
/**
* \brief Get text from the clipboard, which must be freed with SDL_free()
* \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free()
*
* \sa SDL_SetClipboardText()
*/
......@@ -63,54 +62,6 @@ extern DECLSPEC char * SDLCALL SDL_GetClipboardText();
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText();
/**
* \brief Put an image into the clipboard
*
* \sa SDL_GetClipboardImage()
*/
extern DECLSPEC int SDLCALL SDL_SetClipboardImage(SDL_Surface *image);
/**
* \brief Get image from the clipboard, which must be freed with SDL_FreeSurface()
*
* \sa SDL_SetClipboard()
*/
extern DECLSPEC SDL_Surface * SDLCALL SDL_GetClipboardImage();
/**
* \brief Returns whether the clipboard has data in the specified format
*
* \sa SDL_GetClipboardImage()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardImage();
/**
* \brief Set the data in the clipboard in the specified format
*
* \sa SDL_GetClipboard()
*/
extern DECLSPEC int SDLCALL SDL_SetClipboard(Uint32 format, void *data, size_t length);
/**
* \brief Get the data in the clipboard in the specified format, which must be
* freed with SDL_free()
*
* \sa SDL_SetClipboard()
*/
extern DECLSPEC int SDLCALL SDL_GetClipboard(Uint32 format, void **data, size_t *length);
/**
* \brief Returns whether the clipboard has data in the specified format
*
* \sa SDL_GetClipboard()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardFormat(Uint32 format);
/**
* \brief Clear any data out of the clipboard, if possible.
*/
extern DECLSPEC void SDLCALL SDL_ClearClipboard(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
......
......@@ -24,78 +24,50 @@
#include "SDL_clipboard.h"
#include "SDL_sysvideo.h"
/* FOURCC values for text and image clipboard formats */
#define TEXT_DATA SDL_FOURCC('T', 'E', 'X', 'T')
#define IMAGE_DATA SDL_FOURCC('B', 'M', 'P', ' ')
int
SDL_SetClipboardText(const char *text)
{
return SDL_SetClipboard(TEXT_DATA, text, SDL_strlen(text)+1);
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this->SetClipboardText) {
return _this->SetClipboardText(_this, text);
} else {
_this->clipboard_text = SDL_strdup(text);
return 0;
}
}
char *
SDL_GetClipboardText()
{
void *data;
size_t length;
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (SDL_GetClipboard(TEXT_DATA, &data, &length) == 0) {
return SDL_static_cast(char*, data);
if (_this->GetClipboardText) {
return _this->GetClipboardText(_this);
} else {
return NULL;
const char *text = _this->clipboard_text;
if (!text) {
text = "";
}
return SDL_strdup(text);
}
}
SDL_bool
SDL_HasClipboardText()
{
return SDL_HasClipboardFormat(TEXT_DATA);
}
int
SDL_SetClipboardImage(SDL_Surface *image)
{
SDL_Unsupported();
return -1;
}
SDL_Surface *
SDL_GetClipboardImage()
{
SDL_Unsupported();
return NULL;
}
SDL_bool
SDL_HasClipboardImage()
{
return SDL_FALSE;
}
int
SDL_SetClipboard(Uint32 format, void *data, size_t length)
{
SDL_Unsupported();
return -1;
}
int
SDL_GetClipboard(Uint32 format, void **data, size_t *length)
{
SDL_Unsupported();
return -1;
}
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_bool
SDL_HasClipboardFormat(Uint32 format)
{
return SDL_FALSE;
}
void
SDL_ClearClipboard(void)
{
if (_this->HasClipboardText) {
return _this->HasClipboardText(_this);
} else {
if (_this->clipboard_text) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
}
/* vi: set ts=4 sw=4 expandtab: */
......@@ -303,6 +303,11 @@ struct SDL_VideoDevice
void (*StopTextInput) (_THIS);
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
/* Clipboard */
int (*SetClipboardText) (_THIS, const char *text);
char * (*GetClipboardText) (_THIS);
SDL_bool (*HasClipboardText) (_THIS);
/* * * */
/* Data common to all drivers */
SDL_bool suspend_screensaver;
......@@ -312,6 +317,7 @@ struct SDL_VideoDevice
Uint8 window_magic;
Uint8 texture_magic;
Uint32 next_object_id;
char * clipboard_text;
/* * * */
/* Data used by the GL drivers */
......
......@@ -2833,6 +2833,10 @@ SDL_VideoQuit(void)
SDL_free(_this->displays);
_this->displays = NULL;
}
if (_this->clipboard_text) {
SDL_free(_this->clipboard_text);
_this->clipboard_text = NULL;
}
_this->free(_this);
_this = NULL;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment