summaryrefslogtreecommitdiff
path: root/src/w32select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/w32select.c')
-rw-r--r--src/w32select.c63
1 files changed, 23 insertions, 40 deletions
diff --git a/src/w32select.c b/src/w32select.c
index 20f7cfc457f..af3d477f876 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -148,10 +148,9 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
{
/* Since we are now handling multilingual text, we must consider
encoding text for the clipboard. */
- int charset_info = find_charset_in_text (src, SCHARS (string),
- nbytes, NULL, Qnil);
+ int result = string_xstring_p (string);
- if (charset_info == 0)
+ if (result == 0)
{
/* No multibyte character in OBJ. We need not encode it. */
@@ -197,7 +196,6 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
{
/* We must encode contents of OBJ to the selection coding
system. */
- int bufsize;
struct coding_system coding;
HANDLE htext2;
@@ -205,31 +203,20 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
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);
- /* Include the terminating NULL character in the source of
- conversion. */
- nbytes = SBYTES (string) + 1;
- }
- coding.src_multibyte = 1;
- coding.dst_multibyte = 0;
- /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
- encode_coding_iso2022 trying to dereference a null pointer. */
- coding.composing = COMPOSITION_DISABLED;
- if (coding.type == coding_type_iso2022)
- coding.flags |= CODING_FLAG_ISO_SAFE;
+ coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK);
+
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)
+
+ /* We suppress producing escape sequences for composition. */
+ coding.common_flags &= ~CODING_ANNOTATION_MASK;
+ coding.dst_bytes = SCHARS (string) * 2;
+ if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, coding.dst_bytes)) == NULL)
goto error;
- if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
+ if ((coding.destination = (unsigned char *) GlobalLock (htext)) == NULL)
goto error;
- encode_coding (&coding, src, dst, nbytes, bufsize);
- Vlast_coding_system_used = coding.symbol;
+ encode_coding_object (&coding, string, 0, 0,
+ SCHARS (string), SBYTES (string), Qnil);
+ Vlast_coding_system_used = CODING_ID_NAME (coding.id);
/* If clipboard sequence numbers are not supported, keep a copy for
later comparison. */
@@ -246,7 +233,8 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
clipboard_storage_size);
}
if (last_clipboard_text)
- memcpy (last_clipboard_text, dst, coding.produced);
+ memcpy (last_clipboard_text, coding.destination,
+ coding.produced);
}
GlobalUnlock (htext);
@@ -353,8 +341,6 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
if (require_decoding)
{
- int bufsize;
- unsigned char *buf;
struct coding_system coding;
if (NILP (Vnext_selection_coding_system))
@@ -365,20 +351,17 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
coding.dst_multibyte = 1;
Vnext_selection_coding_system = Qnil;
coding.mode |= CODING_MODE_LAST_BLOCK;
- /* We explicitely disable composition handling because
+ /* We explicitly disable composition handling because
selection data should not contain any composition
sequence. */
- coding.composing = COMPOSITION_DISABLED;
- bufsize = decoding_buffer_size (&coding, nbytes);
- buf = (unsigned char *) xmalloc (bufsize);
- decode_coding (&coding, src, buf, nbytes, bufsize);
- Vlast_coding_system_used = coding.symbol;
- ret = make_string_from_bytes ((char *) buf,
+ coding.common_flags &= ~CODING_ANNOTATION_MASK;
+ coding.dst_bytes = nbytes * 2;
+ coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
+ decode_coding_c_string (&coding, src, nbytes, Qnil);
+ Vlast_coding_system_used = CODING_ID_NAME (coding.id);
+ ret = make_string_from_bytes ((char *) coding.destination,
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);
+ xfree (coding.destination);
}
else
{