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
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
47 #define CP_UNICODE 1200
49 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
50 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
52 static HINSTANCE instance;
53 static DWORD MLANG_tls_index; /* to store various per thead data */
56 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
57 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
62 const char *description;
65 const char *web_charset;
66 const char *header_charset;
67 const char *body_charset;
70 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
71 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
73 static const MIME_CP_INFO arabic_cp[] =
76 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
77 MIMECONTF_MIME_LATEST,
78 "ibm864", "ibm864", "ibm864" },
80 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
81 MIMECONTF_MIME_LATEST,
82 "ibm1006", "ibm1006", "ibm1006" },
84 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
85 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
86 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
87 "windows-1256", "windows-1256", "windows-1256" },
89 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
90 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
91 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
92 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
93 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
95 static const MIME_CP_INFO baltic_cp[] =
98 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
99 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
100 "ibm775", "ibm775", "ibm775" },
101 { "Baltic (Windows)",
102 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
103 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
104 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
105 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
106 "windows-1257", "windows-1257", "windows-1257" },
108 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
109 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
110 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
111 MIMECONTF_MIME_LATEST,
112 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
114 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
115 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
116 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
118 static const MIME_CP_INFO chinese_simplified_cp[] =
120 { "Chinese Simplified (GB2312)",
121 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
122 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
123 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
124 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
125 "gb2312", "gb2312", "gb2312" }
127 static const MIME_CP_INFO chinese_traditional_cp[] =
129 { "Chinese Traditional (Big5)",
130 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
131 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
132 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
133 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
134 "big5", "big5", "big5" }
136 static const MIME_CP_INFO central_european_cp[] =
138 { "Central European (DOS)",
139 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
140 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
141 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
142 "ibm852", "ibm852", "ibm852" },
143 { "Central European (Windows)",
144 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
145 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
146 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
147 MIMECONTF_MIME_LATEST,
148 "windows-1250", "windows-1250", "windows-1250" },
149 { "Central European (Mac)",
150 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
151 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
152 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
153 { "Central European (ISO)",
154 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
155 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
156 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
157 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
158 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
160 static const MIME_CP_INFO cyrillic_cp[] =
163 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
164 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
165 "ibm855", "ibm855", "ibm855" },
167 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
168 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
169 MIMECONTF_MIME_LATEST,
170 "cp866", "cp866", "cp866" },
171 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
172 { "Cyrillic (KOI8-R)",
173 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
174 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
175 "koi8-r", "koi8-r", "koi8-r" },
177 { "Cyrillic (Windows)",
178 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
179 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
180 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
181 "windows-1251", "windows-1251", "windows-1251" },
183 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
184 MIMECONTF_MIME_LATEST,
185 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
186 { "Cyrillic (KOI8-R)",
187 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
188 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
189 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
190 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
191 "koi8-r", "koi8-r", "koi8-r" },
192 { "Cyrillic (KOI8-U)",
193 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
194 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
195 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
196 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
197 "koi8-u", "koi8-u", "koi8-u" },
199 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
200 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
201 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
202 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
203 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
205 static const MIME_CP_INFO greek_cp[] =
208 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
209 MIMECONTF_MIME_LATEST,
210 "ibm737", "ibm737", "ibm737" },
211 { "Greek, Modern (DOS)",
212 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
213 MIMECONTF_MIME_LATEST,
214 "ibm869", "ibm869", "ibm869" },
215 { "IBM EBCDIC (Greek Modern)",
216 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
217 MIMECONTF_MIME_LATEST,
218 "cp875", "cp875", "cp875" },
220 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
221 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
222 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
223 "windows-1253", "windows-1253", "windows-1253" },
225 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
226 MIMECONTF_MIME_LATEST,
227 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
229 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
230 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
231 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
232 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
233 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
235 static const MIME_CP_INFO hebrew_cp[] =
238 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
239 MIMECONTF_MIME_LATEST,
240 "ibm424", "ibm424", "ibm424" },
242 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
243 MIMECONTF_MIME_LATEST,
244 "cp856", "cp856", "cp856" },
246 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
247 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
248 MIMECONTF_MIME_LATEST,
249 "dos-862", "dos-862", "dos-862" },
250 { "Hebrew (Windows)",
251 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
252 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
253 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
254 "windows-1255", "windows-1255", "windows-1255" },
255 { "Hebrew (ISO-Visual)",
256 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
257 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
258 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
259 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
261 static const MIME_CP_INFO japanese_cp[] =
263 { "Japanese (Auto-Select)",
264 50932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
265 MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
266 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
267 "_autodetect", "_autodetect", "_autodetect" },
269 51932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
270 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
271 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
272 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
273 "euc-jp", "euc-jp", "euc-jp" },
275 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
276 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
277 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
279 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
280 { "Japanese (JIS 0208-1990 and 0212-1990)",
281 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
282 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
283 "EUC-JP","EUC-JP","EUC-JP"},
284 { "Japanese (JIS-Allow 1 byte Kana)",
285 50221, MIMECONTF_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_SAVABLE_BROWSER |
286 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
287 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
288 "csISO2022JP","iso-2022-jp","iso-2022-jp"},
289 { "Japanese (JIS-Allow 1 byte Kana - SO/SI)",
290 50222, MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_VALID |
291 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
292 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
294 10001, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
295 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
296 "x-mac-japanese","x-mac-japanese","x-mac-japanese"},
297 { "Japanese (Shift-JIS)",
298 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
299 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
300 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
301 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
302 "shift_jis", "iso-2022-jp", "iso-2022-jp" }
304 static const MIME_CP_INFO korean_cp[] =
307 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
308 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
309 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
310 MIMECONTF_MIME_LATEST,
311 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
313 static const MIME_CP_INFO thai_cp[] =
316 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
317 "ibm-thai", "ibm-thai", "ibm-thai" }
319 static const MIME_CP_INFO turkish_cp[] =
322 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
323 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
324 "ibm857", "ibm857", "ibm857" },
325 { "IBM EBCDIC (Turkish Latin-5)",
326 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
327 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
328 "ibm1026", "ibm1026", "ibm1026" },
329 { "Turkish (Windows)",
330 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
331 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
332 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
333 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
334 "windows-1254", "windows-1254", "windows-1254" },
336 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
337 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
338 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
340 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
341 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
342 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
343 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
345 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
346 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
347 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
348 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
349 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
351 static const MIME_CP_INFO vietnamese_cp[] =
353 { "Vietnamese (Windows)",
354 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
355 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
356 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
357 MIMECONTF_MIME_LATEST,
358 "windows-1258", "windows-1258", "windows-1258" }
360 static const MIME_CP_INFO western_cp[] =
362 { "IBM EBCDIC (US-Canada)",
363 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
364 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
365 "ibm037", "ibm037", "ibm037" },
366 { "OEM United States",
367 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
368 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
369 "ibm437", "ibm437", "ibm437" },
370 { "IBM EBCDIC (International)",
371 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
372 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
373 "ibm500", "ibm500", "ibm500" },
374 { "Western European (DOS)",
375 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
376 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
377 "ibm850", "ibm850", "ibm850" },
378 { "Portuguese (DOS)",
379 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
380 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
381 "ibm860", "ibm860", "ibm860" },
383 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
384 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
385 "ibm861", "ibm861", "ibm861" },
386 { "French Canadian (DOS)",
387 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
388 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
389 "ibm863", "ibm863", "ibm863" },
391 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
392 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
393 "ibm865", "ibm865", "ibm865" },
394 { "Western European (Windows)",
395 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
396 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
397 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
398 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
399 "windows-1252", "windows-1252", "iso-8859-1" },
400 { "Western European (Mac)",
401 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
402 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
403 "macintosh", "macintosh", "macintosh" },
405 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
406 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
407 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
409 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
410 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
411 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
412 "us-ascii", "us-ascii", "us-ascii" },
413 { "Western European (ISO)",
414 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
415 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
416 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
417 MIMECONTF_MIME_LATEST,
418 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
420 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
421 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
422 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
423 MIMECONTF_MIME_LATEST,
424 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
426 static const MIME_CP_INFO unicode_cp[] =
429 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
430 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
431 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
432 MIMECONTF_MIME_LATEST,
433 "unicode", "unicode", "unicode" },
435 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
436 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
437 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
438 "utf-7", "utf-7", "utf-7" },
440 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
441 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
442 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
443 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
444 "utf-8", "utf-8", "utf-8" }
447 static const struct mlang_data
449 const char *description;
450 UINT family_codepage;
452 const MIME_CP_INFO *mime_cp_info;
453 const char *fixed_font;
454 const char *proportional_font;
458 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
459 "Courier","Arial", sidArabic }, /* FIXME */
460 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
461 "Courier","Arial", sidAsciiLatin }, /* FIXME */
462 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
463 "Courier","Arial", sidHan }, /* FIXME */
464 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
465 "Courier","Arial", sidBopomofo }, /* FIXME */
466 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
467 "Courier","Arial", sidAsciiLatin }, /* FIXME */
468 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
469 "Courier","Arial", sidCyrillic }, /* FIXME */
470 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
471 "Courier","Arial", sidGreek }, /* FIXME */
472 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
473 "Courier","Arial", sidHebrew }, /* FIXME */
474 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
475 "MS Gothic","MS PGothic", sidKana },
476 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
477 "Courier","Arial", sidHangul }, /* FIXME */
478 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
479 "Courier","Arial", sidThai }, /* FIXME */
480 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
481 "Courier","Arial", sidAsciiLatin }, /* FIXME */
482 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
483 "Courier","Arial", sidAsciiLatin }, /* FIXME */
484 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
485 "Courier","Arial", sidAsciiLatin }, /* FIXME */
486 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
487 "Courier","Arial" } /* FIXME */
490 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
492 static LONG dll_count;
495 * Japanese Detection and Converstion Functions
498 #define HANKATA(A) ((A >= 161) && (A <= 223))
499 #define ISEUC(A) ((A >= 161) && (A <= 254))
500 #define NOTEUC(A,B) (((A >= 129) && (A <= 159)) && ((B >= 64) && (B <= 160)))
501 #define SJIS1(A) (((A >= 129) && (A <= 159)) || ((A >= 224) && (A <= 239)))
502 #define SJIS2(A) ((A >= 64) && (A <= 252))
503 #define ISMARU(A) ((A >= 202) && (A <= 206))
504 #define ISNIGORI(A) (((A >= 182) && (A <= 196)) || ((A >= 202) && (A <= 206)))
506 static UINT DetectJapaneseCode(LPCSTR input, DWORD count)
512 while ((code == 0 || code == 51932) && i < count)
515 if (c1 == 0x1b /* ESC */)
527 if (c1 =='B' || c1 == '@')
541 else if (ISEUC(c1) && ISEUC(c2))
543 else if (((c1 == 142)) && HANKATA(c2))
551 static inline void jis2sjis(unsigned char *p1, unsigned char *p2)
553 unsigned char c1 = *p1;
554 unsigned char c2 = *p2;
555 int row = c1 < 95 ? 112 : 176;
556 int cell = c1 % 2 ? 31 + (c2 > 95) : 126;
558 *p1 = ((c1 + 1) >> 1) + row;
562 static inline void sjis2jis(unsigned char *p1, unsigned char *p2)
564 unsigned char c1 = *p1;
565 unsigned char c2 = *p2;
566 int shift = c2 < 159;
567 int row = c1 < 160 ? 112 : 176;
568 int cell = shift ? (31 + (c2 > 127)): 126;
570 *p1 = ((c1 - row) << 1) - shift;
574 static int han2zen(unsigned char *p1, unsigned char *p2)
578 static const unsigned char char1[] = {129,129,129,129,129,131,131,131,131,
579 131,131,131,131,131,131,129,131,131,131,131,131,131,131,131,131,131,
580 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
581 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
583 static const unsigned char char2[] = {66,117,118,65,69,146,64,66,68,70,
584 72,131,133,135,98,91,65,67,69,71,73,74,76,78,80,82,84,86,88,90,92,94,
585 96,99,101,103,105,106,107,108,109,110,113,116,119,122,125,126,128,
586 129,130,132,134,136,137,138,139,140,141,143,147,74,75};
588 if (( *p2 == 222) && ((ISNIGORI(*p1) || (*p1 == 179))))
590 else if ((*p2 == 223) && (ISMARU(*p1)))
593 if (*p1 >= 161 && *p1 <= 223)
595 unsigned char index = *p1 - 161;
604 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
606 else if ((*p1 == 131) && (*p2 == 69))
609 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
619 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
629 if (p == 0x1b /* ESC */)
635 if (p2 == '$' || p2 =='(')
637 if (p2 == 'K' || p2 =='$')
664 static inline int exit_shift(LPSTR out, int c)
675 static inline int enter_shift(LPSTR out, int c)
687 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
697 if (p == 10 || p == 13) /* NL and CR */
702 j += exit_shift(output,j);
716 p2 = input[i] & 0xff;
723 j+=enter_shift(output,j);
741 p2 = input[i+1] & 0xff;
747 j+=enter_shift(output,j);
762 j += exit_shift(output,j);
774 j += exit_shift(output,j);
778 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
779 LPWSTR output, DWORD out_count)
783 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
784 rc = ConvertJIS2SJIS(input,count,sjis_string);
787 TRACE("%s\n",debugstr_an(sjis_string,rc));
789 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
791 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
793 HeapFree(GetProcessHeap(),0,sjis_string);
798 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
799 LPWSTR output, DWORD out_count)
803 int code = DetectJapaneseCode(input,count);
804 TRACE("Japanese code %i\n",code);
810 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
812 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
817 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
819 rc = MultiByteToWideChar(932,0,input,count,0,0);
824 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
826 rc = MultiByteToWideChar(20932,0,input,count,0,0);
830 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
831 rc = ConvertJIS2SJIS(input,count,sjis_string);
834 TRACE("%s\n",debugstr_an(sjis_string,rc));
836 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
838 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
840 HeapFree(GetProcessHeap(),0,sjis_string);
846 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
847 LPSTR output, DWORD out_count)
853 len = WideCharToMultiByte(932,0,input,count,0,0,NULL,NULL);
854 sjis_string = HeapAlloc(GetProcessHeap(),0,len);
855 WideCharToMultiByte(932,0,input,count,sjis_string,len,NULL,NULL);
856 TRACE("%s\n",debugstr_an(sjis_string,len));
858 rc = ConvertSJIS2JIS(sjis_string, len, NULL);
861 ConvertSJIS2JIS(sjis_string, len, output);
863 HeapFree(GetProcessHeap(),0,sjis_string);
869 * Dll lifetime tracking declaration
871 static void LockModule(void)
873 InterlockedIncrement(&dll_count);
876 static void UnlockModule(void)
878 InterlockedDecrement(&dll_count);
881 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
884 case DLL_PROCESS_ATTACH:
886 MLANG_tls_index = TlsAlloc();
887 DisableThreadLibraryCalls(hInstDLL);
889 case DLL_PROCESS_DETACH:
890 TlsFree(MLANG_tls_index);
896 HRESULT WINAPI ConvertINetMultiByteToUnicode(
906 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
907 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
913 pcSrcSize = &src_len;
921 /* forwarding euc-jp to EUC-JP */
922 if (dwEncoding == 51932)
928 if (*pcSrcSize == -1)
929 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
930 *pcDstSize = min(*pcSrcSize, *pcDstSize);
931 *pcSrcSize *= sizeof(WCHAR);
933 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
939 *pcDstSize = ConvertJISJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
942 *pcDstSize = ConvertUnknownJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
946 if (*pcSrcSize == -1)
947 *pcSrcSize = lstrlenA(pSrcStr);
950 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
952 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
962 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
973 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
974 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
980 pcSrcSize = &src_len;
982 destsz = (pDstStr) ? *pcDstSize : 0;
985 if (!pSrcStr || !*pcSrcSize)
988 if (*pcSrcSize == -1)
989 *pcSrcSize = lstrlenW(pSrcStr);
991 /* forwarding euc-jp to EUC-JP */
992 if (dwEncoding == 51932)
995 if (dwEncoding == CP_UNICODE)
997 if (*pcSrcSize == -1)
998 *pcSrcSize = lstrlenW(pSrcStr);
1000 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
1002 memmove(pDstStr, pSrcStr, size);
1007 else if (dwEncoding == 50220 || dwEncoding == 50221 || dwEncoding == 50222)
1009 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, NULL, 0);
1015 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, pDstStr,
1024 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1025 NULL, 0, NULL, NULL);
1031 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1032 pDstStr, destsz, NULL, NULL);
1047 HRESULT WINAPI ConvertINetString(
1049 DWORD dwSrcEncoding,
1050 DWORD dwDstEncoding,
1057 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
1058 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1060 if (dwSrcEncoding == CP_UNICODE)
1063 if (pcSrcSize && *pcSrcSize != -1)
1065 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
1066 pcSrcSize = &cSrcSizeW;
1068 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
1070 else if (dwDstEncoding == CP_UNICODE)
1072 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
1073 *pcDstSize *= sizeof(WCHAR);
1082 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
1084 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
1088 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
1089 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
1091 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
1093 HeapFree(GetProcessHeap(), 0, pDstStrW);
1098 static HRESULT GetFamilyCodePage(
1100 UINT* puiFamilyCodePage)
1104 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
1106 if (!puiFamilyCodePage) return S_FALSE;
1108 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1110 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1112 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1114 *puiFamilyCodePage = mlang_data[i].family_codepage;
1123 HRESULT WINAPI IsConvertINetStringAvailable(
1124 DWORD dwSrcEncoding,
1125 DWORD dwDstEncoding)
1127 UINT src_family, dst_family;
1129 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
1131 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
1132 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
1135 if (src_family == dst_family) return S_OK;
1137 /* we can convert any codepage to/from unicode */
1138 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
1143 static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
1145 CHAR buffer[MAX_RFC1766_NAME];
1146 INT n = GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1151 i = PRIMARYLANGID(lcid);
1152 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1153 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1154 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1156 buffer[n - 1] = '-';
1157 i = GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1159 buffer[n - 1] = '\0';
1164 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len );
1165 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1170 static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
1172 WCHAR buffer[MAX_RFC1766_NAME];
1173 INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1178 i = PRIMARYLANGID(lcid);
1179 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1180 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1181 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1183 buffer[n - 1] = '-';
1184 i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1186 buffer[n - 1] = '\0';
1191 LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
1192 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1197 HRESULT WINAPI LcidToRfc1766A(
1202 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1204 return E_INVALIDARG;
1206 return lcid_to_rfc1766A(lcid, pszRfc1766, nChar);
1209 HRESULT WINAPI LcidToRfc1766W(
1214 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1216 return E_INVALIDARG;
1218 return lcid_to_rfc1766W(lcid, pszRfc1766, nChar);
1221 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
1226 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
1228 if (!strcmpiW(info.wszRfc1766, rfc1766))
1233 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
1235 *lcid = PRIMARYLANGID(info.lcid);
1243 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
1245 IEnumRfc1766 *enumrfc1766;
1248 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
1250 if (!pLocale || !pszRfc1766)
1251 return E_INVALIDARG;
1253 hr = EnumRfc1766_create(0, &enumrfc1766);
1257 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
1258 IEnumRfc1766_Release(enumrfc1766);
1263 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
1265 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1268 return E_INVALIDARG;
1270 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
1271 rfc1766W[MAX_RFC1766_NAME] = 0;
1273 return Rfc1766ToLcidW(lcid, rfc1766W);
1276 /******************************************************************************
1277 * MLANG ClassFactory
1280 IClassFactory ITF_IClassFactory;
1283 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1284 } IClassFactoryImpl;
1286 struct object_creation_info
1290 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1293 static const struct object_creation_info object_creation[] =
1295 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
1298 static HRESULT WINAPI
1299 MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1301 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1303 TRACE("%s\n", debugstr_guid(riid) );
1305 if (IsEqualGUID(riid, &IID_IUnknown)
1306 || IsEqualGUID(riid, &IID_IClassFactory))
1308 IClassFactory_AddRef(iface);
1313 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
1314 return E_NOINTERFACE;
1317 static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
1319 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1320 return InterlockedIncrement(&This->ref);
1323 static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
1325 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1327 ULONG ref = InterlockedDecrement(&This->ref);
1331 TRACE("Destroying %p\n", This);
1332 HeapFree(GetProcessHeap(), 0, This);
1338 static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
1339 REFIID riid, LPVOID *ppobj)
1341 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
1345 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1348 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
1349 if (SUCCEEDED(hres)) {
1350 hres = IUnknown_QueryInterface(punk, riid, ppobj);
1351 IUnknown_Release(punk);
1353 TRACE("returning (%p) -> %x\n", *ppobj, hres);
1357 static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1367 static const IClassFactoryVtbl MLANGCF_Vtbl =
1369 MLANGCF_QueryInterface,
1372 MLANGCF_CreateInstance,
1376 /******************************************************************
1377 * DllGetClassObject (MLANG.@)
1379 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
1382 IClassFactoryImpl *factory;
1384 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
1386 if ( !IsEqualGUID( &IID_IClassFactory, iid )
1387 && ! IsEqualGUID( &IID_IUnknown, iid) )
1388 return E_NOINTERFACE;
1390 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
1392 if (IsEqualGUID(object_creation[i].clsid, rclsid))
1396 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
1398 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
1399 return CLASS_E_CLASSNOTAVAILABLE;
1402 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
1404 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
1405 if (factory == NULL) return E_OUTOFMEMORY;
1407 factory->ITF_IClassFactory.lpVtbl = &MLANGCF_Vtbl;
1410 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
1412 *ppv = &(factory->ITF_IClassFactory);
1414 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
1420 /******************************************************************************/
1422 typedef struct tagMLang_impl
1424 const IMLangFontLinkVtbl *vtbl_IMLangFontLink;
1425 const IMultiLanguageVtbl *vtbl_IMultiLanguage;
1426 const IMultiLanguage3Vtbl *vtbl_IMultiLanguage3;
1427 const IMLangFontLink2Vtbl *vtbl_IMLangFontLink2;
1428 const IMLangLineBreakConsoleVtbl *vtbl_IMLangLineBreakConsole;
1430 DWORD total_cp, total_scripts;
1433 static ULONG MLang_AddRef( MLang_impl* This)
1435 return InterlockedIncrement(&This->ref);
1438 static ULONG MLang_Release( MLang_impl* This )
1440 ULONG ref = InterlockedDecrement(&This->ref);
1442 TRACE("%p ref = %d\n", This, ref);
1445 TRACE("Destroying %p\n", This);
1446 HeapFree(GetProcessHeap(), 0, This);
1453 static HRESULT MLang_QueryInterface(
1458 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1460 if (IsEqualGUID(riid, &IID_IUnknown)
1461 || IsEqualGUID(riid, &IID_IMLangCodePages)
1462 || IsEqualGUID(riid, &IID_IMLangFontLink))
1465 TRACE("Returning IID_IMLangFontLink %p ref = %d\n", This, This->ref);
1466 *ppvObject = &(This->vtbl_IMLangFontLink);
1470 if (IsEqualGUID(riid, &IID_IMLangFontLink2))
1473 TRACE("Returning IID_IMLangFontLink2 %p ref = %d\n", This, This->ref);
1474 *ppvObject = &(This->vtbl_IMLangFontLink2);
1478 if (IsEqualGUID(riid, &IID_IMultiLanguage) )
1481 TRACE("Returning IID_IMultiLanguage %p ref = %d\n", This, This->ref);
1482 *ppvObject = &(This->vtbl_IMultiLanguage);
1486 if (IsEqualGUID(riid, &IID_IMultiLanguage2) )
1489 *ppvObject = &(This->vtbl_IMultiLanguage3);
1490 TRACE("Returning IID_IMultiLanguage2 %p ref = %d\n", This, This->ref);
1494 if (IsEqualGUID(riid, &IID_IMultiLanguage3) )
1497 *ppvObject = &(This->vtbl_IMultiLanguage3);
1498 TRACE("Returning IID_IMultiLanguage3 %p ref = %d\n", This, This->ref);
1502 if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
1505 TRACE("Returning IID_IMLangLineBreakConsole %p ref = %d\n", This, This->ref);
1506 *ppvObject = &(This->vtbl_IMLangLineBreakConsole);
1511 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1512 return E_NOINTERFACE;
1515 /******************************************************************************/
1517 typedef struct tagEnumCodePage_impl
1519 const IEnumCodePageVtbl *vtbl_IEnumCodePage;
1523 } EnumCodePage_impl;
1525 static inline EnumCodePage_impl *impl_from_IEnumCodePage( IEnumCodePage *iface )
1527 return CONTAINING_RECORD( iface, EnumCodePage_impl, vtbl_IEnumCodePage );
1530 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1531 IEnumCodePage* iface,
1535 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1537 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1539 if (IsEqualGUID(riid, &IID_IUnknown)
1540 || IsEqualGUID(riid, &IID_IEnumCodePage))
1542 IEnumCodePage_AddRef(iface);
1543 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1544 *ppvObject = &(This->vtbl_IEnumCodePage);
1548 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1549 return E_NOINTERFACE;
1552 static ULONG WINAPI fnIEnumCodePage_AddRef(
1553 IEnumCodePage* iface)
1555 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1556 return InterlockedIncrement(&This->ref);
1559 static ULONG WINAPI fnIEnumCodePage_Release(
1560 IEnumCodePage* iface)
1562 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1563 ULONG ref = InterlockedDecrement(&This->ref);
1565 TRACE("%p ref = %d\n", This, ref);
1568 TRACE("Destroying %p\n", This);
1569 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1570 HeapFree(GetProcessHeap(), 0, This);
1576 static HRESULT WINAPI fnIEnumCodePage_Clone(
1577 IEnumCodePage* iface,
1578 IEnumCodePage** ppEnum)
1580 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1581 FIXME("%p %p\n", This, ppEnum);
1585 static HRESULT WINAPI fnIEnumCodePage_Next(
1586 IEnumCodePage* iface,
1589 ULONG* pceltFetched)
1592 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1594 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1596 if (!pceltFetched) return S_FALSE;
1599 if (!rgelt) return S_FALSE;
1601 if (This->pos + celt > This->total)
1602 celt = This->total - This->pos;
1604 if (!celt) return S_FALSE;
1606 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1607 *pceltFetched = celt;
1610 for (i = 0; i < celt; i++)
1612 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1613 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1614 rgelt[i].uiFamilyCodePage,
1615 wine_dbgstr_w(rgelt[i].wszDescription),
1616 wine_dbgstr_w(rgelt[i].wszWebCharset),
1617 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1618 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1619 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1620 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1621 rgelt[i].bGDICharset);
1626 static HRESULT WINAPI fnIEnumCodePage_Reset(
1627 IEnumCodePage* iface)
1629 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1631 TRACE("%p\n", This);
1637 static HRESULT WINAPI fnIEnumCodePage_Skip(
1638 IEnumCodePage* iface,
1641 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1643 TRACE("%p %u\n", This, celt);
1645 if (celt >= This->total) return S_FALSE;
1651 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1653 fnIEnumCodePage_QueryInterface,
1654 fnIEnumCodePage_AddRef,
1655 fnIEnumCodePage_Release,
1656 fnIEnumCodePage_Clone,
1657 fnIEnumCodePage_Next,
1658 fnIEnumCodePage_Reset,
1659 fnIEnumCodePage_Skip
1662 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1663 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1665 EnumCodePage_impl *ecp;
1669 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1671 if (!grfFlags) /* enumerate internal data base of encodings */
1672 grfFlags = MIMECONTF_MIME_LATEST;
1674 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1675 ecp->vtbl_IEnumCodePage = &IEnumCodePage_vtbl;
1679 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1681 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1683 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1688 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1689 sizeof(MIMECPINFO) * ecp->total);
1690 cpinfo = ecp->cpinfo;
1692 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1694 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1696 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1697 fill_cp_info(&mlang_data[i], n, cpinfo++);
1701 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1703 *ppEnumCodePage = (IEnumCodePage*) ecp;
1708 /******************************************************************************/
1710 typedef struct tagEnumScript_impl
1712 const IEnumScriptVtbl *vtbl_IEnumScript;
1714 SCRIPTINFO *script_info;
1718 static inline EnumScript_impl *impl_from_IEnumScript( IEnumScript *iface )
1720 return CONTAINING_RECORD( iface, EnumScript_impl, vtbl_IEnumScript );
1723 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1728 EnumScript_impl *This = impl_from_IEnumScript( iface );
1730 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1732 if (IsEqualGUID(riid, &IID_IUnknown)
1733 || IsEqualGUID(riid, &IID_IEnumScript))
1735 IEnumScript_AddRef(iface);
1736 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1737 *ppvObject = &(This->vtbl_IEnumScript);
1741 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1742 return E_NOINTERFACE;
1745 static ULONG WINAPI fnIEnumScript_AddRef(
1748 EnumScript_impl *This = impl_from_IEnumScript( iface );
1749 return InterlockedIncrement(&This->ref);
1752 static ULONG WINAPI fnIEnumScript_Release(
1755 EnumScript_impl *This = impl_from_IEnumScript( iface );
1756 ULONG ref = InterlockedDecrement(&This->ref);
1758 TRACE("%p ref = %d\n", This, ref);
1761 TRACE("Destroying %p\n", This);
1762 HeapFree(GetProcessHeap(), 0, This->script_info);
1763 HeapFree(GetProcessHeap(), 0, This);
1769 static HRESULT WINAPI fnIEnumScript_Clone(
1771 IEnumScript** ppEnum)
1773 EnumScript_impl *This = impl_from_IEnumScript( iface );
1774 FIXME("%p %p: stub!\n", This, ppEnum);
1778 static HRESULT WINAPI fnIEnumScript_Next(
1782 ULONG* pceltFetched)
1784 EnumScript_impl *This = impl_from_IEnumScript( iface );
1786 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1788 if (!pceltFetched || !rgelt) return E_FAIL;
1792 if (This->pos + celt > This->total)
1793 celt = This->total - This->pos;
1795 if (!celt) return S_FALSE;
1797 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1798 *pceltFetched = celt;
1804 static HRESULT WINAPI fnIEnumScript_Reset(
1807 EnumScript_impl *This = impl_from_IEnumScript( iface );
1809 TRACE("%p\n", This);
1815 static HRESULT WINAPI fnIEnumScript_Skip(
1819 EnumScript_impl *This = impl_from_IEnumScript( iface );
1821 TRACE("%p %u\n", This, celt);
1823 if (celt >= This->total) return S_FALSE;
1829 static const IEnumScriptVtbl IEnumScript_vtbl =
1831 fnIEnumScript_QueryInterface,
1832 fnIEnumScript_AddRef,
1833 fnIEnumScript_Release,
1834 fnIEnumScript_Clone,
1836 fnIEnumScript_Reset,
1840 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1841 LANGID LangId, IEnumScript** ppEnumScript )
1843 EnumScript_impl *es;
1846 TRACE("%p, %08x, %04x, %p: stub!\n", mlang, dwFlags, LangId, ppEnumScript);
1848 if (!dwFlags) /* enumerate all available scripts */
1849 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1851 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1852 es->vtbl_IEnumScript = &IEnumScript_vtbl;
1855 /* do not enumerate unicode flavours */
1856 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1857 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1859 for (i = 0; i < es->total; i++)
1861 es->script_info[i].ScriptId = i;
1862 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1863 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1864 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1865 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1866 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1867 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1868 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1871 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1873 *ppEnumScript = (IEnumScript *)es;
1878 /******************************************************************************/
1880 static inline MLang_impl *impl_from_IMLangFontLink( IMLangFontLink *iface )
1882 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink );
1885 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1886 IMLangFontLink* iface,
1890 MLang_impl *This = impl_from_IMLangFontLink( iface );
1891 return MLang_QueryInterface( This, riid, ppvObject );
1894 static ULONG WINAPI fnIMLangFontLink_AddRef(
1895 IMLangFontLink* iface)
1897 MLang_impl *This = impl_from_IMLangFontLink( iface );
1898 return MLang_AddRef( This );
1901 static ULONG WINAPI fnIMLangFontLink_Release(
1902 IMLangFontLink* iface)
1904 MLang_impl *This = impl_from_IMLangFontLink( iface );
1905 return MLang_Release( This );
1908 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1909 IMLangFontLink* iface,
1911 DWORD* pdwCodePages)
1920 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1922 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
1923 &chSrc, 1, &buf, 1, NULL, &used_dc);
1925 /* If default char is not used, current codepage include the given symbol */
1928 IMLangFontLink_CodePageToCodePages(iface,
1929 mlang_data[i].family_codepage, &codePages);
1930 *pdwCodePages |= codePages;
1936 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1937 IMLangFontLink* iface,
1938 const WCHAR* pszSrc,
1940 DWORD dwPriorityCodePages,
1941 DWORD* pdwCodePages,
1942 LONG* pcchCodePages)
1947 TRACE("(%p)->%s %d %x %p %p\n", iface, debugstr_wn(pszSrc, cchSrc), cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
1949 if (pdwCodePages) *pdwCodePages = 0;
1950 if (pcchCodePages) *pcchCodePages = 0;
1952 if (!pszSrc || !cchSrc || cchSrc < 0)
1953 return E_INVALIDARG;
1955 for (i = 0; i < cchSrc; i++)
1960 ret = fnIMLangFontLink_GetCharCodePages(iface, pszSrc[i], &cp);
1961 if (ret != S_OK) return E_FAIL;
1966 /* FIXME: not tested */
1967 if (dwPriorityCodePages & cps) break;
1970 if (pdwCodePages) *pdwCodePages = cps;
1971 if (pcchCodePages) *pcchCodePages = min( i + 1, cchSrc );
1975 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1976 IMLangFontLink* iface,
1978 DWORD* pdwCodePages)
1980 MLang_impl *This = impl_from_IMLangFontLink( iface );
1984 TRACE("(%p) Seeking %u\n",This, uCodePage);
1986 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uCodePage, &cs, TCI_SRCCODEPAGE);
1990 *pdwCodePages = cs.fs.fsCsb[0];
1991 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1995 TRACE("CodePage Not Found\n");
2000 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
2001 IMLangFontLink* iface,
2003 UINT uDefaultCodePage,
2006 MLang_impl *This = impl_from_IMLangFontLink( iface );
2007 DWORD mask = 0x00000000;
2012 TRACE("(%p) scanning 0x%x default page %u\n",This, dwCodePages,
2015 *puCodePage = 0x00000000;
2017 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uDefaultCodePage, &cs,
2020 if (rc && (dwCodePages & cs.fs.fsCsb[0]))
2022 TRACE("Found Default Codepage\n");
2023 *puCodePage = uDefaultCodePage;
2028 for (i = 0; i < 32; i++)
2032 if (dwCodePages & mask)
2037 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
2041 TRACE("Falling back to least significant found CodePage %u\n",
2043 *puCodePage = cs.ciACP;
2048 TRACE("no codepage found\n");
2052 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
2053 IMLangFontLink* iface,
2056 DWORD* pdwCodePages)
2059 FONTSIGNATURE fontsig;
2060 MLang_impl *This = impl_from_IMLangFontLink( iface );
2062 TRACE("(%p)\n",This);
2064 old_font = SelectObject(hDC,hFont);
2065 GetTextCharsetInfo(hDC,&fontsig, 0);
2066 SelectObject(hDC,old_font);
2068 *pdwCodePages = fontsig.fsCsb[0];
2069 TRACE("CodePages is 0x%x\n",fontsig.fsCsb[0]);
2074 static HRESULT WINAPI fnIMLangFontLink_MapFont(
2075 IMLangFontLink* iface,
2085 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
2086 IMLangFontLink* iface,
2093 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
2094 IMLangFontLink* iface)
2101 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
2103 fnIMLangFontLink_QueryInterface,
2104 fnIMLangFontLink_AddRef,
2105 fnIMLangFontLink_Release,
2106 fnIMLangFontLink_GetCharCodePages,
2107 fnIMLangFontLink_GetStrCodePages,
2108 fnIMLangFontLink_CodePageToCodePages,
2109 fnIMLangFontLink_CodePagesToCodePage,
2110 fnIMLangFontLink_GetFontCodePages,
2111 fnIMLangFontLink_MapFont,
2112 fnIMLangFontLink_ReleaseFont,
2113 fnIMLangFontLink_ResetFontMapping,
2116 /******************************************************************************/
2118 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
2120 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage );
2123 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
2124 IMultiLanguage* iface,
2128 MLang_impl *This = impl_from_IMultiLanguage( iface );
2129 return MLang_QueryInterface( This, riid, ppvObject );
2132 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
2134 MLang_impl *This = impl_from_IMultiLanguage( iface );
2135 return IMLangFontLink_AddRef( ((IMLangFontLink*)This) );
2138 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
2140 MLang_impl *This = impl_from_IMultiLanguage( iface );
2141 return IMLangFontLink_Release( ((IMLangFontLink*)This) );
2144 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
2145 IMultiLanguage* iface,
2148 MLang_impl *This = impl_from_IMultiLanguage( iface );
2150 TRACE("(%p, %p)\n", This, pcCodePage);
2152 if (!pcCodePage) return E_INVALIDARG;
2154 *pcCodePage = This->total_cp;
2158 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
2159 IMultiLanguage* iface,
2161 PMIMECPINFO pCodePageInfo)
2164 MLang_impl *This = impl_from_IMultiLanguage( iface );
2166 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
2168 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2170 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2172 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2174 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2183 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
2184 IMultiLanguage* iface,
2186 UINT* puiFamilyCodePage)
2188 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2191 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
2192 IMultiLanguage* iface,
2194 IEnumCodePage** ppEnumCodePage)
2196 MLang_impl *This = impl_from_IMultiLanguage( iface );
2198 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2200 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2203 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2204 IMultiLanguage* iface,
2206 PMIMECSETINFO pCharsetInfo)
2208 MLang_impl *This = impl_from_IMultiLanguage( iface );
2209 return IMultiLanguage3_GetCharsetInfo((IMultiLanguage3*)&This->vtbl_IMultiLanguage3, Charset, pCharsetInfo);
2212 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2213 IMultiLanguage* iface,
2214 DWORD dwSrcEncoding,
2215 DWORD dwDstEncoding)
2217 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2220 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2221 IMultiLanguage* iface,
2223 DWORD dwSrcEncoding,
2224 DWORD dwDstEncoding,
2230 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2231 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2234 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2235 IMultiLanguage* iface,
2243 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2244 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2247 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2248 IMultiLanguage* iface,
2256 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2257 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2260 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2261 IMultiLanguage* iface)
2267 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2268 IMultiLanguage* iface,
2272 WCHAR buf[MAX_RFC1766_NAME];
2274 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2276 return E_INVALIDARG;
2278 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2280 *pbstrRfc1766 = SysAllocString( buf );
2286 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2287 IMultiLanguage* iface,
2292 IEnumRfc1766 *rfc1766;
2294 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2296 if (!pLocale || !bstrRfc1766)
2297 return E_INVALIDARG;
2299 hr = IMultiLanguage_EnumRfc1766(iface, &rfc1766);
2303 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2305 IEnumRfc1766_Release(rfc1766);
2309 /******************************************************************************/
2311 typedef struct tagEnumRfc1766_impl
2313 const IEnumRfc1766Vtbl *vtbl_IEnumRfc1766;
2319 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2321 return CONTAINING_RECORD( iface, EnumRfc1766_impl, vtbl_IEnumRfc1766 );
2324 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2325 IEnumRfc1766 *iface,
2329 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2331 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2333 if (IsEqualGUID(riid, &IID_IUnknown)
2334 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2336 IEnumRfc1766_AddRef(iface);
2337 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2338 *ppvObject = &(This->vtbl_IEnumRfc1766);
2342 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2343 return E_NOINTERFACE;
2346 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2347 IEnumRfc1766 *iface)
2349 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2350 return InterlockedIncrement(&This->ref);
2353 static ULONG WINAPI fnIEnumRfc1766_Release(
2354 IEnumRfc1766 *iface)
2356 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2357 ULONG ref = InterlockedDecrement(&This->ref);
2359 TRACE("%p ref = %d\n", This, ref);
2362 TRACE("Destroying %p\n", This);
2363 HeapFree(GetProcessHeap(), 0, This->info);
2364 HeapFree(GetProcessHeap(), 0, This);
2369 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2370 IEnumRfc1766 *iface,
2371 IEnumRfc1766 **ppEnum)
2373 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2375 FIXME("%p %p\n", This, ppEnum);
2379 static HRESULT WINAPI fnIEnumRfc1766_Next(
2380 IEnumRfc1766 *iface,
2383 ULONG *pceltFetched)
2386 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2388 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2390 if (!pceltFetched) return S_FALSE;
2393 if (!rgelt) return S_FALSE;
2395 if (This->pos + celt > This->total)
2396 celt = This->total - This->pos;
2398 if (!celt) return S_FALSE;
2400 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2401 *pceltFetched = celt;
2404 for (i = 0; i < celt; i++)
2406 TRACE("#%u: %08x %s %s\n",
2408 wine_dbgstr_w(rgelt[i].wszRfc1766),
2409 wine_dbgstr_w(rgelt[i].wszLocaleName));
2414 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2415 IEnumRfc1766 *iface)
2417 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2419 TRACE("%p\n", This);
2425 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2426 IEnumRfc1766 *iface,
2429 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2431 TRACE("%p %u\n", This, celt);
2433 if (celt >= This->total) return S_FALSE;
2439 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2441 fnIEnumRfc1766_QueryInterface,
2442 fnIEnumRfc1766_AddRef,
2443 fnIEnumRfc1766_Release,
2444 fnIEnumRfc1766_Clone,
2445 fnIEnumRfc1766_Next,
2446 fnIEnumRfc1766_Reset,
2450 struct enum_locales_data
2453 DWORD total, allocated;
2456 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2459 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2462 TRACE("%s\n", debugstr_w(locale));
2464 if (data->total >= data->allocated)
2466 data->allocated += 32;
2467 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2468 if (!data->info) return FALSE;
2471 info = &data->info[data->total];
2473 info->lcid = strtolW(locale, &end, 16);
2474 if (*end) /* invalid number */
2477 info->wszRfc1766[0] = 0;
2478 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2480 info->wszLocaleName[0] = 0;
2481 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2482 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2489 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2491 EnumRfc1766_impl *rfc;
2492 struct enum_locales_data data;
2494 TRACE("%04x, %p\n", LangId, ppEnum);
2496 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2497 rfc->vtbl_IEnumRfc1766 = &IEnumRfc1766_vtbl;
2503 data.allocated = 160;
2504 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2507 HeapFree(GetProcessHeap(), 0, rfc);
2508 return E_OUTOFMEMORY;
2511 TlsSetValue(MLANG_tls_index, &data);
2512 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2513 TlsSetValue(MLANG_tls_index, NULL);
2515 TRACE("enumerated %d rfc1766 structures\n", data.total);
2519 HeapFree(GetProcessHeap(), 0, data.info);
2520 HeapFree(GetProcessHeap(), 0, rfc);
2524 rfc->info = data.info;
2525 rfc->total = data.total;
2527 *ppEnum = (IEnumRfc1766 *)rfc;
2531 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2532 IMultiLanguage *iface,
2533 IEnumRfc1766 **ppEnumRfc1766)
2535 MLang_impl *This = impl_from_IMultiLanguage( iface );
2537 TRACE("%p %p\n", This, ppEnumRfc1766);
2539 return EnumRfc1766_create(0, ppEnumRfc1766);
2542 /******************************************************************************/
2544 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2545 IMultiLanguage* iface,
2547 PRFC1766INFO pRfc1766Info)
2549 LCTYPE type = LOCALE_SLANGUAGE;
2551 TRACE("(%p, 0x%04x, %p)\n", iface, Locale, pRfc1766Info);
2554 return E_INVALIDARG;
2556 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2557 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2558 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2560 if (!SUBLANGID(Locale))
2561 type = LOCALE_SENGLANGUAGE; /* suppress country */
2565 if (!SUBLANGID(Locale)) {
2566 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2571 pRfc1766Info->lcid = Locale;
2572 pRfc1766Info->wszRfc1766[0] = 0;
2573 pRfc1766Info->wszLocaleName[0] = 0;
2575 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2576 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2579 /* Locale not supported */
2580 return E_INVALIDARG;
2583 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2584 IMultiLanguage* iface,
2588 IMLangConvertCharset** ppMLangConvertCharset)
2594 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2596 fnIMultiLanguage_QueryInterface,
2597 fnIMultiLanguage_AddRef,
2598 fnIMultiLanguage_Release,
2599 fnIMultiLanguage_GetNumberOfCodePageInfo,
2600 fnIMultiLanguage_GetCodePageInfo,
2601 fnIMultiLanguage_GetFamilyCodePage,
2602 fnIMultiLanguage_EnumCodePages,
2603 fnIMultiLanguage_GetCharsetInfo,
2604 fnIMultiLanguage_IsConvertible,
2605 fnIMultiLanguage_ConvertString,
2606 fnIMultiLanguage_ConvertStringToUnicode,
2607 fnIMultiLanguage_ConvertStringFromUnicode,
2608 fnIMultiLanguage_ConvertStringReset,
2609 fnIMultiLanguage_GetRfc1766FromLcid,
2610 fnIMultiLanguage_GetLcidFromRfc1766,
2611 fnIMultiLanguage_EnumRfc1766,
2612 fnIMultiLanguage_GetRfc1766Info,
2613 fnIMultiLanguage_CreateConvertCharset,
2617 /******************************************************************************/
2619 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2621 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMultiLanguage3 );
2624 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
2625 IMultiLanguage3* iface,
2629 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2630 return MLang_QueryInterface( This, riid, ppvObject );
2633 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2635 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2636 return MLang_AddRef( This );
2639 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2641 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2642 return MLang_Release( This );
2645 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2646 IMultiLanguage3* iface,
2649 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2651 TRACE("%p, %p\n", This, pcCodePage);
2653 if (!pcCodePage) return E_INVALIDARG;
2655 *pcCodePage = This->total_cp;
2659 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2663 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2665 mime_cp_info->bGDICharset = csi.ciCharset;
2667 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2669 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2670 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2671 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2672 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2673 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2674 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2675 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2676 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2677 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2678 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2679 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2681 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2682 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2683 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2684 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2686 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2687 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2688 mime_cp_info->uiFamilyCodePage,
2689 wine_dbgstr_w(mime_cp_info->wszDescription),
2690 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2691 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2692 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2693 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2694 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2695 mime_cp_info->bGDICharset);
2698 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2699 IMultiLanguage3* iface,
2702 PMIMECPINFO pCodePageInfo)
2705 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2707 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2709 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2711 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2713 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2715 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2724 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2725 IMultiLanguage3* iface,
2727 UINT* puiFamilyCodePage)
2729 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2732 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2733 IMultiLanguage3* iface,
2736 IEnumCodePage** ppEnumCodePage)
2738 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2740 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2742 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2745 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2746 IMultiLanguage3* iface,
2748 PMIMECSETINFO pCharsetInfo)
2751 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2753 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2755 if (!pCharsetInfo) return E_FAIL;
2757 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2759 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2761 WCHAR csetW[MAX_MIMECSET_NAME];
2763 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2764 if (!lstrcmpiW(Charset, csetW))
2766 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2767 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2768 strcpyW(pCharsetInfo->wszCharset, csetW);
2775 * Since we do not support charsets like iso-2022-jp and do not have
2776 * them in our database as a primary (web_charset) encoding this loop
2777 * does an attempt to 'approximate' charset name by header_charset.
2779 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2781 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2783 WCHAR csetW[MAX_MIMECSET_NAME];
2785 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2786 if (!lstrcmpiW(Charset, csetW))
2788 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2789 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2790 strcpyW(pCharsetInfo->wszCharset, csetW);
2799 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2800 IMultiLanguage3* iface,
2801 DWORD dwSrcEncoding,
2802 DWORD dwDstEncoding)
2804 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2807 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2808 IMultiLanguage3* iface,
2810 DWORD dwSrcEncoding,
2811 DWORD dwDstEncoding,
2817 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2818 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2821 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2822 IMultiLanguage3* iface,
2830 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2831 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2834 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2835 IMultiLanguage3* iface,
2843 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2844 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2847 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2848 IMultiLanguage3* iface)
2854 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2855 IMultiLanguage3* iface,
2859 WCHAR buf[MAX_RFC1766_NAME];
2861 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2863 return E_INVALIDARG;
2865 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2867 *pbstrRfc1766 = SysAllocString( buf );
2873 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2874 IMultiLanguage3* iface,
2879 IEnumRfc1766 *rfc1766;
2881 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2883 if (!pLocale || !bstrRfc1766)
2884 return E_INVALIDARG;
2886 hr = IMultiLanguage2_EnumRfc1766(iface, 0, &rfc1766);
2890 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2892 IEnumRfc1766_Release(rfc1766);
2896 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2897 IMultiLanguage3* iface,
2899 IEnumRfc1766** ppEnumRfc1766)
2901 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2903 TRACE("%p %p\n", This, ppEnumRfc1766);
2905 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2908 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2909 IMultiLanguage3* iface,
2912 PRFC1766INFO pRfc1766Info)
2914 static LANGID last_lang = -1;
2915 LCTYPE type = LOCALE_SLANGUAGE;
2917 TRACE("(%p, 0x%04x, 0x%04x, %p)\n", iface, Locale, LangId, pRfc1766Info);
2920 return E_INVALIDARG;
2922 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2923 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2924 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2926 if (!SUBLANGID(Locale))
2927 type = LOCALE_SENGLANGUAGE; /* suppress country */
2931 if (!SUBLANGID(Locale)) {
2932 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2937 pRfc1766Info->lcid = Locale;
2938 pRfc1766Info->wszRfc1766[0] = 0;
2939 pRfc1766Info->wszLocaleName[0] = 0;
2941 if ((PRIMARYLANGID(LangId) != LANG_ENGLISH) &&
2942 (last_lang != LangId)) {
2943 FIXME("Only english names supported (requested: 0x%04x)\n", LangId);
2947 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2948 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2951 /* Locale not supported */
2952 return E_INVALIDARG;
2955 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2956 IMultiLanguage3* iface,
2960 IMLangConvertCharset** ppMLangConvertCharset)
2966 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2967 IMultiLanguage3* iface,
2971 DWORD dwSrcEncoding,
2972 DWORD dwDstEncoding,
2976 char *src, *dst = NULL;
2981 TRACE("%p %0x8 %s %u %u %p %p\n",
2982 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2984 FIXME("dwFlag and lpFallBack not handled\n");
2986 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2987 if (FAILED(hr)) return hr;
2989 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
2990 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
2992 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
2993 if (FAILED(hr)) goto exit;
2995 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
2996 if (FAILED(hr)) goto exit;
2998 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
3003 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
3004 if (FAILED(hr)) goto exit;
3006 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
3009 HeapFree(GetProcessHeap(), 0, src);
3010 HeapFree(GetProcessHeap(), 0, dst);
3014 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
3015 IMultiLanguage3* iface,
3025 if (dwFlag || lpFallBack)
3026 FIXME("Ignoring dwFlag (0x%x/%d) and lpFallBack (%p)\n",
3027 dwFlag, dwFlag, lpFallBack);
3029 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
3030 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
3033 /*****************************************************************************
3034 * MultiLanguage2::ConvertStringToUnicodeEx
3036 * Translates the multibyte string from the specified code page to Unicode.
3039 * see ConvertStringToUnicode
3041 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
3042 * instead unconvertible characters.
3046 * S_FALSE The conversion is not supported.
3047 * E_FAIL Some error has occurred.
3049 * TODO: handle dwFlag and lpFallBack
3051 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
3052 IMultiLanguage3* This,
3063 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
3064 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
3067 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
3068 IMultiLanguage3* iface,
3070 DWORD dwPrefWinCodePage,
3072 DetectEncodingInfo* lpEncoding,
3079 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
3080 IMultiLanguage3* iface,
3082 DWORD dwPrefWinCodePage,
3085 DetectEncodingInfo* lpEncoding,
3092 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
3093 IMultiLanguage3* iface,
3097 return IMultiLanguage2_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
3100 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
3101 IMultiLanguage3* iface,
3104 LPWSTR lpWideCharStr,
3107 /* Find first instance */
3110 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
3111 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)
3117 MultiByteToWideChar(CP_ACP, 0,
3118 mlang_data[i].mime_cp_info[n].description,
3119 -1, lpWideCharStr, cchWideChar);
3128 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
3129 IMultiLanguage3* iface,
3132 TRACE("%u\n", uiCodePage);
3134 /* FIXME: the installable set is usually larger than the set of valid codepages */
3135 return IMultiLanguage2_ValidateCodePageEx(iface, uiCodePage, NULL, CPIOD_PEEK);
3138 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
3139 IMultiLanguage3* iface,
3142 FIXME("0x%08x\n", dwSource);
3146 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
3147 IMultiLanguage3* iface,
3150 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3152 TRACE("%p %p\n", This, pnScripts);
3154 if (!pnScripts) return S_FALSE;
3156 *pnScripts = This->total_scripts;
3160 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
3161 IMultiLanguage3* iface,
3164 IEnumScript** ppEnumScript)
3166 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3168 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3170 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3173 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
3174 IMultiLanguage3* iface,
3177 DWORD dwfIODControl)
3180 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3182 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3184 /* quick check for kernel32 supported code pages */
3185 if (IsValidCodePage(uiCodePage))
3188 /* check for mlang supported code pages */
3189 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3192 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3194 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3199 if (dwfIODControl != CPIOD_PEEK)
3200 FIXME("Request to install codepage language pack not handled\n");
3205 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3206 IMultiLanguage3 *iface,
3208 LPCWSTR lpWideCharStr,
3210 UINT *puiPreferredCodePages,
3211 UINT nPreferredCodePages,
3212 UINT *puiDetectedCodePages,
3213 UINT *pnDetectedCodePages,
3214 WCHAR *lpSpecialChar)
3216 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3218 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3219 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3220 pnDetectedCodePages, lpSpecialChar);
3224 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3225 IMultiLanguage3 *iface,
3228 UINT *puiPreferredCodePages,
3229 UINT nPreferredCodePages,
3230 UINT *puiDetectedCodePages,
3231 UINT *pnDetectedCodePages,
3232 WCHAR *lpSpecialChar)
3234 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3236 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
3237 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3238 pnDetectedCodePages, lpSpecialChar);
3242 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3244 fnIMultiLanguage2_QueryInterface,
3245 fnIMultiLanguage2_AddRef,
3246 fnIMultiLanguage2_Release,
3247 fnIMultiLanguage2_GetNumberOfCodePageInfo,
3248 fnIMultiLanguage2_GetCodePageInfo,
3249 fnIMultiLanguage2_GetFamilyCodePage,
3250 fnIMultiLanguage2_EnumCodePages,
3251 fnIMultiLanguage2_GetCharsetInfo,
3252 fnIMultiLanguage2_IsConvertible,
3253 fnIMultiLanguage2_ConvertString,
3254 fnIMultiLanguage2_ConvertStringToUnicode,
3255 fnIMultiLanguage2_ConvertStringFromUnicode,
3256 fnIMultiLanguage2_ConvertStringReset,
3257 fnIMultiLanguage2_GetRfc1766FromLcid,
3258 fnIMultiLanguage2_GetLcidFromRfc1766,
3259 fnIMultiLanguage2_EnumRfc1766,
3260 fnIMultiLanguage2_GetRfc1766Info,
3261 fnIMultiLanguage2_CreateConvertCharset,
3262 fnIMultiLanguage2_ConvertStringInIStream,
3263 fnIMultiLanguage2_ConvertStringToUnicodeEx,
3264 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
3265 fnIMultiLanguage2_DetectCodepageInIStream,
3266 fnIMultiLanguage2_DetectInputCodepage,
3267 fnIMultiLanguage2_ValidateCodePage,
3268 fnIMultiLanguage2_GetCodePageDescription,
3269 fnIMultiLanguage2_IsCodePageInstallable,
3270 fnIMultiLanguage2_SetMimeDBSource,
3271 fnIMultiLanguage2_GetNumberOfScripts,
3272 fnIMultiLanguage2_EnumScripts,
3273 fnIMultiLanguage2_ValidateCodePageEx,
3274 fnIMultiLanguage3_DetectOutboundCodePage,
3275 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3278 /******************************************************************************/
3280 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3282 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangFontLink2 );
3285 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3286 IMLangFontLink2 * iface,
3290 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3291 return MLang_QueryInterface( This, riid, ppvObject );
3294 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3296 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3297 return MLang_AddRef( This );
3300 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3302 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3303 return MLang_Release( This );
3306 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
3307 WCHAR chSrc, DWORD *pdwCodePages)
3309 FIXME("(%p)->%s %p\n",This, debugstr_wn(&chSrc,1),pdwCodePages);
3313 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
3314 const WCHAR *pszSrc, LONG cchSrc, DWORD dwPriorityCodePages,
3315 DWORD *pdwCodePages, LONG *pcchCodePages)
3317 return fnIMLangFontLink_GetStrCodePages((IMLangFontLink *)This,
3318 pszSrc, cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
3321 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
3323 DWORD *pdwCodePages)
3325 FIXME("(%p)->%i %p\n",This, uCodePage, pdwCodePages);
3329 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* This,
3330 DWORD dwCodePages, UINT uDefaultCodePage, UINT *puCodePage)
3332 FIXME("(%p)->%i %i %p\n",This, dwCodePages, uDefaultCodePage, puCodePage);
3336 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2* This,
3337 HDC hDC, HFONT hFont, DWORD *pdwCodePages)
3339 FIXME("(%p)->%p %p %p\n",This, hDC, hFont, pdwCodePages);
3343 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3346 FIXME("(%p)->%p\n",This, hFont);
3350 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3352 FIXME("(%p)->\n",This);
3356 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3357 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3359 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
3363 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3364 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3369 TRACE("(%p)->%p %p %p\n", This, hDC, puiRanges, pUranges);
3371 if (!puiRanges) return E_INVALIDARG;
3372 if (!(size = GetFontUnicodeRanges(hDC, NULL))) return E_FAIL;
3373 if (!(gs = HeapAlloc(GetProcessHeap(), 0, size))) return E_OUTOFMEMORY;
3375 GetFontUnicodeRanges(hDC, gs);
3376 *puiRanges = gs->cRanges;
3380 for (i = 0; i < gs->cRanges; i++)
3382 if (i >= *puiRanges) break;
3383 pUranges[i].wcFrom = gs->ranges[i].wcLow;
3384 pUranges[i].wcTo = gs->ranges[i].wcLow + gs->ranges[i].cGlyphs;
3388 HeapFree(GetProcessHeap(), 0, gs);
3392 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3393 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3394 SCRIPTFONTINFO *pScriptFont)
3398 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3400 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3402 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3404 if (sid == mlang_data[i].sid)
3408 if (j >= *puiFonts) break;
3410 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3411 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3413 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3414 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3416 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3418 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3419 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3429 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3430 UINT uiCodePage, SCRIPT_ID *pSid)
3434 TRACE("(%p)->%i %p\n", This, uiCodePage, pSid);
3436 if (uiCodePage == CP_UNICODE) return E_FAIL;
3438 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3440 if (uiCodePage == mlang_data[i].family_codepage)
3442 if (pSid) *pSid = mlang_data[i].sid;
3449 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3451 fnIMLangFontLink2_QueryInterface,
3452 fnIMLangFontLink2_AddRef,
3453 fnIMLangFontLink2_Release,
3454 fnIMLangFontLink2_GetCharCodePages,
3455 fnIMLangFontLink2_GetStrCodePages,
3456 fnIMLangFontLink2_CodePageToCodePages,
3457 fnIMLangFontLink2_CodePagesToCodePage,
3458 fnIMLangFontLink2_GetFontCodePages,
3459 fnIMLangFontLink2_ReleaseFont,
3460 fnIMLangFontLink2_ResetFontMapping,
3461 fnIMLangFontLink2_MapFont,
3462 fnIMLangFontLink2_GetFontUnicodeRanges,
3463 fnIMLangFontLink2_GetScriptFontInfo,
3464 fnIMLangFontLink2_CodePageToScriptID
3467 /******************************************************************************/
3469 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3471 return CONTAINING_RECORD( iface, MLang_impl, vtbl_IMLangLineBreakConsole );
3474 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3475 IMLangLineBreakConsole* iface,
3479 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3480 return MLang_QueryInterface( This, riid, ppvObject );
3483 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3484 IMLangLineBreakConsole* iface )
3486 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3487 return MLang_AddRef( This );
3490 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3491 IMLangLineBreakConsole* iface )
3493 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3494 return MLang_Release( This );
3497 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3498 IMLangLineBreakConsole* iface,
3499 IMLangString* pSrcMLStr,
3507 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3511 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3512 IMLangLineBreakConsole* iface,
3514 const WCHAR* pszSrc,
3520 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3527 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3528 IMLangLineBreakConsole* iface,
3537 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3544 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3546 fnIMLangLineBreakConsole_QueryInterface,
3547 fnIMLangLineBreakConsole_AddRef,
3548 fnIMLangLineBreakConsole_Release,
3549 fnIMLangLineBreakConsole_BreakLineML,
3550 fnIMLangLineBreakConsole_BreakLineW,
3551 fnIMLangLineBreakConsole_BreakLineA
3554 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3559 TRACE("Creating MultiLanguage object\n");
3562 return CLASS_E_NOAGGREGATION;
3564 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3565 mlang->vtbl_IMLangFontLink = &IMLangFontLink_vtbl;
3566 mlang->vtbl_IMultiLanguage = &IMultiLanguage_vtbl;
3567 mlang->vtbl_IMultiLanguage3 = &IMultiLanguage3_vtbl;
3568 mlang->vtbl_IMLangFontLink2 = &IMLangFontLink2_vtbl;
3569 mlang->vtbl_IMLangLineBreakConsole = &IMLangLineBreakConsole_vtbl;
3571 mlang->total_cp = 0;
3572 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3573 mlang->total_cp += mlang_data[i].number_of_cp;
3575 /* do not enumerate unicode flavours */
3576 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3580 TRACE("returning %p\n", mlang);
3587 /******************************************************************************/
3589 HRESULT WINAPI DllCanUnloadNow(void)
3591 return dll_count == 0 ? S_OK : S_FALSE;
3595 /***********************************************************************
3596 * DllRegisterServer (MLANG.@)
3598 HRESULT WINAPI DllRegisterServer(void)
3600 return __wine_register_resources( instance, NULL );
3603 /***********************************************************************
3604 * DllUnregisterServer (MLANG.@)
3606 HRESULT WINAPI DllUnregisterServer(void)
3608 return __wine_unregister_resources( instance, NULL );
3611 HRESULT WINAPI GetGlobalFontLinkObject(void)