Mercurial > emacs
comparison src/w32select.c @ 24518:a0423d2b9302
(Fw32_set_clipboard_data): Take into account line
ends when calculating clipboard storage needed for non-ASCII text.
author | Andrew Innes <andrewi@gnu.org> |
---|---|
date | Thu, 25 Mar 1999 22:59:18 +0000 |
parents | 122a362c5024 |
children | ea7d8435d078 |
comparison
equal
deleted
inserted
replaced
24517:e422a11cf832 | 24518:a0423d2b9302 |
---|---|
97 Lisp_Object string, frame; | 97 Lisp_Object string, frame; |
98 { | 98 { |
99 BOOL ok = TRUE; | 99 BOOL ok = TRUE; |
100 HANDLE htext; | 100 HANDLE htext; |
101 int nbytes; | 101 int nbytes; |
102 int truelen; | 102 int truelen, nlines = 0; |
103 unsigned char *src; | 103 unsigned char *src; |
104 unsigned char *dst; | 104 unsigned char *dst; |
105 | 105 |
106 CHECK_STRING (string, 0); | 106 CHECK_STRING (string, 0); |
107 | 107 |
108 if (!NILP (frame)) | 108 if (!NILP (frame)) |
109 CHECK_LIVE_FRAME (frame, 0); | 109 CHECK_LIVE_FRAME (frame, 0); |
110 | 110 |
111 BLOCK_INPUT; | 111 BLOCK_INPUT; |
112 | 112 |
113 nbytes = STRING_BYTES (XSTRING (string)) + 1; | 113 nbytes = STRING_BYTES (XSTRING (string)) + 1; |
114 src = XSTRING (string)->data; | 114 src = XSTRING (string)->data; |
115 dst = src; | |
116 | |
117 /* We need to know how many lines there are, since we need CRLF line | |
118 termination for compatibility with other Windows Programs. | |
119 avoid using strchr because it recomputes the length every time */ | |
120 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) | |
121 { | |
122 nlines++; | |
123 dst++; | |
124 } | |
115 | 125 |
116 { | 126 { |
117 /* Since we are now handling multilingual text, we must consider | 127 /* Since we are now handling multilingual text, we must consider |
118 encoding text for the clipboard. */ | 128 encoding text for the clipboard. */ |
119 int charsets[MAX_CHARSET + 1]; | 129 int charsets[MAX_CHARSET + 1]; |
132 | 142 |
133 /* Need to know final size after CR chars are inserted (the | 143 /* Need to know final size after CR chars are inserted (the |
134 standard CF_TEXT clipboard format uses CRLF line endings, | 144 standard CF_TEXT clipboard format uses CRLF line endings, |
135 while Emacs uses just LF internally). */ | 145 while Emacs uses just LF internally). */ |
136 | 146 |
137 truelen = nbytes; | 147 truelen = nbytes + nlines; |
138 dst = src; | |
139 /* avoid using strchr because it recomputes the length everytime */ | |
140 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) | |
141 { | |
142 truelen++; | |
143 dst++; | |
144 } | |
145 | 148 |
146 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) | 149 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) |
147 goto error; | 150 goto error; |
148 | 151 |
149 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) | 152 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
189 Vnext_selection_coding_system = Vselection_coding_system; | 192 Vnext_selection_coding_system = Vselection_coding_system; |
190 setup_coding_system | 193 setup_coding_system |
191 (Fcheck_coding_system (Vnext_selection_coding_system), &coding); | 194 (Fcheck_coding_system (Vnext_selection_coding_system), &coding); |
192 Vnext_selection_coding_system = Qnil; | 195 Vnext_selection_coding_system = Qnil; |
193 coding.mode |= CODING_MODE_LAST_BLOCK; | 196 coding.mode |= CODING_MODE_LAST_BLOCK; |
194 bufsize = encoding_buffer_size (&coding, nbytes); | 197 bufsize = encoding_buffer_size (&coding, nbytes) + nlines; |
195 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL) | 198 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL) |
196 goto error; | 199 goto error; |
197 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) | 200 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) |
198 goto error; | 201 goto error; |
199 encode_coding (&coding, src, dst, nbytes, bufsize); | 202 encode_coding (&coding, src, dst, nbytes, bufsize); |