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