4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003,2004 Mike McCormack
6 * Copyright 2004,2005 Dmitry Timoshkov
7 * Copyright 2009 Detlef Riekenberg
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
45 #define CP_UNICODE 1200
47 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
48 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
50 static DWORD MLANG_tls_index; /* to store various per thead data */
53 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
54 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
59 const char *description;
62 const char *web_charset;
63 const char *header_charset;
64 const char *body_charset;
67 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
68 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
70 static const MIME_CP_INFO arabic_cp[] =
73 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
74 MIMECONTF_MIME_LATEST,
75 "ibm864", "ibm864", "ibm864" },
77 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
78 MIMECONTF_MIME_LATEST,
79 "ibm1006", "ibm1006", "ibm1006" },
81 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
82 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
83 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
84 "windows-1256", "windows-1256", "windows-1256" },
86 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
87 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
88 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
89 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
90 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
92 static const MIME_CP_INFO baltic_cp[] =
95 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
96 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
97 "ibm775", "ibm775", "ibm775" },
99 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
100 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
101 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
102 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
103 "windows-1257", "windows-1257", "windows-1257" },
105 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
106 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
107 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
108 MIMECONTF_MIME_LATEST,
109 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
111 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
112 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
113 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
115 static const MIME_CP_INFO chinese_simplified_cp[] =
117 { "Chinese Simplified (GB2312)",
118 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
119 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
120 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
121 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
122 "gb2312", "gb2312", "gb2312" }
124 static const MIME_CP_INFO chinese_traditional_cp[] =
126 { "Chinese Traditional (Big5)",
127 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
128 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
129 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
130 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
131 "big5", "big5", "big5" }
133 static const MIME_CP_INFO central_european_cp[] =
135 { "Central European (DOS)",
136 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
137 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
138 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
139 "ibm852", "ibm852", "ibm852" },
140 { "Central European (Windows)",
141 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
142 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
143 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
144 MIMECONTF_MIME_LATEST,
145 "windows-1250", "windows-1250", "windows-1250" },
146 { "Central European (Mac)",
147 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
148 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
149 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
150 { "Central European (ISO)",
151 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
152 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
153 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
154 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
155 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
157 static const MIME_CP_INFO cyrillic_cp[] =
160 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
161 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
162 "ibm855", "ibm855", "ibm855" },
164 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
165 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
166 MIMECONTF_MIME_LATEST,
167 "cp866", "cp866", "cp866" },
168 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
169 { "Cyrillic (KOI8-R)",
170 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
171 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
172 "koi8-r", "koi8-r", "koi8-r" },
174 { "Cyrillic (Windows)",
175 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
176 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
177 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
178 "windows-1251", "windows-1251", "windows-1251" },
180 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
181 MIMECONTF_MIME_LATEST,
182 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
183 { "Cyrillic (KOI8-R)",
184 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
185 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
186 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
187 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
188 "koi8-r", "koi8-r", "koi8-r" },
189 { "Cyrillic (KOI8-U)",
190 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
191 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
192 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
193 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
194 "koi8-u", "koi8-u", "koi8-u" },
196 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
197 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
198 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
199 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
200 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
202 static const MIME_CP_INFO greek_cp[] =
205 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
206 MIMECONTF_MIME_LATEST,
207 "ibm737", "ibm737", "ibm737" },
208 { "Greek, Modern (DOS)",
209 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
210 MIMECONTF_MIME_LATEST,
211 "ibm869", "ibm869", "ibm869" },
212 { "IBM EBCDIC (Greek Modern)",
213 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
214 MIMECONTF_MIME_LATEST,
215 "cp875", "cp875", "cp875" },
217 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
218 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
219 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
220 "windows-1253", "windows-1253", "windows-1253" },
222 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
223 MIMECONTF_MIME_LATEST,
224 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
226 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
227 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
228 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
229 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
230 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
232 static const MIME_CP_INFO hebrew_cp[] =
235 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
236 MIMECONTF_MIME_LATEST,
237 "ibm424", "ibm424", "ibm424" },
239 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
240 MIMECONTF_MIME_LATEST,
241 "cp856", "cp856", "cp856" },
243 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
244 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
245 MIMECONTF_MIME_LATEST,
246 "dos-862", "dos-862", "dos-862" },
247 { "Hebrew (Windows)",
248 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
249 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
250 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
251 "windows-1255", "windows-1255", "windows-1255" },
252 { "Hebrew (ISO-Visual)",
253 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
254 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
255 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
256 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
258 static const MIME_CP_INFO japanese_cp[] =
260 { "Japanese (Auto-Select)",
261 50932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
262 MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
263 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
264 "_autodetect", "_autodetect", "_autodetect" },
266 51932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
267 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
268 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
269 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
270 "euc-jp", "euc-jp", "euc-jp" },
272 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
273 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
274 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
276 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
277 { "Japanese (JIS 0208-1990 and 0212-1990)",
278 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
279 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
280 "EUC-JP","EUC-JP","EUC-JP"},
281 { "Japanese (JIS-Allow 1 byte Kana)",
282 50221, MIMECONTF_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_SAVABLE_BROWSER |
283 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
284 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
285 "csISO2022JP","iso-2022-jp","iso-2022-jp"},
286 { "Japanese (JIS-Allow 1 byte Kana - SO/SI)",
287 50222, MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_VALID |
288 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
289 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
291 10001, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
292 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
293 "x-mac-japanese","x-mac-japanese","x-mac-japanese"},
294 { "Japanese (Shift-JIS)",
295 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
296 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
297 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
298 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
299 "shift_jis", "iso-2022-jp", "iso-2022-jp" }
301 static const MIME_CP_INFO korean_cp[] =
304 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
305 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
306 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
307 MIMECONTF_MIME_LATEST,
308 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
310 static const MIME_CP_INFO thai_cp[] =
313 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
314 "ibm-thai", "ibm-thai", "ibm-thai" }
316 static const MIME_CP_INFO turkish_cp[] =
319 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
320 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
321 "ibm857", "ibm857", "ibm857" },
322 { "IBM EBCDIC (Turkish Latin-5)",
323 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
324 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
325 "ibm1026", "ibm1026", "ibm1026" },
326 { "Turkish (Windows)",
327 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
328 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
329 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
330 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
331 "windows-1254", "windows-1254", "windows-1254" },
333 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
334 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
335 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
337 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
338 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
339 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
340 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
342 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
343 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
344 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
345 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
346 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
348 static const MIME_CP_INFO vietnamese_cp[] =
350 { "Vietnamese (Windows)",
351 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
352 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
353 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
354 MIMECONTF_MIME_LATEST,
355 "windows-1258", "windows-1258", "windows-1258" }
357 static const MIME_CP_INFO western_cp[] =
359 { "IBM EBCDIC (US-Canada)",
360 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
361 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
362 "ibm037", "ibm037", "ibm037" },
363 { "OEM United States",
364 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
365 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
366 "ibm437", "ibm437", "ibm437" },
367 { "IBM EBCDIC (International)",
368 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
369 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
370 "ibm500", "ibm500", "ibm500" },
371 { "Western European (DOS)",
372 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
373 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
374 "ibm850", "ibm850", "ibm850" },
375 { "Portuguese (DOS)",
376 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
377 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
378 "ibm860", "ibm860", "ibm860" },
380 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
381 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
382 "ibm861", "ibm861", "ibm861" },
383 { "French Canadian (DOS)",
384 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
385 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
386 "ibm863", "ibm863", "ibm863" },
388 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
389 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
390 "ibm865", "ibm865", "ibm865" },
391 { "Western European (Windows)",
392 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
393 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
394 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
395 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
396 "windows-1252", "windows-1252", "iso-8859-1" },
397 { "Western European (Mac)",
398 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
399 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
400 "macintosh", "macintosh", "macintosh" },
402 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
403 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
404 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
406 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
407 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
408 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
409 "us-ascii", "us-ascii", "us-ascii" },
410 { "Western European (ISO)",
411 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
412 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
413 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
414 MIMECONTF_MIME_LATEST,
415 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
417 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
418 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
419 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
420 MIMECONTF_MIME_LATEST,
421 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
423 static const MIME_CP_INFO unicode_cp[] =
426 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
427 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
428 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
429 MIMECONTF_MIME_LATEST,
430 "unicode", "unicode", "unicode" },
432 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
433 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
434 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
435 "utf-7", "utf-7", "utf-7" },
437 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
438 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
439 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
440 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
441 "utf-8", "utf-8", "utf-8" }
444 static const struct mlang_data
446 const char *description;
447 UINT family_codepage;
449 const MIME_CP_INFO *mime_cp_info;
450 const char *fixed_font;
451 const char *proportional_font;
455 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
456 "Courier","Arial", sidArabic }, /* FIXME */
457 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
458 "Courier","Arial" }, /* FIXME */
459 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
460 "Courier","Arial" }, /* FIXME */
461 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
462 "Courier","Arial" }, /* FIXME */
463 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
464 "Courier","Arial" }, /* FIXME */
465 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
466 "Courier","Arial", sidCyrillic }, /* FIXME */
467 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
468 "Courier","Arial", sidGreek }, /* FIXME */
469 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
470 "Courier","Arial", sidHebrew }, /* FIXME */
471 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
472 "MS Gothic","MS PGothic" },
473 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
474 "Courier","Arial" }, /* FIXME */
475 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
476 "Courier","Arial", sidThai }, /* FIXME */
477 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
478 "Courier","Arial" }, /* FIXME */
479 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
480 "Courier","Arial" }, /* FIXME */
481 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
482 "Courier","Arial", sidLatin }, /* FIXME */
483 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
484 "Courier","Arial" } /* FIXME */
487 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
489 static LONG dll_count;
492 * Japanese Detection and Converstion Functions
495 #define HANKATA(A) ((A >= 161) && (A <= 223))
496 #define ISEUC(A) ((A >= 161) && (A <= 254))
497 #define NOTEUC(A,B) (((A >= 129) && (A <= 159)) && ((B >= 64) && (B <= 160)))
498 #define SJIS1(A) (((A >= 129) && (A <= 159)) || ((A >= 224) && (A <= 239)))
499 #define SJIS2(A) ((A >= 64) && (A <= 252))
500 #define ISMARU(A) ((A >= 202) && (A <= 206))
501 #define ISNIGORI(A) (((A >= 182) && (A <= 196)) || ((A >= 202) && (A <= 206)))
503 static UINT DetectJapaneseCode(LPCSTR input, DWORD count)
509 while ((code == 0 || code == 51932) && i < count)
512 if (c1 == 0x1b /* ESC */)
524 if (c1 =='B' || c1 == '@')
538 else if (ISEUC(c1) && ISEUC(c2))
540 else if (((c1 == 142)) && HANKATA(c2))
548 static inline void jis2sjis(unsigned char *p1, unsigned char *p2)
550 unsigned char c1 = *p1;
551 unsigned char c2 = *p2;
552 int row = c1 < 95 ? 112 : 176;
553 int cell = c1 % 2 ? 31 + (c2 > 95) : 126;
555 *p1 = ((c1 + 1) >> 1) + row;
559 static inline void sjis2jis(unsigned char *p1, unsigned char *p2)
561 unsigned char c1 = *p1;
562 unsigned char c2 = *p2;
563 int shift = c2 < 159;
564 int row = c1 < 160 ? 112 : 176;
565 int cell = shift ? (31 + (c2 > 127)): 126;
567 *p1 = ((c1 - row) << 1) - shift;
571 static int han2zen(unsigned char *p1, unsigned char *p2)
575 static const unsigned char char1[] = {129,129,129,129,129,131,131,131,131,
576 131,131,131,131,131,131,129,131,131,131,131,131,131,131,131,131,131,
577 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
578 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
580 static const unsigned char char2[] = {66,117,118,65,69,146,64,66,68,70,
581 72,131,133,135,98,91,65,67,69,71,73,74,76,78,80,82,84,86,88,90,92,94,
582 96,99,101,103,105,106,107,108,109,110,113,116,119,122,125,126,128,
583 129,130,132,134,136,137,138,139,140,141,143,147,74,75};
585 if (( *p2 == 222) && ((ISNIGORI(*p1) || (*p1 == 179))))
587 else if ((*p2 == 223) && (ISMARU(*p1)))
590 if (*p1 >= 161 && *p1 <= 223)
592 unsigned char index = *p1 - 161;
601 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
603 else if ((*p1 == 131) && (*p2 == 69))
606 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
616 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
626 if (p == 0x1b /* ESC */)
632 if (p2 == '$' || p2 =='(')
634 if (p2 == 'K' || p2 =='$')
661 static inline int exit_shift(LPSTR out, int c)
672 static inline int enter_shift(LPSTR out, int c)
684 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
694 if (p == 10 || p == 13) /* NL and CR */
699 j += exit_shift(output,j);
713 p2 = input[i] & 0xff;
720 j+=enter_shift(output,j);
738 p2 = input[i+1] & 0xff;
744 j+=enter_shift(output,j);
759 j += exit_shift(output,j);
771 j += exit_shift(output,j);
775 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
776 LPWSTR output, DWORD out_count)
780 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
781 rc = ConvertJIS2SJIS(input,count,sjis_string);
784 TRACE("%s\n",debugstr_an(sjis_string,rc));
786 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
788 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
790 HeapFree(GetProcessHeap(),0,sjis_string);
795 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
796 LPWSTR output, DWORD out_count)
800 int code = DetectJapaneseCode(input,count);
801 TRACE("Japanese code %i\n",code);
807 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
809 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
814 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
816 rc = MultiByteToWideChar(932,0,input,count,0,0);
821 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
823 rc = MultiByteToWideChar(20932,0,input,count,0,0);
827 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
828 rc = ConvertJIS2SJIS(input,count,sjis_string);
831 TRACE("%s\n",debugstr_an(sjis_string,rc));
833 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
835 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
837 HeapFree(GetProcessHeap(),0,sjis_string);
843 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
844 LPSTR output, DWORD out_count)
850 len = WideCharToMultiByte(932,0,input,count,0,0,NULL,NULL);
851 sjis_string = HeapAlloc(GetProcessHeap(),0,len);
852 WideCharToMultiByte(932,0,input,count,sjis_string,len,NULL,NULL);
853 TRACE("%s\n",debugstr_an(sjis_string,len));
855 rc = ConvertSJIS2JIS(sjis_string, len, NULL);
858 ConvertSJIS2JIS(sjis_string, len, output);
860 HeapFree(GetProcessHeap(),0,sjis_string);
866 * Dll lifetime tracking declaration
868 static void LockModule(void)
870 InterlockedIncrement(&dll_count);
873 static void UnlockModule(void)
875 InterlockedDecrement(&dll_count);
878 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
881 case DLL_PROCESS_ATTACH:
882 MLANG_tls_index = TlsAlloc();
883 DisableThreadLibraryCalls(hInstDLL);
885 case DLL_PROCESS_DETACH:
886 TlsFree(MLANG_tls_index);
892 HRESULT WINAPI ConvertINetMultiByteToUnicode(
902 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
903 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
909 pcSrcSize = &src_len;
917 /* forwarding euc-jp to EUC-JP */
918 if (dwEncoding == 51932)
924 if (*pcSrcSize == -1)
925 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
926 *pcDstSize = min(*pcSrcSize, *pcDstSize);
927 *pcSrcSize *= sizeof(WCHAR);
929 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
935 *pcDstSize = ConvertJISJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
938 *pcDstSize = ConvertUnknownJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
942 if (*pcSrcSize == -1)
943 *pcSrcSize = lstrlenA(pSrcStr);
946 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
948 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
958 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
969 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
970 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
976 pcSrcSize = &src_len;
978 destsz = (pDstStr) ? *pcDstSize : 0;
981 if (!pSrcStr || !*pcSrcSize)
984 if (*pcSrcSize == -1)
985 *pcSrcSize = lstrlenW(pSrcStr);
987 /* forwarding euc-jp to EUC-JP */
988 if (dwEncoding == 51932)
991 if (dwEncoding == CP_UNICODE)
993 if (*pcSrcSize == -1)
994 *pcSrcSize = lstrlenW(pSrcStr);
996 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
998 memmove(pDstStr, pSrcStr, size);
1003 else if (dwEncoding == 50220 || dwEncoding == 50221 || dwEncoding == 50222)
1005 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, NULL, 0);
1011 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, pDstStr,
1020 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1021 NULL, 0, NULL, NULL);
1027 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1028 pDstStr, destsz, NULL, NULL);
1043 HRESULT WINAPI ConvertINetString(
1045 DWORD dwSrcEncoding,
1046 DWORD dwDstEncoding,
1053 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
1054 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1056 if (dwSrcEncoding == CP_UNICODE)
1059 if (pcSrcSize && *pcSrcSize != -1)
1061 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
1062 pcSrcSize = &cSrcSizeW;
1064 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
1066 else if (dwDstEncoding == CP_UNICODE)
1068 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
1069 *pcDstSize *= sizeof(WCHAR);
1078 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
1080 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
1084 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
1085 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
1087 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
1089 HeapFree(GetProcessHeap(), 0, pDstStrW);
1094 static HRESULT GetFamilyCodePage(
1096 UINT* puiFamilyCodePage)
1100 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
1102 if (!puiFamilyCodePage) return S_FALSE;
1104 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1106 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1108 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1110 *puiFamilyCodePage = mlang_data[i].family_codepage;
1119 HRESULT WINAPI IsConvertINetStringAvailable(
1120 DWORD dwSrcEncoding,
1121 DWORD dwDstEncoding)
1123 UINT src_family, dst_family;
1125 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
1127 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
1128 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
1131 if (src_family == dst_family) return S_OK;
1133 /* we can convert any codepage to/from unicode */
1134 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
1139 static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
1141 CHAR buffer[MAX_RFC1766_NAME];
1142 INT n = GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1147 i = PRIMARYLANGID(lcid);
1148 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1149 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1150 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1152 buffer[n - 1] = '-';
1153 i = GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1155 buffer[n - 1] = '\0';
1160 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len );
1161 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1166 static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
1168 WCHAR buffer[MAX_RFC1766_NAME];
1169 INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1174 i = PRIMARYLANGID(lcid);
1175 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1176 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1177 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1179 buffer[n - 1] = '-';
1180 i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1182 buffer[n - 1] = '\0';
1187 LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
1188 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1193 HRESULT WINAPI LcidToRfc1766A(
1198 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1200 return E_INVALIDARG;
1202 return lcid_to_rfc1766A(lcid, pszRfc1766, nChar);
1205 HRESULT WINAPI LcidToRfc1766W(
1210 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1212 return E_INVALIDARG;
1214 return lcid_to_rfc1766W(lcid, pszRfc1766, nChar);
1217 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
1222 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
1224 if (!strcmpiW(info.wszRfc1766, rfc1766))
1229 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
1231 *lcid = PRIMARYLANGID(info.lcid);
1239 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
1241 IEnumRfc1766 *enumrfc1766;
1244 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
1246 if (!pLocale || !pszRfc1766)
1247 return E_INVALIDARG;
1249 hr = EnumRfc1766_create(0, &enumrfc1766);
1253 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
1254 IEnumRfc1766_Release(enumrfc1766);
1259 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
1261 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1264 return E_INVALIDARG;
1266 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
1267 rfc1766W[MAX_RFC1766_NAME] = 0;
1269 return Rfc1766ToLcidW(lcid, rfc1766W);
1272 /******************************************************************************
1273 * MLANG ClassFactory
1276 IClassFactory ITF_IClassFactory;
1279 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1280 } IClassFactoryImpl;
1282 struct object_creation_info
1286 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1289 static const struct object_creation_info object_creation[] =
1291 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
1294 static HRESULT WINAPI
1295 MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1297 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1299 TRACE("%s\n", debugstr_guid(riid) );
1301 if (IsEqualGUID(riid, &IID_IUnknown)
1302 || IsEqualGUID(riid, &IID_IClassFactory))
1304 IClassFactory_AddRef(iface);
1309 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
1310 return E_NOINTERFACE;
1313 static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
1315 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1316 return InterlockedIncrement(&This->ref);
1319 static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
1321 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1323 ULONG ref = InterlockedDecrement(&This->ref);
1327 TRACE("Destroying %p\n", This);
1328 HeapFree(GetProcessHeap(), 0, This);
1334 static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
1335 REFIID riid, LPVOID *ppobj)
1337 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1341 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1344 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
1345 if (SUCCEEDED(hres)) {
1346 hres = IUnknown_QueryInterface(punk, riid, ppobj);
1347 IUnknown_Release(punk);
1349 TRACE("returning (%p) -> %x\n", *ppobj, hres);
1353 static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1363 static const IClassFactoryVtbl MLANGCF_Vtbl =
1365 MLANGCF_QueryInterface,
1368 MLANGCF_CreateInstance,
1372 /******************************************************************
1373 * DllGetClassObject (MLANG.@)
1375 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
1378 IClassFactoryImpl *factory;
1380 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
1382 if ( !IsEqualGUID( &IID_IClassFactory, iid )
1383 && ! IsEqualGUID( &IID_IUnknown, iid) )
1384 return E_NOINTERFACE;
1386 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
1388 if (IsEqualGUID(object_creation[i].clsid, rclsid))
1392 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
1394 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
1395 return CLASS_E_CLASSNOTAVAILABLE;
1398 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
1400 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
1401 if (factory == NULL) return E_OUTOFMEMORY;
1403 factory->ITF_IClassFactory.lpVtbl = &MLANGCF_Vtbl;
1406 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
1408 *ppv = &(factory->ITF_IClassFactory);
1410 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
1416 /******************************************************************************/
1418 typedef struct tagMLang_impl
1420 const IMLangFontLinkVtbl *vtbl_IMLangFontLink;
1421 const IMultiLanguageVtbl *vtbl_IMultiLanguage;
1422 const IMultiLanguage3Vtbl *vtbl_IMultiLanguage3;
1423 const IMLangFontLink2Vtbl *vtbl_IMLangFontLink2;
1424 const IMLangLineBreakConsoleVtbl *vtbl_IMLangLineBreakConsole;
1426 DWORD total_cp, total_scripts;
1429 static ULONG MLang_AddRef( MLang_impl* This)
1431 return InterlockedIncrement(&This->ref);
1434 static ULONG MLang_Release( MLang_impl* This )
1436 ULONG ref = InterlockedDecrement(&This->ref);
1438 TRACE("%p ref = %d\n", This, ref);
1441 TRACE("Destroying %p\n", This);
1442 HeapFree(GetProcessHeap(), 0, This);
1449 static HRESULT MLang_QueryInterface(
1454 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1456 if (IsEqualGUID(riid, &IID_IUnknown)
1457 || IsEqualGUID(riid, &IID_IMLangCodePages)
1458 || IsEqualGUID(riid, &IID_IMLangFontLink))
1461 TRACE("Returning IID_IMLangFontLink %p ref = %d\n", This, This->ref);
1462 *ppvObject = &(This->vtbl_IMLangFontLink);
1466 if (IsEqualGUID(riid, &IID_IMLangFontLink2))
1469 TRACE("Returning IID_IMLangFontLink2 %p ref = %d\n", This, This->ref);
1470 *ppvObject = &(This->vtbl_IMLangFontLink2);
1474 if (IsEqualGUID(riid, &IID_IMultiLanguage) )
1477 TRACE("Returning IID_IMultiLanguage %p ref = %d\n", This, This->ref);
1478 *ppvObject = &(This->vtbl_IMultiLanguage);
1482 if (IsEqualGUID(riid, &IID_IMultiLanguage2) )
1485 *ppvObject = &(This->vtbl_IMultiLanguage3);
1486 TRACE("Returning IID_IMultiLanguage2 %p ref = %d\n", This, This->ref);
1490 if (IsEqualGUID(riid, &IID_IMultiLanguage3) )
1493 *ppvObject = &(This->vtbl_IMultiLanguage3);
1494 TRACE("Returning IID_IMultiLanguage3 %p ref = %d\n", This, This->ref);
1498 if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
1501 TRACE("Returning IID_IMLangLineBreakConsole %p ref = %d\n", This, This->ref);
1502 *ppvObject = &(This->vtbl_IMLangLineBreakConsole);
1507 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1508 return E_NOINTERFACE;
1511 /******************************************************************************/
1513 typedef struct tagEnumCodePage_impl
1515 const IEnumCodePageVtbl *vtbl_IEnumCodePage;
1519 } EnumCodePage_impl;
1521 static inline EnumCodePage_impl *impl_from_IEnumCodePage( IEnumCodePage *iface )
1523 return CONTAINING_RECORD( iface, EnumCodePage_impl, vtbl_IEnumCodePage );
1526 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1527 IEnumCodePage* iface,
1531 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1533 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1535 if (IsEqualGUID(riid, &IID_IUnknown)
1536 || IsEqualGUID(riid, &IID_IEnumCodePage))
1538 IEnumCodePage_AddRef(iface);
1539 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1540 *ppvObject = &(This->vtbl_IEnumCodePage);
1544 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1545 return E_NOINTERFACE;
1548 static ULONG WINAPI fnIEnumCodePage_AddRef(
1549 IEnumCodePage* iface)
1551 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1552 return InterlockedIncrement(&This->ref);
1555 static ULONG WINAPI fnIEnumCodePage_Release(
1556 IEnumCodePage* iface)
1558 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1559 ULONG ref = InterlockedDecrement(&This->ref);
1561 TRACE("%p ref = %d\n", This, ref);
1564 TRACE("Destroying %p\n", This);
1565 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1566 HeapFree(GetProcessHeap(), 0, This);
1572 static HRESULT WINAPI fnIEnumCodePage_Clone(
1573 IEnumCodePage* iface,
1574 IEnumCodePage** ppEnum)
1576 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1577 FIXME("%p %p\n", This, ppEnum);
1581 static HRESULT WINAPI fnIEnumCodePage_Next(
1582 IEnumCodePage* iface,
1585 ULONG* pceltFetched)
1588 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1590 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1592 if (!pceltFetched) return S_FALSE;
1595 if (!rgelt) return S_FALSE;
1597 if (This->pos + celt > This->total)
1598 celt = This->total - This->pos;
1600 if (!celt) return S_FALSE;
1602 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1603 *pceltFetched = celt;
1606 for (i = 0; i < celt; i++)
1608 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1609 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1610 rgelt[i].uiFamilyCodePage,
1611 wine_dbgstr_w(rgelt[i].wszDescription),
1612 wine_dbgstr_w(rgelt[i].wszWebCharset),
1613 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1614 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1615 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1616 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1617 rgelt[i].bGDICharset);
1622 static HRESULT WINAPI fnIEnumCodePage_Reset(
1623 IEnumCodePage* iface)
1625 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1627 TRACE("%p\n", This);
1633 static HRESULT WINAPI fnIEnumCodePage_Skip(
1634 IEnumCodePage* iface,
1637 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1639 TRACE("%p %u\n", This, celt);
1641 if (celt >= This->total) return S_FALSE;
1647 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1649 fnIEnumCodePage_QueryInterface,
1650 fnIEnumCodePage_AddRef,
1651 fnIEnumCodePage_Release,
1652 fnIEnumCodePage_Clone,
1653 fnIEnumCodePage_Next,
1654 fnIEnumCodePage_Reset,
1655 fnIEnumCodePage_Skip
1658 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1659 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1661 EnumCodePage_impl *ecp;
1665 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1667 if (!grfFlags) /* enumerate internal data base of encodings */
1668 grfFlags = MIMECONTF_MIME_LATEST;
1670 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1671 ecp->vtbl_IEnumCodePage = &IEnumCodePage_vtbl;
1675 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1677 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1679 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1684 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1685 sizeof(MIMECPINFO) * ecp->total);
1686 cpinfo = ecp->cpinfo;
1688 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1690 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1692 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1693 fill_cp_info(&mlang_data[i], n, cpinfo++);
1697 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1699 *ppEnumCodePage = (IEnumCodePage*) ecp;
1704 /******************************************************************************/
1706 typedef struct tagEnumScript_impl
1708 const IEnumScriptVtbl *vtbl_IEnumScript;
1710 SCRIPTINFO *script_info;
1714 static inline EnumScript_impl *impl_from_IEnumScript( IEnumScript *iface )
1716 return CONTAINING_RECORD( iface, EnumScript_impl, vtbl_IEnumScript );
1719 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1724 EnumScript_impl *This = impl_from_IEnumScript( iface );
1726 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1728 if (IsEqualGUID(riid, &IID_IUnknown)
1729 || IsEqualGUID(riid, &IID_IEnumScript))
1731 IEnumScript_AddRef(iface);
1732 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1733 *ppvObject = &(This->vtbl_IEnumScript);
1737 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1738 return E_NOINTERFACE;
1741 static ULONG WINAPI fnIEnumScript_AddRef(
1744 EnumScript_impl *This = impl_from_IEnumScript( iface );
1745 return InterlockedIncrement(&This->ref);
1748 static ULONG WINAPI fnIEnumScript_Release(
1751 EnumScript_impl *This = impl_from_IEnumScript( iface );
1752 ULONG ref = InterlockedDecrement(&This->ref);
1754 TRACE("%p ref = %d\n", This, ref);
1757 TRACE("Destroying %p\n", This);
1758 HeapFree(GetProcessHeap(), 0, This->script_info);
1759 HeapFree(GetProcessHeap(), 0, This);
1765 static HRESULT WINAPI fnIEnumScript_Clone(
1767 IEnumScript** ppEnum)
1769 EnumScript_impl *This = impl_from_IEnumScript( iface );
1770 FIXME("%p %p: stub!\n", This, ppEnum);
1774 static HRESULT WINAPI fnIEnumScript_Next(
1778 ULONG* pceltFetched)
1780 EnumScript_impl *This = impl_from_IEnumScript( iface );
1782 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1784 if (!pceltFetched || !rgelt) return E_FAIL;
1788 if (This->pos + celt > This->total)
1789 celt = This->total - This->pos;
1791 if (!celt) return S_FALSE;
1793 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1794 *pceltFetched = celt;
1800 static HRESULT WINAPI fnIEnumScript_Reset(
1803 EnumScript_impl *This = impl_from_IEnumScript( iface );
1805 TRACE("%p\n", This);
1811 static HRESULT WINAPI fnIEnumScript_Skip(
1815 EnumScript_impl *This = impl_from_IEnumScript( iface );
1817 TRACE("%p %u\n", This, celt);
1819 if (celt >= This->total) return S_FALSE;
1825 static const IEnumScriptVtbl IEnumScript_vtbl =
1827 fnIEnumScript_QueryInterface,
1828 fnIEnumScript_AddRef,
1829 fnIEnumScript_Release,
1830 fnIEnumScript_Clone,
1832 fnIEnumScript_Reset,
1836 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1837 LANGID LangId, IEnumScript** ppEnumScript )
1839 EnumScript_impl *es;
1842 TRACE("%p, %08x, %04x, %p: stub!\n", mlang, dwFlags, LangId, ppEnumScript);
1844 if (!dwFlags) /* enumerate all available scripts */
1845 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1847 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1848 es->vtbl_IEnumScript = &IEnumScript_vtbl;
1851 /* do not enumerate unicode flavours */
1852 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1853 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1855 for (i = 0; i < es->total; i++)
1857 es->script_info[i].ScriptId = i;
1858 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1859 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1860 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1861 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1862 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1863 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1864 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1867 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1869 *ppEnumScript = (IEnumScript *)es;
1874 /******************************************************************************/
1876 static inline MLang_impl *impl_from_IMLangFontLink( IMLangFontLink *iface )
1878 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink );
1881 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1882 IMLangFontLink* iface,
1886 MLang_impl *This = impl_from_IMLangFontLink( iface );
1887 return MLang_QueryInterface( This, riid, ppvObject );
1890 static ULONG WINAPI fnIMLangFontLink_AddRef(
1891 IMLangFontLink* iface)
1893 MLang_impl *This = impl_from_IMLangFontLink( iface );
1894 return MLang_AddRef( This );
1897 static ULONG WINAPI fnIMLangFontLink_Release(
1898 IMLangFontLink* iface)
1900 MLang_impl *This = impl_from_IMLangFontLink( iface );
1901 return MLang_Release( This );
1904 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1905 IMLangFontLink* iface,
1907 DWORD* pdwCodePages)
1916 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1918 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
1919 &chSrc, 1, &buf, 1, NULL, &used_dc);
1921 /* If default char is not used, current codepage include the given symbol */
1924 IMLangFontLink_CodePageToCodePages(iface,
1925 mlang_data[i].family_codepage, &codePages);
1926 *pdwCodePages |= codePages;
1932 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1933 IMLangFontLink* iface,
1934 const WCHAR* pszSrc,
1936 DWORD dwPriorityCodePages,
1937 DWORD* pdwCodePages,
1938 LONG* pcchCodePages)
1943 TRACE("(%p)->%s %d %x %p %p\n", iface, debugstr_wn(pszSrc, cchSrc), cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
1945 if (pdwCodePages) *pdwCodePages = 0;
1946 if (pcchCodePages) *pcchCodePages = 0;
1948 if (!pszSrc || !cchSrc || cchSrc < 0)
1949 return E_INVALIDARG;
1951 for (i = 0; i < cchSrc; i++)
1956 ret = fnIMLangFontLink_GetCharCodePages(iface, pszSrc[i], &cp);
1957 if (ret != S_OK) return E_FAIL;
1962 /* FIXME: not tested */
1963 if (dwPriorityCodePages & cps) break;
1966 if (pdwCodePages) *pdwCodePages = cps;
1967 if (pcchCodePages) *pcchCodePages = min( i + 1, cchSrc );
1971 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1972 IMLangFontLink* iface,
1974 DWORD* pdwCodePages)
1976 MLang_impl *This = impl_from_IMLangFontLink( iface );
1980 TRACE("(%p) Seeking %u\n",This, uCodePage);
1982 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uCodePage, &cs, TCI_SRCCODEPAGE);
1986 *pdwCodePages = cs.fs.fsCsb[0];
1987 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1991 TRACE("CodePage Not Found\n");
1996 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1997 IMLangFontLink* iface,
1999 UINT uDefaultCodePage,
2002 MLang_impl *This = impl_from_IMLangFontLink( iface );
2003 DWORD mask = 0x00000000;
2008 TRACE("(%p) scanning 0x%x default page %u\n",This, dwCodePages,
2011 *puCodePage = 0x00000000;
2013 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uDefaultCodePage, &cs,
2016 if (rc && (dwCodePages & cs.fs.fsCsb[0]))
2018 TRACE("Found Default Codepage\n");
2019 *puCodePage = uDefaultCodePage;
2024 for (i = 0; i < 32; i++)
2028 if (dwCodePages & mask)
2033 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
2037 TRACE("Falling back to least significant found CodePage %u\n",
2039 *puCodePage = cs.ciACP;
2044 TRACE("no codepage found\n");
2048 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
2049 IMLangFontLink* iface,
2052 DWORD* pdwCodePages)
2055 FONTSIGNATURE fontsig;
2056 MLang_impl *This = impl_from_IMLangFontLink( iface );
2058 TRACE("(%p)\n",This);
2060 old_font = SelectObject(hDC,hFont);
2061 GetTextCharsetInfo(hDC,&fontsig, 0);
2062 SelectObject(hDC,old_font);
2064 *pdwCodePages = fontsig.fsCsb[0];
2065 TRACE("CodePages is 0x%x\n",fontsig.fsCsb[0]);
2070 static HRESULT WINAPI fnIMLangFontLink_MapFont(
2071 IMLangFontLink* iface,
2081 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
2082 IMLangFontLink* iface,
2089 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
2090 IMLangFontLink* iface)
2097 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
2099 fnIMLangFontLink_QueryInterface,
2100 fnIMLangFontLink_AddRef,
2101 fnIMLangFontLink_Release,
2102 fnIMLangFontLink_GetCharCodePages,
2103 fnIMLangFontLink_GetStrCodePages,
2104 fnIMLangFontLink_CodePageToCodePages,
2105 fnIMLangFontLink_CodePagesToCodePage,
2106 fnIMLangFontLink_GetFontCodePages,
2107 fnIMLangFontLink_MapFont,
2108 fnIMLangFontLink_ReleaseFont,
2109 fnIMLangFontLink_ResetFontMapping,
2112 /******************************************************************************/
2114 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
2116 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage );
2119 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
2120 IMultiLanguage* iface,
2124 MLang_impl *This = impl_from_IMultiLanguage( iface );
2125 return MLang_QueryInterface( This, riid, ppvObject );
2128 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
2130 MLang_impl *This = impl_from_IMultiLanguage( iface );
2131 return IMLangFontLink_AddRef( ((IMLangFontLink*)This) );
2134 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
2136 MLang_impl *This = impl_from_IMultiLanguage( iface );
2137 return IMLangFontLink_Release( ((IMLangFontLink*)This) );
2140 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
2141 IMultiLanguage* iface,
2148 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
2149 IMultiLanguage* iface,
2151 PMIMECPINFO pCodePageInfo)
2154 MLang_impl *This = impl_from_IMultiLanguage( iface );
2156 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
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 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2164 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2173 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
2174 IMultiLanguage* iface,
2176 UINT* puiFamilyCodePage)
2178 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2181 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
2182 IMultiLanguage* iface,
2184 IEnumCodePage** ppEnumCodePage)
2186 MLang_impl *This = impl_from_IMultiLanguage( iface );
2188 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2190 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2193 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2194 IMultiLanguage* iface,
2196 PMIMECSETINFO pCharsetInfo)
2198 MLang_impl *This = impl_from_IMultiLanguage( iface );
2199 return IMultiLanguage3_GetCharsetInfo((IMultiLanguage3*)&This->vtbl_IMultiLanguage3, Charset, pCharsetInfo);
2202 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2203 IMultiLanguage* iface,
2204 DWORD dwSrcEncoding,
2205 DWORD dwDstEncoding)
2207 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2210 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2211 IMultiLanguage* iface,
2213 DWORD dwSrcEncoding,
2214 DWORD dwDstEncoding,
2220 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2221 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2224 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2225 IMultiLanguage* iface,
2233 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2234 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2237 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2238 IMultiLanguage* iface,
2246 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2247 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2250 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2251 IMultiLanguage* iface)
2257 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2258 IMultiLanguage* iface,
2262 WCHAR buf[MAX_RFC1766_NAME];
2264 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2266 return E_INVALIDARG;
2268 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2270 *pbstrRfc1766 = SysAllocString( buf );
2276 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2277 IMultiLanguage* iface,
2282 IEnumRfc1766 *rfc1766;
2284 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2286 if (!pLocale || !bstrRfc1766)
2287 return E_INVALIDARG;
2289 hr = IMultiLanguage_EnumRfc1766(iface, &rfc1766);
2293 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2295 IEnumRfc1766_Release(rfc1766);
2299 /******************************************************************************/
2301 typedef struct tagEnumRfc1766_impl
2303 const IEnumRfc1766Vtbl *vtbl_IEnumRfc1766;
2309 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2311 return CONTAINING_RECORD( iface, EnumRfc1766_impl, vtbl_IEnumRfc1766 );
2314 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2315 IEnumRfc1766 *iface,
2319 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2321 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2323 if (IsEqualGUID(riid, &IID_IUnknown)
2324 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2326 IEnumRfc1766_AddRef(iface);
2327 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2328 *ppvObject = &(This->vtbl_IEnumRfc1766);
2332 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2333 return E_NOINTERFACE;
2336 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2337 IEnumRfc1766 *iface)
2339 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2340 return InterlockedIncrement(&This->ref);
2343 static ULONG WINAPI fnIEnumRfc1766_Release(
2344 IEnumRfc1766 *iface)
2346 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2347 ULONG ref = InterlockedDecrement(&This->ref);
2349 TRACE("%p ref = %d\n", This, ref);
2352 TRACE("Destroying %p\n", This);
2353 HeapFree(GetProcessHeap(), 0, This->info);
2354 HeapFree(GetProcessHeap(), 0, This);
2359 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2360 IEnumRfc1766 *iface,
2361 IEnumRfc1766 **ppEnum)
2363 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2365 FIXME("%p %p\n", This, ppEnum);
2369 static HRESULT WINAPI fnIEnumRfc1766_Next(
2370 IEnumRfc1766 *iface,
2373 ULONG *pceltFetched)
2376 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2378 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2380 if (!pceltFetched) return S_FALSE;
2383 if (!rgelt) return S_FALSE;
2385 if (This->pos + celt > This->total)
2386 celt = This->total - This->pos;
2388 if (!celt) return S_FALSE;
2390 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2391 *pceltFetched = celt;
2394 for (i = 0; i < celt; i++)
2396 TRACE("#%u: %08x %s %s\n",
2398 wine_dbgstr_w(rgelt[i].wszRfc1766),
2399 wine_dbgstr_w(rgelt[i].wszLocaleName));
2404 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2405 IEnumRfc1766 *iface)
2407 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2409 TRACE("%p\n", This);
2415 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2416 IEnumRfc1766 *iface,
2419 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2421 TRACE("%p %u\n", This, celt);
2423 if (celt >= This->total) return S_FALSE;
2429 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2431 fnIEnumRfc1766_QueryInterface,
2432 fnIEnumRfc1766_AddRef,
2433 fnIEnumRfc1766_Release,
2434 fnIEnumRfc1766_Clone,
2435 fnIEnumRfc1766_Next,
2436 fnIEnumRfc1766_Reset,
2440 struct enum_locales_data
2443 DWORD total, allocated;
2446 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2449 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2452 TRACE("%s\n", debugstr_w(locale));
2454 if (data->total >= data->allocated)
2456 data->allocated += 32;
2457 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2458 if (!data->info) return FALSE;
2461 info = &data->info[data->total];
2463 info->lcid = strtolW(locale, &end, 16);
2464 if (*end) /* invalid number */
2467 info->wszRfc1766[0] = 0;
2468 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2470 info->wszLocaleName[0] = 0;
2471 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2472 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2479 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2481 EnumRfc1766_impl *rfc;
2482 struct enum_locales_data data;
2484 TRACE("%04x, %p\n", LangId, ppEnum);
2486 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2487 rfc->vtbl_IEnumRfc1766 = &IEnumRfc1766_vtbl;
2493 data.allocated = 32;
2494 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2497 HeapFree(GetProcessHeap(), 0, rfc);
2501 TlsSetValue(MLANG_tls_index, &data);
2502 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2503 TlsSetValue(MLANG_tls_index, NULL);
2505 TRACE("enumerated %d rfc1766 structures\n", data.total);
2509 HeapFree(GetProcessHeap(), 0, data.info);
2510 HeapFree(GetProcessHeap(), 0, rfc);
2514 rfc->info = data.info;
2515 rfc->total = data.total;
2517 *ppEnum = (IEnumRfc1766 *)rfc;
2521 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2522 IMultiLanguage *iface,
2523 IEnumRfc1766 **ppEnumRfc1766)
2525 MLang_impl *This = impl_from_IMultiLanguage( iface );
2527 TRACE("%p %p\n", This, ppEnumRfc1766);
2529 return EnumRfc1766_create(0, ppEnumRfc1766);
2532 /******************************************************************************/
2534 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2535 IMultiLanguage* iface,
2537 PRFC1766INFO pRfc1766Info)
2543 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2544 IMultiLanguage* iface,
2548 IMLangConvertCharset** ppMLangConvertCharset)
2554 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2556 fnIMultiLanguage_QueryInterface,
2557 fnIMultiLanguage_AddRef,
2558 fnIMultiLanguage_Release,
2559 fnIMultiLanguage_GetNumberOfCodePageInfo,
2560 fnIMultiLanguage_GetCodePageInfo,
2561 fnIMultiLanguage_GetFamilyCodePage,
2562 fnIMultiLanguage_EnumCodePages,
2563 fnIMultiLanguage_GetCharsetInfo,
2564 fnIMultiLanguage_IsConvertible,
2565 fnIMultiLanguage_ConvertString,
2566 fnIMultiLanguage_ConvertStringToUnicode,
2567 fnIMultiLanguage_ConvertStringFromUnicode,
2568 fnIMultiLanguage_ConvertStringReset,
2569 fnIMultiLanguage_GetRfc1766FromLcid,
2570 fnIMultiLanguage_GetLcidFromRfc1766,
2571 fnIMultiLanguage_EnumRfc1766,
2572 fnIMultiLanguage_GetRfc1766Info,
2573 fnIMultiLanguage_CreateConvertCharset,
2577 /******************************************************************************/
2579 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2581 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage3 );
2584 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
2585 IMultiLanguage3* iface,
2589 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2590 return MLang_QueryInterface( This, riid, ppvObject );
2593 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2595 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2596 return MLang_AddRef( This );
2599 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2601 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2602 return MLang_Release( This );
2605 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2606 IMultiLanguage3* iface,
2609 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2611 TRACE("%p, %p\n", This, pcCodePage);
2613 if (!pcCodePage) return S_FALSE;
2615 *pcCodePage = This->total_cp;
2619 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2623 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2625 mime_cp_info->bGDICharset = csi.ciCharset;
2627 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2629 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2630 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2631 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2632 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2633 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2634 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2635 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2636 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2637 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2638 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2639 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2641 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2642 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2643 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2644 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2646 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2647 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2648 mime_cp_info->uiFamilyCodePage,
2649 wine_dbgstr_w(mime_cp_info->wszDescription),
2650 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2651 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2652 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2653 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2654 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2655 mime_cp_info->bGDICharset);
2658 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2659 IMultiLanguage3* iface,
2662 PMIMECPINFO pCodePageInfo)
2665 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2667 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2669 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2671 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2673 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2675 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2684 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2685 IMultiLanguage3* iface,
2687 UINT* puiFamilyCodePage)
2689 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2692 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2693 IMultiLanguage3* iface,
2696 IEnumCodePage** ppEnumCodePage)
2698 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2700 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2702 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2705 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2706 IMultiLanguage3* iface,
2708 PMIMECSETINFO pCharsetInfo)
2711 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2713 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2715 if (!pCharsetInfo) return E_FAIL;
2717 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2719 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2721 WCHAR csetW[MAX_MIMECSET_NAME];
2723 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2724 if (!lstrcmpiW(Charset, csetW))
2726 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2727 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2728 strcpyW(pCharsetInfo->wszCharset, csetW);
2735 * Since we do not support charsets like iso-2022-jp and do not have
2736 * them in our database as a primary (web_charset) encoding this loop
2737 * does an attempt to 'approximate' charset name by header_charset.
2739 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2741 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2743 WCHAR csetW[MAX_MIMECSET_NAME];
2745 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2746 if (!lstrcmpiW(Charset, csetW))
2748 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2749 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2750 strcpyW(pCharsetInfo->wszCharset, csetW);
2759 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2760 IMultiLanguage3* iface,
2761 DWORD dwSrcEncoding,
2762 DWORD dwDstEncoding)
2764 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2767 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2768 IMultiLanguage3* iface,
2770 DWORD dwSrcEncoding,
2771 DWORD dwDstEncoding,
2777 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2778 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2781 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2782 IMultiLanguage3* iface,
2790 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2791 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2794 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2795 IMultiLanguage3* iface,
2803 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2804 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2807 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2808 IMultiLanguage3* iface)
2814 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2815 IMultiLanguage3* iface,
2819 WCHAR buf[MAX_RFC1766_NAME];
2821 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2823 return E_INVALIDARG;
2825 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2827 *pbstrRfc1766 = SysAllocString( buf );
2833 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2834 IMultiLanguage3* iface,
2839 IEnumRfc1766 *rfc1766;
2841 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2843 if (!pLocale || !bstrRfc1766)
2844 return E_INVALIDARG;
2846 hr = IMultiLanguage2_EnumRfc1766(iface, 0, &rfc1766);
2850 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2852 IEnumRfc1766_Release(rfc1766);
2856 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2857 IMultiLanguage3* iface,
2859 IEnumRfc1766** ppEnumRfc1766)
2861 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2863 TRACE("%p %p\n", This, ppEnumRfc1766);
2865 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2868 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2869 IMultiLanguage3* iface,
2872 PRFC1766INFO pRfc1766Info)
2878 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2879 IMultiLanguage3* iface,
2883 IMLangConvertCharset** ppMLangConvertCharset)
2889 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2890 IMultiLanguage3* iface,
2894 DWORD dwSrcEncoding,
2895 DWORD dwDstEncoding,
2899 char *src, *dst = NULL;
2904 TRACE("%p %0x8 %s %u %u %p %p\n",
2905 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2907 FIXME("dwFlag and lpFallBack not handled\n");
2909 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2910 if (FAILED(hr)) return hr;
2912 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
2913 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
2915 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
2916 if (FAILED(hr)) goto exit;
2918 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
2919 if (FAILED(hr)) goto exit;
2921 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
2926 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
2927 if (FAILED(hr)) goto exit;
2929 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
2932 HeapFree(GetProcessHeap(), 0, src);
2933 HeapFree(GetProcessHeap(), 0, dst);
2938 * TODO: handle dwFlag and lpFallBack
2940 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
2941 IMultiLanguage3* iface,
2952 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2953 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2956 /*****************************************************************************
2957 * MultiLanguage2::ConvertStringToUnicodeEx
2959 * Translates the multibyte string from the specified code page to Unicode.
2962 * see ConvertStringToUnicode
2964 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2965 * instead unconvertible characters.
2969 * S_FALSE The conversion is not supported.
2970 * E_FAIL Some error has occurred.
2972 * TODO: handle dwFlag and lpFallBack
2974 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
2975 IMultiLanguage3* This,
2986 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2987 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2990 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
2991 IMultiLanguage3* iface,
2993 DWORD dwPrefWinCodePage,
2995 DetectEncodingInfo* lpEncoding,
3002 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
3003 IMultiLanguage3* iface,
3005 DWORD dwPrefWinCodePage,
3008 DetectEncodingInfo* lpEncoding,
3015 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
3016 IMultiLanguage3* iface,
3020 return IMultiLanguage2_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
3023 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
3024 IMultiLanguage3* iface,
3027 LPWSTR lpWideCharStr,
3030 /* Find first instance */
3033 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
3034 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3036 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3038 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3040 MultiByteToWideChar(CP_ACP, 0,
3041 mlang_data[i].mime_cp_info[n].description,
3042 -1, lpWideCharStr, cchWideChar);
3051 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
3052 IMultiLanguage3* iface,
3055 FIXME("%u\n", uiCodePage);
3059 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
3060 IMultiLanguage3* iface,
3063 FIXME("0x%08x\n", dwSource);
3067 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
3068 IMultiLanguage3* iface,
3071 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3073 TRACE("%p %p\n", This, pnScripts);
3075 if (!pnScripts) return S_FALSE;
3077 *pnScripts = This->total_scripts;
3081 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
3082 IMultiLanguage3* iface,
3085 IEnumScript** ppEnumScript)
3087 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3089 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3091 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3094 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
3095 IMultiLanguage3* iface,
3098 DWORD dwfIODControl)
3101 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3103 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3105 /* quick check for kernel32 supported code pages */
3106 if (IsValidCodePage(uiCodePage))
3109 /* check for mlang supported code pages */
3110 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3113 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3115 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3120 if (dwfIODControl != CPIOD_PEEK)
3121 FIXME("Request to install codepage language pack not handled\n");
3126 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3127 IMultiLanguage3 *iface,
3129 LPCWSTR lpWideCharStr,
3131 UINT *puiPreferredCodePages,
3132 UINT nPreferredCodePages,
3133 UINT *puiDetectedCodePages,
3134 UINT *pnDetectedCodePages,
3135 WCHAR *lpSpecialChar)
3137 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3139 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3140 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3141 pnDetectedCodePages, lpSpecialChar);
3145 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3146 IMultiLanguage3 *iface,
3149 UINT *puiPreferredCodePages,
3150 UINT nPreferredCodePages,
3151 UINT *puiDetectedCodePages,
3152 UINT *pnDetectedCodePages,
3153 WCHAR *lpSpecialChar)
3155 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3157 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
3158 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3159 pnDetectedCodePages, lpSpecialChar);
3163 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3165 fnIMultiLanguage2_QueryInterface,
3166 fnIMultiLanguage2_AddRef,
3167 fnIMultiLanguage2_Release,
3168 fnIMultiLanguage2_GetNumberOfCodePageInfo,
3169 fnIMultiLanguage2_GetCodePageInfo,
3170 fnIMultiLanguage2_GetFamilyCodePage,
3171 fnIMultiLanguage2_EnumCodePages,
3172 fnIMultiLanguage2_GetCharsetInfo,
3173 fnIMultiLanguage2_IsConvertible,
3174 fnIMultiLanguage2_ConvertString,
3175 fnIMultiLanguage2_ConvertStringToUnicode,
3176 fnIMultiLanguage2_ConvertStringFromUnicode,
3177 fnIMultiLanguage2_ConvertStringReset,
3178 fnIMultiLanguage2_GetRfc1766FromLcid,
3179 fnIMultiLanguage2_GetLcidFromRfc1766,
3180 fnIMultiLanguage2_EnumRfc1766,
3181 fnIMultiLanguage2_GetRfc1766Info,
3182 fnIMultiLanguage2_CreateConvertCharset,
3183 fnIMultiLanguage2_ConvertStringInIStream,
3184 fnIMultiLanguage2_ConvertStringToUnicodeEx,
3185 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
3186 fnIMultiLanguage2_DetectCodepageInIStream,
3187 fnIMultiLanguage2_DetectInputCodepage,
3188 fnIMultiLanguage2_ValidateCodePage,
3189 fnIMultiLanguage2_GetCodePageDescription,
3190 fnIMultiLanguage2_IsCodePageInstallable,
3191 fnIMultiLanguage2_SetMimeDBSource,
3192 fnIMultiLanguage2_GetNumberOfScripts,
3193 fnIMultiLanguage2_EnumScripts,
3194 fnIMultiLanguage2_ValidateCodePageEx,
3195 fnIMultiLanguage3_DetectOutboundCodePage,
3196 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3199 /******************************************************************************/
3201 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3203 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink2 );
3206 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3207 IMLangFontLink2 * iface,
3211 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3212 return MLang_QueryInterface( This, riid, ppvObject );
3215 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3217 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3218 return MLang_AddRef( This );
3221 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3223 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3224 return MLang_Release( This );
3227 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
3228 WCHAR chSrc, DWORD *pdwCodePages)
3230 FIXME("(%p)->%s %p\n",This, debugstr_wn(&chSrc,1),pdwCodePages);
3234 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
3235 const WCHAR *pszSrc, LONG cchSrc, DWORD dwPriorityCodePages,
3236 DWORD *pdwCodePages, LONG *pcchCodePages)
3238 return fnIMLangFontLink_GetStrCodePages((IMLangFontLink *)This,
3239 pszSrc, cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
3242 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
3244 DWORD *pdwCodePages)
3246 FIXME("(%p)->%i %p\n",This, uCodePage, pdwCodePages);
3250 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* This,
3251 DWORD dwCodePages, UINT uDefaultCodePage, UINT *puCodePage)
3253 FIXME("(%p)->%i %i %p\n",This, dwCodePages, uDefaultCodePage, puCodePage);
3257 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2* This,
3258 HDC hDC, HFONT hFont, DWORD *pdwCodePages)
3260 FIXME("(%p)->%p %p %p\n",This, hDC, hFont, pdwCodePages);
3264 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3267 FIXME("(%p)->%p\n",This, hFont);
3271 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3273 FIXME("(%p)->\n",This);
3277 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3278 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3280 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
3284 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3285 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3287 FIXME("(%p)->%p %p %p\n",This, hDC, puiRanges, pUranges);
3291 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3292 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3293 SCRIPTFONTINFO *pScriptFont)
3297 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3299 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3301 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3303 if (sid == mlang_data[i].sid)
3307 if (j >= *puiFonts) break;
3309 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3310 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3312 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3313 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3315 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3317 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3318 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3328 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3329 UINT uiCodePage, SCRIPT_ID *pSid)
3331 FIXME("(%p)->%i %p\n",This, uiCodePage, pSid);
3335 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3337 fnIMLangFontLink2_QueryInterface,
3338 fnIMLangFontLink2_AddRef,
3339 fnIMLangFontLink2_Release,
3340 fnIMLangFontLink2_GetCharCodePages,
3341 fnIMLangFontLink2_GetStrCodePages,
3342 fnIMLangFontLink2_CodePageToCodePages,
3343 fnIMLangFontLink2_CodePagesToCodePage,
3344 fnIMLangFontLink2_GetFontCodePages,
3345 fnIMLangFontLink2_ReleaseFont,
3346 fnIMLangFontLink2_ResetFontMapping,
3347 fnIMLangFontLink2_MapFont,
3348 fnIMLangFontLink2_GetFontUnicodeRanges,
3349 fnIMLangFontLink2_GetScriptFontInfo,
3350 fnIMLangFontLink2_CodePageToScriptID
3353 /******************************************************************************/
3355 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3357 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangLineBreakConsole );
3360 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3361 IMLangLineBreakConsole* iface,
3365 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3366 return MLang_QueryInterface( This, riid, ppvObject );
3369 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3370 IMLangLineBreakConsole* iface )
3372 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3373 return MLang_AddRef( This );
3376 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3377 IMLangLineBreakConsole* iface )
3379 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3380 return MLang_Release( This );
3383 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3384 IMLangLineBreakConsole* iface,
3385 IMLangString* pSrcMLStr,
3393 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3397 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3398 IMLangLineBreakConsole* iface,
3400 const WCHAR* pszSrc,
3406 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3413 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3414 IMLangLineBreakConsole* iface,
3423 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3430 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3432 fnIMLangLineBreakConsole_QueryInterface,
3433 fnIMLangLineBreakConsole_AddRef,
3434 fnIMLangLineBreakConsole_Release,
3435 fnIMLangLineBreakConsole_BreakLineML,
3436 fnIMLangLineBreakConsole_BreakLineW,
3437 fnIMLangLineBreakConsole_BreakLineA
3440 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3445 TRACE("Creating MultiLanguage object\n");
3448 return CLASS_E_NOAGGREGATION;
3450 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3451 mlang->vtbl_IMLangFontLink = &IMLangFontLink_vtbl;
3452 mlang->vtbl_IMultiLanguage = &IMultiLanguage_vtbl;
3453 mlang->vtbl_IMultiLanguage3 = &IMultiLanguage3_vtbl;
3454 mlang->vtbl_IMLangFontLink2 = &IMLangFontLink2_vtbl;
3455 mlang->vtbl_IMLangLineBreakConsole = &IMLangLineBreakConsole_vtbl;
3457 mlang->total_cp = 0;
3458 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3459 mlang->total_cp += mlang_data[i].number_of_cp;
3461 /* do not enumerate unicode flavours */
3462 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3466 TRACE("returning %p\n", mlang);
3473 /******************************************************************************/
3475 HRESULT WINAPI DllCanUnloadNow(void)
3477 return dll_count == 0 ? S_OK : S_FALSE;
3480 HRESULT WINAPI GetGlobalFontLinkObject(void)