Mercurial > vim
comparison src/gui_w32.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 | 045ab97fe320 |
comparison
equal
deleted
inserted
replaced
16450:bf74bce807e8 | 16451:7ae2396cef62 |
---|---|
318 static HWND s_findrep_hwnd = NULL; | 318 static HWND s_findrep_hwnd = NULL; |
319 static int s_findrep_is_find; // TRUE for find dialog, FALSE | 319 static int s_findrep_is_find; // TRUE for find dialog, FALSE |
320 // for find/replace dialog | 320 // for find/replace dialog |
321 #endif | 321 #endif |
322 | 322 |
323 static HINSTANCE s_hinst = NULL; | |
324 #if !defined(FEAT_GUI) | 323 #if !defined(FEAT_GUI) |
325 static | 324 static |
326 #endif | 325 #endif |
327 HWND s_hwnd = NULL; | 326 HWND s_hwnd = NULL; |
328 static HDC s_hdc = NULL; | 327 static HDC s_hdc = NULL; |
1422 "SCROLLBAR", "Scrollbar", | 1421 "SCROLLBAR", "Scrollbar", |
1423 WS_CHILD | ((orient == SBAR_VERT) ? SBS_VERT : SBS_HORZ), 0, 0, | 1422 WS_CHILD | ((orient == SBAR_VERT) ? SBS_VERT : SBS_HORZ), 0, 0, |
1424 10, /* Any value will do for now */ | 1423 10, /* Any value will do for now */ |
1425 10, /* Any value will do for now */ | 1424 10, /* Any value will do for now */ |
1426 s_hwnd, NULL, | 1425 s_hwnd, NULL, |
1427 s_hinst, NULL); | 1426 g_hinst, NULL); |
1428 } | 1427 } |
1429 | 1428 |
1430 /* | 1429 /* |
1431 * Find the scrollbar with the given hwnd. | 1430 * Find the scrollbar with the given hwnd. |
1432 */ | 1431 */ |
2234 gui_mch_draw_menubar(void) | 2233 gui_mch_draw_menubar(void) |
2235 { | 2234 { |
2236 DrawMenuBar(s_hwnd); | 2235 DrawMenuBar(s_hwnd); |
2237 } | 2236 } |
2238 #endif /*FEAT_MENU*/ | 2237 #endif /*FEAT_MENU*/ |
2239 | |
2240 #ifndef PROTO | |
2241 void | |
2242 _cdecl | |
2243 SaveInst(HINSTANCE hInst) | |
2244 { | |
2245 s_hinst = hInst; | |
2246 } | |
2247 #endif | |
2248 | 2238 |
2249 /* | 2239 /* |
2250 * Return the RGB value of a pixel as a long. | 2240 * Return the RGB value of a pixel as a long. |
2251 */ | 2241 */ |
2252 guicolor_T | 2242 guicolor_T |
4837 arg); | 4827 arg); |
4838 mch_errmsg(buf); | 4828 mch_errmsg(buf); |
4839 } | 4829 } |
4840 #endif | 4830 #endif |
4841 | 4831 |
4832 #if defined(GUI_MAY_SPAWN) || defined(PROTO) | |
4833 static char * | |
4834 gvim_error(void) | |
4835 { | |
4836 char *msg = _("E988: GUI cannot be used. Cannot execute gvim.exe."); | |
4837 | |
4838 if (starting) | |
4839 { | |
4840 mch_errmsg(msg); | |
4841 mch_errmsg("\n"); | |
4842 mch_exit(2); | |
4843 } | |
4844 return msg; | |
4845 } | |
4846 | |
4847 char * | |
4848 gui_mch_do_spawn(char_u *arg) | |
4849 { | |
4850 int len; | |
4851 # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) | |
4852 char_u *session = NULL; | |
4853 LPWSTR tofree1 = NULL; | |
4854 # endif | |
4855 WCHAR name[MAX_PATH]; | |
4856 LPWSTR cmd, newcmd = NULL, p, warg, tofree2 = NULL; | |
4857 STARTUPINFOW si = {sizeof(si)}; | |
4858 PROCESS_INFORMATION pi; | |
4859 | |
4860 if (!GetModuleFileNameW(g_hinst, name, MAX_PATH)) | |
4861 goto error; | |
4862 p = wcsrchr(name, L'\\'); | |
4863 if (p == NULL) | |
4864 goto error; | |
4865 // Replace the executable name from vim(d).exe to gvim(d).exe. | |
4866 # ifdef DEBUG | |
4867 wcscpy(p + 1, L"gvimd.exe"); | |
4868 # else | |
4869 wcscpy(p + 1, L"gvim.exe"); | |
4870 # endif | |
4871 | |
4872 # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) | |
4873 if (starting) | |
4874 # endif | |
4875 { | |
4876 // Pass the command line to the new process. | |
4877 p = GetCommandLineW(); | |
4878 // Skip 1st argument. | |
4879 while (*p && *p != L' ' && *p != L'\t') | |
4880 { | |
4881 if (*p == L'"') | |
4882 { | |
4883 while (*p && *p != L'"') | |
4884 ++p; | |
4885 if (*p) | |
4886 ++p; | |
4887 } | |
4888 else | |
4889 ++p; | |
4890 } | |
4891 cmd = p; | |
4892 } | |
4893 # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) | |
4894 else | |
4895 { | |
4896 // Create a session file and pass it to the new process. | |
4897 LPWSTR wsession; | |
4898 char_u *savebg; | |
4899 int ret; | |
4900 | |
4901 session = vim_tempname('s', FALSE); | |
4902 if (session == NULL) | |
4903 goto error; | |
4904 savebg = p_bg; | |
4905 p_bg = vim_strsave((char_u *)"light"); // Set 'bg' to "light". | |
4906 ret = write_session_file(session); | |
4907 vim_free(p_bg); | |
4908 p_bg = savebg; | |
4909 if (!ret) | |
4910 goto error; | |
4911 wsession = enc_to_utf16(session, NULL); | |
4912 if (wsession == NULL) | |
4913 goto error; | |
4914 len = (int)wcslen(wsession) * 2 + 27 + 1; | |
4915 cmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR)); | |
4916 if (cmd == NULL) | |
4917 { | |
4918 vim_free(wsession); | |
4919 goto error; | |
4920 } | |
4921 tofree1 = cmd; | |
4922 _snwprintf(cmd, len, L" -S \"%s\" -c \"call delete('%s')\"", | |
4923 wsession, wsession); | |
4924 vim_free(wsession); | |
4925 } | |
4926 # endif | |
4927 | |
4928 // Check additional arguments to the `:gui` command. | |
4929 if (arg != NULL) | |
4930 { | |
4931 warg = enc_to_utf16(arg, NULL); | |
4932 if (warg == NULL) | |
4933 goto error; | |
4934 tofree2 = warg; | |
4935 } | |
4936 else | |
4937 warg = L""; | |
4938 | |
4939 // Set up the new command line. | |
4940 len = (int)wcslen(name) + (int)wcslen(cmd) + (int)wcslen(warg) + 4; | |
4941 newcmd = (LPWSTR)alloc(len * (int)sizeof(WCHAR)); | |
4942 if (newcmd == NULL) | |
4943 goto error; | |
4944 _snwprintf(newcmd, len, L"\"%s\"%s %s", name, cmd, warg); | |
4945 | |
4946 // Spawn a new GUI process. | |
4947 if (!CreateProcessW(NULL, newcmd, NULL, NULL, TRUE, 0, | |
4948 NULL, NULL, &si, &pi)) | |
4949 goto error; | |
4950 CloseHandle(pi.hProcess); | |
4951 CloseHandle(pi.hThread); | |
4952 mch_exit(0); | |
4953 | |
4954 error: | |
4955 # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) | |
4956 if (session) | |
4957 mch_remove(session); | |
4958 vim_free(session); | |
4959 vim_free(tofree1); | |
4960 # endif | |
4961 vim_free(newcmd); | |
4962 vim_free(tofree2); | |
4963 return gvim_error(); | |
4964 } | |
4965 #endif | |
4966 | |
4842 /* | 4967 /* |
4843 * Parse the GUI related command-line arguments. Any arguments used are | 4968 * Parse the GUI related command-line arguments. Any arguments used are |
4844 * deleted from argv, and *argc is decremented accordingly. This is called | 4969 * deleted from argv, and *argc is decremented accordingly. This is called |
4845 * when vim is started, whether or not the GUI has been started. | 4970 * when vim is started, whether or not the GUI has been started. |
4846 */ | 4971 */ |
4955 | 5080 |
4956 /* | 5081 /* |
4957 * Load the tearoff bitmap | 5082 * Load the tearoff bitmap |
4958 */ | 5083 */ |
4959 #ifdef FEAT_TEAROFF | 5084 #ifdef FEAT_TEAROFF |
4960 s_htearbitmap = LoadBitmap(s_hinst, "IDB_TEAROFF"); | 5085 s_htearbitmap = LoadBitmap(g_hinst, "IDB_TEAROFF"); |
4961 #endif | 5086 #endif |
4962 | 5087 |
4963 gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); | 5088 gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); |
4964 gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); | 5089 gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); |
4965 #ifdef FEAT_MENU | 5090 #ifdef FEAT_MENU |
4969 | 5094 |
4970 s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); | 5095 s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); |
4971 | 5096 |
4972 /* First try using the wide version, so that we can use any title. | 5097 /* First try using the wide version, so that we can use any title. |
4973 * Otherwise only characters in the active codepage will work. */ | 5098 * Otherwise only characters in the active codepage will work. */ |
4974 if (GetClassInfoW(s_hinst, szVimWndClassW, &wndclassw) == 0) | 5099 if (GetClassInfoW(g_hinst, szVimWndClassW, &wndclassw) == 0) |
4975 { | 5100 { |
4976 wndclassw.style = CS_DBLCLKS; | 5101 wndclassw.style = CS_DBLCLKS; |
4977 wndclassw.lpfnWndProc = _WndProc; | 5102 wndclassw.lpfnWndProc = _WndProc; |
4978 wndclassw.cbClsExtra = 0; | 5103 wndclassw.cbClsExtra = 0; |
4979 wndclassw.cbWndExtra = 0; | 5104 wndclassw.cbWndExtra = 0; |
4980 wndclassw.hInstance = s_hinst; | 5105 wndclassw.hInstance = g_hinst; |
4981 wndclassw.hIcon = LoadIcon(wndclassw.hInstance, "IDR_VIM"); | 5106 wndclassw.hIcon = LoadIcon(wndclassw.hInstance, "IDR_VIM"); |
4982 wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); | 5107 wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
4983 wndclassw.hbrBackground = s_brush; | 5108 wndclassw.hbrBackground = s_brush; |
4984 wndclassw.lpszMenuName = NULL; | 5109 wndclassw.lpszMenuName = NULL; |
4985 wndclassw.lpszClassName = szVimWndClassW; | 5110 wndclassw.lpszClassName = szVimWndClassW; |
5009 gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, | 5134 gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
5010 gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, | 5135 gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
5011 100, // Any value will do | 5136 100, // Any value will do |
5012 100, // Any value will do | 5137 100, // Any value will do |
5013 vim_parent_hwnd, NULL, | 5138 vim_parent_hwnd, NULL, |
5014 s_hinst, NULL); | 5139 g_hinst, NULL); |
5015 #ifdef HAVE_TRY_EXCEPT | 5140 #ifdef HAVE_TRY_EXCEPT |
5016 } | 5141 } |
5017 __except(EXCEPTION_EXECUTE_HANDLER) | 5142 __except(EXCEPTION_EXECUTE_HANDLER) |
5018 { | 5143 { |
5019 /* NOP */ | 5144 /* NOP */ |
5041 gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, | 5166 gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
5042 gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, | 5167 gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
5043 100, /* Any value will do */ | 5168 100, /* Any value will do */ |
5044 100, /* Any value will do */ | 5169 100, /* Any value will do */ |
5045 NULL, NULL, | 5170 NULL, NULL, |
5046 s_hinst, NULL); | 5171 g_hinst, NULL); |
5047 if (s_hwnd != NULL && win_socket_id != 0) | 5172 if (s_hwnd != NULL && win_socket_id != 0) |
5048 { | 5173 { |
5049 SetParent(s_hwnd, (HWND)win_socket_id); | 5174 SetParent(s_hwnd, (HWND)win_socket_id); |
5050 ShowWindow(s_hwnd, SW_SHOWMAXIMIZED); | 5175 ShowWindow(s_hwnd, SW_SHOWMAXIMIZED); |
5051 } | 5176 } |
5060 #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) | 5185 #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
5061 dyn_imm_load(); | 5186 dyn_imm_load(); |
5062 #endif | 5187 #endif |
5063 | 5188 |
5064 /* Create the text area window */ | 5189 /* Create the text area window */ |
5065 if (GetClassInfoW(s_hinst, szTextAreaClassW, &wndclassw) == 0) | 5190 if (GetClassInfoW(g_hinst, szTextAreaClassW, &wndclassw) == 0) |
5066 { | 5191 { |
5067 wndclassw.style = CS_OWNDC; | 5192 wndclassw.style = CS_OWNDC; |
5068 wndclassw.lpfnWndProc = _TextAreaWndProc; | 5193 wndclassw.lpfnWndProc = _TextAreaWndProc; |
5069 wndclassw.cbClsExtra = 0; | 5194 wndclassw.cbClsExtra = 0; |
5070 wndclassw.cbWndExtra = 0; | 5195 wndclassw.cbWndExtra = 0; |
5071 wndclassw.hInstance = s_hinst; | 5196 wndclassw.hInstance = g_hinst; |
5072 wndclassw.hIcon = NULL; | 5197 wndclassw.hIcon = NULL; |
5073 wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); | 5198 wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
5074 wndclassw.hbrBackground = NULL; | 5199 wndclassw.hbrBackground = NULL; |
5075 wndclassw.lpszMenuName = NULL; | 5200 wndclassw.lpszMenuName = NULL; |
5076 wndclassw.lpszClassName = szTextAreaClassW; | 5201 wndclassw.lpszClassName = szTextAreaClassW; |
5084 szTextAreaClassW, L"Vim text area", | 5209 szTextAreaClassW, L"Vim text area", |
5085 WS_CHILD | WS_VISIBLE, 0, 0, | 5210 WS_CHILD | WS_VISIBLE, 0, 0, |
5086 100, // Any value will do for now | 5211 100, // Any value will do for now |
5087 100, // Any value will do for now | 5212 100, // Any value will do for now |
5088 s_hwnd, NULL, | 5213 s_hwnd, NULL, |
5089 s_hinst, NULL); | 5214 g_hinst, NULL); |
5090 | 5215 |
5091 if (s_textArea == NULL) | 5216 if (s_textArea == NULL) |
5092 return FAIL; | 5217 return FAIL; |
5093 | 5218 |
5094 #ifdef FEAT_LIBCALL | 5219 #ifdef FEAT_LIBCALL |
6638 garray_T ga; | 6763 garray_T ga; |
6639 int l; | 6764 int l; |
6640 | 6765 |
6641 #ifndef NO_CONSOLE | 6766 #ifndef NO_CONSOLE |
6642 /* Don't output anything in silent mode ("ex -s") */ | 6767 /* Don't output anything in silent mode ("ex -s") */ |
6643 if (silent_mode) | 6768 # ifdef VIMDLL |
6644 return dfltbutton; /* return default option */ | 6769 if (!(gui.in_use || gui.starting)) |
6770 # endif | |
6771 if (silent_mode) | |
6772 return dfltbutton; /* return default option */ | |
6645 #endif | 6773 #endif |
6646 | 6774 |
6647 if (s_hwnd == NULL) | 6775 if (s_hwnd == NULL) |
6648 get_dialog_font_metrics(); | 6776 get_dialog_font_metrics(); |
6649 | 6777 |
7048 s_textfield = NULL; | 7176 s_textfield = NULL; |
7049 } | 7177 } |
7050 | 7178 |
7051 /* show the dialog box modally and get a return value */ | 7179 /* show the dialog box modally and get a return value */ |
7052 nchar = (int)DialogBoxIndirect( | 7180 nchar = (int)DialogBoxIndirect( |
7053 s_hinst, | 7181 g_hinst, |
7054 (LPDLGTEMPLATE)pdlgtemplate, | 7182 (LPDLGTEMPLATE)pdlgtemplate, |
7055 s_hwnd, | 7183 s_hwnd, |
7056 (DLGPROC)dialog_callback); | 7184 (DLGPROC)dialog_callback); |
7057 | 7185 |
7058 LocalFree(LocalHandle(pdlgtemplate)); | 7186 LocalFree(LocalHandle(pdlgtemplate)); |
7642 *ptrueheight = (WORD)(sepPadding + 1 + 13 * (*pnumitems)); | 7770 *ptrueheight = (WORD)(sepPadding + 1 + 13 * (*pnumitems)); |
7643 | 7771 |
7644 | 7772 |
7645 /* show modelessly */ | 7773 /* show modelessly */ |
7646 the_menu->tearoff_handle = CreateDialogIndirectParam( | 7774 the_menu->tearoff_handle = CreateDialogIndirectParam( |
7647 s_hinst, | 7775 g_hinst, |
7648 (LPDLGTEMPLATE)pdlgtemplate, | 7776 (LPDLGTEMPLATE)pdlgtemplate, |
7649 s_hwnd, | 7777 s_hwnd, |
7650 (DLGPROC)tearoff_callback, | 7778 (DLGPROC)tearoff_callback, |
7651 (LPARAM)top_menu); | 7779 (LPARAM)top_menu); |
7652 | 7780 |
7687 s_toolbarhwnd = CreateToolbarEx( | 7815 s_toolbarhwnd = CreateToolbarEx( |
7688 s_hwnd, | 7816 s_hwnd, |
7689 WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, | 7817 WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, |
7690 4000, //any old big number | 7818 4000, //any old big number |
7691 31, //number of images in initial bitmap | 7819 31, //number of images in initial bitmap |
7692 s_hinst, | 7820 g_hinst, |
7693 IDR_TOOLBAR1, // id of initial bitmap | 7821 IDR_TOOLBAR1, // id of initial bitmap |
7694 NULL, | 7822 NULL, |
7695 0, // initial number of buttons | 7823 0, // initial number of buttons |
7696 TOOLBAR_BUTTON_WIDTH, //api guide is wrong! | 7824 TOOLBAR_BUTTON_WIDTH, //api guide is wrong! |
7697 TOOLBAR_BUTTON_HEIGHT, | 7825 TOOLBAR_BUTTON_HEIGHT, |
7788 InitCommonControls(); | 7916 InitCommonControls(); |
7789 | 7917 |
7790 s_tabhwnd = CreateWindow(WC_TABCONTROL, "Vim tabline", | 7918 s_tabhwnd = CreateWindow(WC_TABCONTROL, "Vim tabline", |
7791 WS_CHILD|TCS_FOCUSNEVER|TCS_TOOLTIPS, | 7919 WS_CHILD|TCS_FOCUSNEVER|TCS_TOOLTIPS, |
7792 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | 7920 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
7793 CW_USEDEFAULT, s_hwnd, NULL, s_hinst, NULL); | 7921 CW_USEDEFAULT, s_hwnd, NULL, g_hinst, NULL); |
7794 s_tabline_wndproc = SubclassWindow(s_tabhwnd, tabline_wndproc); | 7922 s_tabline_wndproc = SubclassWindow(s_tabhwnd, tabline_wndproc); |
7795 | 7923 |
7796 gui.tabline_height = TABLINE_HEIGHT; | 7924 gui.tabline_height = TABLINE_HEIGHT; |
7797 | 7925 |
7798 # ifdef USE_SYSMENU_FONT | 7926 # ifdef USE_SYSMENU_FONT |
8243 return; | 8371 return; |
8244 | 8372 |
8245 beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, | 8373 beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, |
8246 NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, | 8374 NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
8247 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | 8375 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
8248 beval->target, NULL, s_hinst, NULL); | 8376 beval->target, NULL, g_hinst, NULL); |
8249 | 8377 |
8250 SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, | 8378 SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, |
8251 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | 8379 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
8252 | 8380 |
8253 pti->cbSize = ToolInfoSize; | 8381 pti->cbSize = ToolInfoSize; |