aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2000-11-21 19:18:13 +0000
committerJason Rumney2000-11-21 19:18:13 +0000
commit06466d9ad1c4e3771143b3e336051a040d6fdc98 (patch)
treeb48aaabeda2d054fa0da45d3890038db210858c6 /src
parent556635d618cfcf583812a46ebad25519f3c3aad4 (diff)
downloademacs-06466d9ad1c4e3771143b3e336051a040d6fdc98.tar.gz
emacs-06466d9ad1c4e3771143b3e336051a040d6fdc98.zip
(Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
(Fw32_get_clipboard_data): Compare data on clipboard with saved copy of what Emacs last put there. If they are the same, do not use the clipboard copy to avoid losing data due to coding conversions.
Diffstat (limited to 'src')
-rw-r--r--src/w32select.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/w32select.c b/src/w32select.c
index 560fad01a20..520610ee961 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -37,9 +37,18 @@ Lisp_Object QCLIPBOARD;
37 clipboard. */ 37 clipboard. */
38static Lisp_Object Vselection_coding_system; 38static Lisp_Object Vselection_coding_system;
39 39
40/* Coding system for the next communicating with other X clients. */ 40/* Coding system for the next communicating with other Windows programs. */
41static Lisp_Object Vnext_selection_coding_system; 41static Lisp_Object Vnext_selection_coding_system;
42 42
43/* The last text we put into the clipboard. This is used to prevent
44 passing back our own text from the clipboard, instead of using the
45 kill ring. The former is undesirable because the clipboard data
46 could be MULEtilated by inappropriately chosen
47 (next-)selection-coding-system. For this reason, we must store the
48 text *after* it was encoded/Unix-to-DOS-converted. */
49static unsigned char *last_clipboard_text = NULL;
50static size_t clipboard_storage_size = 0;
51
43#if 0 52#if 0
44DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0, 53DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0,
45 "This opens the clipboard with the given frame pointer.") 54 "This opens the clipboard with the given frame pointer.")
@@ -174,10 +183,8 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
174 } 183 }
175 else 184 else
176 { 185 {
177 /* We must encode contents of OBJ to compound text format. 186 /* We must encode contents of OBJ to the selection coding
178 The format is compatible with what the target `STRING' 187 system. */
179 expects if OBJ contains only ASCII and Latin-1
180 characters. */
181 int bufsize; 188 int bufsize;
182 struct coding_system coding; 189 struct coding_system coding;
183 HANDLE htext2; 190 HANDLE htext2;
@@ -197,16 +204,31 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
197 goto error; 204 goto error;
198 encode_coding (&coding, src, dst, nbytes, bufsize); 205 encode_coding (&coding, src, dst, nbytes, bufsize);
199 Vlast_coding_system_used = coding.symbol; 206 Vlast_coding_system_used = coding.symbol;
207
208 /* Stash away the data we are about to put into the clipboard, so we
209 could later check inside Fw32_get_clipboard_data whether
210 the clipboard still holds our data. */
211 if (clipboard_storage_size < coding.produced)
212 {
213 clipboard_storage_size = coding.produced + 100;
214 last_clipboard_text = (char *) xrealloc (last_clipboard_text,
215 clipboard_storage_size);
216 }
217 if (last_clipboard_text)
218 memcpy (last_clipboard_text, dst, coding.produced);
219
200 GlobalUnlock (htext); 220 GlobalUnlock (htext);
221
201 /* Shrink data block to actual size. */ 222 /* Shrink data block to actual size. */
202 htext2 = GlobalReAlloc (htext, coding.produced, GMEM_MOVEABLE | GMEM_DDESHARE); 223 htext2 = GlobalReAlloc (htext, coding.produced,
224 GMEM_MOVEABLE | GMEM_DDESHARE);
203 if (htext2 != NULL) htext = htext2; 225 if (htext2 != NULL) htext = htext2;
204 } 226 }
205 } 227 }
206 228
207 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) 229 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
208 goto error; 230 goto error;
209 231
210 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); 232 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
211 233
212 CloseClipboard (); 234 CloseClipboard ();
@@ -217,7 +239,9 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, Sw32_set_clipboard_dat
217 239
218 ok = FALSE; 240 ok = FALSE;
219 if (htext) GlobalFree (htext); 241 if (htext) GlobalFree (htext);
220 242 if (last_clipboard_text)
243 *last_clipboard_text = '\0';
244
221 done: 245 done:
222 UNBLOCK_INPUT; 246 UNBLOCK_INPUT;
223 247
@@ -255,6 +279,16 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
255 279
256 nbytes = strlen (src); 280 nbytes = strlen (src);
257 281
282 /* If the text in clipboard is identical to what we put there
283 last time w32_set_clipboard_data was called, pretend there's no
284 data in the clipboard. This is so we don't pass our own text
285 from the clipboard (which might be troublesome if the killed
286 text includes null characters). */
287 if (last_clipboard_text
288 && clipboard_storage_size >= nbytes
289 && memcmp(last_clipboard_text, src, nbytes) == 0)
290 goto closeclip;
291
258 if ( 292 if (
259#if 1 293#if 1
260 1 294 1
@@ -295,8 +329,8 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_dat
295 buf = (unsigned char *) xmalloc (bufsize); 329 buf = (unsigned char *) xmalloc (bufsize);
296 decode_coding (&coding, src, buf, nbytes, bufsize); 330 decode_coding (&coding, src, buf, nbytes, bufsize);
297 Vlast_coding_system_used = coding.symbol; 331 Vlast_coding_system_used = coding.symbol;
298 ret = make_string_from_bytes ((char *) buf, 332 ret = make_string_from_bytes ((char *) buf,
299 coding.produced_char, coding.produced); 333 coding.produced_char, coding.produced);
300 xfree (buf); 334 xfree (buf);
301 } 335 }
302 else 336 else