Mercurial > vim
annotate src/os_mswin.c @ 16451:7ae2396cef62 v8.1.1230
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
commit https://github.com/vim/vim/commit/afde13b62b8fa25dac4635d5caee8d088b937ee0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 28 19:46:49 2019 +0200
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Problem: A lot of code is shared between vim.exe and gvim.exe.
Solution: Optionally put the shared code in vim.dll. (Ken Takata,
closes #4287)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Apr 2019 20:00:10 +0200 |
parents | 9d20e26dc13c |
children | 7e733046db1d |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * os_mswin.c | |
12 * | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8090
diff
changeset
|
13 * Routines for Win32. |
7 | 14 */ |
15 | |
16 #include "vim.h" | |
17 | |
18 #include <sys/types.h> | |
19 #include <signal.h> | |
20 #include <limits.h> | |
3927 | 21 #ifndef PROTO |
22 # include <process.h> | |
23 #endif | |
7 | 24 |
25 #undef chdir | |
26 #ifdef __GNUC__ | |
27 # ifndef __MINGW32__ | |
28 # include <dirent.h> | |
29 # endif | |
30 #else | |
31 # include <direct.h> | |
32 #endif | |
33 | |
3927 | 34 #ifndef PROTO |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
35 # if defined(FEAT_TITLE) && !defined(FEAT_GUI_MSWIN) |
3927 | 36 # include <shellapi.h> |
37 # endif | |
38 | |
39 # if defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT) | |
40 # include <dlgs.h> | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
41 # include <winspool.h> |
3927 | 42 # include <commdlg.h> |
10440
f54e4c691de4
commit https://github.com/vim/vim/commit/b04a98f6c3cca14bf055934b0a793f4dc376858b
Christian Brabandt <cb@256bit.org>
parents:
10355
diff
changeset
|
43 # endif |
7 | 44 |
3927 | 45 #endif /* PROTO */ |
7 | 46 |
47 #ifdef __MINGW32__ | |
48 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | |
49 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | |
50 # endif | |
51 # ifndef RIGHTMOST_BUTTON_PRESSED | |
52 # define RIGHTMOST_BUTTON_PRESSED 0x0002 | |
53 # endif | |
54 # ifndef FROM_LEFT_2ND_BUTTON_PRESSED | |
55 # define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 | |
56 # endif | |
57 # ifndef FROM_LEFT_3RD_BUTTON_PRESSED | |
58 # define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 | |
59 # endif | |
60 # ifndef FROM_LEFT_4TH_BUTTON_PRESSED | |
61 # define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 | |
62 # endif | |
63 | |
64 /* | |
65 * EventFlags | |
66 */ | |
67 # ifndef MOUSE_MOVED | |
68 # define MOUSE_MOVED 0x0001 | |
69 # endif | |
70 # ifndef DOUBLE_CLICK | |
71 # define DOUBLE_CLICK 0x0002 | |
72 # endif | |
73 #endif | |
74 | |
75 /* | |
76 * When generating prototypes for Win32 on Unix, these lines make the syntax | |
77 * errors disappear. They do not need to be correct. | |
78 */ | |
79 #ifdef PROTO | |
80 #define WINAPI | |
81 #define WINBASEAPI | |
82 typedef int BOOL; | |
83 typedef int CALLBACK; | |
84 typedef int COLORREF; | |
85 typedef int CONSOLE_CURSOR_INFO; | |
86 typedef int COORD; | |
87 typedef int DWORD; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
88 typedef int ENUMLOGFONTW; |
7 | 89 typedef int HANDLE; |
90 typedef int HDC; | |
91 typedef int HFONT; | |
92 typedef int HICON; | |
93 typedef int HWND; | |
94 typedef int INPUT_RECORD; | |
95 typedef int KEY_EVENT_RECORD; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
96 typedef int LOGFONTW; |
7 | 97 typedef int LPARAM; |
98 typedef int LPBOOL; | |
99 typedef int LPCSTR; | |
100 typedef int LPCWSTR; | |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
101 typedef int LPDWORD; |
7 | 102 typedef int LPSTR; |
103 typedef int LPTSTR; | |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
104 typedef int LPVOID; |
7 | 105 typedef int LPWSTR; |
106 typedef int LRESULT; | |
107 typedef int MOUSE_EVENT_RECORD; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
108 typedef int NEWTEXTMETRICW; |
7 | 109 typedef int PACL; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
110 typedef int PRINTDLGW; |
7 | 111 typedef int PSECURITY_DESCRIPTOR; |
112 typedef int PSID; | |
113 typedef int SECURITY_INFORMATION; | |
114 typedef int SHORT; | |
115 typedef int SMALL_RECT; | |
116 typedef int TEXTMETRIC; | |
117 typedef int UINT; | |
118 typedef int WCHAR; | |
15195
16b2f2db6f28
patch 8.1.0607: proto files are not in sync with the source code
Bram Moolenaar <Bram@vim.org>
parents:
14907
diff
changeset
|
119 typedef int WNDENUMPROC; |
7 | 120 typedef int WORD; |
121 typedef int WPARAM; | |
122 typedef void VOID; | |
123 #endif | |
124 | |
125 /* Record all output and all keyboard & mouse input */ | |
126 /* #define MCH_WRITE_DUMP */ | |
127 | |
128 #ifdef MCH_WRITE_DUMP | |
129 FILE* fdDump = NULL; | |
130 #endif | |
131 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
132 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 133 extern char g_szOrigTitle[]; |
134 #endif | |
135 | |
136 #ifdef FEAT_GUI | |
137 extern HWND s_hwnd; | |
138 #else | |
139 static HWND s_hwnd = 0; /* console window handle, set by GetConsoleHwnd() */ | |
140 #endif | |
141 | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
142 #ifdef FEAT_JOB_CHANNEL |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
143 int WSInitialized = FALSE; /* WinSock is initialized */ |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
144 #endif |
7 | 145 |
146 /* Don't generate prototypes here, because some systems do have these | |
147 * functions. */ | |
148 #if defined(__GNUC__) && !defined(PROTO) | |
149 # ifndef __MINGW32__ | |
150 int _stricoll(char *a, char *b) | |
151 { | |
152 // the ANSI-ish correct way is to use strxfrm(): | |
153 char a_buff[512], b_buff[512]; // file names, so this is enough on Win32 | |
154 strxfrm(a_buff, a, 512); | |
155 strxfrm(b_buff, b, 512); | |
156 return strcoll(a_buff, b_buff); | |
157 } | |
158 | |
159 char * _fullpath(char *buf, char *fname, int len) | |
160 { | |
161 LPTSTR toss; | |
162 | |
163 return (char *)GetFullPathName(fname, len, buf, &toss); | |
164 } | |
165 # endif | |
166 | |
4238 | 167 # if !defined(__MINGW32__) || (__GNUC__ < 4) |
7 | 168 int _chdrive(int drive) |
169 { | |
170 char temp [3] = "-:"; | |
171 temp[0] = drive + 'A' - 1; | |
172 return !SetCurrentDirectory(temp); | |
173 } | |
4238 | 174 # endif |
7 | 175 #else |
176 # ifdef __BORLANDC__ | |
177 /* being a more ANSI compliant compiler, BorlandC doesn't define _stricoll: | |
178 * but it does in BC 5.02! */ | |
179 # if __BORLANDC__ < 0x502 | |
180 int _stricoll(char *a, char *b) | |
181 { | |
182 # if 1 | |
183 // this is fast but not correct: | |
184 return stricmp(a, b); | |
185 # else | |
186 // the ANSI-ish correct way is to use strxfrm(): | |
187 char a_buff[512], b_buff[512]; // file names, so this is enough on Win32 | |
188 strxfrm(a_buff, a, 512); | |
189 strxfrm(b_buff, b, 512); | |
190 return strcoll(a_buff, b_buff); | |
191 # endif | |
192 } | |
193 # endif | |
194 # endif | |
195 #endif | |
196 | |
197 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
198 #ifndef PROTO |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
199 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
200 * Save the instance handle of the exe/dll. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
201 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
202 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
203 SaveInst(HINSTANCE hInst) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
204 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
205 g_hinst = hInst; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
206 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
207 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
208 |
7 | 209 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) |
210 /* | |
211 * GUI version of mch_exit(). | |
212 * Shut down and exit with status `r' | |
213 * Careful: mch_exit() may be called before mch_init()! | |
214 */ | |
215 void | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
216 mch_exit_g(int r) |
7 | 217 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
218 exiting = TRUE; |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10783
diff
changeset
|
219 |
7 | 220 display_errors(); |
221 | |
222 ml_close_all(TRUE); /* remove all memfiles */ | |
223 | |
224 # ifdef FEAT_OLE | |
225 UninitOLE(); | |
226 # endif | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
227 # ifdef FEAT_JOB_CHANNEL |
7 | 228 if (WSInitialized) |
229 { | |
230 WSInitialized = FALSE; | |
231 WSACleanup(); | |
232 } | |
233 # endif | |
234 #ifdef DYNAMIC_GETTEXT | |
235 dyn_libintl_end(); | |
236 #endif | |
237 | |
238 if (gui.in_use) | |
239 gui_exit(r); | |
1071 | 240 |
241 #ifdef EXITFREE | |
242 free_all_mem(); | |
243 #endif | |
244 | |
7 | 245 exit(r); |
246 } | |
247 | |
248 #endif /* FEAT_GUI_MSWIN */ | |
249 | |
250 | |
251 /* | |
252 * Init the tables for toupper() and tolower(). | |
253 */ | |
254 void | |
255 mch_early_init(void) | |
256 { | |
257 int i; | |
258 | |
259 PlatformId(); | |
260 | |
261 /* Init the tables for toupper() and tolower() */ | |
262 for (i = 0; i < 256; ++i) | |
263 toupper_tab[i] = tolower_tab[i] = i; | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
264 CharUpperBuff((LPSTR)toupper_tab, 256); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
265 CharLowerBuff((LPSTR)tolower_tab, 256); |
7 | 266 } |
267 | |
268 | |
269 /* | |
270 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
271 */ | |
272 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
273 mch_input_isatty(void) |
7 | 274 { |
275 #ifdef FEAT_GUI_MSWIN | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
276 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
277 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
278 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
279 return TRUE; /* GUI always has a tty */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
280 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
281 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 282 if (isatty(read_cmd_fd)) |
283 return TRUE; | |
284 return FALSE; | |
285 #endif | |
286 } | |
287 | |
288 #ifdef FEAT_TITLE | |
289 /* | |
290 * mch_settitle(): set titlebar of our window | |
291 */ | |
292 void | |
293 mch_settitle( | |
294 char_u *title, | |
295 char_u *icon) | |
296 { | |
297 # ifdef FEAT_GUI_MSWIN | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
298 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
299 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
300 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
301 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
302 gui_mch_settitle(title, icon); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
303 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
304 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
305 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
306 # if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 307 if (title != NULL) |
26 | 308 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
309 WCHAR *wp = enc_to_utf16(title, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
310 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
311 if (wp == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
312 return; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
313 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
314 SetConsoleTitleW(wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
315 vim_free(wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
316 return; |
26 | 317 } |
7 | 318 # endif |
319 } | |
320 | |
321 | |
322 /* | |
323 * Restore the window/icon title. | |
324 * which is one of: | |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
13929
diff
changeset
|
325 * SAVE_RESTORE_TITLE: Just restore title |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
13929
diff
changeset
|
326 * SAVE_RESTORE_ICON: Just restore icon (which we don't have) |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
13929
diff
changeset
|
327 * SAVE_RESTORE_BOTH: Restore title and icon (which we don't have) |
7 | 328 */ |
329 void | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
330 mch_restore_title(int which UNUSED) |
7 | 331 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
332 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
333 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
334 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
335 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
336 SetConsoleTitle(g_szOrigTitle); |
7 | 337 #endif |
338 } | |
339 | |
340 | |
341 /* | |
342 * Return TRUE if we can restore the title (we can) | |
343 */ | |
344 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
345 mch_can_restore_title(void) |
7 | 346 { |
347 return TRUE; | |
348 } | |
349 | |
350 | |
351 /* | |
352 * Return TRUE if we can restore the icon title (we can't) | |
353 */ | |
354 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
355 mch_can_restore_icon(void) |
7 | 356 { |
357 return FALSE; | |
358 } | |
359 #endif /* FEAT_TITLE */ | |
360 | |
361 | |
362 /* | |
39 | 363 * Get absolute file name into buffer "buf" of length "len" bytes, |
364 * turning all '/'s into '\\'s and getting the correct case of each component | |
365 * of the file name. Append a (back)slash to a directory name. | |
7 | 366 * When 'shellslash' set do it the other way around. |
367 * Return OK or FAIL. | |
368 */ | |
369 int | |
370 mch_FullName( | |
371 char_u *fname, | |
372 char_u *buf, | |
373 int len, | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
374 int force UNUSED) |
7 | 375 { |
376 int nResult = FAIL; | |
377 | |
378 #ifdef __BORLANDC__ | |
379 if (*fname == NUL) /* Borland behaves badly here - make it consistent */ | |
380 nResult = mch_dirname(buf, len); | |
381 else | |
382 #endif | |
383 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
384 WCHAR *wname; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
385 WCHAR wbuf[MAX_PATH]; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
386 char_u *cname = NULL; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
387 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
388 wname = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
389 if (wname != NULL && _wfullpath(wbuf, wname, MAX_PATH) != NULL) |
39 | 390 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
391 cname = utf16_to_enc((short_u *)wbuf, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
392 if (cname != NULL) |
39 | 393 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
394 vim_strncpy(buf, cname, len - 1); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
395 nResult = OK; |
39 | 396 } |
397 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
398 vim_free(wname); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
399 vim_free(cname); |
7 | 400 } |
401 | |
402 #ifdef USE_FNAME_CASE | |
403 fname_case(buf, len); | |
39 | 404 #else |
405 slash_adjust(buf); | |
7 | 406 #endif |
407 | |
408 return nResult; | |
409 } | |
410 | |
411 | |
412 /* | |
413 * Return TRUE if "fname" does not depend on the current directory. | |
414 */ | |
415 int | |
416 mch_isFullName(char_u *fname) | |
417 { | |
5320 | 418 /* WinNT and later can use _MAX_PATH wide characters for a pathname, which |
419 * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is | |
420 * UTF-8. */ | |
421 char szName[_MAX_PATH * 3 + 1]; | |
7 | 422 |
423 /* A name like "d:/foo" and "//server/share" is absolute */ | |
424 if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) | |
425 || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))) | |
426 return TRUE; | |
427 | |
428 /* A name that can't be made absolute probably isn't absolute. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
429 if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL) |
7 | 430 return FALSE; |
431 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
432 return pathcmp((const char *)fname, (const char *)szName, -1) == 0; |
7 | 433 } |
434 | |
435 /* | |
436 * Replace all slashes by backslashes. | |
437 * This used to be the other way around, but MS-DOS sometimes has problems | |
438 * with slashes (e.g. in a command name). We can't have mixed slashes and | |
439 * backslashes, because comparing file names will not work correctly. The | |
440 * commands that use a file name should try to avoid the need to type a | |
441 * backslash twice. | |
442 * When 'shellslash' set do it the other way around. | |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
6347
diff
changeset
|
443 * When the path looks like a URL leave it unmodified. |
7 | 444 */ |
445 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
446 slash_adjust(char_u *p) |
7 | 447 { |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
6347
diff
changeset
|
448 if (path_with_url(p)) |
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
6347
diff
changeset
|
449 return; |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
450 |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
451 if (*p == '`') |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
452 { |
12015
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
453 size_t len = STRLEN(p); |
7e704d75a882
patch 8.0.0888: compiler warnings with 64 bit build
Christian Brabandt <cb@256bit.org>
parents:
11991
diff
changeset
|
454 |
11991
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
455 /* don't replace backslash in backtick quoted strings */ |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
456 if (len > 2 && *(p + len - 1) == '`') |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
457 return; |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
458 } |
15ec6d5adf43
patch 8.0.0876: backslashes and wildcards in backticks don't work
Christian Brabandt <cb@256bit.org>
parents:
11949
diff
changeset
|
459 |
434 | 460 while (*p) |
461 { | |
462 if (*p == psepcN) | |
463 *p = psepc; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
464 MB_PTR_ADV(p); |
434 | 465 } |
7 | 466 } |
467 | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
468 /* Use 64-bit stat functions if available. */ |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
469 #ifdef HAVE_STAT64 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
470 # undef stat |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
471 # undef _stat |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
472 # undef _wstat |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
473 # undef _fstat |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
474 # define stat _stat64 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
475 # define _stat _stat64 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
476 # define _wstat _wstat64 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
477 # define _fstat _fstat64 |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
478 #endif |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
479 |
5594 | 480 #if (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(__MINGW32__) |
5386 | 481 # define OPEN_OH_ARGTYPE intptr_t |
482 #else | |
483 # define OPEN_OH_ARGTYPE long | |
484 #endif | |
485 | |
5376 | 486 static int |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
487 wstat_symlink_aware(const WCHAR *name, stat_T *stp) |
5376 | 488 { |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
489 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) |
7681
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
490 /* Work around for VC12 or earlier (and MinGW). _wstat() can't handle |
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
491 * symlinks properly. |
5376 | 492 * VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves |
493 * status of a symlink itself. | |
494 * VC10: _wstat() supports a symlink to a normal file, but it doesn't | |
7681
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
495 * support a symlink to a directory (always returns an error). |
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
496 * VC11 and VC12: _wstat() doesn't return an error for a symlink to a |
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
497 * directory, but it doesn't set S_IFDIR flag. |
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
498 * MinGW: Same as VC9. */ |
5376 | 499 int n; |
500 BOOL is_symlink = FALSE; | |
501 HANDLE hFind, h; | |
502 DWORD attr = 0; | |
503 WIN32_FIND_DATAW findDataW; | |
504 | |
505 hFind = FindFirstFileW(name, &findDataW); | |
506 if (hFind != INVALID_HANDLE_VALUE) | |
507 { | |
508 attr = findDataW.dwFileAttributes; | |
509 if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) | |
510 && (findDataW.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) | |
511 is_symlink = TRUE; | |
512 FindClose(hFind); | |
513 } | |
514 if (is_symlink) | |
515 { | |
516 h = CreateFileW(name, FILE_READ_ATTRIBUTES, | |
517 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | |
518 OPEN_EXISTING, | |
519 (attr & FILE_ATTRIBUTE_DIRECTORY) | |
520 ? FILE_FLAG_BACKUP_SEMANTICS : 0, | |
521 NULL); | |
522 if (h != INVALID_HANDLE_VALUE) | |
523 { | |
524 int fd; | |
525 | |
5386 | 526 fd = _open_osfhandle((OPEN_OH_ARGTYPE)h, _O_RDONLY); |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
527 n = _fstat(fd, (struct _stat *)stp); |
7681
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
528 if ((n == 0) && (attr & FILE_ATTRIBUTE_DIRECTORY)) |
07cfa8fea697
commit https://github.com/vim/vim/commit/fce7b3d24fd18b1486e474e933a95f9090df9973
Christian Brabandt <cb@256bit.org>
parents:
7170
diff
changeset
|
529 stp->st_mode = (stp->st_mode & ~S_IFREG) | S_IFDIR; |
5376 | 530 _close(fd); |
531 return n; | |
532 } | |
533 } | |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
534 #endif |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
535 return _wstat(name, (struct _stat *)stp); |
5376 | 536 } |
7 | 537 |
538 /* | |
539 * stat() can't handle a trailing '/' or '\', remove it first. | |
540 */ | |
541 int | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9091
diff
changeset
|
542 vim_stat(const char *name, stat_T *stp) |
7 | 543 { |
5320 | 544 /* WinNT and later can use _MAX_PATH wide characters for a pathname, which |
545 * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is | |
546 * UTF-8. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
547 char_u buf[_MAX_PATH * 3 + 1]; |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
548 char_u *p; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
549 WCHAR *wp; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
550 int n; |
7 | 551 |
5320 | 552 vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1); |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
553 p = buf + STRLEN(buf); |
7 | 554 if (p > buf) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
555 MB_PTR_BACK(buf, p); |
5578 | 556 |
557 /* Remove trailing '\\' except root path. */ | |
7 | 558 if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') |
559 *p = NUL; | |
5578 | 560 |
561 if ((buf[0] == '\\' && buf[1] == '\\') || (buf[0] == '/' && buf[1] == '/')) | |
562 { | |
563 /* UNC root path must be followed by '\\'. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
564 p = vim_strpbrk(buf + 2, (char_u *)"\\/"); |
5578 | 565 if (p != NULL) |
566 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
567 p = vim_strpbrk(p + 1, (char_u *)"\\/"); |
5578 | 568 if (p == NULL) |
569 STRCAT(buf, "\\"); | |
570 } | |
571 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
572 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
573 wp = enc_to_utf16(buf, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
574 if (wp == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
575 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
576 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
577 n = wstat_symlink_aware(wp, stp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
578 vim_free(wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
579 return n; |
7 | 580 } |
581 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
582 #if (defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)) || defined(PROTO) |
7 | 583 void |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
584 mch_settmode(int tmode UNUSED) |
7 | 585 { |
586 /* nothing to do */ | |
587 } | |
588 | |
589 int | |
590 mch_get_shellsize(void) | |
591 { | |
592 /* never used */ | |
593 return OK; | |
594 } | |
595 | |
596 void | |
597 mch_set_shellsize(void) | |
598 { | |
599 /* never used */ | |
600 } | |
601 | |
602 /* | |
603 * Rows and/or Columns has changed. | |
604 */ | |
605 void | |
606 mch_new_shellsize(void) | |
607 { | |
608 /* never used */ | |
609 } | |
610 | |
611 #endif | |
612 | |
613 /* | |
614 * We have no job control, so fake it by starting a new shell. | |
615 */ | |
616 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
617 mch_suspend(void) |
7 | 618 { |
619 suspend_shell(); | |
620 } | |
621 | |
622 #if defined(USE_MCH_ERRMSG) || defined(PROTO) | |
623 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
624 # ifdef display_errors |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
625 # undef display_errors |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
626 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
627 |
7 | 628 /* |
629 * Display the saved error message(s). | |
630 */ | |
631 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
632 display_errors(void) |
7 | 633 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
634 # ifdef FEAT_GUI |
7 | 635 char *p; |
636 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
637 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
638 if (gui.in_use || gui.starting) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
639 # endif |
7 | 640 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
641 if (error_ga.ga_data != NULL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
642 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
643 /* avoid putting up a message box with blanks only */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
644 for (p = (char *)error_ga.ga_data; *p; ++p) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
645 if (!isspace(*p)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
646 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
647 (void)gui_mch_dialog( |
802 | 648 gui.starting ? VIM_INFO : |
649 VIM_ERROR, | |
650 gui.starting ? (char_u *)_("Message") : | |
651 (char_u *)_("Error"), | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
652 (char_u *)p, (char_u *)_("&Ok"), |
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
653 1, NULL, FALSE); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
654 break; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
655 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
656 ga_clear(&error_ga); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
657 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
658 return; |
7 | 659 } |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
660 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
661 # if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
662 FlushFileBuffers(GetStdHandle(STD_ERROR_HANDLE)); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
663 # endif |
7 | 664 } |
665 #endif | |
666 | |
667 | |
668 /* | |
669 * Return TRUE if "p" contain a wildcard that can be expanded by | |
670 * dos_expandpath(). | |
671 */ | |
672 int | |
673 mch_has_exp_wildcard(char_u *p) | |
674 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
675 for ( ; *p; MB_PTR_ADV(p)) |
7 | 676 { |
677 if (vim_strchr((char_u *)"?*[", *p) != NULL | |
678 || (*p == '~' && p[1] != NUL)) | |
679 return TRUE; | |
680 } | |
681 return FALSE; | |
682 } | |
683 | |
684 /* | |
685 * Return TRUE if "p" contain a wildcard or a "~1" kind of thing (could be a | |
686 * shortened file name). | |
687 */ | |
688 int | |
689 mch_has_wildcard(char_u *p) | |
690 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
691 for ( ; *p; MB_PTR_ADV(p)) |
7 | 692 { |
693 if (vim_strchr((char_u *) | |
694 # ifdef VIM_BACKTICK | |
695 "?*$[`" | |
696 # else | |
697 "?*$[" | |
698 # endif | |
699 , *p) != NULL | |
700 || (*p == '~' && p[1] != NUL)) | |
701 return TRUE; | |
702 } | |
703 return FALSE; | |
704 } | |
705 | |
706 | |
707 /* | |
708 * The normal _chdir() does not change the default drive. This one does. | |
709 * Returning 0 implies success; -1 implies failure. | |
710 */ | |
711 int | |
712 mch_chdir(char *path) | |
713 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
714 WCHAR *p; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
715 int n; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
716 |
7 | 717 if (path[0] == NUL) /* just checking... */ |
718 return -1; | |
719 | |
1936 | 720 if (p_verbose >= 5) |
721 { | |
722 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
723 smsg("chdir(%s)", path); |
1936 | 724 verbose_leave(); |
725 } | |
7 | 726 if (isalpha(path[0]) && path[1] == ':') /* has a drive name */ |
727 { | |
728 /* If we can change to the drive, skip that part of the path. If we | |
729 * can't then the current directory may be invalid, try using chdir() | |
730 * with the whole path. */ | |
731 if (_chdrive(TOLOWER_ASC(path[0]) - 'a' + 1) == 0) | |
732 path += 2; | |
733 } | |
734 | |
735 if (*path == NUL) /* drive name only */ | |
736 return 0; | |
737 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
738 p = enc_to_utf16((char_u *)path, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
739 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
740 return -1; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
741 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
742 n = _wchdir(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
743 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
744 return n; |
7 | 745 } |
746 | |
747 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
748 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) |
7 | 749 /* |
750 * return non-zero if a character is available | |
751 */ | |
752 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
753 mch_char_avail(void) |
7 | 754 { |
755 /* never used */ | |
756 return TRUE; | |
757 } | |
11949
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
758 |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
759 # if defined(FEAT_TERMINAL) || defined(PROTO) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
760 /* |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
761 * Check for any pending input or messages. |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
762 */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
763 int |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
764 mch_check_messages(void) |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
765 { |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
766 /* TODO: check for messages */ |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
767 return TRUE; |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
768 } |
74e45c11b754
patch 8.0.0854: no redraw after terminal was closed
Christian Brabandt <cb@256bit.org>
parents:
11215
diff
changeset
|
769 # endif |
7 | 770 #endif |
771 | |
772 | |
773 /* | |
774 * set screen mode, always fails. | |
775 */ | |
776 int | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
777 mch_screenmode(char_u *arg UNUSED) |
7 | 778 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
779 emsg(_(e_screenmode)); |
7 | 780 return FAIL; |
781 } | |
782 | |
783 | |
784 #if defined(FEAT_LIBCALL) || defined(PROTO) | |
785 /* | |
786 * Call a DLL routine which takes either a string or int param | |
787 * and returns an allocated string. | |
788 * Return OK if it worked, FAIL if not. | |
789 */ | |
790 typedef LPTSTR (*MYSTRPROCSTR)(LPTSTR); | |
791 typedef LPTSTR (*MYINTPROCSTR)(int); | |
792 typedef int (*MYSTRPROCINT)(LPTSTR); | |
793 typedef int (*MYINTPROCINT)(int); | |
794 | |
795 /* | |
796 * Check if a pointer points to a valid NUL terminated string. | |
797 * Return the length of the string, including terminating NUL. | |
798 * Returns 0 for an invalid pointer, 1 for an empty string. | |
799 */ | |
800 static size_t | |
801 check_str_len(char_u *str) | |
802 { | |
803 SYSTEM_INFO si; | |
804 MEMORY_BASIC_INFORMATION mbi; | |
805 size_t length = 0; | |
806 size_t i; | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
807 const char_u *p; |
7 | 808 |
809 /* get page size */ | |
810 GetSystemInfo(&si); | |
811 | |
812 /* get memory information */ | |
813 if (VirtualQuery(str, &mbi, sizeof(mbi))) | |
814 { | |
815 /* pre cast these (typing savers) */ | |
840 | 816 long_u dwStr = (long_u)str; |
817 long_u dwBaseAddress = (long_u)mbi.BaseAddress; | |
7 | 818 |
819 /* get start address of page that str is on */ | |
840 | 820 long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize; |
7 | 821 |
822 /* get length from str to end of page */ | |
840 | 823 long_u pageLength = si.dwPageSize - (dwStr - strPage); |
7 | 824 |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
825 for (p = str; !IsBadReadPtr(p, (UINT)pageLength); |
7 | 826 p += pageLength, pageLength = si.dwPageSize) |
827 for (i = 0; i < pageLength; ++i, ++length) | |
828 if (p[i] == NUL) | |
829 return length + 1; | |
830 } | |
831 | |
832 return 0; | |
833 } | |
834 | |
6249 | 835 /* |
836 * Passed to do_in_runtimepath() to load a vim.ico file. | |
837 */ | |
838 static void | |
839 mch_icon_load_cb(char_u *fname, void *cookie) | |
840 { | |
841 HANDLE *h = (HANDLE *)cookie; | |
842 | |
843 *h = LoadImage(NULL, | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
844 (LPSTR)fname, |
6249 | 845 IMAGE_ICON, |
846 64, | |
847 64, | |
848 LR_LOADFROMFILE | LR_LOADMAP3DCOLORS); | |
849 } | |
850 | |
851 /* | |
852 * Try loading an icon file from 'runtimepath'. | |
853 */ | |
854 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
855 mch_icon_load(HANDLE *iconp) |
6249 | 856 { |
857 return do_in_runtimepath((char_u *)"bitmaps/vim.ico", | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
858 0, mch_icon_load_cb, iconp); |
6249 | 859 } |
860 | |
7 | 861 int |
862 mch_libcall( | |
863 char_u *libname, | |
864 char_u *funcname, | |
865 char_u *argstring, /* NULL when using a argint */ | |
866 int argint, | |
867 char_u **string_result,/* NULL when using number_result */ | |
868 int *number_result) | |
869 { | |
870 HINSTANCE hinstLib; | |
871 MYSTRPROCSTR ProcAdd; | |
872 MYINTPROCSTR ProcAddI; | |
873 char_u *retval_str = NULL; | |
874 int retval_int = 0; | |
875 size_t len; | |
876 | |
877 BOOL fRunTimeLinkSuccess = FALSE; | |
878 | |
879 // Get a handle to the DLL module. | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
880 hinstLib = vimLoadLib((char *)libname); |
7 | 881 |
882 // If the handle is valid, try to get the function address. | |
883 if (hinstLib != NULL) | |
884 { | |
885 #ifdef HAVE_TRY_EXCEPT | |
886 __try | |
887 { | |
888 #endif | |
889 if (argstring != NULL) | |
890 { | |
891 /* Call with string argument */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
892 ProcAdd = (MYSTRPROCSTR)GetProcAddress(hinstLib, (LPCSTR)funcname); |
7 | 893 if ((fRunTimeLinkSuccess = (ProcAdd != NULL)) != 0) |
894 { | |
895 if (string_result == NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
896 retval_int = ((MYSTRPROCINT)ProcAdd)((LPSTR)argstring); |
7 | 897 else |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
898 retval_str = (char_u *)(ProcAdd)((LPSTR)argstring); |
7 | 899 } |
900 } | |
901 else | |
902 { | |
903 /* Call with number argument */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
904 ProcAddI = (MYINTPROCSTR) GetProcAddress(hinstLib, (LPCSTR)funcname); |
7 | 905 if ((fRunTimeLinkSuccess = (ProcAddI != NULL)) != 0) |
906 { | |
907 if (string_result == NULL) | |
908 retval_int = ((MYINTPROCINT)ProcAddI)(argint); | |
909 else | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
910 retval_str = (char_u *)(ProcAddI)(argint); |
7 | 911 } |
912 } | |
913 | |
914 // Save the string before we free the library. | |
915 // Assume that a "1" result is an illegal pointer. | |
916 if (string_result == NULL) | |
917 *number_result = retval_int; | |
918 else if (retval_str != NULL | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
8090
diff
changeset
|
919 && (len = check_str_len(retval_str)) > 0) |
7 | 920 { |
921 *string_result = lalloc((long_u)len, TRUE); | |
922 if (*string_result != NULL) | |
923 mch_memmove(*string_result, retval_str, len); | |
924 } | |
925 | |
926 #ifdef HAVE_TRY_EXCEPT | |
927 } | |
928 __except(EXCEPTION_EXECUTE_HANDLER) | |
929 { | |
930 if (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW) | |
931 RESETSTKOFLW(); | |
932 fRunTimeLinkSuccess = 0; | |
933 } | |
934 #endif | |
935 | |
936 // Free the DLL module. | |
937 (void)FreeLibrary(hinstLib); | |
938 } | |
939 | |
940 if (!fRunTimeLinkSuccess) | |
941 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
942 semsg(_(e_libcall), funcname); |
7 | 943 return FAIL; |
944 } | |
945 | |
946 return OK; | |
947 } | |
948 #endif | |
949 | |
950 /* | |
951 * Debugging helper: expose the MCH_WRITE_DUMP stuff to other modules | |
952 */ | |
953 void | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
954 DumpPutS(const char *psz UNUSED) |
7 | 955 { |
956 # ifdef MCH_WRITE_DUMP | |
957 if (fdDump) | |
958 { | |
959 fputs(psz, fdDump); | |
960 if (psz[strlen(psz) - 1] != '\n') | |
961 fputc('\n', fdDump); | |
962 fflush(fdDump); | |
963 } | |
964 # endif | |
965 } | |
966 | |
967 #ifdef _DEBUG | |
968 | |
969 void __cdecl | |
970 Trace( | |
971 char *pszFormat, | |
972 ...) | |
973 { | |
974 CHAR szBuff[2048]; | |
975 va_list args; | |
976 | |
977 va_start(args, pszFormat); | |
978 vsprintf(szBuff, pszFormat, args); | |
979 va_end(args); | |
980 | |
981 OutputDebugString(szBuff); | |
982 } | |
983 | |
984 #endif //_DEBUG | |
985 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
986 #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO) |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
987 # ifdef FEAT_TITLE |
7 | 988 extern HWND g_hWnd; /* This is in os_win32.c. */ |
989 # endif | |
990 | |
991 /* | |
992 * Showing the printer dialog is tricky since we have no GUI | |
993 * window to parent it. The following routines are needed to | |
994 * get the window parenting and Z-order to work properly. | |
995 */ | |
996 static void | |
997 GetConsoleHwnd(void) | |
998 { | |
999 /* Skip if it's already set. */ | |
1000 if (s_hwnd != 0) | |
1001 return; | |
1002 | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1003 # ifdef FEAT_TITLE |
7 | 1004 /* Window handle may have been found by init code (Windows NT only) */ |
1005 if (g_hWnd != 0) | |
1006 { | |
1007 s_hwnd = g_hWnd; | |
1008 return; | |
1009 } | |
1010 # endif | |
1011 | |
15798
028c9fdb8469
patch 8.1.0906: using clumsy way to get console window handle
Bram Moolenaar <Bram@vim.org>
parents:
15774
diff
changeset
|
1012 s_hwnd = GetConsoleWindow(); |
7 | 1013 } |
11 | 1014 |
1015 /* | |
1016 * Console implementation of ":winpos". | |
1017 */ | |
1018 int | |
1019 mch_get_winpos(int *x, int *y) | |
1020 { | |
1021 RECT rect; | |
1022 | |
1023 GetConsoleHwnd(); | |
1024 GetWindowRect(s_hwnd, &rect); | |
1025 *x = rect.left; | |
1026 *y = rect.top; | |
1027 return OK; | |
1028 } | |
1029 | |
1030 /* | |
1031 * Console implementation of ":winpos x y". | |
1032 */ | |
1033 void | |
1034 mch_set_winpos(int x, int y) | |
1035 { | |
1036 GetConsoleHwnd(); | |
1037 SetWindowPos(s_hwnd, NULL, x, y, 0, 0, | |
1038 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); | |
1039 } | |
7 | 1040 #endif |
1041 | |
1042 #if (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) || defined(PROTO) | |
1043 | |
1044 /*================================================================= | |
1045 * Win32 printer stuff | |
1046 */ | |
1047 | |
1048 static HFONT prt_font_handles[2][2][2]; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1049 static PRINTDLGW prt_dlg; |
7 | 1050 static const int boldface[2] = {FW_REGULAR, FW_BOLD}; |
1051 static TEXTMETRIC prt_tm; | |
1052 static int prt_line_height; | |
1053 static int prt_number_width; | |
1054 static int prt_left_margin; | |
1055 static int prt_right_margin; | |
1056 static int prt_top_margin; | |
1057 static char_u szAppName[] = TEXT("VIM"); | |
1058 static HWND hDlgPrint; | |
1059 static int *bUserAbort = NULL; | |
1060 static char_u *prt_name = NULL; | |
1061 | |
1062 /* Defines which are also in vim.rc. */ | |
1063 #define IDC_BOX1 400 | |
1064 #define IDC_PRINTTEXT1 401 | |
1065 #define IDC_PRINTTEXT2 402 | |
1066 #define IDC_PROGRESS 403 | |
1067 | |
4932
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1068 static BOOL |
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1069 vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s) |
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1070 { |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1071 WCHAR *wp; |
4932
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1072 BOOL ret; |
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1073 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1074 wp = enc_to_utf16(s, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1075 if (wp == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1076 return FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1077 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1078 ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1079 vim_free(wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1080 return ret; |
4932
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1081 } |
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1082 |
7 | 1083 /* |
1084 * Convert BGR to RGB for Windows GDI calls | |
1085 */ | |
1086 static COLORREF | |
1087 swap_me(COLORREF colorref) | |
1088 { | |
1089 int temp; | |
1090 char *ptr = (char *)&colorref; | |
1091 | |
1092 temp = *(ptr); | |
1093 *(ptr ) = *(ptr + 2); | |
1094 *(ptr + 2) = temp; | |
1095 return colorref; | |
1096 } | |
1097 | |
1702 | 1098 /* Attempt to make this work for old and new compilers */ |
3102 | 1099 #if !defined(_WIN64) && (!defined(_MSC_VER) || _MSC_VER < 1300) |
1702 | 1100 # define PDP_RETVAL BOOL |
1101 #else | |
1102 # define PDP_RETVAL INT_PTR | |
1103 #endif | |
1104 | |
1105 static PDP_RETVAL CALLBACK | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1106 PrintDlgProc( |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1107 HWND hDlg, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1108 UINT message, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1109 WPARAM wParam UNUSED, |
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1110 LPARAM lParam UNUSED) |
7 | 1111 { |
1112 #ifdef FEAT_GETTEXT | |
1113 NONCLIENTMETRICS nm; | |
1114 static HFONT hfont; | |
1115 #endif | |
1116 | |
1117 switch (message) | |
1118 { | |
1119 case WM_INITDIALOG: | |
1120 #ifdef FEAT_GETTEXT | |
1121 nm.cbSize = sizeof(NONCLIENTMETRICS); | |
1122 if (SystemParametersInfo( | |
1123 SPI_GETNONCLIENTMETRICS, | |
1124 sizeof(NONCLIENTMETRICS), | |
1125 &nm, | |
1126 0)) | |
1127 { | |
1128 char buff[MAX_PATH]; | |
1129 int i; | |
1130 | |
1131 /* Translate the dialog texts */ | |
1132 hfont = CreateFontIndirect(&nm.lfMessageFont); | |
1133 for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) | |
1134 { | |
1135 SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1); | |
1136 if (GetDlgItemText(hDlg,i, buff, sizeof(buff))) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1137 vimSetDlgItemText(hDlg,i, (char_u *)_(buff)); |
7 | 1138 } |
1139 SendDlgItemMessage(hDlg, IDCANCEL, | |
1140 WM_SETFONT, (WPARAM)hfont, 1); | |
1141 if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff))) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1142 vimSetDlgItemText(hDlg,IDCANCEL, (char_u *)_(buff)); |
7 | 1143 } |
1144 #endif | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1145 SetWindowText(hDlg, (LPCSTR)szAppName); |
7 | 1146 if (prt_name != NULL) |
1147 { | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1148 vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (char_u *)prt_name); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12054
diff
changeset
|
1149 VIM_CLEAR(prt_name); |
7 | 1150 } |
1151 EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED); | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1152 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1153 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1154 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1155 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1156 BringWindowToTop(s_hwnd); |
7 | 1157 #endif |
1158 return TRUE; | |
1159 | |
1160 case WM_COMMAND: | |
1161 *bUserAbort = TRUE; | |
1162 EnableWindow(GetParent(hDlg), TRUE); | |
1163 DestroyWindow(hDlg); | |
1164 hDlgPrint = NULL; | |
1165 #ifdef FEAT_GETTEXT | |
1166 DeleteObject(hfont); | |
1167 #endif | |
1168 return TRUE; | |
1169 } | |
1170 return FALSE; | |
1171 } | |
1172 | |
1173 static BOOL CALLBACK | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1174 AbortProc(HDC hdcPrn UNUSED, int iCode UNUSED) |
7 | 1175 { |
1176 MSG msg; | |
1177 | |
3010 | 1178 while (!*bUserAbort && pPeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) |
7 | 1179 { |
3010 | 1180 if (!hDlgPrint || !pIsDialogMessage(hDlgPrint, &msg)) |
7 | 1181 { |
1182 TranslateMessage(&msg); | |
3010 | 1183 pDispatchMessage(&msg); |
7 | 1184 } |
1185 } | |
1186 return !*bUserAbort; | |
1187 } | |
1188 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1189 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7 | 1190 |
3174 | 1191 static UINT_PTR CALLBACK |
7 | 1192 PrintHookProc( |
1193 HWND hDlg, // handle to dialog box | |
1194 UINT uiMsg, // message identifier | |
1195 WPARAM wParam, // message parameter | |
1196 LPARAM lParam // message parameter | |
1197 ) | |
1198 { | |
1199 HWND hwndOwner; | |
1200 RECT rc, rcDlg, rcOwner; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1201 PRINTDLGW *pPD; |
7 | 1202 |
1203 if (uiMsg == WM_INITDIALOG) | |
1204 { | |
1205 // Get the owner window and dialog box rectangles. | |
1206 if ((hwndOwner = GetParent(hDlg)) == NULL) | |
1207 hwndOwner = GetDesktopWindow(); | |
1208 | |
1209 GetWindowRect(hwndOwner, &rcOwner); | |
1210 GetWindowRect(hDlg, &rcDlg); | |
1211 CopyRect(&rc, &rcOwner); | |
1212 | |
1213 // Offset the owner and dialog box rectangles so that | |
1214 // right and bottom values represent the width and | |
1215 // height, and then offset the owner again to discard | |
1216 // space taken up by the dialog box. | |
1217 | |
1218 OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); | |
1219 OffsetRect(&rc, -rc.left, -rc.top); | |
1220 OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); | |
1221 | |
1222 // The new position is the sum of half the remaining | |
1223 // space and the owner's original position. | |
1224 | |
1225 SetWindowPos(hDlg, | |
1226 HWND_TOP, | |
1227 rcOwner.left + (rc.right / 2), | |
1228 rcOwner.top + (rc.bottom / 2), | |
1229 0, 0, // ignores size arguments | |
1230 SWP_NOSIZE); | |
1231 | |
1232 /* tackle the printdlg copiesctrl problem */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1233 pPD = (PRINTDLGW *)lParam; |
7 | 1234 pPD->nCopies = (WORD)pPD->lCustData; |
1235 SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); | |
1236 /* Bring the window to top */ | |
1237 BringWindowToTop(GetParent(hDlg)); | |
1238 SetForegroundWindow(hDlg); | |
1239 } | |
1240 | |
1241 return FALSE; | |
1242 } | |
1243 #endif | |
1244 | |
1245 void | |
1246 mch_print_cleanup(void) | |
1247 { | |
1248 int pifItalic; | |
1249 int pifBold; | |
1250 int pifUnderline; | |
1251 | |
1252 for (pifBold = 0; pifBold <= 1; pifBold++) | |
1253 for (pifItalic = 0; pifItalic <= 1; pifItalic++) | |
1254 for (pifUnderline = 0; pifUnderline <= 1; pifUnderline++) | |
1255 DeleteObject(prt_font_handles[pifBold][pifItalic][pifUnderline]); | |
1256 | |
1257 if (prt_dlg.hDC != NULL) | |
1258 DeleteDC(prt_dlg.hDC); | |
1259 if (!*bUserAbort) | |
1260 SendMessage(hDlgPrint, WM_COMMAND, 0, 0); | |
1261 } | |
1262 | |
1263 static int | |
1264 to_device_units(int idx, int dpi, int physsize, int offset, int def_number) | |
1265 { | |
1266 int ret = 0; | |
1267 int u; | |
1268 int nr; | |
1269 | |
1270 u = prt_get_unit(idx); | |
1271 if (u == PRT_UNIT_NONE) | |
1272 { | |
1273 u = PRT_UNIT_PERC; | |
1274 nr = def_number; | |
1275 } | |
1276 else | |
1277 nr = printer_opts[idx].number; | |
1278 | |
1279 switch (u) | |
1280 { | |
1281 case PRT_UNIT_PERC: | |
1282 ret = (physsize * nr) / 100; | |
1283 break; | |
1284 case PRT_UNIT_INCH: | |
1285 ret = (nr * dpi); | |
1286 break; | |
1287 case PRT_UNIT_MM: | |
1288 ret = (nr * 10 * dpi) / 254; | |
1289 break; | |
1290 case PRT_UNIT_POINT: | |
1291 ret = (nr * 10 * dpi) / 720; | |
1292 break; | |
1293 } | |
1294 | |
1295 if (ret < offset) | |
1296 return 0; | |
1297 else | |
1298 return ret - offset; | |
1299 } | |
1300 | |
1301 static int | |
1302 prt_get_cpl(void) | |
1303 { | |
1304 int hr; | |
1305 int phyw; | |
1306 int dvoff; | |
1307 int rev_offset; | |
1308 int dpi; | |
1309 | |
1310 GetTextMetrics(prt_dlg.hDC, &prt_tm); | |
1311 prt_line_height = prt_tm.tmHeight + prt_tm.tmExternalLeading; | |
1312 | |
1313 hr = GetDeviceCaps(prt_dlg.hDC, HORZRES); | |
1314 phyw = GetDeviceCaps(prt_dlg.hDC, PHYSICALWIDTH); | |
1315 dvoff = GetDeviceCaps(prt_dlg.hDC, PHYSICALOFFSETX); | |
1316 dpi = GetDeviceCaps(prt_dlg.hDC, LOGPIXELSX); | |
1317 | |
1318 rev_offset = phyw - (dvoff + hr); | |
1319 | |
1320 prt_left_margin = to_device_units(OPT_PRINT_LEFT, dpi, phyw, dvoff, 10); | |
1321 if (prt_use_number()) | |
1322 { | |
1323 prt_number_width = PRINT_NUMBER_WIDTH * prt_tm.tmAveCharWidth; | |
1324 prt_left_margin += prt_number_width; | |
1325 } | |
1326 else | |
1327 prt_number_width = 0; | |
1328 | |
1329 prt_right_margin = hr - to_device_units(OPT_PRINT_RIGHT, dpi, phyw, | |
1330 rev_offset, 5); | |
1331 | |
1332 return (prt_right_margin - prt_left_margin) / prt_tm.tmAveCharWidth; | |
1333 } | |
1334 | |
1335 static int | |
1336 prt_get_lpp(void) | |
1337 { | |
1338 int vr; | |
1339 int phyw; | |
1340 int dvoff; | |
1341 int rev_offset; | |
1342 int bottom_margin; | |
1343 int dpi; | |
1344 | |
1345 vr = GetDeviceCaps(prt_dlg.hDC, VERTRES); | |
1346 phyw = GetDeviceCaps(prt_dlg.hDC, PHYSICALHEIGHT); | |
1347 dvoff = GetDeviceCaps(prt_dlg.hDC, PHYSICALOFFSETY); | |
1348 dpi = GetDeviceCaps(prt_dlg.hDC, LOGPIXELSY); | |
1349 | |
1350 rev_offset = phyw - (dvoff + vr); | |
1351 | |
1352 prt_top_margin = to_device_units(OPT_PRINT_TOP, dpi, phyw, dvoff, 5); | |
1353 | |
1354 /* adjust top margin if there is a header */ | |
1355 prt_top_margin += prt_line_height * prt_header_height(); | |
1356 | |
1357 bottom_margin = vr - to_device_units(OPT_PRINT_BOT, dpi, phyw, | |
1358 rev_offset, 5); | |
1359 | |
1360 return (bottom_margin - prt_top_margin) / prt_line_height; | |
1361 } | |
1362 | |
1363 int | |
1364 mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) | |
1365 { | |
1366 static HGLOBAL stored_dm = NULL; | |
1367 static HGLOBAL stored_devn = NULL; | |
1368 static int stored_nCopies = 1; | |
1369 static int stored_nFlags = 0; | |
1370 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1371 LOGFONTW fLogFont; |
7 | 1372 int pifItalic; |
1373 int pifBold; | |
1374 int pifUnderline; | |
1375 | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1376 DEVMODEW *mem; |
7 | 1377 DEVNAMES *devname; |
1378 int i; | |
1379 | |
1380 bUserAbort = &(psettings->user_abort); | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1381 vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW)); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1382 prt_dlg.lStructSize = sizeof(PRINTDLGW); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1383 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1384 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1385 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1386 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1387 GetConsoleHwnd(); /* get value of s_hwnd */ |
7 | 1388 #endif |
1389 prt_dlg.hwndOwner = s_hwnd; | |
1390 prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; | |
1391 if (!forceit) | |
1392 { | |
1393 prt_dlg.hDevMode = stored_dm; | |
1394 prt_dlg.hDevNames = stored_devn; | |
1395 prt_dlg.lCustData = stored_nCopies; // work around bug in print dialog | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1396 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1397 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1398 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1399 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1400 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1401 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1402 * Use hook to prevent console window being sent to back |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1403 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1404 prt_dlg.lpfnPrintHook = PrintHookProc; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1405 prt_dlg.Flags |= PD_ENABLEPRINTHOOK; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1406 } |
7 | 1407 #endif |
1408 prt_dlg.Flags |= stored_nFlags; | |
1409 } | |
1410 | |
1411 /* | |
1412 * If bang present, return default printer setup with no dialog | |
1413 * never show dialog if we are running over telnet | |
1414 */ | |
1415 if (forceit | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1416 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1417 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1418 || (!gui.in_use && !term_console) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1419 # else |
7 | 1420 || !term_console |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1421 # endif |
7 | 1422 #endif |
1423 ) | |
1424 { | |
1425 prt_dlg.Flags |= PD_RETURNDEFAULT; | |
1426 /* | |
1427 * MSDN suggests setting the first parameter to WINSPOOL for | |
1428 * NT, but NULL appears to work just as well. | |
1429 */ | |
1430 if (*p_pdev != NUL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1431 prt_dlg.hDC = CreateDC(NULL, (LPCSTR)p_pdev, NULL, NULL); |
7 | 1432 else |
1433 { | |
1434 prt_dlg.Flags |= PD_RETURNDEFAULT; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1435 if (PrintDlgW(&prt_dlg) == 0) |
7 | 1436 goto init_fail_dlg; |
1437 } | |
1438 } | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1439 else if (PrintDlgW(&prt_dlg) == 0) |
7 | 1440 goto init_fail_dlg; |
1441 else | |
1442 { | |
1443 /* | |
1444 * keep the previous driver context | |
1445 */ | |
1446 stored_dm = prt_dlg.hDevMode; | |
1447 stored_devn = prt_dlg.hDevNames; | |
1448 stored_nFlags = prt_dlg.Flags; | |
1449 stored_nCopies = prt_dlg.nCopies; | |
1450 } | |
1451 | |
1452 if (prt_dlg.hDC == NULL) | |
1453 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
1454 emsg(_("E237: Printer selection failed")); |
7 | 1455 mch_print_cleanup(); |
1456 return FALSE; | |
1457 } | |
1458 | |
1459 /* Not all printer drivers report the support of color (or grey) in the | |
1460 * same way. Let's set has_color if there appears to be some way to print | |
1461 * more than B&W. */ | |
1462 i = GetDeviceCaps(prt_dlg.hDC, NUMCOLORS); | |
1463 psettings->has_color = (GetDeviceCaps(prt_dlg.hDC, BITSPIXEL) > 1 | |
1464 || GetDeviceCaps(prt_dlg.hDC, PLANES) > 1 | |
1465 || i > 2 || i == -1); | |
1466 | |
1467 /* Ensure all font styles are baseline aligned */ | |
1468 SetTextAlign(prt_dlg.hDC, TA_BASELINE|TA_LEFT); | |
1469 | |
1470 /* | |
1471 * On some windows systems the nCopies parameter is not | |
1472 * passed back correctly. It must be retrieved from the | |
1473 * hDevMode struct. | |
1474 */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1475 mem = (DEVMODEW *)GlobalLock(prt_dlg.hDevMode); |
7 | 1476 if (mem != NULL) |
1477 { | |
1478 if (mem->dmCopies != 1) | |
1479 stored_nCopies = mem->dmCopies; | |
1480 if ((mem->dmFields & DM_DUPLEX) && (mem->dmDuplex & ~DMDUP_SIMPLEX)) | |
1481 psettings->duplex = TRUE; | |
1482 if ((mem->dmFields & DM_COLOR) && (mem->dmColor & DMCOLOR_COLOR)) | |
1483 psettings->has_color = TRUE; | |
1484 } | |
1485 GlobalUnlock(prt_dlg.hDevMode); | |
1486 | |
1487 devname = (DEVNAMES *)GlobalLock(prt_dlg.hDevNames); | |
1488 if (devname != 0) | |
1489 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1490 WCHAR *wprinter_name = (WCHAR *)devname + devname->wDeviceOffset; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1491 WCHAR *wport_name = (WCHAR *)devname + devname->wOutputOffset; |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1492 char_u *text = (char_u *)_("to %s on %s"); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1493 char_u *printer_name = utf16_to_enc(wprinter_name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1494 char_u *port_name = utf16_to_enc(wport_name, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1495 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1496 if (printer_name != NULL && port_name != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1497 prt_name = alloc((unsigned)(STRLEN(printer_name) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1498 + STRLEN(port_name) + STRLEN(text))); |
7 | 1499 if (prt_name != NULL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1500 wsprintf((char *)prt_name, (const char *)text, |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1501 printer_name, port_name); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1502 vim_free(printer_name); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1503 vim_free(port_name); |
7 | 1504 } |
1505 GlobalUnlock(prt_dlg.hDevNames); | |
1506 | |
1507 /* | |
1508 * Initialise the font according to 'printfont' | |
1509 */ | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1936
diff
changeset
|
1510 vim_memset(&fLogFont, 0, sizeof(fLogFont)); |
37 | 1511 if (get_logfont(&fLogFont, p_pfn, prt_dlg.hDC, TRUE) == FAIL) |
7 | 1512 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
1513 semsg(_("E613: Unknown printer font: %s"), p_pfn); |
7 | 1514 mch_print_cleanup(); |
1515 return FALSE; | |
1516 } | |
1517 | |
1518 for (pifBold = 0; pifBold <= 1; pifBold++) | |
1519 for (pifItalic = 0; pifItalic <= 1; pifItalic++) | |
1520 for (pifUnderline = 0; pifUnderline <= 1; pifUnderline++) | |
1521 { | |
1522 fLogFont.lfWeight = boldface[pifBold]; | |
1523 fLogFont.lfItalic = pifItalic; | |
1524 fLogFont.lfUnderline = pifUnderline; | |
1525 prt_font_handles[pifBold][pifItalic][pifUnderline] | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1526 = CreateFontIndirectW(&fLogFont); |
7 | 1527 } |
1528 | |
1529 SetBkMode(prt_dlg.hDC, OPAQUE); | |
1530 SelectObject(prt_dlg.hDC, prt_font_handles[0][0][0]); | |
1531 | |
1532 /* | |
1533 * Fill in the settings struct | |
1534 */ | |
1535 psettings->chars_per_line = prt_get_cpl(); | |
1536 psettings->lines_per_page = prt_get_lpp(); | |
6253 | 1537 if (prt_dlg.Flags & PD_USEDEVMODECOPIESANDCOLLATE) |
1538 { | |
1539 psettings->n_collated_copies = (prt_dlg.Flags & PD_COLLATE) | |
1540 ? prt_dlg.nCopies : 1; | |
1541 psettings->n_uncollated_copies = (prt_dlg.Flags & PD_COLLATE) | |
1542 ? 1 : prt_dlg.nCopies; | |
1543 | |
1544 if (psettings->n_collated_copies == 0) | |
1545 psettings->n_collated_copies = 1; | |
1546 | |
1547 if (psettings->n_uncollated_copies == 0) | |
1548 psettings->n_uncollated_copies = 1; | |
10440
f54e4c691de4
commit https://github.com/vim/vim/commit/b04a98f6c3cca14bf055934b0a793f4dc376858b
Christian Brabandt <cb@256bit.org>
parents:
10355
diff
changeset
|
1549 } |
f54e4c691de4
commit https://github.com/vim/vim/commit/b04a98f6c3cca14bf055934b0a793f4dc376858b
Christian Brabandt <cb@256bit.org>
parents:
10355
diff
changeset
|
1550 else |
f54e4c691de4
commit https://github.com/vim/vim/commit/b04a98f6c3cca14bf055934b0a793f4dc376858b
Christian Brabandt <cb@256bit.org>
parents:
10355
diff
changeset
|
1551 { |
7 | 1552 psettings->n_collated_copies = 1; |
1553 psettings->n_uncollated_copies = 1; | |
6253 | 1554 } |
7 | 1555 |
1556 psettings->jobname = jobname; | |
1557 | |
1558 return TRUE; | |
1559 | |
1560 init_fail_dlg: | |
1561 { | |
1562 DWORD err = CommDlgExtendedError(); | |
1563 | |
1564 if (err) | |
1565 { | |
1566 char_u *buf; | |
1567 | |
1568 /* I suspect FormatMessage() doesn't work for values returned by | |
1569 * CommDlgExtendedError(). What does? */ | |
1570 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
1571 FORMAT_MESSAGE_FROM_SYSTEM | | |
1572 FORMAT_MESSAGE_IGNORE_INSERTS, | |
1573 NULL, err, 0, (LPTSTR)(&buf), 0, NULL); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
1574 semsg(_("E238: Print error: %s"), |
7 | 1575 buf == NULL ? (char_u *)_("Unknown") : buf); |
1576 LocalFree((LPVOID)(buf)); | |
1577 } | |
1578 else | |
1579 msg_clr_eos(); /* Maybe canceled */ | |
1580 | |
1581 mch_print_cleanup(); | |
1582 return FALSE; | |
1583 } | |
1584 } | |
1585 | |
1586 | |
1587 int | |
1588 mch_print_begin(prt_settings_T *psettings) | |
1589 { | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1590 int ret = 0; |
7 | 1591 char szBuffer[300]; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1592 WCHAR *wp; |
7 | 1593 |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1594 hDlgPrint = CreateDialog(g_hinst, TEXT("PrintDlgBox"), |
7 | 1595 prt_dlg.hwndOwner, PrintDlgProc); |
1596 SetAbortProc(prt_dlg.hDC, AbortProc); | |
1597 wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname)); | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1598 vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (char_u *)szBuffer); |
7 | 1599 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1600 wp = enc_to_utf16(psettings->jobname, NULL); |
13929
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1601 if (wp != NULL) |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1602 { |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1603 DOCINFOW di; |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1604 |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1605 vim_memset(&di, 0, sizeof(di)); |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1606 di.cbSize = sizeof(di); |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1607 di.lpszDocName = wp; |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1608 ret = StartDocW(prt_dlg.hDC, &di); |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1609 vim_free(wp); |
05aec5ac9630
patch 8.0.1835: print document name does not support multi-byte
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1610 } |
7 | 1611 |
1612 #ifdef FEAT_GUI | |
1613 /* Give focus back to main window (when using MDI). */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1614 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1615 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1616 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1617 SetFocus(s_hwnd); |
7 | 1618 #endif |
1619 | |
1620 return (ret > 0); | |
1621 } | |
1622 | |
1623 void | |
10783
04eb70c77cf4
patch 8.0.0281: some files are still using ARGSUSED instead of UNUSED
Christian Brabandt <cb@256bit.org>
parents:
10440
diff
changeset
|
1624 mch_print_end(prt_settings_T *psettings UNUSED) |
7 | 1625 { |
1626 EndDoc(prt_dlg.hDC); | |
1627 if (!*bUserAbort) | |
1628 SendMessage(hDlgPrint, WM_COMMAND, 0, 0); | |
1629 } | |
1630 | |
1631 int | |
1632 mch_print_end_page(void) | |
1633 { | |
1634 return (EndPage(prt_dlg.hDC) > 0); | |
1635 } | |
1636 | |
1637 int | |
1638 mch_print_begin_page(char_u *msg) | |
1639 { | |
1640 if (msg != NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1641 vimSetDlgItemText(hDlgPrint, IDC_PROGRESS, msg); |
7 | 1642 return (StartPage(prt_dlg.hDC) > 0); |
1643 } | |
1644 | |
1645 int | |
1646 mch_print_blank_page(void) | |
1647 { | |
1648 return (mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE); | |
1649 } | |
1650 | |
1651 static int prt_pos_x = 0; | |
1652 static int prt_pos_y = 0; | |
1653 | |
1654 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
1655 mch_print_start_line(int margin, int page_line) |
7 | 1656 { |
1657 if (margin) | |
1658 prt_pos_x = -prt_number_width; | |
1659 else | |
1660 prt_pos_x = 0; | |
1661 prt_pos_y = page_line * prt_line_height | |
1662 + prt_tm.tmAscent + prt_tm.tmExternalLeading; | |
1663 } | |
1664 | |
1665 int | |
1666 mch_print_text_out(char_u *p, int len) | |
1667 { | |
1668 SIZE sz; | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1669 WCHAR *wp; |
4932
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
1670 int wlen = len; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1671 int ret = FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1672 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1673 wp = enc_to_utf16(p, &wlen); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1674 if (wp == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1675 return FALSE; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1676 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1677 TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1678 prt_pos_y + prt_top_margin, wp, wlen); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1679 GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1680 vim_free(wp); |
7 | 1681 prt_pos_x += (sz.cx - prt_tm.tmOverhang); |
1682 /* This is wrong when printing spaces for a TAB. */ | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1683 if (p[len] != NUL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1684 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1685 wlen = MB_PTR2LEN(p + len); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1686 wp = enc_to_utf16(p + len, &wlen); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1687 if (wp != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1688 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1689 GetTextExtentPoint32W(prt_dlg.hDC, wp, 1, &sz); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1690 ret = (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1691 vim_free(wp); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1692 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1693 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1694 return ret; |
7 | 1695 } |
1696 | |
1697 void | |
1698 mch_print_set_font(int iBold, int iItalic, int iUnderline) | |
1699 { | |
1700 SelectObject(prt_dlg.hDC, prt_font_handles[iBold][iItalic][iUnderline]); | |
1701 } | |
1702 | |
1703 void | |
843 | 1704 mch_print_set_bg(long_u bgcol) |
7 | 1705 { |
843 | 1706 SetBkColor(prt_dlg.hDC, GetNearestColor(prt_dlg.hDC, |
1707 swap_me((COLORREF)bgcol))); | |
7 | 1708 /* |
1709 * With a white background we can draw characters transparent, which is | |
1710 * good for italic characters that overlap to the next char cell. | |
1711 */ | |
1712 if (bgcol == 0xffffffUL) | |
1713 SetBkMode(prt_dlg.hDC, TRANSPARENT); | |
1714 else | |
1715 SetBkMode(prt_dlg.hDC, OPAQUE); | |
1716 } | |
1717 | |
1718 void | |
843 | 1719 mch_print_set_fg(long_u fgcol) |
7 | 1720 { |
843 | 1721 SetTextColor(prt_dlg.hDC, GetNearestColor(prt_dlg.hDC, |
1722 swap_me((COLORREF)fgcol))); | |
7 | 1723 } |
1724 | |
1725 #endif /*FEAT_PRINTER && !FEAT_POSTSCRIPT*/ | |
1726 | |
440 | 1727 |
1728 | |
7 | 1729 #if defined(FEAT_SHORTCUT) || defined(PROTO) |
3927 | 1730 # ifndef PROTO |
1731 # include <shlobj.h> | |
1732 # endif | |
7 | 1733 |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1734 typedef enum _FILE_INFO_BY_HANDLE_CLASS_ { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1735 FileBasicInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1736 FileStandardInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1737 FileNameInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1738 FileRenameInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1739 FileDispositionInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1740 FileAllocationInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1741 FileEndOfFileInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1742 FileStreamInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1743 FileCompressionInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1744 FileAttributeTagInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1745 FileIdBothDirectoryInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1746 FileIdBothDirectoryRestartInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1747 FileIoPriorityHintInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1748 FileRemoteProtocolInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1749 FileFullDirectoryInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1750 FileFullDirectoryRestartInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1751 FileStorageInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1752 FileAlignmentInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1753 FileIdInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1754 FileIdExtdDirectoryInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1755 FileIdExtdDirectoryRestartInfo_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1756 FileDispositionInfoEx_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1757 FileRenameInfoEx_, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1758 MaximumFileInfoByHandleClass_ |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1759 } FILE_INFO_BY_HANDLE_CLASS_; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1760 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1761 typedef struct _FILE_NAME_INFO_ { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1762 DWORD FileNameLength; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1763 WCHAR FileName[1]; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1764 } FILE_NAME_INFO_; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1765 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1766 typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)( |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1767 HANDLE hFile, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1768 FILE_INFO_BY_HANDLE_CLASS_ FileInformationClass, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1769 LPVOID lpFileInformation, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1770 DWORD dwBufferSize); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1771 static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1772 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1773 typedef BOOL (WINAPI *pfnGetVolumeInformationByHandleW)( |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1774 HANDLE hFile, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1775 LPWSTR lpVolumeNameBuffer, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1776 DWORD nVolumeNameSize, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1777 LPDWORD lpVolumeSerialNumber, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1778 LPDWORD lpMaximumComponentLength, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1779 LPDWORD lpFileSystemFlags, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1780 LPWSTR lpFileSystemNameBuffer, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1781 DWORD nFileSystemNameSize); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1782 static pfnGetVolumeInformationByHandleW pGetVolumeInformationByHandleW = NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1783 |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16196
diff
changeset
|
1784 static char_u * |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1785 resolve_reparse_point(char_u *fname) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1786 { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1787 HANDLE h = INVALID_HANDLE_VALUE; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1788 DWORD size; |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1789 WCHAR *p; |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1790 char_u *rfname = NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1791 FILE_NAME_INFO_ *nameinfo = NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1792 WCHAR buff[MAX_PATH], *volnames = NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1793 HANDLE hv; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1794 DWORD snfile, snfind; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1795 static BOOL loaded = FALSE; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1796 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1797 if (pGetFileInformationByHandleEx == NULL || |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1798 pGetVolumeInformationByHandleW == NULL) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1799 { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1800 HMODULE hmod = GetModuleHandle("kernel32.dll"); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1801 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1802 if (loaded == TRUE) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1803 return NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1804 pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1805 GetProcAddress(hmod, "GetFileInformationByHandleEx"); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1806 pGetVolumeInformationByHandleW = (pfnGetVolumeInformationByHandleW) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1807 GetProcAddress(hmod, "GetVolumeInformationByHandleW"); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1808 loaded = TRUE; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1809 if (pGetFileInformationByHandleEx == NULL || |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1810 pGetVolumeInformationByHandleW == NULL) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1811 return NULL; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1812 } |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1813 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1814 p = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1815 if (p == NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1816 goto fail; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1817 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1818 if ((GetFileAttributesW(p) & FILE_ATTRIBUTE_REPARSE_POINT) == 0) |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1819 { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1820 vim_free(p); |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1821 goto fail; |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1822 } |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1823 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1824 h = CreateFileW(p, 0, 0, NULL, OPEN_EXISTING, |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1825 FILE_FLAG_BACKUP_SEMANTICS, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1826 vim_free(p); |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1827 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1828 if (h == INVALID_HANDLE_VALUE) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1829 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1830 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1831 size = sizeof(FILE_NAME_INFO_) + sizeof(WCHAR) * (MAX_PATH - 1); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1832 nameinfo = (FILE_NAME_INFO_*)alloc(size + sizeof(WCHAR)); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1833 if (nameinfo == NULL) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1834 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1835 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1836 if (!pGetFileInformationByHandleEx(h, FileNameInfo_, nameinfo, size)) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1837 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1838 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1839 nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = 0; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1840 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1841 if (!pGetVolumeInformationByHandleW( |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1842 h, NULL, 0, &snfile, NULL, NULL, NULL, 0)) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1843 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1844 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1845 hv = FindFirstVolumeW(buff, MAX_PATH); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1846 if (hv == INVALID_HANDLE_VALUE) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1847 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1848 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1849 do { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1850 GetVolumeInformationW( |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1851 buff, NULL, 0, &snfind, NULL, NULL, NULL, 0); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1852 if (snfind == snfile) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1853 break; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1854 } while (FindNextVolumeW(hv, buff, MAX_PATH)); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1855 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1856 FindVolumeClose(hv); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1857 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1858 if (snfind != snfile) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1859 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1860 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1861 size = 0; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1862 if (!GetVolumePathNamesForVolumeNameW(buff, NULL, 0, &size) && |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1863 GetLastError() != ERROR_MORE_DATA) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1864 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1865 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1866 volnames = (WCHAR*)alloc(size * sizeof(WCHAR)); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1867 if (!GetVolumePathNamesForVolumeNameW(buff, volnames, size, |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1868 &size)) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1869 goto fail; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1870 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1871 wcscpy(buff, volnames); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1872 if (nameinfo->FileName[0] == '\\') |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1873 wcscat(buff, nameinfo->FileName + 1); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1874 else |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1875 wcscat(buff, nameinfo->FileName); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1876 rfname = utf16_to_enc(buff, NULL); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1877 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1878 fail: |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1879 if (h != INVALID_HANDLE_VALUE) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1880 CloseHandle(h); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1881 if (nameinfo != NULL) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1882 vim_free(nameinfo); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1883 if (volnames != NULL) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1884 vim_free(volnames); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1885 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1886 return rfname; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1887 } |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1888 |
7 | 1889 /* |
1890 * When "fname" is the name of a shortcut (*.lnk) resolve the file it points | |
1891 * to and return that name in allocated memory. | |
1892 * Otherwise NULL is returned. | |
1893 */ | |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1894 static char_u * |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1895 resolve_shortcut(char_u *fname) |
7 | 1896 { |
1897 HRESULT hr; | |
1898 IShellLink *psl = NULL; | |
1899 IPersistFile *ppf = NULL; | |
1900 OLECHAR wsz[MAX_PATH]; | |
1901 char_u *rfname = NULL; | |
1902 int len; | |
5318 | 1903 IShellLinkW *pslw = NULL; |
1904 WIN32_FIND_DATAW ffdw; // we get those free of charge | |
7 | 1905 |
1906 /* Check if the file name ends in ".lnk". Avoid calling | |
1907 * CoCreateInstance(), it's quite slow. */ | |
1908 if (fname == NULL) | |
1909 return rfname; | |
835 | 1910 len = (int)STRLEN(fname); |
7 | 1911 if (len <= 4 || STRNICMP(fname + len - 4, ".lnk", 4) != 0) |
1912 return rfname; | |
1913 | |
1914 CoInitialize(NULL); | |
1915 | |
1916 // create a link manager object and request its interface | |
1917 hr = CoCreateInstance( | |
1918 &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, | |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1919 &IID_IShellLinkW, (void**)&pslw); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1920 if (hr == S_OK) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1921 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1922 WCHAR *p = enc_to_utf16(fname, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1923 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1924 if (p != NULL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1925 { |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1926 // Get a pointer to the IPersistFile interface. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1927 hr = pslw->lpVtbl->QueryInterface( |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1928 pslw, &IID_IPersistFile, (void**)&ppf); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1929 if (hr != S_OK) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1930 goto shortcut_errorw; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1931 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1932 // "load" the name and resolve the link |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1933 hr = ppf->lpVtbl->Load(ppf, p, STGM_READ); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1934 if (hr != S_OK) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1935 goto shortcut_errorw; |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1936 # if 0 // This makes Vim wait a long time if the target does not exist. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1937 hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1938 if (hr != S_OK) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1939 goto shortcut_errorw; |
5318 | 1940 # endif |
7 | 1941 |
16196
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1942 // Get the path to the link target. |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1943 ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR)); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1944 hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1945 if (hr == S_OK && wsz[0] != NUL) |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1946 rfname = utf16_to_enc(wsz, NULL); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1947 |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1948 shortcut_errorw: |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1949 vim_free(p); |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1950 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1951 } |
973070a30381
patch 8.1.1103: MS-Windows: old API calls are no longer needed
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1952 |
7 | 1953 // Release all interface pointers (both belong to the same object) |
1954 if (ppf != NULL) | |
1955 ppf->lpVtbl->Release(ppf); | |
1956 if (psl != NULL) | |
1957 psl->lpVtbl->Release(psl); | |
5318 | 1958 if (pslw != NULL) |
1959 pslw->lpVtbl->Release(pslw); | |
7 | 1960 |
1961 CoUninitialize(); | |
1962 return rfname; | |
1963 } | |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1964 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1965 char_u * |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1966 mch_resolve_path(char_u *fname, int reparse_point) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1967 { |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1968 char_u *path = resolve_shortcut(fname); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1969 |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1970 if (path == NULL && reparse_point) |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1971 path = resolve_reparse_point(fname); |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1972 return path; |
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1973 } |
7 | 1974 #endif |
1975 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
1976 #if (defined(FEAT_EVAL) && (!defined(FEAT_GUI) || defined(VIMDLL))) || defined(PROTO) |
7 | 1977 /* |
1978 * Bring ourselves to the foreground. Does work if the OS doesn't allow it. | |
1979 */ | |
1980 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
1981 win32_set_foreground(void) |
7 | 1982 { |
1983 GetConsoleHwnd(); /* get value of s_hwnd */ | |
1984 if (s_hwnd != 0) | |
1985 SetForegroundWindow(s_hwnd); | |
1986 } | |
1987 #endif | |
1988 | |
1989 #if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
1990 /* | |
1991 * Client-server code for Vim | |
1992 * | |
1993 * Originally written by Paul Moore | |
1994 */ | |
1995 | |
1996 /* In order to handle inter-process messages, we need to have a window. But | |
1997 * the functions in this module can be called before the main GUI window is | |
1998 * created (and may also be called in the console version, where there is no | |
1999 * GUI window at all). | |
2000 * | |
2001 * So we create a hidden window, and arrange to destroy it on exit. | |
2002 */ | |
4352 | 2003 HWND message_window = 0; /* window that's handling messages */ |
7 | 2004 |
2005 #define VIM_CLASSNAME "VIM_MESSAGES" | |
2006 #define VIM_CLASSNAME_LEN (sizeof(VIM_CLASSNAME) - 1) | |
2007 | |
2008 /* Communication is via WM_COPYDATA messages. The message type is send in | |
2009 * the dwData parameter. Types are defined here. */ | |
2010 #define COPYDATA_KEYS 0 | |
2011 #define COPYDATA_REPLY 1 | |
2012 #define COPYDATA_EXPR 10 | |
2013 #define COPYDATA_RESULT 11 | |
2014 #define COPYDATA_ERROR_RESULT 12 | |
39 | 2015 #define COPYDATA_ENCODING 20 |
7 | 2016 |
2017 /* This is a structure containing a server HWND and its name. */ | |
2018 struct server_id | |
2019 { | |
2020 HWND hwnd; | |
2021 char_u *name; | |
2022 }; | |
2023 | |
39 | 2024 /* Last received 'encoding' that the client uses. */ |
2025 static char_u *client_enc = NULL; | |
2026 | |
2027 /* | |
2028 * Tell the other side what encoding we are using. | |
2029 * Errors are ignored. | |
2030 */ | |
2031 static void | |
2032 serverSendEnc(HWND target) | |
2033 { | |
2034 COPYDATASTRUCT data; | |
2035 | |
2036 data.dwData = COPYDATA_ENCODING; | |
835 | 2037 data.cbData = (DWORD)STRLEN(p_enc) + 1; |
39 | 2038 data.lpData = p_enc; |
2039 (void)SendMessage(target, WM_COPYDATA, (WPARAM)message_window, | |
2040 (LPARAM)(&data)); | |
2041 } | |
2042 | |
7 | 2043 /* |
2044 * Clean up on exit. This destroys the hidden message window. | |
2045 */ | |
2046 static void | |
2047 #ifdef __BORLANDC__ | |
2048 _RTLENTRYF | |
2049 #endif | |
2050 CleanUpMessaging(void) | |
2051 { | |
2052 if (message_window != 0) | |
2053 { | |
2054 DestroyWindow(message_window); | |
2055 message_window = 0; | |
2056 } | |
2057 } | |
2058 | |
2059 static int save_reply(HWND server, char_u *reply, int expr); | |
2060 | |
4352 | 2061 /* |
7 | 2062 * The window procedure for the hidden message window. |
2063 * It handles callback messages and notifications from servers. | |
2064 * In order to process these messages, it is necessary to run a | |
2065 * message loop. Code which may run before the main message loop | |
2066 * is started (in the GUI) is careful to pump messages when it needs | |
2067 * to. Features which require message delivery during normal use will | |
2068 * not work in the console version - this basically means those | |
2069 * features which allow Vim to act as a server, rather than a client. | |
2070 */ | |
2071 static LRESULT CALLBACK | |
2072 Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
2073 { | |
2074 if (msg == WM_COPYDATA) | |
2075 { | |
2076 /* This is a message from another Vim. The dwData member of the | |
2077 * COPYDATASTRUCT determines the type of message: | |
39 | 2078 * COPYDATA_ENCODING: |
2079 * The encoding that the client uses. Following messages will | |
2080 * use this encoding, convert if needed. | |
7 | 2081 * COPYDATA_KEYS: |
2082 * A key sequence. We are a server, and a client wants these keys | |
2083 * adding to the input queue. | |
2084 * COPYDATA_REPLY: | |
2085 * A reply. We are a client, and a server has sent this message | |
2086 * in response to a request. (server2client()) | |
2087 * COPYDATA_EXPR: | |
2088 * An expression. We are a server, and a client wants us to | |
2089 * evaluate this expression. | |
2090 * COPYDATA_RESULT: | |
2091 * A reply. We are a client, and a server has sent this message | |
2092 * in response to a COPYDATA_EXPR. | |
2093 * COPYDATA_ERROR_RESULT: | |
2094 * A reply. We are a client, and a server has sent this message | |
2095 * in response to a COPYDATA_EXPR that failed to evaluate. | |
2096 */ | |
2097 COPYDATASTRUCT *data = (COPYDATASTRUCT*)lParam; | |
2098 HWND sender = (HWND)wParam; | |
2099 COPYDATASTRUCT reply; | |
2100 char_u *res; | |
2101 int retval; | |
39 | 2102 char_u *str; |
2103 char_u *tofree; | |
7 | 2104 |
2105 switch (data->dwData) | |
2106 { | |
39 | 2107 case COPYDATA_ENCODING: |
2108 /* Remember the encoding that the client uses. */ | |
2109 vim_free(client_enc); | |
2110 client_enc = enc_canonize((char_u *)data->lpData); | |
2111 return 1; | |
2112 | |
7 | 2113 case COPYDATA_KEYS: |
2114 /* Remember who sent this, for <client> */ | |
2115 clientWindow = sender; | |
2116 | |
2117 /* Add the received keys to the input buffer. The loop waiting | |
2118 * for the user to do something should check the input buffer. */ | |
39 | 2119 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2120 server_to_input_buf(str); | |
2121 vim_free(tofree); | |
7 | 2122 |
2123 # ifdef FEAT_GUI | |
2124 /* Wake up the main GUI loop. */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2125 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2126 if (gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2127 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2128 if (s_hwnd != 0) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2129 PostMessage(s_hwnd, WM_NULL, 0, 0); |
7 | 2130 # endif |
2131 return 1; | |
2132 | |
2133 case COPYDATA_EXPR: | |
2134 /* Remember who sent this, for <client> */ | |
2135 clientWindow = sender; | |
2136 | |
39 | 2137 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2138 res = eval_client_expr_to_string(str); | |
2139 | |
7 | 2140 if (res == NULL) |
2141 { | |
11175
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2142 char *err = _(e_invexprmsg); |
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2143 size_t len = STRLEN(str) + STRLEN(err) + 5; |
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2144 |
11215
2e4877acfe0a
patch 8.0.0494: build failure with older compiler on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11211
diff
changeset
|
2145 res = alloc((unsigned)len); |
11175
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2146 if (res != NULL) |
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2147 vim_snprintf((char *)res, len, "%s: \"%s\"", err, str); |
7 | 2148 reply.dwData = COPYDATA_ERROR_RESULT; |
2149 } | |
2150 else | |
2151 reply.dwData = COPYDATA_RESULT; | |
2152 reply.lpData = res; | |
835 | 2153 reply.cbData = (DWORD)STRLEN(res) + 1; |
7 | 2154 |
39 | 2155 serverSendEnc(sender); |
4932
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
2156 retval = (int)SendMessage(sender, WM_COPYDATA, |
1cf02fbe6281
updated for version 7.3.1211
Bram Moolenaar <bram@vim.org>
parents:
4926
diff
changeset
|
2157 (WPARAM)message_window, (LPARAM)(&reply)); |
11175
9836b701afd9
patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2158 vim_free(tofree); |
7 | 2159 vim_free(res); |
2160 return retval; | |
2161 | |
2162 case COPYDATA_REPLY: | |
2163 case COPYDATA_RESULT: | |
2164 case COPYDATA_ERROR_RESULT: | |
2165 if (data->lpData != NULL) | |
2166 { | |
39 | 2167 str = serverConvert(client_enc, (char_u *)data->lpData, |
2168 &tofree); | |
2169 if (tofree == NULL) | |
2170 str = vim_strsave(str); | |
2171 if (save_reply(sender, str, | |
7 | 2172 (data->dwData == COPYDATA_REPLY ? 0 : |
2173 (data->dwData == COPYDATA_RESULT ? 1 : | |
39 | 2174 2))) == FAIL) |
2175 vim_free(str); | |
2176 else if (data->dwData == COPYDATA_REPLY) | |
7 | 2177 { |
4926
784e342ddcae
updated for version 7.3.1208
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2178 char_u winstr[30]; |
784e342ddcae
updated for version 7.3.1208
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2179 |
840 | 2180 sprintf((char *)winstr, PRINTF_HEX_LONG_U, (long_u)sender); |
39 | 2181 apply_autocmds(EVENT_REMOTEREPLY, winstr, str, |
7 | 2182 TRUE, curbuf); |
2183 } | |
2184 } | |
2185 return 1; | |
2186 } | |
2187 | |
2188 return 0; | |
2189 } | |
2190 | |
2191 else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) | |
2192 { | |
2193 /* When the message window is activated (brought to the foreground), | |
2194 * this actually applies to the text window. */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2195 #if !defined(FEAT_GUI) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2196 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2197 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2198 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2199 GetConsoleHwnd(); /* get value of s_hwnd */ |
7 | 2200 #endif |
2201 if (s_hwnd != 0) | |
2202 { | |
2203 SetForegroundWindow(s_hwnd); | |
2204 return 0; | |
2205 } | |
2206 } | |
2207 | |
2208 return DefWindowProc(hwnd, msg, wParam, lParam); | |
2209 } | |
2210 | |
2211 /* | |
2212 * Initialise the message handling process. This involves creating a window | |
2213 * to handle messages - the window will not be visible. | |
2214 */ | |
2215 void | |
2216 serverInitMessaging(void) | |
2217 { | |
2218 WNDCLASS wndclass; | |
2219 | |
2220 /* Clean up on exit */ | |
2221 atexit(CleanUpMessaging); | |
2222 | |
2223 /* Register a window class - we only really care | |
2224 * about the window procedure | |
2225 */ | |
2226 wndclass.style = 0; | |
2227 wndclass.lpfnWndProc = Messaging_WndProc; | |
2228 wndclass.cbClsExtra = 0; | |
2229 wndclass.cbWndExtra = 0; | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2230 wndclass.hInstance = g_hinst; |
7 | 2231 wndclass.hIcon = NULL; |
2232 wndclass.hCursor = NULL; | |
2233 wndclass.hbrBackground = NULL; | |
2234 wndclass.lpszMenuName = NULL; | |
2235 wndclass.lpszClassName = VIM_CLASSNAME; | |
2236 RegisterClass(&wndclass); | |
2237 | |
2238 /* Create the message window. It will be hidden, so the details don't | |
2239 * matter. Don't use WS_OVERLAPPEDWINDOW, it will make a shortcut remove | |
2240 * focus from gvim. */ | |
2241 message_window = CreateWindow(VIM_CLASSNAME, "", | |
2242 WS_POPUPWINDOW | WS_CAPTION, | |
2243 CW_USEDEFAULT, CW_USEDEFAULT, | |
2244 100, 100, NULL, NULL, | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2245 g_hinst, NULL); |
7 | 2246 } |
2247 | |
844 | 2248 /* Used by serverSendToVim() to find an alternate server name. */ |
2249 static char_u *altname_buf_ptr = NULL; | |
2250 | |
7 | 2251 /* |
2252 * Get the title of the window "hwnd", which is the Vim server name, in | |
2253 * "name[namelen]" and return the length. | |
2254 * Returns zero if window "hwnd" is not a Vim server. | |
2255 */ | |
2256 static int | |
2257 getVimServerName(HWND hwnd, char *name, int namelen) | |
2258 { | |
2259 int len; | |
2260 char buffer[VIM_CLASSNAME_LEN + 1]; | |
2261 | |
2262 /* Ignore windows which aren't Vim message windows */ | |
2263 len = GetClassName(hwnd, buffer, sizeof(buffer)); | |
2264 if (len != VIM_CLASSNAME_LEN || STRCMP(buffer, VIM_CLASSNAME) != 0) | |
2265 return 0; | |
2266 | |
2267 /* Get the title of the window */ | |
2268 return GetWindowText(hwnd, name, namelen); | |
2269 } | |
2270 | |
2271 static BOOL CALLBACK | |
2272 enumWindowsGetServer(HWND hwnd, LPARAM lparam) | |
2273 { | |
2274 struct server_id *id = (struct server_id *)lparam; | |
2275 char server[MAX_PATH]; | |
2276 | |
2277 /* Get the title of the window */ | |
2278 if (getVimServerName(hwnd, server, sizeof(server)) == 0) | |
2279 return TRUE; | |
2280 | |
2281 /* If this is the server we're looking for, return its HWND */ | |
2282 if (STRICMP(server, id->name) == 0) | |
2283 { | |
2284 id->hwnd = hwnd; | |
2285 return FALSE; | |
2286 } | |
2287 | |
844 | 2288 /* If we are looking for an alternate server, remember this name. */ |
2289 if (altname_buf_ptr != NULL | |
2290 && STRNICMP(server, id->name, STRLEN(id->name)) == 0 | |
2291 && vim_isdigit(server[STRLEN(id->name)])) | |
2292 { | |
2293 STRCPY(altname_buf_ptr, server); | |
2294 altname_buf_ptr = NULL; /* don't use another name */ | |
2295 } | |
2296 | |
7 | 2297 /* Otherwise, keep looking */ |
2298 return TRUE; | |
2299 } | |
2300 | |
2301 static BOOL CALLBACK | |
2302 enumWindowsGetNames(HWND hwnd, LPARAM lparam) | |
2303 { | |
2304 garray_T *ga = (garray_T *)lparam; | |
2305 char server[MAX_PATH]; | |
2306 | |
2307 /* Get the title of the window */ | |
2308 if (getVimServerName(hwnd, server, sizeof(server)) == 0) | |
2309 return TRUE; | |
2310 | |
2311 /* Add the name to the list */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2312 ga_concat(ga, (char_u *)server); |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2313 ga_concat(ga, (char_u *)"\n"); |
7 | 2314 return TRUE; |
2315 } | |
2316 | |
14901
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2317 struct enum_windows_s |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2318 { |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2319 WNDENUMPROC lpEnumFunc; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2320 LPARAM lParam; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2321 }; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2322 |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2323 static BOOL CALLBACK |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2324 enum_windows_child(HWND hwnd, LPARAM lParam) |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2325 { |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2326 struct enum_windows_s *ew = (struct enum_windows_s *)lParam; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2327 |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2328 return (ew->lpEnumFunc)(hwnd, ew->lParam); |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2329 } |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2330 |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2331 static BOOL CALLBACK |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2332 enum_windows_toplevel(HWND hwnd, LPARAM lParam) |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2333 { |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2334 struct enum_windows_s *ew = (struct enum_windows_s *)lParam; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2335 |
14907
497009f367ea
patch 8.1.0465: client-server test fails
Bram Moolenaar <Bram@vim.org>
parents:
14901
diff
changeset
|
2336 if ((ew->lpEnumFunc)(hwnd, ew->lParam)) |
497009f367ea
patch 8.1.0465: client-server test fails
Bram Moolenaar <Bram@vim.org>
parents:
14901
diff
changeset
|
2337 return TRUE; |
14901
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2338 return EnumChildWindows(hwnd, enum_windows_child, lParam); |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2339 } |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2340 |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2341 /* Enumerate all windows including children. */ |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2342 static BOOL |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2343 enum_windows(WNDENUMPROC lpEnumFunc, LPARAM lParam) |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2344 { |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2345 struct enum_windows_s ew; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2346 |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2347 ew.lpEnumFunc = lpEnumFunc; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2348 ew.lParam = lParam; |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2349 return EnumWindows(enum_windows_toplevel, (LPARAM)&ew); |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2350 } |
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2351 |
7 | 2352 static HWND |
2353 findServer(char_u *name) | |
2354 { | |
2355 struct server_id id; | |
2356 | |
2357 id.name = name; | |
2358 id.hwnd = 0; | |
2359 | |
14901
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2360 enum_windows(enumWindowsGetServer, (LPARAM)(&id)); |
7 | 2361 |
2362 return id.hwnd; | |
2363 } | |
2364 | |
2365 void | |
2366 serverSetName(char_u *name) | |
2367 { | |
2368 char_u *ok_name; | |
2369 HWND hwnd = 0; | |
2370 int i = 0; | |
2371 char_u *p; | |
2372 | |
2373 /* Leave enough space for a 9-digit suffix to ensure uniqueness! */ | |
835 | 2374 ok_name = alloc((unsigned)STRLEN(name) + 10); |
7 | 2375 |
2376 STRCPY(ok_name, name); | |
2377 p = ok_name + STRLEN(name); | |
2378 | |
2379 for (;;) | |
2380 { | |
2381 /* This is inefficient - we're doing an EnumWindows loop for each | |
2382 * possible name. It would be better to grab all names in one go, | |
2383 * and scan the list each time... | |
2384 */ | |
2385 hwnd = findServer(ok_name); | |
2386 if (hwnd == 0) | |
2387 break; | |
2388 | |
2389 ++i; | |
2390 if (i >= 1000) | |
2391 break; | |
2392 | |
2393 sprintf((char *)p, "%d", i); | |
2394 } | |
2395 | |
2396 if (hwnd != 0) | |
2397 vim_free(ok_name); | |
2398 else | |
2399 { | |
2400 /* Remember the name */ | |
2401 serverName = ok_name; | |
2402 #ifdef FEAT_TITLE | |
2403 need_maketitle = TRUE; /* update Vim window title later */ | |
2404 #endif | |
2405 | |
2406 /* Update the message window title */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
2407 SetWindowText(message_window, (LPCSTR)ok_name); |
7 | 2408 |
2409 #ifdef FEAT_EVAL | |
2410 /* Set the servername variable */ | |
2411 set_vim_var_string(VV_SEND_SERVER, serverName, -1); | |
2412 #endif | |
2413 } | |
2414 } | |
2415 | |
2416 char_u * | |
2417 serverGetVimNames(void) | |
2418 { | |
2419 garray_T ga; | |
2420 | |
2421 ga_init2(&ga, 1, 100); | |
2422 | |
14901
014d916ab258
patch 8.1.0462: when using ConPTY Vim can be a child process
Bram Moolenaar <Bram@vim.org>
parents:
14479
diff
changeset
|
2423 enum_windows(enumWindowsGetNames, (LPARAM)(&ga)); |
21 | 2424 ga_append(&ga, NUL); |
7 | 2425 |
2426 return ga.ga_data; | |
2427 } | |
2428 | |
2429 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2430 serverSendReply( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2431 char_u *name, /* Where to send. */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2432 char_u *reply) /* What to send. */ |
7 | 2433 { |
2434 HWND target; | |
2435 COPYDATASTRUCT data; | |
840 | 2436 long_u n = 0; |
7 | 2437 |
2438 /* The "name" argument is a magic cookie obtained from expand("<client>"). | |
2439 * It should be of the form 0xXXXXX - i.e. a C hex literal, which is the | |
2440 * value of the client's message window HWND. | |
2441 */ | |
840 | 2442 sscanf((char *)name, SCANF_HEX_LONG_U, &n); |
7 | 2443 if (n == 0) |
2444 return -1; | |
2445 | |
2446 target = (HWND)n; | |
2447 if (!IsWindow(target)) | |
2448 return -1; | |
2449 | |
2450 data.dwData = COPYDATA_REPLY; | |
835 | 2451 data.cbData = (DWORD)STRLEN(reply) + 1; |
7 | 2452 data.lpData = reply; |
2453 | |
39 | 2454 serverSendEnc(target); |
7 | 2455 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, |
2456 (LPARAM)(&data))) | |
2457 return 0; | |
2458 | |
2459 return -1; | |
2460 } | |
2461 | |
2462 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2463 serverSendToVim( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2464 char_u *name, /* Where to send. */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2465 char_u *cmd, /* What to send. */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2466 char_u **result, /* Result of eval'ed expression */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2467 void *ptarget, /* HWND of server */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2468 int asExpr, /* Expression or keys? */ |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2469 int timeout, /* timeout in seconds or zero */ |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2470 int silent) /* don't complain about no server */ |
7 | 2471 { |
844 | 2472 HWND target; |
7 | 2473 COPYDATASTRUCT data; |
2474 char_u *retval = NULL; | |
2475 int retcode = 0; | |
844 | 2476 char_u altname_buf[MAX_PATH]; |
2477 | |
11177
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11175
diff
changeset
|
2478 /* Execute locally if no display or target is ourselves */ |
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11175
diff
changeset
|
2479 if (serverName != NULL && STRICMP(name, serverName) == 0) |
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11175
diff
changeset
|
2480 return sendToLocalVim(cmd, asExpr, result); |
76fb679a310e
patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents:
11175
diff
changeset
|
2481 |
844 | 2482 /* If the server name does not end in a digit then we look for an |
2483 * alternate name. e.g. when "name" is GVIM the we may find GVIM2. */ | |
2484 if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) | |
2485 altname_buf_ptr = altname_buf; | |
2486 altname_buf[0] = NUL; | |
2487 target = findServer(name); | |
2488 altname_buf_ptr = NULL; | |
2489 if (target == 0 && altname_buf[0] != NUL) | |
2490 /* Use another server name we found. */ | |
2491 target = findServer(altname_buf); | |
7 | 2492 |
2493 if (target == 0) | |
2494 { | |
2495 if (!silent) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
2496 semsg(_(e_noserver), name); |
7 | 2497 return -1; |
2498 } | |
2499 | |
2500 if (ptarget) | |
2501 *(HWND *)ptarget = target; | |
2502 | |
2503 data.dwData = asExpr ? COPYDATA_EXPR : COPYDATA_KEYS; | |
835 | 2504 data.cbData = (DWORD)STRLEN(cmd) + 1; |
7 | 2505 data.lpData = cmd; |
2506 | |
39 | 2507 serverSendEnc(target); |
7 | 2508 if (SendMessage(target, WM_COPYDATA, (WPARAM)message_window, |
2509 (LPARAM)(&data)) == 0) | |
2510 return -1; | |
2511 | |
2512 if (asExpr) | |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2513 retval = serverGetReply(target, &retcode, TRUE, TRUE, timeout); |
7 | 2514 |
2515 if (result == NULL) | |
2516 vim_free(retval); | |
2517 else | |
2518 *result = retval; /* Caller assumes responsibility for freeing */ | |
2519 | |
2520 return retcode; | |
2521 } | |
2522 | |
2523 /* | |
2524 * Bring the server to the foreground. | |
2525 */ | |
2526 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
2527 serverForeground(char_u *name) |
7 | 2528 { |
2529 HWND target = findServer(name); | |
2530 | |
2531 if (target != 0) | |
2532 SetForegroundWindow(target); | |
2533 } | |
2534 | |
2535 /* Replies from server need to be stored until the client picks them up via | |
2536 * remote_read(). So we maintain a list of server-id/reply pairs. | |
2537 * Note that there could be multiple replies from one server pending if the | |
2538 * client is slow picking them up. | |
2539 * We just store the replies in a simple list. When we remove an entry, we | |
2540 * move list entries down to fill the gap. | |
2541 * The server ID is simply the HWND. | |
2542 */ | |
2543 typedef struct | |
2544 { | |
2545 HWND server; /* server window */ | |
2546 char_u *reply; /* reply string */ | |
2547 int expr_result; /* 0 for REPLY, 1 for RESULT 2 for error */ | |
323 | 2548 } reply_T; |
7 | 2549 |
2550 static garray_T reply_list = {0, 0, sizeof(reply_T), 5, 0}; | |
2551 | |
2552 #define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i)) | |
2553 #define REPLY_COUNT (reply_list.ga_len) | |
2554 | |
2555 /* Flag which is used to wait for a reply */ | |
2556 static int reply_received = 0; | |
2557 | |
39 | 2558 /* |
2559 * Store a reply. "reply" must be allocated memory (or NULL). | |
2560 */ | |
7 | 2561 static int |
2562 save_reply(HWND server, char_u *reply, int expr) | |
2563 { | |
2564 reply_T *rep; | |
2565 | |
2566 if (ga_grow(&reply_list, 1) == FAIL) | |
2567 return FAIL; | |
2568 | |
2569 rep = REPLY_ITEM(REPLY_COUNT); | |
2570 rep->server = server; | |
39 | 2571 rep->reply = reply; |
7 | 2572 rep->expr_result = expr; |
2573 if (rep->reply == NULL) | |
2574 return FAIL; | |
2575 | |
2576 ++REPLY_COUNT; | |
2577 reply_received = 1; | |
2578 return OK; | |
2579 } | |
2580 | |
2581 /* | |
2582 * Get a reply from server "server". | |
2583 * When "expr_res" is non NULL, get the result of an expression, otherwise a | |
2584 * server2client() message. | |
2585 * When non NULL, point to return code. 0 => OK, -1 => ERROR | |
2586 * If "remove" is TRUE, consume the message, the caller must free it then. | |
2587 * if "wait" is TRUE block until a message arrives (or the server exits). | |
2588 */ | |
2589 char_u * | |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2590 serverGetReply(HWND server, int *expr_res, int remove, int wait, int timeout) |
7 | 2591 { |
2592 int i; | |
2593 char_u *reply; | |
2594 reply_T *rep; | |
11187
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2595 int did_process = FALSE; |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2596 time_t start; |
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2597 time_t now; |
7 | 2598 |
2599 /* When waiting, loop until the message waiting for is received. */ | |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2600 time(&start); |
7 | 2601 for (;;) |
2602 { | |
2603 /* Reset this here, in case a message arrives while we are going | |
2604 * through the already received messages. */ | |
2605 reply_received = 0; | |
2606 | |
2607 for (i = 0; i < REPLY_COUNT; ++i) | |
2608 { | |
2609 rep = REPLY_ITEM(i); | |
2610 if (rep->server == server | |
2611 && ((rep->expr_result != 0) == (expr_res != NULL))) | |
2612 { | |
2613 /* Save the values we've found for later */ | |
2614 reply = rep->reply; | |
2615 if (expr_res != NULL) | |
2616 *expr_res = rep->expr_result == 1 ? 0 : -1; | |
2617 | |
2618 if (remove) | |
2619 { | |
2620 /* Move the rest of the list down to fill the gap */ | |
2621 mch_memmove(rep, rep + 1, | |
2622 (REPLY_COUNT - i - 1) * sizeof(reply_T)); | |
2623 --REPLY_COUNT; | |
2624 } | |
2625 | |
2626 /* Return the reply to the caller, who takes on responsibility | |
2627 * for freeing it if "remove" is TRUE. */ | |
2628 return reply; | |
2629 } | |
2630 } | |
2631 | |
2632 /* If we got here, we didn't find a reply. Return immediately if the | |
2633 * "wait" parameter isn't set. */ | |
2634 if (!wait) | |
11187
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2635 { |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2636 /* Process pending messages once. Without this, looping on |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2637 * remote_peek() would never get the reply. */ |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2638 if (!did_process) |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2639 { |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2640 did_process = TRUE; |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2641 serverProcessPendingMessages(); |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2642 continue; |
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2643 } |
7 | 2644 break; |
11187
515db00c4676
patch 8.0.0480: the remote_peek() test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11181
diff
changeset
|
2645 } |
7 | 2646 |
2647 /* We need to wait for a reply. Enter a message loop until the | |
2648 * "reply_received" flag gets set. */ | |
2649 | |
2650 /* Loop until we receive a reply */ | |
2651 while (reply_received == 0) | |
2652 { | |
11181
13544aa85dc0
patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents:
11177
diff
changeset
|
2653 #ifdef FEAT_TIMERS |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12054
diff
changeset
|
2654 /* TODO: use the return value to decide how long to wait. */ |
11181
13544aa85dc0
patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents:
11177
diff
changeset
|
2655 check_due_timer(); |
13544aa85dc0
patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents:
11177
diff
changeset
|
2656 #endif |
11211
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2657 time(&now); |
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2658 if (timeout > 0 && (now - start) >= timeout) |
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2659 break; |
71311d899b42
patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents:
11187
diff
changeset
|
2660 |
7 | 2661 /* Wait for a SendMessage() call to us. This could be the reply |
2662 * we are waiting for. Use a timeout of a second, to catch the | |
2663 * situation that the server died unexpectedly. */ | |
2664 MsgWaitForMultipleObjects(0, NULL, TRUE, 1000, QS_ALLINPUT); | |
2665 | |
2666 /* If the server has died, give up */ | |
2667 if (!IsWindow(server)) | |
2668 return NULL; | |
2669 | |
2670 serverProcessPendingMessages(); | |
2671 } | |
2672 } | |
2673 | |
2674 return NULL; | |
2675 } | |
2676 | |
2677 /* | |
2678 * Process any messages in the Windows message queue. | |
2679 */ | |
2680 void | |
2681 serverProcessPendingMessages(void) | |
2682 { | |
2683 MSG msg; | |
2684 | |
3010 | 2685 while (pPeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) |
7 | 2686 { |
2687 TranslateMessage(&msg); | |
3010 | 2688 pDispatchMessage(&msg); |
7 | 2689 } |
2690 } | |
2691 | |
2692 #endif /* FEAT_CLIENTSERVER */ | |
2693 | |
2694 #if defined(FEAT_GUI) || (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) \ | |
2695 || defined(PROTO) | |
2696 | |
2697 struct charset_pair | |
2698 { | |
2699 char *name; | |
2700 BYTE charset; | |
2701 }; | |
2702 | |
2703 static struct charset_pair | |
2704 charset_pairs[] = | |
2705 { | |
2706 {"ANSI", ANSI_CHARSET}, | |
2707 {"CHINESEBIG5", CHINESEBIG5_CHARSET}, | |
2708 {"DEFAULT", DEFAULT_CHARSET}, | |
2709 {"HANGEUL", HANGEUL_CHARSET}, | |
2710 {"OEM", OEM_CHARSET}, | |
2711 {"SHIFTJIS", SHIFTJIS_CHARSET}, | |
2712 {"SYMBOL", SYMBOL_CHARSET}, | |
2713 {"ARABIC", ARABIC_CHARSET}, | |
2714 {"BALTIC", BALTIC_CHARSET}, | |
2715 {"EASTEUROPE", EASTEUROPE_CHARSET}, | |
2716 {"GB2312", GB2312_CHARSET}, | |
2717 {"GREEK", GREEK_CHARSET}, | |
2718 {"HEBREW", HEBREW_CHARSET}, | |
2719 {"JOHAB", JOHAB_CHARSET}, | |
2720 {"MAC", MAC_CHARSET}, | |
2721 {"RUSSIAN", RUSSIAN_CHARSET}, | |
2722 {"THAI", THAI_CHARSET}, | |
2723 {"TURKISH", TURKISH_CHARSET}, | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2724 #ifdef VIETNAMESE_CHARSET |
7 | 2725 {"VIETNAMESE", VIETNAMESE_CHARSET}, |
2726 #endif | |
2727 {NULL, 0} | |
2728 }; | |
2729 | |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2730 struct quality_pair |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2731 { |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2732 char *name; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2733 DWORD quality; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2734 }; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2735 |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2736 static struct quality_pair |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2737 quality_pairs[] = { |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2738 #ifdef CLEARTYPE_QUALITY |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2739 {"CLEARTYPE", CLEARTYPE_QUALITY}, |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2740 #endif |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2741 #ifdef ANTIALIASED_QUALITY |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2742 {"ANTIALIASED", ANTIALIASED_QUALITY}, |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2743 #endif |
9091
294cfd18e9c7
commit https://github.com/vim/vim/commit/73a733e08bb7853d2ac12c60756ae51e39abb4d9
Christian Brabandt <cb@256bit.org>
parents:
8843
diff
changeset
|
2744 #ifdef NONANTIALIASED_QUALITY |
294cfd18e9c7
commit https://github.com/vim/vim/commit/73a733e08bb7853d2ac12c60756ae51e39abb4d9
Christian Brabandt <cb@256bit.org>
parents:
8843
diff
changeset
|
2745 {"NONANTIALIASED", NONANTIALIASED_QUALITY}, |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2746 #endif |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2747 #ifdef PROOF_QUALITY |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2748 {"PROOF", PROOF_QUALITY}, |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2749 #endif |
8843
87a6a0d65788
commit https://github.com/vim/vim/commit/4c9ce053d9f2a94cd704342dd4c25670a5995cbd
Christian Brabandt <cb@256bit.org>
parents:
8835
diff
changeset
|
2750 #ifdef DRAFT_QUALITY |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2751 {"DRAFT", DRAFT_QUALITY}, |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2752 #endif |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2753 {"DEFAULT", DEFAULT_QUALITY}, |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2754 {NULL, 0} |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2755 }; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2756 |
7 | 2757 /* |
2758 * Convert a charset ID to a name. | |
2759 * Return NULL when not recognized. | |
2760 */ | |
2761 char * | |
2762 charset_id2name(int id) | |
2763 { | |
2764 struct charset_pair *cp; | |
2765 | |
2766 for (cp = charset_pairs; cp->name != NULL; ++cp) | |
2767 if ((BYTE)id == cp->charset) | |
2768 break; | |
2769 return cp->name; | |
2770 } | |
2771 | |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2772 /* |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2773 * Convert a quality ID to a name. |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2774 * Return NULL when not recognized. |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2775 */ |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2776 char * |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2777 quality_id2name(DWORD id) |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2778 { |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2779 struct quality_pair *qp; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2780 |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2781 for (qp = quality_pairs; qp->name != NULL; ++qp) |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2782 if (id == qp->quality) |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2783 break; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2784 return qp->name; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2785 } |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2786 |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2787 static const LOGFONTW s_lfDefault = |
7 | 2788 { |
2789 -12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, | |
2790 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, | |
2791 PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2792 L"Fixedsys" /* see _ReadVimIni */ |
7 | 2793 }; |
2794 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2795 // Initialise the "current height" to -12 (same as s_lfDefault) just |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2796 // in case the user specifies a font in "guifont" with no size before a font |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2797 // with an explicit size has been set. This defaults the size to this value |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2798 // (-12 equates to roughly 9pt). |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16439
diff
changeset
|
2799 int current_font_height = -12; // also used in gui_w32.c |
7 | 2800 |
2801 /* Convert a string representing a point size into pixels. The string should | |
2802 * be a positive decimal number, with an optional decimal point (eg, "12", or | |
2803 * "10.5"). The pixel value is returned, and a pointer to the next unconverted | |
2804 * character is stored in *end. The flag "vertical" says whether this | |
2805 * calculation is for a vertical (height) size or a horizontal (width) one. | |
2806 */ | |
2807 static int | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2808 points_to_pixels(WCHAR *str, WCHAR **end, int vertical, long_i pprinter_dc) |
7 | 2809 { |
2810 int pixels; | |
2811 int points = 0; | |
2812 int divisor = 0; | |
2813 HWND hwnd = (HWND)0; | |
2814 HDC hdc; | |
2815 HDC printer_dc = (HDC)pprinter_dc; | |
2816 | |
2817 while (*str != NUL) | |
2818 { | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2819 if (*str == L'.' && divisor == 0) |
7 | 2820 { |
2821 /* Start keeping a divisor, for later */ | |
2822 divisor = 1; | |
2823 } | |
2824 else | |
2825 { | |
2826 if (!VIM_ISDIGIT(*str)) | |
2827 break; | |
2828 | |
2829 points *= 10; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2830 points += *str - L'0'; |
7 | 2831 divisor *= 10; |
2832 } | |
2833 ++str; | |
2834 } | |
2835 | |
2836 if (divisor == 0) | |
2837 divisor = 1; | |
2838 | |
2839 if (printer_dc == NULL) | |
2840 { | |
2841 hwnd = GetDesktopWindow(); | |
2842 hdc = GetWindowDC(hwnd); | |
2843 } | |
2844 else | |
2845 hdc = printer_dc; | |
2846 | |
2847 pixels = MulDiv(points, | |
2848 GetDeviceCaps(hdc, vertical ? LOGPIXELSY : LOGPIXELSX), | |
2849 72 * divisor); | |
2850 | |
2851 if (printer_dc == NULL) | |
2852 ReleaseDC(hwnd, hdc); | |
2853 | |
2854 *end = str; | |
2855 return pixels; | |
2856 } | |
2857 | |
2858 static int CALLBACK | |
2859 font_enumproc( | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2860 ENUMLOGFONTW *elf, |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2861 NEWTEXTMETRICW *ntm UNUSED, |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2862 DWORD type UNUSED, |
7 | 2863 LPARAM lparam) |
2864 { | |
2865 /* Return value: | |
2866 * 0 = terminate now (monospace & ANSI) | |
2867 * 1 = continue, still no luck... | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2868 * 2 = continue, but we have an acceptable LOGFONTW |
7 | 2869 * (monospace, not ANSI) |
2870 * We use these values, as EnumFontFamilies returns 1 if the | |
2871 * callback function is never called. So, we check the return as | |
2872 * 0 = perfect, 2 = OK, 1 = no good... | |
2873 * It's not pretty, but it works! | |
2874 */ | |
2875 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2876 LOGFONTW *lf = (LOGFONTW *)(lparam); |
7 | 2877 |
2878 #ifndef FEAT_PROPORTIONAL_FONTS | |
2879 /* Ignore non-monospace fonts without further ado */ | |
2880 if ((ntm->tmPitchAndFamily & 1) != 0) | |
2881 return 1; | |
2882 #endif | |
2883 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2884 /* Remember this LOGFONTW as a "possible" */ |
7 | 2885 *lf = elf->elfLogFont; |
2886 | |
2887 /* Terminate the scan as soon as we find an ANSI font */ | |
2888 if (lf->lfCharSet == ANSI_CHARSET | |
2889 || lf->lfCharSet == OEM_CHARSET | |
2890 || lf->lfCharSet == DEFAULT_CHARSET) | |
2891 return 0; | |
2892 | |
2893 /* Continue the scan - we have a non-ANSI font */ | |
2894 return 2; | |
2895 } | |
2896 | |
2897 static int | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2898 init_logfont(LOGFONTW *lf) |
7 | 2899 { |
2900 int n; | |
2901 HWND hwnd = GetDesktopWindow(); | |
2902 HDC hdc = GetWindowDC(hwnd); | |
2903 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2904 n = EnumFontFamiliesW(hdc, |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2905 lf->lfFaceName, |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2906 (FONTENUMPROCW)font_enumproc, |
7 | 2907 (LPARAM)lf); |
2908 | |
2909 ReleaseDC(hwnd, hdc); | |
2910 | |
4352 | 2911 /* If we couldn't find a usable font, return failure */ |
7 | 2912 if (n == 1) |
2913 return FAIL; | |
2914 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2915 /* Tidy up the rest of the LOGFONTW structure. We set to a basic |
7 | 2916 * font - get_logfont() sets bold, italic, etc based on the user's |
2917 * input. | |
2918 */ | |
2919 lf->lfHeight = current_font_height; | |
2920 lf->lfWidth = 0; | |
2921 lf->lfItalic = FALSE; | |
2922 lf->lfUnderline = FALSE; | |
2923 lf->lfStrikeOut = FALSE; | |
2924 lf->lfWeight = FW_NORMAL; | |
2925 | |
2926 /* Return success */ | |
2927 return OK; | |
2928 } | |
2929 | |
37 | 2930 /* |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2931 * Compare a UTF-16 string and an ASCII string literally. |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2932 * Only works all the code points are inside ASCII range. |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2933 */ |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2934 static int |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2935 utf16ascncmp(const WCHAR *w, const char *p, size_t n) |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2936 { |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2937 size_t i; |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2938 |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2939 for (i = 0; i < n; i++) |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2940 { |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2941 if (w[i] == 0 || w[i] != p[i]) |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2942 return w[i] - p[i]; |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2943 } |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2944 return 0; |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2945 } |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2946 |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2947 /* |
37 | 2948 * Get font info from "name" into logfont "lf". |
2949 * Return OK for a valid name, FAIL otherwise. | |
2950 */ | |
7 | 2951 int |
2952 get_logfont( | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2953 LOGFONTW *lf, |
37 | 2954 char_u *name, |
2955 HDC printer_dc, | |
2956 int verbose) | |
7 | 2957 { |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2958 WCHAR *p; |
7 | 2959 int i; |
5714 | 2960 int ret = FAIL; |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2961 static LOGFONTW *lastlf = NULL; |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2962 WCHAR *wname; |
7 | 2963 |
2964 *lf = s_lfDefault; | |
2965 if (name == NULL) | |
37 | 2966 return OK; |
7 | 2967 |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2968 wname = enc_to_utf16(name, NULL); |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2969 if (wname == NULL) |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2970 return FAIL; |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2971 |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2972 if (wcscmp(wname, L"*") == 0) |
7 | 2973 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
2974 #if defined(FEAT_GUI_MSWIN) |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2975 CHOOSEFONTW cf; |
7 | 2976 /* if name is "*", bring up std font dialog: */ |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
1936
diff
changeset
|
2977 vim_memset(&cf, 0, sizeof(cf)); |
7 | 2978 cf.lStructSize = sizeof(cf); |
2979 cf.hwndOwner = s_hwnd; | |
2980 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT; | |
2981 if (lastlf != NULL) | |
2982 *lf = *lastlf; | |
2983 cf.lpLogFont = lf; | |
2984 cf.nFontType = 0 ; //REGULAR_FONTTYPE; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2985 if (ChooseFontW(&cf)) |
5714 | 2986 ret = OK; |
7 | 2987 #endif |
5714 | 2988 goto theend; |
7 | 2989 } |
2990 | |
2991 /* | |
2992 * Split name up, it could be <name>:h<height>:w<width> etc. | |
2993 */ | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2994 for (p = wname; *p && *p != L':'; p++) |
7 | 2995 { |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2996 if (p - wname + 1 >= LF_FACESIZE) |
5714 | 2997 goto theend; /* Name too long */ |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2998 lf->lfFaceName[p - wname] = *p; |
7 | 2999 } |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3000 if (p != wname) |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3001 lf->lfFaceName[p - wname] = NUL; |
7 | 3002 |
3003 /* First set defaults */ | |
3004 lf->lfHeight = -12; | |
3005 lf->lfWidth = 0; | |
3006 lf->lfWeight = FW_NORMAL; | |
3007 lf->lfItalic = FALSE; | |
3008 lf->lfUnderline = FALSE; | |
3009 lf->lfStrikeOut = FALSE; | |
3010 | |
3011 /* | |
3012 * If the font can't be found, try replacing '_' by ' '. | |
3013 */ | |
3014 if (init_logfont(lf) == FAIL) | |
3015 { | |
3016 int did_replace = FALSE; | |
3017 | |
3018 for (i = 0; lf->lfFaceName[i]; ++i) | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3019 if (lf->lfFaceName[i] == L'_') |
7 | 3020 { |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3021 lf->lfFaceName[i] = L' '; |
7 | 3022 did_replace = TRUE; |
3023 } | |
3024 if (!did_replace || init_logfont(lf) == FAIL) | |
5714 | 3025 goto theend; |
7 | 3026 } |
3027 | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3028 while (*p == L':') |
7 | 3029 p++; |
3030 | |
3031 /* Set the values found after ':' */ | |
3032 while (*p) | |
3033 { | |
3034 switch (*p++) | |
3035 { | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3036 case L'h': |
840 | 3037 lf->lfHeight = - points_to_pixels(p, &p, TRUE, (long_i)printer_dc); |
7 | 3038 break; |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3039 case L'w': |
840 | 3040 lf->lfWidth = points_to_pixels(p, &p, FALSE, (long_i)printer_dc); |
7 | 3041 break; |
16439
9d20e26dc13c
patch 8.1.1224: MS-Windows: cannot specify font weight
Bram Moolenaar <Bram@vim.org>
parents:
16354
diff
changeset
|
3042 case L'W': |
9d20e26dc13c
patch 8.1.1224: MS-Windows: cannot specify font weight
Bram Moolenaar <Bram@vim.org>
parents:
16354
diff
changeset
|
3043 lf->lfWeight = wcstol(p, &p, 10); |
9d20e26dc13c
patch 8.1.1224: MS-Windows: cannot specify font weight
Bram Moolenaar <Bram@vim.org>
parents:
16354
diff
changeset
|
3044 break; |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3045 case L'b': |
7 | 3046 lf->lfWeight = FW_BOLD; |
3047 break; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3048 case L'i': |
7 | 3049 lf->lfItalic = TRUE; |
3050 break; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3051 case L'u': |
7 | 3052 lf->lfUnderline = TRUE; |
3053 break; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3054 case L's': |
7 | 3055 lf->lfStrikeOut = TRUE; |
3056 break; | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3057 case L'c': |
7 | 3058 { |
3059 struct charset_pair *cp; | |
3060 | |
3061 for (cp = charset_pairs; cp->name != NULL; ++cp) | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3062 if (utf16ascncmp(p, cp->name, strlen(cp->name)) == 0) |
7 | 3063 { |
3064 lf->lfCharSet = cp->charset; | |
3065 p += strlen(cp->name); | |
3066 break; | |
3067 } | |
37 | 3068 if (cp->name == NULL && verbose) |
7 | 3069 { |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3070 char_u *s = utf16_to_enc(p, NULL); |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3071 semsg(_("E244: Illegal charset name \"%s\" in font name \"%s\""), s, name); |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3072 vim_free(s); |
7 | 3073 break; |
3074 } | |
3075 break; | |
3076 } | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3077 case L'q': |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3078 { |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3079 struct quality_pair *qp; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3080 |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3081 for (qp = quality_pairs; qp->name != NULL; ++qp) |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3082 if (utf16ascncmp(p, qp->name, strlen(qp->name)) == 0) |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3083 { |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3084 lf->lfQuality = qp->quality; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3085 p += strlen(qp->name); |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3086 break; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3087 } |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3088 if (qp->name == NULL && verbose) |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3089 { |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3090 char_u *s = utf16_to_enc(p, NULL); |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3091 semsg(_("E244: Illegal quality name \"%s\" in font name \"%s\""), s, name); |
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3092 vim_free(s); |
8835
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3093 break; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3094 } |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3095 break; |
c1a5623cfc86
commit https://github.com/vim/vim/commit/7c1c6dbb6817640fd3956a0d5417da23fde336d8
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3096 } |
7 | 3097 default: |
37 | 3098 if (verbose) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15195
diff
changeset
|
3099 semsg(_("E245: Illegal char '%c' in font name \"%s\""), p[-1], name); |
5714 | 3100 goto theend; |
7 | 3101 } |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3102 while (*p == L':') |
7 | 3103 p++; |
3104 } | |
5714 | 3105 ret = OK; |
3106 | |
7 | 3107 theend: |
3108 /* ron: init lastlf */ | |
5714 | 3109 if (ret == OK && printer_dc == NULL) |
7 | 3110 { |
3111 vim_free(lastlf); | |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3112 lastlf = (LOGFONTW *)alloc(sizeof(LOGFONTW)); |
7 | 3113 if (lastlf != NULL) |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3114 mch_memmove(lastlf, lf, sizeof(LOGFONTW)); |
7 | 3115 } |
16152
8f4eccaaf2c0
patch 8.1.1081: MS-Windows: cannot use some fonts
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3116 vim_free(wname); |
5714 | 3117 |
3118 return ret; | |
7 | 3119 } |
3120 | |
3121 #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */ | |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3122 |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
3123 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3124 /* |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3125 * Initialize the Winsock dll. |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3126 */ |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3127 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7797
diff
changeset
|
3128 channel_init_winsock(void) |
7797
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3129 { |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3130 WSADATA wsaData; |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3131 int wsaerr; |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3132 |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3133 if (WSInitialized) |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3134 return; |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3135 |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3136 wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData); |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3137 if (wsaerr == 0) |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3138 WSInitialized = TRUE; |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3139 } |
0d46cea25641
commit https://github.com/vim/vim/commit/f12d983deab06b0408781d7a6c2f8970d765b723
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
3140 #endif |