annotate src/GvimExt/gvimext.cpp @ 6793:e1d59836eecc v7.4.718

patch 7.4.718 Problem: Autocommands triggered by quickfix cannot get the current title value. Solution: Set w:quickfix_title earlier. (Yannick) Also move the check for a title into the function.
author Bram Moolenaar <bram@vim.org>
date Mon, 04 May 2015 12:34:22 +0200
parents 04736b4030ec
children 81cb471657e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
2 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved gvimext by Tianmiao Hu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
4 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
7 */
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
8
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
9 /*
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
10 * gvimext is a DLL which is used for the "Edit with Vim" context menu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
11 * extension. It implements a MS defined interface with the Shell.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
12 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
13 * If you have any questions or any suggestions concerning gvimext, please
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
14 * contact Tianmiao Hu: tianmiao@acm.org.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
15 */
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
16
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
17 #include "gvimext.h"
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
18
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
19 #ifdef __BORLANDC__
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
20 # include <dir.h>
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
21 # ifndef _strnicmp
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
22 # define _strnicmp(a, b, c) strnicmp((a), (b), (c))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
23 # endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
24 #else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
25 static char *searchpath(char *name);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
26 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
27
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
28 // Always get an error while putting the following stuff to the
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
29 // gvimext.h file as class protected variables, give up and
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
30 // declare them as global stuff
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
31 FORMATETC fmte = {CF_HDROP,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
32 (DVTARGETDEVICE FAR *)NULL,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
33 DVASPECT_CONTENT,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
34 -1,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
35 TYMED_HGLOBAL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
36 };
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
37 STGMEDIUM medium;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
38 HRESULT hres = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
39 UINT cbFiles = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
40
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
41 /* The buffers size used to be MAX_PATH (256 bytes), but that's not always
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
42 * enough */
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
43 #define BUFSIZE 1100
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
44
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
45 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
46 // Get the name of the Gvim executable to use, with the path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
47 // When "runtime" is non-zero, we were called to find the runtime directory.
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
48 // Returns the path in name[BUFSIZE]. It's empty when it fails.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
49 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
50 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
51 getGvimName(char *name, int runtime)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
52 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
53 HKEY keyhandle;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
54 DWORD hlen;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
55
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
56 // Get the location of gvim from the registry.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
57 name[0] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
58 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
59 KEY_READ, &keyhandle) == ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
60 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
61 hlen = BUFSIZE;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
62 if (RegQueryValueEx(keyhandle, "path", 0, NULL, (BYTE *)name, &hlen)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
63 != ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
64 name[0] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
65 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
66 name[hlen] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
67 RegCloseKey(keyhandle);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
68 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
69
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
70 // Registry didn't work, use the search path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
71 if (name[0] == 0)
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
72 strcpy(name, searchpath((char *)"gvim.exe"));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
73
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
74 if (!runtime)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
75 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
76 // Only when looking for the executable, not the runtime dir, we can
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
77 // search for the batch file or a name without a path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
78 if (name[0] == 0)
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
79 strcpy(name, searchpath((char *)"gvim.bat"));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
80 if (name[0] == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
81 strcpy(name, "gvim"); // finds gvim.bat or gvim.exe
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
82
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
83 // avoid that Vim tries to expand wildcards in the file names
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
84 strcat(name, " --literal");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
85 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
86 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
87
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
88 static void
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
89 getGvimNameW(wchar_t *nameW)
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
90 {
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
91 char *name;
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
92
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
93 name = (char *)malloc(BUFSIZE);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
94 getGvimName(name, 0);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
95 mbstowcs(nameW, name, BUFSIZE);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
96 free(name);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
97 }
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
98
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
99 //
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
100 // Get the Vim runtime directory into buf[BUFSIZE].
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
101 // The result is empty when it failed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
102 // When it works, the path ends in a slash or backslash.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
103 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
104 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
105 getRuntimeDir(char *buf)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
106 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
107 int idx;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
108
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
109 getGvimName(buf, 1);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
110 if (buf[0] != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
111 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
112 // When no path found, use the search path to expand it.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
113 if (strchr(buf, '/') == NULL && strchr(buf, '\\') == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
114 strcpy(buf, searchpath(buf));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
115
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
116 // remove "gvim.exe" from the end
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 415
diff changeset
117 for (idx = (int)strlen(buf) - 1; idx >= 0; idx--)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
118 if (buf[idx] == '\\' || buf[idx] == '/')
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
119 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
120 buf[idx + 1] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
121 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
122 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
123 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
124 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
125
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
126 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
127 // GETTEXT: translated messages and menu entries
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
128 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
129 #ifndef FEAT_GETTEXT
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
130 # define _(x) x
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
131 #else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
132 # define _(x) (*dyn_libintl_gettext)(x)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
133 # define VIMPACKAGE "vim"
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
134 # ifndef GETTEXT_DLL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
135 # define GETTEXT_DLL "libintl.dll"
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
136 # endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
137
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
138 // Dummy functions
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
139 static char *null_libintl_gettext(const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
140 static char *null_libintl_textdomain(const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
141 static char *null_libintl_bindtextdomain(const char *, const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
142 static int dyn_libintl_init(char *dir);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
143 static void dyn_libintl_end(void);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
144
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
145 static wchar_t *oldenv = NULL;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
146 static HINSTANCE hLibintlDLL = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
147 static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
148 static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
149 static char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
150 = null_libintl_bindtextdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
151
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
152 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
153 // Attempt to load libintl.dll. If it doesn't work, use dummy functions.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
154 // "dir" is the directory where the libintl.dll might be.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
155 // Return 1 for success, 0 for failure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
156 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
157 static int
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
158 dyn_libintl_init(char *dir)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
159 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
160 int i;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
161 static struct
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
162 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
163 char *name;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
164 FARPROC *ptr;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
165 } libintl_entry[] =
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
166 {
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
167 {(char *)"gettext", (FARPROC*)&dyn_libintl_gettext},
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
168 {(char *)"textdomain", (FARPROC*)&dyn_libintl_textdomain},
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
169 {(char *)"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain},
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
170 {NULL, NULL}
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
171 };
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
172
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
173 // No need to initialize twice.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
174 if (hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
175 return 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
176
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
177 // Load gettext library, first try the Vim runtime directory, then search
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
178 // the path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
179 strcat(dir, GETTEXT_DLL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
180 hLibintlDLL = LoadLibrary(dir);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
181 if (!hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
182 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
183 hLibintlDLL = LoadLibrary(GETTEXT_DLL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
184 if (!hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
185 return 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
186 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
187
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
188 // Get the addresses of the functions we need.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
189 for (i = 0; libintl_entry[i].name != NULL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
190 && libintl_entry[i].ptr != NULL; ++i)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
191 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
192 if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
193 libintl_entry[i].name)) == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
194 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
195 dyn_libintl_end();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
196 return 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
197 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
198 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
199 return 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
200 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
201
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
202 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
203 dyn_libintl_end(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
204 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
205 if (hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
206 FreeLibrary(hLibintlDLL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
207 hLibintlDLL = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
208 dyn_libintl_gettext = null_libintl_gettext;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
209 dyn_libintl_textdomain = null_libintl_textdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
210 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
211 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
212
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
213 static char *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
214 null_libintl_gettext(const char *msgid)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
215 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
216 return (char *)msgid;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
217 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
218
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
219 static char *
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
220 null_libintl_bindtextdomain(const char * /* domainname */, const char * /* dirname */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
221 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
222 return NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
223 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
224
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
225 static char *
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
226 null_libintl_textdomain(const char* /* domainname */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
227 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
228 return NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
229 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
230
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
231 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
232 // Setup for translating strings.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
233 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
234 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
235 dyn_gettext_load(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
236 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
237 char szBuff[BUFSIZE];
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
238 char szLang[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
239 DWORD len;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
240 HKEY keyhandle;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
241 int gotlang = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
242
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
243 strcpy(szLang, "LANG=");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
244
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
245 // First try getting the language from the registry, this can be
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
246 // used to overrule the system language.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
247 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
248 KEY_READ, &keyhandle) == ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
249 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
250 len = BUFSIZE;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
251 if (RegQueryValueEx(keyhandle, "lang", 0, NULL, (BYTE*)szBuff, &len)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
252 == ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
253 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
254 szBuff[len] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
255 strcat(szLang, szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
256 gotlang = 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
257 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
258 RegCloseKey(keyhandle);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
259 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
260
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
261 if (!gotlang && getenv("LANG") == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
262 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
263 // Get the language from the system.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
264 // Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
265 // LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
266 // only the first two.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
267 len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
268 (LPTSTR)szBuff, BUFSIZE);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
269 if (len >= 2 && _strnicmp(szBuff, "en", 2) != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
270 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
271 // There are a few exceptions (probably more)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
272 if (_strnicmp(szBuff, "cht", 3) == 0
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
273 || _strnicmp(szBuff, "zht", 3) == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
274 strcpy(szBuff, "zh_TW");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
275 else if (_strnicmp(szBuff, "chs", 3) == 0
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
276 || _strnicmp(szBuff, "zhc", 3) == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
277 strcpy(szBuff, "zh_CN");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
278 else if (_strnicmp(szBuff, "jp", 2) == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
279 strcpy(szBuff, "ja");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
280 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
281 szBuff[2] = 0; // truncate to two-letter code
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
282 strcat(szLang, szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
283 gotlang = 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
284 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
285 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
286 if (gotlang)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
287 putenv(szLang);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
288
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
289 // Try to locate the runtime files. The path is used to find libintl.dll
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
290 // and the vim.mo files.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
291 getRuntimeDir(szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
292 if (szBuff[0] != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
293 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 415
diff changeset
294 len = (DWORD)strlen(szBuff);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
295 if (dyn_libintl_init(szBuff))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
296 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
297 strcpy(szBuff + len, "lang");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
298
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
299 (*dyn_libintl_bindtextdomain)(VIMPACKAGE, szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
300 (*dyn_libintl_textdomain)(VIMPACKAGE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
301 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
302 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
303 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
304
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
305 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
306 dyn_gettext_free(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
307 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
308 dyn_libintl_end();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
309 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
310 #endif // FEAT_GETTEXT
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
311
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
312 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
313 // Global variables
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
314 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
315 UINT g_cRefThisDll = 0; // Reference count of this DLL.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
316 HINSTANCE g_hmodThisDll = NULL; // Handle to this DLL itself.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
317
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
318
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
319 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
320 // DllMain
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
321 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
322 extern "C" int APIENTRY
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
323 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
324 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
325 switch (dwReason)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
326 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
327 case DLL_PROCESS_ATTACH:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
328 // Extension DLL one-time initialization
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
329 g_hmodThisDll = hInstance;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
330 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
331
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
332 case DLL_PROCESS_DETACH:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
333 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
334 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
335
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
336 return 1; // ok
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
337 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
338
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
339 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
340 inc_cRefThisDLL()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
341 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
342 #ifdef FEAT_GETTEXT
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
343 if (g_cRefThisDll == 0) {
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
344 dyn_gettext_load();
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
345 oldenv = GetEnvironmentStringsW();
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
346 }
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
347 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
348 InterlockedIncrement((LPLONG)&g_cRefThisDll);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
349 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
350
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
351 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
352 dec_cRefThisDLL()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
353 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
354 #ifdef FEAT_GETTEXT
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
355 if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0) {
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
356 dyn_gettext_free();
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
357 if (oldenv != NULL) {
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
358 FreeEnvironmentStringsW(oldenv);
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
359 oldenv = NULL;
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
360 }
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
361 }
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
362 #else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
363 InterlockedDecrement((LPLONG)&g_cRefThisDll);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
364 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
365 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
366
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
367 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
368 // DllCanUnloadNow
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
369 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
370
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
371 STDAPI DllCanUnloadNow(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
372 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
373 return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
374 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
375
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
376 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
377 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
378 *ppvOut = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
379
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
380 if (IsEqualIID(rclsid, CLSID_ShellExtension))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
381 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
382 CShellExtClassFactory *pcf = new CShellExtClassFactory;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
383
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
384 return pcf->QueryInterface(riid, ppvOut);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
385 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
386
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
387 return CLASS_E_CLASSNOTAVAILABLE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
388 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
389
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
390 CShellExtClassFactory::CShellExtClassFactory()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
391 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
392 m_cRef = 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
393
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
394 inc_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
395 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
396
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
397 CShellExtClassFactory::~CShellExtClassFactory()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
398 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
399 dec_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
400 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
401
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
402 STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
403 LPVOID FAR *ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
404 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
405 *ppv = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
406
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
407 // Any interface on this object is the object pointer
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
408
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
409 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
410 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
411 *ppv = (LPCLASSFACTORY)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
412
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
413 AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
414
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
415 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
416 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
417
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
418 return E_NOINTERFACE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
419 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
420
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
421 STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
422 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
423 return InterlockedIncrement((LPLONG)&m_cRef);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
424 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
425
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
426 STDMETHODIMP_(ULONG) CShellExtClassFactory::Release()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
427 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
428 if (InterlockedDecrement((LPLONG)&m_cRef))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
429 return m_cRef;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
430
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
431 delete this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
432
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
433 return 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
434 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
435
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
436 STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
437 REFIID riid,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
438 LPVOID *ppvObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
439 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
440 *ppvObj = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
441
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
442 // Shell extensions typically don't support aggregation (inheritance)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
443
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
444 if (pUnkOuter)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
445 return CLASS_E_NOAGGREGATION;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
446
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
447 // Create the main shell extension object. The shell will then call
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
448 // QueryInterface with IID_IShellExtInit--this is how shell extensions are
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
449 // initialized.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
450
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
451 LPCSHELLEXT pShellExt = new CShellExt(); //Create the CShellExt object
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
452
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
453 if (NULL == pShellExt)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
454 return E_OUTOFMEMORY;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
455
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
456 return pShellExt->QueryInterface(riid, ppvObj);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
457 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
458
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
459
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
460 STDMETHODIMP CShellExtClassFactory::LockServer(BOOL /* fLock */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
461 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
462 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
463 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
464
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
465 // *********************** CShellExt *************************
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
466 CShellExt::CShellExt()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
467 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
468 m_cRef = 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
469 m_pDataObj = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
470
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
471 inc_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
472 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
473
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
474 CShellExt::~CShellExt()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
475 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
476 if (m_pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
477 m_pDataObj->Release();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
478
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
479 dec_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
480 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
481
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
482 STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
483 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
484 *ppv = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
485
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
486 if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
487 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
488 *ppv = (LPSHELLEXTINIT)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
489 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
490 else if (IsEqualIID(riid, IID_IContextMenu))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
491 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
492 *ppv = (LPCONTEXTMENU)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
493 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
494
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
495 if (*ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
496 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
497 AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
498
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
499 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
500 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
501
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
502 return E_NOINTERFACE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
503 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
504
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
505 STDMETHODIMP_(ULONG) CShellExt::AddRef()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
506 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
507 return InterlockedIncrement((LPLONG)&m_cRef);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
508 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
509
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
510 STDMETHODIMP_(ULONG) CShellExt::Release()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
511 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
512
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
513 if (InterlockedDecrement((LPLONG)&m_cRef))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
514 return m_cRef;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
515
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
516 delete this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
517
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
518 return 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
519 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
520
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
521
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
522 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
523 // FUNCTION: CShellExt::Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
524 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
525 // PURPOSE: Called by the shell when initializing a context menu or property
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
526 // sheet extension.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
527 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
528 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
529 // pIDFolder - Specifies the parent folder
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3008
diff changeset
530 // pDataObj - Specifies the set of items selected in that folder.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
531 // hRegKey - Specifies the type of the focused item in the selection.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
532 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
533 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
534 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
535 // NOERROR in all cases.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
536 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
537 // COMMENTS: Note that at the time this function is called, we don't know
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
538 // (or care) what type of shell extension is being initialized.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
539 // It could be a context menu or a property sheet.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
540 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
541
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
542 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST /* pIDFolder */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
543 LPDATAOBJECT pDataObj,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
544 HKEY /* hRegKey */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
545 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
546 // Initialize can be called more than once
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
547 if (m_pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
548 m_pDataObj->Release();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
549
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
550 // duplicate the object pointer and registry handle
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
551
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
552 if (pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
553 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
554 m_pDataObj = pDataObj;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
555 pDataObj->AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
556 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
557
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
558 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
559 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
560
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
561
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
562 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
563 // FUNCTION: CShellExt::QueryContextMenu(HMENU, UINT, UINT, UINT, UINT)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
564 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
565 // PURPOSE: Called by the shell just before the context menu is displayed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
566 // This is where you add your specific menu items.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
567 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
568 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
569 // hMenu - Handle to the context menu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
570 // indexMenu - Index of where to begin inserting menu items
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
571 // idCmdFirst - Lowest value for new menu ID's
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
572 // idCmtLast - Highest value for new menu ID's
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
573 // uFlags - Specifies the context of the menu event
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
574 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
575 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
576 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
577 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
578 // COMMENTS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
579 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
580
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
581 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
582 UINT indexMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
583 UINT idCmdFirst,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
584 UINT /* idCmdLast */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
585 UINT /* uFlags */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
586 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
587 UINT idCmd = idCmdFirst;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
588
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
589 hres = m_pDataObj->GetData(&fmte, &medium);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
590 if (medium.hGlobal)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
591 cbFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, 0, 0);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
592
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
593 // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
594
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
595 // Initialize m_cntOfHWnd to 0
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
596 m_cntOfHWnd = 0;
2972
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
597
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
598 HKEY keyhandle;
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
599 bool showExisting = true;
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
600
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
601 // Check whether "Edit with existing Vim" entries are disabled.
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
602 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
603 KEY_READ, &keyhandle) == ERROR_SUCCESS)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
604 {
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
605 if (RegQueryValueEx(keyhandle, "DisableEditWithExisting", 0, NULL,
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
606 NULL, NULL) == ERROR_SUCCESS)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
607 showExisting = false;
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
608 RegCloseKey(keyhandle);
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
609 }
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
610
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
611 // Retrieve all the vim instances, unless disabled.
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
612 if (showExisting)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
613 EnumWindows(EnumWindowsProc, (LPARAM)this);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
614
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
615 if (cbFiles > 1)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
616 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
617 InsertMenu(hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
618 indexMenu++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
619 MF_STRING|MF_BYPOSITION,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
620 idCmd++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
621 _("Edit with &multiple Vims"));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
622
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
623 InsertMenu(hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
624 indexMenu++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
625 MF_STRING|MF_BYPOSITION,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
626 idCmd++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
627 _("Edit with single &Vim"));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
628
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
629 if (cbFiles <= 4)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
630 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
631 // Can edit up to 4 files in diff mode
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
632 InsertMenu(hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
633 indexMenu++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
634 MF_STRING|MF_BYPOSITION,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
635 idCmd++,
23
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 10
diff changeset
636 _("Diff with Vim"));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
637 m_edit_existing_off = 3;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
638 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
639 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
640 m_edit_existing_off = 2;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
641
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
642 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
643 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
644 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
645 InsertMenu(hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
646 indexMenu++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
647 MF_STRING|MF_BYPOSITION,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
648 idCmd++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
649 _("Edit with &Vim"));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
650 m_edit_existing_off = 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
651 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
652
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
653 // Now display all the vim instances
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
654 for (int i = 0; i < m_cntOfHWnd; i++)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
655 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
656 char title[BUFSIZE];
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
657 char temp[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
658
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
659 // Obtain window title, continue if can not
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
660 if (GetWindowText(m_hWnd[i], title, BUFSIZE - 1) == 0)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
661 continue;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
662 // Truncate the title before the path, keep the file name
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
663 char *pos = strchr(title, '(');
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
664 if (pos != NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
665 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
666 if (pos > title && pos[-1] == ' ')
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
667 --pos;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
668 *pos = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
669 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
670 // Now concatenate
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
671 strncpy(temp, _("Edit with existing Vim - "), BUFSIZE - 1);
1953
378e33d47ab0 updated for version 7.2-250
vimboss
parents: 1686
diff changeset
672 temp[BUFSIZE - 1] = '\0';
378e33d47ab0 updated for version 7.2-250
vimboss
parents: 1686
diff changeset
673 strncat(temp, title, BUFSIZE - 1 - strlen(temp));
378e33d47ab0 updated for version 7.2-250
vimboss
parents: 1686
diff changeset
674 temp[BUFSIZE - 1] = '\0';
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
675 InsertMenu(hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
676 indexMenu++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
677 MF_STRING|MF_BYPOSITION,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
678 idCmd++,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
679 temp);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
680 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
681 // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
682
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
683 // Must return number of menu items we added.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
684 return ResultFromShort(idCmd-idCmdFirst);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
685 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
686
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
687 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
688 // FUNCTION: CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
689 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
690 // PURPOSE: Called by the shell after the user has selected on of the
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
691 // menu items that was added in QueryContextMenu().
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
692 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
693 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
694 // lpcmi - Pointer to an CMINVOKECOMMANDINFO structure
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
695 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
696 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
697 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
698 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
699 // COMMENTS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
700 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
701
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
702 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
703 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
704 HRESULT hr = E_INVALIDARG;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
705
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
706 // If HIWORD(lpcmi->lpVerb) then we have been called programmatically
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
707 // and lpVerb is a command that should be invoked. Otherwise, the shell
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
708 // has called us, and LOWORD(lpcmi->lpVerb) is the menu ID the user has
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
709 // selected. Actually, it's (menu ID - idCmdFirst) from QueryContextMenu().
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
710 if (!HIWORD(lpcmi->lpVerb))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
711 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
712 UINT idCmd = LOWORD(lpcmi->lpVerb);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
713
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
714 if (idCmd >= m_edit_existing_off)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
715 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
716 // Existing with vim instance
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
717 hr = PushToWindow(lpcmi->hwnd,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
718 lpcmi->lpDirectory,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
719 lpcmi->lpVerb,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
720 lpcmi->lpParameters,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
721 lpcmi->nShow,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
722 idCmd - m_edit_existing_off);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
723 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
724 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
725 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
726 switch (idCmd)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
727 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
728 case 0:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
729 hr = InvokeGvim(lpcmi->hwnd,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
730 lpcmi->lpDirectory,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
731 lpcmi->lpVerb,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
732 lpcmi->lpParameters,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
733 lpcmi->nShow);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
734 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
735 case 1:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
736 hr = InvokeSingleGvim(lpcmi->hwnd,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
737 lpcmi->lpDirectory,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
738 lpcmi->lpVerb,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
739 lpcmi->lpParameters,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
740 lpcmi->nShow,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
741 0);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
742 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
743 case 2:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
744 hr = InvokeSingleGvim(lpcmi->hwnd,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
745 lpcmi->lpDirectory,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
746 lpcmi->lpVerb,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
747 lpcmi->lpParameters,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
748 lpcmi->nShow,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
749 1);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
750 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
751 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
752 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
753 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
754 return hr;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
755 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
756
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
757 STDMETHODIMP CShellExt::PushToWindow(HWND /* hParent */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
758 LPCSTR /* pszWorkingDir */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
759 LPCSTR /* pszCmd */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
760 LPCSTR /* pszParam */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
761 int /* iShowCmd */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
762 int idHWnd)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
763 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
764 HWND hWnd = m_hWnd[idHWnd];
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
765
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
766 // Show and bring vim instance to foreground
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
767 if (IsIconic(hWnd) != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
768 ShowWindow(hWnd, SW_RESTORE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
769 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
770 ShowWindow(hWnd, SW_SHOW);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
771 SetForegroundWindow(hWnd);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
772
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
773 // Post the selected files to the vim instance
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
774 PostMessage(hWnd, WM_DROPFILES, (WPARAM)medium.hGlobal, 0);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
775
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
776 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
777 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
778
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
779 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR /* idCmd */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
780 UINT uFlags,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
781 UINT FAR * /* reserved */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
782 LPSTR pszName,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
783 UINT cchMax)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
784 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
785 if (uFlags == GCS_HELPTEXT && cchMax > 35)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
786 lstrcpy(pszName, _("Edits the selected file(s) with Vim"));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
787
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
788 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
789 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
790
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
791 BOOL CALLBACK CShellExt::EnumWindowsProc(HWND hWnd, LPARAM lParam)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
792 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
793 char temp[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
794
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
795 // First do a bunch of check
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
796 // No invisible window
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
797 if (!IsWindowVisible(hWnd)) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
798 // No child window ???
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
799 // if (GetParent(hWnd)) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
800 // Class name should be Vim, if failed to get class name, return
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
801 if (GetClassName(hWnd, temp, sizeof(temp)) == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
802 return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
803 // Compare class name to that of vim, if not, return
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
804 if (_strnicmp(temp, "vim", sizeof("vim")) != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
805 return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
806 // First check if the number of vim instance exceeds MAX_HWND
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
807 CShellExt *cs = (CShellExt*) lParam;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
808 if (cs->m_cntOfHWnd >= MAX_HWND) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
809 // Now we get the vim window, put it into some kind of array
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
810 cs->m_hWnd[cs->m_cntOfHWnd] = hWnd;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
811 cs->m_cntOfHWnd ++;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
812
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
813 return TRUE; // continue enumeration (otherwise this would be false)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
814 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
815
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
816 #ifdef WIN32
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
817 // This symbol is not defined in older versions of the SDK or Visual C++.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
818
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
819 #ifndef VER_PLATFORM_WIN32_WINDOWS
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
820 # define VER_PLATFORM_WIN32_WINDOWS 1
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
821 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
822
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
823 static DWORD g_PlatformId;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
824
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
825 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
826 // Set g_PlatformId to VER_PLATFORM_WIN32_NT (NT) or
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
827 // VER_PLATFORM_WIN32_WINDOWS (Win95).
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
828 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
829 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
830 PlatformId(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
831 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
832 static int done = FALSE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
833
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
834 if (!done)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
835 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
836 OSVERSIONINFO ovi;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
837
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
838 ovi.dwOSVersionInfoSize = sizeof(ovi);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
839 GetVersionEx(&ovi);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
840
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
841 g_PlatformId = ovi.dwPlatformId;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
842 done = TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
843 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
844 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
845
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
846 # ifndef __BORLANDC__
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
847 static char *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
848 searchpath(char *name)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
849 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
850 static char widename[2 * BUFSIZE];
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
851 static char location[2 * BUFSIZE + 2];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
852
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
853 // There appears to be a bug in FindExecutableA() on Windows NT.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
854 // Use FindExecutableW() instead...
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
855 PlatformId();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
856 if (g_PlatformId == VER_PLATFORM_WIN32_NT)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
857 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
858 MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)name, -1,
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
859 (LPWSTR)widename, BUFSIZE);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
860 if (FindExecutableW((LPCWSTR)widename, (LPCWSTR)"",
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
861 (LPWSTR)location) > (HINSTANCE)32)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
862 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
863 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)location, -1,
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
864 (LPSTR)widename, 2 * BUFSIZE, NULL, NULL);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
865 return widename;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
866 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
867 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
868 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
869 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
870 if (FindExecutableA((LPCTSTR)name, (LPCTSTR)"",
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
871 (LPTSTR)location) > (HINSTANCE)32)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
872 return location;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
873 }
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
874 return (char *)"";
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
875 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
876 # endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
877 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
878
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
879 STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
880 LPCSTR /* pszWorkingDir */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
881 LPCSTR /* pszCmd */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
882 LPCSTR /* pszParam */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
883 int /* iShowCmd */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
884 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
885 wchar_t m_szFileUserClickedOn[BUFSIZE];
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
886 wchar_t cmdStrW[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
887 UINT i;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
888
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
889 for (i = 0; i < cbFiles; i++)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
890 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
891 DragQueryFileW((HDROP)medium.hGlobal,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
892 i,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
893 m_szFileUserClickedOn,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
894 sizeof(m_szFileUserClickedOn));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
895
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
896 getGvimNameW(cmdStrW);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
897 wcscat(cmdStrW, L" \"");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
898
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
899 if ((wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 2) < BUFSIZE)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
900 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
901 wcscat(cmdStrW, m_szFileUserClickedOn);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
902 wcscat(cmdStrW, L"\"");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
903
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
904 STARTUPINFOW si;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
905 PROCESS_INFORMATION pi;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
906
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
907 ZeroMemory(&si, sizeof(si));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
908 si.cb = sizeof(si);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
909
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
910 // Start the child process.
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
911 if (!CreateProcessW(NULL, // No module name (use command line).
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
912 cmdStrW, // Command line.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
913 NULL, // Process handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
914 NULL, // Thread handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
915 FALSE, // Set handle inheritance to FALSE.
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
916 oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
917 oldenv, // Use unmodified environment block.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
918 NULL, // Use parent's starting directory.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
919 &si, // Pointer to STARTUPINFO structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
920 &pi) // Pointer to PROCESS_INFORMATION structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
921 )
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
922 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
923 MessageBox(
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
924 hParent,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
925 _("Error creating process: Check if gvim is in your path!"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
926 _("gvimext.dll error"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
927 MB_OK);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
928 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
929 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
930 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
931 CloseHandle( pi.hProcess );
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
932 CloseHandle( pi.hThread );
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
933 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
934 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
935 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
936 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
937 MessageBox(
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
938 hParent,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
939 _("Path length too long!"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
940 _("gvimext.dll error"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
941 MB_OK);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
942 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
943 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
944
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
945 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
946 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
947
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
948
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
949 STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
950 LPCSTR /* pszWorkingDir */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
951 LPCSTR /* pszCmd */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
952 LPCSTR /* pszParam */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
953 int /* iShowCmd */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
954 int useDiff)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
955 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
956 wchar_t m_szFileUserClickedOn[BUFSIZE];
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
957 wchar_t *cmdStrW;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
958 size_t cmdlen;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
959 size_t len;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
960 UINT i;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
961
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
962 cmdlen = BUFSIZE;
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
963 cmdStrW = (wchar_t *) malloc(cmdlen * sizeof(wchar_t));
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
964 getGvimNameW(cmdStrW);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
965
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
966 if (useDiff)
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
967 wcscat(cmdStrW, L" -d");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
968 for (i = 0; i < cbFiles; i++)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
969 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
970 DragQueryFileW((HDROP)medium.hGlobal,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
971 i,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
972 m_szFileUserClickedOn,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
973 sizeof(m_szFileUserClickedOn));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
974
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
975 len = wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 4;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
976 if (len > cmdlen)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
977 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
978 cmdlen = len + BUFSIZE;
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
979 cmdStrW = (wchar_t *)realloc(cmdStrW, cmdlen * sizeof(wchar_t));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
980 }
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
981 wcscat(cmdStrW, L" \"");
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
982 wcscat(cmdStrW, m_szFileUserClickedOn);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
983 wcscat(cmdStrW, L"\"");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
984 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
985
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
986 STARTUPINFOW si;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
987 PROCESS_INFORMATION pi;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
988
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
989 ZeroMemory(&si, sizeof(si));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
990 si.cb = sizeof(si);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
991
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
992 // Start the child process.
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
993 if (!CreateProcessW(NULL, // No module name (use command line).
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
994 cmdStrW, // Command line.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
995 NULL, // Process handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
996 NULL, // Thread handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
997 FALSE, // Set handle inheritance to FALSE.
3008
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
998 oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
37a54a85413e updated for version 7.3.276
Bram Moolenaar <bram@vim.org>
parents: 2972
diff changeset
999 oldenv, // Use unmodified environment block.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1000 NULL, // Use parent's starting directory.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1001 &si, // Pointer to STARTUPINFO structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1002 &pi) // Pointer to PROCESS_INFORMATION structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1003 )
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1004 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1005 MessageBox(
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1006 hParent,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1007 _("Error creating process: Check if gvim is in your path!"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1008 _("gvimext.dll error"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1009 MB_OK);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1010 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1011 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1012 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1013 CloseHandle(pi.hProcess);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1014 CloseHandle(pi.hThread);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1015 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1016
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
1017 free(cmdStrW);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1018
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1019 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1020 }