Mercurial > emacs
comparison src/xselect.c @ 46881:970ca194ce9a
(QUTF8_STRING): New variable.
(symbol_to_x_atom): Pay attention to QUTF8_STRING.
(x_atom_to_symbol): Likewise.
(x_get_local_selection): New argument local_request. If it is
nonzero, call handler_fn with the second arg nil.
(x_handle_selection_request): Call x_get_local_selection with
local_request 0.
(lisp_data_to_selection_data): Don't encode the string here.
(Fx_get_selection_internal): Call x_get_local_selection with
local_request 1.
(syms_of_xselect): Intern and staticpro QUTF8_STRING.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 14 Aug 2002 00:58:39 +0000 |
parents | 40db0673e6f0 |
children | 9d5666b8bf1a |
comparison
equal
deleted
inserted
replaced
46880:12873c268a23 | 46881:970ca194ce9a |
---|---|
38 | 38 |
39 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom)); | 39 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom)); |
40 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *, | 40 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *, |
41 Lisp_Object)); | 41 Lisp_Object)); |
42 static void x_own_selection P_ ((Lisp_Object, Lisp_Object)); | 42 static void x_own_selection P_ ((Lisp_Object, Lisp_Object)); |
43 static Lisp_Object x_get_local_selection P_ ((Lisp_Object, Lisp_Object)); | 43 static Lisp_Object x_get_local_selection P_ ((Lisp_Object, Lisp_Object, int)); |
44 static void x_decline_selection_request P_ ((struct input_event *)); | 44 static void x_decline_selection_request P_ ((struct input_event *)); |
45 static Lisp_Object x_selection_request_lisp_error P_ ((Lisp_Object)); | 45 static Lisp_Object x_selection_request_lisp_error P_ ((Lisp_Object)); |
46 static Lisp_Object queue_selection_requests_unwind P_ ((Lisp_Object)); | 46 static Lisp_Object queue_selection_requests_unwind P_ ((Lisp_Object)); |
47 static Lisp_Object some_frame_on_display P_ ((struct x_display_info *)); | 47 static Lisp_Object some_frame_on_display P_ ((struct x_display_info *)); |
48 static void x_reply_selection_request P_ ((struct input_event *, int, | 48 static void x_reply_selection_request P_ ((struct input_event *, int, |
94 Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP, | 94 Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP, |
95 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL, | 95 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL, |
96 QATOM_PAIR; | 96 QATOM_PAIR; |
97 | 97 |
98 Lisp_Object QCOMPOUND_TEXT; /* This is a type of selection. */ | 98 Lisp_Object QCOMPOUND_TEXT; /* This is a type of selection. */ |
99 Lisp_Object QUTF8_STRING; /* This is a type of selection. */ | |
99 | 100 |
100 Lisp_Object Qcompound_text_with_extensions; | 101 Lisp_Object Qcompound_text_with_extensions; |
101 | 102 |
102 #ifdef CUT_BUFFER_SUPPORT | 103 #ifdef CUT_BUFFER_SUPPORT |
103 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3, | 104 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3, |
180 if (EQ (sym, QATOM)) return XA_ATOM; | 181 if (EQ (sym, QATOM)) return XA_ATOM; |
181 if (EQ (sym, QCLIPBOARD)) return dpyinfo->Xatom_CLIPBOARD; | 182 if (EQ (sym, QCLIPBOARD)) return dpyinfo->Xatom_CLIPBOARD; |
182 if (EQ (sym, QTIMESTAMP)) return dpyinfo->Xatom_TIMESTAMP; | 183 if (EQ (sym, QTIMESTAMP)) return dpyinfo->Xatom_TIMESTAMP; |
183 if (EQ (sym, QTEXT)) return dpyinfo->Xatom_TEXT; | 184 if (EQ (sym, QTEXT)) return dpyinfo->Xatom_TEXT; |
184 if (EQ (sym, QCOMPOUND_TEXT)) return dpyinfo->Xatom_COMPOUND_TEXT; | 185 if (EQ (sym, QCOMPOUND_TEXT)) return dpyinfo->Xatom_COMPOUND_TEXT; |
186 if (EQ (sym, QUTF8_STRING)) return dpyinfo->Xatom_UTF8_STRING; | |
185 if (EQ (sym, QDELETE)) return dpyinfo->Xatom_DELETE; | 187 if (EQ (sym, QDELETE)) return dpyinfo->Xatom_DELETE; |
186 if (EQ (sym, QMULTIPLE)) return dpyinfo->Xatom_MULTIPLE; | 188 if (EQ (sym, QMULTIPLE)) return dpyinfo->Xatom_MULTIPLE; |
187 if (EQ (sym, QINCR)) return dpyinfo->Xatom_INCR; | 189 if (EQ (sym, QINCR)) return dpyinfo->Xatom_INCR; |
188 if (EQ (sym, QEMACS_TMP)) return dpyinfo->Xatom_EMACS_TMP; | 190 if (EQ (sym, QEMACS_TMP)) return dpyinfo->Xatom_EMACS_TMP; |
189 if (EQ (sym, QTARGETS)) return dpyinfo->Xatom_TARGETS; | 191 if (EQ (sym, QTARGETS)) return dpyinfo->Xatom_TARGETS; |
262 return QTIMESTAMP; | 264 return QTIMESTAMP; |
263 if (atom == dpyinfo->Xatom_TEXT) | 265 if (atom == dpyinfo->Xatom_TEXT) |
264 return QTEXT; | 266 return QTEXT; |
265 if (atom == dpyinfo->Xatom_COMPOUND_TEXT) | 267 if (atom == dpyinfo->Xatom_COMPOUND_TEXT) |
266 return QCOMPOUND_TEXT; | 268 return QCOMPOUND_TEXT; |
269 if (atom == dpyinfo->Xatom_UTF8_STRING) | |
270 return QUTF8_STRING; | |
267 if (atom == dpyinfo->Xatom_DELETE) | 271 if (atom == dpyinfo->Xatom_DELETE) |
268 return QDELETE; | 272 return QDELETE; |
269 if (atom == dpyinfo->Xatom_MULTIPLE) | 273 if (atom == dpyinfo->Xatom_MULTIPLE) |
270 return QMULTIPLE; | 274 return QMULTIPLE; |
271 if (atom == dpyinfo->Xatom_INCR) | 275 if (atom == dpyinfo->Xatom_INCR) |
348 } | 352 } |
349 | 353 |
350 /* Given a selection-name and desired type, look up our local copy of | 354 /* Given a selection-name and desired type, look up our local copy of |
351 the selection value and convert it to the type. | 355 the selection value and convert it to the type. |
352 The value is nil or a string. | 356 The value is nil or a string. |
353 This function is used both for remote requests | 357 This function is used both for remote requests (LOCAL_REQUEST is zero) |
354 and for local x-get-selection-internal. | 358 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero). |
355 | 359 |
356 This calls random Lisp code, and may signal or gc. */ | 360 This calls random Lisp code, and may signal or gc. */ |
357 | 361 |
358 static Lisp_Object | 362 static Lisp_Object |
359 x_get_local_selection (selection_symbol, target_type) | 363 x_get_local_selection (selection_symbol, target_type, local_request) |
360 Lisp_Object selection_symbol, target_type; | 364 Lisp_Object selection_symbol, target_type; |
365 int local_request; | |
361 { | 366 { |
362 Lisp_Object local_value; | 367 Lisp_Object local_value; |
363 Lisp_Object handler_fn, value, type, check; | 368 Lisp_Object handler_fn, value, type, check; |
364 int count; | 369 int count; |
365 | 370 |
402 { | 407 { |
403 Lisp_Object pair; | 408 Lisp_Object pair; |
404 pair = XVECTOR (pairs)->contents [i]; | 409 pair = XVECTOR (pairs)->contents [i]; |
405 XVECTOR (pair)->contents [1] | 410 XVECTOR (pair)->contents [1] |
406 = x_get_local_selection (XVECTOR (pair)->contents [0], | 411 = x_get_local_selection (XVECTOR (pair)->contents [0], |
407 XVECTOR (pair)->contents [1]); | 412 XVECTOR (pair)->contents [1], |
413 local_request); | |
408 } | 414 } |
409 return pairs; | 415 return pairs; |
410 } | 416 } |
411 #endif | 417 #endif |
412 else | 418 else |
419 | 425 |
420 CHECK_SYMBOL (target_type); | 426 CHECK_SYMBOL (target_type); |
421 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); | 427 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); |
422 if (!NILP (handler_fn)) | 428 if (!NILP (handler_fn)) |
423 value = call3 (handler_fn, | 429 value = call3 (handler_fn, |
424 selection_symbol, target_type, | 430 selection_symbol, (local_request ? Qnil : target_type), |
425 XCAR (XCDR (local_value))); | 431 XCAR (XCDR (local_value))); |
426 else | 432 else |
427 value = Qnil; | 433 value = Qnil; |
428 unbind_to (count, Qnil); | 434 unbind_to (count, Qnil); |
429 } | 435 } |
799 #endif | 805 #endif |
800 | 806 |
801 /* Convert lisp objects back into binary data */ | 807 /* Convert lisp objects back into binary data */ |
802 | 808 |
803 converted_selection | 809 converted_selection |
804 = x_get_local_selection (selection_symbol, target_symbol); | 810 = x_get_local_selection (selection_symbol, target_symbol, 0); |
805 | 811 |
806 if (! NILP (converted_selection)) | 812 if (! NILP (converted_selection)) |
807 { | 813 { |
808 unsigned char *data; | 814 unsigned char *data; |
809 unsigned int size; | 815 unsigned int size; |
1756 *data_ret = 0; | 1762 *data_ret = 0; |
1757 type = QNULL; | 1763 type = QNULL; |
1758 } | 1764 } |
1759 else if (STRINGP (obj)) | 1765 else if (STRINGP (obj)) |
1760 { | 1766 { |
1761 /* Since we are now handling multilingual text, we must consider | 1767 xassert (! STRING_MULTIBYTE (obj)); |
1762 sending back compound text. */ | 1768 if (NILP (type)) |
1763 int stringp; | 1769 type = QSTRING; |
1764 extern Lisp_Object Qcompound_text; | |
1765 | |
1766 if (NILP (Vnext_selection_coding_system)) | |
1767 Vnext_selection_coding_system = Vselection_coding_system; | |
1768 | |
1769 *format_ret = 8; | 1770 *format_ret = 8; |
1770 /* If the requested type is STRING, we must encode the selected | 1771 *size_ret = SBYTES (obj); |
1771 text as a string, even if the coding system set by the user | 1772 *data_ret = SDATA (obj); |
1772 is ctext or its derivatives. */ | 1773 *nofree_ret = 1; |
1773 if (EQ (type, QSTRING) | |
1774 && (EQ (Vnext_selection_coding_system, Qcompound_text) | |
1775 || EQ (Vnext_selection_coding_system, | |
1776 Qcompound_text_with_extensions))) | |
1777 { | |
1778 Lisp_Object unibyte_string; | |
1779 | |
1780 unibyte_string = string_make_unibyte (obj); | |
1781 *data_ret = SDATA (unibyte_string); | |
1782 *nofree_ret = 1; | |
1783 *size_ret = SBYTES (unibyte_string); | |
1784 } | |
1785 else | |
1786 { | |
1787 *data_ret = x_encode_text (obj, Vnext_selection_coding_system, 1, | |
1788 (int *) size_ret, &stringp); | |
1789 *nofree_ret = (*data_ret == SDATA (obj)); | |
1790 } | |
1791 if (NILP (type)) | |
1792 type = (stringp ? QSTRING : QCOMPOUND_TEXT); | |
1793 Vlast_coding_system_used = (*nofree_ret | |
1794 ? Qraw_text | |
1795 : Vnext_selection_coding_system); | |
1796 Vnext_selection_coding_system = Qnil; | |
1797 } | 1774 } |
1798 else if (SYMBOLP (obj)) | 1775 else if (SYMBOLP (obj)) |
1799 { | 1776 { |
1800 *format_ret = 32; | 1777 *format_ret = 32; |
1801 *size_ret = 1; | 1778 *size_ret = 1; |
2023 } | 2000 } |
2024 else | 2001 else |
2025 #endif | 2002 #endif |
2026 CHECK_SYMBOL (target_type); | 2003 CHECK_SYMBOL (target_type); |
2027 | 2004 |
2028 val = x_get_local_selection (selection_symbol, target_type); | 2005 val = x_get_local_selection (selection_symbol, target_type, 1); |
2029 | 2006 |
2030 if (NILP (val)) | 2007 if (NILP (val)) |
2031 { | 2008 { |
2032 val = x_get_foreign_selection (selection_symbol, target_type); | 2009 val = x_get_foreign_selection (selection_symbol, target_type); |
2033 goto DONE; | 2010 goto DONE; |
2444 QINTEGER = intern ("INTEGER"); staticpro (&QINTEGER); | 2421 QINTEGER = intern ("INTEGER"); staticpro (&QINTEGER); |
2445 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); | 2422 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); |
2446 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); | 2423 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); |
2447 QTEXT = intern ("TEXT"); staticpro (&QTEXT); | 2424 QTEXT = intern ("TEXT"); staticpro (&QTEXT); |
2448 QCOMPOUND_TEXT = intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT); | 2425 QCOMPOUND_TEXT = intern ("COMPOUND_TEXT"); staticpro (&QCOMPOUND_TEXT); |
2426 QUTF8_STRING = intern ("UTF8_STRING"); staticpro (&QUTF8_STRING); | |
2449 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); | 2427 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP); |
2450 QDELETE = intern ("DELETE"); staticpro (&QDELETE); | 2428 QDELETE = intern ("DELETE"); staticpro (&QDELETE); |
2451 QMULTIPLE = intern ("MULTIPLE"); staticpro (&QMULTIPLE); | 2429 QMULTIPLE = intern ("MULTIPLE"); staticpro (&QMULTIPLE); |
2452 QINCR = intern ("INCR"); staticpro (&QINCR); | 2430 QINCR = intern ("INCR"); staticpro (&QINCR); |
2453 QEMACS_TMP = intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP); | 2431 QEMACS_TMP = intern ("_EMACS_TMP_"); staticpro (&QEMACS_TMP); |