void clip_mch_set_selection(VimClipboard *cbd) { int type; long_u len; char_u *text_clip, vim_clip[2], *str = NULL; PhClipHeader clip_header[2]; /* Prevent recursion from clip_get_selection() */ if (cbd->owned == TRUE) return; cbd->owned = TRUE; clip_get_selection(cbd); cbd->owned = FALSE; type = clip_convert_selection(&str, &len, cbd); if (type >= 0) { text_clip = lalloc(len + 1, TRUE); /* Normal text */ if (text_clip && vim_clip) { memset(clip_header, 0, sizeof(clip_header)); STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8); clip_header[0].length = sizeof(vim_clip); clip_header[0].data = vim_clip; STRNCPY(clip_header[1].type, CLIP_TYPE_TEXT, 8); clip_header[1].length = len + 1; clip_header[1].data = text_clip; switch(type) { default: /* fallthrough to MLINE */ case MLINE: *vim_clip = 'L'; break; case MCHAR: *vim_clip = 'C'; break; case MBLOCK: *vim_clip = 'B'; break; } vim_strncpy(text_clip, str, len); vim_clip[ 1 ] = NUL; PhClipboardCopy(PhInputGroup(NULL), 2, clip_header); } vim_free(text_clip); } vim_free(str); }
void put_scrap(int type, int srclen, char *src) { scrap_type format; int dstlen; #if (defined(WZ_WS_X11) || defined(WZ_WS_WIN) || defined(WZ_WS_QNX)) char *dst; #endif format = convert_format(type); dstlen = convert_data(type, NULL, src, srclen); #if defined(WZ_WS_X11) dst = (char *)malloc(dstlen); if ( dst != NULL ) { Lock_Display(); convert_data(type, dst, src, srclen); XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER0, format, 8, PropModeReplace, (unsigned char *)dst, dstlen); free(dst); if ( lost_scrap() ) XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); Unlock_Display(); } #elif defined(WZ_WS_WIN) /* * */ if ( OpenClipboard(SDL_Window) ) { HANDLE hMem; hMem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), dstlen); if ( hMem != NULL ) { dst = (char *)GlobalLock(hMem); convert_data(type, dst, src, srclen); GlobalUnlock(hMem); EmptyClipboard(); SetClipboardData(format, hMem); } CloseClipboard(); } #elif defined(WZ_WS_QNX) /* * */ #if (_NTO_VERSION < 620) /* before 6.2.0 releases */ { PhClipHeader clheader= {Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; int* cldata; int status; dst = (char *)malloc(dstlen+4); if (dst != NULL) { cldata=(int*)dst; *cldata=type; convert_data(type, dst+4, src, srclen); clheader.data=dst; if (dstlen>65535) { clheader.length=65535; /* maximum photon clipboard size :( */ } else { clheader.length=dstlen+4; } status=PhClipboardCopy(InputGroup, 1, &clheader); if (status==-1) { fprintf(stderr, "Photon: copy to clipboard was failed !\n"); } free(dst); } } #else /* 6.2.0 and 6.2.1 and future releases */ { PhClipboardHdr clheader= {Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; int* cldata; int status; dst = (char *)malloc(dstlen+4); if (dst != NULL) { cldata=(int*)dst; *cldata=type; convert_data(type, dst+4, src, srclen); clheader.data=dst; clheader.length=dstlen+4; status=PhClipboardWrite(InputGroup, 1, &clheader); if (status==-1) { fprintf(stderr, "Photon: copy to clipboard was failed !\n"); } free(dst); } } #endif #endif /* scrap type */ }
static void _clippy_copy_to_sys(int do_sel) { int j; char *dst; char *freeme; #if defined(__QNXNTO__) PhClipboardHdr clheader = {Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; char *tmp; int *cldata; int status; #endif freeme = NULL; if (!_current_selection) { dst = NULL; j = 0; } else #if defined(WIN32) j = strlen(_current_selection); #else if (has_sys_clip) { int i; /* convert to local */ freeme = dst = malloc(strlen(_current_selection)+4); if (!dst) return; for (i = j = 0; _current_selection[i]; i++) { dst[j] = _current_selection[i]; if (dst[j] != '\r') j++; } dst[j] = '\0'; } else { dst = NULL; j = 0; } #endif #if defined(USE_X11) if (has_sys_clip) { lock_display(); if (!dst) dst = (char *) ""; /* blah */ if (j < 0) j = 0; if (do_sel) { if (XGetSelectionOwner(SDL_Display, XA_PRIMARY) != SDL_Window) { XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); } XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER1, XA_STRING, 8, PropModeReplace, (unsigned char *)dst, j); } else { if (XGetSelectionOwner(SDL_Display, atom_clip) != SDL_Window) { XSetSelectionOwner(SDL_Display, atom_clip, SDL_Window, CurrentTime); } XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER0, XA_STRING, 8, PropModeReplace, (unsigned char *)dst, j); XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER1, XA_STRING, 8, PropModeReplace, (unsigned char *)dst, j); } unlock_display(); } #elif defined(WIN32) if (!do_sel && OpenClipboard(SDL_Window)) { _hmem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), j+1); if (_hmem) { dst = (char *)GlobalLock(_hmem); if (dst) { /* this seems wrong, but msdn does this */ memcpy(dst, _current_selection, j); dst[j] = '\0'; GlobalUnlock(_hmem); EmptyClipboard(); SetClipboardData(CF_TEXT, _hmem); } } CloseClipboard(); _hmem = NULL; dst = 0; } #elif defined(__QNXNTO__) if (!do_sel) { tmp = (char *)malloc(j+4); if (!tmp) { cldata=(int*)tmp; *cldata = Ph_CL_TEXT; if (dst) memcpy(tmp+4, dst, j); clheader.data = tmp; #if (NTO_VERSION < 620) if (clheader.length > 65535) clheader.length=65535; #endif clheader.length = j + 4; #if (NTO_VERSION < 620) PhClipboardCopy(inputgroup, 1, &clheader); #else PhClipboardWrite(inputgroup, 1, &clheader); #endif free(tmp); } } #elif defined(MACOSX) if (!do_sel) macosx_clippy_put(_current_clipboard); #else // some other system -- linux without x11, maybe // pretend we used the param to silence warnings (void) do_sel; #endif if (freeme) free(freeme); }