diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-06-16 16:41:47 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-06-16 16:41:47 +0200 |
commit | 5246cd7a9bb514fd5c44f8deaf0b3ed889e1602f (patch) | |
tree | ed994eac1c64a83deeade87311a727eade094230 /src/os_mswin.c | |
parent | 03e114b0f2c994d58cd744f9be1b498245bd8c08 (diff) | |
download | vim-git-5246cd7a9bb514fd5c44f8deaf0b3ed889e1602f.tar.gz |
updated for version 7.3.1211v7.3.1211
Problem: MS-Windows: When 'encoding' differs from the current codepage
":hardcopy" does not work properly.
Solution: Use TextOutW() and SetDlgItemTextW(). (Ken Takata)
Diffstat (limited to 'src/os_mswin.c')
-rw-r--r-- | src/os_mswin.c | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/src/os_mswin.c b/src/os_mswin.c index 5af1dee51..96d3448c3 100644 --- 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, WPARAM wParam, LPARAM lParam) { 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 *psettings) 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, WPARAM wParam, LPARAM lParam) 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; |