summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixSelect.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tkUnixSelect.c')
-rw-r--r--unix/tkUnixSelect.c74
1 files changed, 54 insertions, 20 deletions
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: