/* Selection processing for Emacs on the Microsoft W32 API.
Copyright (C) 1993, 1994 Free Software Foundation.
-
+
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
/* Coding system for the next communicating with other Windows programs. */
static Lisp_Object Vnext_selection_coding_system;
-/* The last text we put into the clipboard. This is used to prevent
- passing back our own text from the clipboard, instead of using the
- kill ring. The former is undesirable because the clipboard data
+/* Sequence number, used where possible to detect when we are pasting
+ our own text. */
+static DWORD last_clipboard_sequence_number;
+extern ClipboardSequence_Proc clipboard_sequence_fn;
+
+/* The last text we put into the clipboard. This is used when the OS
+ does not support sequence numbers (NT4, 95). It is undesirable to
+ use data put on the clipboard by Emacs because the clipboard data
could be MULEtilated by inappropriately chosen
(next-)selection-coding-system. For this reason, we must store the
text *after* it was encoded/Unix-to-DOS-converted. */
Lisp_Object frame;
{
BOOL ok = FALSE;
-
+
if (!NILP (frame))
CHECK_LIVE_FRAME (frame);
-
+
BLOCK_INPUT;
-
+
ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL);
-
+
UNBLOCK_INPUT;
-
+
return (ok ? frame : Qnil);
}
()
{
BOOL ok = FALSE;
-
+
BLOCK_INPUT;
-
+
ok = EmptyClipboard ();
-
+
UNBLOCK_INPUT;
-
+
return (ok ? Qt : Qnil);
}
()
{
BOOL ok = FALSE;
-
+
BLOCK_INPUT;
-
+
ok = CloseClipboard ();
-
+
UNBLOCK_INPUT;
-
+
return (ok ? Qt : Qnil);
}
unsigned char *dst;
CHECK_STRING (string);
-
+
if (!NILP (frame))
CHECK_LIVE_FRAME (frame);
-
+
BLOCK_INPUT;
- nbytes = STRING_BYTES (XSTRING (string)) + 1;
- src = XSTRING (string)->data;
+ nbytes = SBYTES (string) + 1;
+ src = SDATA (string);
dst = src;
/* We need to know how many lines there are, since we need CRLF line
{
/* Since we are now handling multilingual text, we must consider
encoding text for the clipboard. */
- int charset_info = find_charset_in_text (src, XSTRING (string)->size,
+ int charset_info = find_charset_in_text (src, SCHARS (string),
nbytes, NULL, Qnil);
if (charset_info == 0)
if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
goto error;
-
+
/* convert to CRLF line endings expected by clipboard */
while (1)
{
next[-1] = '\r';
next[0] = '\n';
dst = next + 1;
- }
+ }
else
/* copied remaining partial line -> now finished */
break;
}
-
+
GlobalUnlock (htext);
Vlast_coding_system_used = Qraw_text;
&& !NILP (Ffboundp (coding.pre_write_conversion)))
{
string = run_pre_post_conversion_on_str (string, &coding, 1);
- src = XSTRING (string)->data;
- nbytes = STRING_BYTES (XSTRING (string));
+ src = SDATA (string);
+ nbytes = SBYTES (string);
}
coding.src_multibyte = 1;
coding.dst_multibyte = 0;
encode_coding (&coding, src, dst, nbytes, bufsize);
Vlast_coding_system_used = coding.symbol;
- /* Stash away the data we are about to put into the clipboard, so we
- could later check inside Fw32_get_clipboard_data whether
- the clipboard still holds our data. */
- if (clipboard_storage_size < coding.produced)
- {
- clipboard_storage_size = coding.produced + 100;
- last_clipboard_text = (char *) xrealloc (last_clipboard_text,
- clipboard_storage_size);
- }
- if (last_clipboard_text)
- memcpy (last_clipboard_text, dst, coding.produced);
+ /* If clipboard sequence numbers are not supported, keep a copy for
+ later comparison. */
+ if (!clipboard_sequence_fn)
+ {
+ /* Stash away the data we are about to put into the
+ clipboard, so we could later check inside
+ Fw32_get_clipboard_data whether the clipboard still
+ holds our data. */
+ if (clipboard_storage_size < coding.produced)
+ {
+ clipboard_storage_size = coding.produced + 100;
+ last_clipboard_text = (char *) xrealloc (last_clipboard_text,
+ clipboard_storage_size);
+ }
+ if (last_clipboard_text)
+ memcpy (last_clipboard_text, dst, coding.produced);
+ }
GlobalUnlock (htext);
if (htext2 != NULL) htext = htext2;
}
}
-
+
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
goto error;
ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
-
+
+ if (clipboard_sequence_fn)
+ last_clipboard_sequence_number = clipboard_sequence_fn ();
+
CloseClipboard ();
-
+
if (ok) goto done;
error:
-
+
ok = FALSE;
if (htext) GlobalFree (htext);
if (last_clipboard_text)
*last_clipboard_text = '\0';
+ last_clipboard_sequence_number = 0;
+
done:
UNBLOCK_INPUT;
-
+
return (ok ? string : Qnil);
}
{
HANDLE htext;
Lisp_Object ret = Qnil;
-
+
if (!NILP (frame))
CHECK_LIVE_FRAME (frame);
-
+
BLOCK_INPUT;
-
+
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
goto done;
-
+
if ((htext = GetClipboardData (CF_TEXT)) == NULL)
goto closeclip;
int nbytes;
int truelen;
int require_decoding = 0;
-
+
if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
goto closeclip;
-
+
nbytes = strlen (src);
/* If the text in clipboard is identical to what we put there
data in the clipboard. This is so we don't pass our own text
from the clipboard (which might be troublesome if the killed
text includes null characters). */
- if (last_clipboard_text
- && clipboard_storage_size >= nbytes
- && memcmp(last_clipboard_text, src, nbytes) == 0)
+ if ((clipboard_sequence_fn
+ && clipboard_sequence_fn () == last_clipboard_sequence_number)
+ || (last_clipboard_text
+ && clipboard_storage_size >= nbytes
+ && memcmp(last_clipboard_text, src, nbytes) == 0))
goto closeclip;
{
/* Convert CRLF line endings (the standard CF_TEXT clipboard
format) to LF endings as used internally by Emacs. */
- dst = XSTRING (ret)->data;
+ dst = SDATA (ret);
while (1)
{
unsigned char *next;
closeclip:
CloseClipboard ();
-
+
done:
UNBLOCK_INPUT;
-
+
return (ret);
}
return Qnil;
}
-void
+void
syms_of_w32select ()
{
#if 0
DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
doc: /* Coding system for communicating with other programs.
When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system. */);
- Vselection_coding_system=intern ("iso-latin-1-dos");
+the text is encoded or decoded by this coding system.
+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 programs.
Usually, `selection-coding-system' is used for communicating with
-other programs. But, if this variable is set, it is used for the
-next communication only. After the communication, this variable is
+other programs. 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;
QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD);
}
+
+/* arch-tag: c96e9724-5eb1-4dad-be07-289f092fd2af
+ (do not change this comment) */