comparison src/os_mswin.c @ 16451:7ae2396cef62 v8.1.1230

patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe commit https://github.com/vim/vim/commit/afde13b62b8fa25dac4635d5caee8d088b937ee0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 28 19:46:49 2019 +0200 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe Problem: A lot of code is shared between vim.exe and gvim.exe. Solution: Optionally put the shared code in vim.dll. (Ken Takata, closes #4287)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Apr 2019 20:00:10 +0200
parents 9d20e26dc13c
children 7e733046db1d
comparison
equal deleted inserted replaced
16450:bf74bce807e8 16451:7ae2396cef62
127 127
128 #ifdef MCH_WRITE_DUMP 128 #ifdef MCH_WRITE_DUMP
129 FILE* fdDump = NULL; 129 FILE* fdDump = NULL;
130 #endif 130 #endif
131 131
132 #ifndef FEAT_GUI_MSWIN 132 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
133 extern char g_szOrigTitle[]; 133 extern char g_szOrigTitle[];
134 #endif 134 #endif
135 135
136 #ifdef FEAT_GUI 136 #ifdef FEAT_GUI
137 extern HWND s_hwnd; 137 extern HWND s_hwnd;
193 # endif 193 # endif
194 # endif 194 # endif
195 #endif 195 #endif
196 196
197 197
198 #ifndef PROTO
199 /*
200 * Save the instance handle of the exe/dll.
201 */
202 void
203 SaveInst(HINSTANCE hInst)
204 {
205 g_hinst = hInst;
206 }
207 #endif
208
198 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) 209 #if defined(FEAT_GUI_MSWIN) || defined(PROTO)
199 /* 210 /*
200 * GUI version of mch_exit(). 211 * GUI version of mch_exit().
201 * Shut down and exit with status `r' 212 * Shut down and exit with status `r'
202 * Careful: mch_exit() may be called before mch_init()! 213 * Careful: mch_exit() may be called before mch_init()!
203 */ 214 */
204 void 215 void
205 mch_exit(int r) 216 mch_exit_g(int r)
206 { 217 {
207 exiting = TRUE; 218 exiting = TRUE;
208 219
209 display_errors(); 220 display_errors();
210 221
260 */ 271 */
261 int 272 int
262 mch_input_isatty(void) 273 mch_input_isatty(void)
263 { 274 {
264 #ifdef FEAT_GUI_MSWIN 275 #ifdef FEAT_GUI_MSWIN
265 return OK; /* GUI always has a tty */ 276 # ifdef VIMDLL
266 #else 277 if (gui.in_use)
278 # endif
279 return TRUE; /* GUI always has a tty */
280 #endif
281 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
267 if (isatty(read_cmd_fd)) 282 if (isatty(read_cmd_fd))
268 return TRUE; 283 return TRUE;
269 return FALSE; 284 return FALSE;
270 #endif 285 #endif
271 } 286 }
278 mch_settitle( 293 mch_settitle(
279 char_u *title, 294 char_u *title,
280 char_u *icon) 295 char_u *icon)
281 { 296 {
282 # ifdef FEAT_GUI_MSWIN 297 # ifdef FEAT_GUI_MSWIN
283 gui_mch_settitle(title, icon); 298 # ifdef VIMDLL
284 # else 299 if (gui.in_use)
300 # endif
301 {
302 gui_mch_settitle(title, icon);
303 return;
304 }
305 # endif
306 # if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
285 if (title != NULL) 307 if (title != NULL)
286 { 308 {
287 WCHAR *wp = enc_to_utf16(title, NULL); 309 WCHAR *wp = enc_to_utf16(title, NULL);
288 310
289 if (wp == NULL) 311 if (wp == NULL)
305 * SAVE_RESTORE_BOTH: Restore title and icon (which we don't have) 327 * SAVE_RESTORE_BOTH: Restore title and icon (which we don't have)
306 */ 328 */
307 void 329 void
308 mch_restore_title(int which UNUSED) 330 mch_restore_title(int which UNUSED)
309 { 331 {
310 #ifndef FEAT_GUI_MSWIN 332 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
311 SetConsoleTitle(g_szOrigTitle); 333 # ifdef VIMDLL
334 if (!gui.in_use)
335 # endif
336 SetConsoleTitle(g_szOrigTitle);
312 #endif 337 #endif
313 } 338 }
314 339
315 340
316 /* 341 /*
552 n = wstat_symlink_aware(wp, stp); 577 n = wstat_symlink_aware(wp, stp);
553 vim_free(wp); 578 vim_free(wp);
554 return n; 579 return n;
555 } 580 }
556 581
557 #if defined(FEAT_GUI_MSWIN) || defined(PROTO) 582 #if (defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)) || defined(PROTO)
558 void 583 void
559 mch_settmode(int tmode UNUSED) 584 mch_settmode(int tmode UNUSED)
560 { 585 {
561 /* nothing to do */ 586 /* nothing to do */
562 } 587 }
594 suspend_shell(); 619 suspend_shell();
595 } 620 }
596 621
597 #if defined(USE_MCH_ERRMSG) || defined(PROTO) 622 #if defined(USE_MCH_ERRMSG) || defined(PROTO)
598 623
599 #ifdef display_errors 624 # ifdef display_errors
600 # undef display_errors 625 # undef display_errors
601 #endif 626 # endif
602 627
603 #ifdef FEAT_GUI
604 /* 628 /*
605 * Display the saved error message(s). 629 * Display the saved error message(s).
606 */ 630 */
607 void 631 void
608 display_errors(void) 632 display_errors(void)
609 { 633 {
634 # ifdef FEAT_GUI
610 char *p; 635 char *p;
611 636
612 if (error_ga.ga_data != NULL) 637 # ifdef VIMDLL
613 { 638 if (gui.in_use || gui.starting)
614 /* avoid putting up a message box with blanks only */ 639 # endif
615 for (p = (char *)error_ga.ga_data; *p; ++p) 640 {
616 if (!isspace(*p)) 641 if (error_ga.ga_data != NULL)
617 { 642 {
618 (void)gui_mch_dialog( 643 /* avoid putting up a message box with blanks only */
644 for (p = (char *)error_ga.ga_data; *p; ++p)
645 if (!isspace(*p))
646 {
647 (void)gui_mch_dialog(
619 gui.starting ? VIM_INFO : 648 gui.starting ? VIM_INFO :
620 VIM_ERROR, 649 VIM_ERROR,
621 gui.starting ? (char_u *)_("Message") : 650 gui.starting ? (char_u *)_("Message") :
622 (char_u *)_("Error"), 651 (char_u *)_("Error"),
623 (char_u *)p, (char_u *)_("&Ok"), 652 (char_u *)p, (char_u *)_("&Ok"),
624 1, NULL, FALSE); 653 1, NULL, FALSE);
625 break; 654 break;
626 } 655 }
627 ga_clear(&error_ga); 656 ga_clear(&error_ga);
628 } 657 }
629 } 658 return;
630 #else 659 }
631 void 660 # endif
632 display_errors(void) 661 # if !defined(FEAT_GUI) || defined(VIMDLL)
633 {
634 FlushFileBuffers(GetStdHandle(STD_ERROR_HANDLE)); 662 FlushFileBuffers(GetStdHandle(STD_ERROR_HANDLE));
635 } 663 # endif
636 #endif 664 }
637 #endif 665 #endif
638 666
639 667
640 /* 668 /*
641 * Return TRUE if "p" contain a wildcard that can be expanded by 669 * Return TRUE if "p" contain a wildcard that can be expanded by
715 vim_free(p); 743 vim_free(p);
716 return n; 744 return n;
717 } 745 }
718 746
719 747
720 #ifdef FEAT_GUI_MSWIN 748 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
721 /* 749 /*
722 * return non-zero if a character is available 750 * return non-zero if a character is available
723 */ 751 */
724 int 752 int
725 mch_char_avail(void) 753 mch_char_avail(void)
953 OutputDebugString(szBuff); 981 OutputDebugString(szBuff);
954 } 982 }
955 983
956 #endif //_DEBUG 984 #endif //_DEBUG
957 985
958 #if !defined(FEAT_GUI) || defined(PROTO) 986 #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO)
959 # ifdef FEAT_TITLE 987 # ifdef FEAT_TITLE
960 extern HWND g_hWnd; /* This is in os_win32.c. */ 988 extern HWND g_hWnd; /* This is in os_win32.c. */
961 # endif 989 # endif
962 990
963 /* 991 /*
1119 { 1147 {
1120 vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (char_u *)prt_name); 1148 vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (char_u *)prt_name);
1121 VIM_CLEAR(prt_name); 1149 VIM_CLEAR(prt_name);
1122 } 1150 }
1123 EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED); 1151 EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_GRAYED);
1124 #ifndef FEAT_GUI 1152 #if !defined(FEAT_GUI) || defined(VIMDLL)
1125 BringWindowToTop(s_hwnd); 1153 # ifdef VIMDLL
1154 if (!gui.in_use)
1155 # endif
1156 BringWindowToTop(s_hwnd);
1126 #endif 1157 #endif
1127 return TRUE; 1158 return TRUE;
1128 1159
1129 case WM_COMMAND: 1160 case WM_COMMAND:
1130 *bUserAbort = TRUE; 1161 *bUserAbort = TRUE;
1153 } 1184 }
1154 } 1185 }
1155 return !*bUserAbort; 1186 return !*bUserAbort;
1156 } 1187 }
1157 1188
1158 #ifndef FEAT_GUI 1189 #if !defined(FEAT_GUI) || defined(VIMDLL)
1159 1190
1160 static UINT_PTR CALLBACK 1191 static UINT_PTR CALLBACK
1161 PrintHookProc( 1192 PrintHookProc(
1162 HWND hDlg, // handle to dialog box 1193 HWND hDlg, // handle to dialog box
1163 UINT uiMsg, // message identifier 1194 UINT uiMsg, // message identifier
1347 int i; 1378 int i;
1348 1379
1349 bUserAbort = &(psettings->user_abort); 1380 bUserAbort = &(psettings->user_abort);
1350 vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW)); 1381 vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW));
1351 prt_dlg.lStructSize = sizeof(PRINTDLGW); 1382 prt_dlg.lStructSize = sizeof(PRINTDLGW);
1352 #ifndef FEAT_GUI 1383 #if !defined(FEAT_GUI) || defined(VIMDLL)
1353 GetConsoleHwnd(); /* get value of s_hwnd */ 1384 # ifdef VIMDLL
1385 if (!gui.in_use)
1386 # endif
1387 GetConsoleHwnd(); /* get value of s_hwnd */
1354 #endif 1388 #endif
1355 prt_dlg.hwndOwner = s_hwnd; 1389 prt_dlg.hwndOwner = s_hwnd;
1356 prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; 1390 prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC;
1357 if (!forceit) 1391 if (!forceit)
1358 { 1392 {
1359 prt_dlg.hDevMode = stored_dm; 1393 prt_dlg.hDevMode = stored_dm;
1360 prt_dlg.hDevNames = stored_devn; 1394 prt_dlg.hDevNames = stored_devn;
1361 prt_dlg.lCustData = stored_nCopies; // work around bug in print dialog 1395 prt_dlg.lCustData = stored_nCopies; // work around bug in print dialog
1362 #ifndef FEAT_GUI 1396 #if !defined(FEAT_GUI) || defined(VIMDLL)
1363 /* 1397 # ifdef VIMDLL
1364 * Use hook to prevent console window being sent to back 1398 if (!gui.in_use)
1365 */ 1399 # endif
1366 prt_dlg.lpfnPrintHook = PrintHookProc; 1400 {
1367 prt_dlg.Flags |= PD_ENABLEPRINTHOOK; 1401 /*
1402 * Use hook to prevent console window being sent to back
1403 */
1404 prt_dlg.lpfnPrintHook = PrintHookProc;
1405 prt_dlg.Flags |= PD_ENABLEPRINTHOOK;
1406 }
1368 #endif 1407 #endif
1369 prt_dlg.Flags |= stored_nFlags; 1408 prt_dlg.Flags |= stored_nFlags;
1370 } 1409 }
1371 1410
1372 /* 1411 /*
1373 * If bang present, return default printer setup with no dialog 1412 * If bang present, return default printer setup with no dialog
1374 * never show dialog if we are running over telnet 1413 * never show dialog if we are running over telnet
1375 */ 1414 */
1376 if (forceit 1415 if (forceit
1377 #ifndef FEAT_GUI 1416 #if !defined(FEAT_GUI) || defined(VIMDLL)
1417 # ifdef VIMDLL
1418 || (!gui.in_use && !term_console)
1419 # else
1378 || !term_console 1420 || !term_console
1421 # endif
1379 #endif 1422 #endif
1380 ) 1423 )
1381 { 1424 {
1382 prt_dlg.Flags |= PD_RETURNDEFAULT; 1425 prt_dlg.Flags |= PD_RETURNDEFAULT;
1383 /* 1426 /*
1546 { 1589 {
1547 int ret = 0; 1590 int ret = 0;
1548 char szBuffer[300]; 1591 char szBuffer[300];
1549 WCHAR *wp; 1592 WCHAR *wp;
1550 1593
1551 hDlgPrint = CreateDialog(GetModuleHandle(NULL), TEXT("PrintDlgBox"), 1594 hDlgPrint = CreateDialog(g_hinst, TEXT("PrintDlgBox"),
1552 prt_dlg.hwndOwner, PrintDlgProc); 1595 prt_dlg.hwndOwner, PrintDlgProc);
1553 SetAbortProc(prt_dlg.hDC, AbortProc); 1596 SetAbortProc(prt_dlg.hDC, AbortProc);
1554 wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname)); 1597 wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
1555 vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (char_u *)szBuffer); 1598 vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (char_u *)szBuffer);
1556 1599
1566 vim_free(wp); 1609 vim_free(wp);
1567 } 1610 }
1568 1611
1569 #ifdef FEAT_GUI 1612 #ifdef FEAT_GUI
1570 /* Give focus back to main window (when using MDI). */ 1613 /* Give focus back to main window (when using MDI). */
1571 SetFocus(s_hwnd); 1614 # ifdef VIMDLL
1615 if (gui.in_use)
1616 # endif
1617 SetFocus(s_hwnd);
1572 #endif 1618 #endif
1573 1619
1574 return (ret > 0); 1620 return (ret > 0);
1575 } 1621 }
1576 1622
1925 path = resolve_reparse_point(fname); 1971 path = resolve_reparse_point(fname);
1926 return path; 1972 return path;
1927 } 1973 }
1928 #endif 1974 #endif
1929 1975
1930 #if (defined(FEAT_EVAL) && !defined(FEAT_GUI)) || defined(PROTO) 1976 #if (defined(FEAT_EVAL) && (!defined(FEAT_GUI) || defined(VIMDLL))) || defined(PROTO)
1931 /* 1977 /*
1932 * Bring ourselves to the foreground. Does work if the OS doesn't allow it. 1978 * Bring ourselves to the foreground. Does work if the OS doesn't allow it.
1933 */ 1979 */
1934 void 1980 void
1935 win32_set_foreground(void) 1981 win32_set_foreground(void)
1936 { 1982 {
1937 # ifndef FEAT_GUI
1938 GetConsoleHwnd(); /* get value of s_hwnd */ 1983 GetConsoleHwnd(); /* get value of s_hwnd */
1939 # endif
1940 if (s_hwnd != 0) 1984 if (s_hwnd != 0)
1941 SetForegroundWindow(s_hwnd); 1985 SetForegroundWindow(s_hwnd);
1942 } 1986 }
1943 #endif 1987 #endif
1944 1988
2076 server_to_input_buf(str); 2120 server_to_input_buf(str);
2077 vim_free(tofree); 2121 vim_free(tofree);
2078 2122
2079 # ifdef FEAT_GUI 2123 # ifdef FEAT_GUI
2080 /* Wake up the main GUI loop. */ 2124 /* Wake up the main GUI loop. */
2081 if (s_hwnd != 0) 2125 # ifdef VIMDLL
2082 PostMessage(s_hwnd, WM_NULL, 0, 0); 2126 if (gui.in_use)
2127 # endif
2128 if (s_hwnd != 0)
2129 PostMessage(s_hwnd, WM_NULL, 0, 0);
2083 # endif 2130 # endif
2084 return 1; 2131 return 1;
2085 2132
2086 case COPYDATA_EXPR: 2133 case COPYDATA_EXPR:
2087 /* Remember who sent this, for <client> */ 2134 /* Remember who sent this, for <client> */
2143 2190
2144 else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) 2191 else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE)
2145 { 2192 {
2146 /* When the message window is activated (brought to the foreground), 2193 /* When the message window is activated (brought to the foreground),
2147 * this actually applies to the text window. */ 2194 * this actually applies to the text window. */
2148 #ifndef FEAT_GUI 2195 #if !defined(FEAT_GUI) || defined(VIMDLL)
2149 GetConsoleHwnd(); /* get value of s_hwnd */ 2196 # ifdef VIMDLL
2197 if (!gui.in_use)
2198 # endif
2199 GetConsoleHwnd(); /* get value of s_hwnd */
2150 #endif 2200 #endif
2151 if (s_hwnd != 0) 2201 if (s_hwnd != 0)
2152 { 2202 {
2153 SetForegroundWindow(s_hwnd); 2203 SetForegroundWindow(s_hwnd);
2154 return 0; 2204 return 0;
2164 */ 2214 */
2165 void 2215 void
2166 serverInitMessaging(void) 2216 serverInitMessaging(void)
2167 { 2217 {
2168 WNDCLASS wndclass; 2218 WNDCLASS wndclass;
2169 HINSTANCE s_hinst;
2170 2219
2171 /* Clean up on exit */ 2220 /* Clean up on exit */
2172 atexit(CleanUpMessaging); 2221 atexit(CleanUpMessaging);
2173 2222
2174 /* Register a window class - we only really care 2223 /* Register a window class - we only really care
2175 * about the window procedure 2224 * about the window procedure
2176 */ 2225 */
2177 s_hinst = (HINSTANCE)GetModuleHandle(0);
2178 wndclass.style = 0; 2226 wndclass.style = 0;
2179 wndclass.lpfnWndProc = Messaging_WndProc; 2227 wndclass.lpfnWndProc = Messaging_WndProc;
2180 wndclass.cbClsExtra = 0; 2228 wndclass.cbClsExtra = 0;
2181 wndclass.cbWndExtra = 0; 2229 wndclass.cbWndExtra = 0;
2182 wndclass.hInstance = s_hinst; 2230 wndclass.hInstance = g_hinst;
2183 wndclass.hIcon = NULL; 2231 wndclass.hIcon = NULL;
2184 wndclass.hCursor = NULL; 2232 wndclass.hCursor = NULL;
2185 wndclass.hbrBackground = NULL; 2233 wndclass.hbrBackground = NULL;
2186 wndclass.lpszMenuName = NULL; 2234 wndclass.lpszMenuName = NULL;
2187 wndclass.lpszClassName = VIM_CLASSNAME; 2235 wndclass.lpszClassName = VIM_CLASSNAME;
2192 * focus from gvim. */ 2240 * focus from gvim. */
2193 message_window = CreateWindow(VIM_CLASSNAME, "", 2241 message_window = CreateWindow(VIM_CLASSNAME, "",
2194 WS_POPUPWINDOW | WS_CAPTION, 2242 WS_POPUPWINDOW | WS_CAPTION,
2195 CW_USEDEFAULT, CW_USEDEFAULT, 2243 CW_USEDEFAULT, CW_USEDEFAULT,
2196 100, 100, NULL, NULL, 2244 100, 100, NULL, NULL,
2197 s_hinst, NULL); 2245 g_hinst, NULL);
2198 } 2246 }
2199 2247
2200 /* Used by serverSendToVim() to find an alternate server name. */ 2248 /* Used by serverSendToVim() to find an alternate server name. */
2201 static char_u *altname_buf_ptr = NULL; 2249 static char_u *altname_buf_ptr = NULL;
2202 2250
2742 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 2790 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
2743 PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, 2791 PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE,
2744 L"Fixedsys" /* see _ReadVimIni */ 2792 L"Fixedsys" /* see _ReadVimIni */
2745 }; 2793 };
2746 2794
2747 /* Initialise the "current height" to -12 (same as s_lfDefault) just 2795 // Initialise the "current height" to -12 (same as s_lfDefault) just
2748 * in case the user specifies a font in "guifont" with no size before a font 2796 // in case the user specifies a font in "guifont" with no size before a font
2749 * with an explicit size has been set. This defaults the size to this value 2797 // with an explicit size has been set. This defaults the size to this value
2750 * (-12 equates to roughly 9pt). 2798 // (-12 equates to roughly 9pt).
2751 */ 2799 int current_font_height = -12; // also used in gui_w32.c
2752 int current_font_height = -12; /* also used in gui_w48.c */
2753 2800
2754 /* Convert a string representing a point size into pixels. The string should 2801 /* Convert a string representing a point size into pixels. The string should
2755 * be a positive decimal number, with an optional decimal point (eg, "12", or 2802 * be a positive decimal number, with an optional decimal point (eg, "12", or
2756 * "10.5"). The pixel value is returned, and a pointer to the next unconverted 2803 * "10.5"). The pixel value is returned, and a pointer to the next unconverted
2757 * character is stored in *end. The flag "vertical" says whether this 2804 * character is stored in *end. The flag "vertical" says whether this