Mercurial > emacs
annotate src/w16select.c @ 112433:7b649f6eac4f
Merge from mainline.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 22 Jan 2011 17:09:09 -0800 |
parents | 42e22c4f06b7 |
children |
rev | line source |
---|---|
21709
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
1 /* 16-bit Windows Selection processing for emacs on MS-Windows |
112284
61f7601898b1
Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents:
112228
diff
changeset
|
2 |
61f7601898b1
Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents:
112228
diff
changeset
|
3 Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
61f7601898b1
Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents:
112228
diff
changeset
|
4 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
45333 | 5 |
17451 | 6 This file is part of GNU Emacs. |
7 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91327
diff
changeset
|
8 GNU Emacs is free software: you can redistribute it and/or modify |
17451 | 9 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91327
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91327
diff
changeset
|
11 (at your option) any later version. |
17451 | 12 |
13 GNU Emacs is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91327
diff
changeset
|
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
17451 | 20 |
21 /* These functions work by using WinOldAp interface. WinOldAp | |
22 (WINOLDAP.MOD) is a Microsoft Windows extension supporting | |
23 "old" (character-mode) application access to Dynamic Data Exchange, | |
24 menus, and the Windows clipboard. */ | |
25 | |
26 /* Written by Dale P. Smith <dpsm@en.com> */ | |
107733
84b961690802
Remove support for DJGPP v1.x (bug#5813).
Eli Zaretskii <eliz@gnu.org>
parents:
106815
diff
changeset
|
27 /* Adapted to DJGPP by Eli Zaretskii <eliz@gnu.org> */ |
17451 | 28 |
29 #ifdef MSDOS | |
30 | |
31 #include <config.h> | |
32 #include <dpmi.h> | |
33 #include <go32.h> | |
34 #include <sys/farptr.h> | |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100951
diff
changeset
|
35 #include <setjmp.h> |
17451 | 36 #include "lisp.h" |
37 #include "dispextern.h" /* frame.h seems to want this */ | |
38 #include "frame.h" /* Need this to get the X window of selected_frame */ | |
39 #include "blockinput.h" | |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
40 #include "buffer.h" |
88351
aac41b50c875
Include "character.h" instead of "charset.h".
Kenichi Handa <handa@m17n.org>
parents:
43475
diff
changeset
|
41 #include "character.h" |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
42 #include "coding.h" |
45988
37913830a881
Include composite.h
Juanma Barranquero <lekktu@gmail.com>
parents:
45982
diff
changeset
|
43 #include "composite.h" |
17451 | 44 |
45 /* If ever some function outside this file will need to call any | |
46 clipboard-related function, the following prototypes and constants | |
47 should be put on a header file. Right now, nobody else uses them. */ | |
48 | |
49 #define CF_TEXT 0x01 | |
50 #define CF_BITMAP 0x02 | |
51 #define CF_METAFILE 0x03 | |
52 #define CF_SYLK 0x04 | |
53 #define CF_DIF 0x05 | |
54 #define CF_TIFF 0x06 | |
55 #define CF_OEMTEXT 0x07 | |
56 #define CF_DIBBITMAP 0x08 | |
57 #define CF_WINWRITE 0x80 | |
58 #define CF_DSPTEXT 0x81 | |
59 #define CF_DSPBITMAP 0x82 | |
60 | |
61 unsigned identify_winoldap_version (void); | |
62 unsigned open_clipboard (void); | |
63 unsigned empty_clipboard (void); | |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
64 unsigned set_clipboard_data (unsigned, void *, unsigned, int); |
17451 | 65 unsigned get_clipboard_data_size (unsigned); |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
66 unsigned get_clipboard_data (unsigned, void *, unsigned, int); |
17451 | 67 unsigned close_clipboard (void); |
68 unsigned clipboard_compact (unsigned); | |
69 | |
70 Lisp_Object QCLIPBOARD, QPRIMARY; | |
71 | |
72 /* The segment address and the size of the buffer in low | |
73 memory used to move data between us and WinOldAp module. */ | |
74 static struct { | |
75 unsigned long size; | |
76 unsigned short rm_segment; | |
77 } clipboard_xfer_buf_info; | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
78 |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
79 /* The last text we put into the clipboard. This is used to prevent |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
80 passing back our own text from the clipboard, instead of using the |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
81 kill ring. The former is undesirable because the clipboard data |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
82 could be MULEtilated by inappropriately chosen |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
83 (next-)selection-coding-system. For this reason, we must store the |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
84 text *after* it was encoded/Unix-to-DOS-converted. */ |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
85 static unsigned char *last_clipboard_text; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
86 |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
87 /* The size of allocated storage for storing the clipboard data. */ |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
88 static size_t clipboard_storage_size; |
17451 | 89 |
90 /* C functions to access the Windows 3.1x clipboard from DOS apps. | |
91 | |
92 The information was obtained from the Microsoft Knowledge Base, | |
93 article Q67675 and can be found at: | |
94 http://www.microsoft.com/kb/developr/win_dk/q67675.htm */ | |
95 | |
96 /* See also Ralf Brown's Interrupt List. | |
97 | |
98 I also seem to remember reading about this in Dr. Dobbs Journal a | |
99 while ago, but if you knew my memory... :-) | |
100 | |
101 Dale P. Smith <dpsm@en.com> */ | |
102 | |
103 /* Return the WinOldAp support version, or 0x1700 if not supported. */ | |
104 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
105 identify_winoldap_version (void) |
17451 | 106 { |
107 __dpmi_regs regs; | |
108 | |
109 /* Calls Int 2Fh/AX=1700h | |
110 Return Values AX == 1700H: Clipboard functions not available | |
111 <> 1700H: AL = Major version number | |
112 AH = Minor version number */ | |
113 regs.x.ax = 0x1700; | |
114 __dpmi_int(0x2f, ®s); | |
115 return regs.x.ax; | |
116 } | |
117 | |
118 /* Open the clipboard, return non-zero if successfull. */ | |
119 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
120 open_clipboard (void) |
17451 | 121 { |
122 __dpmi_regs regs; | |
123 | |
124 /* Is WINOLDAP supported? */ | |
125 /* Kludge alert!! If WinOldAp is not supported, we return a 0, | |
126 which is the same as ``Clipboard already open''. Currently, | |
127 this is taken as an error by all the functions that use | |
128 `open_clipboard', but if somebody someday will use that ``open'' | |
129 clipboard, they will have interesting time debugging it... */ | |
130 if (identify_winoldap_version () == 0x1700) | |
131 return 0; | |
132 | |
133 /* Calls Int 2Fh/AX=1701h | |
134 Return Values AX == 0: Clipboard already open | |
135 <> 0: Clipboard opened */ | |
136 regs.x.ax = 0x1701; | |
137 __dpmi_int(0x2f, ®s); | |
138 return regs.x.ax; | |
139 } | |
140 | |
141 /* Empty clipboard, return non-zero if successfull. */ | |
142 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
143 empty_clipboard (void) |
17451 | 144 { |
145 __dpmi_regs regs; | |
45333 | 146 |
17451 | 147 /* Calls Int 2Fh/AX=1702h |
148 Return Values AX == 0: Error occurred | |
149 <> 0: OK, Clipboard emptied */ | |
150 regs.x.ax = 0x1702; | |
151 __dpmi_int(0x2f, ®s); | |
152 return regs.x.ax; | |
153 } | |
154 | |
155 /* Ensure we have a buffer in low memory with enough memory for data | |
156 of size WANT_SIZE. Return the linear address of the buffer. */ | |
157 static unsigned long | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
158 alloc_xfer_buf (unsigned want_size) |
17451 | 159 { |
160 __dpmi_regs regs; | |
161 | |
162 /* If the usual DJGPP transfer buffer is large enough, use that. */ | |
163 if (want_size <= _go32_info_block.size_of_transfer_buffer) | |
164 return __tb & 0xfffff; | |
165 | |
21709
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
166 /* Don't even try to allocate more than 1MB of memory: DOS cannot |
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
167 possibly handle that (it will overflow the BX register below). */ |
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
168 if (want_size > 0xfffff) |
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
169 return 0; |
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
170 |
17451 | 171 /* Need size rounded up to the nearest paragraph, and in |
172 paragraph units (1 paragraph = 16 bytes). */ | |
173 clipboard_xfer_buf_info.size = (want_size + 15) >> 4; | |
174 | |
175 /* The NT DPMI host crashes us if we free DOS memory via the | |
176 DPMI service. Work around by calling DOS allocate/free block. */ | |
177 regs.h.ah = 0x48; | |
178 regs.x.bx = clipboard_xfer_buf_info.size; | |
179 __dpmi_int (0x21, ®s); | |
180 if (regs.x.flags & 1) | |
181 { | |
182 clipboard_xfer_buf_info.size = 0; | |
183 return 0; | |
184 } | |
185 | |
186 clipboard_xfer_buf_info.rm_segment = regs.x.ax; | |
187 return (((int)clipboard_xfer_buf_info.rm_segment) << 4) & 0xfffff; | |
188 } | |
189 | |
190 /* Free our clipboard buffer. We always free it after use, because | |
191 keeping it leaves less free conventional memory for subprocesses. | |
192 The clipboard buffer tends to be large in size, because for small | |
193 clipboard data sizes we use the DJGPP transfer buffer. */ | |
194 static void | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
195 free_xfer_buf (void) |
17451 | 196 { |
197 /* If the size is 0, we used DJGPP transfer buffer, so don't free. */ | |
198 if (clipboard_xfer_buf_info.size) | |
199 { | |
200 __dpmi_regs regs; | |
201 | |
202 /* The NT DPMI host crashes us if we free DOS memory via | |
203 the DPMI service. Work around by calling DOS free block. */ | |
204 regs.h.ah = 0x49; | |
205 regs.x.es = clipboard_xfer_buf_info.rm_segment; | |
206 __dpmi_int (0x21, ®s); | |
207 clipboard_xfer_buf_info.size = 0; | |
208 } | |
209 } | |
210 | |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
211 /* Copy data into the clipboard, return zero if successfull. */ |
17451 | 212 unsigned |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
213 set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw) |
17451 | 214 { |
215 __dpmi_regs regs; | |
216 unsigned truelen; | |
217 unsigned long xbuf_addr, buf_offset; | |
218 unsigned char *dp = Data, *dstart = dp; | |
219 | |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
220 if (Format != CF_OEMTEXT) |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
221 return 3; |
17451 | 222 |
223 /* need to know final size after '\r' chars are inserted (the | |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
224 standard CF_OEMTEXT clipboard format uses CRLF line endings, |
17451 | 225 while Emacs uses just LF internally). */ |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
226 truelen = Size + 1; /* +1 for the terminating null */ |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
227 |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
228 if (!Raw) |
17451 | 229 { |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
230 /* avoid using strchr because it recomputes the length everytime */ |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
231 while ((dp = memchr (dp, '\n', Size - (dp - dstart))) != 0) |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
232 { |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
233 truelen++; |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
234 dp++; |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
235 } |
17451 | 236 } |
237 | |
238 if (clipboard_compact (truelen) < truelen) | |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
239 return 1; |
17451 | 240 |
241 if ((xbuf_addr = alloc_xfer_buf (truelen)) == 0) | |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
242 return 1; |
17451 | 243 |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
244 /* Move the buffer into the low memory, convert LF into CR-LF if needed. */ |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
245 if (Raw) |
24251
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
246 { |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
247 dosmemput (Data, Size, xbuf_addr); |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
248 |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
249 /* Terminate with a null, otherwise Windows does strange things |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
250 when the text size is an integral multiple of 32 bytes. */ |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
251 _farpokeb (_dos_ds, xbuf_addr + Size, '\0'); |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
252 } |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
253 else |
17451 | 254 { |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
255 dp = Data; |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
256 buf_offset = xbuf_addr; |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
257 _farsetsel (_dos_ds); |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
258 while (Size--) |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
259 { |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
260 /* Don't allow them to put binary data into the clipboard, since |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
261 it will cause yanked data to be truncated at the first null. */ |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
262 if (*dp == '\0') |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
263 return 2; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
264 if (*dp == '\n') |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
265 _farnspokeb (buf_offset++, '\r'); |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
266 _farnspokeb (buf_offset++, *dp++); |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
267 } |
24251
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
268 |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
269 /* Terminate with a null, otherwise Windows does strange things |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
270 when the text size is an integral multiple of 32 bytes. */ |
2394581ada26
(set_clipboard_data): Correctly null-terminate the
Eli Zaretskii <eliz@gnu.org>
parents:
24003
diff
changeset
|
271 _farnspokeb (buf_offset, '\0'); |
17451 | 272 } |
273 | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
274 /* Stash away the data we are about to put into the clipboard, so we |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
275 could later check inside get_clipboard_data whether the clipboard |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
276 still holds our data. */ |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
277 if (clipboard_storage_size < truelen) |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
278 { |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
279 clipboard_storage_size = truelen + 100; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
280 last_clipboard_text = |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
281 (char *) xrealloc (last_clipboard_text, clipboard_storage_size); |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
282 } |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
283 if (last_clipboard_text) |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
284 dosmemget (xbuf_addr, truelen, last_clipboard_text); |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
285 |
17451 | 286 /* Calls Int 2Fh/AX=1703h with: |
287 DX = WinOldAp-Supported Clipboard format | |
288 ES:BX = Pointer to data | |
289 SI:CX = Size of data in bytes | |
290 Return Values AX == 0: Error occurred | |
291 <> 0: OK. Data copied into the Clipboard. */ | |
292 regs.x.ax = 0x1703; | |
293 regs.x.dx = Format; | |
294 regs.x.si = truelen >> 16; | |
295 regs.x.cx = truelen & 0xffff; | |
296 regs.x.es = xbuf_addr >> 4; | |
297 regs.x.bx = xbuf_addr & 15; | |
298 __dpmi_int(0x2f, ®s); | |
299 | |
300 free_xfer_buf (); | |
301 | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
302 /* If the above failed, invalidate the local copy of the clipboard. */ |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
303 if (regs.x.ax == 0) |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
304 *last_clipboard_text = '\0'; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
305 |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
306 /* Zero means success, otherwise (1, 2, or 3) it's an error. */ |
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
307 return regs.x.ax > 0 ? 0 : 3; |
17451 | 308 } |
309 | |
310 /* Return the size of the clipboard data of format FORMAT. */ | |
311 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
312 get_clipboard_data_size (unsigned Format) |
17451 | 313 { |
314 __dpmi_regs regs; | |
315 | |
316 /* Calls Int 2Fh/AX=1704h with: | |
317 DX = WinOldAp-Supported Clipboard format | |
318 Return Values DX:AX == Size of the data in bytes, including any | |
319 headers. | |
320 == 0 If data in this format is not in | |
321 the clipboard. */ | |
322 regs.x.ax = 0x1704; | |
323 regs.x.dx = Format; | |
324 __dpmi_int(0x2f, ®s); | |
325 return ( (((unsigned)regs.x.dx) << 16) | regs.x.ax); | |
326 } | |
327 | |
328 /* Get clipboard data, return its length. | |
329 Warning: this doesn't check whether DATA has enough space to hold | |
330 SIZE bytes. */ | |
331 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
332 get_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw) |
17451 | 333 { |
334 __dpmi_regs regs; | |
335 unsigned long xbuf_addr; | |
336 unsigned char *dp = Data; | |
337 | |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
338 if (Format != CF_OEMTEXT) |
17451 | 339 return 0; |
340 | |
341 if (Size == 0) | |
342 return 0; | |
343 | |
344 if ((xbuf_addr = alloc_xfer_buf (Size)) == 0) | |
345 return 0; | |
346 | |
347 /* Calls Int 2Fh/AX=1705h with: | |
348 DX = WinOldAp-Supported Clipboard format | |
349 ES:BX = Pointer to data buffer to hold data | |
350 Return Values AX == 0: Error occurred (or data in this format is not | |
351 in the clipboard) | |
352 <> 0: OK */ | |
353 regs.x.ax = 0x1705; | |
354 regs.x.dx = Format; | |
355 regs.x.es = xbuf_addr >> 4; | |
356 regs.x.bx = xbuf_addr & 15; | |
357 __dpmi_int(0x2f, ®s); | |
358 if (regs.x.ax != 0) | |
359 { | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
360 unsigned char null_char = '\0'; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
361 unsigned long xbuf_beg = xbuf_addr; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
362 |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
363 /* If last_clipboard_text is NULL, we don't want to slow down |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
364 the next loop by an additional test. */ |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
365 register unsigned char *lcdp = |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
366 last_clipboard_text == NULL ? &null_char : last_clipboard_text; |
45333 | 367 |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
368 /* Copy data from low memory, remove CR |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
369 characters before LF if needed. */ |
17451 | 370 _farsetsel (_dos_ds); |
371 while (Size--) | |
372 { | |
373 register unsigned char c = _farnspeekb (xbuf_addr++); | |
374 | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
375 if (*lcdp == c) |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
376 lcdp++; |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
377 |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
378 if ((*dp++ = c) == '\r' && !Raw && _farnspeekb (xbuf_addr) == '\n') |
17451 | 379 { |
380 dp--; | |
381 *dp++ = '\n'; | |
382 xbuf_addr++; | |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
383 if (*lcdp == '\n') |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
384 lcdp++; |
17451 | 385 } |
386 /* Windows reportedly rounds up the size of clipboard data | |
24428
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
387 (passed in SIZE) to a multiple of 32, and removes trailing |
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
388 spaces from each line without updating SIZE. We therefore |
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
389 bail out when we see the first null character. */ |
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
390 else if (c == '\0') |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
391 break; |
17451 | 392 } |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
393 |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
394 /* If the text in clipboard is identical to what we put there |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
395 last time set_clipboard_data was called, pretend there's no |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
396 data in the clipboard. This is so we don't pass our own text |
24428
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
397 from the clipboard (which might be troublesome if the killed |
3d10131927a6
(get_clipboard_data): Always stop at the first null byte.
Eli Zaretskii <eliz@gnu.org>
parents:
24318
diff
changeset
|
398 text includes null characters). */ |
24260
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
399 if (last_clipboard_text && |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
400 xbuf_addr - xbuf_beg == (long)(lcdp - last_clipboard_text)) |
bd3ce96bc7eb
(last_clipboard_text, clipboard_storage_size): New
Eli Zaretskii <eliz@gnu.org>
parents:
24258
diff
changeset
|
401 dp = (unsigned char *)Data + 1; |
17451 | 402 } |
403 | |
404 free_xfer_buf (); | |
405 | |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
406 return (unsigned) (dp - (unsigned char *)Data - 1); |
17451 | 407 } |
408 | |
409 /* Close clipboard, return non-zero if successfull. */ | |
410 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
411 close_clipboard (void) |
17451 | 412 { |
413 __dpmi_regs regs; | |
414 | |
415 /* Calls Int 2Fh/AX=1708h | |
416 Return Values AX == 0: Error occurred | |
417 <> 0: OK */ | |
418 regs.x.ax = 0x1708; | |
419 __dpmi_int(0x2f, ®s); | |
420 return regs.x.ax; | |
421 } | |
422 | |
423 /* Compact clipboard data so that at least SIZE bytes is available. */ | |
424 unsigned | |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
425 clipboard_compact (unsigned Size) |
17451 | 426 { |
427 __dpmi_regs regs; | |
428 | |
429 /* Calls Int 2Fh/AX=1709H with: | |
430 SI:CX = Desired memory size in bytes. | |
431 Return Values DX:AX == Number of bytes of largest block of free memory. | |
432 == 0 if error or no memory */ | |
433 regs.x.ax = 0x1709; | |
434 regs.x.si = Size >> 16; | |
435 regs.x.cx = Size & 0xffff; | |
436 __dpmi_int(0x2f, ®s); | |
437 return ((unsigned)regs.x.dx << 16) | regs.x.ax; | |
438 } | |
439 | |
440 static char no_mem_msg[] = | |
441 "(Not enough DOS memory to put saved text into clipboard.)"; | |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
442 static char binary_msg[] = |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
443 "(Binary characters in saved text; clipboard data not set.)"; |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
444 static char system_error_msg[] = |
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
445 "(Clipboard interface failure; clipboard data not set.)"; |
17451 | 446 |
21709
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
447 DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0, |
41940
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
448 doc: /* This sets the clipboard data to the given text. */) |
109179
8cfee7d2955f
Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109162
diff
changeset
|
449 (Lisp_Object string, Lisp_Object frame) |
17451 | 450 { |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
451 unsigned ok = 1, put_status = 0; |
109761
31def5db596a
Fix -Wall compiler warnings in MSDOS sources.
Eli Zaretskii <eliz@gnu.org>
parents:
109179
diff
changeset
|
452 int nbytes, no_crlf_conversion; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
453 unsigned char *src, *dst = NULL; |
17451 | 454 |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
37858
diff
changeset
|
455 CHECK_STRING (string); |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
456 |
17451 | 457 if (NILP (frame)) |
458 frame = Fselected_frame (); | |
459 | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
37858
diff
changeset
|
460 CHECK_LIVE_FRAME (frame); |
17451 | 461 if ( !FRAME_MSDOS_P (XFRAME (frame))) |
462 goto done; | |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
463 |
17451 | 464 BLOCK_INPUT; |
465 | |
97869
455b25c4ebc2
(Fw16_set_clipboard_data): Don't encode text if clipboard is unavailable.
Eli Zaretskii <eliz@gnu.org>
parents:
97651
diff
changeset
|
466 if (!open_clipboard ()) |
455b25c4ebc2
(Fw16_set_clipboard_data): Don't encode text if clipboard is unavailable.
Eli Zaretskii <eliz@gnu.org>
parents:
97651
diff
changeset
|
467 goto error; |
455b25c4ebc2
(Fw16_set_clipboard_data): Don't encode text if clipboard is unavailable.
Eli Zaretskii <eliz@gnu.org>
parents:
97651
diff
changeset
|
468 |
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45988
diff
changeset
|
469 nbytes = SBYTES (string); |
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents:
45988
diff
changeset
|
470 src = SDATA (string); |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
471 |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
472 /* Do we need to encode this text? */ |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
473 for (dst = src; dst < src + nbytes; dst++) |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
474 { |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
475 if (*dst == '\0' || *dst >= 0x80) |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
476 break; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
477 } |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
478 if (dst >= src + nbytes) |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
479 { |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
480 /* No multibyte characters in text. We need not encode it, but we |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
481 will have to convert it to DOS CR-LF style. */ |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
482 no_crlf_conversion = 0; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
483 Vlast_coding_system_used = Qraw_text; |
97869
455b25c4ebc2
(Fw16_set_clipboard_data): Don't encode text if clipboard is unavailable.
Eli Zaretskii <eliz@gnu.org>
parents:
97651
diff
changeset
|
484 dst = NULL; /* so we don't try to free a random pointer */ |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
485 } |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
486 else |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
487 { |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
488 /* We must encode contents of STRING according to what |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
489 clipboard-coding-system specifies. */ |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
490 struct coding_system coding; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
491 Lisp_Object coding_system = |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
492 NILP (Vnext_selection_coding_system) ? |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
493 Vselection_coding_system : Vnext_selection_coding_system; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
494 |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
495 setup_coding_system (Fcheck_coding_system (coding_system), &coding); |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
496 coding.dst_bytes = nbytes * 4; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
497 coding.destination = (unsigned char *) xmalloc (coding.dst_bytes); |
23164
ecc4641bf00a
(Vnext_selection_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
22904
diff
changeset
|
498 Vnext_selection_coding_system = Qnil; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
499 coding.mode |= CODING_MODE_LAST_BLOCK; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
500 dst = coding.destination; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
501 encode_coding_object (&coding, string, 0, 0, |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
502 SCHARS (string), nbytes, Qnil); |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
503 no_crlf_conversion = 1; |
24257
7507c0552393
(Fw16_set_clipboard_data): When the text needs to be
Eli Zaretskii <eliz@gnu.org>
parents:
24251
diff
changeset
|
504 nbytes = coding.produced; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
505 Vlast_coding_system_used = CODING_ID_NAME (coding.id); |
24258 | 506 src = dst; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
507 } |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
508 |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
509 ok = empty_clipboard () |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
510 && ((put_status |
24258 | 511 = set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion)) |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
512 == 0); |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
513 |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
514 if (!no_crlf_conversion) |
17451 | 515 close_clipboard (); |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
516 |
21707
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
517 if (ok) goto unblock; |
17451 | 518 |
519 error: | |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
520 |
17451 | 521 ok = 0; |
522 | |
21707
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
523 unblock: |
95481
4390d64d3328
Make "xfree (NULL)" a no-op; remove useless if-before-xfree.
Jim Meyering <jim@meyering.net>
parents:
94963
diff
changeset
|
524 xfree (dst); |
21707
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
525 UNBLOCK_INPUT; |
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
526 |
17451 | 527 /* Notify user if the text is too large to fit into DOS memory. |
528 (This will happen somewhere after 600K bytes (470K in DJGPP v1.x), | |
529 depending on user system configuration.) If we just silently | |
530 fail the function, people might wonder why their text sometimes | |
531 doesn't make it to the clipboard. */ | |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
532 if (put_status) |
17451 | 533 { |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
534 switch (put_status) |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
535 { |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
536 case 1: |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
537 message2 (no_mem_msg, sizeof (no_mem_msg) - 1, 0); |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
538 break; |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
539 case 2: |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
540 message2 (binary_msg, sizeof (binary_msg) - 1, 0); |
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
541 break; |
30900
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
542 case 3: |
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
543 message2 (system_error_msg, sizeof (system_error_msg) - 1, 0); |
2bec1c202b13
(set_clipboard_data): If there's not enough memory
Eli Zaretskii <eliz@gnu.org>
parents:
29179
diff
changeset
|
544 break; |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
545 } |
74183
727f68fa1f38
(Fw16_set_clipboard_data): Fix the call to sit_for as per the calling sequence
Eli Zaretskii <eliz@gnu.org>
parents:
68651
diff
changeset
|
546 sit_for (make_number (2), 0, 2); |
17451 | 547 } |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
548 |
17451 | 549 done: |
550 | |
24003
5048f069091e
(set_clipboard_data): Terminate the text with a null
Eli Zaretskii <eliz@gnu.org>
parents:
23875
diff
changeset
|
551 return (ok && put_status == 0 ? string : Qnil); |
17451 | 552 } |
553 | |
21709
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
554 DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0, |
41940
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
555 doc: /* This gets the clipboard data in text format. */) |
109179
8cfee7d2955f
Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109162
diff
changeset
|
556 (Lisp_Object frame) |
17451 | 557 { |
558 unsigned data_size, truelen; | |
97869
455b25c4ebc2
(Fw16_set_clipboard_data): Don't encode text if clipboard is unavailable.
Eli Zaretskii <eliz@gnu.org>
parents:
97651
diff
changeset
|
559 unsigned char *htext = NULL; |
17451 | 560 Lisp_Object ret = Qnil; |
109761
31def5db596a
Fix -Wall compiler warnings in MSDOS sources.
Eli Zaretskii <eliz@gnu.org>
parents:
109179
diff
changeset
|
561 int require_decoding = 0; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
562 |
17451 | 563 if (NILP (frame)) |
564 frame = Fselected_frame (); | |
565 | |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
37858
diff
changeset
|
566 CHECK_LIVE_FRAME (frame); |
17451 | 567 if ( !FRAME_MSDOS_P (XFRAME (frame))) |
568 goto done; | |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
569 |
17451 | 570 BLOCK_INPUT; |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
571 |
17451 | 572 if (!open_clipboard ()) |
21707
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
573 goto unblock; |
17451 | 574 |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
575 if ((data_size = get_clipboard_data_size (CF_OEMTEXT)) == 0 || |
17451 | 576 (htext = (unsigned char *)xmalloc (data_size)) == 0) |
577 goto closeclip; | |
578 | |
579 /* need to know final size after '\r' chars are removed because | |
580 we can't change the string size manually, and doing an extra | |
581 copy is silly */ | |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
582 if ((truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 0)) == 0) |
17451 | 583 goto closeclip; |
584 | |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
585 /* Do we need to decode it? */ |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
586 { |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
587 /* If the clipboard data contains any 8-bit Latin-1 code, we |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
588 need to decode it. */ |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
589 int i; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
590 |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
591 for (i = 0; i < truelen; i++) |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
592 { |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
593 if (htext[i] >= 0x80) |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
594 { |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
595 require_decoding = 1; |
43460
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
596 break; |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
597 } |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
598 } |
aa52a9cea9f8
(Fw16_set_clipboard_data): Run pre-write-conversion
Eli Zaretskii <eliz@gnu.org>
parents:
41940
diff
changeset
|
599 } |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
600 if (require_decoding) |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
601 { |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
602 struct coding_system coding; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
603 Lisp_Object coding_system = Vnext_selection_coding_system; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
604 |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
605 truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1); |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
606 if (NILP (coding_system)) |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
607 coding_system = Vselection_coding_system; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
608 setup_coding_system (Fcheck_coding_system (coding_system), &coding); |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
609 coding.source = htext; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
610 coding.mode |= CODING_MODE_LAST_BLOCK; |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
611 /* We explicitly disable composition handling because selection |
45982
864289635b41
(Fw16_get_clipboard_data): Disable composition handling.
Kenichi Handa <handa@m17n.org>
parents:
45333
diff
changeset
|
612 data should not contain any composition sequence. */ |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
613 coding.mode &= CODING_ANNOTATION_MASK; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
614 decode_coding_object (&coding, Qnil, 0, 0, truelen, truelen, Qt); |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
615 ret = coding.dst_object; |
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
616 Vlast_coding_system_used = CODING_ID_NAME (coding.id); |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
617 } |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
618 else |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
619 { |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
620 ret = make_unibyte_string ((char *) htext, truelen); |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
621 Vlast_coding_system_used = Qraw_text; |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
622 } |
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
623 |
17451 | 624 xfree (htext); |
97651
62ec1a5d873b
(Fw16_set_clipboard_data, Fw16_get_clipboard_data): Adjust for changes in
Eli Zaretskii <eliz@gnu.org>
parents:
95481
diff
changeset
|
625 Vnext_selection_coding_system = Qnil; |
17451 | 626 |
627 closeclip: | |
628 close_clipboard (); | |
21707
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
629 |
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
630 unblock: |
7b76832ac019
(Fwin16_set_clipboard_data): Call UNBLOCK_INPUT before calling sit_for.
Eli Zaretskii <eliz@gnu.org>
parents:
21417
diff
changeset
|
631 UNBLOCK_INPUT; |
45333 | 632 |
17451 | 633 done: |
45333 | 634 |
17451 | 635 return (ret); |
636 } | |
637 | |
638 /* Support checking for a clipboard selection. */ | |
639 | |
640 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p, | |
41940
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
641 0, 1, 0, |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
642 doc: /* Whether there is an owner for the given X Selection. |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
643 The arg should be the name of the selection in question, typically one of |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
644 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
645 \(Those are literal upper-case symbol names, since that's what X expects.) |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
646 For convenience, the symbol nil is the same as `PRIMARY', |
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
647 and t is the same as `SECONDARY'. */) |
109179
8cfee7d2955f
Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109162
diff
changeset
|
648 (Lisp_Object selection) |
17451 | 649 { |
40656
cdfd4d09b79a
Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents:
37858
diff
changeset
|
650 CHECK_SYMBOL (selection); |
17451 | 651 |
652 /* Return nil for SECONDARY selection. For PRIMARY (or nil) | |
653 selection, check if there is some text on the kill-ring; | |
654 for CLIPBOARD, check if the clipboard currently has valid | |
655 text format contents. | |
656 | |
657 The test for killed text on the kill-ring emulates the Emacs | |
658 behavior on X, where killed text is also put into X selection | |
659 by the X interface code. (On MSDOS, killed text is only put | |
660 into the clipboard if we run under Windows, so we cannot check | |
661 the clipboard alone.) */ | |
662 if ((EQ (selection, Qnil) || EQ (selection, QPRIMARY)) | |
108299
a5fcd78ad3eb
Don't use XSYMBOL (foo)->value.
Eli Zaretskii <eliz@gnu.org>
parents:
107733
diff
changeset
|
663 && ! NILP (Fsymbol_value (Fintern_soft (build_string ("kill-ring"), |
a5fcd78ad3eb
Don't use XSYMBOL (foo)->value.
Eli Zaretskii <eliz@gnu.org>
parents:
107733
diff
changeset
|
664 Qnil)))) |
17451 | 665 return Qt; |
666 | |
667 if (EQ (selection, QCLIPBOARD)) | |
668 { | |
669 Lisp_Object val = Qnil; | |
670 | |
671 if (open_clipboard ()) | |
672 { | |
22749
14bde44d261c
(set_clipboard_data, get_clipboard_data, Fw16_set_clipboard_data,
Eli Zaretskii <eliz@gnu.org>
parents:
22729
diff
changeset
|
673 if (get_clipboard_data_size (CF_OEMTEXT)) |
17451 | 674 val = Qt; |
675 close_clipboard (); | |
676 } | |
677 return val; | |
678 } | |
679 return Qnil; | |
680 } | |
681 | |
45333 | 682 void |
109162
8efd6d04c47a
Convert function definitions in MS-DOS sources to ANSI C.
Eli Zaretskii <eliz@gnu.org>
parents:
108299
diff
changeset
|
683 syms_of_win16select (void) |
17451 | 684 { |
21709
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
685 defsubr (&Sw16_set_clipboard_data); |
64adf1f4d54d
(alloc_xfer_buf): If want_size is more than 1MB,
Eli Zaretskii <eliz@gnu.org>
parents:
21707
diff
changeset
|
686 defsubr (&Sw16_get_clipboard_data); |
17451 | 687 defsubr (&Sx_selection_exists_p); |
688 | |
112364
42e22c4f06b7
Move all DEFVAR'd globals into a structure -- threading infrastructure
Tom Tromey <tromey@redhat.com>
parents:
112284
diff
changeset
|
689 DEFVAR_LISP ("selection-coding-system", Vselection_coding_system, |
111136
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
690 doc: /* Coding system for communicating with other programs. |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
691 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
692 For MS-Windows and MS-DOS: |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
693 When sending or receiving text via selection and clipboard, the text |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
694 is encoded or decoded by this coding system. The default value is |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
695 the current system default encoding on 9x/Me, `utf-16le-dos' |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
696 \(Unicode) on NT/W2K/XP, and `iso-latin-1-dos' on MS-DOS. |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
697 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
698 For X Windows: |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
699 When sending text via selection and clipboard, if the target |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
700 data-type matches with the type of this coding system, it is used |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
701 for encoding the text. Otherwise (including the case that this |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
702 variable is nil), a proper coding system is used as below: |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
703 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
704 data-type coding system |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
705 --------- ------------- |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
706 UTF8_STRING utf-8 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
707 COMPOUND_TEXT compound-text-with-extensions |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
708 STRING iso-latin-1 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
709 C_STRING no-conversion |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
710 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
711 When receiving text, if this coding system is non-nil, it is used |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
712 for decoding regardless of the data-type. If this is nil, a |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
713 proper coding system is used according to the data-type as above. |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
714 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
715 See also the documentation of the variable `x-select-request-type' how |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
716 to control which data-type to request for receiving text. |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
717 |
bc1274182cc8
Sync docs of selection-coding-system between C and Lisp.
Glenn Morris <rgm@gnu.org>
parents:
111135
diff
changeset
|
718 The default value is nil. */); |
47878
be195e2a4bfb
(syms_of_win16select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents:
47279
diff
changeset
|
719 Vselection_coding_system = intern ("iso-latin-1-dos"); |
23164
ecc4641bf00a
(Vnext_selection_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
22904
diff
changeset
|
720 |
112364
42e22c4f06b7
Move all DEFVAR'd globals into a structure -- threading infrastructure
Tom Tromey <tromey@redhat.com>
parents:
112284
diff
changeset
|
721 DEFVAR_LISP ("next-selection-coding-system", Vnext_selection_coding_system, |
111135
600f564fdc23
Sync Lisp and C docs of next-selection-coding-system.
Glenn Morris <rgm@gnu.org>
parents:
110683
diff
changeset
|
722 doc: /* Coding system for the next communication with other programs. |
41940
63819c5d6049
Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents:
40656
diff
changeset
|
723 Usually, `selection-coding-system' is used for communicating with |
111135
600f564fdc23
Sync Lisp and C docs of next-selection-coding-system.
Glenn Morris <rgm@gnu.org>
parents:
110683
diff
changeset
|
724 other programs (X Windows clients or MS Windows programs). But, if this |
600f564fdc23
Sync Lisp and C docs of next-selection-coding-system.
Glenn Morris <rgm@gnu.org>
parents:
110683
diff
changeset
|
725 variable is set, it is used for the next communication only. |
600f564fdc23
Sync Lisp and C docs of next-selection-coding-system.
Glenn Morris <rgm@gnu.org>
parents:
110683
diff
changeset
|
726 After the communication, this variable is set to nil. */); |
23164
ecc4641bf00a
(Vnext_selection_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
22904
diff
changeset
|
727 Vnext_selection_coding_system = Qnil; |
22729
3537e1563a66
(Vclipboard_coding_system): New variable.
Eli Zaretskii <eliz@gnu.org>
parents:
21709
diff
changeset
|
728 |
17451 | 729 QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY); |
730 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); | |
731 } | |
732 | |
733 #endif /* MSDOS */ | |
52401 | 734 |