rsaenh/tests: Add more AES encrypt/decrypt tests.
[wine.git] / dlls / mlang / mlang.c
blobf4a689cb1206fb7cfb726d2609489872254f8d77
1 /*
2 * MLANG Class Factory
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
24 #include "config.h"
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "ole2.h"
36 #include "objbase.h"
37 #include "rpcproxy.h"
38 #include "mlang.h"
39 #include "mimeole.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
46 #include "initguid.h"
48 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
49 static HRESULT MLangConvertCharset_create(IUnknown *outer, void **obj);
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 */
55 /* FIXME:
56 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
57 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
60 typedef struct
62 const char *description;
63 UINT cp;
64 DWORD flags;
65 const char *web_charset;
66 const char *header_charset;
67 const char *body_charset;
68 } MIME_CP_INFO;
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[] =
75 { "Arabic (864)",
76 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
77 MIMECONTF_MIME_LATEST,
78 "ibm864", "ibm864", "ibm864" },
79 { "Arabic (1006)",
80 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
81 MIMECONTF_MIME_LATEST,
82 "ibm1006", "ibm1006", "ibm1006" },
83 { "Arabic (Windows)",
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" },
88 { "Arabic (ISO)",
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[] =
97 { "Baltic (DOS)",
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" },
107 { "Baltic (ISO)",
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" },
113 { "Estonian (ISO)",
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[] =
162 { "OEM Cyrillic",
163 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
164 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
165 "ibm855", "ibm855", "ibm855" },
166 { "Cyrillic (DOS)",
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" },
176 #endif
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" },
182 { "Cyrillic (Mac)",
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" },
198 { "Cyrillic (ISO)",
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[] =
207 { "Greek (DOS)",
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" },
219 { "Greek (Windows)",
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" },
224 { "Greek (Mac)",
225 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
226 MIMECONTF_MIME_LATEST,
227 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
228 { "Greek (ISO)",
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[] =
237 { "Hebrew (424)",
238 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
239 MIMECONTF_MIME_LATEST,
240 "ibm424", "ibm424", "ibm424" },
241 { "Hebrew (856)",
242 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
243 MIMECONTF_MIME_LATEST,
244 "cp856", "cp856", "cp856" },
245 { "Hebrew (DOS)",
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" },
268 { "Japanese (EUC)",
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" },
274 { "Japanese (JIS)",
275 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
276 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
277 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
278 MIMECONTF_MIME_IE4,
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"},
293 { "Japanese (Mac)",
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[] =
306 { "Korean",
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[] =
315 { "Thai (Windows)",
316 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
317 "ibm-thai", "ibm-thai", "ibm-thai" }
319 static const MIME_CP_INFO turkish_cp[] =
321 { "Turkish (DOS)",
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" },
335 { "Turkish (Mac)",
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" },
339 { "Latin 3 (ISO)",
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" },
344 { "Turkish (ISO)",
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" },
382 { "Icelandic (DOS)",
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" },
390 { "Nordic (DOS)",
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" },
404 { "Icelandic (Mac)",
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" },
408 { "US-ASCII",
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" },
419 { "Latin 9 (ISO)",
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[] =
428 { "Unicode",
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" },
434 { "Unicode (UTF-7)",
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" },
439 { "Unicode (UTF-8)",
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;
451 UINT number_of_cp;
452 const MIME_CP_INFO *mime_cp_info;
453 const char *fixed_font;
454 const char *proportional_font;
455 SCRIPT_ID sid;
456 } mlang_data[] =
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)
508 UINT code = 0;
509 DWORD i = 0;
510 unsigned char c1,c2;
512 while ((code == 0 || code == 51932) && i < count)
514 c1 = input[i];
515 if (c1 == 0x1b /* ESC */)
517 i++;
518 if (i >= count)
519 return code;
520 c1 = input[i];
521 if (c1 == '$')
523 i++;
524 if (i >= count)
525 return code;
526 c1 = input[i];
527 if (c1 =='B' || c1 == '@')
528 code = 50220;
530 if (c1 == 'K')
531 code = 50220;
533 else if (c1 >= 129)
535 i++;
536 if (i >= count)
537 return code;
538 c2 = input[i];
539 if NOTEUC(c1,c2)
540 code = 932;
541 else if (ISEUC(c1) && ISEUC(c2))
542 code = 51932;
543 else if (((c1 == 142)) && HANKATA(c2))
544 code = 51932;
546 i++;
548 return code;
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;
559 *p2 = c2 + cell;
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;
571 *p2 -= cell;
574 static int han2zen(unsigned char *p1, unsigned char *p2)
576 BOOL maru = FALSE;
577 BOOL nigori = FALSE;
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,
582 131,129,129 };
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))))
589 nigori = TRUE;
590 else if ((*p2 == 223) && (ISMARU(*p1)))
591 maru = TRUE;
593 if (*p1 >= 161 && *p1 <= 223)
595 unsigned char index = *p1 - 161;
596 *p1 = char1[index];
597 *p2 = char2[index];
600 if (maru || nigori)
602 if (nigori)
604 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
605 (*p2)++;
606 else if ((*p1 == 131) && (*p2 == 69))
607 *p2 = 148;
609 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
610 *p2+= 2;
612 return 1;
615 return 0;
619 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
621 DWORD i = 0;
622 int j = 0;
623 unsigned char p2,p;
624 BOOL shifted = FALSE;
626 while (i < count)
628 p = input[i];
629 if (p == 0x1b /* ESC */)
631 i++;
632 if (i >= count)
633 return 0;
634 p2 = input[i];
635 if (p2 == '$' || p2 =='(')
636 i++;
637 if (p2 == 'K' || p2 =='$')
638 shifted = TRUE;
639 else
640 shifted = FALSE;
642 else
644 if (shifted)
646 i++;
647 if (i >= count)
648 return 0;
649 p2 = input[i];
650 jis2sjis(&p,&p2);
651 output[j++]=p;
652 output[j++]=p2;
654 else
656 output[j++] = p;
659 i++;
661 return j;
664 static inline int exit_shift(LPSTR out, int c)
666 if (out)
668 out[c] = 0x1b;
669 out[c+1] = '(';
670 out[c+2] = 'B';
672 return 3;
675 static inline int enter_shift(LPSTR out, int c)
677 if (out)
679 out[c] = 0x1b;
680 out[c+1] = '$';
681 out[c+2] = 'B';
683 return 3;
687 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
689 DWORD i = 0;
690 int j = 0;
691 unsigned char p2,p;
692 BOOL shifted = FALSE;
694 while (i < count)
696 p = input[i] & 0xff;
697 if (p == 10 || p == 13) /* NL and CR */
699 if (shifted)
701 shifted = FALSE;
702 j += exit_shift(output,j);
704 if (output)
705 output[j++] = p;
706 else
707 j++;
709 else
711 if (SJIS1(p))
713 i++;
714 if (i >= count)
715 return 0;
716 p2 = input[i] & 0xff;
717 if (SJIS2(p2))
719 sjis2jis(&p,&p2);
720 if (!shifted)
722 shifted = TRUE;
723 j+=enter_shift(output,j);
727 if (output)
729 output[j++]=p;
730 output[j++]=p2;
732 else
733 j+=2;
735 else
737 if (HANKATA(p))
739 if ((i+1) >= count)
740 return 0;
741 p2 = input[i+1] & 0xff;
742 i+=han2zen(&p,&p2);
743 sjis2jis(&p,&p2);
744 if (!shifted)
746 shifted = TRUE;
747 j+=enter_shift(output,j);
749 if (output)
751 output[j++]=p;
752 output[j++]=p2;
754 else
755 j+=2;
757 else
759 if (shifted)
761 shifted = FALSE;
762 j += exit_shift(output,j);
764 if (output)
765 output[j++]=p;
766 else
767 j++;
771 i++;
773 if (shifted)
774 j += exit_shift(output,j);
775 return j;
778 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
779 LPWSTR output, DWORD out_count)
781 CHAR *sjis_string;
782 UINT rc = 0;
783 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
784 rc = ConvertJIS2SJIS(input,count,sjis_string);
785 if (rc)
787 TRACE("%s\n",debugstr_an(sjis_string,rc));
788 if (output)
789 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
790 else
791 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
793 HeapFree(GetProcessHeap(),0,sjis_string);
794 return rc;
798 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
799 LPWSTR output, DWORD out_count)
801 CHAR *sjis_string;
802 UINT rc = 0;
803 int code = DetectJapaneseCode(input,count);
804 TRACE("Japanese code %i\n",code);
806 switch (code)
808 case 0:
809 if (output)
810 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
811 else
812 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
813 break;
815 case 932:
816 if (output)
817 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
818 else
819 rc = MultiByteToWideChar(932,0,input,count,0,0);
820 break;
822 case 51932:
823 if (output)
824 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
825 else
826 rc = MultiByteToWideChar(20932,0,input,count,0,0);
827 break;
829 case 50220:
830 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
831 rc = ConvertJIS2SJIS(input,count,sjis_string);
832 if (rc)
834 TRACE("%s\n",debugstr_an(sjis_string,rc));
835 if (output)
836 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
837 else
838 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
840 HeapFree(GetProcessHeap(),0,sjis_string);
841 break;
843 return rc;
846 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
847 LPSTR output, DWORD out_count)
849 CHAR *sjis_string;
850 INT len;
851 UINT rc = 0;
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);
859 if (out_count >= rc)
861 ConvertSJIS2JIS(sjis_string, len, output);
863 HeapFree(GetProcessHeap(),0,sjis_string);
864 return rc;
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)
883 switch(fdwReason) {
884 case DLL_PROCESS_ATTACH:
885 instance = hInstDLL;
886 MLANG_tls_index = TlsAlloc();
887 DisableThreadLibraryCalls(hInstDLL);
888 break;
889 case DLL_PROCESS_DETACH:
890 if (lpv) break;
891 TlsFree(MLANG_tls_index);
892 break;
894 return TRUE;
897 HRESULT WINAPI ConvertINetMultiByteToUnicode(
898 LPDWORD pdwMode,
899 DWORD dwEncoding,
900 LPCSTR pSrcStr,
901 LPINT pcSrcSize,
902 LPWSTR pDstStr,
903 LPINT pcDstSize)
905 INT src_len = -1;
907 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
908 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
910 if (!pcDstSize)
911 return E_FAIL;
913 if (!pcSrcSize)
914 pcSrcSize = &src_len;
916 if (!*pcSrcSize)
918 *pcDstSize = 0;
919 return S_OK;
922 /* forwarding euc-jp to EUC-JP */
923 if (dwEncoding == 51932)
924 dwEncoding = 20932;
926 switch (dwEncoding)
928 case CP_UNICODE:
929 if (*pcSrcSize == -1)
930 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
931 *pcDstSize = min(*pcSrcSize, *pcDstSize);
932 *pcSrcSize *= sizeof(WCHAR);
933 if (pDstStr)
934 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
935 break;
937 case 50220:
938 case 50221:
939 case 50222:
940 *pcDstSize = ConvertJISJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
941 break;
942 case 50932:
943 *pcDstSize = ConvertUnknownJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
944 break;
946 default:
947 if (*pcSrcSize == -1)
948 *pcSrcSize = lstrlenA(pSrcStr);
950 if (pDstStr)
951 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
952 else
953 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
954 break;
957 if (!*pcDstSize)
958 return E_FAIL;
960 return S_OK;
963 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
964 LPDWORD pdwMode,
965 DWORD dwEncoding,
966 LPCWSTR pSrcStr,
967 LPINT pcSrcSize,
968 LPSTR pDstStr,
969 LPINT pcDstSize)
971 INT destsz, size;
972 INT src_len = -1;
974 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
975 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
977 if (!pcDstSize)
978 return S_OK;
980 if (!pcSrcSize)
981 pcSrcSize = &src_len;
983 destsz = (pDstStr) ? *pcDstSize : 0;
984 *pcDstSize = 0;
986 if (!pSrcStr || !*pcSrcSize)
987 return S_OK;
989 if (*pcSrcSize == -1)
990 *pcSrcSize = lstrlenW(pSrcStr);
992 /* forwarding euc-jp to EUC-JP */
993 if (dwEncoding == 51932)
994 dwEncoding = 20932;
996 if (dwEncoding == CP_UNICODE)
998 if (*pcSrcSize == -1)
999 *pcSrcSize = lstrlenW(pSrcStr);
1001 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
1002 if (pDstStr)
1003 memmove(pDstStr, pSrcStr, size);
1005 if (size >= destsz)
1006 goto fail;
1008 else if (dwEncoding == 50220 || dwEncoding == 50221 || dwEncoding == 50222)
1010 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, NULL, 0);
1011 if (!size)
1012 goto fail;
1014 if (pDstStr)
1016 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, pDstStr,
1017 destsz);
1018 if (!size)
1019 goto fail;
1023 else
1025 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1026 NULL, 0, NULL, NULL);
1027 if (!size)
1028 goto fail;
1030 if (pDstStr)
1032 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1033 pDstStr, destsz, NULL, NULL);
1034 if (!size)
1035 goto fail;
1039 *pcDstSize = size;
1040 return S_OK;
1042 fail:
1043 *pcSrcSize = 0;
1044 *pcDstSize = 0;
1045 return E_FAIL;
1048 HRESULT WINAPI ConvertINetString(
1049 LPDWORD pdwMode,
1050 DWORD dwSrcEncoding,
1051 DWORD dwDstEncoding,
1052 LPCSTR pSrcStr,
1053 LPINT pcSrcSize,
1054 LPSTR pDstStr,
1055 LPINT pcDstSize
1058 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
1059 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1061 if (dwSrcEncoding == CP_UNICODE)
1063 INT cSrcSizeW;
1064 if (pcSrcSize && *pcSrcSize != -1)
1066 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
1067 pcSrcSize = &cSrcSizeW;
1069 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
1071 else if (dwDstEncoding == CP_UNICODE)
1073 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
1074 *pcDstSize *= sizeof(WCHAR);
1075 return hr;
1077 else
1079 INT cDstSizeW;
1080 LPWSTR pDstStrW;
1081 HRESULT hr;
1083 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
1085 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
1086 if (hr != S_OK)
1087 return hr;
1089 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
1090 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
1091 if (hr == S_OK)
1092 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
1094 HeapFree(GetProcessHeap(), 0, pDstStrW);
1095 return hr;
1099 static HRESULT GetFamilyCodePage(
1100 UINT uiCodePage,
1101 UINT* puiFamilyCodePage)
1103 UINT i, n;
1105 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
1107 if (!puiFamilyCodePage) return S_FALSE;
1109 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1111 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1113 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1115 *puiFamilyCodePage = mlang_data[i].family_codepage;
1116 return S_OK;
1121 return S_FALSE;
1124 HRESULT WINAPI IsConvertINetStringAvailable(
1125 DWORD dwSrcEncoding,
1126 DWORD dwDstEncoding)
1128 UINT src_family, dst_family;
1130 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
1132 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
1133 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
1134 return S_FALSE;
1136 if (src_family == dst_family) return S_OK;
1138 /* we can convert any codepage to/from unicode */
1139 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
1141 return S_FALSE;
1144 static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
1146 CHAR buffer[MAX_RFC1766_NAME];
1147 INT n = GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1148 INT i;
1150 if (n)
1152 i = PRIMARYLANGID(lcid);
1153 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1154 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1155 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1157 buffer[n - 1] = '-';
1158 i = GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1159 if (!i)
1160 buffer[n - 1] = '\0';
1162 else
1163 i = 0;
1165 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len );
1166 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1168 return E_FAIL;
1171 static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
1173 WCHAR buffer[MAX_RFC1766_NAME];
1174 INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1175 INT i;
1177 if (n)
1179 i = PRIMARYLANGID(lcid);
1180 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1181 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1182 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1184 buffer[n - 1] = '-';
1185 i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1186 if (!i)
1187 buffer[n - 1] = '\0';
1189 else
1190 i = 0;
1192 LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
1193 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1195 return E_FAIL;
1198 HRESULT WINAPI LcidToRfc1766A(
1199 LCID lcid,
1200 LPSTR pszRfc1766,
1201 INT nChar)
1203 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1204 if (!pszRfc1766)
1205 return E_INVALIDARG;
1207 return lcid_to_rfc1766A(lcid, pszRfc1766, nChar);
1210 HRESULT WINAPI LcidToRfc1766W(
1211 LCID lcid,
1212 LPWSTR pszRfc1766,
1213 INT nChar)
1215 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1216 if (!pszRfc1766)
1217 return E_INVALIDARG;
1219 return lcid_to_rfc1766W(lcid, pszRfc1766, nChar);
1222 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
1224 RFC1766INFO info;
1225 ULONG num;
1227 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
1229 if (!strcmpiW(info.wszRfc1766, rfc1766))
1231 *lcid = info.lcid;
1232 return S_OK;
1234 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
1236 *lcid = PRIMARYLANGID(info.lcid);
1237 return S_OK;
1241 return E_FAIL;
1244 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
1246 IEnumRfc1766 *enumrfc1766;
1247 HRESULT hr;
1249 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
1251 if (!pLocale || !pszRfc1766)
1252 return E_INVALIDARG;
1254 hr = EnumRfc1766_create(0, &enumrfc1766);
1255 if (FAILED(hr))
1256 return hr;
1258 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
1259 IEnumRfc1766_Release(enumrfc1766);
1261 return hr;
1264 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
1266 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1268 if (!rfc1766A)
1269 return E_INVALIDARG;
1271 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
1272 rfc1766W[MAX_RFC1766_NAME] = 0;
1274 return Rfc1766ToLcidW(lcid, rfc1766W);
1277 /******************************************************************************
1278 * MLANG ClassFactory
1280 typedef struct {
1281 IClassFactory IClassFactory_iface;
1282 LONG ref;
1283 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1284 } IClassFactoryImpl;
1286 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
1288 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
1291 struct object_creation_info
1293 const CLSID *clsid;
1294 LPCSTR szClassName;
1295 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1298 static const struct object_creation_info object_creation[] =
1300 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
1301 { &CLSID_CMLangConvertCharset, "CLSID_CMLangConvertCharset", MLangConvertCharset_create }
1304 static HRESULT WINAPI MLANGCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
1306 TRACE("%s\n", debugstr_guid(riid) );
1308 if (IsEqualGUID(riid, &IID_IUnknown)
1309 || IsEqualGUID(riid, &IID_IClassFactory))
1311 IClassFactory_AddRef(iface);
1312 *ppobj = iface;
1313 return S_OK;
1316 *ppobj = NULL;
1317 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
1318 return E_NOINTERFACE;
1321 static ULONG WINAPI MLANGCF_AddRef(IClassFactory *iface)
1323 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1324 return InterlockedIncrement(&This->ref);
1327 static ULONG WINAPI MLANGCF_Release(IClassFactory *iface)
1329 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1330 ULONG ref = InterlockedDecrement(&This->ref);
1332 if (ref == 0)
1334 TRACE("Destroying %p\n", This);
1335 HeapFree(GetProcessHeap(), 0, This);
1338 return ref;
1341 static HRESULT WINAPI MLANGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1342 REFIID riid, void **ppobj)
1344 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1345 HRESULT hres;
1346 LPUNKNOWN punk;
1348 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1350 *ppobj = NULL;
1351 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
1352 if (SUCCEEDED(hres)) {
1353 hres = IUnknown_QueryInterface(punk, riid, ppobj);
1354 IUnknown_Release(punk);
1356 TRACE("returning (%p) -> %x\n", *ppobj, hres);
1357 return hres;
1360 static HRESULT WINAPI MLANGCF_LockServer(IClassFactory *iface, BOOL dolock)
1362 if (dolock)
1363 LockModule();
1364 else
1365 UnlockModule();
1367 return S_OK;
1370 static const IClassFactoryVtbl MLANGCF_Vtbl =
1372 MLANGCF_QueryInterface,
1373 MLANGCF_AddRef,
1374 MLANGCF_Release,
1375 MLANGCF_CreateInstance,
1376 MLANGCF_LockServer
1379 /******************************************************************
1380 * DllGetClassObject (MLANG.@)
1382 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
1384 unsigned int i;
1385 IClassFactoryImpl *factory;
1387 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
1389 if ( !IsEqualGUID( &IID_IClassFactory, iid )
1390 && ! IsEqualGUID( &IID_IUnknown, iid) )
1391 return E_NOINTERFACE;
1393 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
1395 if (IsEqualGUID(object_creation[i].clsid, rclsid))
1396 break;
1399 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
1401 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
1402 return CLASS_E_CLASSNOTAVAILABLE;
1405 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
1407 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
1408 if (factory == NULL) return E_OUTOFMEMORY;
1410 factory->IClassFactory_iface.lpVtbl = &MLANGCF_Vtbl;
1411 factory->ref = 1;
1413 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
1415 *ppv = &factory->IClassFactory_iface;
1417 TRACE("(%p) <- %p\n", ppv, &factory->IClassFactory_iface);
1419 return S_OK;
1423 /******************************************************************************/
1425 typedef struct tagMLang_impl
1427 IMLangFontLink IMLangFontLink_iface;
1428 IMultiLanguage IMultiLanguage_iface;
1429 IMultiLanguage3 IMultiLanguage3_iface;
1430 IMLangFontLink2 IMLangFontLink2_iface;
1431 IMLangLineBreakConsole IMLangLineBreakConsole_iface;
1432 LONG ref;
1433 DWORD total_cp, total_scripts;
1434 } MLang_impl;
1436 /******************************************************************************/
1438 typedef struct tagEnumCodePage_impl
1440 IEnumCodePage IEnumCodePage_iface;
1441 LONG ref;
1442 MIMECPINFO *cpinfo;
1443 DWORD total, pos;
1444 } EnumCodePage_impl;
1446 static inline EnumCodePage_impl *impl_from_IEnumCodePage( IEnumCodePage *iface )
1448 return CONTAINING_RECORD( iface, EnumCodePage_impl, IEnumCodePage_iface );
1451 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1452 IEnumCodePage* iface,
1453 REFIID riid,
1454 void** ppvObject)
1456 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1458 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1460 if (IsEqualGUID(riid, &IID_IUnknown)
1461 || IsEqualGUID(riid, &IID_IEnumCodePage))
1463 IEnumCodePage_AddRef(iface);
1464 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1465 *ppvObject = &This->IEnumCodePage_iface;
1466 return S_OK;
1469 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1470 return E_NOINTERFACE;
1473 static ULONG WINAPI fnIEnumCodePage_AddRef(
1474 IEnumCodePage* iface)
1476 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1477 return InterlockedIncrement(&This->ref);
1480 static ULONG WINAPI fnIEnumCodePage_Release(
1481 IEnumCodePage* iface)
1483 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1484 ULONG ref = InterlockedDecrement(&This->ref);
1486 TRACE("%p ref = %d\n", This, ref);
1487 if (ref == 0)
1489 TRACE("Destroying %p\n", This);
1490 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1491 HeapFree(GetProcessHeap(), 0, This);
1494 return ref;
1497 static HRESULT WINAPI fnIEnumCodePage_Clone(
1498 IEnumCodePage* iface,
1499 IEnumCodePage** ppEnum)
1501 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1502 FIXME("%p %p\n", This, ppEnum);
1503 return E_NOTIMPL;
1506 static HRESULT WINAPI fnIEnumCodePage_Next(
1507 IEnumCodePage* iface,
1508 ULONG celt,
1509 PMIMECPINFO rgelt,
1510 ULONG* pceltFetched)
1512 ULONG i;
1513 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1515 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1517 if (!pceltFetched) return S_FALSE;
1518 *pceltFetched = 0;
1520 if (!rgelt) return S_FALSE;
1522 if (This->pos + celt > This->total)
1523 celt = This->total - This->pos;
1525 if (!celt) return S_FALSE;
1527 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1528 *pceltFetched = celt;
1529 This->pos += celt;
1531 for (i = 0; i < celt; i++)
1533 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1534 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1535 rgelt[i].uiFamilyCodePage,
1536 wine_dbgstr_w(rgelt[i].wszDescription),
1537 wine_dbgstr_w(rgelt[i].wszWebCharset),
1538 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1539 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1540 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1541 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1542 rgelt[i].bGDICharset);
1544 return S_OK;
1547 static HRESULT WINAPI fnIEnumCodePage_Reset(
1548 IEnumCodePage* iface)
1550 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1552 TRACE("%p\n", This);
1554 This->pos = 0;
1555 return S_OK;
1558 static HRESULT WINAPI fnIEnumCodePage_Skip(
1559 IEnumCodePage* iface,
1560 ULONG celt)
1562 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1564 TRACE("%p %u\n", This, celt);
1566 if (celt >= This->total) return S_FALSE;
1568 This->pos += celt;
1569 return S_OK;
1572 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1574 fnIEnumCodePage_QueryInterface,
1575 fnIEnumCodePage_AddRef,
1576 fnIEnumCodePage_Release,
1577 fnIEnumCodePage_Clone,
1578 fnIEnumCodePage_Next,
1579 fnIEnumCodePage_Reset,
1580 fnIEnumCodePage_Skip
1583 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1584 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1586 EnumCodePage_impl *ecp;
1587 MIMECPINFO *cpinfo;
1588 UINT i, n;
1590 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1592 if (!grfFlags) /* enumerate internal data base of encodings */
1593 grfFlags = MIMECONTF_MIME_LATEST;
1595 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1596 ecp->IEnumCodePage_iface.lpVtbl = &IEnumCodePage_vtbl;
1597 ecp->ref = 1;
1598 ecp->pos = 0;
1599 ecp->total = 0;
1600 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1602 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1604 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1605 ecp->total++;
1609 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1610 sizeof(MIMECPINFO) * ecp->total);
1611 cpinfo = ecp->cpinfo;
1613 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1615 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1617 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1618 fill_cp_info(&mlang_data[i], n, cpinfo++);
1622 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1624 *ppEnumCodePage = &ecp->IEnumCodePage_iface;
1626 return S_OK;
1629 /******************************************************************************/
1631 typedef struct tagEnumScript_impl
1633 IEnumScript IEnumScript_iface;
1634 LONG ref;
1635 SCRIPTINFO *script_info;
1636 DWORD total, pos;
1637 } EnumScript_impl;
1639 static inline EnumScript_impl *impl_from_IEnumScript( IEnumScript *iface )
1641 return CONTAINING_RECORD( iface, EnumScript_impl, IEnumScript_iface );
1644 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1645 IEnumScript* iface,
1646 REFIID riid,
1647 void** ppvObject)
1649 EnumScript_impl *This = impl_from_IEnumScript( iface );
1651 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1653 if (IsEqualGUID(riid, &IID_IUnknown)
1654 || IsEqualGUID(riid, &IID_IEnumScript))
1656 IEnumScript_AddRef(iface);
1657 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1658 *ppvObject = &This->IEnumScript_iface;
1659 return S_OK;
1662 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1663 return E_NOINTERFACE;
1666 static ULONG WINAPI fnIEnumScript_AddRef(
1667 IEnumScript* iface)
1669 EnumScript_impl *This = impl_from_IEnumScript( iface );
1670 return InterlockedIncrement(&This->ref);
1673 static ULONG WINAPI fnIEnumScript_Release(
1674 IEnumScript* iface)
1676 EnumScript_impl *This = impl_from_IEnumScript( iface );
1677 ULONG ref = InterlockedDecrement(&This->ref);
1679 TRACE("%p ref = %d\n", This, ref);
1680 if (ref == 0)
1682 TRACE("Destroying %p\n", This);
1683 HeapFree(GetProcessHeap(), 0, This->script_info);
1684 HeapFree(GetProcessHeap(), 0, This);
1687 return ref;
1690 static HRESULT WINAPI fnIEnumScript_Clone(
1691 IEnumScript* iface,
1692 IEnumScript** ppEnum)
1694 EnumScript_impl *This = impl_from_IEnumScript( iface );
1695 FIXME("%p %p: stub!\n", This, ppEnum);
1696 return E_NOTIMPL;
1699 static HRESULT WINAPI fnIEnumScript_Next(
1700 IEnumScript* iface,
1701 ULONG celt,
1702 PSCRIPTINFO rgelt,
1703 ULONG* pceltFetched)
1705 EnumScript_impl *This = impl_from_IEnumScript( iface );
1707 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1709 if (!pceltFetched || !rgelt) return E_FAIL;
1711 *pceltFetched = 0;
1713 if (This->pos + celt > This->total)
1714 celt = This->total - This->pos;
1716 if (!celt) return S_FALSE;
1718 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1719 *pceltFetched = celt;
1720 This->pos += celt;
1722 return S_OK;
1725 static HRESULT WINAPI fnIEnumScript_Reset(
1726 IEnumScript* iface)
1728 EnumScript_impl *This = impl_from_IEnumScript( iface );
1730 TRACE("%p\n", This);
1732 This->pos = 0;
1733 return S_OK;
1736 static HRESULT WINAPI fnIEnumScript_Skip(
1737 IEnumScript* iface,
1738 ULONG celt)
1740 EnumScript_impl *This = impl_from_IEnumScript( iface );
1742 TRACE("%p %u\n", This, celt);
1744 if (celt >= This->total) return S_FALSE;
1746 This->pos += celt;
1747 return S_OK;
1750 static const IEnumScriptVtbl IEnumScript_vtbl =
1752 fnIEnumScript_QueryInterface,
1753 fnIEnumScript_AddRef,
1754 fnIEnumScript_Release,
1755 fnIEnumScript_Clone,
1756 fnIEnumScript_Next,
1757 fnIEnumScript_Reset,
1758 fnIEnumScript_Skip
1761 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1762 LANGID LangId, IEnumScript** ppEnumScript )
1764 EnumScript_impl *es;
1765 UINT i;
1767 TRACE("%p, %08x, %04x, %p\n", mlang, dwFlags, LangId, ppEnumScript);
1769 if (!dwFlags) /* enumerate all available scripts */
1770 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1772 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1773 es->IEnumScript_iface.lpVtbl = &IEnumScript_vtbl;
1774 es->ref = 1;
1775 es->pos = 0;
1776 /* do not enumerate unicode flavours */
1777 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1778 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1780 for (i = 0; i < es->total; i++)
1782 es->script_info[i].ScriptId = i;
1783 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1784 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1785 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1786 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1787 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1788 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1789 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1792 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1794 *ppEnumScript = &es->IEnumScript_iface;
1796 return S_OK;
1799 /******************************************************************************/
1801 static inline MLang_impl *impl_from_IMLangFontLink( IMLangFontLink *iface )
1803 return CONTAINING_RECORD( iface, MLang_impl, IMLangFontLink_iface );
1806 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1807 IMLangFontLink* iface,
1808 REFIID riid,
1809 void** ppvObject)
1811 MLang_impl *This = impl_from_IMLangFontLink( iface );
1812 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
1815 static ULONG WINAPI fnIMLangFontLink_AddRef(
1816 IMLangFontLink* iface)
1818 MLang_impl *This = impl_from_IMLangFontLink( iface );
1819 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
1822 static ULONG WINAPI fnIMLangFontLink_Release(
1823 IMLangFontLink* iface)
1825 MLang_impl *This = impl_from_IMLangFontLink( iface );
1826 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
1829 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1830 IMLangFontLink* iface,
1831 WCHAR ch_src,
1832 DWORD* codepages)
1834 MLang_impl *This = impl_from_IMLangFontLink( iface );
1835 return IMLangFontLink2_GetCharCodePages(&This->IMLangFontLink2_iface, ch_src, codepages);
1838 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1839 IMLangFontLink* iface,
1840 const WCHAR* src,
1841 LONG src_len,
1842 DWORD priority_cp,
1843 DWORD* codepages,
1844 LONG* ret_len)
1846 MLang_impl *This = impl_from_IMLangFontLink( iface );
1847 return IMLangFontLink2_GetStrCodePages(&This->IMLangFontLink2_iface, src, src_len, priority_cp,
1848 codepages, ret_len);
1851 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1852 IMLangFontLink* iface,
1853 UINT codepage,
1854 DWORD* codepages)
1856 MLang_impl *This = impl_from_IMLangFontLink( iface );
1857 return IMLangFontLink2_CodePageToCodePages(&This->IMLangFontLink2_iface, codepage, codepages);
1860 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1861 IMLangFontLink* iface,
1862 DWORD codepages,
1863 UINT def_codepage,
1864 UINT* codepage)
1866 MLang_impl *This = impl_from_IMLangFontLink(iface);
1867 return IMLangFontLink2_CodePagesToCodePage(&This->IMLangFontLink2_iface, codepages,
1868 def_codepage, codepage);
1871 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
1872 IMLangFontLink* iface,
1873 HDC hdc,
1874 HFONT hfont,
1875 DWORD* codepages)
1877 MLang_impl *This = impl_from_IMLangFontLink(iface);
1878 return IMLangFontLink2_GetFontCodePages(&This->IMLangFontLink2_iface, hdc, hfont, codepages);
1881 static HRESULT WINAPI fnIMLangFontLink_MapFont(
1882 IMLangFontLink* iface,
1883 HDC hDC,
1884 DWORD dwCodePages,
1885 HFONT hSrcFont,
1886 HFONT* phDestFont)
1888 FIXME("\n");
1889 return E_NOTIMPL;
1892 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
1893 IMLangFontLink* iface,
1894 HFONT hFont)
1896 FIXME("\n");
1897 return E_NOTIMPL;
1900 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
1901 IMLangFontLink* iface)
1903 FIXME("\n");
1904 return E_NOTIMPL;
1908 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
1910 fnIMLangFontLink_QueryInterface,
1911 fnIMLangFontLink_AddRef,
1912 fnIMLangFontLink_Release,
1913 fnIMLangFontLink_GetCharCodePages,
1914 fnIMLangFontLink_GetStrCodePages,
1915 fnIMLangFontLink_CodePageToCodePages,
1916 fnIMLangFontLink_CodePagesToCodePage,
1917 fnIMLangFontLink_GetFontCodePages,
1918 fnIMLangFontLink_MapFont,
1919 fnIMLangFontLink_ReleaseFont,
1920 fnIMLangFontLink_ResetFontMapping,
1923 /******************************************************************************/
1925 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
1927 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage_iface );
1930 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
1931 IMultiLanguage* iface,
1932 REFIID riid,
1933 void** obj)
1935 MLang_impl *This = impl_from_IMultiLanguage( iface );
1936 return IMultiLanguage3_QueryInterface(&This->IMultiLanguage3_iface, riid, obj);
1939 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
1941 MLang_impl *This = impl_from_IMultiLanguage( iface );
1942 return IMultiLanguage3_AddRef(&This->IMultiLanguage3_iface);
1945 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
1947 MLang_impl *This = impl_from_IMultiLanguage( iface );
1948 return IMultiLanguage3_Release(&This->IMultiLanguage3_iface);
1951 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
1952 IMultiLanguage* iface,
1953 UINT* cp)
1955 MLang_impl *This = impl_from_IMultiLanguage( iface );
1956 TRACE("(%p, %p)\n", This, cp);
1957 return IMultiLanguage3_GetNumberOfCodePageInfo(&This->IMultiLanguage3_iface, cp);
1960 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
1961 IMultiLanguage* iface,
1962 UINT uiCodePage,
1963 PMIMECPINFO pCodePageInfo)
1965 UINT i, n;
1966 MLang_impl *This = impl_from_IMultiLanguage( iface );
1968 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
1970 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1972 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1974 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1976 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
1977 return S_OK;
1982 return S_FALSE;
1985 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
1986 IMultiLanguage* iface,
1987 UINT cp,
1988 UINT* family_cp)
1990 MLang_impl *This = impl_from_IMultiLanguage( iface );
1991 return IMultiLanguage3_GetFamilyCodePage(&This->IMultiLanguage3_iface, cp, family_cp);
1994 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
1995 IMultiLanguage* iface,
1996 DWORD grfFlags,
1997 IEnumCodePage** ppEnumCodePage)
1999 MLang_impl *This = impl_from_IMultiLanguage( iface );
2001 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2003 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2006 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2007 IMultiLanguage* iface,
2008 BSTR Charset,
2009 PMIMECSETINFO pCharsetInfo)
2011 MLang_impl *This = impl_from_IMultiLanguage( iface );
2012 return IMultiLanguage3_GetCharsetInfo( &This->IMultiLanguage3_iface, Charset, pCharsetInfo );
2015 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2016 IMultiLanguage* iface,
2017 DWORD src_enc,
2018 DWORD dst_enc)
2020 MLang_impl *This = impl_from_IMultiLanguage( iface );
2021 return IMultiLanguage3_IsConvertible(&This->IMultiLanguage3_iface, src_enc, dst_enc);
2024 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2025 IMultiLanguage* iface,
2026 DWORD* mode,
2027 DWORD src_enc,
2028 DWORD dst_enc,
2029 BYTE* src,
2030 UINT* src_size,
2031 BYTE* dest,
2032 UINT* dest_size)
2034 MLang_impl *This = impl_from_IMultiLanguage( iface );
2035 return IMultiLanguage3_ConvertString(&This->IMultiLanguage3_iface, mode, src_enc,
2036 dst_enc, src, src_size, dest, dest_size);
2039 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2040 IMultiLanguage* iface,
2041 DWORD* mode,
2042 DWORD src_enc,
2043 CHAR* src,
2044 UINT* src_size,
2045 WCHAR* dest,
2046 UINT* dest_size)
2048 MLang_impl *This = impl_from_IMultiLanguage( iface );
2049 return IMultiLanguage3_ConvertStringToUnicode(&This->IMultiLanguage3_iface,
2050 mode, src_enc, src, src_size, dest, dest_size);
2053 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2054 IMultiLanguage* iface,
2055 DWORD* mode,
2056 DWORD encoding,
2057 WCHAR* src,
2058 UINT* src_size,
2059 CHAR* dest,
2060 UINT* dest_size)
2062 MLang_impl *This = impl_from_IMultiLanguage(iface);
2063 return IMultiLanguage3_ConvertStringFromUnicode(&This->IMultiLanguage3_iface,
2064 mode, encoding, src, src_size, dest, dest_size);
2067 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2068 IMultiLanguage* iface)
2070 MLang_impl *This = impl_from_IMultiLanguage( iface );
2071 return IMultiLanguage3_ConvertStringReset(&This->IMultiLanguage3_iface);
2074 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2075 IMultiLanguage* iface,
2076 LCID lcid,
2077 BSTR* pbstrRfc1766)
2079 MLang_impl *This = impl_from_IMultiLanguage(iface);
2080 return IMultiLanguage3_GetRfc1766FromLcid(&This->IMultiLanguage3_iface, lcid, pbstrRfc1766);
2083 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2084 IMultiLanguage* iface,
2085 LCID* locale,
2086 BSTR rfc1766)
2088 MLang_impl *This = impl_from_IMultiLanguage(iface);
2089 return IMultiLanguage3_GetLcidFromRfc1766(&This->IMultiLanguage3_iface, locale, rfc1766);
2092 /******************************************************************************/
2094 typedef struct tagEnumRfc1766_impl
2096 IEnumRfc1766 IEnumRfc1766_iface;
2097 LONG ref;
2098 RFC1766INFO *info;
2099 DWORD total, pos;
2100 } EnumRfc1766_impl;
2102 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2104 return CONTAINING_RECORD( iface, EnumRfc1766_impl, IEnumRfc1766_iface );
2107 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2108 IEnumRfc1766 *iface,
2109 REFIID riid,
2110 void** ppvObject)
2112 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2114 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2116 if (IsEqualGUID(riid, &IID_IUnknown)
2117 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2119 IEnumRfc1766_AddRef(iface);
2120 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2121 *ppvObject = &This->IEnumRfc1766_iface;
2122 return S_OK;
2125 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2126 return E_NOINTERFACE;
2129 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2130 IEnumRfc1766 *iface)
2132 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2133 return InterlockedIncrement(&This->ref);
2136 static ULONG WINAPI fnIEnumRfc1766_Release(
2137 IEnumRfc1766 *iface)
2139 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2140 ULONG ref = InterlockedDecrement(&This->ref);
2142 TRACE("%p ref = %d\n", This, ref);
2143 if (ref == 0)
2145 TRACE("Destroying %p\n", This);
2146 HeapFree(GetProcessHeap(), 0, This->info);
2147 HeapFree(GetProcessHeap(), 0, This);
2149 return ref;
2152 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2153 IEnumRfc1766 *iface,
2154 IEnumRfc1766 **ppEnum)
2156 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2158 FIXME("%p %p\n", This, ppEnum);
2159 return E_NOTIMPL;
2162 static HRESULT WINAPI fnIEnumRfc1766_Next(
2163 IEnumRfc1766 *iface,
2164 ULONG celt,
2165 PRFC1766INFO rgelt,
2166 ULONG *pceltFetched)
2168 ULONG i;
2169 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2171 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2173 if (!pceltFetched) return S_FALSE;
2174 *pceltFetched = 0;
2176 if (!rgelt) return S_FALSE;
2178 if (This->pos + celt > This->total)
2179 celt = This->total - This->pos;
2181 if (!celt) return S_FALSE;
2183 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2184 *pceltFetched = celt;
2185 This->pos += celt;
2187 for (i = 0; i < celt; i++)
2189 TRACE("#%u: %08x %s %s\n",
2190 i, rgelt[i].lcid,
2191 wine_dbgstr_w(rgelt[i].wszRfc1766),
2192 wine_dbgstr_w(rgelt[i].wszLocaleName));
2194 return S_OK;
2197 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2198 IEnumRfc1766 *iface)
2200 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2202 TRACE("%p\n", This);
2204 This->pos = 0;
2205 return S_OK;
2208 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2209 IEnumRfc1766 *iface,
2210 ULONG celt)
2212 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2214 TRACE("%p %u\n", This, celt);
2216 if (celt >= This->total) return S_FALSE;
2218 This->pos += celt;
2219 return S_OK;
2222 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2224 fnIEnumRfc1766_QueryInterface,
2225 fnIEnumRfc1766_AddRef,
2226 fnIEnumRfc1766_Release,
2227 fnIEnumRfc1766_Clone,
2228 fnIEnumRfc1766_Next,
2229 fnIEnumRfc1766_Reset,
2230 fnIEnumRfc1766_Skip
2233 struct enum_locales_data
2235 RFC1766INFO *info;
2236 DWORD total, allocated;
2239 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2241 WCHAR *end;
2242 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2243 RFC1766INFO *info;
2245 TRACE("%s\n", debugstr_w(locale));
2247 if (data->total >= data->allocated)
2249 data->allocated += 32;
2250 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2251 if (!data->info) return FALSE;
2254 info = &data->info[data->total];
2256 info->lcid = strtolW(locale, &end, 16);
2257 if (*end) /* invalid number */
2258 return FALSE;
2260 info->wszRfc1766[0] = 0;
2261 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2263 info->wszLocaleName[0] = 0;
2264 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2265 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2267 data->total++;
2269 return TRUE;
2272 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2274 EnumRfc1766_impl *rfc;
2275 struct enum_locales_data data;
2277 TRACE("%04x, %p\n", LangId, ppEnum);
2279 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2280 rfc->IEnumRfc1766_iface.lpVtbl = &IEnumRfc1766_vtbl;
2281 rfc->ref = 1;
2282 rfc->pos = 0;
2283 rfc->total = 0;
2285 data.total = 0;
2286 data.allocated = 160;
2287 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2288 if (!data.info)
2290 HeapFree(GetProcessHeap(), 0, rfc);
2291 return E_OUTOFMEMORY;
2294 TlsSetValue(MLANG_tls_index, &data);
2295 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2296 TlsSetValue(MLANG_tls_index, NULL);
2298 TRACE("enumerated %d rfc1766 structures\n", data.total);
2300 if (!data.total)
2302 HeapFree(GetProcessHeap(), 0, data.info);
2303 HeapFree(GetProcessHeap(), 0, rfc);
2304 return E_FAIL;
2307 rfc->info = data.info;
2308 rfc->total = data.total;
2310 *ppEnum = &rfc->IEnumRfc1766_iface;
2311 return S_OK;
2314 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2315 IMultiLanguage *iface,
2316 IEnumRfc1766 **ppEnumRfc1766)
2318 MLang_impl *This = impl_from_IMultiLanguage( iface );
2320 TRACE("%p %p\n", This, ppEnumRfc1766);
2322 return EnumRfc1766_create(0, ppEnumRfc1766);
2325 /******************************************************************************/
2327 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2328 IMultiLanguage* iface,
2329 LCID Locale,
2330 PRFC1766INFO pRfc1766Info)
2332 LCTYPE type = LOCALE_SLANGUAGE;
2334 TRACE("(%p, 0x%04x, %p)\n", iface, Locale, pRfc1766Info);
2336 if (!pRfc1766Info)
2337 return E_INVALIDARG;
2339 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2340 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2341 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2343 if (!SUBLANGID(Locale))
2344 type = LOCALE_SENGLANGUAGE; /* suppress country */
2346 else
2348 if (!SUBLANGID(Locale)) {
2349 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2350 return E_FAIL;
2354 pRfc1766Info->lcid = Locale;
2355 pRfc1766Info->wszRfc1766[0] = 0;
2356 pRfc1766Info->wszLocaleName[0] = 0;
2358 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2359 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2360 return S_OK;
2362 /* Locale not supported */
2363 return E_INVALIDARG;
2366 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2367 IMultiLanguage* iface,
2368 UINT src_cp,
2369 UINT dst_cp,
2370 DWORD prop,
2371 IMLangConvertCharset** convert_charset)
2373 MLang_impl *This = impl_from_IMultiLanguage(iface);
2374 return IMultiLanguage3_CreateConvertCharset(&This->IMultiLanguage3_iface, src_cp, dst_cp, prop, convert_charset);
2377 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2379 fnIMultiLanguage_QueryInterface,
2380 fnIMultiLanguage_AddRef,
2381 fnIMultiLanguage_Release,
2382 fnIMultiLanguage_GetNumberOfCodePageInfo,
2383 fnIMultiLanguage_GetCodePageInfo,
2384 fnIMultiLanguage_GetFamilyCodePage,
2385 fnIMultiLanguage_EnumCodePages,
2386 fnIMultiLanguage_GetCharsetInfo,
2387 fnIMultiLanguage_IsConvertible,
2388 fnIMultiLanguage_ConvertString,
2389 fnIMultiLanguage_ConvertStringToUnicode,
2390 fnIMultiLanguage_ConvertStringFromUnicode,
2391 fnIMultiLanguage_ConvertStringReset,
2392 fnIMultiLanguage_GetRfc1766FromLcid,
2393 fnIMultiLanguage_GetLcidFromRfc1766,
2394 fnIMultiLanguage_EnumRfc1766,
2395 fnIMultiLanguage_GetRfc1766Info,
2396 fnIMultiLanguage_CreateConvertCharset,
2400 /******************************************************************************/
2402 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2404 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage3_iface );
2407 static HRESULT WINAPI fnIMultiLanguage3_QueryInterface(
2408 IMultiLanguage3* iface,
2409 REFIID riid,
2410 void** obj)
2412 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2414 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
2416 if (IsEqualGUID(riid, &IID_IUnknown) ||
2417 IsEqualGUID(riid, &IID_IMultiLanguage))
2419 *obj = &This->IMultiLanguage_iface;
2421 else if (IsEqualGUID(riid, &IID_IMLangCodePages) ||
2422 IsEqualGUID(riid, &IID_IMLangFontLink))
2424 *obj = &This->IMLangFontLink_iface;
2426 else if (IsEqualGUID(riid, &IID_IMLangFontLink2))
2428 *obj = &This->IMLangFontLink2_iface;
2430 else if (IsEqualGUID(riid, &IID_IMultiLanguage2) ||
2431 IsEqualGUID(riid, &IID_IMultiLanguage3))
2433 *obj = &This->IMultiLanguage3_iface;
2435 else if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
2437 *obj = &This->IMLangLineBreakConsole_iface;
2439 else
2441 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), obj);
2442 *obj = NULL;
2443 return E_NOINTERFACE;
2446 IMultiLanguage3_AddRef(iface);
2447 return S_OK;
2450 static ULONG WINAPI fnIMultiLanguage3_AddRef( IMultiLanguage3* iface )
2452 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2453 return InterlockedIncrement(&This->ref);
2456 static ULONG WINAPI fnIMultiLanguage3_Release( IMultiLanguage3* iface )
2458 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2459 ULONG ref = InterlockedDecrement(&This->ref);
2461 TRACE("(%p)->(%d)\n", This, ref);
2462 if (ref == 0)
2464 HeapFree(GetProcessHeap(), 0, This);
2465 UnlockModule();
2468 return ref;
2471 static HRESULT WINAPI fnIMultiLanguage3_GetNumberOfCodePageInfo(
2472 IMultiLanguage3* iface,
2473 UINT* pcCodePage)
2475 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2477 TRACE("%p, %p\n", This, pcCodePage);
2479 if (!pcCodePage) return E_INVALIDARG;
2481 *pcCodePage = This->total_cp;
2482 return S_OK;
2485 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2487 CHARSETINFO csi;
2489 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2490 TCI_SRCCODEPAGE))
2491 mime_cp_info->bGDICharset = csi.ciCharset;
2492 else
2493 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2495 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2496 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2497 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2498 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2499 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2500 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2501 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2502 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2503 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2504 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2505 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2507 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2508 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2509 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2510 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2512 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2513 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2514 mime_cp_info->uiFamilyCodePage,
2515 wine_dbgstr_w(mime_cp_info->wszDescription),
2516 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2517 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2518 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2519 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2520 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2521 mime_cp_info->bGDICharset);
2524 static HRESULT WINAPI fnIMultiLanguage3_GetCodePageInfo(
2525 IMultiLanguage3* iface,
2526 UINT uiCodePage,
2527 LANGID LangId,
2528 PMIMECPINFO pCodePageInfo)
2530 UINT i, n;
2531 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2533 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2535 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2537 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2539 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2541 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2542 return S_OK;
2547 return S_FALSE;
2550 static HRESULT WINAPI fnIMultiLanguage3_GetFamilyCodePage(
2551 IMultiLanguage3* iface,
2552 UINT uiCodePage,
2553 UINT* puiFamilyCodePage)
2555 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2558 static HRESULT WINAPI fnIMultiLanguage3_EnumCodePages(
2559 IMultiLanguage3* iface,
2560 DWORD grfFlags,
2561 LANGID LangId,
2562 IEnumCodePage** ppEnumCodePage)
2564 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2566 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2568 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2571 static HRESULT WINAPI fnIMultiLanguage3_GetCharsetInfo(
2572 IMultiLanguage3* iface,
2573 BSTR Charset,
2574 PMIMECSETINFO pCharsetInfo)
2576 UINT i, n;
2577 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2579 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2581 if (!pCharsetInfo) return E_FAIL;
2583 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2585 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2587 WCHAR csetW[MAX_MIMECSET_NAME];
2589 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2590 if (!lstrcmpiW(Charset, csetW))
2592 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2593 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2594 strcpyW(pCharsetInfo->wszCharset, csetW);
2595 return S_OK;
2600 /* FIXME:
2601 * Since we do not support charsets like iso-2022-jp and do not have
2602 * them in our database as a primary (web_charset) encoding this loop
2603 * does an attempt to 'approximate' charset name by header_charset.
2605 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2607 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2609 WCHAR csetW[MAX_MIMECSET_NAME];
2611 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2612 if (!lstrcmpiW(Charset, csetW))
2614 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2615 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2616 strcpyW(pCharsetInfo->wszCharset, csetW);
2617 return S_OK;
2622 return E_FAIL;
2625 static HRESULT WINAPI fnIMultiLanguage3_IsConvertible(
2626 IMultiLanguage3* iface,
2627 DWORD dwSrcEncoding,
2628 DWORD dwDstEncoding)
2630 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2633 static HRESULT WINAPI fnIMultiLanguage3_ConvertString(
2634 IMultiLanguage3* iface,
2635 DWORD* pdwMode,
2636 DWORD dwSrcEncoding,
2637 DWORD dwDstEncoding,
2638 BYTE* pSrcStr,
2639 UINT* pcSrcSize,
2640 BYTE* pDstStr,
2641 UINT* pcDstSize)
2643 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2644 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2647 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringToUnicode(
2648 IMultiLanguage3* iface,
2649 DWORD* pdwMode,
2650 DWORD dwEncoding,
2651 CHAR* pSrcStr,
2652 UINT* pcSrcSize,
2653 WCHAR* pDstStr,
2654 UINT* pcDstSize)
2656 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2657 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2660 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringFromUnicode(
2661 IMultiLanguage3* iface,
2662 DWORD* pdwMode,
2663 DWORD dwEncoding,
2664 WCHAR* pSrcStr,
2665 UINT* pcSrcSize,
2666 CHAR* pDstStr,
2667 UINT* pcDstSize)
2669 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2670 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2673 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringReset(
2674 IMultiLanguage3* iface)
2676 FIXME("\n");
2677 return E_NOTIMPL;
2680 static HRESULT WINAPI fnIMultiLanguage3_GetRfc1766FromLcid(
2681 IMultiLanguage3* iface,
2682 LCID lcid,
2683 BSTR* pbstrRfc1766)
2685 WCHAR buf[MAX_RFC1766_NAME];
2687 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2688 if (!pbstrRfc1766)
2689 return E_INVALIDARG;
2691 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2693 *pbstrRfc1766 = SysAllocString( buf );
2694 return S_OK;
2696 return E_FAIL;
2699 static HRESULT WINAPI fnIMultiLanguage3_GetLcidFromRfc1766(
2700 IMultiLanguage3* iface,
2701 LCID* pLocale,
2702 BSTR bstrRfc1766)
2704 HRESULT hr;
2705 IEnumRfc1766 *rfc1766;
2707 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2709 if (!pLocale || !bstrRfc1766)
2710 return E_INVALIDARG;
2712 hr = IMultiLanguage3_EnumRfc1766(iface, 0, &rfc1766);
2713 if (FAILED(hr))
2714 return hr;
2716 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2718 IEnumRfc1766_Release(rfc1766);
2719 return hr;
2722 static HRESULT WINAPI fnIMultiLanguage3_EnumRfc1766(
2723 IMultiLanguage3* iface,
2724 LANGID LangId,
2725 IEnumRfc1766** ppEnumRfc1766)
2727 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2729 TRACE("%p %p\n", This, ppEnumRfc1766);
2731 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2734 static HRESULT WINAPI fnIMultiLanguage3_GetRfc1766Info(
2735 IMultiLanguage3* iface,
2736 LCID Locale,
2737 LANGID LangId,
2738 PRFC1766INFO pRfc1766Info)
2740 static LANGID last_lang = -1;
2741 LCTYPE type = LOCALE_SLANGUAGE;
2743 TRACE("(%p, 0x%04x, 0x%04x, %p)\n", iface, Locale, LangId, pRfc1766Info);
2745 if (!pRfc1766Info)
2746 return E_INVALIDARG;
2748 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2749 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2750 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2752 if (!SUBLANGID(Locale))
2753 type = LOCALE_SENGLANGUAGE; /* suppress country */
2755 else
2757 if (!SUBLANGID(Locale)) {
2758 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2759 return E_FAIL;
2763 pRfc1766Info->lcid = Locale;
2764 pRfc1766Info->wszRfc1766[0] = 0;
2765 pRfc1766Info->wszLocaleName[0] = 0;
2767 if ((PRIMARYLANGID(LangId) != LANG_ENGLISH) &&
2768 (last_lang != LangId)) {
2769 FIXME("Only English names supported (requested: 0x%04x)\n", LangId);
2770 last_lang = LangId;
2773 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2774 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2775 return S_OK;
2777 /* Locale not supported */
2778 return E_INVALIDARG;
2781 static HRESULT WINAPI fnIMultiLanguage3_CreateConvertCharset(
2782 IMultiLanguage3* iface,
2783 UINT src_cp,
2784 UINT dst_cp,
2785 DWORD prop,
2786 IMLangConvertCharset** convert_charset)
2788 HRESULT hr;
2790 TRACE("(%u %u 0x%08x %p)\n", src_cp, dst_cp, prop, convert_charset);
2792 hr = MLangConvertCharset_create(NULL, (void**)convert_charset);
2793 if (FAILED(hr)) return hr;
2795 return IMLangConvertCharset_Initialize(*convert_charset, src_cp, dst_cp, prop);
2798 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringInIStream(
2799 IMultiLanguage3* iface,
2800 DWORD* pdwMode,
2801 DWORD dwFlag,
2802 WCHAR* lpFallBack,
2803 DWORD dwSrcEncoding,
2804 DWORD dwDstEncoding,
2805 IStream* pstmIn,
2806 IStream* pstmOut)
2808 char *src, *dst = NULL;
2809 INT srclen, dstlen;
2810 STATSTG stat;
2811 HRESULT hr;
2813 TRACE("%p %0x8 %s %u %u %p %p\n",
2814 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2816 FIXME("dwFlag and lpFallBack not handled\n");
2818 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2819 if (FAILED(hr)) return hr;
2821 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
2822 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
2824 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
2825 if (FAILED(hr)) goto exit;
2827 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
2828 if (FAILED(hr)) goto exit;
2830 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
2832 hr = E_OUTOFMEMORY;
2833 goto exit;
2835 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
2836 if (FAILED(hr)) goto exit;
2838 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
2840 exit:
2841 HeapFree(GetProcessHeap(), 0, src);
2842 HeapFree(GetProcessHeap(), 0, dst);
2843 return hr;
2846 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringToUnicodeEx(
2847 IMultiLanguage3* iface,
2848 DWORD* pdwMode,
2849 DWORD dwEncoding,
2850 CHAR* pSrcStr,
2851 UINT* pcSrcSize,
2852 WCHAR* pDstStr,
2853 UINT* pcDstSize,
2854 DWORD dwFlag,
2855 WCHAR* lpFallBack)
2857 if (dwFlag || lpFallBack)
2858 FIXME("Ignoring dwFlag (0x%x/%d) and lpFallBack (%p)\n",
2859 dwFlag, dwFlag, lpFallBack);
2861 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2862 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2865 /*****************************************************************************
2866 * MultiLanguage2::ConvertStringToUnicodeEx
2868 * Translates the multibyte string from the specified code page to Unicode.
2870 * PARAMS
2871 * see ConvertStringToUnicode
2872 * dwFlag
2873 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2874 * instead unconvertible characters.
2876 * RETURNS
2877 * S_OK Success.
2878 * S_FALSE The conversion is not supported.
2879 * E_FAIL Some error has occurred.
2881 * TODO: handle dwFlag and lpFallBack
2883 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringFromUnicodeEx(
2884 IMultiLanguage3* This,
2885 DWORD* pdwMode,
2886 DWORD dwEncoding,
2887 WCHAR* pSrcStr,
2888 UINT* pcSrcSize,
2889 CHAR* pDstStr,
2890 UINT* pcDstSize,
2891 DWORD dwFlag,
2892 WCHAR* lpFallBack)
2894 FIXME("\n");
2895 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2896 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2899 static HRESULT WINAPI fnIMultiLanguage3_DetectCodepageInIStream(
2900 IMultiLanguage3* iface,
2901 DWORD dwFlag,
2902 DWORD dwPrefWinCodePage,
2903 IStream* pstmIn,
2904 DetectEncodingInfo* lpEncoding,
2905 INT* pnScores)
2907 FIXME("\n");
2908 return E_NOTIMPL;
2911 static HRESULT WINAPI fnIMultiLanguage3_DetectInputCodepage(
2912 IMultiLanguage3* iface,
2913 DWORD dwFlag,
2914 DWORD dwPrefWinCodePage,
2915 CHAR* pSrcStr,
2916 INT* pcSrcSize,
2917 DetectEncodingInfo* lpEncoding,
2918 INT* pnScores)
2920 FIXME("\n");
2921 return E_NOTIMPL;
2924 static HRESULT WINAPI fnIMultiLanguage3_ValidateCodePage(
2925 IMultiLanguage3* iface,
2926 UINT uiCodePage,
2927 HWND hwnd)
2929 return IMultiLanguage3_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
2932 static HRESULT WINAPI fnIMultiLanguage3_GetCodePageDescription(
2933 IMultiLanguage3* iface,
2934 UINT uiCodePage,
2935 LCID lcid,
2936 LPWSTR lpWideCharStr,
2937 int cchWideChar)
2939 /* Find first instance */
2940 unsigned int i,n;
2942 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
2943 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2945 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2947 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2949 MultiByteToWideChar(CP_ACP, 0,
2950 mlang_data[i].mime_cp_info[n].description,
2951 -1, lpWideCharStr, cchWideChar);
2952 return S_OK;
2957 return S_FALSE;
2960 static HRESULT WINAPI fnIMultiLanguage3_IsCodePageInstallable(
2961 IMultiLanguage3* iface,
2962 UINT uiCodePage)
2964 TRACE("%u\n", uiCodePage);
2966 /* FIXME: the installable set is usually larger than the set of valid codepages */
2967 return IMultiLanguage3_ValidateCodePageEx(iface, uiCodePage, NULL, CPIOD_PEEK);
2970 static HRESULT WINAPI fnIMultiLanguage3_SetMimeDBSource(
2971 IMultiLanguage3* iface,
2972 MIMECONTF dwSource)
2974 FIXME("0x%08x\n", dwSource);
2975 return S_OK;
2978 static HRESULT WINAPI fnIMultiLanguage3_GetNumberOfScripts(
2979 IMultiLanguage3* iface,
2980 UINT* pnScripts)
2982 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2984 TRACE("%p %p\n", This, pnScripts);
2986 if (!pnScripts) return S_FALSE;
2988 *pnScripts = This->total_scripts;
2989 return S_OK;
2992 static HRESULT WINAPI fnIMultiLanguage3_EnumScripts(
2993 IMultiLanguage3* iface,
2994 DWORD dwFlags,
2995 LANGID LangId,
2996 IEnumScript** ppEnumScript)
2998 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3000 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3002 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3005 static HRESULT WINAPI fnIMultiLanguage3_ValidateCodePageEx(
3006 IMultiLanguage3* iface,
3007 UINT uiCodePage,
3008 HWND hwnd,
3009 DWORD dwfIODControl)
3011 unsigned int i;
3012 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3014 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3016 /* quick check for kernel32 supported code pages */
3017 if (IsValidCodePage(uiCodePage))
3018 return S_OK;
3020 /* check for mlang supported code pages */
3021 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3023 UINT n;
3024 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3026 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3027 return S_OK;
3031 if (dwfIODControl != CPIOD_PEEK)
3032 FIXME("Request to install codepage language pack not handled\n");
3034 return S_FALSE;
3037 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3038 IMultiLanguage3 *iface,
3039 DWORD dwFlags,
3040 LPCWSTR lpWideCharStr,
3041 UINT cchWideChar,
3042 UINT *puiPreferredCodePages,
3043 UINT nPreferredCodePages,
3044 UINT *puiDetectedCodePages,
3045 UINT *pnDetectedCodePages,
3046 WCHAR *lpSpecialChar)
3048 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3050 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3051 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3052 pnDetectedCodePages, lpSpecialChar);
3053 return E_NOTIMPL;
3056 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3057 IMultiLanguage3 *iface,
3058 DWORD dwFlags,
3059 IStream *pStrIn,
3060 UINT *puiPreferredCodePages,
3061 UINT nPreferredCodePages,
3062 UINT *puiDetectedCodePages,
3063 UINT *pnDetectedCodePages,
3064 WCHAR *lpSpecialChar)
3066 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3068 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
3069 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3070 pnDetectedCodePages, lpSpecialChar);
3071 return E_NOTIMPL;
3074 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3076 fnIMultiLanguage3_QueryInterface,
3077 fnIMultiLanguage3_AddRef,
3078 fnIMultiLanguage3_Release,
3079 fnIMultiLanguage3_GetNumberOfCodePageInfo,
3080 fnIMultiLanguage3_GetCodePageInfo,
3081 fnIMultiLanguage3_GetFamilyCodePage,
3082 fnIMultiLanguage3_EnumCodePages,
3083 fnIMultiLanguage3_GetCharsetInfo,
3084 fnIMultiLanguage3_IsConvertible,
3085 fnIMultiLanguage3_ConvertString,
3086 fnIMultiLanguage3_ConvertStringToUnicode,
3087 fnIMultiLanguage3_ConvertStringFromUnicode,
3088 fnIMultiLanguage3_ConvertStringReset,
3089 fnIMultiLanguage3_GetRfc1766FromLcid,
3090 fnIMultiLanguage3_GetLcidFromRfc1766,
3091 fnIMultiLanguage3_EnumRfc1766,
3092 fnIMultiLanguage3_GetRfc1766Info,
3093 fnIMultiLanguage3_CreateConvertCharset,
3094 fnIMultiLanguage3_ConvertStringInIStream,
3095 fnIMultiLanguage3_ConvertStringToUnicodeEx,
3096 fnIMultiLanguage3_ConvertStringFromUnicodeEx,
3097 fnIMultiLanguage3_DetectCodepageInIStream,
3098 fnIMultiLanguage3_DetectInputCodepage,
3099 fnIMultiLanguage3_ValidateCodePage,
3100 fnIMultiLanguage3_GetCodePageDescription,
3101 fnIMultiLanguage3_IsCodePageInstallable,
3102 fnIMultiLanguage3_SetMimeDBSource,
3103 fnIMultiLanguage3_GetNumberOfScripts,
3104 fnIMultiLanguage3_EnumScripts,
3105 fnIMultiLanguage3_ValidateCodePageEx,
3106 fnIMultiLanguage3_DetectOutboundCodePage,
3107 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3110 /******************************************************************************/
3112 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3114 return CONTAINING_RECORD( iface, MLang_impl, IMLangFontLink2_iface );
3117 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3118 IMLangFontLink2 * iface,
3119 REFIID riid,
3120 void** ppvObject)
3122 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3123 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3126 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3128 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3129 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3132 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3134 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3135 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3138 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* iface,
3139 WCHAR ch_src, DWORD *ret_codepages)
3141 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3142 unsigned int i;
3144 TRACE("(%p)->(%s %p)\n", This, debugstr_wn(&ch_src, 1), ret_codepages);
3146 *ret_codepages = 0;
3148 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3150 BOOL used_dc;
3151 CHAR buf;
3153 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
3154 &ch_src, 1, &buf, 1, NULL, &used_dc);
3156 /* If default char is not used, current codepage include the given symbol */
3157 if (!used_dc)
3159 DWORD codepages;
3161 IMLangFontLink2_CodePageToCodePages(iface,
3162 mlang_data[i].family_codepage, &codepages);
3163 *ret_codepages |= codepages;
3166 return S_OK;
3169 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* iface,
3170 const WCHAR *src, LONG src_len, DWORD priority_cp,
3171 DWORD *codepages, LONG *ret_len)
3173 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3174 LONG i;
3175 DWORD cps = 0;
3177 TRACE("(%p)->(%s:%d %x %p %p)\n", This, debugstr_wn(src, src_len), src_len, priority_cp,
3178 codepages, ret_len);
3180 if (codepages) *codepages = 0;
3181 if (ret_len) *ret_len = 0;
3183 if (!src || !src_len || src_len < 0)
3184 return E_INVALIDARG;
3186 for (i = 0; i < src_len; i++)
3188 DWORD cp;
3189 HRESULT ret;
3191 ret = IMLangFontLink2_GetCharCodePages(iface, src[i], &cp);
3192 if (ret != S_OK) return E_FAIL;
3194 if (!cps) cps = cp;
3195 else cps &= cp;
3197 /* FIXME: not tested */
3198 if (priority_cp & cps) break;
3201 if (codepages) *codepages = cps;
3202 if (ret_len) *ret_len = min( i + 1, src_len );
3203 return S_OK;
3206 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* iface,
3207 UINT codepage,
3208 DWORD *codepages)
3210 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3211 CHARSETINFO cs;
3212 BOOL rc;
3214 TRACE("(%p)->(%u %p)\n", This, codepage, codepages);
3216 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)codepage, &cs, TCI_SRCCODEPAGE);
3217 if (rc)
3219 *codepages = cs.fs.fsCsb[0];
3220 TRACE("resulting codepages 0x%x\n", *codepages);
3221 return S_OK;
3224 TRACE("codepage not found\n");
3225 *codepages = 0;
3226 return E_FAIL;
3229 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* iface,
3230 DWORD codepages, UINT def_codepage, UINT *codepage)
3232 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3233 DWORD mask = 0;
3234 CHARSETINFO cs;
3235 BOOL rc;
3236 UINT i;
3238 TRACE("(%p)->(0x%x %u %p)\n", This, codepages, def_codepage, codepage);
3240 *codepage = 0;
3242 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)def_codepage, &cs, TCI_SRCCODEPAGE);
3243 if (rc && (codepages & cs.fs.fsCsb[0]))
3245 TRACE("Found Default Codepage\n");
3246 *codepage = def_codepage;
3247 return S_OK;
3250 for (i = 0; i < 32; i++)
3252 mask = 1 << i;
3253 if (codepages & mask)
3255 DWORD Csb[2];
3256 Csb[0] = mask;
3257 Csb[1] = 0x0;
3258 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
3259 if (!rc)
3260 continue;
3262 TRACE("Falling back to least significant found CodePage %u\n",
3263 cs.ciACP);
3264 *codepage = cs.ciACP;
3265 return S_OK;
3269 TRACE("no codepage found\n");
3270 return E_FAIL;
3273 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2 *iface,
3274 HDC hdc, HFONT hfont, DWORD *codepages)
3276 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3277 FONTSIGNATURE fontsig;
3278 HFONT old_font;
3280 TRACE("(%p)->(%p %p %p)\n", This, hdc, hfont, codepages);
3282 old_font = SelectObject(hdc, hfont);
3283 GetTextCharsetInfo(hdc, &fontsig, 0);
3284 SelectObject(hdc, old_font);
3286 *codepages = fontsig.fsCsb[0];
3287 TRACE("ret 0x%x\n", fontsig.fsCsb[0]);
3289 return S_OK;
3292 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3293 HFONT hFont)
3295 FIXME("(%p)->%p\n",This, hFont);
3296 return E_NOTIMPL;
3299 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3301 FIXME("(%p)->\n",This);
3302 return E_NOTIMPL;
3305 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3306 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3308 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
3309 return E_NOTIMPL;
3312 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3313 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3315 DWORD size;
3316 GLYPHSET *gs;
3318 TRACE("(%p)->%p %p %p\n", This, hDC, puiRanges, pUranges);
3320 if (!puiRanges) return E_INVALIDARG;
3321 if (!(size = GetFontUnicodeRanges(hDC, NULL))) return E_FAIL;
3322 if (!(gs = HeapAlloc(GetProcessHeap(), 0, size))) return E_OUTOFMEMORY;
3324 GetFontUnicodeRanges(hDC, gs);
3325 *puiRanges = gs->cRanges;
3326 if (pUranges)
3328 UINT i;
3329 for (i = 0; i < gs->cRanges; i++)
3331 if (i >= *puiRanges) break;
3332 pUranges[i].wcFrom = gs->ranges[i].wcLow;
3333 pUranges[i].wcTo = gs->ranges[i].wcLow + gs->ranges[i].cGlyphs;
3335 *puiRanges = i;
3337 HeapFree(GetProcessHeap(), 0, gs);
3338 return S_OK;
3341 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3342 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3343 SCRIPTFONTINFO *pScriptFont)
3345 UINT i, j;
3347 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3349 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3351 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3353 if (sid == mlang_data[i].sid)
3355 if (pScriptFont)
3357 if (j >= *puiFonts) break;
3359 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3360 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3362 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3363 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3365 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3367 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3368 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3371 j++;
3374 *puiFonts = j;
3375 return S_OK;
3378 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3379 UINT uiCodePage, SCRIPT_ID *pSid)
3381 UINT i;
3383 TRACE("(%p)->%i %p\n", This, uiCodePage, pSid);
3385 if (uiCodePage == CP_UNICODE) return E_FAIL;
3387 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3389 if (uiCodePage == mlang_data[i].family_codepage)
3391 if (pSid) *pSid = mlang_data[i].sid;
3392 return S_OK;
3395 return E_FAIL;
3398 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3400 fnIMLangFontLink2_QueryInterface,
3401 fnIMLangFontLink2_AddRef,
3402 fnIMLangFontLink2_Release,
3403 fnIMLangFontLink2_GetCharCodePages,
3404 fnIMLangFontLink2_GetStrCodePages,
3405 fnIMLangFontLink2_CodePageToCodePages,
3406 fnIMLangFontLink2_CodePagesToCodePage,
3407 fnIMLangFontLink2_GetFontCodePages,
3408 fnIMLangFontLink2_ReleaseFont,
3409 fnIMLangFontLink2_ResetFontMapping,
3410 fnIMLangFontLink2_MapFont,
3411 fnIMLangFontLink2_GetFontUnicodeRanges,
3412 fnIMLangFontLink2_GetScriptFontInfo,
3413 fnIMLangFontLink2_CodePageToScriptID
3416 /******************************************************************************/
3418 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3420 return CONTAINING_RECORD( iface, MLang_impl, IMLangLineBreakConsole_iface );
3423 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3424 IMLangLineBreakConsole* iface,
3425 REFIID riid,
3426 void** ppvObject)
3428 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3429 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3432 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3433 IMLangLineBreakConsole* iface )
3435 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3436 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3439 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3440 IMLangLineBreakConsole* iface )
3442 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3443 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3446 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3447 IMLangLineBreakConsole* iface,
3448 IMLangString* pSrcMLStr,
3449 LONG lSrcPos,
3450 LONG lSrcLen,
3451 LONG cMinColumns,
3452 LONG cMaxColumns,
3453 LONG* plLineLen,
3454 LONG* plSkipLen)
3456 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3457 return E_NOTIMPL;
3460 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3461 IMLangLineBreakConsole* iface,
3462 LCID locale,
3463 const WCHAR* pszSrc,
3464 LONG cchSrc,
3465 LONG cMaxColumns,
3466 LONG* pcchLine,
3467 LONG* pcchSkip )
3469 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3471 *pcchLine = cchSrc;
3472 *pcchSkip = 0;
3473 return S_OK;
3476 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3477 IMLangLineBreakConsole* iface,
3478 LCID locale,
3479 UINT uCodePage,
3480 const CHAR* pszSrc,
3481 LONG cchSrc,
3482 LONG cMaxColumns,
3483 LONG* pcchLine,
3484 LONG* pcchSkip)
3486 LONG i, line = cchSrc, skip = 0;
3488 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3490 if (uCodePage == CP_USASCII && cchSrc > cMaxColumns)
3492 for (line = cMaxColumns, i = cMaxColumns - 1; i >= 0; i--)
3494 if (pszSrc[i] == ' ')
3496 while (i >= 0 && pszSrc[i] == ' ')
3498 i--;
3499 line--;
3500 skip++;
3502 break;
3506 *pcchLine = line;
3507 *pcchSkip = skip;
3508 return S_OK;
3511 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3513 fnIMLangLineBreakConsole_QueryInterface,
3514 fnIMLangLineBreakConsole_AddRef,
3515 fnIMLangLineBreakConsole_Release,
3516 fnIMLangLineBreakConsole_BreakLineML,
3517 fnIMLangLineBreakConsole_BreakLineW,
3518 fnIMLangLineBreakConsole_BreakLineA
3521 struct convert_charset {
3522 IMLangConvertCharset IMLangConvertCharset_iface;
3523 LONG ref;
3525 UINT src_cp;
3526 UINT dst_cp;
3529 static inline struct convert_charset *impl_from_IMLangConvertCharset(IMLangConvertCharset *iface)
3531 return CONTAINING_RECORD(iface, struct convert_charset, IMLangConvertCharset_iface);
3534 static HRESULT WINAPI MLangConvertCharset_QueryInterface(IMLangConvertCharset *iface, REFIID riid, void **obj)
3536 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3538 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
3540 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMLangConvertCharset))
3542 *obj = &This->IMLangConvertCharset_iface;
3543 IMLangConvertCharset_AddRef(iface);
3544 return S_OK;
3547 *obj = NULL;
3548 return E_NOINTERFACE;
3551 static ULONG WINAPI MLangConvertCharset_AddRef(IMLangConvertCharset *iface)
3553 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3554 ULONG ref = InterlockedIncrement(&This->ref);
3555 TRACE("(%p)->(%u)\n", This, ref);
3556 return ref;
3559 static ULONG WINAPI MLangConvertCharset_Release(IMLangConvertCharset *iface)
3561 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3562 ULONG ref = InterlockedDecrement(&This->ref);
3564 TRACE("(%p)->(%u)\n", This, ref);
3565 if (!ref)
3567 HeapFree(GetProcessHeap(), 0, This);
3568 UnlockModule();
3571 return ref;
3574 static HRESULT WINAPI MLangConvertCharset_Initialize(IMLangConvertCharset *iface,
3575 UINT src_cp, UINT dst_cp, DWORD prop)
3577 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3579 TRACE("(%p)->(%u %u 0x%08x)\n", This, src_cp, dst_cp, prop);
3581 prop &= ~MLCONVCHARF_USEDEFCHAR;
3582 if (prop)
3583 FIXME("property 0x%08x not supported\n", prop);
3585 This->src_cp = src_cp;
3586 This->dst_cp = dst_cp;
3588 return S_OK;
3591 static HRESULT WINAPI MLangConvertCharset_GetSourceCodePage(IMLangConvertCharset *iface, UINT *src_cp)
3593 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3595 TRACE("(%p)->(%p)\n", This, src_cp);
3597 if (!src_cp) return E_INVALIDARG;
3598 *src_cp = This->src_cp;
3599 return S_OK;
3602 static HRESULT WINAPI MLangConvertCharset_GetDestinationCodePage(IMLangConvertCharset *iface, UINT *dst_cp)
3604 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3606 TRACE("(%p)->(%p)\n", This, dst_cp);
3608 if (!dst_cp) return E_INVALIDARG;
3609 *dst_cp = This->dst_cp;
3610 return S_OK;
3613 static HRESULT WINAPI MLangConvertCharset_GetProperty(IMLangConvertCharset *iface, DWORD *prop)
3615 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3616 FIXME("(%p)->(%p): stub\n", This, prop);
3617 return E_NOTIMPL;
3620 static HRESULT WINAPI MLangConvertCharset_DoConversion(IMLangConvertCharset *iface, BYTE *src,
3621 UINT *src_size, BYTE *dest, UINT *dest_size)
3623 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3624 FIXME("(%p)->(%p %p %p %p): stub\n", This, src, src_size, dest, dest_size);
3625 return E_NOTIMPL;
3628 static HRESULT WINAPI MLangConvertCharset_DoConversionToUnicode(IMLangConvertCharset *iface, CHAR *src,
3629 UINT *src_size, WCHAR *dest, UINT *dest_size)
3631 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3632 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3633 return ConvertINetMultiByteToUnicode(NULL, This->src_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3636 static HRESULT WINAPI MLangConvertCharset_DoConversionFromUnicode(IMLangConvertCharset *iface,
3637 WCHAR *src, UINT *src_size, CHAR *dest, UINT *dest_size)
3639 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3640 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3641 return ConvertINetUnicodeToMultiByte(NULL, This->dst_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3644 static const IMLangConvertCharsetVtbl MLangConvertCharsetVtbl =
3646 MLangConvertCharset_QueryInterface,
3647 MLangConvertCharset_AddRef,
3648 MLangConvertCharset_Release,
3649 MLangConvertCharset_Initialize,
3650 MLangConvertCharset_GetSourceCodePage,
3651 MLangConvertCharset_GetDestinationCodePage,
3652 MLangConvertCharset_GetProperty,
3653 MLangConvertCharset_DoConversion,
3654 MLangConvertCharset_DoConversionToUnicode,
3655 MLangConvertCharset_DoConversionFromUnicode
3658 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3660 MLang_impl *mlang;
3661 UINT i;
3663 TRACE("Creating MultiLanguage object\n");
3665 if( pUnkOuter )
3666 return CLASS_E_NOAGGREGATION;
3668 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3669 mlang->IMLangFontLink_iface.lpVtbl = &IMLangFontLink_vtbl;
3670 mlang->IMultiLanguage_iface.lpVtbl = &IMultiLanguage_vtbl;
3671 mlang->IMultiLanguage3_iface.lpVtbl = &IMultiLanguage3_vtbl;
3672 mlang->IMLangFontLink2_iface.lpVtbl = &IMLangFontLink2_vtbl;
3673 mlang->IMLangLineBreakConsole_iface.lpVtbl = &IMLangLineBreakConsole_vtbl;
3675 mlang->total_cp = 0;
3676 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3677 mlang->total_cp += mlang_data[i].number_of_cp;
3679 /* do not enumerate unicode flavours */
3680 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3682 mlang->ref = 1;
3683 *ppObj = &mlang->IMultiLanguage_iface;
3684 TRACE("returning %p\n", mlang);
3686 LockModule();
3688 return S_OK;
3691 static HRESULT MLangConvertCharset_create(IUnknown *outer, void **obj)
3693 struct convert_charset *convert;
3695 if (outer)
3696 return CLASS_E_NOAGGREGATION;
3698 *obj = NULL;
3700 convert = HeapAlloc(GetProcessHeap(), 0, sizeof(struct convert_charset));
3701 if (!convert) return E_OUTOFMEMORY;
3703 convert->IMLangConvertCharset_iface.lpVtbl = &MLangConvertCharsetVtbl;
3704 convert->ref = 1;
3706 *obj = &convert->IMLangConvertCharset_iface;
3708 LockModule();
3710 return S_OK;
3713 /******************************************************************************/
3715 HRESULT WINAPI DllCanUnloadNow(void)
3717 return dll_count == 0 ? S_OK : S_FALSE;
3721 /***********************************************************************
3722 * DllRegisterServer (MLANG.@)
3724 HRESULT WINAPI DllRegisterServer(void)
3726 return __wine_register_resources( instance );
3729 /***********************************************************************
3730 * DllUnregisterServer (MLANG.@)
3732 HRESULT WINAPI DllUnregisterServer(void)
3734 return __wine_unregister_resources( instance );
3737 HRESULT WINAPI GetGlobalFontLinkObject(void **unknown)
3739 if (!unknown) return E_INVALIDARG;
3741 FIXME("%p: stub\n", unknown);
3743 return S_FALSE;