push e263afdf8dbf9f9408e8594e045d25c4af1d55cd
[wine/hacks.git] / dlls / mlang / mlang.c
blob0920178c6ade5338a16956de81b09e329f43697a
1 /*
2 * MLANG Class Factory
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003,2004 Mike McCormack
6 * Copyright 2004,2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "mlang.h"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
42 #include "initguid.h"
44 #define CP_UNICODE 1200
46 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
48 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
49 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
51 static DWORD MLANG_tls_index; /* to store various per thead data */
53 /* FIXME:
54 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
55 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
58 typedef struct
60 const char *description;
61 UINT cp;
62 DWORD flags;
63 const char *web_charset;
64 const char *header_charset;
65 const char *body_charset;
66 } MIME_CP_INFO;
68 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
69 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
71 static const MIME_CP_INFO arabic_cp[] =
73 { "Arabic (864)",
74 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
75 MIMECONTF_MIME_LATEST,
76 "ibm864", "ibm864", "ibm864" },
77 { "Arabic (1006)",
78 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
79 MIMECONTF_MIME_LATEST,
80 "ibm1006", "ibm1006", "ibm1006" },
81 { "Arabic (Windows)",
82 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
83 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
84 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
85 "windows-1256", "windows-1256", "windows-1256" },
86 { "Arabic (ISO)",
87 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
88 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
89 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
90 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
91 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
93 static const MIME_CP_INFO baltic_cp[] =
95 { "Baltic (DOS)",
96 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
97 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
98 "ibm775", "ibm775", "ibm775" },
99 { "Baltic (Windows)",
100 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
101 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
102 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
103 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
104 "windows-1257", "windows-1257", "windows-1257" },
105 { "Baltic (ISO)",
106 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
107 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
108 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
109 MIMECONTF_MIME_LATEST,
110 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
111 { "Estonian (ISO)",
112 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
113 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
114 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
116 static const MIME_CP_INFO chinese_simplified_cp[] =
118 { "Chinese Simplified (GB2312)",
119 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
120 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
121 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
122 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
123 "gb2312", "gb2312", "gb2312" }
125 static const MIME_CP_INFO chinese_traditional_cp[] =
127 { "Chinese Traditional (Big5)",
128 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
129 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
130 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
131 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
132 "big5", "big5", "big5" }
134 static const MIME_CP_INFO central_european_cp[] =
136 { "Central European (DOS)",
137 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
138 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
139 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
140 "ibm852", "ibm852", "ibm852" },
141 { "Central European (Windows)",
142 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
143 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
144 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
145 MIMECONTF_MIME_LATEST,
146 "windows-1250", "windows-1250", "windows-1250" },
147 { "Central European (Mac)",
148 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
149 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
150 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
151 { "Central European (ISO)",
152 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
153 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
154 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
155 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
156 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
158 static const MIME_CP_INFO cyrillic_cp[] =
160 { "OEM Cyrillic",
161 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
162 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
163 "ibm855", "ibm855", "ibm855" },
164 { "Cyrillic (DOS)",
165 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
166 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
167 MIMECONTF_MIME_LATEST,
168 "cp866", "cp866", "cp866" },
169 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
170 { "Cyrillic (KOI8-R)",
171 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
172 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
173 "koi8-r", "koi8-r", "koi8-r" },
174 #endif
175 { "Cyrillic (Windows)",
176 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
177 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
178 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
179 "windows-1251", "windows-1251", "windows-1251" },
180 { "Cyrillic (Mac)",
181 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
182 MIMECONTF_MIME_LATEST,
183 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
184 { "Cyrillic (KOI8-R)",
185 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
186 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
187 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
188 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
189 "koi8-r", "koi8-r", "koi8-r" },
190 { "Cyrillic (KOI8-U)",
191 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
192 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
193 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
194 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
195 "koi8-u", "koi8-u", "koi8-u" },
196 { "Cyrillic (ISO)",
197 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
198 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
199 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
200 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
201 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
203 static const MIME_CP_INFO greek_cp[] =
205 { "Greek (DOS)",
206 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
207 MIMECONTF_MIME_LATEST,
208 "ibm737", "ibm737", "ibm737" },
209 { "Greek, Modern (DOS)",
210 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
211 MIMECONTF_MIME_LATEST,
212 "ibm869", "ibm869", "ibm869" },
213 { "IBM EBCDIC (Greek Modern)",
214 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
215 MIMECONTF_MIME_LATEST,
216 "cp875", "cp875", "cp875" },
217 { "Greek (Windows)",
218 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
219 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
220 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
221 "windows-1253", "windows-1253", "windows-1253" },
222 { "Greek (Mac)",
223 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
224 MIMECONTF_MIME_LATEST,
225 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
226 { "Greek (ISO)",
227 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
228 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
229 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
230 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
231 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
233 static const MIME_CP_INFO hebrew_cp[] =
235 { "Hebrew (424)",
236 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
237 MIMECONTF_MIME_LATEST,
238 "ibm424", "ibm424", "ibm424" },
239 { "Hebrew (856)",
240 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
241 MIMECONTF_MIME_LATEST,
242 "cp856", "cp856", "cp856" },
243 { "Hebrew (DOS)",
244 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
245 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
246 MIMECONTF_MIME_LATEST,
247 "dos-862", "dos-862", "dos-862" },
248 { "Hebrew (Windows)",
249 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
250 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
251 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
252 "windows-1255", "windows-1255", "windows-1255" },
253 { "Hebrew (ISO-Visual)",
254 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
255 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
256 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
257 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
259 static const MIME_CP_INFO japanese_cp[] =
261 { "Japanese (Shift-JIS)",
262 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
263 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
264 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
265 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
266 "shift_jis", "iso-2022-jp", "iso-2022-jp" },
267 { "Japanese (JIS 0208-1990 and 0212-1990)",
268 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
269 MIMECONTF_MIME_LATEST,
270 "euc-jp", "euc-jp", "euc-jp" }
272 static const MIME_CP_INFO korean_cp[] =
274 { "Korean",
275 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
276 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
277 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
278 MIMECONTF_MIME_LATEST,
279 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
281 static const MIME_CP_INFO thai_cp[] =
283 { "Thai (Windows)",
284 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
285 "ibm-thai", "ibm-thai", "ibm-thai" }
287 static const MIME_CP_INFO turkish_cp[] =
289 { "Turkish (DOS)",
290 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
291 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
292 "ibm857", "ibm857", "ibm857" },
293 { "IBM EBCDIC (Turkish Latin-5)",
294 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
295 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
296 "ibm1026", "ibm1026", "ibm1026" },
297 { "Turkish (Windows)",
298 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
299 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
300 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
301 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
302 "windows-1254", "windows-1254", "windows-1254" },
303 { "Turkish (Mac)",
304 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
305 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
306 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
307 { "Latin 3 (ISO)",
308 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
309 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
310 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
311 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
312 { "Turkish (ISO)",
313 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
314 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
315 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
316 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
317 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
319 static const MIME_CP_INFO vietnamese_cp[] =
321 { "Vietnamese (Windows)",
322 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
323 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
324 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
325 MIMECONTF_MIME_LATEST,
326 "windows-1258", "windows-1258", "windows-1258" }
328 static const MIME_CP_INFO western_cp[] =
330 { "IBM EBCDIC (US-Canada)",
331 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
332 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
333 "ibm037", "ibm037", "ibm037" },
334 { "OEM United States",
335 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
336 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
337 "ibm437", "ibm437", "ibm437" },
338 { "IBM EBCDIC (International)",
339 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
340 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
341 "ibm500", "ibm500", "ibm500" },
342 { "Western European (DOS)",
343 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
344 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
345 "ibm850", "ibm850", "ibm850" },
346 { "Portuguese (DOS)",
347 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
348 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
349 "ibm860", "ibm860", "ibm860" },
350 { "Icelandic (DOS)",
351 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
352 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
353 "ibm861", "ibm861", "ibm861" },
354 { "French Canadian (DOS)",
355 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
356 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
357 "ibm863", "ibm863", "ibm863" },
358 { "Nordic (DOS)",
359 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
360 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
361 "ibm865", "ibm865", "ibm865" },
362 { "Western European (Windows)",
363 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
364 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
365 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
366 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
367 "windows-1252", "windows-1252", "iso-8859-1" },
368 { "Western European (Mac)",
369 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
370 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
371 "macintosh", "macintosh", "macintosh" },
372 { "Icelandic (Mac)",
373 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
374 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
375 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
376 { "US-ASCII",
377 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
378 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
379 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
380 "us-ascii", "us-ascii", "us-ascii" },
381 { "Western European (ISO)",
382 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
383 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
384 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
385 MIMECONTF_MIME_LATEST,
386 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
387 { "Latin 9 (ISO)",
388 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
389 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
390 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
391 MIMECONTF_MIME_LATEST,
392 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
394 static const MIME_CP_INFO unicode_cp[] =
396 { "Unicode",
397 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
398 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
399 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
400 MIMECONTF_MIME_LATEST,
401 "unicode", "unicode", "unicode" },
402 { "Unicode (UTF-7)",
403 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
404 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
405 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
406 "utf-7", "utf-7", "utf-7" },
407 { "Unicode (UTF-8)",
408 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
409 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
410 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
411 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
412 "utf-8", "utf-8", "utf-8" }
415 static const struct mlang_data
417 const char *description;
418 UINT family_codepage;
419 UINT number_of_cp;
420 const MIME_CP_INFO *mime_cp_info;
421 const char *fixed_font;
422 const char *proportional_font;
423 } mlang_data[] =
425 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
426 "Courier","Arial" }, /* FIXME */
427 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
428 "Courier","Arial" }, /* FIXME */
429 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
430 "Courier","Arial" }, /* FIXME */
431 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
432 "Courier","Arial" }, /* FIXME */
433 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
434 "Courier","Arial" }, /* FIXME */
435 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
436 "Courier","Arial" }, /* FIXME */
437 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
438 "Courier","Arial" }, /* FIXME */
439 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
440 "Courier","Arial" }, /* FIXME */
441 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
442 "Courier","Arial" }, /* FIXME */
443 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
444 "Courier","Arial" }, /* FIXME */
445 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
446 "Courier","Arial" }, /* FIXME */
447 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
448 "Courier","Arial" }, /* FIXME */
449 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
450 "Courier","Arial" }, /* FIXME */
451 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
452 "Courier","Arial" }, /* FIXME */
453 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
454 "Courier","Arial" } /* FIXME */
457 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
459 static LONG dll_count;
462 * Dll lifetime tracking declaration
464 static void LockModule(void)
466 InterlockedIncrement(&dll_count);
469 static void UnlockModule(void)
471 InterlockedDecrement(&dll_count);
474 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
476 switch(fdwReason) {
477 case DLL_PROCESS_ATTACH:
478 MLANG_tls_index = TlsAlloc();
479 DisableThreadLibraryCalls(hInstDLL);
480 break;
481 case DLL_PROCESS_DETACH:
482 TlsFree(MLANG_tls_index);
483 break;
485 return TRUE;
488 HRESULT WINAPI ConvertINetMultiByteToUnicode(
489 LPDWORD pdwMode,
490 DWORD dwEncoding,
491 LPCSTR pSrcStr,
492 LPINT pcSrcSize,
493 LPWSTR pDstStr,
494 LPINT pcDstSize)
496 INT src_len = -1;
498 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
499 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
501 if (!pcDstSize)
502 return E_FAIL;
504 if (!pcSrcSize)
505 pcSrcSize = &src_len;
507 if (!*pcSrcSize)
509 *pcDstSize = 0;
510 return S_OK;
513 switch (dwEncoding)
515 case CP_UNICODE:
516 if (*pcSrcSize == -1)
517 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
518 *pcDstSize = min(*pcSrcSize, *pcDstSize);
519 *pcSrcSize *= sizeof(WCHAR);
520 if (pDstStr)
521 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
522 break;
524 default:
525 if (*pcSrcSize == -1)
526 *pcSrcSize = lstrlenA(pSrcStr);
528 if (pDstStr)
529 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
530 else
531 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
532 break;
535 if (!*pcDstSize)
536 return E_FAIL;
538 return S_OK;
541 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
542 LPDWORD pdwMode,
543 DWORD dwEncoding,
544 LPCWSTR pSrcStr,
545 LPINT pcSrcSize,
546 LPSTR pDstStr,
547 LPINT pcDstSize)
549 INT destsz, size;
550 INT src_len = -1;
552 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
553 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
555 if (!pcDstSize)
556 return S_OK;
558 if (!pcSrcSize)
559 pcSrcSize = &src_len;
561 destsz = (pDstStr) ? *pcDstSize : 0;
562 *pcDstSize = 0;
564 if (!pSrcStr || !*pcSrcSize)
565 return S_OK;
567 if (*pcSrcSize == -1)
568 *pcSrcSize = lstrlenW(pSrcStr);
570 if (dwEncoding == CP_UNICODE)
572 if (*pcSrcSize == -1)
573 *pcSrcSize = lstrlenW(pSrcStr);
575 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
576 if (pDstStr)
577 memmove(pDstStr, pSrcStr, size);
579 if (size >= destsz)
580 goto fail;
582 else
584 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
585 NULL, 0, NULL, NULL);
586 if (!size)
587 goto fail;
589 if (pDstStr)
591 size = min(size, destsz);
592 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
593 pDstStr, destsz, NULL, NULL);
594 if (!size)
595 goto fail;
599 *pcDstSize = size;
600 return S_OK;
602 fail:
603 *pcSrcSize = 0;
604 *pcDstSize = 0;
605 return E_FAIL;
608 HRESULT WINAPI ConvertINetString(
609 LPDWORD pdwMode,
610 DWORD dwSrcEncoding,
611 DWORD dwDstEncoding,
612 LPCSTR pSrcStr,
613 LPINT pcSrcSize,
614 LPSTR pDstStr,
615 LPINT pcDstSize
618 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
619 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
621 if (dwSrcEncoding == CP_UNICODE)
623 INT cSrcSizeW;
624 if (pcSrcSize && *pcSrcSize != -1)
626 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
627 pcSrcSize = &cSrcSizeW;
629 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
631 else if (dwDstEncoding == CP_UNICODE)
633 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
634 *pcDstSize *= sizeof(WCHAR);
635 return hr;
637 else
639 INT cDstSizeW;
640 LPWSTR pDstStrW;
641 HRESULT hr;
643 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
645 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
646 if (hr != S_OK)
647 return hr;
649 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
650 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
651 if (hr == S_OK)
652 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
654 HeapFree(GetProcessHeap(), 0, pDstStrW);
655 return hr;
659 static HRESULT GetFamilyCodePage(
660 UINT uiCodePage,
661 UINT* puiFamilyCodePage)
663 UINT i, n;
665 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
667 if (!puiFamilyCodePage) return S_FALSE;
669 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
671 for (n = 0; n < mlang_data[i].number_of_cp; n++)
673 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
675 *puiFamilyCodePage = mlang_data[i].family_codepage;
676 return S_OK;
681 return S_FALSE;
684 HRESULT WINAPI IsConvertINetStringAvailable(
685 DWORD dwSrcEncoding,
686 DWORD dwDstEncoding)
688 UINT src_family, dst_family;
690 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
692 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
693 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
694 return S_FALSE;
696 if (src_family == dst_family) return S_OK;
698 /* we can convert any codepage to/from unicode */
699 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
701 return S_FALSE;
704 static inline INT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
706 INT n = GetLocaleInfoA( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
707 if (n)
709 rfc1766[n - 1] = '-';
710 n += GetLocaleInfoA( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
711 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
712 return n;
714 return 0;
717 static inline INT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
719 INT n = GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
720 INT save = n;
721 if (n)
723 rfc1766[n - 1] = '-';
724 n += GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
725 if (n == save)
726 rfc1766[n - 1] = '\0';
727 LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
728 return n;
730 return 0;
733 HRESULT WINAPI LcidToRfc1766A(
734 LCID lcid,
735 LPSTR pszRfc1766,
736 INT nChar)
738 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
740 if (lcid_to_rfc1766A( lcid, pszRfc1766, nChar ))
741 return S_OK;
743 return S_FALSE;
746 HRESULT WINAPI LcidToRfc1766W(
747 LCID lcid,
748 LPWSTR pszRfc1766,
749 INT nChar)
751 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
753 if (lcid_to_rfc1766W( lcid, pszRfc1766, nChar ))
754 return S_OK;
756 return S_FALSE;
759 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
761 RFC1766INFO info;
762 ULONG num;
764 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
766 if (!strcmpW(info.wszRfc1766, rfc1766))
768 *lcid = info.lcid;
769 return S_OK;
771 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
773 *lcid = PRIMARYLANGID(info.lcid);
774 return S_OK;
778 return E_FAIL;
781 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
783 IEnumRfc1766 *enumrfc1766;
784 HRESULT hr;
786 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
788 if (!pLocale || !pszRfc1766)
789 return E_INVALIDARG;
791 *pLocale = 0;
793 hr = EnumRfc1766_create(0, &enumrfc1766);
794 if (FAILED(hr))
795 return hr;
797 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
798 IEnumRfc1766_Release(enumrfc1766);
800 return hr;
803 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
805 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
807 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
808 rfc1766W[MAX_RFC1766_NAME] = 0;
810 return Rfc1766ToLcidW(lcid, rfc1766W);
813 /******************************************************************************
814 * MLANG ClassFactory
816 typedef struct {
817 IClassFactory ITF_IClassFactory;
819 LONG ref;
820 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
821 } IClassFactoryImpl;
823 struct object_creation_info
825 const CLSID *clsid;
826 LPCSTR szClassName;
827 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
830 static const struct object_creation_info object_creation[] =
832 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
835 static HRESULT WINAPI
836 MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
838 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
840 TRACE("%s\n", debugstr_guid(riid) );
842 if (IsEqualGUID(riid, &IID_IUnknown)
843 || IsEqualGUID(riid, &IID_IClassFactory))
845 IClassFactory_AddRef(iface);
846 *ppobj = This;
847 return S_OK;
850 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
851 return E_NOINTERFACE;
854 static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
856 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
857 return InterlockedIncrement(&This->ref);
860 static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
862 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
864 ULONG ref = InterlockedDecrement(&This->ref);
866 if (ref == 0)
868 TRACE("Destroying %p\n", This);
869 HeapFree(GetProcessHeap(), 0, This);
872 return ref;
875 static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
876 REFIID riid, LPVOID *ppobj)
878 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
879 HRESULT hres;
880 LPUNKNOWN punk;
882 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
884 *ppobj = NULL;
885 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
886 if (SUCCEEDED(hres)) {
887 hres = IUnknown_QueryInterface(punk, riid, ppobj);
888 IUnknown_Release(punk);
890 TRACE("returning (%p) -> %x\n", *ppobj, hres);
891 return hres;
894 static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
896 if (dolock)
897 LockModule();
898 else
899 UnlockModule();
901 return S_OK;
904 static const IClassFactoryVtbl MLANGCF_Vtbl =
906 MLANGCF_QueryInterface,
907 MLANGCF_AddRef,
908 MLANGCF_Release,
909 MLANGCF_CreateInstance,
910 MLANGCF_LockServer
913 /******************************************************************
914 * DllGetClassObject (MLANG.@)
916 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
918 int i;
919 IClassFactoryImpl *factory;
921 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
923 if ( !IsEqualGUID( &IID_IClassFactory, iid )
924 && ! IsEqualGUID( &IID_IUnknown, iid) )
925 return E_NOINTERFACE;
927 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
929 if (IsEqualGUID(object_creation[i].clsid, rclsid))
930 break;
933 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
935 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
936 return CLASS_E_CLASSNOTAVAILABLE;
939 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
941 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
942 if (factory == NULL) return E_OUTOFMEMORY;
944 factory->ITF_IClassFactory.lpVtbl = &MLANGCF_Vtbl;
945 factory->ref = 1;
947 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
949 *ppv = &(factory->ITF_IClassFactory);
951 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
953 return S_OK;
957 /******************************************************************************/
959 typedef struct tagMLang_impl
961 const IMLangFontLinkVtbl *vtbl_IMLangFontLink;
962 const IMultiLanguageVtbl *vtbl_IMultiLanguage;
963 const IMultiLanguage3Vtbl *vtbl_IMultiLanguage3;
964 const IMLangFontLink2Vtbl *vtbl_IMLangFontLink2;
965 LONG ref;
966 DWORD total_cp, total_scripts;
967 } MLang_impl;
969 static ULONG WINAPI MLang_AddRef( MLang_impl* This)
971 return InterlockedIncrement(&This->ref);
974 static ULONG WINAPI MLang_Release( MLang_impl* This )
976 ULONG ref = InterlockedDecrement(&This->ref);
978 TRACE("%p ref = %d\n", This, ref);
979 if (ref == 0)
981 TRACE("Destroying %p\n", This);
982 HeapFree(GetProcessHeap(), 0, This);
983 UnlockModule();
986 return ref;
989 static HRESULT WINAPI MLang_QueryInterface(
990 MLang_impl* This,
991 REFIID riid,
992 void** ppvObject)
994 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
996 if (IsEqualGUID(riid, &IID_IUnknown)
997 || IsEqualGUID(riid, &IID_IMLangCodePages)
998 || IsEqualGUID(riid, &IID_IMLangFontLink))
1000 MLang_AddRef(This);
1001 TRACE("Returning IID_IMLangFontLink %p ref = %d\n", This, This->ref);
1002 *ppvObject = &(This->vtbl_IMLangFontLink);
1003 return S_OK;
1006 if (IsEqualGUID(riid, &IID_IMLangFontLink2))
1008 MLang_AddRef(This);
1009 TRACE("Returning IID_IMLangFontLink2 %p ref = %d\n", This, This->ref);
1010 *ppvObject = &(This->vtbl_IMLangFontLink2);
1011 return S_OK;
1014 if (IsEqualGUID(riid, &IID_IMultiLanguage) )
1016 MLang_AddRef(This);
1017 TRACE("Returning IID_IMultiLanguage %p ref = %d\n", This, This->ref);
1018 *ppvObject = &(This->vtbl_IMultiLanguage);
1019 return S_OK;
1022 if (IsEqualGUID(riid, &IID_IMultiLanguage2) )
1024 MLang_AddRef(This);
1025 *ppvObject = &(This->vtbl_IMultiLanguage3);
1026 TRACE("Returning IID_IMultiLanguage2 %p ref = %d\n", This, This->ref);
1027 return S_OK;
1030 if (IsEqualGUID(riid, &IID_IMultiLanguage3) )
1032 MLang_AddRef(This);
1033 *ppvObject = &(This->vtbl_IMultiLanguage3);
1034 TRACE("Returning IID_IMultiLanguage3 %p ref = %d\n", This, This->ref);
1035 return S_OK;
1038 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1039 return E_NOINTERFACE;
1042 /******************************************************************************/
1044 typedef struct tagEnumCodePage_impl
1046 const IEnumCodePageVtbl *vtbl_IEnumCodePage;
1047 LONG ref;
1048 MIMECPINFO *cpinfo;
1049 DWORD total, pos;
1050 } EnumCodePage_impl;
1052 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1053 IEnumCodePage* iface,
1054 REFIID riid,
1055 void** ppvObject)
1057 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1059 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1061 if (IsEqualGUID(riid, &IID_IUnknown)
1062 || IsEqualGUID(riid, &IID_IEnumCodePage))
1064 IEnumCodePage_AddRef(iface);
1065 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1066 *ppvObject = &(This->vtbl_IEnumCodePage);
1067 return S_OK;
1070 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1071 return E_NOINTERFACE;
1074 static ULONG WINAPI fnIEnumCodePage_AddRef(
1075 IEnumCodePage* iface)
1077 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1078 return InterlockedIncrement(&This->ref);
1081 static ULONG WINAPI fnIEnumCodePage_Release(
1082 IEnumCodePage* iface)
1084 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1085 ULONG ref = InterlockedDecrement(&This->ref);
1087 TRACE("%p ref = %d\n", This, ref);
1088 if (ref == 0)
1090 TRACE("Destroying %p\n", This);
1091 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1092 HeapFree(GetProcessHeap(), 0, This);
1095 return ref;
1098 static HRESULT WINAPI fnIEnumCodePage_Clone(
1099 IEnumCodePage* iface,
1100 IEnumCodePage** ppEnum)
1102 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1103 FIXME("%p %p\n", This, ppEnum);
1104 return E_NOTIMPL;
1107 static HRESULT WINAPI fnIEnumCodePage_Next(
1108 IEnumCodePage* iface,
1109 ULONG celt,
1110 PMIMECPINFO rgelt,
1111 ULONG* pceltFetched)
1113 ULONG i;
1115 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1116 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1118 if (!pceltFetched) return S_FALSE;
1119 *pceltFetched = 0;
1121 if (!rgelt) return S_FALSE;
1123 if (This->pos + celt > This->total)
1124 celt = This->total - This->pos;
1126 if (!celt) return S_FALSE;
1128 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1129 *pceltFetched = celt;
1130 This->pos += celt;
1132 for (i = 0; i < celt; i++)
1134 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1135 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1136 rgelt[i].uiFamilyCodePage,
1137 wine_dbgstr_w(rgelt[i].wszDescription),
1138 wine_dbgstr_w(rgelt[i].wszWebCharset),
1139 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1140 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1141 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1142 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1143 rgelt[i].bGDICharset);
1145 return S_OK;
1148 static HRESULT WINAPI fnIEnumCodePage_Reset(
1149 IEnumCodePage* iface)
1151 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1152 TRACE("%p\n", This);
1154 This->pos = 0;
1155 return S_OK;
1158 static HRESULT WINAPI fnIEnumCodePage_Skip(
1159 IEnumCodePage* iface,
1160 ULONG celt)
1162 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1163 TRACE("%p %u\n", This, celt);
1165 if (celt >= This->total) return S_FALSE;
1167 This->pos += celt;
1168 return S_OK;
1171 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1173 fnIEnumCodePage_QueryInterface,
1174 fnIEnumCodePage_AddRef,
1175 fnIEnumCodePage_Release,
1176 fnIEnumCodePage_Clone,
1177 fnIEnumCodePage_Next,
1178 fnIEnumCodePage_Reset,
1179 fnIEnumCodePage_Skip
1182 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1183 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1185 EnumCodePage_impl *ecp;
1186 MIMECPINFO *cpinfo;
1187 UINT i, n;
1189 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1191 if (!grfFlags) /* enumerate internal data base of encodings */
1192 grfFlags = MIMECONTF_MIME_LATEST;
1194 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1195 ecp->vtbl_IEnumCodePage = &IEnumCodePage_vtbl;
1196 ecp->ref = 1;
1197 ecp->pos = 0;
1198 ecp->total = 0;
1199 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1201 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1203 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1204 ecp->total++;
1208 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1209 sizeof(MIMECPINFO) * ecp->total);
1210 cpinfo = ecp->cpinfo;
1212 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1214 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1216 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1217 fill_cp_info(&mlang_data[i], n, cpinfo++);
1221 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1223 *ppEnumCodePage = (IEnumCodePage*) ecp;
1225 return S_OK;
1228 /******************************************************************************/
1230 typedef struct tagEnumScript_impl
1232 const IEnumScriptVtbl *vtbl_IEnumScript;
1233 LONG ref;
1234 SCRIPTINFO *script_info;
1235 DWORD total, pos;
1236 } EnumScript_impl;
1238 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1239 IEnumScript* iface,
1240 REFIID riid,
1241 void** ppvObject)
1243 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1245 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1247 if (IsEqualGUID(riid, &IID_IUnknown)
1248 || IsEqualGUID(riid, &IID_IEnumScript))
1250 IEnumScript_AddRef(iface);
1251 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1252 *ppvObject = &(This->vtbl_IEnumScript);
1253 return S_OK;
1256 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1257 return E_NOINTERFACE;
1260 static ULONG WINAPI fnIEnumScript_AddRef(
1261 IEnumScript* iface)
1263 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1264 return InterlockedIncrement(&This->ref);
1267 static ULONG WINAPI fnIEnumScript_Release(
1268 IEnumScript* iface)
1270 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1271 ULONG ref = InterlockedDecrement(&This->ref);
1273 TRACE("%p ref = %d\n", This, ref);
1274 if (ref == 0)
1276 TRACE("Destroying %p\n", This);
1277 HeapFree(GetProcessHeap(), 0, This->script_info);
1278 HeapFree(GetProcessHeap(), 0, This);
1281 return ref;
1284 static HRESULT WINAPI fnIEnumScript_Clone(
1285 IEnumScript* iface,
1286 IEnumScript** ppEnum)
1288 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1289 FIXME("%p %p: stub!\n", This, ppEnum);
1290 return E_NOTIMPL;
1293 static HRESULT WINAPI fnIEnumScript_Next(
1294 IEnumScript* iface,
1295 ULONG celt,
1296 PSCRIPTINFO rgelt,
1297 ULONG* pceltFetched)
1299 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1300 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1302 if (!pceltFetched || !rgelt) return E_FAIL;
1304 *pceltFetched = 0;
1306 if (This->pos + celt > This->total)
1307 celt = This->total - This->pos;
1309 if (!celt) return S_FALSE;
1311 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1312 *pceltFetched = celt;
1313 This->pos += celt;
1315 return S_OK;
1318 static HRESULT WINAPI fnIEnumScript_Reset(
1319 IEnumScript* iface)
1321 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1322 TRACE("%p\n", This);
1324 This->pos = 0;
1325 return S_OK;
1328 static HRESULT WINAPI fnIEnumScript_Skip(
1329 IEnumScript* iface,
1330 ULONG celt)
1332 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1333 TRACE("%p %u\n", This, celt);
1335 if (celt >= This->total) return S_FALSE;
1337 This->pos += celt;
1338 return S_OK;
1341 static const IEnumScriptVtbl IEnumScript_vtbl =
1343 fnIEnumScript_QueryInterface,
1344 fnIEnumScript_AddRef,
1345 fnIEnumScript_Release,
1346 fnIEnumScript_Clone,
1347 fnIEnumScript_Next,
1348 fnIEnumScript_Reset,
1349 fnIEnumScript_Skip
1352 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1353 LANGID LangId, IEnumScript** ppEnumScript )
1355 EnumScript_impl *es;
1356 UINT i;
1358 TRACE("%p, %08x, %04x, %p: stub!\n", mlang, dwFlags, LangId, ppEnumScript);
1360 if (!dwFlags) /* enumerate all available scripts */
1361 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1363 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1364 es->vtbl_IEnumScript = &IEnumScript_vtbl;
1365 es->ref = 1;
1366 es->pos = 0;
1367 /* do not enumerate unicode flavours */
1368 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1369 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1371 for (i = 0; i < es->total; i++)
1373 es->script_info[i].ScriptId = i;
1374 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1375 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1376 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1377 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1378 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1379 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1380 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1383 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1385 *ppEnumScript = (IEnumScript *)es;
1387 return S_OK;
1390 /******************************************************************************/
1392 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1393 IMLangFontLink* iface,
1394 REFIID riid,
1395 void** ppvObject)
1397 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1398 return MLang_QueryInterface( This, riid, ppvObject );
1401 static ULONG WINAPI fnIMLangFontLink_AddRef(
1402 IMLangFontLink* iface)
1404 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1405 return MLang_AddRef( This );
1408 static ULONG WINAPI fnIMLangFontLink_Release(
1409 IMLangFontLink* iface)
1411 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1412 return MLang_Release( This );
1415 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1416 IMLangFontLink* iface,
1417 WCHAR chSrc,
1418 DWORD* pdwCodePages)
1420 FIXME("\n");
1421 return E_NOTIMPL;
1424 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1425 IMLangFontLink* iface,
1426 const WCHAR* pszSrc,
1427 long cchSrc,
1428 DWORD dwPriorityCodePages,
1429 DWORD* pdwCodePages,
1430 long* pcchCodePages)
1432 FIXME("(pszSrc=%s, cchSrc=%ld, dwPriorityCodePages=%d) stub\n", debugstr_w(pszSrc), cchSrc, dwPriorityCodePages);
1433 *pdwCodePages = 0;
1434 *pcchCodePages = 1;
1435 return S_OK;
1438 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1439 IMLangFontLink* iface,
1440 UINT uCodePage,
1441 DWORD* pdwCodePages)
1443 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1444 CHARSETINFO cs;
1445 BOOL rc;
1447 TRACE("(%p) Seeking %u\n",This, uCodePage);
1448 memset(&cs, 0, sizeof(cs));
1450 rc = TranslateCharsetInfo((DWORD*)uCodePage, &cs, TCI_SRCCODEPAGE);
1452 if (rc)
1454 *pdwCodePages = cs.fs.fsCsb[0];
1455 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1457 else
1458 TRACE("CodePage Not Found\n");
1460 return S_OK;
1463 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1464 IMLangFontLink* iface,
1465 DWORD dwCodePages,
1466 UINT uDefaultCodePage,
1467 UINT* puCodePage)
1469 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1470 DWORD mask = 0x00000000;
1471 UINT i;
1472 CHARSETINFO cs;
1473 BOOL rc;
1475 TRACE("(%p) scanning 0x%x default page %u\n",This, dwCodePages,
1476 uDefaultCodePage);
1478 *puCodePage = 0x00000000;
1480 rc = TranslateCharsetInfo((DWORD*)uDefaultCodePage, &cs, TCI_SRCCODEPAGE);
1482 if (rc && (dwCodePages & cs.fs.fsCsb[0]))
1484 TRACE("Found Default Codepage\n");
1485 *puCodePage = uDefaultCodePage;
1486 return S_OK;
1490 for (i = 0; i < 32; i++)
1493 mask = 1 << i;
1494 if (dwCodePages & mask)
1496 DWORD Csb[2];
1497 Csb[0] = mask;
1498 Csb[1] = 0x0;
1499 rc = TranslateCharsetInfo((DWORD*)Csb, &cs, TCI_SRCFONTSIG);
1500 if (!rc)
1501 continue;
1503 TRACE("Falling back to least significant found CodePage %u\n",
1504 cs.ciACP);
1505 *puCodePage = cs.ciACP;
1506 return S_OK;
1510 TRACE("no codepage found\n");
1511 return E_FAIL;
1514 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
1515 IMLangFontLink* iface,
1516 HDC hDC,
1517 HFONT hFont,
1518 DWORD* pdwCodePages)
1520 HFONT old_font;
1521 FONTSIGNATURE fontsig;
1522 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1524 TRACE("(%p)\n",This);
1526 old_font = SelectObject(hDC,hFont);
1527 GetTextCharsetInfo(hDC,&fontsig, 0);
1528 SelectObject(hDC,old_font);
1530 *pdwCodePages = fontsig.fsCsb[0];
1531 TRACE("CodePages is 0x%x\n",fontsig.fsCsb[0]);
1533 return S_OK;
1536 static HRESULT WINAPI fnIMLangFontLink_MapFont(
1537 IMLangFontLink* iface,
1538 HDC hDC,
1539 DWORD dwCodePages,
1540 HFONT hSrcFont,
1541 HFONT* phDestFont)
1543 FIXME("\n");
1544 return E_NOTIMPL;
1547 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
1548 IMLangFontLink* iface,
1549 HFONT hFont)
1551 FIXME("\n");
1552 return E_NOTIMPL;
1555 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
1556 IMLangFontLink* iface)
1558 FIXME("\n");
1559 return E_NOTIMPL;
1563 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
1565 fnIMLangFontLink_QueryInterface,
1566 fnIMLangFontLink_AddRef,
1567 fnIMLangFontLink_Release,
1568 fnIMLangFontLink_GetCharCodePages,
1569 fnIMLangFontLink_GetStrCodePages,
1570 fnIMLangFontLink_CodePageToCodePages,
1571 fnIMLangFontLink_CodePagesToCodePage,
1572 fnIMLangFontLink_GetFontCodePages,
1573 fnIMLangFontLink_MapFont,
1574 fnIMLangFontLink_ReleaseFont,
1575 fnIMLangFontLink_ResetFontMapping,
1578 /******************************************************************************/
1580 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
1581 IMultiLanguage* iface,
1582 REFIID riid,
1583 void** ppvObject)
1585 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1586 return MLang_QueryInterface( This, riid, ppvObject );
1589 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
1591 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1592 return IMLangFontLink_AddRef( ((IMLangFontLink*)This) );
1595 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
1597 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1598 return IMLangFontLink_Release( ((IMLangFontLink*)This) );
1601 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
1602 IMultiLanguage* iface,
1603 UINT* pcCodePage)
1605 FIXME("\n");
1606 return E_NOTIMPL;
1609 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
1610 IMultiLanguage* iface,
1611 UINT uiCodePage,
1612 PMIMECPINFO pCodePageInfo)
1614 UINT i, n;
1616 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1617 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
1619 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1621 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1623 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1625 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
1626 return S_OK;
1631 return S_FALSE;
1634 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
1635 IMultiLanguage* iface,
1636 UINT uiCodePage,
1637 UINT* puiFamilyCodePage)
1639 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
1642 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
1643 IMultiLanguage* iface,
1644 DWORD grfFlags,
1645 IEnumCodePage** ppEnumCodePage)
1647 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1648 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
1650 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
1653 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
1654 IMultiLanguage* iface,
1655 BSTR Charset,
1656 PMIMECSETINFO pCharsetInfo)
1658 FIXME("\n");
1659 return E_NOTIMPL;
1662 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
1663 IMultiLanguage* iface,
1664 DWORD dwSrcEncoding,
1665 DWORD dwDstEncoding)
1667 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
1670 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
1671 IMultiLanguage* iface,
1672 DWORD* pdwMode,
1673 DWORD dwSrcEncoding,
1674 DWORD dwDstEncoding,
1675 BYTE* pSrcStr,
1676 UINT* pcSrcSize,
1677 BYTE* pDstStr,
1678 UINT* pcDstSize)
1680 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
1681 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
1684 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
1685 IMultiLanguage* iface,
1686 DWORD* pdwMode,
1687 DWORD dwEncoding,
1688 CHAR* pSrcStr,
1689 UINT* pcSrcSize,
1690 WCHAR* pDstStr,
1691 UINT* pcDstSize)
1693 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
1694 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
1697 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
1698 IMultiLanguage* iface,
1699 DWORD* pdwMode,
1700 DWORD dwEncoding,
1701 WCHAR* pSrcStr,
1702 UINT* pcSrcSize,
1703 CHAR* pDstStr,
1704 UINT* pcDstSize)
1706 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
1707 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
1710 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
1711 IMultiLanguage* iface)
1713 FIXME("\n");
1714 return E_NOTIMPL;
1717 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
1718 IMultiLanguage* iface,
1719 LCID lcid,
1720 BSTR* pbstrRfc1766)
1722 WCHAR buf[MAX_RFC1766_NAME];
1724 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
1726 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
1728 *pbstrRfc1766 = SysAllocString( buf );
1729 return S_OK;
1731 return E_FAIL;
1734 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
1735 IMultiLanguage* iface,
1736 LCID* pLocale,
1737 BSTR bstrRfc1766)
1739 HRESULT hr;
1740 IEnumRfc1766 *rfc1766;
1742 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
1744 if (!pLocale || !bstrRfc1766)
1745 return E_INVALIDARG;
1747 hr = IMultiLanguage_EnumRfc1766(iface, &rfc1766);
1748 if (FAILED(hr))
1749 return hr;
1751 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
1753 IEnumRfc1766_Release(rfc1766);
1754 return hr;
1757 /******************************************************************************/
1759 typedef struct tagEnumRfc1766_impl
1761 const IEnumRfc1766Vtbl *vtbl_IEnumRfc1766;
1762 LONG ref;
1763 RFC1766INFO *info;
1764 DWORD total, pos;
1765 } EnumRfc1766_impl;
1767 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
1768 IEnumRfc1766 *iface,
1769 REFIID riid,
1770 void** ppvObject)
1772 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1774 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1776 if (IsEqualGUID(riid, &IID_IUnknown)
1777 || IsEqualGUID(riid, &IID_IEnumRfc1766))
1779 IEnumRfc1766_AddRef(iface);
1780 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
1781 *ppvObject = &(This->vtbl_IEnumRfc1766);
1782 return S_OK;
1785 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
1786 return E_NOINTERFACE;
1789 static ULONG WINAPI fnIEnumRfc1766_AddRef(
1790 IEnumRfc1766 *iface)
1792 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1793 return InterlockedIncrement(&This->ref);
1796 static ULONG WINAPI fnIEnumRfc1766_Release(
1797 IEnumRfc1766 *iface)
1799 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1800 ULONG ref = InterlockedDecrement(&This->ref);
1802 TRACE("%p ref = %d\n", This, ref);
1803 if (ref == 0)
1805 TRACE("Destroying %p\n", This);
1806 HeapFree(GetProcessHeap(), 0, This->info);
1807 HeapFree(GetProcessHeap(), 0, This);
1809 return ref;
1812 static HRESULT WINAPI fnIEnumRfc1766_Clone(
1813 IEnumRfc1766 *iface,
1814 IEnumRfc1766 **ppEnum)
1816 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1817 FIXME("%p %p\n", This, ppEnum);
1818 return E_NOTIMPL;
1821 static HRESULT WINAPI fnIEnumRfc1766_Next(
1822 IEnumRfc1766 *iface,
1823 ULONG celt,
1824 PRFC1766INFO rgelt,
1825 ULONG *pceltFetched)
1827 ULONG i;
1829 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1830 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1832 if (!pceltFetched) return S_FALSE;
1833 *pceltFetched = 0;
1835 if (!rgelt) return S_FALSE;
1837 if (This->pos + celt > This->total)
1838 celt = This->total - This->pos;
1840 if (!celt) return S_FALSE;
1842 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
1843 *pceltFetched = celt;
1844 This->pos += celt;
1846 for (i = 0; i < celt; i++)
1848 TRACE("#%u: %08x %s %s\n",
1849 i, rgelt[i].lcid,
1850 wine_dbgstr_w(rgelt[i].wszRfc1766),
1851 wine_dbgstr_w(rgelt[i].wszLocaleName));
1853 return S_OK;
1856 static HRESULT WINAPI fnIEnumRfc1766_Reset(
1857 IEnumRfc1766 *iface)
1859 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1860 TRACE("%p\n", This);
1862 This->pos = 0;
1863 return S_OK;
1866 static HRESULT WINAPI fnIEnumRfc1766_Skip(
1867 IEnumRfc1766 *iface,
1868 ULONG celt)
1870 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1871 TRACE("%p %u\n", This, celt);
1873 if (celt >= This->total) return S_FALSE;
1875 This->pos += celt;
1876 return S_OK;
1879 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
1881 fnIEnumRfc1766_QueryInterface,
1882 fnIEnumRfc1766_AddRef,
1883 fnIEnumRfc1766_Release,
1884 fnIEnumRfc1766_Clone,
1885 fnIEnumRfc1766_Next,
1886 fnIEnumRfc1766_Reset,
1887 fnIEnumRfc1766_Skip
1890 struct enum_locales_data
1892 RFC1766INFO *info;
1893 DWORD total, allocated;
1896 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
1898 WCHAR *end;
1899 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
1900 RFC1766INFO *info;
1902 TRACE("%s\n", debugstr_w(locale));
1904 if (data->total >= data->allocated)
1906 data->allocated += 32;
1907 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
1908 if (!data->info) return FALSE;
1911 info = &data->info[data->total];
1913 info->lcid = strtolW(locale, &end, 16);
1914 if (*end) /* invalid number */
1915 return FALSE;
1917 info->wszRfc1766[0] = 0;
1918 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
1920 info->wszLocaleName[0] = 0;
1921 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
1922 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
1924 data->total++;
1926 return TRUE;
1929 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
1931 EnumRfc1766_impl *rfc;
1932 struct enum_locales_data data;
1934 TRACE("%04x, %p\n", LangId, ppEnum);
1936 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
1937 rfc->vtbl_IEnumRfc1766 = &IEnumRfc1766_vtbl;
1938 rfc->ref = 1;
1939 rfc->pos = 0;
1940 rfc->total = 0;
1942 data.total = 0;
1943 data.allocated = 32;
1944 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
1945 if (!data.info)
1947 HeapFree(GetProcessHeap(), 0, rfc);
1948 return S_FALSE;
1951 TlsSetValue(MLANG_tls_index, &data);
1952 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
1953 TlsSetValue(MLANG_tls_index, NULL);
1955 TRACE("enumerated %d rfc1766 structures\n", data.total);
1957 if (!data.total)
1959 HeapFree(GetProcessHeap(), 0, data.info);
1960 HeapFree(GetProcessHeap(), 0, rfc);
1961 return FALSE;
1964 rfc->info = data.info;
1965 rfc->total = data.total;
1967 *ppEnum = (IEnumRfc1766 *)rfc;
1968 return S_OK;
1971 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
1972 IMultiLanguage *iface,
1973 IEnumRfc1766 **ppEnumRfc1766)
1975 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1976 TRACE("%p %p\n", This, ppEnumRfc1766);
1978 return EnumRfc1766_create(0, ppEnumRfc1766);
1981 /******************************************************************************/
1983 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
1984 IMultiLanguage* iface,
1985 LCID Locale,
1986 PRFC1766INFO pRfc1766Info)
1988 FIXME("\n");
1989 return E_NOTIMPL;
1992 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
1993 IMultiLanguage* iface,
1994 UINT uiSrcCodePage,
1995 UINT uiDstCodePage,
1996 DWORD dwProperty,
1997 IMLangConvertCharset** ppMLangConvertCharset)
1999 FIXME("\n");
2000 return E_NOTIMPL;
2003 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2005 fnIMultiLanguage_QueryInterface,
2006 fnIMultiLanguage_AddRef,
2007 fnIMultiLanguage_Release,
2008 fnIMultiLanguage_GetNumberOfCodePageInfo,
2009 fnIMultiLanguage_GetCodePageInfo,
2010 fnIMultiLanguage_GetFamilyCodePage,
2011 fnIMultiLanguage_EnumCodePages,
2012 fnIMultiLanguage_GetCharsetInfo,
2013 fnIMultiLanguage_IsConvertible,
2014 fnIMultiLanguage_ConvertString,
2015 fnIMultiLanguage_ConvertStringToUnicode,
2016 fnIMultiLanguage_ConvertStringFromUnicode,
2017 fnIMultiLanguage_ConvertStringReset,
2018 fnIMultiLanguage_GetRfc1766FromLcid,
2019 fnIMultiLanguage_GetLcidFromRfc1766,
2020 fnIMultiLanguage_EnumRfc1766,
2021 fnIMultiLanguage_GetRfc1766Info,
2022 fnIMultiLanguage_CreateConvertCharset,
2026 /******************************************************************************/
2028 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
2029 IMultiLanguage3* iface,
2030 REFIID riid,
2031 void** ppvObject)
2033 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2034 return MLang_QueryInterface( This, riid, ppvObject );
2037 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2039 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2040 return MLang_AddRef( This );
2043 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2045 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2046 return MLang_Release( This );
2049 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2050 IMultiLanguage3* iface,
2051 UINT* pcCodePage)
2053 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2054 TRACE("%p, %p\n", This, pcCodePage);
2056 if (!pcCodePage) return S_FALSE;
2058 *pcCodePage = This->total_cp;
2059 return S_OK;
2062 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2064 CHARSETINFO csi;
2066 if (TranslateCharsetInfo((DWORD *)ml_data->family_codepage, &csi, TCI_SRCCODEPAGE))
2067 mime_cp_info->bGDICharset = csi.ciCharset;
2068 else
2069 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2071 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2072 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2073 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2074 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2075 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2076 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2077 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2078 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2079 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2080 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2081 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2083 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2084 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2085 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2086 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2088 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2089 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2090 mime_cp_info->uiFamilyCodePage,
2091 wine_dbgstr_w(mime_cp_info->wszDescription),
2092 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2093 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2094 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2095 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2096 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2097 mime_cp_info->bGDICharset);
2100 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2101 IMultiLanguage3* iface,
2102 UINT uiCodePage,
2103 LANGID LangId,
2104 PMIMECPINFO pCodePageInfo)
2106 UINT i, n;
2108 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2109 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2111 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2113 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2115 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2117 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2118 return S_OK;
2123 return S_FALSE;
2126 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2127 IMultiLanguage3* iface,
2128 UINT uiCodePage,
2129 UINT* puiFamilyCodePage)
2131 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2134 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2135 IMultiLanguage3* iface,
2136 DWORD grfFlags,
2137 LANGID LangId,
2138 IEnumCodePage** ppEnumCodePage)
2140 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2141 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2143 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2146 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2147 IMultiLanguage3* iface,
2148 BSTR Charset,
2149 PMIMECSETINFO pCharsetInfo)
2151 UINT i, n;
2153 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2154 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2156 if (!pCharsetInfo) return E_FAIL;
2158 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2160 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2162 WCHAR csetW[MAX_MIMECSET_NAME];
2164 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2165 if (!lstrcmpiW(Charset, csetW))
2167 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2168 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2169 strcpyW(pCharsetInfo->wszCharset, csetW);
2170 return S_OK;
2175 /* FIXME:
2176 * Since we do not support charsets like iso-2022-jp and do not have
2177 * them in our database as a primary (web_charset) encoding this loop
2178 * does an attempt to 'approximate' charset name by header_charset.
2180 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2182 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2184 WCHAR csetW[MAX_MIMECSET_NAME];
2186 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2187 if (!lstrcmpiW(Charset, csetW))
2189 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2190 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2191 strcpyW(pCharsetInfo->wszCharset, csetW);
2192 return S_OK;
2197 return E_FAIL;
2200 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2201 IMultiLanguage3* iface,
2202 DWORD dwSrcEncoding,
2203 DWORD dwDstEncoding)
2205 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2208 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2209 IMultiLanguage3* iface,
2210 DWORD* pdwMode,
2211 DWORD dwSrcEncoding,
2212 DWORD dwDstEncoding,
2213 BYTE* pSrcStr,
2214 UINT* pcSrcSize,
2215 BYTE* pDstStr,
2216 UINT* pcDstSize)
2218 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2219 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2222 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2223 IMultiLanguage3* iface,
2224 DWORD* pdwMode,
2225 DWORD dwEncoding,
2226 CHAR* pSrcStr,
2227 UINT* pcSrcSize,
2228 WCHAR* pDstStr,
2229 UINT* pcDstSize)
2231 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2232 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2235 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2236 IMultiLanguage3* iface,
2237 DWORD* pdwMode,
2238 DWORD dwEncoding,
2239 WCHAR* pSrcStr,
2240 UINT* pcSrcSize,
2241 CHAR* pDstStr,
2242 UINT* pcDstSize)
2244 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2245 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2248 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2249 IMultiLanguage3* iface)
2251 FIXME("\n");
2252 return E_NOTIMPL;
2255 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2256 IMultiLanguage3* iface,
2257 LCID lcid,
2258 BSTR* pbstrRfc1766)
2260 WCHAR buf[MAX_RFC1766_NAME];
2262 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2264 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2266 *pbstrRfc1766 = SysAllocString( buf );
2267 return S_OK;
2269 return E_FAIL;
2272 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2273 IMultiLanguage3* iface,
2274 LCID* pLocale,
2275 BSTR bstrRfc1766)
2277 HRESULT hr;
2278 IEnumRfc1766 *rfc1766;
2280 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2282 if (!pLocale || !bstrRfc1766)
2283 return E_INVALIDARG;
2285 hr = IMultiLanguage2_EnumRfc1766(iface, 0, &rfc1766);
2286 if (FAILED(hr))
2287 return hr;
2289 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2291 IEnumRfc1766_Release(rfc1766);
2292 return hr;
2295 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2296 IMultiLanguage3* iface,
2297 LANGID LangId,
2298 IEnumRfc1766** ppEnumRfc1766)
2300 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
2301 TRACE("%p %p\n", This, ppEnumRfc1766);
2303 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2306 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2307 IMultiLanguage3* iface,
2308 LCID Locale,
2309 LANGID LangId,
2310 PRFC1766INFO pRfc1766Info)
2312 FIXME("\n");
2313 return E_NOTIMPL;
2316 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2317 IMultiLanguage3* iface,
2318 UINT uiSrcCodePage,
2319 UINT uiDstCodePage,
2320 DWORD dwProperty,
2321 IMLangConvertCharset** ppMLangConvertCharset)
2323 FIXME("\n");
2324 return E_NOTIMPL;
2327 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2328 IMultiLanguage3* iface,
2329 DWORD* pdwMode,
2330 DWORD dwFlag,
2331 WCHAR* lpFallBack,
2332 DWORD dwSrcEncoding,
2333 DWORD dwDstEncoding,
2334 IStream* pstmIn,
2335 IStream* pstmOut)
2337 FIXME("\n");
2338 return E_NOTIMPL;
2342 * TODO: handle dwFlag and lpFallBack
2344 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
2345 IMultiLanguage3* iface,
2346 DWORD* pdwMode,
2347 DWORD dwEncoding,
2348 CHAR* pSrcStr,
2349 UINT* pcSrcSize,
2350 WCHAR* pDstStr,
2351 UINT* pcDstSize,
2352 DWORD dwFlag,
2353 WCHAR* lpFallBack)
2355 FIXME("\n");
2356 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2357 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2360 /*****************************************************************************
2361 * MultiLanguage2::ConvertStringToUnicodeEx
2363 * Translates the multibyte string from the specified code page to Unicode.
2365 * PARAMS
2366 * see ConvertStringToUnicode
2367 * dwFlag
2368 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2369 * instead unconvertible characters.
2371 * RETURNS
2372 * S_OK Success.
2373 * S_FALSE The conversion is not supported.
2374 * E_FAIL Some error has occurred.
2376 * TODO: handle dwFlag and lpFallBack
2378 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
2379 IMultiLanguage3* This,
2380 DWORD* pdwMode,
2381 DWORD dwEncoding,
2382 WCHAR* pSrcStr,
2383 UINT* pcSrcSize,
2384 CHAR* pDstStr,
2385 UINT* pcDstSize,
2386 DWORD dwFlag,
2387 WCHAR* lpFallBack)
2389 FIXME("\n");
2390 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2391 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2394 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
2395 IMultiLanguage3* iface,
2396 DWORD dwFlag,
2397 DWORD dwPrefWinCodePage,
2398 IStream* pstmIn,
2399 DetectEncodingInfo* lpEncoding,
2400 INT* pnScores)
2402 FIXME("\n");
2403 return E_NOTIMPL;
2406 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
2407 IMultiLanguage3* iface,
2408 DWORD dwFlag,
2409 DWORD dwPrefWinCodePage,
2410 CHAR* pSrcStr,
2411 INT* pcSrcSize,
2412 DetectEncodingInfo* lpEncoding,
2413 INT* pnScores)
2415 FIXME("\n");
2416 return E_NOTIMPL;
2419 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
2420 IMultiLanguage3* iface,
2421 UINT uiCodePage,
2422 HWND hwnd)
2424 FIXME("%u, %p\n", uiCodePage, hwnd);
2425 return E_NOTIMPL;
2428 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
2429 IMultiLanguage3* iface,
2430 UINT uiCodePage,
2431 LCID lcid,
2432 LPWSTR lpWideCharStr,
2433 int cchWideChar)
2435 /* Find first instance */
2436 unsigned int i,n;
2438 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
2439 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2441 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2443 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2445 MultiByteToWideChar(CP_ACP, 0,
2446 mlang_data[i].mime_cp_info[n].description,
2447 -1, lpWideCharStr, cchWideChar);
2448 return S_OK;
2453 return S_FALSE;
2456 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
2457 IMultiLanguage3* iface,
2458 UINT uiCodePage)
2460 FIXME("%u\n", uiCodePage);
2461 return E_NOTIMPL;
2464 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
2465 IMultiLanguage3* iface,
2466 MIMECONTF dwSource)
2468 FIXME("0x%08x\n", dwSource);
2469 return S_OK;
2472 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
2473 IMultiLanguage3* iface,
2474 UINT* pnScripts)
2476 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2477 TRACE("%p %p\n", This, pnScripts);
2479 if (!pnScripts) return S_FALSE;
2481 *pnScripts = This->total_scripts;
2482 return S_OK;
2485 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
2486 IMultiLanguage3* iface,
2487 DWORD dwFlags,
2488 LANGID LangId,
2489 IEnumScript** ppEnumScript)
2491 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2492 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
2494 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
2497 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
2498 IMultiLanguage3* iface,
2499 UINT uiCodePage,
2500 HWND hwnd,
2501 DWORD dwfIODControl)
2503 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2504 FIXME("%p %u %p %08x: stub!\n", This, uiCodePage, hwnd, dwfIODControl);
2506 return S_FALSE;
2509 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
2510 IMultiLanguage3 *iface,
2511 DWORD dwFlags,
2512 LPCWSTR lpWideCharStr,
2513 UINT cchWideChar,
2514 UINT *puiPreferredCodePages,
2515 UINT nPreferredCodePages,
2516 UINT *puiDetectedCodePages,
2517 UINT *pnDetectedCodePages,
2518 WCHAR *lpSpecialChar)
2520 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2521 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
2522 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
2523 pnDetectedCodePages, lpSpecialChar);
2524 return E_NOTIMPL;
2527 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
2528 IMultiLanguage3 *iface,
2529 DWORD dwFlags,
2530 IStream *pStrIn,
2531 UINT *puiPreferredCodePages,
2532 UINT nPreferredCodePages,
2533 UINT *puiDetectedCodePages,
2534 UINT *pnDetectedCodePages,
2535 WCHAR *lpSpecialChar)
2537 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2538 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
2539 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
2540 pnDetectedCodePages, lpSpecialChar);
2541 return E_NOTIMPL;
2544 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
2546 fnIMultiLanguage2_QueryInterface,
2547 fnIMultiLanguage2_AddRef,
2548 fnIMultiLanguage2_Release,
2549 fnIMultiLanguage2_GetNumberOfCodePageInfo,
2550 fnIMultiLanguage2_GetCodePageInfo,
2551 fnIMultiLanguage2_GetFamilyCodePage,
2552 fnIMultiLanguage2_EnumCodePages,
2553 fnIMultiLanguage2_GetCharsetInfo,
2554 fnIMultiLanguage2_IsConvertible,
2555 fnIMultiLanguage2_ConvertString,
2556 fnIMultiLanguage2_ConvertStringToUnicode,
2557 fnIMultiLanguage2_ConvertStringFromUnicode,
2558 fnIMultiLanguage2_ConvertStringReset,
2559 fnIMultiLanguage2_GetRfc1766FromLcid,
2560 fnIMultiLanguage2_GetLcidFromRfc1766,
2561 fnIMultiLanguage2_EnumRfc1766,
2562 fnIMultiLanguage2_GetRfc1766Info,
2563 fnIMultiLanguage2_CreateConvertCharset,
2564 fnIMultiLanguage2_ConvertStringInIStream,
2565 fnIMultiLanguage2_ConvertStringToUnicodeEx,
2566 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
2567 fnIMultiLanguage2_DetectCodepageInIStream,
2568 fnIMultiLanguage2_DetectInputCodepage,
2569 fnIMultiLanguage2_ValidateCodePage,
2570 fnIMultiLanguage2_GetCodePageDescription,
2571 fnIMultiLanguage2_IsCodePageInstallable,
2572 fnIMultiLanguage2_SetMimeDBSource,
2573 fnIMultiLanguage2_GetNumberOfScripts,
2574 fnIMultiLanguage2_EnumScripts,
2575 fnIMultiLanguage2_ValidateCodePageEx,
2576 fnIMultiLanguage3_DetectOutboundCodePage,
2577 fnIMultiLanguage3_DetectOutboundCodePageInIStream
2580 /******************************************************************************/
2581 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
2582 IMLangFontLink2 * iface,
2583 REFIID riid,
2584 void** ppvObject)
2586 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink2, iface);
2587 return MLang_QueryInterface( This, riid, ppvObject );
2590 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
2592 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink2, iface);
2593 return MLang_AddRef( This );
2596 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
2598 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink2, iface);
2599 return MLang_Release( This );
2602 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
2603 WCHAR chSrc, DWORD *pdwCodePages)
2605 FIXME("(%p)->%s %p\n",This, debugstr_wn(&chSrc,1),pdwCodePages);
2606 return E_NOTIMPL;
2609 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
2610 const WCHAR *pszSrc, long cchSrc, DWORD dwPriorityCodePages,
2611 DWORD *pdwCodePages, long *pcchCodePages)
2613 FIXME("(%p)->%s %li %x %p %p\n",This, debugstr_wn(pszSrc,cchSrc),cchSrc,dwPriorityCodePages,pdwCodePages,pcchCodePages);
2614 return E_NOTIMPL;
2617 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
2618 UINT uCodePage,
2619 DWORD *pdwCodePages)
2621 FIXME("(%p)->%i %p\n",This, uCodePage, pdwCodePages);
2622 return E_NOTIMPL;
2625 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* This,
2626 DWORD dwCodePages, UINT uDefaultCodePage, UINT *puCodePage)
2628 FIXME("(%p)->%i %i %p\n",This, dwCodePages, uDefaultCodePage, puCodePage);
2629 return E_NOTIMPL;
2632 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2* This,
2633 HDC hDC, HFONT hFont, DWORD *pdwCodePages)
2635 FIXME("(%p)->%p %p %p\n",This, hDC, hFont, pdwCodePages);
2636 return E_NOTIMPL;
2639 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
2640 HFONT hFont)
2642 FIXME("(%p)->%p\n",This, hFont);
2643 return E_NOTIMPL;
2646 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
2648 FIXME("(%p)->\n",This);
2649 return E_NOTIMPL;
2652 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
2653 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
2655 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
2656 return E_NOTIMPL;
2659 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
2660 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
2662 FIXME("(%p)->%p %p %p\n",This, hDC, puiRanges, pUranges);
2663 return E_NOTIMPL;
2666 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
2667 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
2668 SCRIPTFONTINFO *pScriptFont)
2670 FIXME("(%p)->%i %i %p %p\n",This, sid, dwFlags, puiFonts, pScriptFont);
2671 return E_NOTIMPL;
2674 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
2675 UINT uiCodePage, SCRIPT_ID *pSid)
2677 FIXME("(%p)->%i %p\n",This, uiCodePage, pSid);
2678 return E_NOTIMPL;
2681 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
2683 fnIMLangFontLink2_QueryInterface,
2684 fnIMLangFontLink2_AddRef,
2685 fnIMLangFontLink2_Release,
2686 fnIMLangFontLink2_GetCharCodePages,
2687 fnIMLangFontLink2_GetStrCodePages,
2688 fnIMLangFontLink2_CodePageToCodePages,
2689 fnIMLangFontLink2_CodePagesToCodePage,
2690 fnIMLangFontLink2_GetFontCodePages,
2691 fnIMLangFontLink2_ReleaseFont,
2692 fnIMLangFontLink2_ResetFontMapping,
2693 fnIMLangFontLink2_MapFont,
2694 fnIMLangFontLink2_GetFontUnicodeRanges,
2695 fnIMLangFontLink2_GetScriptFontInfo,
2696 fnIMLangFontLink2_CodePageToScriptID
2700 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2702 MLang_impl *mlang;
2703 UINT i;
2705 TRACE("Creating MultiLanguage object\n");
2707 if( pUnkOuter )
2708 return CLASS_E_NOAGGREGATION;
2710 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
2711 mlang->vtbl_IMLangFontLink = &IMLangFontLink_vtbl;
2712 mlang->vtbl_IMultiLanguage = &IMultiLanguage_vtbl;
2713 mlang->vtbl_IMultiLanguage3 = &IMultiLanguage3_vtbl;
2714 mlang->vtbl_IMLangFontLink2 = &IMLangFontLink2_vtbl;
2716 mlang->total_cp = 0;
2717 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2718 mlang->total_cp += mlang_data[i].number_of_cp;
2720 /* do not enumerate unicode flavours */
2721 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
2723 mlang->ref = 1;
2724 *ppObj = (LPVOID) mlang;
2725 TRACE("returning %p\n", mlang);
2727 LockModule();
2729 return S_OK;
2732 /******************************************************************************/
2734 HRESULT WINAPI DllCanUnloadNow(void)
2736 return dll_count == 0 ? S_OK : S_FALSE;
2739 HRESULT WINAPI GetGlobalFontLinkObject(void)
2741 FIXME("\n");
2742 return S_FALSE;