0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.1.1103: MS-Windows: old API calls are no longer needed

Problem:    MS-Windows: old API calls are no longer needed.
Solution:   Always use the wide functions. (Ken Takata, closes #4199)
This commit is contained in:
Bram Moolenaar 2019-04-02 22:15:55 +02:00
parent b26705afb5
commit 0eb035c974
8 changed files with 719 additions and 1563 deletions

View File

@ -133,14 +133,7 @@ global_ime_DefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
if (pIApp == NULL || pIApp->OnDefWindowProc(hWnd, Msg, if (pIApp == NULL || pIApp->OnDefWindowProc(hWnd, Msg,
wParam, lParam, &lResult) != S_OK) wParam, lParam, &lResult) != S_OK)
{ lResult = DefWindowProcW(hWnd, Msg, wParam, lParam);
#if defined(MSWIN)
if (wide_WindowProc)
lResult = DefWindowProcW(hWnd, Msg, wParam, lParam);
else
#endif
lResult = DefWindowProc(hWnd, Msg, wParam, lParam);
}
return lResult; return lResult;
} }

View File

@ -822,10 +822,6 @@ EXTERN int enc_latin9 INIT(= FALSE); /* 'encoding' is latin9 */
#endif #endif
EXTERN int has_mbyte INIT(= 0); /* any multi-byte encoding */ EXTERN int has_mbyte INIT(= 0); /* any multi-byte encoding */
#if defined(MSWIN)
EXTERN int wide_WindowProc INIT(= FALSE); /* use wide WindowProc() */
#endif
/* /*
* To speed up BYTELEN() we fill a table with the byte lengths whenever * To speed up BYTELEN() we fill a table with the byte lengths whenever
* enc_utf8 or enc_dbcs changes. * enc_utf8 or enc_dbcs changes.

View File

@ -313,12 +313,11 @@ static int s_busy_processing = FALSE;
static int destroying = FALSE; /* call DestroyWindow() ourselves */ static int destroying = FALSE; /* call DestroyWindow() ourselves */
#ifdef MSWIN_FIND_REPLACE #ifdef MSWIN_FIND_REPLACE
static UINT s_findrep_msg = 0; /* set in gui_w[16/32].c */ static UINT s_findrep_msg = 0; // set in gui_w[16/32].c
static FINDREPLACE s_findrep_struct; static FINDREPLACEW s_findrep_struct;
static FINDREPLACEW s_findrep_struct_w;
static HWND s_findrep_hwnd = NULL; static HWND s_findrep_hwnd = NULL;
static int s_findrep_is_find; /* TRUE for find dialog, FALSE static int s_findrep_is_find; // TRUE for find dialog, FALSE
for find/replace dialog */ // for find/replace dialog
#endif #endif
static HINSTANCE s_hinst = NULL; static HINSTANCE s_hinst = NULL;
@ -391,7 +390,7 @@ directx_binddc(void)
} }
#endif #endif
/* use of WindowProc depends on wide_WindowProc */ /* use of WindowProc depends on Global IME */
#define MyWindowProc vim_WindowProc #define MyWindowProc vim_WindowProc
extern int current_font_height; /* this is in os_mswin.c */ extern int current_font_height; /* this is in os_mswin.c */
@ -1106,43 +1105,6 @@ _OnMenu(
#endif #endif
#ifdef MSWIN_FIND_REPLACE #ifdef MSWIN_FIND_REPLACE
/*
* copy useful data from structure LPFINDREPLACE to structure LPFINDREPLACEW
*/
static void
findrep_atow(LPFINDREPLACEW lpfrw, LPFINDREPLACE lpfr)
{
WCHAR *wp;
lpfrw->hwndOwner = lpfr->hwndOwner;
lpfrw->Flags = lpfr->Flags;
wp = enc_to_utf16((char_u *)lpfr->lpstrFindWhat, NULL);
wcsncpy(lpfrw->lpstrFindWhat, wp, lpfrw->wFindWhatLen - 1);
vim_free(wp);
/* the field "lpstrReplaceWith" doesn't need to be copied */
}
/*
* copy useful data from structure LPFINDREPLACEW to structure LPFINDREPLACE
*/
static void
findrep_wtoa(LPFINDREPLACE lpfr, LPFINDREPLACEW lpfrw)
{
char_u *p;
lpfr->Flags = lpfrw->Flags;
p = utf16_to_enc((short_u*)lpfrw->lpstrFindWhat, NULL);
vim_strncpy((char_u *)lpfr->lpstrFindWhat, p, lpfr->wFindWhatLen - 1);
vim_free(p);
p = utf16_to_enc((short_u*)lpfrw->lpstrReplaceWith, NULL);
vim_strncpy((char_u *)lpfr->lpstrReplaceWith, p, lpfr->wReplaceWithLen - 1);
vim_free(p);
}
/* /*
* Handle a Find/Replace window message. * Handle a Find/Replace window message.
*/ */
@ -1152,11 +1114,6 @@ _OnFindRepl(void)
int flags = 0; int flags = 0;
int down; int down;
/* If the OS is Windows NT, and 'encoding' differs from active codepage:
* convert text from wide string. */
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
findrep_wtoa(&s_findrep_struct, &s_findrep_struct_w);
if (s_findrep_struct.Flags & FR_DIALOGTERM) if (s_findrep_struct.Flags & FR_DIALOGTERM)
/* Give main window the focus back. */ /* Give main window the focus back. */
(void)SetFocus(s_hwnd); (void)SetFocus(s_hwnd);
@ -1184,14 +1141,20 @@ _OnFindRepl(void)
if (flags != 0) if (flags != 0)
{ {
char_u *p, *q;
/* Call the generic GUI function to do the actual work. */ /* Call the generic GUI function to do the actual work. */
if (s_findrep_struct.Flags & FR_WHOLEWORD) if (s_findrep_struct.Flags & FR_WHOLEWORD)
flags |= FRD_WHOLE_WORD; flags |= FRD_WHOLE_WORD;
if (s_findrep_struct.Flags & FR_MATCHCASE) if (s_findrep_struct.Flags & FR_MATCHCASE)
flags |= FRD_MATCH_CASE; flags |= FRD_MATCH_CASE;
down = (s_findrep_struct.Flags & FR_DOWN) != 0; down = (s_findrep_struct.Flags & FR_DOWN) != 0;
gui_do_findrepl(flags, (char_u *)s_findrep_struct.lpstrFindWhat, p = utf16_to_enc(s_findrep_struct.lpstrFindWhat, NULL);
(char_u *)s_findrep_struct.lpstrReplaceWith, down); q = utf16_to_enc(s_findrep_struct.lpstrReplaceWith, NULL);
if (p != NULL && q != NULL)
gui_do_findrepl(flags, p, q, down);
vim_free(p);
vim_free(q);
} }
} }
#endif #endif
@ -1310,9 +1273,7 @@ vim_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
#ifdef GLOBAL_IME #ifdef GLOBAL_IME
return global_ime_DefWindowProc(hwnd, message, wParam, lParam); return global_ime_DefWindowProc(hwnd, message, wParam, lParam);
#else #else
if (wide_WindowProc) return DefWindowProcW(hwnd, message, wParam, lParam);
return DefWindowProcW(hwnd, message, wParam, lParam);
return DefWindowProc(hwnd, message, wParam, lParam);
#endif #endif
} }
@ -2332,21 +2293,15 @@ GetTextWidthEnc(HDC hdc, char_u *str, int len)
int n; int n;
int wlen = len; int wlen = len;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wstr = enc_to_utf16(str, &wlen);
{ if (wstr == NULL)
/* 'encoding' differs from active codepage: convert text and use wide return 0;
* function */
wstr = enc_to_utf16(str, &wlen);
if (wstr != NULL)
{
n = GetTextExtentPointW(hdc, wstr, wlen, &size);
vim_free(wstr);
if (n)
return size.cx;
}
}
return GetTextWidth(hdc, str, len); n = GetTextExtentPointW(hdc, wstr, wlen, &size);
vim_free(wstr);
if (n)
return size.cx;
return 0;
} }
static void get_work_area(RECT *spi_rect); static void get_work_area(RECT *spi_rect);
@ -2423,19 +2378,19 @@ gui_mch_show_toolbar(int showit)
if (showit) if (showit)
{ {
# ifndef TB_SETUNICODEFORMAT # ifndef TB_SETUNICODEFORMAT
/* For older compilers. We assume this never changes. */ // For older compilers. We assume this never changes.
# define TB_SETUNICODEFORMAT 0x2005 # define TB_SETUNICODEFORMAT 0x2005
# endif # endif
/* Enable/disable unicode support */ // Enable unicode support
int uu = (enc_codepage >= 0 && (int)GetACP() != enc_codepage); SendMessage(s_toolbarhwnd, TB_SETUNICODEFORMAT, (WPARAM)TRUE,
SendMessage(s_toolbarhwnd, TB_SETUNICODEFORMAT, (WPARAM)uu, (LPARAM)0); (LPARAM)0);
ShowWindow(s_toolbarhwnd, SW_SHOW); ShowWindow(s_toolbarhwnd, SW_SHOW);
} }
else else
ShowWindow(s_toolbarhwnd, SW_HIDE); ShowWindow(s_toolbarhwnd, SW_HIDE);
} }
/* Then number of bitmaps is fixed. Exit is missing! */ /* The number of bitmaps is fixed. Exit is missing! */
#define TOOLBAR_BITMAP_COUNT 31 #define TOOLBAR_BITMAP_COUNT 31
#endif #endif
@ -2444,40 +2399,21 @@ gui_mch_show_toolbar(int showit)
static void static void
add_tabline_popup_menu_entry(HMENU pmenu, UINT item_id, char_u *item_text) add_tabline_popup_menu_entry(HMENU pmenu, UINT item_id, char_u *item_text)
{ {
WCHAR *wn = NULL; WCHAR *wn;
MENUITEMINFOW infow;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
/* 'encoding' differs from active codepage: convert menu name
* and use wide function */
wn = enc_to_utf16(item_text, NULL);
if (wn != NULL)
{
MENUITEMINFOW infow;
infow.cbSize = sizeof(infow);
infow.fMask = MIIM_TYPE | MIIM_ID;
infow.wID = item_id;
infow.fType = MFT_STRING;
infow.dwTypeData = wn;
infow.cch = (UINT)wcslen(wn);
InsertMenuItemW(pmenu, item_id, FALSE, &infow);
vim_free(wn);
}
}
wn = enc_to_utf16(item_text, NULL);
if (wn == NULL) if (wn == NULL)
{ return;
MENUITEMINFO info;
info.cbSize = sizeof(info); infow.cbSize = sizeof(infow);
info.fMask = MIIM_TYPE | MIIM_ID; infow.fMask = MIIM_TYPE | MIIM_ID;
info.wID = item_id; infow.wID = item_id;
info.fType = MFT_STRING; infow.fType = MFT_STRING;
info.dwTypeData = (LPTSTR)item_text; infow.dwTypeData = wn;
info.cch = (UINT)STRLEN(item_text); infow.cch = (UINT)wcslen(wn);
InsertMenuItem(pmenu, item_id, FALSE, &info); InsertMenuItemW(pmenu, item_id, FALSE, &infow);
} vim_free(wn);
} }
static void static void
@ -2573,8 +2509,6 @@ gui_mch_update_tabline(void)
int nr = 0; int nr = 0;
int curtabidx = 0; int curtabidx = 0;
int tabadded = 0; int tabadded = 0;
static int use_unicode = FALSE;
int uu;
WCHAR *wstr = NULL; WCHAR *wstr = NULL;
if (s_tabhwnd == NULL) if (s_tabhwnd == NULL)
@ -2584,13 +2518,8 @@ gui_mch_update_tabline(void)
/* For older compilers. We assume this never changes. */ /* For older compilers. We assume this never changes. */
# define CCM_SETUNICODEFORMAT 0x2005 # define CCM_SETUNICODEFORMAT 0x2005
#endif #endif
uu = (enc_codepage >= 0 && (int)GetACP() != enc_codepage); // Enable unicode support
if (uu != use_unicode) SendMessage(s_tabhwnd, CCM_SETUNICODEFORMAT, (WPARAM)TRUE, (LPARAM)0);
{
/* Enable/disable unicode support */
SendMessage(s_tabhwnd, CCM_SETUNICODEFORMAT, (WPARAM)uu, (LPARAM)0);
use_unicode = uu;
}
tie.mask = TCIF_TEXT; tie.mask = TCIF_TEXT;
tie.iImage = -1; tie.iImage = -1;
@ -2614,24 +2543,18 @@ gui_mch_update_tabline(void)
get_tabline_label(tp, FALSE); get_tabline_label(tp, FALSE);
tie.pszText = (LPSTR)NameBuff; tie.pszText = (LPSTR)NameBuff;
wstr = NULL;
if (use_unicode)
{
/* Need to go through Unicode. */
wstr = enc_to_utf16(NameBuff, NULL);
if (wstr != NULL)
{
TCITEMW tiw;
tiw.mask = TCIF_TEXT; wstr = enc_to_utf16(NameBuff, NULL);
tiw.iImage = -1; if (wstr != NULL)
tiw.pszText = wstr; {
SendMessage(s_tabhwnd, TCM_SETITEMW, (WPARAM)nr, (LPARAM)&tiw); TCITEMW tiw;
vim_free(wstr);
} tiw.mask = TCIF_TEXT;
tiw.iImage = -1;
tiw.pszText = wstr;
SendMessage(s_tabhwnd, TCM_SETITEMW, (WPARAM)nr, (LPARAM)&tiw);
vim_free(wstr);
} }
if (wstr == NULL)
TabCtrl_SetItem(s_tabhwnd, nr, &tie);
} }
/* Remove any old labels. */ /* Remove any old labels. */
@ -2720,8 +2643,17 @@ initialise_findrep(char_u *initial_string)
if (wword) if (wword)
s_findrep_struct.Flags |= FR_WHOLEWORD; s_findrep_struct.Flags |= FR_WHOLEWORD;
if (entry_text != NULL && *entry_text != NUL) if (entry_text != NULL && *entry_text != NUL)
vim_strncpy((char_u *)s_findrep_struct.lpstrFindWhat, entry_text, {
s_findrep_struct.wFindWhatLen - 1); WCHAR *p = enc_to_utf16(entry_text, NULL);
if (p != NULL)
{
int len = s_findrep_struct.wFindWhatLen - 1;
wcsncpy(s_findrep_struct.lpstrFindWhat, p, len);
s_findrep_struct.lpstrFindWhat[len] = NUL;
vim_free(p);
}
}
vim_free(entry_text); vim_free(entry_text);
} }
#endif #endif
@ -2729,7 +2661,7 @@ initialise_findrep(char_u *initial_string)
static void static void
set_window_title(HWND hwnd, char *title) set_window_title(HWND hwnd, char *title)
{ {
if (title != NULL && enc_codepage >= 0 && enc_codepage != (int)GetACP()) if (title != NULL)
{ {
WCHAR *wbuf; WCHAR *wbuf;
@ -2740,9 +2672,9 @@ set_window_title(HWND hwnd, char *title)
SetWindowTextW(hwnd, wbuf); SetWindowTextW(hwnd, wbuf);
vim_free(wbuf); vim_free(wbuf);
} }
return;
} }
(void)SetWindowText(hwnd, (LPCSTR)title); else
(void)SetWindowTextW(hwnd, NULL);
} }
void void
@ -2757,16 +2689,7 @@ gui_mch_find_dialog(exarg_T *eap)
if (!IsWindow(s_findrep_hwnd)) if (!IsWindow(s_findrep_hwnd))
{ {
initialise_findrep(eap->arg); initialise_findrep(eap->arg);
/* If the OS is Windows NT, and 'encoding' differs from active s_findrep_hwnd = FindTextW((LPFINDREPLACEW) &s_findrep_struct);
* codepage: convert text and use wide function. */
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
findrep_atow(&s_findrep_struct_w, &s_findrep_struct);
s_findrep_hwnd = FindTextW(
(LPFINDREPLACEW) &s_findrep_struct_w);
}
else
s_findrep_hwnd = FindText((LPFINDREPLACE) &s_findrep_struct);
} }
set_window_title(s_findrep_hwnd, _("Find string")); set_window_title(s_findrep_hwnd, _("Find string"));
@ -2790,15 +2713,7 @@ gui_mch_replace_dialog(exarg_T *eap)
if (!IsWindow(s_findrep_hwnd)) if (!IsWindow(s_findrep_hwnd))
{ {
initialise_findrep(eap->arg); initialise_findrep(eap->arg);
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) s_findrep_hwnd = ReplaceTextW((LPFINDREPLACEW) &s_findrep_struct);
{
findrep_atow(&s_findrep_struct_w, &s_findrep_struct);
s_findrep_hwnd = ReplaceTextW(
(LPFINDREPLACEW) &s_findrep_struct_w);
}
else
s_findrep_hwnd = ReplaceText(
(LPFINDREPLACE) &s_findrep_struct);
} }
set_window_title(s_findrep_hwnd, _("Find & Replace")); set_window_title(s_findrep_hwnd, _("Find & Replace"));
@ -4147,7 +4062,6 @@ static UINT s_menu_id = 100;
#define USE_SYSMENU_FONT #define USE_SYSMENU_FONT
#define VIM_NAME "vim" #define VIM_NAME "vim"
#define VIM_CLASS "Vim"
#define VIM_CLASSW L"Vim" #define VIM_CLASSW L"Vim"
/* Initial size for the dialog template. For gui_mch_dialog() it's fixed, /* Initial size for the dialog template. For gui_mch_dialog() it's fixed,
@ -5021,9 +4935,6 @@ gui_mch_prepare(int *argc, char **argv)
int int
gui_mch_init(void) gui_mch_init(void)
{ {
const char szVimWndClass[] = VIM_CLASS;
const char szTextAreaClass[] = "VimTextArea";
WNDCLASS wndclass;
const WCHAR szVimWndClassW[] = VIM_CLASSW; const WCHAR szVimWndClassW[] = VIM_CLASSW;
const WCHAR szTextAreaClassW[] = L"VimTextArea"; const WCHAR szTextAreaClassW[] = L"VimTextArea";
WNDCLASSW wndclassw; WNDCLASSW wndclassw;
@ -5073,50 +4984,26 @@ gui_mch_init(void)
#endif #endif
RegisterClassW(&wndclassw)) == 0) RegisterClassW(&wndclassw)) == 0)
return FAIL; return FAIL;
else
wide_WindowProc = TRUE;
} }
if (!wide_WindowProc)
if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0)
{
wndclass.style = CS_DBLCLKS;
wndclass.lpfnWndProc = _WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = s_hinst;
wndclass.hIcon = LoadIcon(wndclass.hInstance, "IDR_VIM");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = s_brush;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szVimWndClass;
if ((
#ifdef GLOBAL_IME
atom =
#endif
RegisterClass(&wndclass)) == 0)
return FAIL;
}
if (vim_parent_hwnd != NULL) if (vim_parent_hwnd != NULL)
{ {
#ifdef HAVE_TRY_EXCEPT #ifdef HAVE_TRY_EXCEPT
__try __try
{ {
#endif #endif
/* Open inside the specified parent window. // Open inside the specified parent window.
* TODO: last argument should point to a CLIENTCREATESTRUCT // TODO: last argument should point to a CLIENTCREATESTRUCT
* structure. */ // structure.
s_hwnd = CreateWindowEx( s_hwnd = CreateWindowExW(
WS_EX_MDICHILD, WS_EX_MDICHILD,
szVimWndClass, "Vim MSWindows GUI", szVimWndClassW, L"Vim MSWindows GUI",
WS_OVERLAPPEDWINDOW | WS_CHILD WS_OVERLAPPEDWINDOW | WS_CHILD
| WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 0xC000, | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 0xC000,
gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y,
100, /* Any value will do */ 100, // Any value will do
100, /* Any value will do */ 100, // Any value will do
vim_parent_hwnd, NULL, vim_parent_hwnd, NULL,
s_hinst, NULL); s_hinst, NULL);
#ifdef HAVE_TRY_EXCEPT #ifdef HAVE_TRY_EXCEPT
@ -5141,8 +5028,8 @@ gui_mch_init(void)
/* Create a window. If win_socket_id is not zero without border and /* Create a window. If win_socket_id is not zero without border and
* titlebar, it will be reparented below. */ * titlebar, it will be reparented below. */
s_hwnd = CreateWindow( s_hwnd = CreateWindowW(
szVimWndClass, "Vim MSWindows GUI", szVimWndClassW, L"Vim MSWindows GUI",
(win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP) (win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP)
| WS_CLIPSIBLINGS | WS_CLIPCHILDREN, | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
@ -5169,60 +5056,32 @@ gui_mch_init(void)
#endif #endif
/* Create the text area window */ /* Create the text area window */
if (wide_WindowProc) if (GetClassInfoW(s_hinst, szTextAreaClassW, &wndclassw) == 0)
{ {
if (GetClassInfoW(s_hinst, szTextAreaClassW, &wndclassw) == 0) wndclassw.style = CS_OWNDC;
{ wndclassw.lpfnWndProc = _TextAreaWndProc;
wndclassw.style = CS_OWNDC; wndclassw.cbClsExtra = 0;
wndclassw.lpfnWndProc = _TextAreaWndProc; wndclassw.cbWndExtra = 0;
wndclassw.cbClsExtra = 0; wndclassw.hInstance = s_hinst;
wndclassw.cbWndExtra = 0; wndclassw.hIcon = NULL;
wndclassw.hInstance = s_hinst; wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclassw.hIcon = NULL; wndclassw.hbrBackground = NULL;
wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); wndclassw.lpszMenuName = NULL;
wndclassw.hbrBackground = NULL; wndclassw.lpszClassName = szTextAreaClassW;
wndclassw.lpszMenuName = NULL;
wndclassw.lpszClassName = szTextAreaClassW;
if (RegisterClassW(&wndclassw) == 0) if (RegisterClassW(&wndclassw) == 0)
return FAIL;
}
s_textArea = CreateWindowExW(
0,
szTextAreaClassW, L"Vim text area",
WS_CHILD | WS_VISIBLE, 0, 0,
100, // Any value will do for now
100, // Any value will do for now
s_hwnd, NULL,
s_hinst, NULL);
}
else if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0)
{
wndclass.style = CS_OWNDC;
wndclass.lpfnWndProc = _TextAreaWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = s_hinst;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szTextAreaClass;
if (RegisterClass(&wndclass) == 0)
return FAIL; return FAIL;
s_textArea = CreateWindowEx(
0,
szTextAreaClass, "Vim text area",
WS_CHILD | WS_VISIBLE, 0, 0,
100, // Any value will do for now
100, // Any value will do for now
s_hwnd, NULL,
s_hinst, NULL);
} }
s_textArea = CreateWindowExW(
0,
szTextAreaClassW, L"Vim text area",
WS_CHILD | WS_VISIBLE, 0, 0,
100, // Any value will do for now
100, // Any value will do for now
s_hwnd, NULL,
s_hinst, NULL);
if (s_textArea == NULL) if (s_textArea == NULL)
return FAIL; return FAIL;
@ -5299,21 +5158,14 @@ gui_mch_init(void)
/* Initialise the struct */ /* Initialise the struct */
s_findrep_struct.lStructSize = sizeof(s_findrep_struct); s_findrep_struct.lStructSize = sizeof(s_findrep_struct);
s_findrep_struct.lpstrFindWhat = (LPSTR)alloc(MSWIN_FR_BUFSIZE); s_findrep_struct.lpstrFindWhat =
(LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
s_findrep_struct.lpstrFindWhat[0] = NUL; s_findrep_struct.lpstrFindWhat[0] = NUL;
s_findrep_struct.lpstrReplaceWith = (LPSTR)alloc(MSWIN_FR_BUFSIZE); s_findrep_struct.lpstrReplaceWith =
(LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
s_findrep_struct.lpstrReplaceWith[0] = NUL; s_findrep_struct.lpstrReplaceWith[0] = NUL;
s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
s_findrep_struct_w.lStructSize = sizeof(s_findrep_struct_w);
s_findrep_struct_w.lpstrFindWhat =
(LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
s_findrep_struct_w.lpstrFindWhat[0] = NUL;
s_findrep_struct_w.lpstrReplaceWith =
(LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR));
s_findrep_struct_w.lpstrReplaceWith[0] = NUL;
s_findrep_struct_w.wFindWhatLen = MSWIN_FR_BUFSIZE;
s_findrep_struct_w.wReplaceWithLen = MSWIN_FR_BUFSIZE;
#endif #endif
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
@ -6344,49 +6196,26 @@ gui_mch_add_menu(
if (menu_is_menubar(menu->name)) if (menu_is_menubar(menu->name))
{ {
WCHAR *wn = NULL; WCHAR *wn;
MENUITEMINFOW infow;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
/* 'encoding' differs from active codepage: convert menu name
* and use wide function */
wn = enc_to_utf16(menu->name, NULL);
if (wn != NULL)
{
MENUITEMINFOW infow;
infow.cbSize = sizeof(infow);
infow.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID
| MIIM_SUBMENU;
infow.dwItemData = (long_u)menu;
infow.wID = menu->id;
infow.fType = MFT_STRING;
infow.dwTypeData = wn;
infow.cch = (UINT)wcslen(wn);
infow.hSubMenu = menu->submenu_id;
InsertMenuItemW((parent == NULL)
? s_menuBar : parent->submenu_id,
(UINT)pos, TRUE, &infow);
vim_free(wn);
}
}
wn = enc_to_utf16(menu->name, NULL);
if (wn == NULL) if (wn == NULL)
{ return;
MENUITEMINFO info;
info.cbSize = sizeof(info); infow.cbSize = sizeof(infow);
info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID | MIIM_SUBMENU; infow.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID
info.dwItemData = (long_u)menu; | MIIM_SUBMENU;
info.wID = menu->id; infow.dwItemData = (long_u)menu;
info.fType = MFT_STRING; infow.wID = menu->id;
info.dwTypeData = (LPTSTR)menu->name; infow.fType = MFT_STRING;
info.cch = (UINT)STRLEN(menu->name); infow.dwTypeData = wn;
info.hSubMenu = menu->submenu_id; infow.cch = (UINT)wcslen(wn);
InsertMenuItem((parent == NULL) infow.hSubMenu = menu->submenu_id;
? s_menuBar : parent->submenu_id, InsertMenuItemW((parent == NULL)
(UINT)pos, TRUE, &info); ? s_menuBar : parent->submenu_id,
} (UINT)pos, TRUE, &infow);
vim_free(wn);
} }
/* Fix window size if menu may have wrapped */ /* Fix window size if menu may have wrapped */
@ -6499,27 +6328,17 @@ gui_mch_add_menu_item(
else else
#endif #endif
{ {
WCHAR *wn = NULL; WCHAR *wn;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wn = enc_to_utf16(menu->name, NULL);
if (wn != NULL)
{ {
/* 'encoding' differs from active codepage: convert menu item name InsertMenuW(parent->submenu_id, (UINT)idx,
* and use wide function */ (menu_is_separator(menu->name)
wn = enc_to_utf16(menu->name, NULL); ? MF_SEPARATOR : MF_STRING) | MF_BYPOSITION,
if (wn != NULL) (UINT)menu->id, wn);
{ vim_free(wn);
InsertMenuW(parent->submenu_id, (UINT)idx,
(menu_is_separator(menu->name)
? MF_SEPARATOR : MF_STRING) | MF_BYPOSITION,
(UINT)menu->id, wn);
vim_free(wn);
}
} }
if (wn == NULL)
InsertMenu(parent->submenu_id, (UINT)idx,
(menu_is_separator(menu->name) ? MF_SEPARATOR : MF_STRING)
| MF_BYPOSITION,
(UINT)menu->id, (LPCTSTR)menu->name);
#ifdef FEAT_TEAROFF #ifdef FEAT_TEAROFF
if (IsWindow(parent->tearoff_handle)) if (IsWindow(parent->tearoff_handle))
rebuild_tearoff(parent); rebuild_tearoff(parent);
@ -6709,22 +6528,14 @@ dialog_callback(
/* If the edit box exists, copy the string. */ /* If the edit box exists, copy the string. */
if (s_textfield != NULL) if (s_textfield != NULL)
{ {
/* If the OS is Windows NT, and 'encoding' differs from active WCHAR *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR));
* codepage: use wide function and convert text. */ char_u *p;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
WCHAR *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR));
char_u *p;
GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE); GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE);
p = utf16_to_enc(wp, NULL); p = utf16_to_enc(wp, NULL);
vim_strncpy(s_textfield, p, IOSIZE); vim_strncpy(s_textfield, p, IOSIZE);
vim_free(p); vim_free(p);
vim_free(wp); vim_free(wp);
}
else
GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2,
(LPSTR)s_textfield, IOSIZE);
} }
/* /*
@ -8411,7 +8222,7 @@ multiline_balloon_available(void)
} }
static void static void
make_tooltipw(BalloonEval *beval, char *text, POINT pt) make_tooltip(BalloonEval *beval, char *text, POINT pt)
{ {
TOOLINFOW *pti; TOOLINFOW *pti;
int ToolInfoSize; int ToolInfoSize;
@ -8480,77 +8291,6 @@ make_tooltipw(BalloonEval *beval, char *text, POINT pt)
vim_free(pti); vim_free(pti);
} }
static void
make_tooltip(BalloonEval *beval, char *text, POINT pt)
{
TOOLINFO *pti;
int ToolInfoSize;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
make_tooltipw(beval, text, pt);
return;
}
if (multiline_balloon_available() == TRUE)
ToolInfoSize = sizeof(TOOLINFO_NEW);
else
ToolInfoSize = sizeof(TOOLINFO);
pti = (TOOLINFO *)alloc(ToolInfoSize);
if (pti == NULL)
return;
beval->balloon = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS,
NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
beval->target, NULL, s_hinst, NULL);
SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
pti->cbSize = ToolInfoSize;
pti->uFlags = TTF_SUBCLASS;
pti->hwnd = beval->target;
pti->hinst = 0; /* Don't use string resources */
pti->uId = ID_BEVAL_TOOLTIP;
if (multiline_balloon_available() == TRUE)
{
RECT rect;
TOOLINFO_NEW *ptin = (TOOLINFO_NEW *)pti;
pti->lpszText = LPSTR_TEXTCALLBACK;
beval->tofree = vim_strsave((char_u*)text);
ptin->lParam = (LPARAM)beval->tofree;
if (GetClientRect(s_textArea, &rect)) /* switch multiline tooltips on */
SendMessage(beval->balloon, TTM_SETMAXTIPWIDTH, 0,
(LPARAM)rect.right);
}
else
pti->lpszText = text; /* do this old way */
/* Limit ballooneval bounding rect to CursorPos neighbourhood */
pti->rect.left = pt.x - 3;
pti->rect.top = pt.y - 3;
pti->rect.right = pt.x + 3;
pti->rect.bottom = pt.y + 3;
SendMessage(beval->balloon, TTM_ADDTOOL, 0, (LPARAM)pti);
/* Make tooltip appear sooner */
SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_INITIAL, 10);
/* I've performed some tests and it seems the longest possible life time
* of tooltip is 30 seconds */
SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_AUTOPOP, 30000);
/*
* HACK: force tooltip to appear, because it'll not appear until
* first mouse move. D*mn M$
* Amazingly moving (2, 2) and then (-1, -1) the mouse doesn't move.
*/
mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0);
mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0);
vim_free(pti);
}
static void static void
delete_tooltip(BalloonEval *beval) delete_tooltip(BalloonEval *beval)
{ {

View File

@ -5670,11 +5670,10 @@ dos_expandpath(
int matches; int matches;
int len; int len;
int starstar = FALSE; int starstar = FALSE;
static int stardepth = 0; /* depth for "**" expansion */ static int stardepth = 0; // depth for "**" expansion
WIN32_FIND_DATA fb; HANDLE hFind = INVALID_HANDLE_VALUE;
HANDLE hFind = (HANDLE)0;
WIN32_FIND_DATAW wfb; WIN32_FIND_DATAW wfb;
WCHAR *wn = NULL; /* UCS-2 name, NULL when not used. */ WCHAR *wn = NULL; // UCS-2 name, NULL when not used.
char_u *matchname; char_u *matchname;
int ok; int ok;
@ -5783,33 +5782,16 @@ dos_expandpath(
/* Scan all files in the directory with "dir/ *.*" */ /* Scan all files in the directory with "dir/ *.*" */
STRCPY(s, "*.*"); STRCPY(s, "*.*");
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wn = enc_to_utf16(buf, NULL);
{ if (wn != NULL)
/* The active codepage differs from 'encoding'. Attempt using the hFind = FindFirstFileW(wn, &wfb);
* wide function. If it fails because it is not implemented fall back
* to the non-wide version (for Windows 98) */
wn = enc_to_utf16(buf, NULL);
if (wn != NULL)
{
hFind = FindFirstFileW(wn, &wfb);
if (hFind == INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
VIM_CLEAR(wn);
}
}
if (wn == NULL)
hFind = FindFirstFile((LPCSTR)buf, &fb);
ok = (hFind != INVALID_HANDLE_VALUE); ok = (hFind != INVALID_HANDLE_VALUE);
while (ok) while (ok)
{ {
if (wn != NULL) p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here
p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */ // Ignore entries starting with a dot, unless when asked for. Accept
else // all entries found with "matchname".
p = (char_u *)fb.cFileName;
/* Ignore entries starting with a dot, unless when asked for. Accept
* all entries found with "matchname". */
if ((p[0] != '.' || starts_with_dot if ((p[0] != '.' || starts_with_dot
|| ((flags & EW_DODOT) || ((flags & EW_DODOT)
&& p[1] != NUL && (p[1] != '.' || p[2] != NUL))) && p[1] != NUL && (p[1] != '.' || p[2] != NUL)))
@ -5851,13 +5833,8 @@ dos_expandpath(
} }
} }
if (wn != NULL) vim_free(p);
{ ok = FindNextFileW(hFind, &wfb);
vim_free(p);
ok = FindNextFileW(hFind, &wfb);
}
else
ok = FindNextFile(hFind, &fb);
/* If no more matches and no match was used, try expanding the name /* If no more matches and no match was used, try expanding the name
* itself. Finds the long name of a short filename. */ * itself. Finds the long name of a short filename. */
@ -5865,15 +5842,12 @@ dos_expandpath(
{ {
STRCPY(s, matchname); STRCPY(s, matchname);
FindClose(hFind); FindClose(hFind);
vim_free(wn);
wn = enc_to_utf16(buf, NULL);
if (wn != NULL) if (wn != NULL)
{ hFind = FindFirstFileW(wn, &wfb);
vim_free(wn); else
wn = enc_to_utf16(buf, NULL); hFind = INVALID_HANDLE_VALUE;
if (wn != NULL)
hFind = FindFirstFileW(wn, &wfb);
}
if (wn == NULL)
hFind = FindFirstFile((LPCSTR)buf, &fb);
ok = (hFind != INVALID_HANDLE_VALUE); ok = (hFind != INVALID_HANDLE_VALUE);
VIM_CLEAR(matchname); VIM_CLEAR(matchname);
} }

View File

@ -105,7 +105,7 @@ typedef int LRESULT;
typedef int MOUSE_EVENT_RECORD; typedef int MOUSE_EVENT_RECORD;
typedef int NEWTEXTMETRICW; typedef int NEWTEXTMETRICW;
typedef int PACL; typedef int PACL;
typedef int PRINTDLG; typedef int PRINTDLGW;
typedef int PSECURITY_DESCRIPTOR; typedef int PSECURITY_DESCRIPTOR;
typedef int PSID; typedef int PSID;
typedef int SECURITY_INFORMATION; typedef int SECURITY_INFORMATION;
@ -282,19 +282,14 @@ mch_settitle(
# else # else
if (title != NULL) if (title != NULL)
{ {
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) WCHAR *wp = enc_to_utf16(title, NULL);
{
/* Convert the title from 'encoding' to the active codepage. */
WCHAR *wp = enc_to_utf16(title, NULL);
if (wp != NULL) if (wp == NULL)
{ return;
SetConsoleTitleW(wp);
vim_free(wp); SetConsoleTitleW(wp);
return; vim_free(wp);
} return;
}
SetConsoleTitle((LPCSTR)title);
} }
# endif # endif
} }
@ -359,40 +354,22 @@ mch_FullName(
else else
#endif #endif
{ {
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) WCHAR *wname;
{ WCHAR wbuf[MAX_PATH];
WCHAR *wname; char_u *cname = NULL;
WCHAR wbuf[MAX_PATH];
char_u *cname = NULL;
/* Use the wide function: wname = enc_to_utf16(fname, NULL);
* - convert the fname from 'encoding' to UCS2. if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH) != NULL)
* - invoke _wfullpath()
* - convert the result from UCS2 to 'encoding'.
*/
wname = enc_to_utf16(fname, NULL);
if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH) != NULL)
{
cname = utf16_to_enc((short_u *)wbuf, NULL);
if (cname != NULL)
{
vim_strncpy(buf, cname, len - 1);
nResult = OK;
}
}
vim_free(wname);
vim_free(cname);
}
if (nResult == FAIL) /* fall back to non-wide function */
{ {
if (_fullpath((char *)buf, (const char *)fname, len - 1) == NULL) cname = utf16_to_enc((short_u *)wbuf, NULL);
if (cname != NULL)
{ {
/* failed, use relative path name */ vim_strncpy(buf, cname, len - 1);
vim_strncpy(buf, fname, len - 1);
}
else
nResult = OK; nResult = OK;
}
} }
vim_free(wname);
vim_free(cname);
} }
#ifdef USE_FNAME_CASE #ifdef USE_FNAME_CASE
@ -479,57 +456,6 @@ slash_adjust(char_u *p)
# define OPEN_OH_ARGTYPE long # define OPEN_OH_ARGTYPE long
#endif #endif
static int
stat_symlink_aware(const char *name, stat_T *stp)
{
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__)
/* Work around for VC12 or earlier (and MinGW). stat() can't handle
* symlinks properly.
* VC9 or earlier: stat() doesn't support a symlink at all. It retrieves
* status of a symlink itself.
* VC10: stat() supports a symlink to a normal file, but it doesn't support
* a symlink to a directory (always returns an error).
* VC11 and VC12: stat() doesn't return an error for a symlink to a
* directory, but it doesn't set S_IFDIR flag.
* MinGW: Same as VC9. */
WIN32_FIND_DATA findData;
HANDLE hFind, h;
DWORD attr = 0;
BOOL is_symlink = FALSE;
hFind = FindFirstFile(name, &findData);
if (hFind != INVALID_HANDLE_VALUE)
{
attr = findData.dwFileAttributes;
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT)
&& (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK))
is_symlink = TRUE;
FindClose(hFind);
}
if (is_symlink)
{
h = CreateFile(name, FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING,
(attr & FILE_ATTRIBUTE_DIRECTORY)
? FILE_FLAG_BACKUP_SEMANTICS : 0,
NULL);
if (h != INVALID_HANDLE_VALUE)
{
int fd, n;
fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY);
n = _fstat(fd, (struct _stat *)stp);
if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY))
stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR;
_close(fd);
return n;
}
}
#endif
return stat(name, stp);
}
static int static int
wstat_symlink_aware(const WCHAR *name, stat_T *stp) wstat_symlink_aware(const WCHAR *name, stat_T *stp)
{ {
@ -593,6 +519,8 @@ vim_stat(const char *name, stat_T *stp)
* UTF-8. */ * UTF-8. */
char_u buf[_MAX_PATH * 3 + 1]; char_u buf[_MAX_PATH * 3 + 1];
char_u *p; char_u *p;
WCHAR *wp;
int n;
vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1); vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1);
p = buf + STRLEN(buf); p = buf + STRLEN(buf);
@ -614,19 +542,14 @@ vim_stat(const char *name, stat_T *stp)
STRCAT(buf, "\\"); STRCAT(buf, "\\");
} }
} }
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
WCHAR *wp = enc_to_utf16(buf, NULL);
int n;
if (wp != NULL) wp = enc_to_utf16(buf, NULL);
{ if (wp == NULL)
n = wstat_symlink_aware(wp, stp); return -1;
vim_free(wp);
return n; n = wstat_symlink_aware(wp, stp);
} vim_free(wp);
} return n;
return stat_symlink_aware((char *)buf, stp);
} }
#if defined(FEAT_GUI_MSWIN) || defined(PROTO) #if defined(FEAT_GUI_MSWIN) || defined(PROTO)
@ -758,6 +681,9 @@ mch_has_wildcard(char_u *p)
int int
mch_chdir(char *path) mch_chdir(char *path)
{ {
WCHAR *p;
int n;
if (path[0] == NUL) /* just checking... */ if (path[0] == NUL) /* just checking... */
return -1; return -1;
@ -779,20 +705,13 @@ mch_chdir(char *path)
if (*path == NUL) /* drive name only */ if (*path == NUL) /* drive name only */
return 0; return 0;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) p = enc_to_utf16((char_u *)path, NULL);
{ if (p == NULL)
WCHAR *p = enc_to_utf16((char_u *)path, NULL); return -1;
int n;
if (p != NULL) n = _wchdir(p);
{ vim_free(p);
n = _wchdir(p); return n;
vim_free(p);
return n;
}
}
return chdir(path); /* let the normal chdir() do the rest */
} }
@ -1097,7 +1016,7 @@ mch_set_winpos(int x, int y)
*/ */
static HFONT prt_font_handles[2][2][2]; static HFONT prt_font_handles[2][2][2];
static PRINTDLG prt_dlg; static PRINTDLGW prt_dlg;
static const int boldface[2] = {FW_REGULAR, FW_BOLD}; static const int boldface[2] = {FW_REGULAR, FW_BOLD};
static TEXTMETRIC prt_tm; static TEXTMETRIC prt_tm;
static int prt_line_height; static int prt_line_height;
@ -1119,18 +1038,16 @@ static char_u *prt_name = NULL;
static BOOL static BOOL
vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s) vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s)
{ {
WCHAR *wp = NULL; WCHAR *wp;
BOOL ret; BOOL ret;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wp = enc_to_utf16(s, NULL);
wp = enc_to_utf16(s, NULL); if (wp == NULL)
if (wp != NULL) return FALSE;
{
ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp); ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp);
vim_free(wp); vim_free(wp);
return ret; return ret;
}
return SetDlgItemText(hDlg, nIDDlgItem, (LPCSTR)s);
} }
/* /*
@ -1248,7 +1165,7 @@ PrintHookProc(
{ {
HWND hwndOwner; HWND hwndOwner;
RECT rc, rcDlg, rcOwner; RECT rc, rcDlg, rcOwner;
PRINTDLG *pPD; PRINTDLGW *pPD;
if (uiMsg == WM_INITDIALOG) if (uiMsg == WM_INITDIALOG)
{ {
@ -1280,7 +1197,7 @@ PrintHookProc(
SWP_NOSIZE); SWP_NOSIZE);
/* tackle the printdlg copiesctrl problem */ /* tackle the printdlg copiesctrl problem */
pPD = (PRINTDLG *)lParam; pPD = (PRINTDLGW *)lParam;
pPD->nCopies = (WORD)pPD->lCustData; pPD->nCopies = (WORD)pPD->lCustData;
SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE );
/* Bring the window to top */ /* Bring the window to top */
@ -1423,13 +1340,13 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
int pifBold; int pifBold;
int pifUnderline; int pifUnderline;
DEVMODE *mem; DEVMODEW *mem;
DEVNAMES *devname; DEVNAMES *devname;
int i; int i;
bUserAbort = &(psettings->user_abort); bUserAbort = &(psettings->user_abort);
vim_memset(&prt_dlg, 0, sizeof(PRINTDLG)); vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW));
prt_dlg.lStructSize = sizeof(PRINTDLG); prt_dlg.lStructSize = sizeof(PRINTDLGW);
#ifndef FEAT_GUI #ifndef FEAT_GUI
GetConsoleHwnd(); /* get value of s_hwnd */ GetConsoleHwnd(); /* get value of s_hwnd */
#endif #endif
@ -1470,11 +1387,11 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
else else
{ {
prt_dlg.Flags |= PD_RETURNDEFAULT; prt_dlg.Flags |= PD_RETURNDEFAULT;
if (PrintDlg(&prt_dlg) == 0) if (PrintDlgW(&prt_dlg) == 0)
goto init_fail_dlg; goto init_fail_dlg;
} }
} }
else if (PrintDlg(&prt_dlg) == 0) else if (PrintDlgW(&prt_dlg) == 0)
goto init_fail_dlg; goto init_fail_dlg;
else else
{ {
@ -1510,7 +1427,7 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
* passed back correctly. It must be retrieved from the * passed back correctly. It must be retrieved from the
* hDevMode struct. * hDevMode struct.
*/ */
mem = (DEVMODE *)GlobalLock(prt_dlg.hDevMode); mem = (DEVMODEW *)GlobalLock(prt_dlg.hDevMode);
if (mem != NULL) if (mem != NULL)
{ {
if (mem->dmCopies != 1) if (mem->dmCopies != 1)
@ -1525,34 +1442,20 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
devname = (DEVNAMES *)GlobalLock(prt_dlg.hDevNames); devname = (DEVNAMES *)GlobalLock(prt_dlg.hDevNames);
if (devname != 0) if (devname != 0)
{ {
char_u *printer_name = (char_u *)devname + devname->wDeviceOffset; WCHAR *wprinter_name = (WCHAR *)devname + devname->wDeviceOffset;
char_u *port_name = (char_u *)devname +devname->wOutputOffset; WCHAR *wport_name = (WCHAR *)devname + devname->wOutputOffset;
char_u *text = (char_u *)_("to %s on %s"); char_u *text = (char_u *)_("to %s on %s");
char_u *printer_name_orig = printer_name; char_u *printer_name = utf16_to_enc(wprinter_name, NULL);
char_u *port_name_orig = port_name; char_u *port_name = utf16_to_enc(wport_name, NULL);
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) if (printer_name != NULL && port_name != NULL)
{ prt_name = alloc((unsigned)(STRLEN(printer_name)
char_u *to_free = NULL; + STRLEN(port_name) + STRLEN(text)));
int maxlen;
acp_to_enc(printer_name, (int)STRLEN(printer_name), &to_free,
&maxlen);
if (to_free != NULL)
printer_name = to_free;
acp_to_enc(port_name, (int)STRLEN(port_name), &to_free, &maxlen);
if (to_free != NULL)
port_name = to_free;
}
prt_name = alloc((unsigned)(STRLEN(printer_name) + STRLEN(port_name)
+ STRLEN(text)));
if (prt_name != NULL) if (prt_name != NULL)
wsprintf((char *)prt_name, (const char *)text, wsprintf((char *)prt_name, (const char *)text,
printer_name, port_name); printer_name, port_name);
if (printer_name != printer_name_orig) vim_free(printer_name);
vim_free(printer_name); vim_free(port_name);
if (port_name != port_name_orig)
vim_free(port_name);
} }
GlobalUnlock(prt_dlg.hDevNames); GlobalUnlock(prt_dlg.hDevNames);
@ -1639,9 +1542,9 @@ init_fail_dlg:
int int
mch_print_begin(prt_settings_T *psettings) mch_print_begin(prt_settings_T *psettings)
{ {
int ret; int ret = 0;
char szBuffer[300]; char szBuffer[300];
WCHAR *wp = NULL; WCHAR *wp;
hDlgPrint = CreateDialog(GetModuleHandle(NULL), TEXT("PrintDlgBox"), hDlgPrint = CreateDialog(GetModuleHandle(NULL), TEXT("PrintDlgBox"),
prt_dlg.hwndOwner, PrintDlgProc); prt_dlg.hwndOwner, PrintDlgProc);
@ -1649,8 +1552,7 @@ mch_print_begin(prt_settings_T *psettings)
wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname)); wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (char_u *)szBuffer); vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (char_u *)szBuffer);
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wp = enc_to_utf16(psettings->jobname, NULL);
wp = enc_to_utf16(psettings->jobname, NULL);
if (wp != NULL) if (wp != NULL)
{ {
DOCINFOW di; DOCINFOW di;
@ -1661,15 +1563,6 @@ mch_print_begin(prt_settings_T *psettings)
ret = StartDocW(prt_dlg.hDC, &di); ret = StartDocW(prt_dlg.hDC, &di);
vim_free(wp); vim_free(wp);
} }
else
{
DOCINFO di;
vim_memset(&di, 0, sizeof(di));
di.cbSize = sizeof(di);
di.lpszDocName = (LPCSTR)psettings->jobname;
ret = StartDoc(prt_dlg.hDC, &di);
}
#ifdef FEAT_GUI #ifdef FEAT_GUI
/* Give focus back to main window (when using MDI). */ /* Give focus back to main window (when using MDI). */
@ -1725,50 +1618,32 @@ mch_print_start_line(int margin, int page_line)
mch_print_text_out(char_u *p, int len) mch_print_text_out(char_u *p, int len)
{ {
SIZE sz; SIZE sz;
WCHAR *wp = NULL; WCHAR *wp;
int wlen = len; int wlen = len;
int ret = FALSE;
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) wp = enc_to_utf16(p, &wlen);
wp = enc_to_utf16(p, &wlen); if (wp == NULL)
if (wp != NULL) return FALSE;
{
int ret = FALSE;
TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin, TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin,
prt_pos_y + prt_top_margin, wp, wlen); prt_pos_y + prt_top_margin, wp, wlen);
GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz);
vim_free(wp); 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;
}
TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin,
prt_pos_y + prt_top_margin,
(LPCSTR)p, len);
#ifndef FEAT_PROPORTIONAL_FONTS
prt_pos_x += len * prt_tm.tmAveCharWidth;
return (prt_pos_x + prt_left_margin + prt_tm.tmAveCharWidth
+ prt_tm.tmOverhang > prt_right_margin);
#else
GetTextExtentPoint32(prt_dlg.hDC, (LPCSTR)p, len, &sz);
prt_pos_x += (sz.cx - prt_tm.tmOverhang); prt_pos_x += (sz.cx - prt_tm.tmOverhang);
/* This is wrong when printing spaces for a TAB. */ /* This is wrong when printing spaces for a TAB. */
if (p[len] == NUL) if (p[len] != NUL)
return FALSE; {
GetTextExtentPoint32(prt_dlg.hDC, p + len, 1, &sz); wlen = MB_PTR2LEN(p + len);
return (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin); wp = enc_to_utf16(p + len, &wlen);
#endif 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;
} }
void void
@ -1863,6 +1738,7 @@ resolve_reparse_point(char_u *fname)
{ {
HANDLE h = INVALID_HANDLE_VALUE; HANDLE h = INVALID_HANDLE_VALUE;
DWORD size; DWORD size;
WCHAR *p;
char_u *rfname = NULL; char_u *rfname = NULL;
FILE_NAME_INFO_ *nameinfo = NULL; FILE_NAME_INFO_ *nameinfo = NULL;
WCHAR buff[MAX_PATH], *volnames = NULL; WCHAR buff[MAX_PATH], *volnames = NULL;
@ -1887,33 +1763,19 @@ resolve_reparse_point(char_u *fname)
return NULL; return NULL;
} }
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) p = enc_to_utf16(fname, NULL);
if (p == NULL)
goto fail;
if ((GetFileAttributesW(p) & FILE_ATTRIBUTE_REPARSE_POINT) == 0)
{ {
WCHAR *p;
p = enc_to_utf16(fname, NULL);
if (p == NULL)
goto fail;
if ((GetFileAttributesW(p) & FILE_ATTRIBUTE_REPARSE_POINT) == 0)
{
vim_free(p);
goto fail;
}
h = CreateFileW(p, 0, 0, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);
vim_free(p); vim_free(p);
goto fail;
} }
else
{
if ((GetFileAttributes((char*) fname) &
FILE_ATTRIBUTE_REPARSE_POINT) == 0)
goto fail;
h = CreateFile((char*) fname, 0, 0, NULL, OPEN_EXISTING, h = CreateFileW(p, 0, 0, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL); FILE_FLAG_BACKUP_SEMANTICS, NULL);
} vim_free(p);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
goto fail; goto fail;
@ -1988,8 +1850,6 @@ resolve_shortcut(char_u *fname)
IShellLink *psl = NULL; IShellLink *psl = NULL;
IPersistFile *ppf = NULL; IPersistFile *ppf = NULL;
OLECHAR wsz[MAX_PATH]; OLECHAR wsz[MAX_PATH];
WIN32_FIND_DATA ffd; // we get those free of charge
CHAR buf[MAX_PATH]; // could have simply reused 'wsz'...
char_u *rfname = NULL; char_u *rfname = NULL;
int len; int len;
IShellLinkW *pslw = NULL; IShellLinkW *pslw = NULL;
@ -2005,80 +1865,43 @@ resolve_shortcut(char_u *fname)
CoInitialize(NULL); CoInitialize(NULL);
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
// create a link manager object and request its interface
hr = CoCreateInstance(
&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
&IID_IShellLinkW, (void**)&pslw);
if (hr == S_OK)
{
WCHAR *p = enc_to_utf16(fname, NULL);
if (p != NULL)
{
// Get a pointer to the IPersistFile interface.
hr = pslw->lpVtbl->QueryInterface(
pslw, &IID_IPersistFile, (void**)&ppf);
if (hr != S_OK)
goto shortcut_errorw;
// "load" the name and resolve the link
hr = ppf->lpVtbl->Load(ppf, p, STGM_READ);
if (hr != S_OK)
goto shortcut_errorw;
# if 0 // This makes Vim wait a long time if the target does not exist.
hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI);
if (hr != S_OK)
goto shortcut_errorw;
# endif
// Get the path to the link target.
ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
if (hr == S_OK && wsz[0] != NUL)
rfname = utf16_to_enc(wsz, NULL);
shortcut_errorw:
vim_free(p);
goto shortcut_end;
}
}
goto shortcut_end;
}
// create a link manager object and request its interface // create a link manager object and request its interface
hr = CoCreateInstance( hr = CoCreateInstance(
&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
&IID_IShellLink, (void**)&psl); &IID_IShellLinkW, (void**)&pslw);
if (hr != S_OK) if (hr == S_OK)
goto shortcut_end; {
WCHAR *p = enc_to_utf16(fname, NULL);
// Get a pointer to the IPersistFile interface. if (p != NULL)
hr = psl->lpVtbl->QueryInterface( {
psl, &IID_IPersistFile, (void**)&ppf); // Get a pointer to the IPersistFile interface.
if (hr != S_OK) hr = pslw->lpVtbl->QueryInterface(
goto shortcut_end; pslw, &IID_IPersistFile, (void**)&ppf);
if (hr != S_OK)
goto shortcut_errorw;
// full path string must be in Unicode. // "load" the name and resolve the link
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)fname, -1, wsz, MAX_PATH); hr = ppf->lpVtbl->Load(ppf, p, STGM_READ);
if (hr != S_OK)
// "load" the name and resolve the link goto shortcut_errorw;
hr = ppf->lpVtbl->Load(ppf, wsz, STGM_READ); # if 0 // This makes Vim wait a long time if the target does not exist.
if (hr != S_OK) hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI);
goto shortcut_end; if (hr != S_OK)
# if 0 // This makes Vim wait a long time if the target doesn't exist. goto shortcut_errorw;
hr = psl->lpVtbl->Resolve(psl, NULL, SLR_NO_UI);
if (hr != S_OK)
goto shortcut_end;
# endif # endif
// Get the path to the link target. // Get the path to the link target.
ZeroMemory(buf, MAX_PATH); ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
hr = psl->lpVtbl->GetPath(psl, buf, MAX_PATH, &ffd, 0); hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
if (hr == S_OK && buf[0] != NUL) if (hr == S_OK && wsz[0] != NUL)
rfname = vim_strsave((char_u *)buf); rfname = utf16_to_enc(wsz, NULL);
shortcut_errorw:
vim_free(p);
}
}
shortcut_end:
// Release all interface pointers (both belong to the same object) // Release all interface pointers (both belong to the same object)
if (ppf != NULL) if (ppf != NULL)
ppf->lpVtbl->Release(ppf); ppf->lpVtbl->Release(ppf);

File diff suppressed because it is too large Load Diff

View File

@ -771,6 +771,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1103,
/**/ /**/
1102, 1102,
/**/ /**/

View File

@ -536,7 +536,7 @@ extern char *(*dyn_libintl_ngettext)(const char *msgid, const char *msgid_plural
extern char *(*dyn_libintl_bindtextdomain)(const char *domainname, const char *dirname); extern char *(*dyn_libintl_bindtextdomain)(const char *domainname, const char *dirname);
extern char *(*dyn_libintl_bind_textdomain_codeset)(const char *domainname, const char *codeset); extern char *(*dyn_libintl_bind_textdomain_codeset)(const char *domainname, const char *codeset);
extern char *(*dyn_libintl_textdomain)(const char *domainname); extern char *(*dyn_libintl_textdomain)(const char *domainname);
extern int (*dyn_libintl_putenv)(const char *envstring); extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#endif #endif
@ -559,7 +559,6 @@ extern int (*dyn_libintl_putenv)(const char *envstring);
# define HAVE_BIND_TEXTDOMAIN_CODESET 1 # define HAVE_BIND_TEXTDOMAIN_CODESET 1
# endif # endif
# define textdomain(domain) (*dyn_libintl_textdomain)(domain) # define textdomain(domain) (*dyn_libintl_textdomain)(domain)
# define libintl_putenv(envstring) (*dyn_libintl_putenv)(envstring)
# define libintl_wputenv(envstring) (*dyn_libintl_wputenv)(envstring) # define libintl_wputenv(envstring) (*dyn_libintl_wputenv)(envstring)
# else # else
# include <libintl.h> # include <libintl.h>