/* PDCurses */12#include "pdcwin.h"34#include <string.h>56/*man-start**************************************************************78clipboard9---------1011### Synopsis1213int PDC_getclipboard(char **contents, long *length);14int PDC_setclipboard(const char *contents, long length);15int PDC_freeclipboard(char *contents);16int PDC_clearclipboard(void);1718### Description1920PDC_getclipboard() gets the textual contents of the system's21clipboard. This function returns the contents of the clipboard in the22contents argument. It is the responsibility of the caller to free the23memory returned, via PDC_freeclipboard(). The length of the clipboard24contents is returned in the length argument.2526PDC_setclipboard copies the supplied text into the system's27clipboard, emptying the clipboard prior to the copy.2829PDC_clearclipboard() clears the internal clipboard.3031### Return Values3233indicator of success/failure of call.34PDC_CLIP_SUCCESS the call was successful35PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for36the clipboard contents37PDC_CLIP_EMPTY the clipboard contains no text38PDC_CLIP_ACCESS_ERROR no clipboard support3940### Portability41X/Open ncurses NetBSD42PDC_getclipboard - - -43PDC_setclipboard - - -44PDC_freeclipboard - - -45PDC_clearclipboard - - -4647**man-end****************************************************************/4849#ifdef PDC_WIDE50# define PDC_TEXT CF_UNICODETEXT51#else52# define PDC_TEXT CF_OEMTEXT53#endif5455int PDC_getclipboard(char **contents, long *length)56{57HANDLE handle;58long len;5960PDC_LOG(("PDC_getclipboard() - called\n"));6162if (!OpenClipboard(NULL))63return PDC_CLIP_ACCESS_ERROR;6465if ((handle = GetClipboardData(PDC_TEXT)) == NULL)66{67CloseClipboard();68return PDC_CLIP_EMPTY;69}7071#ifdef PDC_WIDE72len = wcslen((wchar_t *)handle) * 3;73#else74len = strlen((char *)handle);75#endif76*contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1);7778if (!*contents)79{80CloseClipboard();81return PDC_CLIP_MEMORY_ERROR;82}8384#ifdef PDC_WIDE85len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len);86#else87strcpy((char *)*contents, (char *)handle);88#endif89*length = len;90CloseClipboard();9192return PDC_CLIP_SUCCESS;93}9495int PDC_setclipboard(const char *contents, long length)96{97HGLOBAL ptr1;98LPTSTR ptr2;99100PDC_LOG(("PDC_setclipboard() - called\n"));101102if (!OpenClipboard(NULL))103return PDC_CLIP_ACCESS_ERROR;104105ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,106(length + 1) * sizeof(TCHAR));107108if (!ptr1)109return PDC_CLIP_MEMORY_ERROR;110111ptr2 = GlobalLock(ptr1);112113#ifdef PDC_WIDE114PDC_mbstowcs((wchar_t *)ptr2, contents, length);115#else116memcpy((char *)ptr2, contents, length + 1);117#endif118GlobalUnlock(ptr1);119EmptyClipboard();120121if (!SetClipboardData(PDC_TEXT, ptr1))122{123GlobalFree(ptr1);124return PDC_CLIP_ACCESS_ERROR;125}126127CloseClipboard();128GlobalFree(ptr1);129130return PDC_CLIP_SUCCESS;131}132133int PDC_freeclipboard(char *contents)134{135PDC_LOG(("PDC_freeclipboard() - called\n"));136137GlobalFree(contents);138return PDC_CLIP_SUCCESS;139}140141int PDC_clearclipboard(void)142{143PDC_LOG(("PDC_clearclipboard() - called\n"));144145EmptyClipboard();146147return PDC_CLIP_SUCCESS;148}149150151