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