Mercurial > emacs
comparison src/w32select.c @ 47879:4ef507bc376e
(syms_of_win32select): Fix docstring for `selection-coding-system'.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Mon, 14 Oct 2002 11:01:49 +0000 |
parents | 7e81df5e2e1a |
children | 940c7de274a2 d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
47878:be195e2a4bfb | 47879:4ef507bc376e |
---|---|
1 /* Selection processing for Emacs on the Microsoft W32 API. | 1 /* Selection processing for Emacs on the Microsoft W32 API. |
2 Copyright (C) 1993, 1994 Free Software Foundation. | 2 Copyright (C) 1993, 1994 Free Software Foundation. |
3 | 3 |
4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
5 | 5 |
6 GNU Emacs is free software; you can redistribute it and/or modify | 6 GNU Emacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation; either version 2, or (at your option) | 8 the Free Software Foundation; either version 2, or (at your option) |
55 doc: /* This opens the clipboard with the given frame pointer. */) | 55 doc: /* This opens the clipboard with the given frame pointer. */) |
56 (frame) | 56 (frame) |
57 Lisp_Object frame; | 57 Lisp_Object frame; |
58 { | 58 { |
59 BOOL ok = FALSE; | 59 BOOL ok = FALSE; |
60 | 60 |
61 if (!NILP (frame)) | 61 if (!NILP (frame)) |
62 CHECK_LIVE_FRAME (frame); | 62 CHECK_LIVE_FRAME (frame); |
63 | 63 |
64 BLOCK_INPUT; | 64 BLOCK_INPUT; |
65 | 65 |
66 ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); | 66 ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); |
67 | 67 |
68 UNBLOCK_INPUT; | 68 UNBLOCK_INPUT; |
69 | 69 |
70 return (ok ? frame : Qnil); | 70 return (ok ? frame : Qnil); |
71 } | 71 } |
72 | 72 |
73 DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, | 73 DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, |
74 Sw32_empty_clipboard, 0, 0, 0, | 74 Sw32_empty_clipboard, 0, 0, 0, |
75 doc: /* Empty the clipboard. | 75 doc: /* Empty the clipboard. |
76 Assigns ownership of the clipboard to the window which opened it. */) | 76 Assigns ownership of the clipboard to the window which opened it. */) |
77 () | 77 () |
78 { | 78 { |
79 BOOL ok = FALSE; | 79 BOOL ok = FALSE; |
80 | 80 |
81 BLOCK_INPUT; | 81 BLOCK_INPUT; |
82 | 82 |
83 ok = EmptyClipboard (); | 83 ok = EmptyClipboard (); |
84 | 84 |
85 UNBLOCK_INPUT; | 85 UNBLOCK_INPUT; |
86 | 86 |
87 return (ok ? Qt : Qnil); | 87 return (ok ? Qt : Qnil); |
88 } | 88 } |
89 | 89 |
90 DEFUN ("w32-close-clipboard", Fw32_close_clipboard, | 90 DEFUN ("w32-close-clipboard", Fw32_close_clipboard, |
91 Sw32_close_clipboard, 0, 0, 0, | 91 Sw32_close_clipboard, 0, 0, 0, |
92 doc: /* Close the clipboard. */) | 92 doc: /* Close the clipboard. */) |
93 () | 93 () |
94 { | 94 { |
95 BOOL ok = FALSE; | 95 BOOL ok = FALSE; |
96 | 96 |
97 BLOCK_INPUT; | 97 BLOCK_INPUT; |
98 | 98 |
99 ok = CloseClipboard (); | 99 ok = CloseClipboard (); |
100 | 100 |
101 UNBLOCK_INPUT; | 101 UNBLOCK_INPUT; |
102 | 102 |
103 return (ok ? Qt : Qnil); | 103 return (ok ? Qt : Qnil); |
104 } | 104 } |
105 | 105 |
106 #endif | 106 #endif |
107 | 107 |
117 int truelen, nlines = 0; | 117 int truelen, nlines = 0; |
118 unsigned char *src; | 118 unsigned char *src; |
119 unsigned char *dst; | 119 unsigned char *dst; |
120 | 120 |
121 CHECK_STRING (string); | 121 CHECK_STRING (string); |
122 | 122 |
123 if (!NILP (frame)) | 123 if (!NILP (frame)) |
124 CHECK_LIVE_FRAME (frame); | 124 CHECK_LIVE_FRAME (frame); |
125 | 125 |
126 BLOCK_INPUT; | 126 BLOCK_INPUT; |
127 | 127 |
128 nbytes = SBYTES (string) + 1; | 128 nbytes = SBYTES (string) + 1; |
129 src = SDATA (string); | 129 src = SDATA (string); |
130 dst = src; | 130 dst = src; |
157 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) | 157 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) |
158 goto error; | 158 goto error; |
159 | 159 |
160 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) | 160 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
161 goto error; | 161 goto error; |
162 | 162 |
163 /* convert to CRLF line endings expected by clipboard */ | 163 /* convert to CRLF line endings expected by clipboard */ |
164 while (1) | 164 while (1) |
165 { | 165 { |
166 unsigned char *next; | 166 unsigned char *next; |
167 /* copy next line or remaining bytes including '\0' */ | 167 /* copy next line or remaining bytes including '\0' */ |
174 src += copied; | 174 src += copied; |
175 /* insert '\r' before '\n' */ | 175 /* insert '\r' before '\n' */ |
176 next[-1] = '\r'; | 176 next[-1] = '\r'; |
177 next[0] = '\n'; | 177 next[0] = '\n'; |
178 dst = next + 1; | 178 dst = next + 1; |
179 } | 179 } |
180 else | 180 else |
181 /* copied remaining partial line -> now finished */ | 181 /* copied remaining partial line -> now finished */ |
182 break; | 182 break; |
183 } | 183 } |
184 | 184 |
185 GlobalUnlock (htext); | 185 GlobalUnlock (htext); |
186 | 186 |
187 Vlast_coding_system_used = Qraw_text; | 187 Vlast_coding_system_used = Qraw_text; |
188 } | 188 } |
189 else | 189 else |
235 htext2 = GlobalReAlloc (htext, coding.produced, | 235 htext2 = GlobalReAlloc (htext, coding.produced, |
236 GMEM_MOVEABLE | GMEM_DDESHARE); | 236 GMEM_MOVEABLE | GMEM_DDESHARE); |
237 if (htext2 != NULL) htext = htext2; | 237 if (htext2 != NULL) htext = htext2; |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) | 241 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
242 goto error; | 242 goto error; |
243 | 243 |
244 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); | 244 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); |
245 | 245 |
246 CloseClipboard (); | 246 CloseClipboard (); |
247 | 247 |
248 if (ok) goto done; | 248 if (ok) goto done; |
249 | 249 |
250 error: | 250 error: |
251 | 251 |
252 ok = FALSE; | 252 ok = FALSE; |
253 if (htext) GlobalFree (htext); | 253 if (htext) GlobalFree (htext); |
254 if (last_clipboard_text) | 254 if (last_clipboard_text) |
255 *last_clipboard_text = '\0'; | 255 *last_clipboard_text = '\0'; |
256 | 256 |
257 done: | 257 done: |
258 UNBLOCK_INPUT; | 258 UNBLOCK_INPUT; |
259 | 259 |
260 return (ok ? string : Qnil); | 260 return (ok ? string : Qnil); |
261 } | 261 } |
262 | 262 |
263 DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, | 263 DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, |
264 Sw32_get_clipboard_data, 0, 1, 0, | 264 Sw32_get_clipboard_data, 0, 1, 0, |
266 (frame) | 266 (frame) |
267 Lisp_Object frame; | 267 Lisp_Object frame; |
268 { | 268 { |
269 HANDLE htext; | 269 HANDLE htext; |
270 Lisp_Object ret = Qnil; | 270 Lisp_Object ret = Qnil; |
271 | 271 |
272 if (!NILP (frame)) | 272 if (!NILP (frame)) |
273 CHECK_LIVE_FRAME (frame); | 273 CHECK_LIVE_FRAME (frame); |
274 | 274 |
275 BLOCK_INPUT; | 275 BLOCK_INPUT; |
276 | 276 |
277 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) | 277 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
278 goto done; | 278 goto done; |
279 | 279 |
280 if ((htext = GetClipboardData (CF_TEXT)) == NULL) | 280 if ((htext = GetClipboardData (CF_TEXT)) == NULL) |
281 goto closeclip; | 281 goto closeclip; |
282 | 282 |
283 { | 283 { |
284 unsigned char *src; | 284 unsigned char *src; |
285 unsigned char *dst; | 285 unsigned char *dst; |
286 int nbytes; | 286 int nbytes; |
287 int truelen; | 287 int truelen; |
288 int require_decoding = 0; | 288 int require_decoding = 0; |
289 | 289 |
290 if ((src = (unsigned char *) GlobalLock (htext)) == NULL) | 290 if ((src = (unsigned char *) GlobalLock (htext)) == NULL) |
291 goto closeclip; | 291 goto closeclip; |
292 | 292 |
293 nbytes = strlen (src); | 293 nbytes = strlen (src); |
294 | 294 |
295 /* If the text in clipboard is identical to what we put there | 295 /* If the text in clipboard is identical to what we put there |
296 last time w32_set_clipboard_data was called, pretend there's no | 296 last time w32_set_clipboard_data was called, pretend there's no |
297 data in the clipboard. This is so we don't pass our own text | 297 data in the clipboard. This is so we don't pass our own text |
395 GlobalUnlock (htext); | 395 GlobalUnlock (htext); |
396 } | 396 } |
397 | 397 |
398 closeclip: | 398 closeclip: |
399 CloseClipboard (); | 399 CloseClipboard (); |
400 | 400 |
401 done: | 401 done: |
402 UNBLOCK_INPUT; | 402 UNBLOCK_INPUT; |
403 | 403 |
404 return (ret); | 404 return (ret); |
405 } | 405 } |
406 | 406 |
407 /* Support checking for a clipboard selection. */ | 407 /* Support checking for a clipboard selection. */ |
408 | 408 |
440 return val; | 440 return val; |
441 } | 441 } |
442 return Qnil; | 442 return Qnil; |
443 } | 443 } |
444 | 444 |
445 void | 445 void |
446 syms_of_w32select () | 446 syms_of_w32select () |
447 { | 447 { |
448 #if 0 | 448 #if 0 |
449 defsubr (&Sw32_open_clipboard); | 449 defsubr (&Sw32_open_clipboard); |
450 defsubr (&Sw32_empty_clipboard); | 450 defsubr (&Sw32_empty_clipboard); |
455 defsubr (&Sx_selection_exists_p); | 455 defsubr (&Sx_selection_exists_p); |
456 | 456 |
457 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, | 457 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, |
458 doc: /* Coding system for communicating with other programs. | 458 doc: /* Coding system for communicating with other programs. |
459 When sending or receiving text via cut_buffer, selection, and clipboard, | 459 When sending or receiving text via cut_buffer, selection, and clipboard, |
460 the text is encoded or decoded by this coding system. */); | 460 the text is encoded or decoded by this coding system. |
461 Vselection_coding_system=intern ("iso-latin-1-dos"); | 461 The default value is `iso-latin-1-dos'. */); |
462 Vselection_coding_system = intern ("iso-latin-1-dos"); | |
462 | 463 |
463 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, | 464 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, |
464 doc: /* Coding system for the next communication with other programs. | 465 doc: /* Coding system for the next communication with other programs. |
465 Usually, `selection-coding-system' is used for communicating with | 466 Usually, `selection-coding-system' is used for communicating with |
466 other programs. But, if this variable is set, it is used for the | 467 other programs. But, if this variable is set, it is used for the |