annotate src/GvimExt/gvimext.cpp @ 32669:448aef880252

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