1 /* Public Domain Curses */ 2 3 #include "pdcsdl.h" 4 5 #include <stdlib.h> 6 7 /*man-start************************************************************** 8 9 clipboard 10 --------- 11 12 ### Synopsis 13 14 int PDC_getclipboard(char **contents, long *length); 15 int PDC_setclipboard(const char *contents, long length); 16 int PDC_freeclipboard(char *contents); 17 int PDC_clearclipboard(void); 18 19 ### Description 20 21 PDC_getclipboard() gets the textual contents of the system's 22 clipboard. This function returns the contents of the clipboard 23 in the contents argument. It is the responsibilitiy of the 24 caller to free the memory returned, via PDC_freeclipboard(). 25 The length of the clipboard contents is returned in the length 26 argument. 27 28 PDC_setclipboard copies the supplied text into the system's 29 clipboard, emptying the clipboard prior to the copy. 30 31 PDC_clearclipboard() clears the internal clipboard. 32 33 ### Return Values 34 35 indicator of success/failure of call. 36 PDC_CLIP_SUCCESS the call was successful 37 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for 38 the clipboard contents 39 PDC_CLIP_EMPTY the clipboard contains no text 40 PDC_CLIP_ACCESS_ERROR no clipboard support 41 42 ### Portability 43 X/Open BSD SYS V 44 PDC_getclipboard - - - 45 PDC_setclipboard - - - 46 PDC_freeclipboard - - - 47 PDC_clearclipboard - - - 48 49 **man-end****************************************************************/ 50 PDC_getclipboard(char ** contents,long * length)51int PDC_getclipboard(char **contents, long *length) 52 { 53 PDC_LOG(("PDC_getclipboard() - called\n")); 54 55 if (SDL_HasClipboardText() == SDL_FALSE) 56 return PDC_CLIP_EMPTY; 57 *contents = SDL_GetClipboardText(); 58 *length = strlen(*contents); 59 60 return PDC_CLIP_SUCCESS; 61 } 62 PDC_setclipboard(const char * contents,long length)63int PDC_setclipboard(const char *contents, long length) 64 { 65 PDC_LOG(("PDC_setclipboard() - called\n")); 66 67 if (SDL_SetClipboardText(contents) != 0) 68 return PDC_CLIP_ACCESS_ERROR; 69 70 return PDC_CLIP_SUCCESS; 71 } 72 PDC_freeclipboard(char * contents)73int PDC_freeclipboard(char *contents) 74 { 75 PDC_LOG(("PDC_freeclipboard() - called\n")); 76 77 SDL_free(contents); 78 79 return PDC_CLIP_SUCCESS; 80 } 81 PDC_clearclipboard(void)82int PDC_clearclipboard(void) 83 { 84 PDC_LOG(("PDC_clearclipboard() - called\n")); 85 86 if (SDL_HasClipboardText() == SDL_TRUE) 87 { 88 SDL_SetClipboardText(NULL); 89 } 90 91 return PDC_CLIP_SUCCESS; 92 } 93