changeset 4932:1cf02fbe6281 v7.3.1211

updated for version 7.3.1211 Problem: MS-Windows: When 'encoding' differs from the current codepage ":hardcopy" does not work properly. Solution: Use TextOutW() and SetDlgItemTextW(). (Ken Takata)
author Bram Moolenaar <bram@vim.org>
date Sun, 16 Jun 2013 16:41:47 +0200
parents ea297dbcc864
children 411ca276be59
files src/os_mswin.c src/version.c src/vim.rc
diffstat 3 files changed, 68 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -1045,6 +1045,29 @@ static char_u		*prt_name = NULL;
 #define IDC_PRINTTEXT2		402
 #define IDC_PROGRESS		403
 
+#if !defined(FEAT_MBYTE) || defined(WIN16)
+# define vimSetDlgItemText(h, i, s) SetDlgItemText(h, i, s)
+#else
+    static BOOL
+vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s)
+{
+    WCHAR   *wp = NULL;
+    BOOL    ret;
+
+    if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+    {
+	wp = enc_to_utf16(s, NULL);
+    }
+    if (wp != NULL)
+    {
+	ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp);
+	vim_free(wp);
+	return ret;
+    }
+    return SetDlgItemText(hDlg, nIDDlgItem, s);
+}
+#endif
+
 /*
  * Convert BGR to RGB for Windows GDI calls
  */
@@ -1096,18 +1119,18 @@ PrintDlgProc(HWND hDlg, UINT message, WP
 		{
 		    SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1);
 		    if (GetDlgItemText(hDlg,i, buff, sizeof(buff)))
-			SetDlgItemText(hDlg,i, _(buff));
+			vimSetDlgItemText(hDlg,i, _(buff));
 		}
 		SendDlgItemMessage(hDlg, IDCANCEL,
 						WM_SETFONT, (WPARAM)hfont, 1);
 		if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff)))
-		    SetDlgItemText(hDlg,IDCANCEL, _(buff));
+		    vimSetDlgItemText(hDlg,IDCANCEL, _(buff));
 	    }
 #endif
 	    SetWindowText(hDlg, szAppName);
 	    if (prt_name != NULL)
 	    {
-		SetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
+		vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
 		vim_free(prt_name);
 		prt_name = NULL;
 	    }
@@ -1565,7 +1588,7 @@ mch_print_begin(prt_settings_T *psetting
     SetAbortProc(prt_dlg.hDC, AbortProc);
 #endif
     wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
-    SetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
+    vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
 
     vim_memset(&di, 0, sizeof(DOCINFO));
     di.cbSize = sizeof(DOCINFO);
@@ -1599,7 +1622,7 @@ mch_print_end_page(void)
 mch_print_begin_page(char_u *msg)
 {
     if (msg != NULL)
-	SetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
+	vimSetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
     return (StartPage(prt_dlg.hDC) > 0);
 }
 
@@ -1628,10 +1651,41 @@ mch_print_start_line(margin, page_line)
     int
 mch_print_text_out(char_u *p, int len)
 {
-#ifdef FEAT_PROPORTIONAL_FONTS
+#if defined(FEAT_PROPORTIONAL_FONTS) || (defined(FEAT_MBYTE) && !defined(WIN16))
     SIZE	sz;
 #endif
-
+#if defined(FEAT_MBYTE) && !defined(WIN16)
+    WCHAR	*wp = NULL;
+    int		wlen = len;
+
+    if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+    {
+	wp = enc_to_utf16(p, &wlen);
+    }
+    if (wp != NULL)
+    {
+	int ret = FALSE;
+
+	TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin,
+					 prt_pos_y + prt_top_margin, wp, wlen);
+	GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz);
+	vim_free(wp);
+	prt_pos_x += (sz.cx - prt_tm.tmOverhang);
+	/* This is wrong when printing spaces for a TAB. */
+	if (p[len] != NUL)
+	{
+	    wlen = MB_PTR2LEN(p + len);
+	    wp = enc_to_utf16(p + len, &wlen);
+	    if (wp != NULL)
+	    {
+		GetTextExtentPoint32W(prt_dlg.hDC, wp, 1, &sz);
+		ret = (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin);
+		vim_free(wp);
+	    }
+	}
+	return ret;
+    }
+#endif
     TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin,
 					  prt_pos_y + prt_top_margin, p, len);
 #ifndef FEAT_PROPORTIONAL_FONTS
@@ -1947,8 +2001,8 @@ Messaging_WndProc(HWND hwnd, UINT msg, W
 	    reply.cbData = (DWORD)STRLEN(res) + 1;
 
 	    serverSendEnc(sender);
-	    retval = (int)SendMessage(sender, WM_COPYDATA, (WPARAM)message_window,
-							    (LPARAM)(&reply));
+	    retval = (int)SendMessage(sender, WM_COPYDATA,
+				    (WPARAM)message_window, (LPARAM)(&reply));
 	    vim_free(res);
 	    return retval;
 
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1211,
+/**/
     1210,
 /**/
     1209,
--- a/src/vim.rc
+++ b/src/vim.rc
@@ -116,8 +116,8 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_VISI
 FONT 8, "Helv"
 BEGIN
     DEFPUSHBUTTON   "Cancel", IDCANCEL, 85, 60, 40, 14
-    CTEXT	    "Printing",IDC_PRINTTEXT1,23,15,157,8
-    CTEXT	    " ",IDC_PRINTTEXT2,23,25,157,8
-    CTEXT	    "Initializing...",IDC_PROGRESS,24,38,157,8
+    CTEXT	    "Printing",IDC_PRINTTEXT1,23,15,157,9
+    CTEXT	    " ",IDC_PRINTTEXT2,23,25,157,9
+    CTEXT	    "Initializing...",IDC_PROGRESS,24,38,157,9
     GROUPBOX	    "",IDC_BOX1,19,9,170,47
 END