void clip_mch_request_selection(VimClipboard *cbd) { int type = MLINE, clip_length = 0, is_type_set = FALSE; void *cbdata; PhClipHeader *clip_header; char_u *clip_text = NULL; cbdata = PhClipboardPasteStart(PhInputGroup(NULL)); if (cbdata != NULL) { /* Look for the vim specific clip first */ clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM); if (clip_header != NULL && clip_header->data != NULL) { switch(*(char *) clip_header->data) { default: /* fallthrough to line type */ case 'L': type = MLINE; break; case 'C': type = MCHAR; break; case 'B': type = MBLOCK; break; } is_type_set = TRUE; } /* Try for just normal text */ clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT); if (clip_header != NULL) { clip_text = clip_header->data; clip_length = clip_header->length - 1; if (clip_text != NULL && is_type_set == FALSE) type = MAUTO; } if ((clip_text != NULL) && (clip_length > 0)) { clip_yank_selection(type, clip_text, clip_length, cbd); } PhClipboardPasteFinish(cbdata); } }
void get_scrap(int type, int *dstlen, char **dst) { scrap_type format; *dstlen = 0; format = convert_format(type); #if defined(WZ_WS_X11) /* * */ { Window owner; Atom selection; Atom seln_type; int seln_format; unsigned long nbytes; unsigned long overflow; unsigned char * src; Lock_Display(); owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); Unlock_Display(); if ( (owner == None) || (owner == SDL_Window) ) { owner = DefaultRootWindow(SDL_Display); selection = XA_CUT_BUFFER0; } else { int selection_response = 0; SDL_Event event; owner = SDL_Window; Lock_Display(); selection = XInternAtom(SDL_Display, "SDL_SELECTION", False); XConvertSelection(SDL_Display, XA_PRIMARY, format, selection, owner, CurrentTime); Unlock_Display(); while ( ! selection_response ) { SDL_WaitEvent(&event); if ( event.type == SDL_SYSWMEVENT ) { XEvent xevent = event.syswm.msg->event.xevent; if ( (xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner) ) selection_response = 1; } } } Lock_Display(); if ( XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, &src) == Success ) { if ( seln_type == format ) { *dstlen = convert_scrap(type, NULL, (char*)src, nbytes); *dst = (char *)realloc(*dst, *dstlen); if ( *dst == NULL ) *dstlen = 0; else convert_scrap(type, *dst, (char*)src, nbytes); } XFree(src); } Unlock_Display(); } #elif defined(WZ_WS_WIN) /* * */ if ( IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window) ) { HANDLE hMem; char *src; hMem = GetClipboardData(format); if ( hMem != NULL ) { src = (char *)GlobalLock(hMem); *dstlen = convert_scrap(type, NULL, src, 0); *dst = (char *)realloc(*dst, *dstlen); if ( *dst == NULL ) *dstlen = 0; else convert_scrap(type, *dst, src, 0); GlobalUnlock(hMem); } CloseClipboard(); } #elif defined(WZ_WS_QNX) /* * */ #if (_NTO_VERSION < 620) /* before 6.2.0 releases */ { void* clhandle; PhClipHeader* clheader; int* cldata; clhandle=PhClipboardPasteStart(InputGroup); if (clhandle!=NULL) { clheader=PhClipboardPasteType(clhandle, Ph_CLIPBOARD_TYPE_TEXT); if (clheader!=NULL) { cldata=clheader->data; if ((clheader->length>4) && (*cldata==type)) { *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); *dst = (char *)realloc(*dst, *dstlen); if (*dst == NULL) { *dstlen = 0; } else { convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); } } } PhClipboardPasteFinish(clhandle); } } #else /* 6.2.0 and 6.2.1 and future releases */ { void* clhandle; PhClipboardHdr* clheader; int* cldata; clheader=PhClipboardRead(InputGroup, Ph_CLIPBOARD_TYPE_TEXT); if (clheader!=NULL) { cldata=clheader->data; if ((clheader->length>4) && (*cldata==type)) { *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); *dst = (char *)realloc(*dst, *dstlen); if (*dst == NULL) { *dstlen = 0; } else { convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); } } } } #endif #endif /* scrap type */ }
static char *_internal_clippy_paste(int cb) { #if defined(MACOSX) char *src; #endif #if defined(USE_X11) Window owner; int getme; #elif defined(WIN32) char *src; int clen; #elif defined(__QNXNTO__) void *clhandle; PhClipHeader *clheader; int *cldata; #endif if (has_sys_clip) { #if defined(USE_X11) if (cb == CLIPPY_SELECT) { getme = XA_PRIMARY; } else { getme = atom_clip; } lock_display(); owner = XGetSelectionOwner(SDL_Display, getme); unlock_display(); if (owner == None || owner == SDL_Window) { /* fall through to default implementation */ } else { lock_display(); XConvertSelection(SDL_Display, getme, XA_STRING, atom_sel, SDL_Window, CurrentTime); /* at some point in the near future, we'll get a SelectionNotify see _x11_clip_filter for more details; because of this (otherwise) oddity, we take the selection immediately... */ unlock_display(); return NULL; } #else if (cb == CLIPPY_BUFFER) { #if defined(WIN32) if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(SDL_Window)) { _hmem = GetClipboardData(CF_TEXT); if (_hmem) { if (_current_selection != _current_clipboard) { free(_current_clipboard); } _current_clipboard = NULL; src = (char*)GlobalLock(_hmem); if (src) { clen = GlobalSize(_hmem); if (clen > 0) { _current_clipboard = mem_alloc(clen+1); memcpy(_current_clipboard, src, clen); _current_clipboard[clen] = '\0'; } GlobalUnlock(_hmem); } } CloseClipboard(); _hmem = NULL; } #elif defined(__QNXNTO__) if (_current_selection != _current_clipboard) { free(_current_clipboard); } _current_clipboard = NULL; #if (NTO_VERSION < 620) clhandle = PhClipboardPasteStart(inputgroup); if (clhandle) { clheader = PhClipboardPasteType(clhandle, Ph_CLIPBOARD_TYPE_TEXT); if (clheader) { cldata = clheader->data; if (clheader->length > 4 && *cldata == Ph_CL_TEXT) { src = ((char *)clheader->data)+4; clen = clheader->length - 4; _current_clipboard = mem_alloc(clen+1); memcpy(_current_clipboard, src, clen); _current_clipboard[clen] = '\0'; } PhClipboardPasteFinish(clhandle); } } #else /* argh! qnx */ clheader = PhClipboardRead(inputgroup, Ph_CLIPBOARD_TYPE_TEXT); if (clheader) { cldata = clheader->data; if (clheader->length > 4 && *cldata == Ph_CL_TEXT) { src = ((char *)clheader->data)+4; clen = clheader->length - 4; _current_clipboard = mem_alloc(clen+1); memcpy(_current_clipboard, src, clen); _current_clipboard[clen] = '\0'; } } #endif /* NTO version selector */ /* okay, we either own the buffer, or it's a selection for folks without */ #endif /* win32/qnx */ } #endif /* x11/others */ /* fall through; the current window owns it */ } if (cb == CLIPPY_SELECT) return _current_selection; #ifdef MACOSX if (cb == CLIPPY_BUFFER) { src = str_dup(macosx_clippy_get()); if (_current_clipboard != _current_selection) { free(_current_clipboard); } _current_clipboard = src; if (!src) return (char *) ""; /* FIXME: de-const-ing is bad */ return _current_clipboard; } #else if (cb == CLIPPY_BUFFER) return _current_clipboard; #endif return NULL; }