void XSetSelectionOwner( Display* display, /* X Display. */ Atom selection, /* What selection to own. */ Window owner, /* Window to be the owner. */ Time time) /* The current time? */ { Tk_Window tkwin; TkDisplay *dispPtr; /* * This is a gross hack because the Tk_InternAtom interface is broken. * It expects a Tk_Window, even though it only needs a Tk_Display. */ tkwin = (Tk_Window) TkGetMainInfoList()->winPtr; if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) { /* * Only claim and empty the clipboard if we aren't already the * owner of the clipboard. */ dispPtr = TkGetMainInfoList()->winPtr->dispPtr; if (dispPtr->clipboardActive) { return; } ZeroScrap(); } }
int XSetSelectionOwner( Display *display, Atom selection, Window owner, Time time) { HWND hwnd = owner ? TkWinGetHWND(owner) : NULL; Tk_Window tkwin; /* * This is a gross hack because the Tk_InternAtom interface is broken. It * expects a Tk_Window, even though it only needs a Tk_Display. */ tkwin = (Tk_Window) TkGetMainInfoList()->winPtr; if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) { /* * Only claim and empty the clipboard if we aren't already the owner * of the clipboard. */ if (GetClipboardOwner() != hwnd) { UpdateClipboard(hwnd); } } return Success; }
void TkSuspendClipboard() { TkClipboardTarget *targetPtr; TkClipboardBuffer *cbPtr; TkDisplay *dispPtr; char *buffer, *p, *endPtr, *buffPtr; long length; dispPtr = TkGetDisplayList(); if ((dispPtr == NULL) || !dispPtr->clipboardActive) { return; } for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL; targetPtr = targetPtr->nextPtr) { if (targetPtr->type == XA_STRING) break; } if (targetPtr != NULL) { Tcl_DString encodedText; length = 0; for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL; cbPtr = cbPtr->nextPtr) { length += cbPtr->length; } buffer = ckalloc(length); buffPtr = buffer; for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL; cbPtr = cbPtr->nextPtr) { for (p = cbPtr->buffer, endPtr = p + cbPtr->length; p < endPtr; p++) { if (*p == '\n') { *buffPtr++ = '\r'; } else { *buffPtr++ = *p; } } } ZeroScrap(); Tcl_UtfToExternalDString(NULL, buffer, length, &encodedText); PutScrap(Tcl_DStringLength(&encodedText), 'TEXT', Tcl_DStringValue(&encodedText)); Tcl_DStringFree(&encodedText); ckfree(buffer); } /* * The system now owns the scrap. We tell Tk that it has * lost the selection so that it will look for it the next time * it needs it. (Window list NULL if quiting.) */ if (TkGetMainInfoList() != NULL) { Tk_ClearSelection((Tk_Window) TkGetMainInfoList()->winPtr, Tk_InternAtom((Tk_Window) TkGetMainInfoList()->winPtr, "CLIPBOARD")); } return; }