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