]> code.delx.au - gnu-emacs/blobdiff - src/w16select.c
*** empty log message ***
[gnu-emacs] / src / w16select.c
index 582c5019e6f21f75679b071e2260d934639bc357..7fb0534f36d7dbf3f713e5bbb4139aad64d91369 100644 (file)
@@ -1,6 +1,6 @@
 /* 16-bit Windows Selection processing for emacs on MS-Windows
    Copyright (C) 1996, 1997, 2001 Free Software Foundation.
-   
+
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
@@ -40,6 +40,7 @@ Boston, MA 02111-1307, USA.  */
 #include "buffer.h"
 #include "charset.h"
 #include "coding.h"
+#include "composite.h"
 
 /* If ever some function outside this file will need to call any
    clipboard-related function, the following prototypes and constants
@@ -168,7 +169,7 @@ unsigned
 empty_clipboard ()
 {
   __dpmi_regs regs;
-  
+
   /* Calls Int 2Fh/AX=1702h
      Return Values   AX == 0: Error occurred
                        <> 0: OK, Clipboard emptied */
@@ -399,7 +400,7 @@ get_clipboard_data (Format, Data, Size, Raw)
         the next loop by an additional test.  */
       register unsigned char *lcdp =
        last_clipboard_text == NULL ? &null_char : last_clipboard_text;
-       
+
       /* Copy data from low memory, remove CR
         characters before LF if needed.  */
       _farsetsel (_dos_ds);
@@ -486,28 +487,26 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
      Lisp_Object string, frame;
 {
   unsigned ok = 1, put_status = 0;
-  int nbytes;
+  int nbytes, charset_info, no_crlf_conversion;
   unsigned char *src, *dst = NULL;
-  int charset_info;
-  int no_crlf_conversion;
 
   CHECK_STRING (string);
-  
+
   if (NILP (frame))
     frame = Fselected_frame ();
 
   CHECK_LIVE_FRAME (frame);
   if ( !FRAME_MSDOS_P (XFRAME (frame)))
     goto done;
-  
+
   BLOCK_INPUT;
 
-  nbytes = STRING_BYTES (XSTRING (string));
-  src = XSTRING (string)->data;
+  nbytes = SBYTES (string);
+  src = SDATA (string);
 
   /* Since we are now handling multilingual text, we must consider
      encoding text for the clipboard.  */
-  charset_info = find_charset_in_text (src, XSTRING (string)->size, nbytes,
+  charset_info = find_charset_in_text (src, SCHARS (string), nbytes,
                                       NULL, Qnil);
 
   if (charset_info == 0)
@@ -528,6 +527,13 @@ 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);
+      if (SYMBOLP (coding.pre_write_conversion)
+         && !NILP (Ffboundp (coding.pre_write_conversion)))
+       {
+         string = run_pre_post_conversion_on_str (string, &coding, 1);
+         src = SDATA (string);
+         nbytes = SBYTES (string);
+       }
       coding.src_multibyte = 1;
       coding.dst_multibyte = 0;
       Vnext_selection_coding_system = Qnil;
@@ -543,7 +549,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
 
   if (!open_clipboard ())
     goto error;
-  
+
   ok = empty_clipboard ()
     && ((put_status
         = set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion))
@@ -552,11 +558,11 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
   if (!no_crlf_conversion)
     Vlast_coding_system_used = Qraw_text;
   close_clipboard ();
-  
+
   if (ok) goto unblock;
 
  error:
-  
+
   ok = 0;
 
  unblock:
@@ -585,7 +591,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
        }
       sit_for (2, 0, 0, 1, 1);
     }
-  
+
  done:
 
   return (ok && put_status == 0 ? string : Qnil);
@@ -599,8 +605,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
   unsigned data_size, truelen;
   unsigned char *htext;
   Lisp_Object ret = Qnil;
-  int no_crlf_conversion;
-  int require_encoding = 0;
+  int no_crlf_conversion, require_encoding = 0;
 
   if (NILP (frame))
     frame = Fselected_frame ();
@@ -608,9 +613,9 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
   CHECK_LIVE_FRAME (frame);
   if ( !FRAME_MSDOS_P (XFRAME (frame)))
     goto done;
-  
+
   BLOCK_INPUT;
-  
+
   if (!open_clipboard ())
     goto unblock;
 
@@ -625,27 +630,20 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
     goto closeclip;
 
   /* Do we need to decode it?  */
-  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 < truelen; i++)
-       {
-         if (htext[i] >= 0x80)
-           {
-             require_encoding = 1;
-             break;
-           }
-       }
-    }
+  {
+    /* If the clipboard data contains any 8-bit Latin-1 code, we
+       need to decode it.  */
+    int i;
+
+    for (i = 0; i < truelen; i++)
+      {
+       if (htext[i] >= 0x80)
+         {
+           require_encoding = 1;
+           break;
+         }
+      }
+  }
   if (require_encoding)
     {
       int bufsize;
@@ -660,6 +658,9 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
       coding.dst_multibyte = 1;
       Vnext_selection_coding_system = Qnil;
       coding.mode |= CODING_MODE_LAST_BLOCK;
+      /* We explicitely disable composition handling because selection
+        data should not contain any composition sequence.  */
+      coding.composing = COMPOSITION_DISABLED;
       truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1);
       bufsize = decoding_buffer_size (&coding, truelen);
       buf = (unsigned char *) xmalloc (bufsize);
@@ -667,6 +668,9 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
       ret = make_string_from_bytes ((char *) buf,
                                    coding.produced_char, coding.produced);
       xfree (buf);
+      if (SYMBOLP (coding.post_read_conversion)
+         && !NILP (Ffboundp (coding.post_read_conversion)))
+       ret = run_pre_post_conversion_on_str (ret, &coding, 0);
       Vlast_coding_system_used = coding.symbol;
     }
   else
@@ -682,9 +686,9 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
 
  unblock:
   UNBLOCK_INPUT;
-  
+
  done:
-  
+
   return (ret);
 }
 
@@ -733,7 +737,7 @@ and t is the same as `SECONDARY'.  */)
   return Qnil;
 }
 
-void 
+void
 syms_of_win16select ()
 {
   defsubr (&Sw16_set_clipboard_data);
@@ -744,14 +748,14 @@ syms_of_win16select ()
               doc: /* Coding system for communicating with other X clients.
 When sending or receiving text via cut_buffer, selection, and clipboard,
 the text is encoded or decoded by this coding system.
-A default value is `iso-latin-1-dos'.  */);
-  Vselection_coding_system=intern ("iso-latin-1-dos");
+The default value is `iso-latin-1-dos'.  */);
+  Vselection_coding_system = intern ("iso-latin-1-dos");
 
   DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
               doc: /* Coding system for the next communication with other X clients.
 Usually, `selection-coding-system' is used for communicating with
-other X clients.   But, if this variable is set, it is used for the
-next communication only.   After the communication, this variable is
+other X clients.  But, if this variable is set, it is used for the
+next communication only.  After the communication, this variable is
 set to nil.  */);
   Vnext_selection_coding_system = Qnil;
 
@@ -760,3 +764,6 @@ set to nil.  */);
 }
 
 #endif /* MSDOS */
+
+/* arch-tag: 085a22c8-7324-436e-a6da-102464ce95d8
+   (do not change this comment) */