Mercurial > hg > xemacs-beta
comparison src/xselect.c @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | ac2d302a0011 |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
365 long dataid; | 365 long dataid; |
366 #else | 366 #else |
367 int dataid; /* 1.2 wants long, but 1.1.5 wants int... */ | 367 int dataid; /* 1.2 wants long, but 1.1.5 wants int... */ |
368 #endif | 368 #endif |
369 XmString fmh; | 369 XmString fmh; |
370 String encoding = (String) "STRING"; | |
371 Extbyte *data = XSTRING_DATA (selection_value); | |
372 Extcount bytes = XSTRING_LENGTH (selection_value); | |
373 | |
374 | |
370 fmh = XmStringCreateLtoR ((String) "Clipboard", | 375 fmh = XmStringCreateLtoR ((String) "Clipboard", |
371 XmSTRING_DEFAULT_CHARSET); | 376 XmSTRING_DEFAULT_CHARSET); |
372 while (ClipboardSuccess != | 377 while (ClipboardSuccess != |
373 XmClipboardStartCopy (display, selecting_window, fmh, thyme, | 378 XmClipboardStartCopy (display, selecting_window, fmh, thyme, |
374 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK | 379 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK |
378 #endif | 383 #endif |
379 &itemid)) | 384 &itemid)) |
380 ; | 385 ; |
381 XmStringFree (fmh); | 386 XmStringFree (fmh); |
382 while (ClipboardSuccess != | 387 while (ClipboardSuccess != |
383 XmClipboardCopy (display, selecting_window, itemid, | 388 XmClipboardCopy (display, selecting_window, itemid, encoding, |
384 (String) "STRING", | |
385 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK | 389 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK |
386 /* O'Reilly examples say size can be 0, | 390 /* O'Reilly examples say size can be 0, |
387 but this clearly is not the case. */ | 391 but this clearly is not the case. */ |
388 0, string_length (XSTRING (selection_value)) + 1, | 392 0, bytes, (int) selecting_window, /* private id */ |
389 (int) selecting_window, /* private id */ | |
390 #else /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */ | 393 #else /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */ |
391 (char *) string_data (XSTRING (selection_value)), | 394 (XtPointer) data, bytes, 0, |
392 string_length (XSTRING (selection_value)) + 1, | |
393 0, | |
394 #endif /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */ | 395 #endif /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */ |
395 &dataid)) | 396 &dataid)) |
396 ; | 397 ; |
397 while (ClipboardSuccess != | 398 while (ClipboardSuccess != |
398 XmClipboardEndCopy (display, selecting_window, itemid)) | 399 XmClipboardEndCopy (display, selecting_window, itemid)) |
421 Lisp_Object selection = assq_no_quit (QCLIPBOARD, Vselection_alist); | 422 Lisp_Object selection = assq_no_quit (QCLIPBOARD, Vselection_alist); |
422 if (NILP (selection)) abort (); | 423 if (NILP (selection)) abort (); |
423 selection = XCDR (selection); | 424 selection = XCDR (selection); |
424 if (!STRINGP (selection)) abort (); | 425 if (!STRINGP (selection)) abort (); |
425 XmClipboardCopyByName (dpy, window, *data_id, | 426 XmClipboardCopyByName (dpy, window, *data_id, |
426 (char *) string_data (XSTRING (selection)), | 427 (char *) XSTRING_DATA (selection), |
427 string_length (XSTRING (selection)) + 1, | 428 XSTRING_LENGTH (selection) + 1, |
428 0); | 429 0); |
429 } | 430 } |
430 break; | 431 break; |
431 case XmCR_CLIPBOARD_DATA_DELETE: | 432 case XmCR_CLIPBOARD_DATA_DELETE: |
432 default: | 433 default: |
1818 | 1819 |
1819 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */ | 1820 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */ |
1820 static void | 1821 static void |
1821 initialize_cut_buffers (Display *display, Window window) | 1822 initialize_cut_buffers (Display *display, Window window) |
1822 { | 1823 { |
1823 unsigned CONST char *data = (unsigned CONST char *) ""; | 1824 static unsigned CONST char * CONST data = (unsigned CONST char *) ""; |
1824 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \ | 1825 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \ |
1825 PropModeAppend, data, 0) | 1826 PropModeAppend, data, 0) |
1826 FROB (XA_CUT_BUFFER0); | 1827 FROB (XA_CUT_BUFFER0); |
1827 FROB (XA_CUT_BUFFER1); | 1828 FROB (XA_CUT_BUFFER1); |
1828 FROB (XA_CUT_BUFFER2); | 1829 FROB (XA_CUT_BUFFER2); |
1833 FROB (XA_CUT_BUFFER7); | 1834 FROB (XA_CUT_BUFFER7); |
1834 #undef FROB | 1835 #undef FROB |
1835 cut_buffers_initialized = 1; | 1836 cut_buffers_initialized = 1; |
1836 } | 1837 } |
1837 | 1838 |
1838 | |
1839 #define CHECK_CUTBUFFER(symbol) \ | 1839 #define CHECK_CUTBUFFER(symbol) \ |
1840 { CHECK_SYMBOL (symbol); \ | 1840 { CHECK_SYMBOL (symbol); \ |
1841 if (!EQ((symbol),QCUT_BUFFER0) && !EQ((symbol),QCUT_BUFFER1) && \ | 1841 if (!EQ((symbol),QCUT_BUFFER0) && !EQ((symbol),QCUT_BUFFER1) && \ |
1842 !EQ((symbol),QCUT_BUFFER2) && !EQ((symbol),QCUT_BUFFER3) && \ | 1842 !EQ((symbol),QCUT_BUFFER2) && !EQ((symbol),QCUT_BUFFER3) && \ |
1843 !EQ((symbol),QCUT_BUFFER4) && !EQ((symbol),QCUT_BUFFER5) && \ | 1843 !EQ((symbol),QCUT_BUFFER4) && !EQ((symbol),QCUT_BUFFER5) && \ |
1844 !EQ((symbol),QCUT_BUFFER6) && !EQ((symbol),QCUT_BUFFER7)) \ | 1844 !EQ((symbol),QCUT_BUFFER6) && !EQ((symbol),QCUT_BUFFER7)) \ |
1845 signal_error (Qerror, list2 (build_string ("doesn't name a cutbuffer"), \ | 1845 signal_error (Qerror, list2 (build_string ("Doesn't name a cutbuffer"), \ |
1846 (symbol))); \ | 1846 (symbol))); \ |
1847 } | 1847 } |
1848 | 1848 |
1849 DEFUN ("x-get-cutbuffer-internal", Fx_get_cutbuffer_internal, | 1849 DEFUN ("x-get-cutbuffer-internal", Fx_get_cutbuffer_internal, |
1850 Sx_get_cutbuffer_internal, 1, 1, 0 /* | 1850 Sx_get_cutbuffer_internal, 1, 1, 0 /* |
1851 Return the value of the named cutbuffer (typically CUT_BUFFER0). | 1851 Return the value of the named CUTBUFFER (typically CUT_BUFFER0). |
1852 */ ) | 1852 */ ) |
1853 (buffer) | 1853 (cutbuffer) |
1854 Lisp_Object buffer; | 1854 Lisp_Object cutbuffer; |
1855 { | 1855 { |
1856 struct device *d = decode_x_device (Qnil); | 1856 struct device *d = decode_x_device (Qnil); |
1857 Display *display = DEVICE_X_DISPLAY (d); | 1857 Display *display = DEVICE_X_DISPLAY (d); |
1858 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */ | 1858 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */ |
1859 Atom buffer_atom; | 1859 Atom cut_buffer_atom; |
1860 unsigned char *data; | 1860 unsigned char *data; |
1861 int bytes; | 1861 int bytes; |
1862 Atom type; | 1862 Atom type; |
1863 int format; | 1863 int format; |
1864 unsigned long size; | 1864 unsigned long size; |
1865 Lisp_Object ret; | 1865 Lisp_Object ret; |
1866 | 1866 |
1867 CHECK_CUTBUFFER (buffer); | 1867 CHECK_CUTBUFFER (cutbuffer); |
1868 buffer_atom = symbol_to_x_atom (d, buffer, 0); | 1868 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0); |
1869 | 1869 |
1870 x_get_window_property (display, window, buffer_atom, &data, &bytes, | 1870 x_get_window_property (display, window, cut_buffer_atom, &data, &bytes, |
1871 &type, &format, &size, 0); | 1871 &type, &format, &size, 0); |
1872 if (!data) return Qnil; | 1872 if (!data) return Qnil; |
1873 | 1873 |
1874 if (format != 8 || type != XA_STRING) | 1874 if (format != 8 || type != XA_STRING) |
1875 signal_simple_error_2 ("cut buffer doesn't contain 8-bit data", | 1875 signal_simple_error_2 ("Cut buffer doesn't contain 8-bit STRING data", |
1876 x_atom_to_symbol (d, type), | 1876 x_atom_to_symbol (d, type), |
1877 make_int (format)); | 1877 make_int (format)); |
1878 | 1878 |
1879 ret = (bytes ? make_ext_string (data, bytes, FORMAT_BINARY) : Qnil); | 1879 ret = (bytes ? |
1880 make_ext_string (data, bytes, | |
1881 FORMAT_BINARY) | |
1882 : Qnil); | |
1880 xfree (data); | 1883 xfree (data); |
1881 return ret; | 1884 return ret; |
1882 } | 1885 } |
1883 | 1886 |
1884 | 1887 |
1885 DEFUN ("x-store-cutbuffer-internal", Fx_store_cutbuffer_internal, | 1888 DEFUN ("x-store-cutbuffer-internal", Fx_store_cutbuffer_internal, |
1886 Sx_store_cutbuffer_internal, 2, 2, 0 /* | 1889 Sx_store_cutbuffer_internal, 2, 2, 0 /* |
1887 Sets the value of the named cutbuffer (typically CUT_BUFFER0). | 1890 Set the value of the named CUTBUFFER (typically CUT_BUFFER0) to STRING. |
1888 */ ) | 1891 */ ) |
1889 (buffer, string) | 1892 (cutbuffer, string) |
1890 Lisp_Object buffer, string; | 1893 Lisp_Object cutbuffer, string; |
1891 { | 1894 { |
1892 struct device *d = decode_x_device (Qnil); | 1895 struct device *d = decode_x_device (Qnil); |
1893 Display *display = DEVICE_X_DISPLAY (d); | 1896 Display *display = DEVICE_X_DISPLAY (d); |
1894 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */ | 1897 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */ |
1895 Atom buffer_atom; | 1898 Atom cut_buffer_atom; |
1896 unsigned char *data; | 1899 Extbyte *data = XSTRING_DATA (string); |
1897 int bytes; | 1900 Extcount bytes = XSTRING_LENGTH (string); |
1898 int bytes_remaining; | 1901 Extcount bytes_remaining; |
1899 int max_bytes = SELECTION_QUANTUM (display); | 1902 int max_bytes = SELECTION_QUANTUM (display); |
1900 if (max_bytes > MAX_SELECTION_QUANTUM) max_bytes = MAX_SELECTION_QUANTUM; | 1903 |
1901 | 1904 if (max_bytes > MAX_SELECTION_QUANTUM) |
1902 CHECK_CUTBUFFER (buffer); | 1905 max_bytes = MAX_SELECTION_QUANTUM; |
1906 | |
1907 CHECK_CUTBUFFER (cutbuffer); | |
1903 CHECK_STRING (string); | 1908 CHECK_STRING (string); |
1904 buffer_atom = symbol_to_x_atom (d, buffer, 0); | 1909 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0); |
1905 GET_STRING_BINARY_DATA_ALLOCA (string, data, bytes); | 1910 |
1911 if (! cut_buffers_initialized) | |
1912 initialize_cut_buffers (display, window); | |
1913 | |
1906 bytes_remaining = bytes; | 1914 bytes_remaining = bytes; |
1907 | 1915 |
1908 if (! cut_buffers_initialized) initialize_cut_buffers (display, window); | |
1909 | |
1910 while (bytes_remaining) | 1916 while (bytes_remaining) |
1911 { | 1917 { |
1912 int chunk = (bytes_remaining < max_bytes | 1918 int chunk = bytes_remaining < max_bytes ? bytes_remaining : max_bytes; |
1913 ? bytes_remaining : max_bytes); | 1919 XChangeProperty (display, window, cut_buffer_atom, XA_STRING, 8, |
1914 XChangeProperty (display, window, buffer_atom, XA_STRING, 8, | |
1915 (bytes_remaining == bytes | 1920 (bytes_remaining == bytes |
1916 ? PropModeReplace | 1921 ? PropModeReplace : PropModeAppend), |
1917 : PropModeAppend), | |
1918 data, chunk); | 1922 data, chunk); |
1919 data += chunk; | 1923 data += chunk; |
1920 bytes_remaining -= chunk; | 1924 bytes_remaining -= chunk; |
1921 } | 1925 } |
1922 return string; | 1926 return string; |
1951 props[7] = XA_CUT_BUFFER7; | 1955 props[7] = XA_CUT_BUFFER7; |
1952 XRotateWindowProperties (display, window, props, 8, XINT (n)); | 1956 XRotateWindowProperties (display, window, props, 8, XINT (n)); |
1953 return n; | 1957 return n; |
1954 } | 1958 } |
1955 | 1959 |
1956 #endif | 1960 #endif /* CUT_BUFFER_SUPPORT */ |
1957 | 1961 |
1958 | 1962 |
1959 /************************************************************************/ | 1963 /************************************************************************/ |
1960 /* initialization */ | 1964 /* initialization */ |
1961 /************************************************************************/ | 1965 /************************************************************************/ |
1971 | 1975 |
1972 #ifdef CUT_BUFFER_SUPPORT | 1976 #ifdef CUT_BUFFER_SUPPORT |
1973 defsubr (&Sx_get_cutbuffer_internal); | 1977 defsubr (&Sx_get_cutbuffer_internal); |
1974 defsubr (&Sx_store_cutbuffer_internal); | 1978 defsubr (&Sx_store_cutbuffer_internal); |
1975 defsubr (&Sx_rotate_cutbuffers_internal); | 1979 defsubr (&Sx_rotate_cutbuffers_internal); |
1976 #endif | 1980 #endif /* CUT_BUFFER_SUPPORT */ |
1977 | 1981 |
1978 /* Unfortunately, timeout handlers must be lisp functions. */ | 1982 /* Unfortunately, timeout handlers must be lisp functions. */ |
1979 defsymbol (&Qx_selection_reply_timeout_internal, | 1983 defsymbol (&Qx_selection_reply_timeout_internal, |
1980 "x-selection-reply-timeout-internal"); | 1984 "x-selection-reply-timeout-internal"); |
1981 defsubr (&Sx_selection_reply_timeout_internal); | 1985 defsubr (&Sx_selection_reply_timeout_internal); |