From 23c93fc468b9ccb7b9d9845ab87c1d4005043ab9 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 15 Jul 2009 20:56:48 +0000 Subject: Apply patch from [Bug 2821962] to make binary byte selection transfers work. --- ChangeLog | 5 ++++ unix/tkUnixSelect.c | 74 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a80546..e20be63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-07-15 Donal K. Fellows + + * unix/tkUnixSelect.c (TkSelEventProc, SelRcvIncrProc, SelCvtFromX8): + [Bug 2821962]: Make byte sequence selection transfers possible. + 2009-07-14 Donal K. Fellows * doc/canvas.n (WINDOW ITEMS): [Bug 2326602]: Corrected definition of diff --git a/unix/tkUnixSelect.c b/unix/tkUnixSelect.c index df8c3af..9476e4e 100644 --- a/unix/tkUnixSelect.c +++ b/unix/tkUnixSelect.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixSelect.c,v 1.22 2008/11/08 18:44:40 dkf Exp $ + * RCS: @(#) $Id: tkUnixSelect.c,v 1.23 2009/07/15 20:56:49 dkf Exp $ */ #include "tkInt.h" @@ -93,7 +93,9 @@ static TkSelRetrievalInfo *pendingRetrievals = NULL; static void ConvertSelection(TkWindow *winPtr, XSelectionRequestEvent *eventPtr); static void IncrTimeoutProc(ClientData clientData); -static void SelCvtFromX(long *propPtr, int numValues, Atom type, +static void SelCvtFromX32(long *propPtr, int numValues, Atom type, + Tk_Window tkwin, Tcl_DString *dsPtr); +static void SelCvtFromX8(char *propPtr, int numValues, Atom type, Tk_Window tkwin, Tcl_DString *dsPtr); static long * SelCvtToX(char *string, Atom type, Tk_Window tkwin, int *numLongsPtr); @@ -672,19 +674,23 @@ TkSelEventProc( } else { Tcl_DString ds; - if (format != 32) { + if (format != 32 && format != 8) { char buf[64 + TCL_INTEGER_SPACE]; - sprintf(buf, - "bad format for selection: wanted \"32\", got \"%d\"", - format); + sprintf(buf, "bad format for selection: wanted \"32\" or " + "\"8\", got \"%d\"", format); Tcl_SetResult(retrPtr->interp, buf, TCL_VOLATILE); retrPtr->result = TCL_ERROR; return; } Tcl_DStringInit(&ds); - SelCvtFromX((long *) propInfo, (int) numItems, type, - (Tk_Window) winPtr, &ds); + if (format == 32) { + SelCvtFromX32((long *) propInfo, (int) numItems, type, + (Tk_Window) winPtr, &ds); + } else { + SelCvtFromX8((char *) propInfo, (int) numItems, type, + (Tk_Window) winPtr, &ds); + } interp = retrPtr->interp; Tcl_Preserve(interp); retrPtr->result = retrPtr->proc(retrPtr->clientData, @@ -1251,19 +1257,23 @@ SelRcvIncrProc( } else { Tcl_DString ds; - if (format != 32) { + if (format != 32 && format != 8) { char buf[64 + TCL_INTEGER_SPACE]; - sprintf(buf, - "bad format for selection: wanted \"32\", got \"%d\"", - format); + sprintf(buf, "bad format for selection: wanted \"32\" or " + "\"8\", got \"%d\"", format); Tcl_SetResult(retrPtr->interp, buf, TCL_VOLATILE); retrPtr->result = TCL_ERROR; goto done; } Tcl_DStringInit(&ds); - SelCvtFromX((long *) propInfo, (int) numItems, type, - (Tk_Window) retrPtr->winPtr, &ds); + if (format == 32) { + SelCvtFromX32((long *) propInfo, (int) numItems, type, + (Tk_Window) retrPtr->winPtr, &ds); + } else { + SelCvtFromX8((char *) propInfo, (int) numItems, type, + (Tk_Window) retrPtr->winPtr, &ds); + } interp = retrPtr->interp; Tcl_Preserve(interp); result = retrPtr->proc(retrPtr->clientData, interp, @@ -1447,12 +1457,12 @@ SelCvtToX( /* *---------------------------------------------------------------------- * - * SelCvtFromX -- + * SelCvtFromX32, SelCvtFromX8 -- * - * Given an X property value, formatted as a collection of 32-bit values - * according to "type" and the ICCCM conventions, convert the value to a - * string suitable for manipulation by Tcl. This function is the inverse - * of SelCvtToX. + * Given an X property value, formatted as a collection of 32-bit or + * 8-bit values according to "type" and the ICCCM conventions, convert + * the value to a string suitable for manipulation by Tcl. These + * functions are the inverse of SelCvtToX. * * Results: * The return value (stored in a Tcl_DString) is the string equivalent of @@ -1465,7 +1475,7 @@ SelCvtToX( */ static void -SelCvtFromX( +SelCvtFromX32( register long *propPtr, /* Property value from X. */ int numValues, /* Number of 32-bit values in property. */ Atom type, /* Type of property Should not be XA_STRING @@ -1495,6 +1505,30 @@ SelCvtFromX( } } } + +static void +SelCvtFromX8( + register char *propPtr, /* Property value from X. */ + int numValues, /* Number of 8-bit values in property. */ + Atom type, /* Type of property Should not be XA_STRING + * (if so, don't bother calling this function + * at all). */ + Tk_Window tkwin, /* Window to use for atom conversion. */ + Tcl_DString *dsPtr) /* Where to store the converted string. */ +{ + /* + * Convert each long in the property to a string value, which is a + * hexadecimal string. We build the list in a Tcl_DString because this is + * easier than trying to get the quoting correct ourselves. + */ + + for ( ; numValues > 0; propPtr++, numValues--) { + char buf[12]; + + sprintf(buf, "0x%x", (unsigned char) *propPtr); + Tcl_DStringAppendElement(dsPtr, buf); + } +} /* * Local Variables: -- cgit v0.12