changeset 23562:5f3243813b18

(Vnext_selection_coding_system): New variable. (syms_of_w32select): DEFVAR_LISP it. (Fw32_set_clipboard_data): Use Vnext_selection_coding_system if non-nil. Always convert multibyte strings. (Fw32_get_clipboard_data): Use Vnext_selection_coding_system if non-nil. Always convert a string that includes non-ASCII characters.
author Geoff Voelker <voelker@cs.washington.edu>
date Wed, 28 Oct 1998 03:50:07 +0000
parents 70fafedc3c4c
children 18c5f58b70b5
files src/w32select.c
diffstat 1 files changed, 46 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/w32select.c	Wed Oct 28 00:04:28 1998 +0000
+++ b/src/w32select.c	Wed Oct 28 03:50:07 1998 +0000
@@ -36,6 +36,9 @@
    clipboard.  */
 static Lisp_Object Vselection_coding_system;
 
+/* Coding system for the next communicating with other X clients.  */
+static Lisp_Object Vnext_selection_coding_system;
+
 #if 0
 DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0,
        "This opens the clipboard with the given frame pointer.")
@@ -117,8 +120,9 @@
     int num;
 
     bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
-    num = ((nbytes <= 2	/* Check the possibility of short cut.  */
-	    || NILP (buffer_defaults.enable_multibyte_characters))
+    num = ((nbytes <= 1	/* Check the possibility of short cut.  */
+	    || !STRING_MULTIBYTE (string)
+	    || nbytes == XSTRING (string)->size)
 	   ? 0
 	   : find_charset_in_str (src, nbytes, charsets, Qnil, 0));
 
@@ -181,8 +185,11 @@
 	struct coding_system coding;
 	HANDLE htext2;
 
+	if (NILP (Vnext_selection_coding_system))
+	  Vnext_selection_coding_system = Vselection_coding_system;
 	setup_coding_system
-	  (Fcheck_coding_system (Vselection_coding_system), &coding);
+	  (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
+	Vnext_selection_coding_system = Qnil;
 	coding.mode |= CODING_MODE_LAST_BLOCK;
 	bufsize = encoding_buffer_size (&coding, nbytes);
 	if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL)
@@ -242,20 +249,46 @@
     unsigned char *dst;
     int nbytes;
     int truelen;
+    int require_encoding = 0;
     
     if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
       goto closeclip;
     
     nbytes = strlen (src);
 
-    if (! NILP (buffer_defaults.enable_multibyte_characters))
+    if (
+#if 1
+	1
+#else
+	! NILP (buffer_defaults.enable_multibyte_characters)
+#endif
+	)
+      {
+	/* If the clipboard data contains any 8-bit Latin-1 code, we
+	   need to decode it.  */
+	int i;
+
+	for (i = 0; i < nbytes; i++)
+	  {
+	    if (src[i] >= 0x80)
+	      {
+		require_encoding = 1;
+		break;
+	      }
+	  }
+      }
+    
+    if (require_encoding)
       {
 	int bufsize;
 	unsigned char *buf;
 	struct coding_system coding;
 
+	if (NILP (Vnext_selection_coding_system))
+	  Vnext_selection_coding_system = Vselection_coding_system;
 	setup_coding_system
-	  (Fcheck_coding_system(Vselection_coding_system), &coding);
+	  (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
+	Vnext_selection_coding_system = Qnil;
 	coding.mode |= CODING_MODE_LAST_BLOCK;
 	bufsize = decoding_buffer_size (&coding, nbytes);
 	buf = (unsigned char *) xmalloc (bufsize);
@@ -378,5 +411,13 @@
 A default value is `compound-text'");
   Vselection_coding_system=intern ("iso-latin-1-dos");
 
+  DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
+    "Coding system for the next communication with other X clients.\n\
+Usually, `selection-coding-system' is used for communicating with\n\
+other X clients.   But, if this variable is set, it is used for the\n\
+next communication only.   After the communication, this variable is\n\
+set to nil.");
+  Vnext_selection_coding_system = Qnil;
+
   QCLIPBOARD = intern ("CLIPBOARD");	staticpro (&QCLIPBOARD);
 }