summaryrefslogtreecommitdiff
path: root/src/w32select.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/w32select.c')
-rw-r--r--src/w32select.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/w32select.c b/src/w32select.c
index 5191b2a2ed2..da01576ddf3 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -36,6 +36,9 @@ Lisp_Object QCLIPBOARD;
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 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
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 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
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 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
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 @@ the text is encoded or decoded by this coding system.\n\
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);
}