]> git.pld-linux.org Git - packages/vim.git/blob - 6.2.345
- updated to 6.2.430
[packages/vim.git] / 6.2.345
1 To: vim-dev@vim.org
2 Subject: Patch 6.2.345 (extra)
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 6.2.345 (extra)
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
16
17
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
20 ***************
21 *** 929,934 ****
22 --- 929,936 ----
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 */
28   } VimClipType_t;
29   
30   /*
31 ***************
32 *** 1123,1137 ****
33       void
34   clip_mch_request_selection(VimClipboard *cbd)
35   {
36 !     VimClipType_t     metadata = { -1, -1, -1 };
37       HGLOBAL           hMem = NULL;
38       char_u            *str = NULL;
39   #if defined(FEAT_MBYTE) && defined(WIN3264)
40       char_u            *to_free = NULL;
41   #endif
42       char_u            *hMemStr = NULL;
43       int                       str_size = 0;
44       int                       maxlen;
45   
46       /*
47        * Don't pass GetActiveWindow() as an argument to OpenClipboard() because
48 --- 1125,1143 ----
49       void
50   clip_mch_request_selection(VimClipboard *cbd)
51   {
52 !     VimClipType_t     metadata = { -1, -1, -1, -1 };
53       HGLOBAL           hMem = NULL;
54       char_u            *str = NULL;
55   #if defined(FEAT_MBYTE) && defined(WIN3264)
56       char_u            *to_free = NULL;
57   #endif
58 + #ifdef FEAT_MBYTE
59 +     HGLOBAL           rawh = NULL;
60 + #endif
61       char_u            *hMemStr = NULL;
62       int                       str_size = 0;
63       int                       maxlen;
64 +     size_t            n;
65   
66       /*
67        * Don't pass GetActiveWindow() as an argument to OpenClipboard() because
68 ***************
69 *** 1151,1162 ****
70         if ((meta_h = GetClipboardData(cbd->format)) != NULL
71                 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL)
72         {
73 !           if (GlobalSize(meta_h) >= sizeof(VimClipType_t))
74 !               memcpy(&metadata, meta_p, sizeof(metadata));
75             GlobalUnlock(meta_h);
76         }
77       }
78   
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)
82 --- 1157,1201 ----
83         if ((meta_h = GetClipboardData(cbd->format)) != NULL
84                 && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL)
85         {
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);
92             GlobalUnlock(meta_h);
93         }
94       }
95   
96 + #ifdef FEAT_MBYTE
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))
101 +     {
102 +       /* We have raw data on the clipboard; try to get it. */
103 +       if ((rawh = GetClipboardData(cbd->format_raw)) != NULL)
104 +       {
105 +           char_u      *rawp;
106
107 +           rawp = (char_u *)GlobalLock(rawh);
108 +           if (rawp != NULL && STRCMP(p_enc, rawp) == 0)
109 +           {
110 +               n = STRLEN(p_enc) + 1;
111 +               str = rawp + n;
112 +               str_size = metadata.rawlen - n;
113 +           }
114 +           else
115 +           {
116 +               GlobalUnlock(rawh);
117 +               rawh = NULL;
118 +           }
119 +       }
120 +     }
121 +     if (str == NULL)
122 +     {
123 + #endif
124
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)
128 ***************
129 *** 1231,1236 ****
130 --- 1270,1278 ----
131   #endif
132         }
133       }
134 + #ifdef FEAT_MBYTE
135 +     }
136 + #endif
137   
138       if (str != NULL && *str != NUL)
139       {
140 ***************
141 *** 1250,1257 ****
142       }
143   
144       /* unlock the global object */
145 !     if (hMemStr != NULL)
146         GlobalUnlock(hMem);
147       CloseClipboard();
148   #if defined(FEAT_MBYTE) && defined(WIN3264)
149       vim_free(to_free);
150 --- 1292,1303 ----
151       }
152   
153       /* unlock the global object */
154 !     if (hMem != NULL)
155         GlobalUnlock(hMem);
156 + #ifdef FEAT_MBYTE
157 +     if (rawh != NULL)
158 +       GlobalUnlock(rawh);
159 + #endif
160       CloseClipboard();
161   #if defined(FEAT_MBYTE) && defined(WIN3264)
162       vim_free(to_free);
163 ***************
164 *** 1267,1272 ****
165 --- 1313,1319 ----
166       char_u            *str = NULL;
167       VimClipType_t     metadata;
168       long_u            txtlen;
169 +     HGLOBAL           hMemRaw = NULL;
170       HGLOBAL           hMem = NULL;
171       HGLOBAL           hMemVim = NULL;
172   # if defined(FEAT_MBYTE) && defined(WIN3264)
173 ***************
174 *** 1284,1289 ****
175 --- 1331,1359 ----
176         return;
177       metadata.txtlen = (int)txtlen;
178       metadata.ucslen = 0;
179 +     metadata.rawlen = 0;
180
181 + #ifdef FEAT_MBYTE
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. */
185 +     {
186 +       LPSTR lpszMemRaw;
187
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)
193 +       {
194 +           STRCPY(lpszMemRaw, p_enc);
195 +           memcpy(lpszMemRaw + STRLEN(p_enc) + 1, str, txtlen + 1);
196 +           GlobalUnlock(hMemRaw);
197 +       }
198 +       else
199 +           metadata.rawlen = 0;
200 +     }
201 + #endif
202   
203   # if defined(FEAT_MBYTE) && defined(WIN3264)
204       {
205 ***************
206 *** 1385,1390 ****
207 --- 1455,1462 ----
208   
209       vim_free(str);
210       /* Free any allocations we didn't give to the clipboard: */
211 +     if (hMemRaw)
212 +       GlobalFree(hMemRaw);
213       if (hMem)
214         GlobalFree(hMem);
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
218 ***************
219 *** 179,184 ****
220 --- 179,185 ----
221        * character to specify MCHAR, MLINE or MBLOCK.
222        */
223       clip_star.format = RegisterClipboardFormat("VimClipboard2");
224 +     clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
225   #endif
226   }
227   
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
230 ***************
231 *** 1540,1545 ****
232 --- 1540,1546 ----
233        * character to specify MCHAR, MLINE or MBLOCK.
234        */
235       clip_star.format = RegisterClipboardFormat("VimClipboard2");
236 +     clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
237   #endif
238   }
239   
240 ***************
241 *** 2038,2043 ****
242 --- 2039,2045 ----
243        * character to specify MCHAR, MLINE or MBLOCK.
244        */
245       clip_star.format = RegisterClipboardFormat("VimClipboard2");
246 +     clip_star.format_raw = RegisterClipboardFormat("VimRawBytes");
247   #endif
248   
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
252 ***************
253 *** 1520,1525 ****
254 --- 1520,1526 ----
255   
256   # ifdef MSWIN
257       int_u     format;         /* Vim's own special clipboard format */
258 +     int_u     format_raw;     /* Vim's raw text clipboard format */
259   # endif
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
264 ***************
265 *** 639,640 ****
266 --- 639,642 ----
267   {   /* Add new patch number below this line */
268 + /**/
269 +     345,
270   /**/
271
272 -- 
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
275    and a laptop.
276
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 ///
This page took 0.042289 seconds and 3 git commands to generate.