comparison src/xselect.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 859a2309aef8
children 54cc21c15cbb
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
369 XmString fmh; 369 XmString fmh;
370 String encoding = (String) "STRING"; 370 String encoding = (String) "STRING";
371 Extbyte *data = XSTRING_DATA (selection_value); 371 Extbyte *data = XSTRING_DATA (selection_value);
372 Extcount bytes = XSTRING_LENGTH (selection_value); 372 Extcount bytes = XSTRING_LENGTH (selection_value);
373 373
374 #ifdef MULE
375 {
376 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
377 CONST Bufbyte *ptr = data, *end = ptr + bytes;
378 /* Optimize for the common ASCII case */
379 while (ptr <= end)
380 {
381 if (BYTE_ASCII_P (*ptr))
382 {
383 ptr++;
384 continue;
385 }
386
387 if ((*ptr) == LEADING_BYTE_LATIN_1 ||
388 (*ptr) == LEADING_BYTE_CONTROL_1)
389 {
390 chartypes = LATIN_1;
391 ptr += 2;
392 continue;
393 }
394
395 chartypes = WORLD;
396 break;
397 }
398
399 switch (chartypes)
400 {
401 case LATIN_1:
402 GET_STRING_BINARY_DATA_ALLOCA (selection_value, data, bytes);
403 break;
404 case WORLD:
405 GET_STRING_CTEXT_DATA_ALLOCA (selection_value, data, bytes);
406 encoding = (String) "COMPOUND_TEXT";
407 break;
408 }
409 }
410 #endif /* MULE */
374 411
375 fmh = XmStringCreateLtoR ((String) "Clipboard", 412 fmh = XmStringCreateLtoR ((String) "Clipboard",
376 XmSTRING_DEFAULT_CHARSET); 413 XmSTRING_DEFAULT_CHARSET);
377 while (ClipboardSuccess != 414 while (ClipboardSuccess !=
378 XmClipboardStartCopy (display, selecting_window, fmh, thyme, 415 XmClipboardStartCopy (display, selecting_window, fmh, thyme,
1339 to be of format 32 if any element is a cons of two integers. 1376 to be of format 32 if any element is a cons of two integers.
1340 1377
1341 When converting an object to C, it may be of the form (SYMBOL . <data>) 1378 When converting an object to C, it may be of the form (SYMBOL . <data>)
1342 where SYMBOL is what we should claim that the type is. Format and 1379 where SYMBOL is what we should claim that the type is. Format and
1343 representation are as above. 1380 representation are as above.
1381
1382 NOTE: Under Mule, when someone shoves us a string without a type, we
1383 set the type to 'COMPOUND_TEXT and automatically convert to Compound
1384 Text. If the string has a type, we assume that the user wants the
1385 data sent as-is so we just do "binary" conversion.
1344 */ 1386 */
1345 1387
1346 1388
1347 static Lisp_Object 1389 static Lisp_Object
1348 selection_data_to_lisp_data (struct device *d, 1390 selection_data_to_lisp_data (struct device *d,
1466 GET_STRING_BINARY_DATA_ALLOCA (obj, extval, extvallen); 1508 GET_STRING_BINARY_DATA_ALLOCA (obj, extval, extvallen);
1467 *format_ret = 8; 1509 *format_ret = 8;
1468 *size_ret = extvallen; 1510 *size_ret = extvallen;
1469 *data_ret = (unsigned char *) xmalloc (*size_ret); 1511 *data_ret = (unsigned char *) xmalloc (*size_ret);
1470 memcpy (*data_ret, extval, *size_ret); 1512 memcpy (*data_ret, extval, *size_ret);
1513 #ifdef MULE
1514 if (NILP (type)) type = QCOMPOUND_TEXT;
1515 #else
1471 if (NILP (type)) type = QSTRING; 1516 if (NILP (type)) type = QSTRING;
1517 #endif
1518 }
1519 else if (CHARP (obj))
1520 {
1521 Bufbyte buf[MAX_EMCHAR_LEN];
1522 Bytecount len;
1523 CONST Extbyte *extval;
1524 Extcount extvallen;
1525
1526 *format_ret = 8;
1527 len = set_charptr_emchar (buf, XCHAR (obj));
1528 GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA (buf, len, extval, extvallen);
1529 *size_ret = extvallen;
1530 *data_ret = (unsigned char *) xmalloc (*size_ret);
1531 memcpy (*data_ret, extval, *size_ret);
1532 #ifdef MULE
1533 if (NILP (type)) type = QCOMPOUND_TEXT;
1534 #else
1535 if (NILP (type)) type = QSTRING;
1536 #endif
1472 } 1537 }
1473 else if (SYMBOLP (obj)) 1538 else if (SYMBOLP (obj))
1474 { 1539 {
1475 *format_ret = 32; 1540 *format_ret = 32;
1476 *size_ret = 1; 1541 *size_ret = 1;
1670 will block until all of the data has arrived. 1735 will block until all of the data has arrived.
1671 */ 1736 */
1672 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, 2, 2, 0, /* 1737 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, 2, 2, 0, /*
1673 Return text selected from some X window. 1738 Return text selected from some X window.
1674 SELECTION is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD. 1739 SELECTION is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
1675 TYPE is the type of data desired, typically STRING. 1740 TYPE is the type of data desired, typically STRING or COMPOUND_TEXT.
1741 Under Mule, if the resultant data comes back as 8-bit data in type
1742 TEXT or COMPOUND_TEXT, it will be decoded as Compound Text.
1676 */ 1743 */
1677 (selection_symbol, target_type)) 1744 (selection_symbol, target_type))
1678 { 1745 {
1679 /* This function can GC */ 1746 /* This function can GC */
1680 Lisp_Object val = Qnil; 1747 Lisp_Object val = Qnil;
1858 if (format != 8 || type != XA_STRING) 1925 if (format != 8 || type != XA_STRING)
1859 signal_simple_error_2 ("Cut buffer doesn't contain 8-bit STRING data", 1926 signal_simple_error_2 ("Cut buffer doesn't contain 8-bit STRING data",
1860 x_atom_to_symbol (d, type), 1927 x_atom_to_symbol (d, type),
1861 make_int (format)); 1928 make_int (format));
1862 1929
1930 /* We cheat - if the string contains an ESC character, that's
1931 technically not allowed in a STRING, so we assume it's
1932 COMPOUND_TEXT that we stored there ourselves earlier,
1933 in x-store-cutbuffer-internal */
1863 ret = (bytes ? 1934 ret = (bytes ?
1864 make_ext_string (data, bytes, 1935 make_ext_string (data, bytes,
1865 FORMAT_BINARY) 1936 memchr (data, 0x1b, bytes) ?
1937 FORMAT_CTEXT : FORMAT_BINARY)
1866 : Qnil); 1938 : Qnil);
1867 xfree (data); 1939 xfree (data);
1868 return ret; 1940 return ret;
1869 } 1941 }
1870 1942
1880 Atom cut_buffer_atom; 1952 Atom cut_buffer_atom;
1881 Extbyte *data = XSTRING_DATA (string); 1953 Extbyte *data = XSTRING_DATA (string);
1882 Extcount bytes = XSTRING_LENGTH (string); 1954 Extcount bytes = XSTRING_LENGTH (string);
1883 Extcount bytes_remaining; 1955 Extcount bytes_remaining;
1884 int max_bytes = SELECTION_QUANTUM (display); 1956 int max_bytes = SELECTION_QUANTUM (display);
1957 #ifdef MULE
1958 CONST Bufbyte *ptr, *end;
1959 Atom encoding = XA_STRING;
1960 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
1961 #endif
1885 1962
1886 if (max_bytes > MAX_SELECTION_QUANTUM) 1963 if (max_bytes > MAX_SELECTION_QUANTUM)
1887 max_bytes = MAX_SELECTION_QUANTUM; 1964 max_bytes = MAX_SELECTION_QUANTUM;
1888 1965
1889 CHECK_CUTBUFFER (cutbuffer); 1966 CHECK_CUTBUFFER (cutbuffer);
1891 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0); 1968 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0);
1892 1969
1893 if (! cut_buffers_initialized) 1970 if (! cut_buffers_initialized)
1894 initialize_cut_buffers (display, window); 1971 initialize_cut_buffers (display, window);
1895 1972
1973 /* We use the STRING encoding (Latin-1 only) if we can, else COMPOUND_TEXT.
1974 We cheat and use type = `STRING' even when using COMPOUND_TEXT.
1975 The ICCCM requires that this be so, and other clients assume it,
1976 as we do ourselves in initialize_cut_buffers. */
1977
1978 #ifdef MULE
1979 /* Optimize for the common ASCII case */
1980 for (ptr = data, end = ptr + bytes; ptr <= end; )
1981 {
1982 if (BYTE_ASCII_P (*ptr))
1983 {
1984 ptr++;
1985 continue;
1986 }
1987
1988 if ((*ptr) == LEADING_BYTE_LATIN_1 ||
1989 (*ptr) == LEADING_BYTE_CONTROL_1)
1990 {
1991 chartypes = LATIN_1;
1992 ptr += 2;
1993 continue;
1994 }
1995
1996 chartypes = WORLD;
1997 break;
1998 }
1999
2000 switch (chartypes)
2001 {
2002 case LATIN_1: GET_STRING_BINARY_DATA_ALLOCA (string, data, bytes); break;
2003 case WORLD: GET_STRING_CTEXT_DATA_ALLOCA (string, data, bytes); break;
2004 }
2005 #endif /* MULE */
2006
1896 bytes_remaining = bytes; 2007 bytes_remaining = bytes;
1897 2008
1898 while (bytes_remaining) 2009 while (bytes_remaining)
1899 { 2010 {
1900 int chunk = bytes_remaining < max_bytes ? bytes_remaining : max_bytes; 2011 int chunk = bytes_remaining < max_bytes ? bytes_remaining : max_bytes;
1936 XRotateWindowProperties (display, window, props, 8, XINT (n)); 2047 XRotateWindowProperties (display, window, props, 8, XINT (n));
1937 return n; 2048 return n;
1938 } 2049 }
1939 2050
1940 #endif /* CUT_BUFFER_SUPPORT */ 2051 #endif /* CUT_BUFFER_SUPPORT */
2052
1941 2053
1942 2054
1943 /************************************************************************/ 2055 /************************************************************************/
1944 /* initialization */ 2056 /* initialization */
1945 /************************************************************************/ 2057 /************************************************************************/
2036 return the value to send to the X server, which should be one of: 2148 return the value to send to the X server, which should be one of:
2037 2149
2038 -- nil (the conversion could not be done) 2150 -- nil (the conversion could not be done)
2039 -- a cons of a symbol and any of the following values; the symbol 2151 -- a cons of a symbol and any of the following values; the symbol
2040 explicitly specifies the type that will be sent. 2152 explicitly specifies the type that will be sent.
2041 -- a string (Will be left as is and sent in the 'STRING format as 8-bit data.) 2153 -- a string (If the type is not specified, then if Mule support exists,
2042 -- a character (Same as for strings.) 2154 the string will be converted to Compound Text and sent in
2155 the 'COMPOUND_TEXT format; otherwise (no Mule support),
2156 the string will be left as-is and sent in the 'STRING
2157 format. If the type is specified, the string will be
2158 left as-is (or converted to binary format under Mule).
2159 In all cases, 8-bit data it sent.)
2160 -- a character (With Mule support, will be converted to Compound Text
2161 whether or not a type is specified. If a type is not
2162 specified, a type of 'STRING or 'COMPOUND_TEXT will be
2163 sent, as for strings.)
2043 -- the symbol 'NULL (Indicates that there is no meaningful return value. 2164 -- the symbol 'NULL (Indicates that there is no meaningful return value.
2044 Empty 32-bit data with a type of 'NULL will be sent.) 2165 Empty 32-bit data with a type of 'NULL will be sent.)
2045 -- a symbol (Will be converted into an atom. If the type is not specified, 2166 -- a symbol (Will be converted into an atom. If the type is not specified,
2046 a type of 'ATOM will be sent.) 2167 a type of 'ATOM will be sent.)
2047 -- an integer (Will be converted into a 16-bit or 32-bit integer depending 2168 -- an integer (Will be converted into a 16-bit or 32-bit integer depending