e5aea61
To: vim-dev@vim.org
e5aea61
Subject: Patch 7.2.093 (extra)
e5aea61
Fcc: outbox
e5aea61
From: Bram Moolenaar <Bram@moolenaar.net>
e5aea61
Mime-Version: 1.0
e5aea61
Content-Type: text/plain; charset=ISO-8859-1
e5aea61
Content-Transfer-Encoding: 8bit
e5aea61
------------
e5aea61
e5aea61
Patch 7.2.093 (extra)
e5aea61
Problem:    Win32: inputdialog() and find/replace dialogs can't handle
e5aea61
	    multi-byte text.
e5aea61
Solution:   Use the wide version of dialog functions when available. (Yanwei
e5aea61
	    Jia)
e5aea61
Files:	    src/gui_w32.c, src/gui_w48.c
e5aea61
e5aea61
e5aea61
*** ../vim-7.2.092/src/gui_w32.c	Thu Nov 20 17:09:09 2008
e5aea61
--- src/gui_w32.c	Wed Jan 28 21:15:29 2009
e5aea61
***************
e5aea61
*** 1582,1587 ****
e5aea61
--- 1582,1598 ----
e5aea61
      s_findrep_struct.lpstrReplaceWith[0] = NUL;
e5aea61
      s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
e5aea61
      s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
e5aea61
+ # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
+     s_findrep_struct_w.lStructSize = sizeof(s_findrep_struct_w);
e5aea61
+     s_findrep_struct_w.lpstrFindWhat =
e5aea61
+ 			      (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
e5aea61
+     s_findrep_struct_w.lpstrFindWhat[0] = NUL;
e5aea61
+     s_findrep_struct_w.lpstrReplaceWith =
e5aea61
+ 			      (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
e5aea61
+     s_findrep_struct_w.lpstrReplaceWith[0] = NUL;
e5aea61
+     s_findrep_struct_w.wFindWhatLen = MSWIN_FR_BUFSIZE;
e5aea61
+     s_findrep_struct_w.wReplaceWithLen = MSWIN_FR_BUFSIZE;
e5aea61
+ # endif
e5aea61
  #endif
e5aea61
  
e5aea61
  theend:
e5aea61
***************
e5aea61
*** 2938,2945 ****
e5aea61
  
e5aea61
  	/* If the edit box exists, copy the string. */
e5aea61
  	if (s_textfield != NULL)
e5aea61
! 	    GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2,
e5aea61
  							 s_textfield, IOSIZE);
e5aea61
  
e5aea61
  	/*
e5aea61
  	 * Need to check for IDOK because if the user just hits Return to
e5aea61
--- 2949,2975 ----
e5aea61
  
e5aea61
  	/* If the edit box exists, copy the string. */
e5aea61
  	if (s_textfield != NULL)
e5aea61
! 	{
e5aea61
! # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
! 	    /* If the OS is Windows NT, and 'encoding' differs from active
e5aea61
! 	     * codepage: use wide function and convert text. */
e5aea61
! 	    if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT
e5aea61
! 		    && enc_codepage >= 0 && (int)GetACP() != enc_codepage)
e5aea61
!             {
e5aea61
! 	       WCHAR  *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR));
e5aea61
! 	       char_u *p;
e5aea61
! 
e5aea61
! 	       GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE);
e5aea61
! 	       p = utf16_to_enc(wp, NULL);
e5aea61
! 	       vim_strncpy(s_textfield, p, IOSIZE);
e5aea61
! 	       vim_free(p);
e5aea61
! 	       vim_free(wp);
e5aea61
! 	    }
e5aea61
! 	    else
e5aea61
! # endif
e5aea61
! 		GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2,
e5aea61
  							 s_textfield, IOSIZE);
e5aea61
+ 	}
e5aea61
  
e5aea61
  	/*
e5aea61
  	 * Need to check for IDOK because if the user just hits Return to
e5aea61
*** ../vim-7.2.092/src/gui_w48.c	Wed Jan 28 14:17:21 2009
e5aea61
--- src/gui_w48.c	Wed Jan 28 21:10:26 2009
e5aea61
***************
e5aea61
*** 153,158 ****
e5aea61
--- 153,161 ----
e5aea61
  #ifdef MSWIN_FIND_REPLACE
e5aea61
  static UINT		s_findrep_msg = 0;	/* set in gui_w[16/32].c */
e5aea61
  static FINDREPLACE	s_findrep_struct;
e5aea61
+ # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
+ static FINDREPLACEW	s_findrep_struct_w;
e5aea61
+ # endif
e5aea61
  static HWND		s_findrep_hwnd = NULL;
e5aea61
  static int		s_findrep_is_find;	/* TRUE for find dialog, FALSE
e5aea61
  						   for find/replace dialog */
e5aea61
***************
e5aea61
*** 884,889 ****
e5aea61
--- 887,931 ----
e5aea61
  #endif
e5aea61
  
e5aea61
  #ifdef MSWIN_FIND_REPLACE
e5aea61
+ # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
+ /*
e5aea61
+  * copy useful data from structure LPFINDREPLACE to structure LPFINDREPLACEW
e5aea61
+  */
e5aea61
+     static void
e5aea61
+ findrep_atow(LPFINDREPLACEW lpfrw, LPFINDREPLACE lpfr)
e5aea61
+ {
e5aea61
+     WCHAR *wp;
e5aea61
+ 
e5aea61
+     lpfrw->hwndOwner = lpfr->hwndOwner;
e5aea61
+     lpfrw->Flags = lpfr->Flags;
e5aea61
+ 
e5aea61
+     wp = enc_to_utf16(lpfr->lpstrFindWhat, NULL);
e5aea61
+     wcsncpy(lpfrw->lpstrFindWhat, wp, lpfrw->wFindWhatLen - 1);
e5aea61
+     vim_free(wp);
e5aea61
+ 
e5aea61
+     /* the field "lpstrReplaceWith" doesn't need to be copied */
e5aea61
+ }
e5aea61
+ 
e5aea61
+ /*
e5aea61
+  * copy useful data from structure LPFINDREPLACEW to structure LPFINDREPLACE
e5aea61
+  */
e5aea61
+     static void
e5aea61
+ findrep_wtoa(LPFINDREPLACE lpfr, LPFINDREPLACEW lpfrw)
e5aea61
+ {
e5aea61
+     char_u *p;
e5aea61
+ 
e5aea61
+     lpfr->Flags = lpfrw->Flags;
e5aea61
+ 
e5aea61
+     p = utf16_to_enc(lpfrw->lpstrFindWhat, NULL);
e5aea61
+     vim_strncpy(lpfr->lpstrFindWhat, p, lpfr->wFindWhatLen - 1);
e5aea61
+     vim_free(p);
e5aea61
+ 
e5aea61
+     p = utf16_to_enc(lpfrw->lpstrReplaceWith, NULL);
e5aea61
+     vim_strncpy(lpfr->lpstrReplaceWith, p, lpfr->wReplaceWithLen - 1);
e5aea61
+     vim_free(p);
e5aea61
+ }
e5aea61
+ # endif
e5aea61
+ 
e5aea61
  /*
e5aea61
   * Handle a Find/Replace window message.
e5aea61
   */
e5aea61
***************
e5aea61
*** 893,898 ****
e5aea61
--- 935,950 ----
e5aea61
      int	    flags = 0;
e5aea61
      int	    down;
e5aea61
  
e5aea61
+ # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
+     /* If the OS is Windows NT, and 'encoding' differs from active codepage:
e5aea61
+      * convert text from wide string. */
e5aea61
+     if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT
e5aea61
+ 			&& enc_codepage >= 0 && (int)GetACP() != enc_codepage)
e5aea61
+     {
e5aea61
+         findrep_wtoa(&s_findrep_struct, &s_findrep_struct_w);
e5aea61
+     }
e5aea61
+ # endif
e5aea61
+ 
e5aea61
      if (s_findrep_struct.Flags & FR_DIALOGTERM)
e5aea61
  	/* Give main window the focus back. */
e5aea61
  	(void)SetFocus(s_hwnd);
e5aea61
***************
e5aea61
*** 2562,2568 ****
e5aea61
  	if (!IsWindow(s_findrep_hwnd))
e5aea61
  	{
e5aea61
  	    initialise_findrep(eap->arg);
e5aea61
! 	    s_findrep_hwnd = FindText((LPFINDREPLACE) &s_findrep_struct);
e5aea61
  	}
e5aea61
  
e5aea61
  	set_window_title(s_findrep_hwnd,
e5aea61
--- 2614,2632 ----
e5aea61
  	if (!IsWindow(s_findrep_hwnd))
e5aea61
  	{
e5aea61
  	    initialise_findrep(eap->arg);
e5aea61
! # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
! 	    /* If the OS is Windows NT, and 'encoding' differs from active
e5aea61
! 	     * codepage: convert text and use wide function. */
e5aea61
! 	    if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT
e5aea61
! 		    && enc_codepage >= 0 && (int)GetACP() != enc_codepage)
e5aea61
! 	    {
e5aea61
! 	        findrep_atow(&s_findrep_struct_w, &s_findrep_struct);
e5aea61
! 		s_findrep_hwnd = FindTextW(
e5aea61
! 					(LPFINDREPLACEW) &s_findrep_struct_w);
e5aea61
! 	    }
e5aea61
! 	    else
e5aea61
! # endif
e5aea61
! 		s_findrep_hwnd = FindText((LPFINDREPLACE) &s_findrep_struct);
e5aea61
  	}
e5aea61
  
e5aea61
  	set_window_title(s_findrep_hwnd,
e5aea61
***************
e5aea61
*** 2587,2593 ****
e5aea61
  	if (!IsWindow(s_findrep_hwnd))
e5aea61
  	{
e5aea61
  	    initialise_findrep(eap->arg);
e5aea61
! 	    s_findrep_hwnd = ReplaceText((LPFINDREPLACE) &s_findrep_struct);
e5aea61
  	}
e5aea61
  
e5aea61
  	set_window_title(s_findrep_hwnd,
e5aea61
--- 2651,2668 ----
e5aea61
  	if (!IsWindow(s_findrep_hwnd))
e5aea61
  	{
e5aea61
  	    initialise_findrep(eap->arg);
e5aea61
! # if defined(FEAT_MBYTE) && defined(WIN3264)
e5aea61
! 	    if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT
e5aea61
! 		    && enc_codepage >= 0 && (int)GetACP() != enc_codepage)
e5aea61
! 	    {
e5aea61
! 		findrep_atow(&s_findrep_struct_w, &s_findrep_struct);
e5aea61
! 		s_findrep_hwnd = ReplaceTextW(
e5aea61
! 					(LPFINDREPLACEW) &s_findrep_struct_w);
e5aea61
! 	    }
e5aea61
! 	    else
e5aea61
! # endif
e5aea61
! 		s_findrep_hwnd = ReplaceText(
e5aea61
! 					   (LPFINDREPLACE) &s_findrep_struct);
e5aea61
  	}
e5aea61
  
e5aea61
  	set_window_title(s_findrep_hwnd,
e5aea61
*** ../vim-7.2.092/src/version.c	Wed Jan 28 19:08:31 2009
e5aea61
--- src/version.c	Wed Jan 28 21:19:56 2009
e5aea61
***************
e5aea61
*** 678,679 ****
e5aea61
--- 678,681 ----
e5aea61
  {   /* Add new patch number below this line */
e5aea61
+ /**/
e5aea61
+     93,
e5aea61
  /**/
e5aea61
e5aea61
-- 
e5aea61
I'm not familiar with this proof, but I'm aware of a significant
e5aea61
following of toddlers who believe that peanut butter is the solution
e5aea61
to all of life's problems... 		-- Tim Hammerquist
e5aea61
e5aea61
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
e5aea61
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
e5aea61
\\\        download, build and distribute -- http://www.A-A-P.org        ///
e5aea61
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///