2 Subject: Patch 6.2.345 (extra)
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Win32: Copy/paste between two Vims fails if 'encoding' is not set
12 properly or there are illegal bytes.
13 Solution: Use a raw byte format. Always set it when copying. When pasting
14 use the raw format if 'encoding' is the same.
15 Files: src/os_mswin.c, src/os_win16.c, src/os_win32.c, src/vim.h
18 *** ../vim-6.2.344/src/os_mswin.c Tue Mar 9 14:24:17 2004
19 --- src/os_mswin.c Wed Mar 10 21:11:19 2004
23 int type; /* MCHAR, MBLOCK or MLINE */
24 int txtlen; /* length of CF_TEXT in bytes */
25 int ucslen; /* length of CF_UNICODETEXT in words */
26 + int rawlen; /* length of clip_star.format_raw, including encoding,
27 + excluding terminating NUL */
34 clip_mch_request_selection(VimClipboard *cbd)
36 ! VimClipType_t metadata = { -1, -1, -1 };
39 #if defined(FEAT_MBYTE) && defined(WIN3264)
40 char_u *to_free = NULL;
42 char_u *hMemStr = NULL;
47 * Don't pass GetActiveWindow() as an argument to OpenClipboard() because
50 clip_mch_request_selection(VimClipboard *cbd)
52 ! VimClipType_t metadata = { -1, -1, -1, -1 };
55 #if defined(FEAT_MBYTE) && defined(WIN3264)
56 char_u *to_free = NULL;
59 + HGLOBAL rawh = NULL;
61 char_u *hMemStr = NULL;
67 * Don't pass GetActiveWindow() as an argument to OpenClipboard() because
70 if ((meta_h = GetClipboardData(cbd->format)) != NULL
71 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL)
73 ! if (GlobalSize(meta_h) >= sizeof(VimClipType_t))
74 ! memcpy(&metadata, meta_p, sizeof(metadata));
79 #if defined(FEAT_MBYTE) && defined(WIN3264)
80 /* Try to get the clipboard in Unicode if it's not an empty string. */
81 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0)
83 if ((meta_h = GetClipboardData(cbd->format)) != NULL
84 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL)
86 ! /* The size of "VimClipType_t" changed, "rawlen" was added later.
87 ! * Only copy what is available for backwards compatibility. */
88 ! n = sizeof(VimClipType_t);
89 ! if (GlobalSize(meta_h) < n)
90 ! n = GlobalSize(meta_h);
91 ! memcpy(&metadata, meta_p, n);
97 + /* Check for Vim's raw clipboard format first. This is used without
98 + * conversion, but only if 'encoding' matches. */
99 + if (IsClipboardFormatAvailable(cbd->format_raw)
100 + && metadata.rawlen > (int)STRLEN(p_enc))
102 + /* We have raw data on the clipboard; try to get it. */
103 + if ((rawh = GetClipboardData(cbd->format_raw)) != NULL)
107 + rawp = (char_u *)GlobalLock(rawh);
108 + if (rawp != NULL && STRCMP(p_enc, rawp) == 0)
110 + n = STRLEN(p_enc) + 1;
112 + str_size = metadata.rawlen - n;
116 + GlobalUnlock(rawh);
125 #if defined(FEAT_MBYTE) && defined(WIN3264)
126 /* Try to get the clipboard in Unicode if it's not an empty string. */
127 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0)
138 if (str != NULL && *str != NUL)
144 /* unlock the global object */
145 ! if (hMemStr != NULL)
148 #if defined(FEAT_MBYTE) && defined(WIN3264)
153 /* unlock the global object */
158 + GlobalUnlock(rawh);
161 #if defined(FEAT_MBYTE) && defined(WIN3264)
167 VimClipType_t metadata;
169 + HGLOBAL hMemRaw = NULL;
171 HGLOBAL hMemVim = NULL;
172 # if defined(FEAT_MBYTE) && defined(WIN3264)
177 metadata.txtlen = (int)txtlen;
179 + metadata.rawlen = 0;
182 + /* Always set the raw bytes: 'encoding', NUL and the text. This is used
183 + * when copy/paste from/to Vim with the same 'encoding', so that illegal
184 + * bytes can also be copied and no conversion is needed. */
188 + metadata.rawlen = txtlen + STRLEN(p_enc) + 1;
189 + hMemRaw = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
190 + metadata.rawlen + 1);
191 + lpszMemRaw = (LPSTR)GlobalLock(hMemRaw);
192 + if (lpszMemRaw != NULL)
194 + STRCPY(lpszMemRaw, p_enc);
195 + memcpy(lpszMemRaw + STRLEN(p_enc) + 1, str, txtlen + 1);
196 + GlobalUnlock(hMemRaw);
199 + metadata.rawlen = 0;
203 # if defined(FEAT_MBYTE) && defined(WIN3264)
210 /* Free any allocations we didn't give to the clipboard: */
212 + GlobalFree(hMemRaw);
215 # if defined(FEAT_MBYTE) && defined(WIN3264)
216 *** ../vim-6.2.344/src/os_win16.c Sat May 24 17:19:47 2003
217 --- src/os_win16.c Wed Mar 10 18:32:17 2004
221 * character to specify MCHAR, MLINE or MBLOCK.
223 clip_star.format = RegisterClipboardFormat("VimClipboard2");
224 + clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
228 *** ../vim-6.2.344/src/os_win32.c Sun Mar 7 17:03:27 2004
229 --- src/os_win32.c Wed Mar 10 18:26:06 2004
233 * character to specify MCHAR, MLINE or MBLOCK.
235 clip_star.format = RegisterClipboardFormat("VimClipboard2");
236 + clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
243 * character to specify MCHAR, MLINE or MBLOCK.
245 clip_star.format = RegisterClipboardFormat("VimClipboard2");
246 + clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
249 /* This will be NULL on anything but NT 4.0 */
250 *** ../vim-6.2.344/src/vim.h Mon Mar 8 12:27:39 2004
251 --- src/vim.h Wed Mar 10 18:28:34 2004
257 int_u format; /* Vim's own special clipboard format */
258 + int_u format_raw; /* Vim's raw text clipboard format */
260 # ifdef FEAT_GUI_BEOS
261 /* no clipboard at the moment */
262 *** ../vim-6.2.344/src/version.c Thu Mar 11 20:59:13 2004
263 --- src/version.c Thu Mar 11 21:01:16 2004
267 { /* Add new patch number below this line */
273 hundred-and-one symptoms of being an internet addict:
274 7. You finally do take that vacation, but only after buying a cellular modem
277 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
278 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
279 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
280 \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///