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