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