comparison src/os_mswin.c @ 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 784e342ddcae
children 8e28c23e482c
comparison
equal deleted inserted replaced
4931:ea297dbcc864 4932:1cf02fbe6281
1043 #define IDC_BOX1 400 1043 #define IDC_BOX1 400
1044 #define IDC_PRINTTEXT1 401 1044 #define IDC_PRINTTEXT1 401
1045 #define IDC_PRINTTEXT2 402 1045 #define IDC_PRINTTEXT2 402
1046 #define IDC_PROGRESS 403 1046 #define IDC_PROGRESS 403
1047 1047
1048 #if !defined(FEAT_MBYTE) || defined(WIN16)
1049 # define vimSetDlgItemText(h, i, s) SetDlgItemText(h, i, s)
1050 #else
1051 static BOOL
1052 vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s)
1053 {
1054 WCHAR *wp = NULL;
1055 BOOL ret;
1056
1057 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
1058 {
1059 wp = enc_to_utf16(s, NULL);
1060 }
1061 if (wp != NULL)
1062 {
1063 ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp);
1064 vim_free(wp);
1065 return ret;
1066 }
1067 return SetDlgItemText(hDlg, nIDDlgItem, s);
1068 }
1069 #endif
1070
1048 /* 1071 /*
1049 * Convert BGR to RGB for Windows GDI calls 1072 * Convert BGR to RGB for Windows GDI calls
1050 */ 1073 */
1051 static COLORREF 1074 static COLORREF
1052 swap_me(COLORREF colorref) 1075 swap_me(COLORREF colorref)
1094 hfont = CreateFontIndirect(&nm.lfMessageFont); 1117 hfont = CreateFontIndirect(&nm.lfMessageFont);
1095 for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) 1118 for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++)
1096 { 1119 {
1097 SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1); 1120 SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1);
1098 if (GetDlgItemText(hDlg,i, buff, sizeof(buff))) 1121 if (GetDlgItemText(hDlg,i, buff, sizeof(buff)))
1099 SetDlgItemText(hDlg,i, _(buff)); 1122 vimSetDlgItemText(hDlg,i, _(buff));
1100 } 1123 }
1101 SendDlgItemMessage(hDlg, IDCANCEL, 1124 SendDlgItemMessage(hDlg, IDCANCEL,
1102 WM_SETFONT, (WPARAM)hfont, 1); 1125 WM_SETFONT, (WPARAM)hfont, 1);
1103 if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff))) 1126 if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff)))
1104 SetDlgItemText(hDlg,IDCANCEL, _(buff)); 1127 vimSetDlgItemText(hDlg,IDCANCEL, _(buff));
1105 } 1128 }
1106 #endif 1129 #endif
1107 SetWindowText(hDlg, szAppName); 1130 SetWindowText(hDlg, szAppName);
1108 if (prt_name != NULL) 1131 if (prt_name != NULL)
1109 { 1132 {
1110 SetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name); 1133 vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
1111 vim_free(prt_name); 1134 vim_free(prt_name);
1112 prt_name = NULL; 1135 prt_name = NULL;
1113 } 1136 }
1114 EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED); 1137 EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED);
1115 #ifndef FEAT_GUI 1138 #ifndef FEAT_GUI
1563 Escape(prt_dlg.hDC, SETABORTPROC, 0, (LPSTR)AbortProc, NULL); 1586 Escape(prt_dlg.hDC, SETABORTPROC, 0, (LPSTR)AbortProc, NULL);
1564 #else 1587 #else
1565 SetAbortProc(prt_dlg.hDC, AbortProc); 1588 SetAbortProc(prt_dlg.hDC, AbortProc);
1566 #endif 1589 #endif
1567 wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname)); 1590 wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
1568 SetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer); 1591 vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
1569 1592
1570 vim_memset(&di, 0, sizeof(DOCINFO)); 1593 vim_memset(&di, 0, sizeof(DOCINFO));
1571 di.cbSize = sizeof(DOCINFO); 1594 di.cbSize = sizeof(DOCINFO);
1572 di.lpszDocName = psettings->jobname; 1595 di.lpszDocName = psettings->jobname;
1573 ret = StartDoc(prt_dlg.hDC, &di); 1596 ret = StartDoc(prt_dlg.hDC, &di);
1597 1620
1598 int 1621 int
1599 mch_print_begin_page(char_u *msg) 1622 mch_print_begin_page(char_u *msg)
1600 { 1623 {
1601 if (msg != NULL) 1624 if (msg != NULL)
1602 SetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg); 1625 vimSetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
1603 return (StartPage(prt_dlg.hDC) > 0); 1626 return (StartPage(prt_dlg.hDC) > 0);
1604 } 1627 }
1605 1628
1606 int 1629 int
1607 mch_print_blank_page(void) 1630 mch_print_blank_page(void)
1626 } 1649 }
1627 1650
1628 int 1651 int
1629 mch_print_text_out(char_u *p, int len) 1652 mch_print_text_out(char_u *p, int len)
1630 { 1653 {
1631 #ifdef FEAT_PROPORTIONAL_FONTS 1654 #if defined(FEAT_PROPORTIONAL_FONTS) || (defined(FEAT_MBYTE) && !defined(WIN16))
1632 SIZE sz; 1655 SIZE sz;
1633 #endif 1656 #endif
1634 1657 #if defined(FEAT_MBYTE) && !defined(WIN16)
1658 WCHAR *wp = NULL;
1659 int wlen = len;
1660
1661 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
1662 {
1663 wp = enc_to_utf16(p, &wlen);
1664 }
1665 if (wp != NULL)
1666 {
1667 int ret = FALSE;
1668
1669 TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin,
1670 prt_pos_y + prt_top_margin, wp, wlen);
1671 GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz);
1672 vim_free(wp);
1673 prt_pos_x += (sz.cx - prt_tm.tmOverhang);
1674 /* This is wrong when printing spaces for a TAB. */
1675 if (p[len] != NUL)
1676 {
1677 wlen = MB_PTR2LEN(p + len);
1678 wp = enc_to_utf16(p + len, &wlen);
1679 if (wp != NULL)
1680 {
1681 GetTextExtentPoint32W(prt_dlg.hDC, wp, 1, &sz);
1682 ret = (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin);
1683 vim_free(wp);
1684 }
1685 }
1686 return ret;
1687 }
1688 #endif
1635 TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin, 1689 TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin,
1636 prt_pos_y + prt_top_margin, p, len); 1690 prt_pos_y + prt_top_margin, p, len);
1637 #ifndef FEAT_PROPORTIONAL_FONTS 1691 #ifndef FEAT_PROPORTIONAL_FONTS
1638 prt_pos_x += len * prt_tm.tmAveCharWidth; 1692 prt_pos_x += len * prt_tm.tmAveCharWidth;
1639 return (prt_pos_x + prt_left_margin + prt_tm.tmAveCharWidth 1693 return (prt_pos_x + prt_left_margin + prt_tm.tmAveCharWidth
1945 reply.dwData = COPYDATA_RESULT; 1999 reply.dwData = COPYDATA_RESULT;
1946 reply.lpData = res; 2000 reply.lpData = res;
1947 reply.cbData = (DWORD)STRLEN(res) + 1; 2001 reply.cbData = (DWORD)STRLEN(res) + 1;
1948 2002
1949 serverSendEnc(sender); 2003 serverSendEnc(sender);
1950 retval = (int)SendMessage(sender, WM_COPYDATA, (WPARAM)message_window, 2004 retval = (int)SendMessage(sender, WM_COPYDATA,
1951 (LPARAM)(&reply)); 2005 (WPARAM)message_window, (LPARAM)(&reply));
1952 vim_free(res); 2006 vim_free(res);
1953 return retval; 2007 return retval;
1954 2008
1955 case COPYDATA_REPLY: 2009 case COPYDATA_REPLY:
1956 case COPYDATA_RESULT: 2010 case COPYDATA_RESULT: