1 |
/* Selection processing for Emacs on the Microsoft W32 API. |
/* Selection processing for Emacs on the Microsoft W32 API. |
2 |
Copyright (C) 1993, 1994 Free Software Foundation. |
Copyright (C) 1993, 1994 Free Software Foundation. |
3 |
|
|
4 |
This file is part of GNU Emacs. |
This file is part of GNU Emacs. |
5 |
|
|
6 |
GNU Emacs is free software; you can redistribute it and/or modify |
GNU Emacs is free software; you can redistribute it and/or modify |
30 |
#include "buffer.h" |
#include "buffer.h" |
31 |
#include "charset.h" |
#include "charset.h" |
32 |
#include "coding.h" |
#include "coding.h" |
33 |
|
#include "composite.h" |
34 |
|
|
35 |
Lisp_Object QCLIPBOARD; |
Lisp_Object QCLIPBOARD; |
36 |
|
|
57 |
Lisp_Object frame; |
Lisp_Object frame; |
58 |
{ |
{ |
59 |
BOOL ok = FALSE; |
BOOL ok = FALSE; |
60 |
|
|
61 |
if (!NILP (frame)) |
if (!NILP (frame)) |
62 |
CHECK_LIVE_FRAME (frame); |
CHECK_LIVE_FRAME (frame); |
63 |
|
|
64 |
BLOCK_INPUT; |
BLOCK_INPUT; |
65 |
|
|
66 |
ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); |
ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); |
67 |
|
|
68 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
69 |
|
|
70 |
return (ok ? frame : Qnil); |
return (ok ? frame : Qnil); |
71 |
} |
} |
72 |
|
|
77 |
() |
() |
78 |
{ |
{ |
79 |
BOOL ok = FALSE; |
BOOL ok = FALSE; |
80 |
|
|
81 |
BLOCK_INPUT; |
BLOCK_INPUT; |
82 |
|
|
83 |
ok = EmptyClipboard (); |
ok = EmptyClipboard (); |
84 |
|
|
85 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
86 |
|
|
87 |
return (ok ? Qt : Qnil); |
return (ok ? Qt : Qnil); |
88 |
} |
} |
89 |
|
|
93 |
() |
() |
94 |
{ |
{ |
95 |
BOOL ok = FALSE; |
BOOL ok = FALSE; |
96 |
|
|
97 |
BLOCK_INPUT; |
BLOCK_INPUT; |
98 |
|
|
99 |
ok = CloseClipboard (); |
ok = CloseClipboard (); |
100 |
|
|
101 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
102 |
|
|
103 |
return (ok ? Qt : Qnil); |
return (ok ? Qt : Qnil); |
104 |
} |
} |
105 |
|
|
119 |
unsigned char *dst; |
unsigned char *dst; |
120 |
|
|
121 |
CHECK_STRING (string); |
CHECK_STRING (string); |
122 |
|
|
123 |
if (!NILP (frame)) |
if (!NILP (frame)) |
124 |
CHECK_LIVE_FRAME (frame); |
CHECK_LIVE_FRAME (frame); |
125 |
|
|
126 |
BLOCK_INPUT; |
BLOCK_INPUT; |
127 |
|
|
128 |
nbytes = STRING_BYTES (XSTRING (string)) + 1; |
nbytes = SBYTES (string) + 1; |
129 |
src = XSTRING (string)->data; |
src = SDATA (string); |
130 |
dst = src; |
dst = src; |
131 |
|
|
132 |
/* We need to know how many lines there are, since we need CRLF line |
/* We need to know how many lines there are, since we need CRLF line |
141 |
{ |
{ |
142 |
/* Since we are now handling multilingual text, we must consider |
/* Since we are now handling multilingual text, we must consider |
143 |
encoding text for the clipboard. */ |
encoding text for the clipboard. */ |
144 |
int charset_info = find_charset_in_text (src, XSTRING (string)->size, |
int charset_info = find_charset_in_text (src, SCHARS (string), |
145 |
nbytes, NULL, Qnil); |
nbytes, NULL, Qnil); |
146 |
|
|
147 |
if (charset_info == 0) |
if (charset_info == 0) |
159 |
|
|
160 |
if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
161 |
goto error; |
goto error; |
162 |
|
|
163 |
/* convert to CRLF line endings expected by clipboard */ |
/* convert to CRLF line endings expected by clipboard */ |
164 |
while (1) |
while (1) |
165 |
{ |
{ |
176 |
next[-1] = '\r'; |
next[-1] = '\r'; |
177 |
next[0] = '\n'; |
next[0] = '\n'; |
178 |
dst = next + 1; |
dst = next + 1; |
179 |
} |
} |
180 |
else |
else |
181 |
/* copied remaining partial line -> now finished */ |
/* copied remaining partial line -> now finished */ |
182 |
break; |
break; |
183 |
} |
} |
184 |
|
|
185 |
GlobalUnlock (htext); |
GlobalUnlock (htext); |
186 |
|
|
187 |
Vlast_coding_system_used = Qraw_text; |
Vlast_coding_system_used = Qraw_text; |
202 |
&& !NILP (Ffboundp (coding.pre_write_conversion))) |
&& !NILP (Ffboundp (coding.pre_write_conversion))) |
203 |
{ |
{ |
204 |
string = run_pre_post_conversion_on_str (string, &coding, 1); |
string = run_pre_post_conversion_on_str (string, &coding, 1); |
205 |
src = XSTRING (string)->data; |
src = SDATA (string); |
206 |
nbytes = STRING_BYTES (XSTRING (string)); |
nbytes = SBYTES (string); |
207 |
} |
} |
208 |
coding.src_multibyte = 1; |
coding.src_multibyte = 1; |
209 |
coding.dst_multibyte = 0; |
coding.dst_multibyte = 0; |
237 |
if (htext2 != NULL) htext = htext2; |
if (htext2 != NULL) htext = htext2; |
238 |
} |
} |
239 |
} |
} |
240 |
|
|
241 |
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
242 |
goto error; |
goto error; |
243 |
|
|
244 |
ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); |
ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); |
245 |
|
|
246 |
CloseClipboard (); |
CloseClipboard (); |
247 |
|
|
248 |
if (ok) goto done; |
if (ok) goto done; |
249 |
|
|
250 |
error: |
error: |
251 |
|
|
252 |
ok = FALSE; |
ok = FALSE; |
253 |
if (htext) GlobalFree (htext); |
if (htext) GlobalFree (htext); |
254 |
if (last_clipboard_text) |
if (last_clipboard_text) |
256 |
|
|
257 |
done: |
done: |
258 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
259 |
|
|
260 |
return (ok ? string : Qnil); |
return (ok ? string : Qnil); |
261 |
} |
} |
262 |
|
|
268 |
{ |
{ |
269 |
HANDLE htext; |
HANDLE htext; |
270 |
Lisp_Object ret = Qnil; |
Lisp_Object ret = Qnil; |
271 |
|
|
272 |
if (!NILP (frame)) |
if (!NILP (frame)) |
273 |
CHECK_LIVE_FRAME (frame); |
CHECK_LIVE_FRAME (frame); |
274 |
|
|
275 |
BLOCK_INPUT; |
BLOCK_INPUT; |
276 |
|
|
277 |
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) |
278 |
goto done; |
goto done; |
279 |
|
|
280 |
if ((htext = GetClipboardData (CF_TEXT)) == NULL) |
if ((htext = GetClipboardData (CF_TEXT)) == NULL) |
281 |
goto closeclip; |
goto closeclip; |
282 |
|
|
286 |
int nbytes; |
int nbytes; |
287 |
int truelen; |
int truelen; |
288 |
int require_decoding = 0; |
int require_decoding = 0; |
289 |
|
|
290 |
if ((src = (unsigned char *) GlobalLock (htext)) == NULL) |
if ((src = (unsigned char *) GlobalLock (htext)) == NULL) |
291 |
goto closeclip; |
goto closeclip; |
292 |
|
|
293 |
nbytes = strlen (src); |
nbytes = strlen (src); |
294 |
|
|
295 |
/* If the text in clipboard is identical to what we put there |
/* If the text in clipboard is identical to what we put there |
331 |
coding.dst_multibyte = 1; |
coding.dst_multibyte = 1; |
332 |
Vnext_selection_coding_system = Qnil; |
Vnext_selection_coding_system = Qnil; |
333 |
coding.mode |= CODING_MODE_LAST_BLOCK; |
coding.mode |= CODING_MODE_LAST_BLOCK; |
334 |
|
/* We explicitely disable composition handling because |
335 |
|
selection data should not contain any composition |
336 |
|
sequence. */ |
337 |
|
coding.composing = COMPOSITION_DISABLED; |
338 |
bufsize = decoding_buffer_size (&coding, nbytes); |
bufsize = decoding_buffer_size (&coding, nbytes); |
339 |
buf = (unsigned char *) xmalloc (bufsize); |
buf = (unsigned char *) xmalloc (bufsize); |
340 |
decode_coding (&coding, src, buf, nbytes, bufsize); |
decode_coding (&coding, src, buf, nbytes, bufsize); |
368 |
/* Convert CRLF line endings (the standard CF_TEXT clipboard |
/* Convert CRLF line endings (the standard CF_TEXT clipboard |
369 |
format) to LF endings as used internally by Emacs. */ |
format) to LF endings as used internally by Emacs. */ |
370 |
|
|
371 |
dst = XSTRING (ret)->data; |
dst = SDATA (ret); |
372 |
while (1) |
while (1) |
373 |
{ |
{ |
374 |
unsigned char *next; |
unsigned char *next; |
397 |
|
|
398 |
closeclip: |
closeclip: |
399 |
CloseClipboard (); |
CloseClipboard (); |
400 |
|
|
401 |
done: |
done: |
402 |
UNBLOCK_INPUT; |
UNBLOCK_INPUT; |
403 |
|
|
404 |
return (ret); |
return (ret); |
405 |
} |
} |
406 |
|
|
442 |
return Qnil; |
return Qnil; |
443 |
} |
} |
444 |
|
|
445 |
void |
void |
446 |
syms_of_w32select () |
syms_of_w32select () |
447 |
{ |
{ |
448 |
#if 0 |
#if 0 |
457 |
DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, |
DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, |
458 |
doc: /* Coding system for communicating with other programs. |
doc: /* Coding system for communicating with other programs. |
459 |
When sending or receiving text via cut_buffer, selection, and clipboard, |
When sending or receiving text via cut_buffer, selection, and clipboard, |
460 |
the text is encoded or decoded by this coding system. */); |
the text is encoded or decoded by this coding system. |
461 |
Vselection_coding_system=intern ("iso-latin-1-dos"); |
The default value is `iso-latin-1-dos'. */); |
462 |
|
Vselection_coding_system = intern ("iso-latin-1-dos"); |
463 |
|
|
464 |
DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, |
DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, |
465 |
doc: /* Coding system for the next communication with other programs. |
doc: /* Coding system for the next communication with other programs. |
466 |
Usually, `selection-coding-system' is used for communicating with |
Usually, `selection-coding-system' is used for communicating with |
467 |
other programs. But, if this variable is set, it is used for the |
other programs. But, if this variable is set, it is used for the |
468 |
next communication only. After the communication, this variable is |
next communication only. After the communication, this variable is |
469 |
set to nil. */); |
set to nil. */); |
470 |
Vnext_selection_coding_system = Qnil; |
Vnext_selection_coding_system = Qnil; |
471 |
|
|