int scrap_get_win (char *type, char **data, unsigned int *size) { UINT format = _convert_format (type); if (!OpenClipboard (_sdlwindow)) { SDL_SetError ("could not access clipboard"); return -1; } if (!IsClipboardFormatAvailable (format)) { /* The format was not found - was it a mapped type? */ format = _convert_internal_type (type); if (format == (UINT)-1) { CloseClipboard (); SDL_SetError ("no matching format on clipboard found"); return -1; } } if (IsClipboardFormatAvailable (format)) { HANDLE hMem; char *src = NULL; int retval = 0; hMem = GetClipboardData (format); if (hMem) { *size = 0; /* CF_BITMAP is not a global, so do not lock it. */ if (format != CF_BITMAP) { src = GlobalLock (hMem); if (!src) { CloseClipboard (); SDL_SetError ("could not acquire the memory pointer"); return -1; } *size = GlobalSize (hMem); } if (format == CF_DIB || format == CF_DIBV5) { /* size will be increased accordingly in * _create_dib_buffer. */ *data = _create_dib_buffer (src, size); retval = 1; } else if (*size != 0) { *data = malloc (*size); if (*data) { memset (*data, 0, *size); memcpy (*data, src, *size); retval = 1; } else { SDL_SetError ("could not allocate memory"); retval = -1; } } GlobalUnlock (hMem); CloseClipboard (); return retval; } } CloseClipboard (); return 0; }
char* pygame_scrap_get (char *type, unsigned long *count) { UINT format = _convert_format (type); char *retval = NULL; if (!pygame_scrap_initialized ()) { PyErr_SetString (PyExc_SDLError, "scrap system not initialized."); return NULL; } if (!pygame_scrap_lost ()) return Bytes_AsString (PyDict_GetItemString (_clipdata, type)); if (!OpenClipboard (SDL_Window)) return NULL; if (!IsClipboardFormatAvailable (format)) { /* The format was not found - was it a mapped type? */ format = _convert_internal_type (type); if (format == -1) { CloseClipboard (); return NULL; } } if (IsClipboardFormatAvailable (format)) { HANDLE hMem; char *src; src = NULL; hMem = GetClipboardData (format); if (hMem) { *count = 0; /* CF_BITMAP is not a global, so do not lock it. */ if (format != CF_BITMAP) { src = GlobalLock (hMem); if (!src) { CloseClipboard (); return NULL; } *count = GlobalSize (hMem); } if (format == CF_DIB || format == CF_DIBV5) { /* Count will be increased accordingly in * _create_dib_buffer. */ src = _create_dib_buffer (src, count); GlobalUnlock (hMem); CloseClipboard (); return src; } else if (*count != 0) { /* weird error, shouldn't get here. */ if(!src) { return NULL; } retval = malloc (*count); if (retval) { memset (retval, 0, *count); memcpy (retval, src, *count); } } GlobalUnlock (hMem); } } CloseClipboard (); return retval; }