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
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
44 #define CP_UNICODE 1200
46 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
47 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
49 static DWORD MLANG_tls_index; /* to store various per thead data */
52 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
53 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
58 const char *description;
61 const char *web_charset;
62 const char *header_charset;
63 const char *body_charset;
66 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
67 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
69 static const MIME_CP_INFO arabic_cp[] =
72 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
73 MIMECONTF_MIME_LATEST,
74 "ibm864", "ibm864", "ibm864" },
76 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
77 MIMECONTF_MIME_LATEST,
78 "ibm1006", "ibm1006", "ibm1006" },
80 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
81 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
82 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
83 "windows-1256", "windows-1256", "windows-1256" },
85 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
86 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
87 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
88 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
89 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
91 static const MIME_CP_INFO baltic_cp[] =
94 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
95 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
96 "ibm775", "ibm775", "ibm775" },
98 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
99 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
100 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
101 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
102 "windows-1257", "windows-1257", "windows-1257" },
104 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
105 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
106 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
107 MIMECONTF_MIME_LATEST,
108 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
110 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
111 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
112 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
114 static const MIME_CP_INFO chinese_simplified_cp[] =
116 { "Chinese Simplified (GB2312)",
117 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
118 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
119 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
120 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
121 "gb2312", "gb2312", "gb2312" }
123 static const MIME_CP_INFO chinese_traditional_cp[] =
125 { "Chinese Traditional (Big5)",
126 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
127 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
128 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
129 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
130 "big5", "big5", "big5" }
132 static const MIME_CP_INFO central_european_cp[] =
134 { "Central European (DOS)",
135 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
136 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
137 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
138 "ibm852", "ibm852", "ibm852" },
139 { "Central European (Windows)",
140 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
141 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
142 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
143 MIMECONTF_MIME_LATEST,
144 "windows-1250", "windows-1250", "windows-1250" },
145 { "Central European (Mac)",
146 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
147 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
148 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
149 { "Central European (ISO)",
150 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
151 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
152 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
153 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
154 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
156 static const MIME_CP_INFO cyrillic_cp[] =
159 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
160 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
161 "ibm855", "ibm855", "ibm855" },
163 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
164 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
165 MIMECONTF_MIME_LATEST,
166 "cp866", "cp866", "cp866" },
167 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
168 { "Cyrillic (KOI8-R)",
169 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
170 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
171 "koi8-r", "koi8-r", "koi8-r" },
173 { "Cyrillic (Windows)",
174 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
175 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
176 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
177 "windows-1251", "windows-1251", "windows-1251" },
179 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
180 MIMECONTF_MIME_LATEST,
181 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
182 { "Cyrillic (KOI8-R)",
183 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
184 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
185 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
186 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
187 "koi8-r", "koi8-r", "koi8-r" },
188 { "Cyrillic (KOI8-U)",
189 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
190 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
191 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
192 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
193 "koi8-u", "koi8-u", "koi8-u" },
195 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
196 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
197 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
198 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
199 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
201 static const MIME_CP_INFO greek_cp[] =
204 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
205 MIMECONTF_MIME_LATEST,
206 "ibm737", "ibm737", "ibm737" },
207 { "Greek, Modern (DOS)",
208 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
209 MIMECONTF_MIME_LATEST,
210 "ibm869", "ibm869", "ibm869" },
211 { "IBM EBCDIC (Greek Modern)",
212 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
213 MIMECONTF_MIME_LATEST,
214 "cp875", "cp875", "cp875" },
216 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
217 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
218 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
219 "windows-1253", "windows-1253", "windows-1253" },
221 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
222 MIMECONTF_MIME_LATEST,
223 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
225 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
226 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
227 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
228 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
229 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
231 static const MIME_CP_INFO hebrew_cp[] =
234 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
235 MIMECONTF_MIME_LATEST,
236 "ibm424", "ibm424", "ibm424" },
238 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
239 MIMECONTF_MIME_LATEST,
240 "cp856", "cp856", "cp856" },
242 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
243 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
244 MIMECONTF_MIME_LATEST,
245 "dos-862", "dos-862", "dos-862" },
246 { "Hebrew (Windows)",
247 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
248 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
249 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
250 "windows-1255", "windows-1255", "windows-1255" },
251 { "Hebrew (ISO-Visual)",
252 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
253 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
254 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
255 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
257 static const MIME_CP_INFO japanese_cp[] =
259 { "Japanese (Auto-Select)",
260 50932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
261 MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
262 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
263 "_autodetect", "_autodetect", "_autodetect" },
265 51932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
266 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
267 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
268 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
269 "euc-jp", "euc-jp", "euc-jp" },
271 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
272 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
273 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
275 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
276 { "Japanese (JIS 0208-1990 and 0212-1990)",
277 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
278 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
279 "EUC-JP","EUC-JP","EUC-JP"},
280 { "Japanese (JIS-Allow 1 byte Kana)",
281 50221, MIMECONTF_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_SAVABLE_BROWSER |
282 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
283 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
284 "csISO2022JP","iso-2022-jp","iso-2022-jp"},
285 { "Japanese (JIS-Allow 1 byte Kana - SO/SI)",
286 50222, MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_VALID |
287 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
288 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
290 10001, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
291 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
292 "x-mac-japanese","x-mac-japanese","x-mac-japanese"},
293 { "Japanese (Shift-JIS)",
294 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
295 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
296 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
297 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
298 "shift_jis", "iso-2022-jp", "iso-2022-jp" }
300 static const MIME_CP_INFO korean_cp[] =
303 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
304 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
305 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
306 MIMECONTF_MIME_LATEST,
307 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
309 static const MIME_CP_INFO thai_cp[] =
312 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
313 "ibm-thai", "ibm-thai", "ibm-thai" }
315 static const MIME_CP_INFO turkish_cp[] =
318 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
319 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
320 "ibm857", "ibm857", "ibm857" },
321 { "IBM EBCDIC (Turkish Latin-5)",
322 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
323 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
324 "ibm1026", "ibm1026", "ibm1026" },
325 { "Turkish (Windows)",
326 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
327 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
328 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
329 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
330 "windows-1254", "windows-1254", "windows-1254" },
332 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
333 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
334 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
336 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
337 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
338 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
339 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
341 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
342 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
343 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
344 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
345 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
347 static const MIME_CP_INFO vietnamese_cp[] =
349 { "Vietnamese (Windows)",
350 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
351 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
352 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
353 MIMECONTF_MIME_LATEST,
354 "windows-1258", "windows-1258", "windows-1258" }
356 static const MIME_CP_INFO western_cp[] =
358 { "IBM EBCDIC (US-Canada)",
359 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
360 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
361 "ibm037", "ibm037", "ibm037" },
362 { "OEM United States",
363 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
364 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
365 "ibm437", "ibm437", "ibm437" },
366 { "IBM EBCDIC (International)",
367 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
368 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
369 "ibm500", "ibm500", "ibm500" },
370 { "Western European (DOS)",
371 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
372 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
373 "ibm850", "ibm850", "ibm850" },
374 { "Portuguese (DOS)",
375 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
376 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
377 "ibm860", "ibm860", "ibm860" },
379 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
380 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
381 "ibm861", "ibm861", "ibm861" },
382 { "French Canadian (DOS)",
383 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
384 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
385 "ibm863", "ibm863", "ibm863" },
387 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
388 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
389 "ibm865", "ibm865", "ibm865" },
390 { "Western European (Windows)",
391 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
392 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
393 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
394 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
395 "windows-1252", "windows-1252", "iso-8859-1" },
396 { "Western European (Mac)",
397 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
398 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
399 "macintosh", "macintosh", "macintosh" },
401 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
402 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
403 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
405 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
406 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
407 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
408 "us-ascii", "us-ascii", "us-ascii" },
409 { "Western European (ISO)",
410 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
411 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
412 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
413 MIMECONTF_MIME_LATEST,
414 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
416 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
417 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
418 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
419 MIMECONTF_MIME_LATEST,
420 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
422 static const MIME_CP_INFO unicode_cp[] =
425 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
426 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
427 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
428 MIMECONTF_MIME_LATEST,
429 "unicode", "unicode", "unicode" },
431 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
432 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
433 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
434 "utf-7", "utf-7", "utf-7" },
436 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
437 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
438 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
439 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
440 "utf-8", "utf-8", "utf-8" }
443 static const struct mlang_data
445 const char *description;
446 UINT family_codepage;
448 const MIME_CP_INFO *mime_cp_info;
449 const char *fixed_font;
450 const char *proportional_font;
454 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
455 "Courier","Arial", sidArabic }, /* FIXME */
456 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
457 "Courier","Arial" }, /* FIXME */
458 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
459 "Courier","Arial" }, /* FIXME */
460 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
461 "Courier","Arial" }, /* FIXME */
462 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
463 "Courier","Arial" }, /* FIXME */
464 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
465 "Courier","Arial", sidCyrillic }, /* FIXME */
466 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
467 "Courier","Arial", sidGreek }, /* FIXME */
468 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
469 "Courier","Arial", sidHebrew }, /* FIXME */
470 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
471 "MS Gothic","MS PGothic" },
472 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
473 "Courier","Arial" }, /* FIXME */
474 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
475 "Courier","Arial", sidThai }, /* FIXME */
476 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
477 "Courier","Arial" }, /* FIXME */
478 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
479 "Courier","Arial" }, /* FIXME */
480 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
481 "Courier","Arial", sidLatin }, /* FIXME */
482 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
483 "Courier","Arial" } /* FIXME */
486 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
488 static LONG dll_count;
491 * Japanese Detection and Converstion Functions
494 #define HANKATA(A) ((A >= 161) && (A <= 223))
495 #define ISEUC(A) ((A >= 161) && (A <= 254))
496 #define NOTEUC(A,B) (((A >= 129) && (A <= 159)) && ((B >= 64) && (B <= 160)))
497 #define SJIS1(A) (((A >= 129) && (A <= 159)) || ((A >= 224) && (A <= 239)))
498 #define SJIS2(A) ((A >= 64) && (A <= 252))
499 #define ISMARU(A) ((A >= 202) && (A <= 206))
500 #define ISNIGORI(A) (((A >= 182) && (A <= 196)) || ((A >= 202) && (A <= 206)))
502 static UINT DetectJapaneseCode(LPCSTR input, DWORD count)
508 while ((code == 0 || code == 51932) && i < count)
511 if (c1 == 0x1b /* ESC */)
523 if (c1 =='B' || c1 == '@')
537 else if (ISEUC(c1) && ISEUC(c2))
539 else if (((c1 == 142)) && HANKATA(c2))
547 static inline void jis2sjis(unsigned char *p1, unsigned char *p2)
549 unsigned char c1 = *p1;
550 unsigned char c2 = *p2;
551 int row = c1 < 95 ? 112 : 176;
552 int cell = c1 % 2 ? 31 + (c2 > 95) : 126;
554 *p1 = ((c1 + 1) >> 1) + row;
558 static inline void sjis2jis(unsigned char *p1, unsigned char *p2)
560 unsigned char c1 = *p1;
561 unsigned char c2 = *p2;
562 int shift = c2 < 159;
563 int row = c1 < 160 ? 112 : 176;
564 int cell = shift ? (31 + (c2 > 127)): 126;
566 *p1 = ((c1 - row) << 1) - shift;
570 static int han2zen(unsigned char *p1, unsigned char *p2)
574 static const unsigned char char1[] = {129,129,129,129,129,131,131,131,131,
575 131,131,131,131,131,131,129,131,131,131,131,131,131,131,131,131,131,
576 131,131,131,131,131,131,131,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,
579 static const unsigned char char2[] = {66,117,118,65,69,146,64,66,68,70,
580 72,131,133,135,98,91,65,67,69,71,73,74,76,78,80,82,84,86,88,90,92,94,
581 96,99,101,103,105,106,107,108,109,110,113,116,119,122,125,126,128,
582 129,130,132,134,136,137,138,139,140,141,143,147,74,75};
584 if (( *p2 == 222) && ((ISNIGORI(*p1) || (*p1 == 179))))
586 else if ((*p2 == 223) && (ISMARU(*p1)))
589 if (*p1 >= 161 && *p1 <= 223)
591 unsigned char index = *p1 - 161;
600 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
602 else if ((*p1 == 131) && (*p2 == 69))
605 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
615 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
625 if (p == 0x1b /* ESC */)
631 if (p2 == '$' || p2 =='(')
633 if (p2 == 'K' || p2 =='$')
660 static inline int exit_shift(LPSTR out, int c)
671 static inline int enter_shift(LPSTR out, int c)
683 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
693 if (p == 10 || p == 13) /* NL and CR */
698 j += exit_shift(output,j);
712 p2 = input[i] & 0xff;
719 j+=enter_shift(output,j);
737 p2 = input[i+1] & 0xff;
743 j+=enter_shift(output,j);
758 j += exit_shift(output,j);
770 j += exit_shift(output,j);
774 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
775 LPWSTR output, DWORD out_count)
779 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
780 rc = ConvertJIS2SJIS(input,count,sjis_string);
783 TRACE("%s\n",debugstr_an(sjis_string,rc));
785 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
787 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
789 HeapFree(GetProcessHeap(),0,sjis_string);
794 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
795 LPWSTR output, DWORD out_count)
799 int code = DetectJapaneseCode(input,count);
800 TRACE("Japanese code %i\n",code);
806 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
808 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
813 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
815 rc = MultiByteToWideChar(932,0,input,count,0,0);
820 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
822 rc = MultiByteToWideChar(20932,0,input,count,0,0);
826 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
827 rc = ConvertJIS2SJIS(input,count,sjis_string);
830 TRACE("%s\n",debugstr_an(sjis_string,rc));
832 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
834 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
836 HeapFree(GetProcessHeap(),0,sjis_string);
842 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
843 LPSTR output, DWORD out_count)
849 len = WideCharToMultiByte(932,0,input,count,0,0,NULL,NULL);
850 sjis_string = HeapAlloc(GetProcessHeap(),0,len);
851 WideCharToMultiByte(932,0,input,count,sjis_string,len,NULL,NULL);
852 TRACE("%s\n",debugstr_an(sjis_string,len));
854 rc = ConvertSJIS2JIS(sjis_string, len, NULL);
857 ConvertSJIS2JIS(sjis_string, len, output);
859 HeapFree(GetProcessHeap(),0,sjis_string);
865 * Dll lifetime tracking declaration
867 static void LockModule(void)
869 InterlockedIncrement(&dll_count);
872 static void UnlockModule(void)
874 InterlockedDecrement(&dll_count);
877 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
880 case DLL_PROCESS_ATTACH:
881 MLANG_tls_index = TlsAlloc();
882 DisableThreadLibraryCalls(hInstDLL);
884 case DLL_PROCESS_DETACH:
885 TlsFree(MLANG_tls_index);
891 HRESULT WINAPI ConvertINetMultiByteToUnicode(
901 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
902 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
908 pcSrcSize = &src_len;
916 /* forwarding euc-jp to EUC-JP */
917 if (dwEncoding == 51932)
923 if (*pcSrcSize == -1)
924 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
925 *pcDstSize = min(*pcSrcSize, *pcDstSize);
926 *pcSrcSize *= sizeof(WCHAR);
928 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
934 *pcDstSize = ConvertJISJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
937 *pcDstSize = ConvertUnknownJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
941 if (*pcSrcSize == -1)
942 *pcSrcSize = lstrlenA(pSrcStr);
945 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
947 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
957 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
968 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
969 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
975 pcSrcSize = &src_len;
977 destsz = (pDstStr) ? *pcDstSize : 0;
980 if (!pSrcStr || !*pcSrcSize)
983 if (*pcSrcSize == -1)
984 *pcSrcSize = lstrlenW(pSrcStr);
986 /* forwarding euc-jp to EUC-JP */
987 if (dwEncoding == 51932)
990 if (dwEncoding == CP_UNICODE)
992 if (*pcSrcSize == -1)
993 *pcSrcSize = lstrlenW(pSrcStr);
995 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
997 memmove(pDstStr, pSrcStr, size);
1002 else if (dwEncoding == 50220 || dwEncoding == 50221 || dwEncoding == 50222)
1004 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, NULL, 0);
1010 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, pDstStr,
1019 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1020 NULL, 0, NULL, NULL);
1026 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1027 pDstStr, destsz, NULL, NULL);
1042 HRESULT WINAPI ConvertINetString(
1044 DWORD dwSrcEncoding,
1045 DWORD dwDstEncoding,
1052 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
1053 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1055 if (dwSrcEncoding == CP_UNICODE)
1058 if (pcSrcSize && *pcSrcSize != -1)
1060 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
1061 pcSrcSize = &cSrcSizeW;
1063 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
1065 else if (dwDstEncoding == CP_UNICODE)
1067 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
1068 *pcDstSize *= sizeof(WCHAR);
1077 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
1079 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
1083 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
1084 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
1086 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
1088 HeapFree(GetProcessHeap(), 0, pDstStrW);
1093 static HRESULT GetFamilyCodePage(
1095 UINT* puiFamilyCodePage)
1099 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
1101 if (!puiFamilyCodePage) return S_FALSE;
1103 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1105 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1107 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1109 *puiFamilyCodePage = mlang_data[i].family_codepage;
1118 HRESULT WINAPI IsConvertINetStringAvailable(
1119 DWORD dwSrcEncoding,
1120 DWORD dwDstEncoding)
1122 UINT src_family, dst_family;
1124 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
1126 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
1127 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
1130 if (src_family == dst_family) return S_OK;
1132 /* we can convert any codepage to/from unicode */
1133 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
1138 static inline INT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
1140 INT n = GetLocaleInfoA( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
1143 rfc1766[n - 1] = '-';
1144 n += GetLocaleInfoA( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
1145 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
1151 static inline INT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
1153 INT n = GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
1157 rfc1766[n - 1] = '-';
1158 n += GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
1160 rfc1766[n - 1] = '\0';
1161 LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
1167 HRESULT WINAPI LcidToRfc1766A(
1172 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1174 if (lcid_to_rfc1766A( lcid, pszRfc1766, nChar ))
1180 HRESULT WINAPI LcidToRfc1766W(
1185 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1187 if (lcid_to_rfc1766W( lcid, pszRfc1766, nChar ))
1193 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
1198 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
1200 if (!strcmpW(info.wszRfc1766, rfc1766))
1205 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
1207 *lcid = PRIMARYLANGID(info.lcid);
1215 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
1217 IEnumRfc1766 *enumrfc1766;
1220 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
1222 if (!pLocale || !pszRfc1766)
1223 return E_INVALIDARG;
1227 hr = EnumRfc1766_create(0, &enumrfc1766);
1231 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
1232 IEnumRfc1766_Release(enumrfc1766);
1237 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
1239 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1241 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
1242 rfc1766W[MAX_RFC1766_NAME] = 0;
1244 return Rfc1766ToLcidW(lcid, rfc1766W);
1247 /******************************************************************************
1248 * MLANG ClassFactory
1251 IClassFactory ITF_IClassFactory;
1254 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1255 } IClassFactoryImpl;
1257 struct object_creation_info
1261 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1264 static const struct object_creation_info object_creation[] =
1266 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
1269 static HRESULT WINAPI
1270 MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1272 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1274 TRACE("%s\n", debugstr_guid(riid) );
1276 if (IsEqualGUID(riid, &IID_IUnknown)
1277 || IsEqualGUID(riid, &IID_IClassFactory))
1279 IClassFactory_AddRef(iface);
1284 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
1285 return E_NOINTERFACE;
1288 static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
1290 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1291 return InterlockedIncrement(&This->ref);
1294 static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
1296 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1298 ULONG ref = InterlockedDecrement(&This->ref);
1302 TRACE("Destroying %p\n", This);
1303 HeapFree(GetProcessHeap(), 0, This);
1309 static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
1310 REFIID riid, LPVOID *ppobj)
1312 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1316 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1319 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
1320 if (SUCCEEDED(hres)) {
1321 hres = IUnknown_QueryInterface(punk, riid, ppobj);
1322 IUnknown_Release(punk);
1324 TRACE("returning (%p) -> %x\n", *ppobj, hres);
1328 static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1338 static const IClassFactoryVtbl MLANGCF_Vtbl =
1340 MLANGCF_QueryInterface,
1343 MLANGCF_CreateInstance,
1347 /******************************************************************
1348 * DllGetClassObject (MLANG.@)
1350 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
1353 IClassFactoryImpl *factory;
1355 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
1357 if ( !IsEqualGUID( &IID_IClassFactory, iid )
1358 && ! IsEqualGUID( &IID_IUnknown, iid) )
1359 return E_NOINTERFACE;
1361 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
1363 if (IsEqualGUID(object_creation[i].clsid, rclsid))
1367 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
1369 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
1370 return CLASS_E_CLASSNOTAVAILABLE;
1373 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
1375 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
1376 if (factory == NULL) return E_OUTOFMEMORY;
1378 factory->ITF_IClassFactory.lpVtbl = &MLANGCF_Vtbl;
1381 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
1383 *ppv = &(factory->ITF_IClassFactory);
1385 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
1391 /******************************************************************************/
1393 typedef struct tagMLang_impl
1395 const IMLangFontLinkVtbl *vtbl_IMLangFontLink;
1396 const IMultiLanguageVtbl *vtbl_IMultiLanguage;
1397 const IMultiLanguage3Vtbl *vtbl_IMultiLanguage3;
1398 const IMLangFontLink2Vtbl *vtbl_IMLangFontLink2;
1399 const IMLangLineBreakConsoleVtbl *vtbl_IMLangLineBreakConsole;
1401 DWORD total_cp, total_scripts;
1404 static ULONG MLang_AddRef( MLang_impl* This)
1406 return InterlockedIncrement(&This->ref);
1409 static ULONG MLang_Release( MLang_impl* This )
1411 ULONG ref = InterlockedDecrement(&This->ref);
1413 TRACE("%p ref = %d\n", This, ref);
1416 TRACE("Destroying %p\n", This);
1417 HeapFree(GetProcessHeap(), 0, This);
1424 static HRESULT MLang_QueryInterface(
1429 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1431 if (IsEqualGUID(riid, &IID_IUnknown)
1432 || IsEqualGUID(riid, &IID_IMLangCodePages)
1433 || IsEqualGUID(riid, &IID_IMLangFontLink))
1436 TRACE("Returning IID_IMLangFontLink %p ref = %d\n", This, This->ref);
1437 *ppvObject = &(This->vtbl_IMLangFontLink);
1441 if (IsEqualGUID(riid, &IID_IMLangFontLink2))
1444 TRACE("Returning IID_IMLangFontLink2 %p ref = %d\n", This, This->ref);
1445 *ppvObject = &(This->vtbl_IMLangFontLink2);
1449 if (IsEqualGUID(riid, &IID_IMultiLanguage) )
1452 TRACE("Returning IID_IMultiLanguage %p ref = %d\n", This, This->ref);
1453 *ppvObject = &(This->vtbl_IMultiLanguage);
1457 if (IsEqualGUID(riid, &IID_IMultiLanguage2) )
1460 *ppvObject = &(This->vtbl_IMultiLanguage3);
1461 TRACE("Returning IID_IMultiLanguage2 %p ref = %d\n", This, This->ref);
1465 if (IsEqualGUID(riid, &IID_IMultiLanguage3) )
1468 *ppvObject = &(This->vtbl_IMultiLanguage3);
1469 TRACE("Returning IID_IMultiLanguage3 %p ref = %d\n", This, This->ref);
1473 if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
1476 TRACE("Returning IID_IMLangLineBreakConsole %p ref = %d\n", This, This->ref);
1477 *ppvObject = &(This->vtbl_IMLangLineBreakConsole);
1482 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1483 return E_NOINTERFACE;
1486 /******************************************************************************/
1488 typedef struct tagEnumCodePage_impl
1490 const IEnumCodePageVtbl *vtbl_IEnumCodePage;
1494 } EnumCodePage_impl;
1496 static inline EnumCodePage_impl *impl_from_IEnumCodePage( IEnumCodePage *iface )
1498 return CONTAINING_RECORD( iface, EnumCodePage_impl, vtbl_IEnumCodePage );
1501 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1502 IEnumCodePage* iface,
1506 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1508 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1510 if (IsEqualGUID(riid, &IID_IUnknown)
1511 || IsEqualGUID(riid, &IID_IEnumCodePage))
1513 IEnumCodePage_AddRef(iface);
1514 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1515 *ppvObject = &(This->vtbl_IEnumCodePage);
1519 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1520 return E_NOINTERFACE;
1523 static ULONG WINAPI fnIEnumCodePage_AddRef(
1524 IEnumCodePage* iface)
1526 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1527 return InterlockedIncrement(&This->ref);
1530 static ULONG WINAPI fnIEnumCodePage_Release(
1531 IEnumCodePage* iface)
1533 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1534 ULONG ref = InterlockedDecrement(&This->ref);
1536 TRACE("%p ref = %d\n", This, ref);
1539 TRACE("Destroying %p\n", This);
1540 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1541 HeapFree(GetProcessHeap(), 0, This);
1547 static HRESULT WINAPI fnIEnumCodePage_Clone(
1548 IEnumCodePage* iface,
1549 IEnumCodePage** ppEnum)
1551 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1552 FIXME("%p %p\n", This, ppEnum);
1556 static HRESULT WINAPI fnIEnumCodePage_Next(
1557 IEnumCodePage* iface,
1560 ULONG* pceltFetched)
1563 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1565 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1567 if (!pceltFetched) return S_FALSE;
1570 if (!rgelt) return S_FALSE;
1572 if (This->pos + celt > This->total)
1573 celt = This->total - This->pos;
1575 if (!celt) return S_FALSE;
1577 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1578 *pceltFetched = celt;
1581 for (i = 0; i < celt; i++)
1583 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1584 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1585 rgelt[i].uiFamilyCodePage,
1586 wine_dbgstr_w(rgelt[i].wszDescription),
1587 wine_dbgstr_w(rgelt[i].wszWebCharset),
1588 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1589 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1590 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1591 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1592 rgelt[i].bGDICharset);
1597 static HRESULT WINAPI fnIEnumCodePage_Reset(
1598 IEnumCodePage* iface)
1600 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1602 TRACE("%p\n", This);
1608 static HRESULT WINAPI fnIEnumCodePage_Skip(
1609 IEnumCodePage* iface,
1612 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1614 TRACE("%p %u\n", This, celt);
1616 if (celt >= This->total) return S_FALSE;
1622 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1624 fnIEnumCodePage_QueryInterface,
1625 fnIEnumCodePage_AddRef,
1626 fnIEnumCodePage_Release,
1627 fnIEnumCodePage_Clone,
1628 fnIEnumCodePage_Next,
1629 fnIEnumCodePage_Reset,
1630 fnIEnumCodePage_Skip
1633 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1634 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1636 EnumCodePage_impl *ecp;
1640 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1642 if (!grfFlags) /* enumerate internal data base of encodings */
1643 grfFlags = MIMECONTF_MIME_LATEST;
1645 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1646 ecp->vtbl_IEnumCodePage = &IEnumCodePage_vtbl;
1650 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1652 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1654 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1659 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1660 sizeof(MIMECPINFO) * ecp->total);
1661 cpinfo = ecp->cpinfo;
1663 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1665 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1667 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1668 fill_cp_info(&mlang_data[i], n, cpinfo++);
1672 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1674 *ppEnumCodePage = (IEnumCodePage*) ecp;
1679 /******************************************************************************/
1681 typedef struct tagEnumScript_impl
1683 const IEnumScriptVtbl *vtbl_IEnumScript;
1685 SCRIPTINFO *script_info;
1689 static inline EnumScript_impl *impl_from_IEnumScript( IEnumScript *iface )
1691 return CONTAINING_RECORD( iface, EnumScript_impl, vtbl_IEnumScript );
1694 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1699 EnumScript_impl *This = impl_from_IEnumScript( iface );
1701 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1703 if (IsEqualGUID(riid, &IID_IUnknown)
1704 || IsEqualGUID(riid, &IID_IEnumScript))
1706 IEnumScript_AddRef(iface);
1707 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1708 *ppvObject = &(This->vtbl_IEnumScript);
1712 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1713 return E_NOINTERFACE;
1716 static ULONG WINAPI fnIEnumScript_AddRef(
1719 EnumScript_impl *This = impl_from_IEnumScript( iface );
1720 return InterlockedIncrement(&This->ref);
1723 static ULONG WINAPI fnIEnumScript_Release(
1726 EnumScript_impl *This = impl_from_IEnumScript( iface );
1727 ULONG ref = InterlockedDecrement(&This->ref);
1729 TRACE("%p ref = %d\n", This, ref);
1732 TRACE("Destroying %p\n", This);
1733 HeapFree(GetProcessHeap(), 0, This->script_info);
1734 HeapFree(GetProcessHeap(), 0, This);
1740 static HRESULT WINAPI fnIEnumScript_Clone(
1742 IEnumScript** ppEnum)
1744 EnumScript_impl *This = impl_from_IEnumScript( iface );
1745 FIXME("%p %p: stub!\n", This, ppEnum);
1749 static HRESULT WINAPI fnIEnumScript_Next(
1753 ULONG* pceltFetched)
1755 EnumScript_impl *This = impl_from_IEnumScript( iface );
1757 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1759 if (!pceltFetched || !rgelt) return E_FAIL;
1763 if (This->pos + celt > This->total)
1764 celt = This->total - This->pos;
1766 if (!celt) return S_FALSE;
1768 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1769 *pceltFetched = celt;
1775 static HRESULT WINAPI fnIEnumScript_Reset(
1778 EnumScript_impl *This = impl_from_IEnumScript( iface );
1780 TRACE("%p\n", This);
1786 static HRESULT WINAPI fnIEnumScript_Skip(
1790 EnumScript_impl *This = impl_from_IEnumScript( iface );
1792 TRACE("%p %u\n", This, celt);
1794 if (celt >= This->total) return S_FALSE;
1800 static const IEnumScriptVtbl IEnumScript_vtbl =
1802 fnIEnumScript_QueryInterface,
1803 fnIEnumScript_AddRef,
1804 fnIEnumScript_Release,
1805 fnIEnumScript_Clone,
1807 fnIEnumScript_Reset,
1811 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1812 LANGID LangId, IEnumScript** ppEnumScript )
1814 EnumScript_impl *es;
1817 TRACE("%p, %08x, %04x, %p: stub!\n", mlang, dwFlags, LangId, ppEnumScript);
1819 if (!dwFlags) /* enumerate all available scripts */
1820 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1822 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1823 es->vtbl_IEnumScript = &IEnumScript_vtbl;
1826 /* do not enumerate unicode flavours */
1827 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1828 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1830 for (i = 0; i < es->total; i++)
1832 es->script_info[i].ScriptId = i;
1833 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1834 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1835 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1836 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1837 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1838 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1839 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1842 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1844 *ppEnumScript = (IEnumScript *)es;
1849 /******************************************************************************/
1851 static inline MLang_impl *impl_from_IMLangFontLink( IMLangFontLink *iface )
1853 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink );
1856 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1857 IMLangFontLink* iface,
1861 MLang_impl *This = impl_from_IMLangFontLink( iface );
1862 return MLang_QueryInterface( This, riid, ppvObject );
1865 static ULONG WINAPI fnIMLangFontLink_AddRef(
1866 IMLangFontLink* iface)
1868 MLang_impl *This = impl_from_IMLangFontLink( iface );
1869 return MLang_AddRef( This );
1872 static ULONG WINAPI fnIMLangFontLink_Release(
1873 IMLangFontLink* iface)
1875 MLang_impl *This = impl_from_IMLangFontLink( iface );
1876 return MLang_Release( This );
1879 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1880 IMLangFontLink* iface,
1882 DWORD* pdwCodePages)
1891 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1893 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
1894 &chSrc, 1, &buf, 1, NULL, &used_dc);
1896 /* If default char is not used, current codepage include the given symbol */
1899 IMLangFontLink_CodePageToCodePages(iface,
1900 mlang_data[i].family_codepage, &codePages);
1901 *pdwCodePages |= codePages;
1907 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1908 IMLangFontLink* iface,
1909 const WCHAR* pszSrc,
1911 DWORD dwPriorityCodePages,
1912 DWORD* pdwCodePages,
1913 LONG* pcchCodePages)
1918 TRACE("(%p)->%s %d %x %p %p\n", iface, debugstr_wn(pszSrc, cchSrc), cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
1920 if (pdwCodePages) *pdwCodePages = 0;
1921 if (pcchCodePages) *pcchCodePages = 0;
1923 if (!pszSrc || !cchSrc || cchSrc < 0)
1924 return E_INVALIDARG;
1926 for (i = 0; i < cchSrc; i++)
1931 ret = fnIMLangFontLink_GetCharCodePages(iface, pszSrc[i], &cp);
1932 if (ret != S_OK) return E_FAIL;
1937 /* FIXME: not tested */
1938 if (dwPriorityCodePages & cps) break;
1941 if (pdwCodePages) *pdwCodePages = cps;
1942 if (pcchCodePages) *pcchCodePages = min( i + 1, cchSrc );
1946 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1947 IMLangFontLink* iface,
1949 DWORD* pdwCodePages)
1951 MLang_impl *This = impl_from_IMLangFontLink( iface );
1955 TRACE("(%p) Seeking %u\n",This, uCodePage);
1957 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uCodePage, &cs, TCI_SRCCODEPAGE);
1961 *pdwCodePages = cs.fs.fsCsb[0];
1962 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1966 TRACE("CodePage Not Found\n");
1971 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1972 IMLangFontLink* iface,
1974 UINT uDefaultCodePage,
1977 MLang_impl *This = impl_from_IMLangFontLink( iface );
1978 DWORD mask = 0x00000000;
1983 TRACE("(%p) scanning 0x%x default page %u\n",This, dwCodePages,
1986 *puCodePage = 0x00000000;
1988 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uDefaultCodePage, &cs,
1991 if (rc && (dwCodePages & cs.fs.fsCsb[0]))
1993 TRACE("Found Default Codepage\n");
1994 *puCodePage = uDefaultCodePage;
1999 for (i = 0; i < 32; i++)
2003 if (dwCodePages & mask)
2008 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
2012 TRACE("Falling back to least significant found CodePage %u\n",
2014 *puCodePage = cs.ciACP;
2019 TRACE("no codepage found\n");
2023 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
2024 IMLangFontLink* iface,
2027 DWORD* pdwCodePages)
2030 FONTSIGNATURE fontsig;
2031 MLang_impl *This = impl_from_IMLangFontLink( iface );
2033 TRACE("(%p)\n",This);
2035 old_font = SelectObject(hDC,hFont);
2036 GetTextCharsetInfo(hDC,&fontsig, 0);
2037 SelectObject(hDC,old_font);
2039 *pdwCodePages = fontsig.fsCsb[0];
2040 TRACE("CodePages is 0x%x\n",fontsig.fsCsb[0]);
2045 static HRESULT WINAPI fnIMLangFontLink_MapFont(
2046 IMLangFontLink* iface,
2056 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
2057 IMLangFontLink* iface,
2064 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
2065 IMLangFontLink* iface)
2072 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
2074 fnIMLangFontLink_QueryInterface,
2075 fnIMLangFontLink_AddRef,
2076 fnIMLangFontLink_Release,
2077 fnIMLangFontLink_GetCharCodePages,
2078 fnIMLangFontLink_GetStrCodePages,
2079 fnIMLangFontLink_CodePageToCodePages,
2080 fnIMLangFontLink_CodePagesToCodePage,
2081 fnIMLangFontLink_GetFontCodePages,
2082 fnIMLangFontLink_MapFont,
2083 fnIMLangFontLink_ReleaseFont,
2084 fnIMLangFontLink_ResetFontMapping,
2087 /******************************************************************************/
2089 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
2091 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage );
2094 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
2095 IMultiLanguage* iface,
2099 MLang_impl *This = impl_from_IMultiLanguage( iface );
2100 return MLang_QueryInterface( This, riid, ppvObject );
2103 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
2105 MLang_impl *This = impl_from_IMultiLanguage( iface );
2106 return IMLangFontLink_AddRef( ((IMLangFontLink*)This) );
2109 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
2111 MLang_impl *This = impl_from_IMultiLanguage( iface );
2112 return IMLangFontLink_Release( ((IMLangFontLink*)This) );
2115 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
2116 IMultiLanguage* iface,
2123 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
2124 IMultiLanguage* iface,
2126 PMIMECPINFO pCodePageInfo)
2129 MLang_impl *This = impl_from_IMultiLanguage( iface );
2131 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
2133 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2135 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2137 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2139 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2148 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
2149 IMultiLanguage* iface,
2151 UINT* puiFamilyCodePage)
2153 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2156 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
2157 IMultiLanguage* iface,
2159 IEnumCodePage** ppEnumCodePage)
2161 MLang_impl *This = impl_from_IMultiLanguage( iface );
2163 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2165 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2168 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2169 IMultiLanguage* iface,
2171 PMIMECSETINFO pCharsetInfo)
2173 MLang_impl *This = impl_from_IMultiLanguage( iface );
2174 return IMultiLanguage3_GetCharsetInfo((IMultiLanguage3*)&This->vtbl_IMultiLanguage3, Charset, pCharsetInfo);
2177 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2178 IMultiLanguage* iface,
2179 DWORD dwSrcEncoding,
2180 DWORD dwDstEncoding)
2182 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2185 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2186 IMultiLanguage* iface,
2188 DWORD dwSrcEncoding,
2189 DWORD dwDstEncoding,
2195 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2196 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2199 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2200 IMultiLanguage* iface,
2208 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2209 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2212 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2213 IMultiLanguage* iface,
2221 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2222 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2225 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2226 IMultiLanguage* iface)
2232 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2233 IMultiLanguage* iface,
2237 WCHAR buf[MAX_RFC1766_NAME];
2239 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2241 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2243 *pbstrRfc1766 = SysAllocString( buf );
2249 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2250 IMultiLanguage* iface,
2255 IEnumRfc1766 *rfc1766;
2257 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2259 if (!pLocale || !bstrRfc1766)
2260 return E_INVALIDARG;
2262 hr = IMultiLanguage_EnumRfc1766(iface, &rfc1766);
2266 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2268 IEnumRfc1766_Release(rfc1766);
2272 /******************************************************************************/
2274 typedef struct tagEnumRfc1766_impl
2276 const IEnumRfc1766Vtbl *vtbl_IEnumRfc1766;
2282 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2284 return CONTAINING_RECORD( iface, EnumRfc1766_impl, vtbl_IEnumRfc1766 );
2287 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2288 IEnumRfc1766 *iface,
2292 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2294 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2296 if (IsEqualGUID(riid, &IID_IUnknown)
2297 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2299 IEnumRfc1766_AddRef(iface);
2300 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2301 *ppvObject = &(This->vtbl_IEnumRfc1766);
2305 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2306 return E_NOINTERFACE;
2309 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2310 IEnumRfc1766 *iface)
2312 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2313 return InterlockedIncrement(&This->ref);
2316 static ULONG WINAPI fnIEnumRfc1766_Release(
2317 IEnumRfc1766 *iface)
2319 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2320 ULONG ref = InterlockedDecrement(&This->ref);
2322 TRACE("%p ref = %d\n", This, ref);
2325 TRACE("Destroying %p\n", This);
2326 HeapFree(GetProcessHeap(), 0, This->info);
2327 HeapFree(GetProcessHeap(), 0, This);
2332 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2333 IEnumRfc1766 *iface,
2334 IEnumRfc1766 **ppEnum)
2336 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2338 FIXME("%p %p\n", This, ppEnum);
2342 static HRESULT WINAPI fnIEnumRfc1766_Next(
2343 IEnumRfc1766 *iface,
2346 ULONG *pceltFetched)
2349 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2351 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2353 if (!pceltFetched) return S_FALSE;
2356 if (!rgelt) return S_FALSE;
2358 if (This->pos + celt > This->total)
2359 celt = This->total - This->pos;
2361 if (!celt) return S_FALSE;
2363 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2364 *pceltFetched = celt;
2367 for (i = 0; i < celt; i++)
2369 TRACE("#%u: %08x %s %s\n",
2371 wine_dbgstr_w(rgelt[i].wszRfc1766),
2372 wine_dbgstr_w(rgelt[i].wszLocaleName));
2377 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2378 IEnumRfc1766 *iface)
2380 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2382 TRACE("%p\n", This);
2388 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2389 IEnumRfc1766 *iface,
2392 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2394 TRACE("%p %u\n", This, celt);
2396 if (celt >= This->total) return S_FALSE;
2402 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2404 fnIEnumRfc1766_QueryInterface,
2405 fnIEnumRfc1766_AddRef,
2406 fnIEnumRfc1766_Release,
2407 fnIEnumRfc1766_Clone,
2408 fnIEnumRfc1766_Next,
2409 fnIEnumRfc1766_Reset,
2413 struct enum_locales_data
2416 DWORD total, allocated;
2419 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2422 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2425 TRACE("%s\n", debugstr_w(locale));
2427 if (data->total >= data->allocated)
2429 data->allocated += 32;
2430 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2431 if (!data->info) return FALSE;
2434 info = &data->info[data->total];
2436 info->lcid = strtolW(locale, &end, 16);
2437 if (*end) /* invalid number */
2440 info->wszRfc1766[0] = 0;
2441 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2443 info->wszLocaleName[0] = 0;
2444 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2445 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2452 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2454 EnumRfc1766_impl *rfc;
2455 struct enum_locales_data data;
2457 TRACE("%04x, %p\n", LangId, ppEnum);
2459 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2460 rfc->vtbl_IEnumRfc1766 = &IEnumRfc1766_vtbl;
2466 data.allocated = 32;
2467 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2470 HeapFree(GetProcessHeap(), 0, rfc);
2474 TlsSetValue(MLANG_tls_index, &data);
2475 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2476 TlsSetValue(MLANG_tls_index, NULL);
2478 TRACE("enumerated %d rfc1766 structures\n", data.total);
2482 HeapFree(GetProcessHeap(), 0, data.info);
2483 HeapFree(GetProcessHeap(), 0, rfc);
2487 rfc->info = data.info;
2488 rfc->total = data.total;
2490 *ppEnum = (IEnumRfc1766 *)rfc;
2494 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2495 IMultiLanguage *iface,
2496 IEnumRfc1766 **ppEnumRfc1766)
2498 MLang_impl *This = impl_from_IMultiLanguage( iface );
2500 TRACE("%p %p\n", This, ppEnumRfc1766);
2502 return EnumRfc1766_create(0, ppEnumRfc1766);
2505 /******************************************************************************/
2507 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2508 IMultiLanguage* iface,
2510 PRFC1766INFO pRfc1766Info)
2516 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2517 IMultiLanguage* iface,
2521 IMLangConvertCharset** ppMLangConvertCharset)
2527 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2529 fnIMultiLanguage_QueryInterface,
2530 fnIMultiLanguage_AddRef,
2531 fnIMultiLanguage_Release,
2532 fnIMultiLanguage_GetNumberOfCodePageInfo,
2533 fnIMultiLanguage_GetCodePageInfo,
2534 fnIMultiLanguage_GetFamilyCodePage,
2535 fnIMultiLanguage_EnumCodePages,
2536 fnIMultiLanguage_GetCharsetInfo,
2537 fnIMultiLanguage_IsConvertible,
2538 fnIMultiLanguage_ConvertString,
2539 fnIMultiLanguage_ConvertStringToUnicode,
2540 fnIMultiLanguage_ConvertStringFromUnicode,
2541 fnIMultiLanguage_ConvertStringReset,
2542 fnIMultiLanguage_GetRfc1766FromLcid,
2543 fnIMultiLanguage_GetLcidFromRfc1766,
2544 fnIMultiLanguage_EnumRfc1766,
2545 fnIMultiLanguage_GetRfc1766Info,
2546 fnIMultiLanguage_CreateConvertCharset,
2550 /******************************************************************************/
2552 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2554 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage3 );
2557 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
2558 IMultiLanguage3* iface,
2562 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2563 return MLang_QueryInterface( This, riid, ppvObject );
2566 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2568 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2569 return MLang_AddRef( This );
2572 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2574 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2575 return MLang_Release( This );
2578 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2579 IMultiLanguage3* iface,
2582 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2584 TRACE("%p, %p\n", This, pcCodePage);
2586 if (!pcCodePage) return S_FALSE;
2588 *pcCodePage = This->total_cp;
2592 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2596 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2598 mime_cp_info->bGDICharset = csi.ciCharset;
2600 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2602 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2603 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2604 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2605 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2606 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2607 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2608 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2609 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2610 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2611 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2612 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2614 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2615 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2616 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2617 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2619 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2620 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2621 mime_cp_info->uiFamilyCodePage,
2622 wine_dbgstr_w(mime_cp_info->wszDescription),
2623 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2624 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2625 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2626 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2627 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2628 mime_cp_info->bGDICharset);
2631 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2632 IMultiLanguage3* iface,
2635 PMIMECPINFO pCodePageInfo)
2638 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2640 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2642 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2644 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2646 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2648 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2657 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2658 IMultiLanguage3* iface,
2660 UINT* puiFamilyCodePage)
2662 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2665 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2666 IMultiLanguage3* iface,
2669 IEnumCodePage** ppEnumCodePage)
2671 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2673 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2675 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2678 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2679 IMultiLanguage3* iface,
2681 PMIMECSETINFO pCharsetInfo)
2684 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2686 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2688 if (!pCharsetInfo) return E_FAIL;
2690 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2692 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2694 WCHAR csetW[MAX_MIMECSET_NAME];
2696 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2697 if (!lstrcmpiW(Charset, csetW))
2699 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2700 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2701 strcpyW(pCharsetInfo->wszCharset, csetW);
2708 * Since we do not support charsets like iso-2022-jp and do not have
2709 * them in our database as a primary (web_charset) encoding this loop
2710 * does an attempt to 'approximate' charset name by header_charset.
2712 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2714 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2716 WCHAR csetW[MAX_MIMECSET_NAME];
2718 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2719 if (!lstrcmpiW(Charset, csetW))
2721 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2722 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2723 strcpyW(pCharsetInfo->wszCharset, csetW);
2732 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2733 IMultiLanguage3* iface,
2734 DWORD dwSrcEncoding,
2735 DWORD dwDstEncoding)
2737 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2740 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2741 IMultiLanguage3* iface,
2743 DWORD dwSrcEncoding,
2744 DWORD dwDstEncoding,
2750 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2751 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2754 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2755 IMultiLanguage3* iface,
2763 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2764 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2767 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2768 IMultiLanguage3* iface,
2776 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2777 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2780 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2781 IMultiLanguage3* iface)
2787 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2788 IMultiLanguage3* iface,
2792 WCHAR buf[MAX_RFC1766_NAME];
2794 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2796 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2798 *pbstrRfc1766 = SysAllocString( buf );
2804 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2805 IMultiLanguage3* iface,
2810 IEnumRfc1766 *rfc1766;
2812 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2814 if (!pLocale || !bstrRfc1766)
2815 return E_INVALIDARG;
2817 hr = IMultiLanguage2_EnumRfc1766(iface, 0, &rfc1766);
2821 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2823 IEnumRfc1766_Release(rfc1766);
2827 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2828 IMultiLanguage3* iface,
2830 IEnumRfc1766** ppEnumRfc1766)
2832 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2834 TRACE("%p %p\n", This, ppEnumRfc1766);
2836 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2839 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2840 IMultiLanguage3* iface,
2843 PRFC1766INFO pRfc1766Info)
2849 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2850 IMultiLanguage3* iface,
2854 IMLangConvertCharset** ppMLangConvertCharset)
2860 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2861 IMultiLanguage3* iface,
2865 DWORD dwSrcEncoding,
2866 DWORD dwDstEncoding,
2870 char *src, *dst = NULL;
2875 TRACE("%p %0x8 %s %u %u %p %p\n",
2876 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2878 FIXME("dwFlag and lpFallBack not handled\n");
2880 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2881 if (FAILED(hr)) return hr;
2883 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
2884 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
2886 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
2887 if (FAILED(hr)) goto exit;
2889 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
2890 if (FAILED(hr)) goto exit;
2892 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
2897 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
2898 if (FAILED(hr)) goto exit;
2900 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
2903 HeapFree(GetProcessHeap(), 0, src);
2904 HeapFree(GetProcessHeap(), 0, dst);
2909 * TODO: handle dwFlag and lpFallBack
2911 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
2912 IMultiLanguage3* iface,
2923 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2924 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2927 /*****************************************************************************
2928 * MultiLanguage2::ConvertStringToUnicodeEx
2930 * Translates the multibyte string from the specified code page to Unicode.
2933 * see ConvertStringToUnicode
2935 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2936 * instead unconvertible characters.
2940 * S_FALSE The conversion is not supported.
2941 * E_FAIL Some error has occurred.
2943 * TODO: handle dwFlag and lpFallBack
2945 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
2946 IMultiLanguage3* This,
2957 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2958 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2961 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
2962 IMultiLanguage3* iface,
2964 DWORD dwPrefWinCodePage,
2966 DetectEncodingInfo* lpEncoding,
2973 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
2974 IMultiLanguage3* iface,
2976 DWORD dwPrefWinCodePage,
2979 DetectEncodingInfo* lpEncoding,
2986 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
2987 IMultiLanguage3* iface,
2991 return IMultiLanguage2_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
2994 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
2995 IMultiLanguage3* iface,
2998 LPWSTR lpWideCharStr,
3001 /* Find first instance */
3004 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
3005 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3007 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3009 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3011 MultiByteToWideChar(CP_ACP, 0,
3012 mlang_data[i].mime_cp_info[n].description,
3013 -1, lpWideCharStr, cchWideChar);
3022 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
3023 IMultiLanguage3* iface,
3026 FIXME("%u\n", uiCodePage);
3030 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
3031 IMultiLanguage3* iface,
3034 FIXME("0x%08x\n", dwSource);
3038 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
3039 IMultiLanguage3* iface,
3042 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3044 TRACE("%p %p\n", This, pnScripts);
3046 if (!pnScripts) return S_FALSE;
3048 *pnScripts = This->total_scripts;
3052 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
3053 IMultiLanguage3* iface,
3056 IEnumScript** ppEnumScript)
3058 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3060 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3062 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3065 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
3066 IMultiLanguage3* iface,
3069 DWORD dwfIODControl)
3072 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3074 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3076 /* quick check for kernel32 supported code pages */
3077 if (IsValidCodePage(uiCodePage))
3080 /* check for mlang supported code pages */
3081 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3084 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3086 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3091 if (dwfIODControl != CPIOD_PEEK)
3092 FIXME("Request to install codepage language pack not handled\n");
3097 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3098 IMultiLanguage3 *iface,
3100 LPCWSTR lpWideCharStr,
3102 UINT *puiPreferredCodePages,
3103 UINT nPreferredCodePages,
3104 UINT *puiDetectedCodePages,
3105 UINT *pnDetectedCodePages,
3106 WCHAR *lpSpecialChar)
3108 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3110 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3111 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3112 pnDetectedCodePages, lpSpecialChar);
3116 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3117 IMultiLanguage3 *iface,
3120 UINT *puiPreferredCodePages,
3121 UINT nPreferredCodePages,
3122 UINT *puiDetectedCodePages,
3123 UINT *pnDetectedCodePages,
3124 WCHAR *lpSpecialChar)
3126 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3128 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
3129 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3130 pnDetectedCodePages, lpSpecialChar);
3134 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3136 fnIMultiLanguage2_QueryInterface,
3137 fnIMultiLanguage2_AddRef,
3138 fnIMultiLanguage2_Release,
3139 fnIMultiLanguage2_GetNumberOfCodePageInfo,
3140 fnIMultiLanguage2_GetCodePageInfo,
3141 fnIMultiLanguage2_GetFamilyCodePage,
3142 fnIMultiLanguage2_EnumCodePages,
3143 fnIMultiLanguage2_GetCharsetInfo,
3144 fnIMultiLanguage2_IsConvertible,
3145 fnIMultiLanguage2_ConvertString,
3146 fnIMultiLanguage2_ConvertStringToUnicode,
3147 fnIMultiLanguage2_ConvertStringFromUnicode,
3148 fnIMultiLanguage2_ConvertStringReset,
3149 fnIMultiLanguage2_GetRfc1766FromLcid,
3150 fnIMultiLanguage2_GetLcidFromRfc1766,
3151 fnIMultiLanguage2_EnumRfc1766,
3152 fnIMultiLanguage2_GetRfc1766Info,
3153 fnIMultiLanguage2_CreateConvertCharset,
3154 fnIMultiLanguage2_ConvertStringInIStream,
3155 fnIMultiLanguage2_ConvertStringToUnicodeEx,
3156 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
3157 fnIMultiLanguage2_DetectCodepageInIStream,
3158 fnIMultiLanguage2_DetectInputCodepage,
3159 fnIMultiLanguage2_ValidateCodePage,
3160 fnIMultiLanguage2_GetCodePageDescription,
3161 fnIMultiLanguage2_IsCodePageInstallable,
3162 fnIMultiLanguage2_SetMimeDBSource,
3163 fnIMultiLanguage2_GetNumberOfScripts,
3164 fnIMultiLanguage2_EnumScripts,
3165 fnIMultiLanguage2_ValidateCodePageEx,
3166 fnIMultiLanguage3_DetectOutboundCodePage,
3167 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3170 /******************************************************************************/
3172 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3174 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink2 );
3177 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3178 IMLangFontLink2 * iface,
3182 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3183 return MLang_QueryInterface( This, riid, ppvObject );
3186 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3188 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3189 return MLang_AddRef( This );
3192 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3194 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3195 return MLang_Release( This );
3198 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
3199 WCHAR chSrc, DWORD *pdwCodePages)
3201 FIXME("(%p)->%s %p\n",This, debugstr_wn(&chSrc,1),pdwCodePages);
3205 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
3206 const WCHAR *pszSrc, LONG cchSrc, DWORD dwPriorityCodePages,
3207 DWORD *pdwCodePages, LONG *pcchCodePages)
3209 return fnIMLangFontLink_GetStrCodePages((IMLangFontLink *)This,
3210 pszSrc, cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
3213 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
3215 DWORD *pdwCodePages)
3217 FIXME("(%p)->%i %p\n",This, uCodePage, pdwCodePages);
3221 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* This,
3222 DWORD dwCodePages, UINT uDefaultCodePage, UINT *puCodePage)
3224 FIXME("(%p)->%i %i %p\n",This, dwCodePages, uDefaultCodePage, puCodePage);
3228 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2* This,
3229 HDC hDC, HFONT hFont, DWORD *pdwCodePages)
3231 FIXME("(%p)->%p %p %p\n",This, hDC, hFont, pdwCodePages);
3235 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3238 FIXME("(%p)->%p\n",This, hFont);
3242 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3244 FIXME("(%p)->\n",This);
3248 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3249 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3251 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
3255 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3256 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3258 FIXME("(%p)->%p %p %p\n",This, hDC, puiRanges, pUranges);
3262 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3263 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3264 SCRIPTFONTINFO *pScriptFont)
3268 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3270 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3272 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3274 if (sid == mlang_data[i].sid)
3278 if (j >= *puiFonts) break;
3280 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3281 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3283 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3284 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3286 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3288 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3289 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3299 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3300 UINT uiCodePage, SCRIPT_ID *pSid)
3302 FIXME("(%p)->%i %p\n",This, uiCodePage, pSid);
3306 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3308 fnIMLangFontLink2_QueryInterface,
3309 fnIMLangFontLink2_AddRef,
3310 fnIMLangFontLink2_Release,
3311 fnIMLangFontLink2_GetCharCodePages,
3312 fnIMLangFontLink2_GetStrCodePages,
3313 fnIMLangFontLink2_CodePageToCodePages,
3314 fnIMLangFontLink2_CodePagesToCodePage,
3315 fnIMLangFontLink2_GetFontCodePages,
3316 fnIMLangFontLink2_ReleaseFont,
3317 fnIMLangFontLink2_ResetFontMapping,
3318 fnIMLangFontLink2_MapFont,
3319 fnIMLangFontLink2_GetFontUnicodeRanges,
3320 fnIMLangFontLink2_GetScriptFontInfo,
3321 fnIMLangFontLink2_CodePageToScriptID
3324 /******************************************************************************/
3326 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3328 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangLineBreakConsole );
3331 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3332 IMLangLineBreakConsole* iface,
3336 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3337 return MLang_QueryInterface( This, riid, ppvObject );
3340 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3341 IMLangLineBreakConsole* iface )
3343 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3344 return MLang_AddRef( This );
3347 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3348 IMLangLineBreakConsole* iface )
3350 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3351 return MLang_Release( This );
3354 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3355 IMLangLineBreakConsole* iface,
3356 IMLangString* pSrcMLStr,
3364 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3368 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3369 IMLangLineBreakConsole* iface,
3371 const WCHAR* pszSrc,
3377 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3384 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3385 IMLangLineBreakConsole* iface,
3394 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3401 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3403 fnIMLangLineBreakConsole_QueryInterface,
3404 fnIMLangLineBreakConsole_AddRef,
3405 fnIMLangLineBreakConsole_Release,
3406 fnIMLangLineBreakConsole_BreakLineML,
3407 fnIMLangLineBreakConsole_BreakLineW,
3408 fnIMLangLineBreakConsole_BreakLineA
3411 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3416 TRACE("Creating MultiLanguage object\n");
3419 return CLASS_E_NOAGGREGATION;
3421 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3422 mlang->vtbl_IMLangFontLink = &IMLangFontLink_vtbl;
3423 mlang->vtbl_IMultiLanguage = &IMultiLanguage_vtbl;
3424 mlang->vtbl_IMultiLanguage3 = &IMultiLanguage3_vtbl;
3425 mlang->vtbl_IMLangFontLink2 = &IMLangFontLink2_vtbl;
3426 mlang->vtbl_IMLangLineBreakConsole = &IMLangLineBreakConsole_vtbl;
3428 mlang->total_cp = 0;
3429 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3430 mlang->total_cp += mlang_data[i].number_of_cp;
3432 /* do not enumerate unicode flavours */
3433 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3437 TRACE("returning %p\n", mlang);
3444 /******************************************************************************/
3446 HRESULT WINAPI DllCanUnloadNow(void)
3448 return dll_count == 0 ? S_OK : S_FALSE;
3451 HRESULT WINAPI GetGlobalFontLinkObject(void)