]> code.delx.au - gnu-emacs/blobdiff - src/w16select.c
Include fontset.h dependent on HAVE_WINDOW_SYSTEM, not HAVE_X_WINDOWS.
[gnu-emacs] / src / w16select.c
index b1f4b3adeba746da8d71cc092607d860c69f0120..dec1af7726b37ae130ad814272c155efe93e7a24 100644 (file)
@@ -369,15 +369,6 @@ get_clipboard_data (Format, Data, Size, Raw)
   __dpmi_regs regs;
   unsigned long xbuf_addr;
   unsigned char *dp = Data;
-  /* Copying text from the DOS box on Windows 95 evidently doubles the
-     size of text as reported by the clipboard.  So we must begin
-     looking for the zeroes as if the actual size were half of what's
-     reported.  Jeez, what a mess!  */
-  unsigned half_size = Size > 32 ? Size / 2 : Size;
-  /* Where we should begin looking for zeroes.  See commentary below.  */
-  unsigned char *last_block = dp + ((half_size & 0x1f)
-                                   ? (half_size & 0x20)
-                                   : half_size - 0x20);
 
   if (Format != CF_OEMTEXT)
     return 0;
@@ -424,23 +415,22 @@ get_clipboard_data (Format, Data, Size, Raw)
              dp--;
              *dp++ = '\n';
              xbuf_addr++;
-             if (last_block > dp)
-               last_block--;   /* adjust the beginning of the last 32 bytes */
              if (*lcdp == '\n')
                lcdp++;
            }
          /* Windows reportedly rounds up the size of clipboard data
-            (passed in SIZE) to a multiple of 32.  We therefore bail
-            out when we see the first null character in the last 32-byte
-            block.  */
-         else if (c == '\0' && dp > last_block)
+            (passed in SIZE) to a multiple of 32, and removes trailing
+            spaces from each line without updating SIZE.  We therefore
+            bail out when we see the first null character.  */
+         else if (c == '\0')
            break;
        }
 
       /* If the text in clipboard is identical to what we put there
         last time set_clipboard_data was called, pretend there's no
         data in the clipboard.  This is so we don't pass our own text
-        from the clipboard.  */
+        from the clipboard (which might be troublesome if the killed
+        text includes null characters).  */
       if (last_clipboard_text &&
          xbuf_addr - xbuf_beg == (long)(lcdp - last_clipboard_text))
        dp = (unsigned char *)Data + 1;
@@ -496,8 +486,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
   unsigned ok = 1, put_status = 0;
   int nbytes;
   unsigned char *src, *dst = NULL;
-  int charsets[MAX_CHARSET + 1];
-  int num;
+  int charset_info;
   int no_crlf_conversion;
 
   CHECK_STRING (string, 0);
@@ -516,14 +505,10 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
 
   /* Since we are now handling multilingual text, we must consider
      encoding text for the clipboard.  */
-  bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
-  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, 1));
-
-  if (!num || (num == 1 && charsets[CHARSET_ASCII]))
+  charset_info = find_charset_in_text (src, XSTRING (string)->size, nbytes,
+                                      NULL, Qnil);
+
+  if (charset_info == 0)
     {
       /* No multibyte character in OBJ.  We need not encode it, but we
         will have to convert it to DOS CR-LF style.  */
@@ -541,6 +526,8 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
        Vnext_selection_coding_system = Vselection_coding_system;
       setup_coding_system
        (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
+      coding.src_multibyte = 1;
+      coding.dst_multibyte = 0;
       Vnext_selection_coding_system = Qnil;
       coding.mode |= CODING_MODE_LAST_BLOCK;
       Vlast_coding_system_used = coding.symbol;
@@ -664,16 +651,16 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
        Vnext_selection_coding_system = Vselection_coding_system;
       setup_coding_system
        (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
+      coding.src_multibyte = 0;
+      coding.dst_multibyte = 1;
       Vnext_selection_coding_system = Qnil;
       coding.mode |= CODING_MODE_LAST_BLOCK;
       truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1);
       bufsize = decoding_buffer_size (&coding, truelen);
       buf = (unsigned char *) xmalloc (bufsize);
       decode_coding (&coding, htext, buf, truelen, bufsize);
-      truelen = (coding.fake_multibyte
-                ? multibyte_chars_in_text (buf, coding.produced)
-                : coding.produced_char);
-      ret = make_string_from_bytes ((char *) buf, truelen, coding.produced);
+      ret = make_string_from_bytes ((char *) buf,
+                                   coding.produced_char, coding.produced);
       xfree (buf);
       Vlast_coding_system_used = coding.symbol;
     }