1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include "SDL.h"
#include "SDL_clipboard.h"
#define PYGAME_SCRAP_FREE_STRING 1
char *pygame_scrap_plaintext_type = "text/plain;charset=utf-8";
char **pygame_scrap_types;
int
pygame_scrap_contains(char *type)
{
return (strcmp(type, pygame_scrap_plaintext_type) == 0) &&
SDL_HasClipboardText();
}
char *
pygame_scrap_get(char *type, size_t *count)
{
char *retval = NULL;
char *clipboard = NULL;
if (!pygame_scrap_initialized()) {
PyErr_SetString(pgExc_SDLError, "scrap system not initialized.");
return NULL;
}
if (strcmp(type, pygame_scrap_plaintext_type) == 0) {
clipboard = SDL_GetClipboardText();
if (clipboard != NULL) {
*count = strlen(clipboard);
retval = strdup(clipboard);
SDL_free(clipboard);
return retval;
}
}
return NULL;
}
char **
pygame_scrap_get_types(void)
{
if (!pygame_scrap_initialized()) {
PyErr_SetString(pgExc_SDLError, "scrap system not initialized.");
return NULL;
}
return pygame_scrap_types;
}
int
pygame_scrap_init(void)
{
SDL_Init(SDL_INIT_VIDEO);
pygame_scrap_types = malloc(sizeof(char *) * 2);
if (!pygame_scrap_types) {
return 0;
}
pygame_scrap_types[0] = pygame_scrap_plaintext_type;
pygame_scrap_types[1] = NULL;
_scrapinitialized = 1;
return _scrapinitialized;
}
int
pygame_scrap_lost(void)
{
return 1;
}
int
pygame_scrap_put(char *type, Py_ssize_t srclen, char *src)
{
if (!pygame_scrap_initialized()) {
PyErr_SetString(pgExc_SDLError, "scrap system not initialized.");
return 0;
}
if (strcmp(type, pygame_scrap_plaintext_type) == 0) {
if (SDL_SetClipboardText(src) == 0) {
return 1;
}
}
return 0;
}
|