home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.1.421 < prev    next >
Encoding:
Internet Message Format  |  2003-03-25  |  6.2 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.1.421 (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.1.421 (extra, depends on 6.1.354)
  11. Problem:    MS-Windows 9x: When putting text on the clipboard it can be in
  12.         the wrong encoding.
  13. Solution:   Convert text to the active codepage for CF_TEXT. (Glenn Maynard)
  14. Files:        src/os_mswin.c
  15.  
  16.  
  17. *** ../vim61.420/src/os_mswin.c    Wed Mar 26 21:48:04 2003
  18. --- src/os_mswin.c    Fri Mar 21 20:24:21 2003
  19. ***************
  20. *** 969,975 ****
  21.   
  22.       utf8_str = alloc((unsigned)length);
  23.       if (utf8_str != NULL)
  24. !         WideCharToMultiByte(enc_dbcs, 0, str, *len, utf8_str, length, 0,0);
  25.       *len = length;
  26.           return utf8_str;
  27.       }
  28. --- 969,975 ----
  29.   
  30.       utf8_str = alloc((unsigned)length);
  31.       if (utf8_str != NULL)
  32. !         WideCharToMultiByte(enc_dbcs, 0, str, *len, utf8_str, length, 0, 0);
  33.       *len = length;
  34.           return utf8_str;
  35.       }
  36. ***************
  37. *** 1018,1023 ****
  38. --- 1018,1024 ----
  39.       VimClipType_t    metadata = { -1, -1, -1 };
  40.       HGLOBAL        hMem = NULL;
  41.       char_u        *str = NULL;
  42. +     char_u        *to_free = NULL;
  43.       char_u        *hMemStr = NULL;
  44.       int            str_size = 0;
  45.       int            maxlen;
  46. ***************
  47. *** 1072,1078 ****
  48.               if (hMemWstr[str_size] == NUL)
  49.               break;
  50.           }
  51. !         str = ucs2_to_enc(hMemWstr, &str_size);
  52.           GlobalUnlock(hMemW);
  53.       }
  54.       }
  55. --- 1073,1079 ----
  56.               if (hMemWstr[str_size] == NUL)
  57.               break;
  58.           }
  59. !         to_free = str = ucs2_to_enc(hMemWstr, &str_size);
  60.           GlobalUnlock(hMemW);
  61.       }
  62.       }
  63. ***************
  64. *** 1101,1106 ****
  65. --- 1102,1124 ----
  66.               if (str[str_size] == NUL)
  67.               break;
  68.           }
  69. +         /* The text is now in the active codepage.  Convert to 'encoding',
  70. +          * going through UCS-2. */
  71. +         maxlen = MultiByteToWideChar(CP_ACP, 0, str, str_size, NULL, 0);
  72. +         to_free = alloc((unsigned)(maxlen * sizeof(WCHAR)));
  73. +         if (to_free != NULL)
  74. +         {
  75. +         MultiByteToWideChar(CP_ACP, 0, str, str_size,
  76. +                             (WCHAR *)to_free, maxlen);
  77. +         str_size = maxlen;
  78. +         str = ucs2_to_enc((WCHAR *)to_free, &str_size);
  79. +         if (str != NULL)
  80. +         {
  81. +             vim_free(to_free);
  82. +             to_free = str;
  83. +         }
  84. +         }
  85.       }
  86.       }
  87.   
  88. ***************
  89. *** 1125,1130 ****
  90. --- 1143,1149 ----
  91.       if (hMemStr != NULL)
  92.       GlobalUnlock(hMem);
  93.       CloseClipboard();
  94. +     vim_free(to_free);
  95.   }
  96.   
  97.   /*
  98. ***************
  99. *** 1134,1140 ****
  100.   clip_mch_set_selection(VimClipboard *cbd)
  101.   {
  102.       char_u        *str = NULL;
  103. -     long_u        str_len;
  104.       VimClipType_t    metadata;
  105.       HGLOBAL        hMem = NULL;
  106.       HGLOBAL        hMemVim = NULL;
  107. --- 1153,1158 ----
  108. ***************
  109. *** 1148,1163 ****
  110.       cbd->owned = FALSE;
  111.   
  112.       /* Get the text to be put on the clipboard, with CR-LF. */
  113. !     metadata.type = clip_convert_selection(&str, &str_len, cbd);
  114.       if (metadata.type < 0)
  115.       return;
  116. -     metadata.txtlen = str_len;
  117.       metadata.ucslen = 0;
  118.   
  119.   # if defined(FEAT_MBYTE) && defined(WIN3264)
  120.       {
  121.           WCHAR        *out;
  122. !         int        len = str_len;
  123.   
  124.       /* Convert the text to UCS-2. This is put on the clipboard as
  125.        * CF_UNICODETEXT. */
  126. --- 1166,1180 ----
  127.       cbd->owned = FALSE;
  128.   
  129.       /* Get the text to be put on the clipboard, with CR-LF. */
  130. !     metadata.type = clip_convert_selection(&str, &metadata.txtlen, cbd);
  131.       if (metadata.type < 0)
  132.       return;
  133.       metadata.ucslen = 0;
  134.   
  135.   # if defined(FEAT_MBYTE) && defined(WIN3264)
  136.       {
  137.           WCHAR        *out;
  138. !         int        len = metadata.txtlen;
  139.   
  140.       /* Convert the text to UCS-2. This is put on the clipboard as
  141.        * CF_UNICODETEXT. */
  142. ***************
  143. *** 1166,1171 ****
  144. --- 1183,1202 ----
  145.       {
  146.           WCHAR *lpszMemW;
  147.   
  148. +         /* Convert the text for CF_TEXT to ANSI codepage. Otherwise it's
  149. +          * p_enc, which has no relation to the ANSI codepage. */
  150. +         metadata.txtlen = WideCharToMultiByte(CP_ACP, 0, out, len,
  151. +                                    NULL, 0, 0, 0);
  152. +         vim_free(str);
  153. +         str = (char_u *)alloc((unsigned)metadata.txtlen);
  154. +         if (str == NULL)
  155. +         {
  156. +         vim_free(out);
  157. +         return;        /* out of memory */
  158. +         }
  159. +         WideCharToMultiByte(CP_ACP, 0, out, len,
  160. +                           str, metadata.txtlen, 0, 0);
  161.           /* Allocate memory for the UCS-2 text, add one NUL word to
  162.            * terminate the string. */
  163.           hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
  164. ***************
  165. *** 1185,1198 ****
  166.   
  167.       /* Allocate memory for the text, add one NUL byte to terminate the string.
  168.        */
  169. !     hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, str_len + 1);
  170.       {
  171.       LPSTR lpszMem = (LPSTR)GlobalLock(hMem);
  172.   
  173.       if (lpszMem)
  174.       {
  175. !         STRNCPY(lpszMem, str, str_len);
  176. !         lpszMem[str_len] = NUL;
  177.           GlobalUnlock(hMem);
  178.       }
  179.       }
  180. --- 1216,1229 ----
  181.   
  182.       /* Allocate memory for the text, add one NUL byte to terminate the string.
  183.        */
  184. !     hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1);
  185.       {
  186.       LPSTR lpszMem = (LPSTR)GlobalLock(hMem);
  187.   
  188.       if (lpszMem)
  189.       {
  190. !         STRNCPY(lpszMem, str, metadata.txtlen);
  191. !         lpszMem[metadata.txtlen] = NUL;
  192.           GlobalUnlock(hMem);
  193.       }
  194.       }
  195. ***************
  196. *** 1226,1233 ****
  197.   # if defined(FEAT_MBYTE) && defined(WIN3264)
  198.           if (hMemW != NULL)
  199.           {
  200. !         SetClipboardData(CF_UNICODETEXT, hMemW);
  201. !         hMemW = 0;
  202.           }
  203.   # endif
  204.           /* Always use CF_TEXT.  On Win98 Notepad won't obtain the
  205. --- 1257,1264 ----
  206.   # if defined(FEAT_MBYTE) && defined(WIN3264)
  207.           if (hMemW != NULL)
  208.           {
  209. !         if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
  210. !             hMemW = NULL;
  211.           }
  212.   # endif
  213.           /* Always use CF_TEXT.  On Win98 Notepad won't obtain the
  214. *** ../vim61.420/src/version.c    Wed Mar 26 22:18:13 2003
  215. --- src/version.c    Wed Mar 26 22:19:52 2003
  216. ***************
  217. *** 613,614 ****
  218. --- 613,616 ----
  219.   {   /* Add new patch number below this line */
  220. + /**/
  221. +     421,
  222.   /**/
  223.  
  224. -- 
  225. Get a life?  What is the URL where it can be downloaded?
  226.  
  227.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  228. ///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
  229. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  230.  \\\     Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
  231.