mlang: Mode CodePagesToCodePage() code to IMLangFontLink2 and forward to it.
[wine.git] / dlls / mlang / mlang.c
blob325828af335118f0f3e3d0f6fffbd1b7e7f4e3b9
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"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
45 #include "initguid.h"
47 #define CP_UNICODE 1200
49 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
50 static HRESULT MLangConvertCharset_create(IUnknown *outer, void **obj);
51 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
53 static HINSTANCE instance;
54 static DWORD MLANG_tls_index; /* to store various per thead data */
56 /* FIXME:
57 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
58 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
61 typedef struct
63 const char *description;
64 UINT cp;
65 DWORD flags;
66 const char *web_charset;
67 const char *header_charset;
68 const char *body_charset;
69 } MIME_CP_INFO;
71 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
72 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
74 static const MIME_CP_INFO arabic_cp[] =
76 { "Arabic (864)",
77 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
78 MIMECONTF_MIME_LATEST,
79 "ibm864", "ibm864", "ibm864" },
80 { "Arabic (1006)",
81 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
82 MIMECONTF_MIME_LATEST,
83 "ibm1006", "ibm1006", "ibm1006" },
84 { "Arabic (Windows)",
85 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
86 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
87 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
88 "windows-1256", "windows-1256", "windows-1256" },
89 { "Arabic (ISO)",
90 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
91 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
92 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
93 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
94 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
96 static const MIME_CP_INFO baltic_cp[] =
98 { "Baltic (DOS)",
99 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
100 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
101 "ibm775", "ibm775", "ibm775" },
102 { "Baltic (Windows)",
103 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
104 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
105 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
106 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
107 "windows-1257", "windows-1257", "windows-1257" },
108 { "Baltic (ISO)",
109 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
110 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
111 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
112 MIMECONTF_MIME_LATEST,
113 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
114 { "Estonian (ISO)",
115 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
116 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
117 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
119 static const MIME_CP_INFO chinese_simplified_cp[] =
121 { "Chinese Simplified (GB2312)",
122 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
123 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
124 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
125 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
126 "gb2312", "gb2312", "gb2312" }
128 static const MIME_CP_INFO chinese_traditional_cp[] =
130 { "Chinese Traditional (Big5)",
131 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
132 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
133 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
134 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
135 "big5", "big5", "big5" }
137 static const MIME_CP_INFO central_european_cp[] =
139 { "Central European (DOS)",
140 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
141 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
142 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
143 "ibm852", "ibm852", "ibm852" },
144 { "Central European (Windows)",
145 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
146 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
147 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
148 MIMECONTF_MIME_LATEST,
149 "windows-1250", "windows-1250", "windows-1250" },
150 { "Central European (Mac)",
151 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
152 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
153 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
154 { "Central European (ISO)",
155 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
156 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
157 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
158 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
159 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
161 static const MIME_CP_INFO cyrillic_cp[] =
163 { "OEM Cyrillic",
164 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
165 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
166 "ibm855", "ibm855", "ibm855" },
167 { "Cyrillic (DOS)",
168 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
169 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
170 MIMECONTF_MIME_LATEST,
171 "cp866", "cp866", "cp866" },
172 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
173 { "Cyrillic (KOI8-R)",
174 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
175 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
176 "koi8-r", "koi8-r", "koi8-r" },
177 #endif
178 { "Cyrillic (Windows)",
179 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
180 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
181 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
182 "windows-1251", "windows-1251", "windows-1251" },
183 { "Cyrillic (Mac)",
184 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
185 MIMECONTF_MIME_LATEST,
186 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
187 { "Cyrillic (KOI8-R)",
188 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
189 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
190 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
191 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
192 "koi8-r", "koi8-r", "koi8-r" },
193 { "Cyrillic (KOI8-U)",
194 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
195 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
196 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
197 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
198 "koi8-u", "koi8-u", "koi8-u" },
199 { "Cyrillic (ISO)",
200 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
201 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
202 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
203 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
204 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
206 static const MIME_CP_INFO greek_cp[] =
208 { "Greek (DOS)",
209 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
210 MIMECONTF_MIME_LATEST,
211 "ibm737", "ibm737", "ibm737" },
212 { "Greek, Modern (DOS)",
213 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
214 MIMECONTF_MIME_LATEST,
215 "ibm869", "ibm869", "ibm869" },
216 { "IBM EBCDIC (Greek Modern)",
217 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
218 MIMECONTF_MIME_LATEST,
219 "cp875", "cp875", "cp875" },
220 { "Greek (Windows)",
221 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
222 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
223 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
224 "windows-1253", "windows-1253", "windows-1253" },
225 { "Greek (Mac)",
226 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
227 MIMECONTF_MIME_LATEST,
228 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
229 { "Greek (ISO)",
230 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
231 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
232 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
233 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
234 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
236 static const MIME_CP_INFO hebrew_cp[] =
238 { "Hebrew (424)",
239 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
240 MIMECONTF_MIME_LATEST,
241 "ibm424", "ibm424", "ibm424" },
242 { "Hebrew (856)",
243 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
244 MIMECONTF_MIME_LATEST,
245 "cp856", "cp856", "cp856" },
246 { "Hebrew (DOS)",
247 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
248 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
249 MIMECONTF_MIME_LATEST,
250 "dos-862", "dos-862", "dos-862" },
251 { "Hebrew (Windows)",
252 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
253 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
254 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
255 "windows-1255", "windows-1255", "windows-1255" },
256 { "Hebrew (ISO-Visual)",
257 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
258 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
259 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
260 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
262 static const MIME_CP_INFO japanese_cp[] =
264 { "Japanese (Auto-Select)",
265 50932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
266 MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
267 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
268 "_autodetect", "_autodetect", "_autodetect" },
269 { "Japanese (EUC)",
270 51932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
271 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
272 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
273 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
274 "euc-jp", "euc-jp", "euc-jp" },
275 { "Japanese (JIS)",
276 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
277 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
278 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
279 MIMECONTF_MIME_IE4,
280 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
281 { "Japanese (JIS 0208-1990 and 0212-1990)",
282 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
283 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
284 "EUC-JP","EUC-JP","EUC-JP"},
285 { "Japanese (JIS-Allow 1 byte Kana)",
286 50221, MIMECONTF_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_SAVABLE_BROWSER |
287 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
288 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
289 "csISO2022JP","iso-2022-jp","iso-2022-jp"},
290 { "Japanese (JIS-Allow 1 byte Kana - SO/SI)",
291 50222, MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_VALID |
292 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
293 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
294 { "Japanese (Mac)",
295 10001, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
296 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
297 "x-mac-japanese","x-mac-japanese","x-mac-japanese"},
298 { "Japanese (Shift-JIS)",
299 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
300 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
301 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
302 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
303 "shift_jis", "iso-2022-jp", "iso-2022-jp" }
305 static const MIME_CP_INFO korean_cp[] =
307 { "Korean",
308 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
309 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
310 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
311 MIMECONTF_MIME_LATEST,
312 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
314 static const MIME_CP_INFO thai_cp[] =
316 { "Thai (Windows)",
317 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
318 "ibm-thai", "ibm-thai", "ibm-thai" }
320 static const MIME_CP_INFO turkish_cp[] =
322 { "Turkish (DOS)",
323 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
324 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
325 "ibm857", "ibm857", "ibm857" },
326 { "IBM EBCDIC (Turkish Latin-5)",
327 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
328 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
329 "ibm1026", "ibm1026", "ibm1026" },
330 { "Turkish (Windows)",
331 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
332 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
333 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
334 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
335 "windows-1254", "windows-1254", "windows-1254" },
336 { "Turkish (Mac)",
337 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
338 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
339 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
340 { "Latin 3 (ISO)",
341 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
342 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
343 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
344 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
345 { "Turkish (ISO)",
346 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
347 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
348 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
349 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
350 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
352 static const MIME_CP_INFO vietnamese_cp[] =
354 { "Vietnamese (Windows)",
355 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
356 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
357 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
358 MIMECONTF_MIME_LATEST,
359 "windows-1258", "windows-1258", "windows-1258" }
361 static const MIME_CP_INFO western_cp[] =
363 { "IBM EBCDIC (US-Canada)",
364 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
365 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
366 "ibm037", "ibm037", "ibm037" },
367 { "OEM United States",
368 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
369 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
370 "ibm437", "ibm437", "ibm437" },
371 { "IBM EBCDIC (International)",
372 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
373 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
374 "ibm500", "ibm500", "ibm500" },
375 { "Western European (DOS)",
376 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
377 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
378 "ibm850", "ibm850", "ibm850" },
379 { "Portuguese (DOS)",
380 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
381 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
382 "ibm860", "ibm860", "ibm860" },
383 { "Icelandic (DOS)",
384 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
385 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
386 "ibm861", "ibm861", "ibm861" },
387 { "French Canadian (DOS)",
388 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
389 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
390 "ibm863", "ibm863", "ibm863" },
391 { "Nordic (DOS)",
392 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
393 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
394 "ibm865", "ibm865", "ibm865" },
395 { "Western European (Windows)",
396 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
397 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
398 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
399 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
400 "windows-1252", "windows-1252", "iso-8859-1" },
401 { "Western European (Mac)",
402 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
403 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
404 "macintosh", "macintosh", "macintosh" },
405 { "Icelandic (Mac)",
406 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
407 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
408 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
409 { "US-ASCII",
410 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
411 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
412 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
413 "us-ascii", "us-ascii", "us-ascii" },
414 { "Western European (ISO)",
415 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
416 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
417 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
418 MIMECONTF_MIME_LATEST,
419 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
420 { "Latin 9 (ISO)",
421 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
422 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
423 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
424 MIMECONTF_MIME_LATEST,
425 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
427 static const MIME_CP_INFO unicode_cp[] =
429 { "Unicode",
430 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
431 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
432 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
433 MIMECONTF_MIME_LATEST,
434 "unicode", "unicode", "unicode" },
435 { "Unicode (UTF-7)",
436 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
437 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
438 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
439 "utf-7", "utf-7", "utf-7" },
440 { "Unicode (UTF-8)",
441 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
442 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
443 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
444 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
445 "utf-8", "utf-8", "utf-8" }
448 static const struct mlang_data
450 const char *description;
451 UINT family_codepage;
452 UINT number_of_cp;
453 const MIME_CP_INFO *mime_cp_info;
454 const char *fixed_font;
455 const char *proportional_font;
456 SCRIPT_ID sid;
457 } mlang_data[] =
459 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
460 "Courier","Arial", sidArabic }, /* FIXME */
461 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
462 "Courier","Arial", sidAsciiLatin }, /* FIXME */
463 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
464 "Courier","Arial", sidHan }, /* FIXME */
465 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
466 "Courier","Arial", sidBopomofo }, /* FIXME */
467 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
468 "Courier","Arial", sidAsciiLatin }, /* FIXME */
469 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
470 "Courier","Arial", sidCyrillic }, /* FIXME */
471 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
472 "Courier","Arial", sidGreek }, /* FIXME */
473 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
474 "Courier","Arial", sidHebrew }, /* FIXME */
475 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
476 "MS Gothic","MS PGothic", sidKana },
477 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
478 "Courier","Arial", sidHangul }, /* FIXME */
479 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
480 "Courier","Arial", sidThai }, /* FIXME */
481 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
482 "Courier","Arial", sidAsciiLatin }, /* FIXME */
483 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
484 "Courier","Arial", sidAsciiLatin }, /* FIXME */
485 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
486 "Courier","Arial", sidAsciiLatin }, /* FIXME */
487 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
488 "Courier","Arial" } /* FIXME */
491 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
493 static LONG dll_count;
496 * Japanese Detection and Converstion Functions
499 #define HANKATA(A) ((A >= 161) && (A <= 223))
500 #define ISEUC(A) ((A >= 161) && (A <= 254))
501 #define NOTEUC(A,B) (((A >= 129) && (A <= 159)) && ((B >= 64) && (B <= 160)))
502 #define SJIS1(A) (((A >= 129) && (A <= 159)) || ((A >= 224) && (A <= 239)))
503 #define SJIS2(A) ((A >= 64) && (A <= 252))
504 #define ISMARU(A) ((A >= 202) && (A <= 206))
505 #define ISNIGORI(A) (((A >= 182) && (A <= 196)) || ((A >= 202) && (A <= 206)))
507 static UINT DetectJapaneseCode(LPCSTR input, DWORD count)
509 UINT code = 0;
510 DWORD i = 0;
511 unsigned char c1,c2;
513 while ((code == 0 || code == 51932) && i < count)
515 c1 = input[i];
516 if (c1 == 0x1b /* ESC */)
518 i++;
519 if (i >= count)
520 return code;
521 c1 = input[i];
522 if (c1 == '$')
524 i++;
525 if (i >= count)
526 return code;
527 c1 = input[i];
528 if (c1 =='B' || c1 == '@')
529 code = 50220;
531 if (c1 == 'K')
532 code = 50220;
534 else if (c1 >= 129)
536 i++;
537 if (i >= count)
538 return code;
539 c2 = input[i];
540 if NOTEUC(c1,c2)
541 code = 932;
542 else if (ISEUC(c1) && ISEUC(c2))
543 code = 51932;
544 else if (((c1 == 142)) && HANKATA(c2))
545 code = 51932;
547 i++;
549 return code;
552 static inline void jis2sjis(unsigned char *p1, unsigned char *p2)
554 unsigned char c1 = *p1;
555 unsigned char c2 = *p2;
556 int row = c1 < 95 ? 112 : 176;
557 int cell = c1 % 2 ? 31 + (c2 > 95) : 126;
559 *p1 = ((c1 + 1) >> 1) + row;
560 *p2 = c2 + cell;
563 static inline void sjis2jis(unsigned char *p1, unsigned char *p2)
565 unsigned char c1 = *p1;
566 unsigned char c2 = *p2;
567 int shift = c2 < 159;
568 int row = c1 < 160 ? 112 : 176;
569 int cell = shift ? (31 + (c2 > 127)): 126;
571 *p1 = ((c1 - row) << 1) - shift;
572 *p2 -= cell;
575 static int han2zen(unsigned char *p1, unsigned char *p2)
577 int maru = FALSE;
578 int nigori = FALSE;
579 static const unsigned char char1[] = {129,129,129,129,129,131,131,131,131,
580 131,131,131,131,131,131,129,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,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
583 131,129,129 };
584 static const unsigned char char2[] = {66,117,118,65,69,146,64,66,68,70,
585 72,131,133,135,98,91,65,67,69,71,73,74,76,78,80,82,84,86,88,90,92,94,
586 96,99,101,103,105,106,107,108,109,110,113,116,119,122,125,126,128,
587 129,130,132,134,136,137,138,139,140,141,143,147,74,75};
589 if (( *p2 == 222) && ((ISNIGORI(*p1) || (*p1 == 179))))
590 nigori = TRUE;
591 else if ((*p2 == 223) && (ISMARU(*p1)))
592 maru = TRUE;
594 if (*p1 >= 161 && *p1 <= 223)
596 unsigned char index = *p1 - 161;
597 *p1 = char1[index];
598 *p2 = char2[index];
601 if (maru || nigori)
603 if (nigori)
605 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
606 (*p2)++;
607 else if ((*p1 == 131) && (*p2 == 69))
608 *p2 = 148;
610 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
611 *p2+= 2;
613 return 1;
616 return 0;
620 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
622 DWORD i = 0;
623 int j = 0;
624 unsigned char p2,p;
625 int shifted = FALSE;
627 while (i < count)
629 p = input[i];
630 if (p == 0x1b /* ESC */)
632 i++;
633 if (i >= count)
634 return 0;
635 p2 = input[i];
636 if (p2 == '$' || p2 =='(')
637 i++;
638 if (p2 == 'K' || p2 =='$')
639 shifted = TRUE;
640 else
641 shifted = FALSE;
643 else
645 if (shifted)
647 i++;
648 if (i >= count)
649 return 0;
650 p2 = input[i];
651 jis2sjis(&p,&p2);
652 output[j++]=p;
653 output[j++]=p2;
655 else
657 output[j++] = p;
660 i++;
662 return j;
665 static inline int exit_shift(LPSTR out, int c)
667 if (out)
669 out[c] = 0x1b;
670 out[c+1] = '(';
671 out[c+2] = 'B';
673 return 3;
676 static inline int enter_shift(LPSTR out, int c)
678 if (out)
680 out[c] = 0x1b;
681 out[c+1] = '$';
682 out[c+2] = 'B';
684 return 3;
688 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
690 DWORD i = 0;
691 int j = 0;
692 unsigned char p2,p;
693 int shifted = FALSE;
695 while (i < count)
697 p = input[i] & 0xff;
698 if (p == 10 || p == 13) /* NL and CR */
700 if (shifted)
702 shifted = FALSE;
703 j += exit_shift(output,j);
705 if (output)
706 output[j++] = p;
707 else
708 j++;
710 else
712 if (SJIS1(p))
714 i++;
715 if (i >= count)
716 return 0;
717 p2 = input[i] & 0xff;
718 if (SJIS2(p2))
720 sjis2jis(&p,&p2);
721 if (!shifted)
723 shifted = TRUE;
724 j+=enter_shift(output,j);
728 if (output)
730 output[j++]=p;
731 output[j++]=p2;
733 else
734 j+=2;
736 else
738 if (HANKATA(p))
740 if ((i+1) >= count)
741 return 0;
742 p2 = input[i+1] & 0xff;
743 i+=han2zen(&p,&p2);
744 sjis2jis(&p,&p2);
745 if (!shifted)
747 shifted = TRUE;
748 j+=enter_shift(output,j);
750 if (output)
752 output[j++]=p;
753 output[j++]=p2;
755 else
756 j+=2;
758 else
760 if (shifted)
762 shifted = FALSE;
763 j += exit_shift(output,j);
765 if (output)
766 output[j++]=p;
767 else
768 j++;
772 i++;
774 if (shifted)
775 j += exit_shift(output,j);
776 return j;
779 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
780 LPWSTR output, DWORD out_count)
782 CHAR *sjis_string;
783 UINT rc = 0;
784 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
785 rc = ConvertJIS2SJIS(input,count,sjis_string);
786 if (rc)
788 TRACE("%s\n",debugstr_an(sjis_string,rc));
789 if (output)
790 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
791 else
792 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
794 HeapFree(GetProcessHeap(),0,sjis_string);
795 return rc;
799 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
800 LPWSTR output, DWORD out_count)
802 CHAR *sjis_string;
803 UINT rc = 0;
804 int code = DetectJapaneseCode(input,count);
805 TRACE("Japanese code %i\n",code);
807 switch (code)
809 case 0:
810 if (output)
811 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
812 else
813 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
814 break;
816 case 932:
817 if (output)
818 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
819 else
820 rc = MultiByteToWideChar(932,0,input,count,0,0);
821 break;
823 case 51932:
824 if (output)
825 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
826 else
827 rc = MultiByteToWideChar(20932,0,input,count,0,0);
828 break;
830 case 50220:
831 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
832 rc = ConvertJIS2SJIS(input,count,sjis_string);
833 if (rc)
835 TRACE("%s\n",debugstr_an(sjis_string,rc));
836 if (output)
837 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
838 else
839 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
841 HeapFree(GetProcessHeap(),0,sjis_string);
842 break;
844 return rc;
847 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
848 LPSTR output, DWORD out_count)
850 CHAR *sjis_string;
851 INT len;
852 UINT rc = 0;
854 len = WideCharToMultiByte(932,0,input,count,0,0,NULL,NULL);
855 sjis_string = HeapAlloc(GetProcessHeap(),0,len);
856 WideCharToMultiByte(932,0,input,count,sjis_string,len,NULL,NULL);
857 TRACE("%s\n",debugstr_an(sjis_string,len));
859 rc = ConvertSJIS2JIS(sjis_string, len, NULL);
860 if (out_count >= rc)
862 ConvertSJIS2JIS(sjis_string, len, output);
864 HeapFree(GetProcessHeap(),0,sjis_string);
865 return rc;
870 * Dll lifetime tracking declaration
872 static void LockModule(void)
874 InterlockedIncrement(&dll_count);
877 static void UnlockModule(void)
879 InterlockedDecrement(&dll_count);
882 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
884 switch(fdwReason) {
885 case DLL_PROCESS_ATTACH:
886 instance = hInstDLL;
887 MLANG_tls_index = TlsAlloc();
888 DisableThreadLibraryCalls(hInstDLL);
889 break;
890 case DLL_PROCESS_DETACH:
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: stub!\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 chSrc,
1832 DWORD* pdwCodePages)
1834 int i;
1835 CHAR buf;
1836 BOOL used_dc;
1837 DWORD codePages;
1839 *pdwCodePages = 0;
1841 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1843 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
1844 &chSrc, 1, &buf, 1, NULL, &used_dc);
1846 /* If default char is not used, current codepage include the given symbol */
1847 if (!used_dc)
1849 IMLangFontLink_CodePageToCodePages(iface,
1850 mlang_data[i].family_codepage, &codePages);
1851 *pdwCodePages |= codePages;
1854 return S_OK;
1857 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1858 IMLangFontLink* iface,
1859 const WCHAR* pszSrc,
1860 LONG cchSrc,
1861 DWORD dwPriorityCodePages,
1862 DWORD* pdwCodePages,
1863 LONG* pcchCodePages)
1865 LONG i;
1866 DWORD cps = 0;
1868 TRACE("(%p)->%s %d %x %p %p\n", iface, debugstr_wn(pszSrc, cchSrc), cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
1870 if (pdwCodePages) *pdwCodePages = 0;
1871 if (pcchCodePages) *pcchCodePages = 0;
1873 if (!pszSrc || !cchSrc || cchSrc < 0)
1874 return E_INVALIDARG;
1876 for (i = 0; i < cchSrc; i++)
1878 DWORD cp;
1879 HRESULT ret;
1881 ret = IMLangFontLink_GetCharCodePages(iface, pszSrc[i], &cp);
1882 if (ret != S_OK) return E_FAIL;
1884 if (!cps) cps = cp;
1885 else cps &= cp;
1887 /* FIXME: not tested */
1888 if (dwPriorityCodePages & cps) break;
1891 if (pdwCodePages) *pdwCodePages = cps;
1892 if (pcchCodePages) *pcchCodePages = min( i + 1, cchSrc );
1893 return S_OK;
1896 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1897 IMLangFontLink* iface,
1898 UINT uCodePage,
1899 DWORD* pdwCodePages)
1901 MLang_impl *This = impl_from_IMLangFontLink( iface );
1902 CHARSETINFO cs;
1903 BOOL rc;
1905 TRACE("(%p) Seeking %u\n",This, uCodePage);
1907 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)uCodePage, &cs, TCI_SRCCODEPAGE);
1909 if (rc)
1911 *pdwCodePages = cs.fs.fsCsb[0];
1912 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1913 return S_OK;
1916 TRACE("CodePage Not Found\n");
1917 *pdwCodePages = 0;
1918 return E_FAIL;
1921 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1922 IMLangFontLink* iface,
1923 DWORD codepages,
1924 UINT def_codepage,
1925 UINT* codepage)
1927 MLang_impl *This = impl_from_IMLangFontLink(iface);
1928 return IMLangFontLink2_CodePagesToCodePage(&This->IMLangFontLink2_iface, codepages,
1929 def_codepage, codepage);
1932 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
1933 IMLangFontLink* iface,
1934 HDC hdc,
1935 HFONT hfont,
1936 DWORD* codepages)
1938 MLang_impl *This = impl_from_IMLangFontLink(iface);
1939 return IMLangFontLink2_GetFontCodePages(&This->IMLangFontLink2_iface, hdc, hfont, codepages);
1942 static HRESULT WINAPI fnIMLangFontLink_MapFont(
1943 IMLangFontLink* iface,
1944 HDC hDC,
1945 DWORD dwCodePages,
1946 HFONT hSrcFont,
1947 HFONT* phDestFont)
1949 FIXME("\n");
1950 return E_NOTIMPL;
1953 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
1954 IMLangFontLink* iface,
1955 HFONT hFont)
1957 FIXME("\n");
1958 return E_NOTIMPL;
1961 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
1962 IMLangFontLink* iface)
1964 FIXME("\n");
1965 return E_NOTIMPL;
1969 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
1971 fnIMLangFontLink_QueryInterface,
1972 fnIMLangFontLink_AddRef,
1973 fnIMLangFontLink_Release,
1974 fnIMLangFontLink_GetCharCodePages,
1975 fnIMLangFontLink_GetStrCodePages,
1976 fnIMLangFontLink_CodePageToCodePages,
1977 fnIMLangFontLink_CodePagesToCodePage,
1978 fnIMLangFontLink_GetFontCodePages,
1979 fnIMLangFontLink_MapFont,
1980 fnIMLangFontLink_ReleaseFont,
1981 fnIMLangFontLink_ResetFontMapping,
1984 /******************************************************************************/
1986 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
1988 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage_iface );
1991 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
1992 IMultiLanguage* iface,
1993 REFIID riid,
1994 void** obj)
1996 MLang_impl *This = impl_from_IMultiLanguage( iface );
1997 return IMultiLanguage3_QueryInterface(&This->IMultiLanguage3_iface, riid, obj);
2000 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
2002 MLang_impl *This = impl_from_IMultiLanguage( iface );
2003 return IMultiLanguage3_AddRef(&This->IMultiLanguage3_iface);
2006 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
2008 MLang_impl *This = impl_from_IMultiLanguage( iface );
2009 return IMultiLanguage3_Release(&This->IMultiLanguage3_iface);
2012 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
2013 IMultiLanguage* iface,
2014 UINT* cp)
2016 MLang_impl *This = impl_from_IMultiLanguage( iface );
2017 TRACE("(%p, %p)\n", This, cp);
2018 return IMultiLanguage3_GetNumberOfCodePageInfo(&This->IMultiLanguage3_iface, cp);
2021 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
2022 IMultiLanguage* iface,
2023 UINT uiCodePage,
2024 PMIMECPINFO pCodePageInfo)
2026 UINT i, n;
2027 MLang_impl *This = impl_from_IMultiLanguage( iface );
2029 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
2031 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2033 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2035 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2037 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2038 return S_OK;
2043 return S_FALSE;
2046 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
2047 IMultiLanguage* iface,
2048 UINT cp,
2049 UINT* family_cp)
2051 MLang_impl *This = impl_from_IMultiLanguage( iface );
2052 return IMultiLanguage3_GetFamilyCodePage(&This->IMultiLanguage3_iface, cp, family_cp);
2055 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
2056 IMultiLanguage* iface,
2057 DWORD grfFlags,
2058 IEnumCodePage** ppEnumCodePage)
2060 MLang_impl *This = impl_from_IMultiLanguage( iface );
2062 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2064 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2067 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2068 IMultiLanguage* iface,
2069 BSTR Charset,
2070 PMIMECSETINFO pCharsetInfo)
2072 MLang_impl *This = impl_from_IMultiLanguage( iface );
2073 return IMultiLanguage3_GetCharsetInfo( &This->IMultiLanguage3_iface, Charset, pCharsetInfo );
2076 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2077 IMultiLanguage* iface,
2078 DWORD src_enc,
2079 DWORD dst_enc)
2081 MLang_impl *This = impl_from_IMultiLanguage( iface );
2082 return IMultiLanguage3_IsConvertible(&This->IMultiLanguage3_iface, src_enc, dst_enc);
2085 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2086 IMultiLanguage* iface,
2087 DWORD* mode,
2088 DWORD src_enc,
2089 DWORD dst_enc,
2090 BYTE* src,
2091 UINT* src_size,
2092 BYTE* dest,
2093 UINT* dest_size)
2095 MLang_impl *This = impl_from_IMultiLanguage( iface );
2096 return IMultiLanguage3_ConvertString(&This->IMultiLanguage3_iface, mode, src_enc,
2097 dst_enc, src, src_size, dest, dest_size);
2100 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2101 IMultiLanguage* iface,
2102 DWORD* mode,
2103 DWORD src_enc,
2104 CHAR* src,
2105 UINT* src_size,
2106 WCHAR* dest,
2107 UINT* dest_size)
2109 MLang_impl *This = impl_from_IMultiLanguage( iface );
2110 return IMultiLanguage3_ConvertStringToUnicode(&This->IMultiLanguage3_iface,
2111 mode, src_enc, src, src_size, dest, dest_size);
2114 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2115 IMultiLanguage* iface,
2116 DWORD* mode,
2117 DWORD encoding,
2118 WCHAR* src,
2119 UINT* src_size,
2120 CHAR* dest,
2121 UINT* dest_size)
2123 MLang_impl *This = impl_from_IMultiLanguage(iface);
2124 return IMultiLanguage3_ConvertStringFromUnicode(&This->IMultiLanguage3_iface,
2125 mode, encoding, src, src_size, dest, dest_size);
2128 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2129 IMultiLanguage* iface)
2131 MLang_impl *This = impl_from_IMultiLanguage( iface );
2132 return IMultiLanguage3_ConvertStringReset(&This->IMultiLanguage3_iface);
2135 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2136 IMultiLanguage* iface,
2137 LCID lcid,
2138 BSTR* pbstrRfc1766)
2140 MLang_impl *This = impl_from_IMultiLanguage(iface);
2141 return IMultiLanguage3_GetRfc1766FromLcid(&This->IMultiLanguage3_iface, lcid, pbstrRfc1766);
2144 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2145 IMultiLanguage* iface,
2146 LCID* locale,
2147 BSTR rfc1766)
2149 MLang_impl *This = impl_from_IMultiLanguage(iface);
2150 return IMultiLanguage3_GetLcidFromRfc1766(&This->IMultiLanguage3_iface, locale, rfc1766);
2153 /******************************************************************************/
2155 typedef struct tagEnumRfc1766_impl
2157 IEnumRfc1766 IEnumRfc1766_iface;
2158 LONG ref;
2159 RFC1766INFO *info;
2160 DWORD total, pos;
2161 } EnumRfc1766_impl;
2163 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2165 return CONTAINING_RECORD( iface, EnumRfc1766_impl, IEnumRfc1766_iface );
2168 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2169 IEnumRfc1766 *iface,
2170 REFIID riid,
2171 void** ppvObject)
2173 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2175 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2177 if (IsEqualGUID(riid, &IID_IUnknown)
2178 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2180 IEnumRfc1766_AddRef(iface);
2181 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2182 *ppvObject = &This->IEnumRfc1766_iface;
2183 return S_OK;
2186 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2187 return E_NOINTERFACE;
2190 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2191 IEnumRfc1766 *iface)
2193 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2194 return InterlockedIncrement(&This->ref);
2197 static ULONG WINAPI fnIEnumRfc1766_Release(
2198 IEnumRfc1766 *iface)
2200 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2201 ULONG ref = InterlockedDecrement(&This->ref);
2203 TRACE("%p ref = %d\n", This, ref);
2204 if (ref == 0)
2206 TRACE("Destroying %p\n", This);
2207 HeapFree(GetProcessHeap(), 0, This->info);
2208 HeapFree(GetProcessHeap(), 0, This);
2210 return ref;
2213 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2214 IEnumRfc1766 *iface,
2215 IEnumRfc1766 **ppEnum)
2217 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2219 FIXME("%p %p\n", This, ppEnum);
2220 return E_NOTIMPL;
2223 static HRESULT WINAPI fnIEnumRfc1766_Next(
2224 IEnumRfc1766 *iface,
2225 ULONG celt,
2226 PRFC1766INFO rgelt,
2227 ULONG *pceltFetched)
2229 ULONG i;
2230 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2232 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2234 if (!pceltFetched) return S_FALSE;
2235 *pceltFetched = 0;
2237 if (!rgelt) return S_FALSE;
2239 if (This->pos + celt > This->total)
2240 celt = This->total - This->pos;
2242 if (!celt) return S_FALSE;
2244 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2245 *pceltFetched = celt;
2246 This->pos += celt;
2248 for (i = 0; i < celt; i++)
2250 TRACE("#%u: %08x %s %s\n",
2251 i, rgelt[i].lcid,
2252 wine_dbgstr_w(rgelt[i].wszRfc1766),
2253 wine_dbgstr_w(rgelt[i].wszLocaleName));
2255 return S_OK;
2258 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2259 IEnumRfc1766 *iface)
2261 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2263 TRACE("%p\n", This);
2265 This->pos = 0;
2266 return S_OK;
2269 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2270 IEnumRfc1766 *iface,
2271 ULONG celt)
2273 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2275 TRACE("%p %u\n", This, celt);
2277 if (celt >= This->total) return S_FALSE;
2279 This->pos += celt;
2280 return S_OK;
2283 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2285 fnIEnumRfc1766_QueryInterface,
2286 fnIEnumRfc1766_AddRef,
2287 fnIEnumRfc1766_Release,
2288 fnIEnumRfc1766_Clone,
2289 fnIEnumRfc1766_Next,
2290 fnIEnumRfc1766_Reset,
2291 fnIEnumRfc1766_Skip
2294 struct enum_locales_data
2296 RFC1766INFO *info;
2297 DWORD total, allocated;
2300 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2302 WCHAR *end;
2303 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2304 RFC1766INFO *info;
2306 TRACE("%s\n", debugstr_w(locale));
2308 if (data->total >= data->allocated)
2310 data->allocated += 32;
2311 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2312 if (!data->info) return FALSE;
2315 info = &data->info[data->total];
2317 info->lcid = strtolW(locale, &end, 16);
2318 if (*end) /* invalid number */
2319 return FALSE;
2321 info->wszRfc1766[0] = 0;
2322 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2324 info->wszLocaleName[0] = 0;
2325 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2326 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2328 data->total++;
2330 return TRUE;
2333 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2335 EnumRfc1766_impl *rfc;
2336 struct enum_locales_data data;
2338 TRACE("%04x, %p\n", LangId, ppEnum);
2340 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2341 rfc->IEnumRfc1766_iface.lpVtbl = &IEnumRfc1766_vtbl;
2342 rfc->ref = 1;
2343 rfc->pos = 0;
2344 rfc->total = 0;
2346 data.total = 0;
2347 data.allocated = 160;
2348 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2349 if (!data.info)
2351 HeapFree(GetProcessHeap(), 0, rfc);
2352 return E_OUTOFMEMORY;
2355 TlsSetValue(MLANG_tls_index, &data);
2356 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2357 TlsSetValue(MLANG_tls_index, NULL);
2359 TRACE("enumerated %d rfc1766 structures\n", data.total);
2361 if (!data.total)
2363 HeapFree(GetProcessHeap(), 0, data.info);
2364 HeapFree(GetProcessHeap(), 0, rfc);
2365 return E_FAIL;
2368 rfc->info = data.info;
2369 rfc->total = data.total;
2371 *ppEnum = &rfc->IEnumRfc1766_iface;
2372 return S_OK;
2375 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2376 IMultiLanguage *iface,
2377 IEnumRfc1766 **ppEnumRfc1766)
2379 MLang_impl *This = impl_from_IMultiLanguage( iface );
2381 TRACE("%p %p\n", This, ppEnumRfc1766);
2383 return EnumRfc1766_create(0, ppEnumRfc1766);
2386 /******************************************************************************/
2388 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2389 IMultiLanguage* iface,
2390 LCID Locale,
2391 PRFC1766INFO pRfc1766Info)
2393 LCTYPE type = LOCALE_SLANGUAGE;
2395 TRACE("(%p, 0x%04x, %p)\n", iface, Locale, pRfc1766Info);
2397 if (!pRfc1766Info)
2398 return E_INVALIDARG;
2400 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2401 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2402 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2404 if (!SUBLANGID(Locale))
2405 type = LOCALE_SENGLANGUAGE; /* suppress country */
2407 else
2409 if (!SUBLANGID(Locale)) {
2410 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2411 return E_FAIL;
2415 pRfc1766Info->lcid = Locale;
2416 pRfc1766Info->wszRfc1766[0] = 0;
2417 pRfc1766Info->wszLocaleName[0] = 0;
2419 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2420 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2421 return S_OK;
2423 /* Locale not supported */
2424 return E_INVALIDARG;
2427 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2428 IMultiLanguage* iface,
2429 UINT src_cp,
2430 UINT dst_cp,
2431 DWORD prop,
2432 IMLangConvertCharset** convert_charset)
2434 MLang_impl *This = impl_from_IMultiLanguage(iface);
2435 return IMultiLanguage3_CreateConvertCharset(&This->IMultiLanguage3_iface, src_cp, dst_cp, prop, convert_charset);
2438 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2440 fnIMultiLanguage_QueryInterface,
2441 fnIMultiLanguage_AddRef,
2442 fnIMultiLanguage_Release,
2443 fnIMultiLanguage_GetNumberOfCodePageInfo,
2444 fnIMultiLanguage_GetCodePageInfo,
2445 fnIMultiLanguage_GetFamilyCodePage,
2446 fnIMultiLanguage_EnumCodePages,
2447 fnIMultiLanguage_GetCharsetInfo,
2448 fnIMultiLanguage_IsConvertible,
2449 fnIMultiLanguage_ConvertString,
2450 fnIMultiLanguage_ConvertStringToUnicode,
2451 fnIMultiLanguage_ConvertStringFromUnicode,
2452 fnIMultiLanguage_ConvertStringReset,
2453 fnIMultiLanguage_GetRfc1766FromLcid,
2454 fnIMultiLanguage_GetLcidFromRfc1766,
2455 fnIMultiLanguage_EnumRfc1766,
2456 fnIMultiLanguage_GetRfc1766Info,
2457 fnIMultiLanguage_CreateConvertCharset,
2461 /******************************************************************************/
2463 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2465 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage3_iface );
2468 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
2469 IMultiLanguage3* iface,
2470 REFIID riid,
2471 void** obj)
2473 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2475 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
2477 if (IsEqualGUID(riid, &IID_IUnknown) ||
2478 IsEqualGUID(riid, &IID_IMultiLanguage))
2480 *obj = &This->IMultiLanguage_iface;
2482 else if (IsEqualGUID(riid, &IID_IMLangCodePages) ||
2483 IsEqualGUID(riid, &IID_IMLangFontLink))
2485 *obj = &This->IMLangFontLink_iface;
2487 else if (IsEqualGUID(riid, &IID_IMLangFontLink2))
2489 *obj = &This->IMLangFontLink2_iface;
2491 else if (IsEqualGUID(riid, &IID_IMultiLanguage2) ||
2492 IsEqualGUID(riid, &IID_IMultiLanguage3))
2494 *obj = &This->IMultiLanguage3_iface;
2496 else if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
2498 *obj = &This->IMLangLineBreakConsole_iface;
2500 else
2502 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), obj);
2503 *obj = NULL;
2504 return E_NOINTERFACE;
2507 IMultiLanguage3_AddRef(iface);
2508 return S_OK;
2511 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2513 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2514 return InterlockedIncrement(&This->ref);
2517 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2519 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2520 ULONG ref = InterlockedDecrement(&This->ref);
2522 TRACE("(%p)->(%d)\n", This, ref);
2523 if (ref == 0)
2525 HeapFree(GetProcessHeap(), 0, This);
2526 UnlockModule();
2529 return ref;
2532 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2533 IMultiLanguage3* iface,
2534 UINT* pcCodePage)
2536 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2538 TRACE("%p, %p\n", This, pcCodePage);
2540 if (!pcCodePage) return E_INVALIDARG;
2542 *pcCodePage = This->total_cp;
2543 return S_OK;
2546 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2548 CHARSETINFO csi;
2550 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2551 TCI_SRCCODEPAGE))
2552 mime_cp_info->bGDICharset = csi.ciCharset;
2553 else
2554 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2556 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2557 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2558 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2559 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2560 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2561 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2562 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2563 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2564 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2565 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2566 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2568 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2569 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2570 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2571 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2573 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2574 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2575 mime_cp_info->uiFamilyCodePage,
2576 wine_dbgstr_w(mime_cp_info->wszDescription),
2577 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2578 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2579 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2580 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2581 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2582 mime_cp_info->bGDICharset);
2585 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2586 IMultiLanguage3* iface,
2587 UINT uiCodePage,
2588 LANGID LangId,
2589 PMIMECPINFO pCodePageInfo)
2591 UINT i, n;
2592 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2594 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2596 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2598 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2600 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2602 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2603 return S_OK;
2608 return S_FALSE;
2611 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2612 IMultiLanguage3* iface,
2613 UINT uiCodePage,
2614 UINT* puiFamilyCodePage)
2616 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2619 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2620 IMultiLanguage3* iface,
2621 DWORD grfFlags,
2622 LANGID LangId,
2623 IEnumCodePage** ppEnumCodePage)
2625 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2627 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2629 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2632 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2633 IMultiLanguage3* iface,
2634 BSTR Charset,
2635 PMIMECSETINFO pCharsetInfo)
2637 UINT i, n;
2638 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2640 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2642 if (!pCharsetInfo) return E_FAIL;
2644 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2646 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2648 WCHAR csetW[MAX_MIMECSET_NAME];
2650 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2651 if (!lstrcmpiW(Charset, csetW))
2653 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2654 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2655 strcpyW(pCharsetInfo->wszCharset, csetW);
2656 return S_OK;
2661 /* FIXME:
2662 * Since we do not support charsets like iso-2022-jp and do not have
2663 * them in our database as a primary (web_charset) encoding this loop
2664 * does an attempt to 'approximate' charset name by header_charset.
2666 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2668 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2670 WCHAR csetW[MAX_MIMECSET_NAME];
2672 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2673 if (!lstrcmpiW(Charset, csetW))
2675 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2676 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2677 strcpyW(pCharsetInfo->wszCharset, csetW);
2678 return S_OK;
2683 return E_FAIL;
2686 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2687 IMultiLanguage3* iface,
2688 DWORD dwSrcEncoding,
2689 DWORD dwDstEncoding)
2691 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2694 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2695 IMultiLanguage3* iface,
2696 DWORD* pdwMode,
2697 DWORD dwSrcEncoding,
2698 DWORD dwDstEncoding,
2699 BYTE* pSrcStr,
2700 UINT* pcSrcSize,
2701 BYTE* pDstStr,
2702 UINT* pcDstSize)
2704 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2705 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2708 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2709 IMultiLanguage3* iface,
2710 DWORD* pdwMode,
2711 DWORD dwEncoding,
2712 CHAR* pSrcStr,
2713 UINT* pcSrcSize,
2714 WCHAR* pDstStr,
2715 UINT* pcDstSize)
2717 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2718 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2721 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2722 IMultiLanguage3* iface,
2723 DWORD* pdwMode,
2724 DWORD dwEncoding,
2725 WCHAR* pSrcStr,
2726 UINT* pcSrcSize,
2727 CHAR* pDstStr,
2728 UINT* pcDstSize)
2730 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2731 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2734 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2735 IMultiLanguage3* iface)
2737 FIXME("\n");
2738 return E_NOTIMPL;
2741 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2742 IMultiLanguage3* iface,
2743 LCID lcid,
2744 BSTR* pbstrRfc1766)
2746 WCHAR buf[MAX_RFC1766_NAME];
2748 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2749 if (!pbstrRfc1766)
2750 return E_INVALIDARG;
2752 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2754 *pbstrRfc1766 = SysAllocString( buf );
2755 return S_OK;
2757 return E_FAIL;
2760 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2761 IMultiLanguage3* iface,
2762 LCID* pLocale,
2763 BSTR bstrRfc1766)
2765 HRESULT hr;
2766 IEnumRfc1766 *rfc1766;
2768 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2770 if (!pLocale || !bstrRfc1766)
2771 return E_INVALIDARG;
2773 hr = IMultiLanguage3_EnumRfc1766(iface, 0, &rfc1766);
2774 if (FAILED(hr))
2775 return hr;
2777 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2779 IEnumRfc1766_Release(rfc1766);
2780 return hr;
2783 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2784 IMultiLanguage3* iface,
2785 LANGID LangId,
2786 IEnumRfc1766** ppEnumRfc1766)
2788 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2790 TRACE("%p %p\n", This, ppEnumRfc1766);
2792 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2795 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2796 IMultiLanguage3* iface,
2797 LCID Locale,
2798 LANGID LangId,
2799 PRFC1766INFO pRfc1766Info)
2801 static LANGID last_lang = -1;
2802 LCTYPE type = LOCALE_SLANGUAGE;
2804 TRACE("(%p, 0x%04x, 0x%04x, %p)\n", iface, Locale, LangId, pRfc1766Info);
2806 if (!pRfc1766Info)
2807 return E_INVALIDARG;
2809 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2810 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2811 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2813 if (!SUBLANGID(Locale))
2814 type = LOCALE_SENGLANGUAGE; /* suppress country */
2816 else
2818 if (!SUBLANGID(Locale)) {
2819 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2820 return E_FAIL;
2824 pRfc1766Info->lcid = Locale;
2825 pRfc1766Info->wszRfc1766[0] = 0;
2826 pRfc1766Info->wszLocaleName[0] = 0;
2828 if ((PRIMARYLANGID(LangId) != LANG_ENGLISH) &&
2829 (last_lang != LangId)) {
2830 FIXME("Only English names supported (requested: 0x%04x)\n", LangId);
2831 last_lang = LangId;
2834 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2835 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2836 return S_OK;
2838 /* Locale not supported */
2839 return E_INVALIDARG;
2842 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2843 IMultiLanguage3* iface,
2844 UINT src_cp,
2845 UINT dst_cp,
2846 DWORD prop,
2847 IMLangConvertCharset** convert_charset)
2849 HRESULT hr;
2851 TRACE("(%u %u 0x%08x %p)\n", src_cp, dst_cp, prop, convert_charset);
2853 hr = MLangConvertCharset_create(NULL, (void**)convert_charset);
2854 if (FAILED(hr)) return hr;
2856 return IMLangConvertCharset_Initialize(*convert_charset, src_cp, dst_cp, prop);
2859 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2860 IMultiLanguage3* iface,
2861 DWORD* pdwMode,
2862 DWORD dwFlag,
2863 WCHAR* lpFallBack,
2864 DWORD dwSrcEncoding,
2865 DWORD dwDstEncoding,
2866 IStream* pstmIn,
2867 IStream* pstmOut)
2869 char *src, *dst = NULL;
2870 INT srclen, dstlen;
2871 STATSTG stat;
2872 HRESULT hr;
2874 TRACE("%p %0x8 %s %u %u %p %p\n",
2875 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2877 FIXME("dwFlag and lpFallBack not handled\n");
2879 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2880 if (FAILED(hr)) return hr;
2882 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
2883 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
2885 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
2886 if (FAILED(hr)) goto exit;
2888 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
2889 if (FAILED(hr)) goto exit;
2891 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
2893 hr = E_OUTOFMEMORY;
2894 goto exit;
2896 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
2897 if (FAILED(hr)) goto exit;
2899 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
2901 exit:
2902 HeapFree(GetProcessHeap(), 0, src);
2903 HeapFree(GetProcessHeap(), 0, dst);
2904 return hr;
2907 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
2908 IMultiLanguage3* iface,
2909 DWORD* pdwMode,
2910 DWORD dwEncoding,
2911 CHAR* pSrcStr,
2912 UINT* pcSrcSize,
2913 WCHAR* pDstStr,
2914 UINT* pcDstSize,
2915 DWORD dwFlag,
2916 WCHAR* lpFallBack)
2918 if (dwFlag || lpFallBack)
2919 FIXME("Ignoring dwFlag (0x%x/%d) and lpFallBack (%p)\n",
2920 dwFlag, dwFlag, lpFallBack);
2922 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2923 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2926 /*****************************************************************************
2927 * MultiLanguage2::ConvertStringToUnicodeEx
2929 * Translates the multibyte string from the specified code page to Unicode.
2931 * PARAMS
2932 * see ConvertStringToUnicode
2933 * dwFlag
2934 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2935 * instead unconvertible characters.
2937 * RETURNS
2938 * S_OK Success.
2939 * S_FALSE The conversion is not supported.
2940 * E_FAIL Some error has occurred.
2942 * TODO: handle dwFlag and lpFallBack
2944 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
2945 IMultiLanguage3* This,
2946 DWORD* pdwMode,
2947 DWORD dwEncoding,
2948 WCHAR* pSrcStr,
2949 UINT* pcSrcSize,
2950 CHAR* pDstStr,
2951 UINT* pcDstSize,
2952 DWORD dwFlag,
2953 WCHAR* lpFallBack)
2955 FIXME("\n");
2956 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2957 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2960 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
2961 IMultiLanguage3* iface,
2962 DWORD dwFlag,
2963 DWORD dwPrefWinCodePage,
2964 IStream* pstmIn,
2965 DetectEncodingInfo* lpEncoding,
2966 INT* pnScores)
2968 FIXME("\n");
2969 return E_NOTIMPL;
2972 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
2973 IMultiLanguage3* iface,
2974 DWORD dwFlag,
2975 DWORD dwPrefWinCodePage,
2976 CHAR* pSrcStr,
2977 INT* pcSrcSize,
2978 DetectEncodingInfo* lpEncoding,
2979 INT* pnScores)
2981 FIXME("\n");
2982 return E_NOTIMPL;
2985 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
2986 IMultiLanguage3* iface,
2987 UINT uiCodePage,
2988 HWND hwnd)
2990 return IMultiLanguage3_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
2993 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
2994 IMultiLanguage3* iface,
2995 UINT uiCodePage,
2996 LCID lcid,
2997 LPWSTR lpWideCharStr,
2998 int cchWideChar)
3000 /* Find first instance */
3001 unsigned int i,n;
3003 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
3004 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3006 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3008 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3010 MultiByteToWideChar(CP_ACP, 0,
3011 mlang_data[i].mime_cp_info[n].description,
3012 -1, lpWideCharStr, cchWideChar);
3013 return S_OK;
3018 return S_FALSE;
3021 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
3022 IMultiLanguage3* iface,
3023 UINT uiCodePage)
3025 TRACE("%u\n", uiCodePage);
3027 /* FIXME: the installable set is usually larger than the set of valid codepages */
3028 return IMultiLanguage3_ValidateCodePageEx(iface, uiCodePage, NULL, CPIOD_PEEK);
3031 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
3032 IMultiLanguage3* iface,
3033 MIMECONTF dwSource)
3035 FIXME("0x%08x\n", dwSource);
3036 return S_OK;
3039 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
3040 IMultiLanguage3* iface,
3041 UINT* pnScripts)
3043 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3045 TRACE("%p %p\n", This, pnScripts);
3047 if (!pnScripts) return S_FALSE;
3049 *pnScripts = This->total_scripts;
3050 return S_OK;
3053 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
3054 IMultiLanguage3* iface,
3055 DWORD dwFlags,
3056 LANGID LangId,
3057 IEnumScript** ppEnumScript)
3059 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3061 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3063 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3066 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
3067 IMultiLanguage3* iface,
3068 UINT uiCodePage,
3069 HWND hwnd,
3070 DWORD dwfIODControl)
3072 int i;
3073 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3075 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3077 /* quick check for kernel32 supported code pages */
3078 if (IsValidCodePage(uiCodePage))
3079 return S_OK;
3081 /* check for mlang supported code pages */
3082 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3084 int n;
3085 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3087 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3088 return S_OK;
3092 if (dwfIODControl != CPIOD_PEEK)
3093 FIXME("Request to install codepage language pack not handled\n");
3095 return S_FALSE;
3098 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3099 IMultiLanguage3 *iface,
3100 DWORD dwFlags,
3101 LPCWSTR lpWideCharStr,
3102 UINT cchWideChar,
3103 UINT *puiPreferredCodePages,
3104 UINT nPreferredCodePages,
3105 UINT *puiDetectedCodePages,
3106 UINT *pnDetectedCodePages,
3107 WCHAR *lpSpecialChar)
3109 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3111 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3112 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3113 pnDetectedCodePages, lpSpecialChar);
3114 return E_NOTIMPL;
3117 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3118 IMultiLanguage3 *iface,
3119 DWORD dwFlags,
3120 IStream *pStrIn,
3121 UINT *puiPreferredCodePages,
3122 UINT nPreferredCodePages,
3123 UINT *puiDetectedCodePages,
3124 UINT *pnDetectedCodePages,
3125 WCHAR *lpSpecialChar)
3127 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3129 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
3130 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3131 pnDetectedCodePages, lpSpecialChar);
3132 return E_NOTIMPL;
3135 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3137 fnIMultiLanguage2_QueryInterface,
3138 fnIMultiLanguage2_AddRef,
3139 fnIMultiLanguage2_Release,
3140 fnIMultiLanguage2_GetNumberOfCodePageInfo,
3141 fnIMultiLanguage2_GetCodePageInfo,
3142 fnIMultiLanguage2_GetFamilyCodePage,
3143 fnIMultiLanguage2_EnumCodePages,
3144 fnIMultiLanguage2_GetCharsetInfo,
3145 fnIMultiLanguage2_IsConvertible,
3146 fnIMultiLanguage2_ConvertString,
3147 fnIMultiLanguage2_ConvertStringToUnicode,
3148 fnIMultiLanguage2_ConvertStringFromUnicode,
3149 fnIMultiLanguage2_ConvertStringReset,
3150 fnIMultiLanguage2_GetRfc1766FromLcid,
3151 fnIMultiLanguage2_GetLcidFromRfc1766,
3152 fnIMultiLanguage2_EnumRfc1766,
3153 fnIMultiLanguage2_GetRfc1766Info,
3154 fnIMultiLanguage2_CreateConvertCharset,
3155 fnIMultiLanguage2_ConvertStringInIStream,
3156 fnIMultiLanguage2_ConvertStringToUnicodeEx,
3157 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
3158 fnIMultiLanguage2_DetectCodepageInIStream,
3159 fnIMultiLanguage2_DetectInputCodepage,
3160 fnIMultiLanguage2_ValidateCodePage,
3161 fnIMultiLanguage2_GetCodePageDescription,
3162 fnIMultiLanguage2_IsCodePageInstallable,
3163 fnIMultiLanguage2_SetMimeDBSource,
3164 fnIMultiLanguage2_GetNumberOfScripts,
3165 fnIMultiLanguage2_EnumScripts,
3166 fnIMultiLanguage2_ValidateCodePageEx,
3167 fnIMultiLanguage3_DetectOutboundCodePage,
3168 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3171 /******************************************************************************/
3173 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3175 return CONTAINING_RECORD( iface, MLang_impl, IMLangFontLink2_iface );
3178 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3179 IMLangFontLink2 * iface,
3180 REFIID riid,
3181 void** ppvObject)
3183 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3184 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3187 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3189 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3190 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3193 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3195 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3196 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3199 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* This,
3200 WCHAR chSrc, DWORD *pdwCodePages)
3202 FIXME("(%p)->%s %p\n",This, debugstr_wn(&chSrc,1),pdwCodePages);
3203 return E_NOTIMPL;
3206 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* This,
3207 const WCHAR *pszSrc, LONG cchSrc, DWORD dwPriorityCodePages,
3208 DWORD *pdwCodePages, LONG *pcchCodePages)
3210 return fnIMLangFontLink_GetStrCodePages((IMLangFontLink *)This,
3211 pszSrc, cchSrc, dwPriorityCodePages, pdwCodePages, pcchCodePages);
3214 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* This,
3215 UINT uCodePage,
3216 DWORD *pdwCodePages)
3218 FIXME("(%p)->%i %p\n",This, uCodePage, pdwCodePages);
3219 return E_NOTIMPL;
3222 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* iface,
3223 DWORD codepages, UINT def_codepage, UINT *codepage)
3225 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3226 DWORD mask = 0;
3227 CHARSETINFO cs;
3228 BOOL rc;
3229 UINT i;
3231 TRACE("(%p)->(0x%x %u %p)\n", This, codepages, def_codepage, codepage);
3233 *codepage = 0;
3235 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)def_codepage, &cs, TCI_SRCCODEPAGE);
3236 if (rc && (codepages & cs.fs.fsCsb[0]))
3238 TRACE("Found Default Codepage\n");
3239 *codepage = def_codepage;
3240 return S_OK;
3243 for (i = 0; i < 32; i++)
3245 mask = 1 << i;
3246 if (codepages & mask)
3248 DWORD Csb[2];
3249 Csb[0] = mask;
3250 Csb[1] = 0x0;
3251 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
3252 if (!rc)
3253 continue;
3255 TRACE("Falling back to least significant found CodePage %u\n",
3256 cs.ciACP);
3257 *codepage = cs.ciACP;
3258 return S_OK;
3262 TRACE("no codepage found\n");
3263 return E_FAIL;
3266 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2 *iface,
3267 HDC hdc, HFONT hfont, DWORD *codepages)
3269 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3270 FONTSIGNATURE fontsig;
3271 HFONT old_font;
3273 TRACE("(%p)->(%p %p %p)\n", This, hdc, hfont, codepages);
3275 old_font = SelectObject(hdc, hfont);
3276 GetTextCharsetInfo(hdc, &fontsig, 0);
3277 SelectObject(hdc, old_font);
3279 *codepages = fontsig.fsCsb[0];
3280 TRACE("ret 0x%x\n", fontsig.fsCsb[0]);
3282 return S_OK;
3285 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3286 HFONT hFont)
3288 FIXME("(%p)->%p\n",This, hFont);
3289 return E_NOTIMPL;
3292 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3294 FIXME("(%p)->\n",This);
3295 return E_NOTIMPL;
3298 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3299 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3301 FIXME("(%p)->%p %i %s %p\n",This, hDC, dwCodePages, debugstr_wn(&chSrc,1), pFont);
3302 return E_NOTIMPL;
3305 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3306 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3308 DWORD size;
3309 GLYPHSET *gs;
3311 TRACE("(%p)->%p %p %p\n", This, hDC, puiRanges, pUranges);
3313 if (!puiRanges) return E_INVALIDARG;
3314 if (!(size = GetFontUnicodeRanges(hDC, NULL))) return E_FAIL;
3315 if (!(gs = HeapAlloc(GetProcessHeap(), 0, size))) return E_OUTOFMEMORY;
3317 GetFontUnicodeRanges(hDC, gs);
3318 *puiRanges = gs->cRanges;
3319 if (pUranges)
3321 UINT i;
3322 for (i = 0; i < gs->cRanges; i++)
3324 if (i >= *puiRanges) break;
3325 pUranges[i].wcFrom = gs->ranges[i].wcLow;
3326 pUranges[i].wcTo = gs->ranges[i].wcLow + gs->ranges[i].cGlyphs;
3328 *puiRanges = i;
3330 HeapFree(GetProcessHeap(), 0, gs);
3331 return S_OK;
3334 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3335 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3336 SCRIPTFONTINFO *pScriptFont)
3338 UINT i, j;
3340 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3342 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3344 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3346 if (sid == mlang_data[i].sid)
3348 if (pScriptFont)
3350 if (j >= *puiFonts) break;
3352 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3353 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3355 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3356 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3358 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3360 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3361 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3364 j++;
3367 *puiFonts = j;
3368 return S_OK;
3371 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3372 UINT uiCodePage, SCRIPT_ID *pSid)
3374 UINT i;
3376 TRACE("(%p)->%i %p\n", This, uiCodePage, pSid);
3378 if (uiCodePage == CP_UNICODE) return E_FAIL;
3380 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3382 if (uiCodePage == mlang_data[i].family_codepage)
3384 if (pSid) *pSid = mlang_data[i].sid;
3385 return S_OK;
3388 return E_FAIL;
3391 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3393 fnIMLangFontLink2_QueryInterface,
3394 fnIMLangFontLink2_AddRef,
3395 fnIMLangFontLink2_Release,
3396 fnIMLangFontLink2_GetCharCodePages,
3397 fnIMLangFontLink2_GetStrCodePages,
3398 fnIMLangFontLink2_CodePageToCodePages,
3399 fnIMLangFontLink2_CodePagesToCodePage,
3400 fnIMLangFontLink2_GetFontCodePages,
3401 fnIMLangFontLink2_ReleaseFont,
3402 fnIMLangFontLink2_ResetFontMapping,
3403 fnIMLangFontLink2_MapFont,
3404 fnIMLangFontLink2_GetFontUnicodeRanges,
3405 fnIMLangFontLink2_GetScriptFontInfo,
3406 fnIMLangFontLink2_CodePageToScriptID
3409 /******************************************************************************/
3411 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3413 return CONTAINING_RECORD( iface, MLang_impl, IMLangLineBreakConsole_iface );
3416 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3417 IMLangLineBreakConsole* iface,
3418 REFIID riid,
3419 void** ppvObject)
3421 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3422 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3425 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3426 IMLangLineBreakConsole* iface )
3428 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3429 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3432 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3433 IMLangLineBreakConsole* iface )
3435 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3436 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3439 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3440 IMLangLineBreakConsole* iface,
3441 IMLangString* pSrcMLStr,
3442 LONG lSrcPos,
3443 LONG lSrcLen,
3444 LONG cMinColumns,
3445 LONG cMaxColumns,
3446 LONG* plLineLen,
3447 LONG* plSkipLen)
3449 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3450 return E_NOTIMPL;
3453 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3454 IMLangLineBreakConsole* iface,
3455 LCID locale,
3456 const WCHAR* pszSrc,
3457 LONG cchSrc,
3458 LONG cMaxColumns,
3459 LONG* pcchLine,
3460 LONG* pcchSkip )
3462 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3464 *pcchLine = cchSrc;
3465 *pcchSkip = 0;
3466 return S_OK;
3469 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3470 IMLangLineBreakConsole* iface,
3471 LCID locale,
3472 UINT uCodePage,
3473 const CHAR* pszSrc,
3474 LONG cchSrc,
3475 LONG cMaxColumns,
3476 LONG* pcchLine,
3477 LONG* pcchSkip)
3479 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3481 *pcchLine = cchSrc;
3482 *pcchSkip = 0;
3483 return S_OK;
3486 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3488 fnIMLangLineBreakConsole_QueryInterface,
3489 fnIMLangLineBreakConsole_AddRef,
3490 fnIMLangLineBreakConsole_Release,
3491 fnIMLangLineBreakConsole_BreakLineML,
3492 fnIMLangLineBreakConsole_BreakLineW,
3493 fnIMLangLineBreakConsole_BreakLineA
3496 struct convert_charset {
3497 IMLangConvertCharset IMLangConvertCharset_iface;
3498 LONG ref;
3500 UINT src_cp;
3501 UINT dst_cp;
3504 static inline struct convert_charset *impl_from_IMLangConvertCharset(IMLangConvertCharset *iface)
3506 return CONTAINING_RECORD(iface, struct convert_charset, IMLangConvertCharset_iface);
3509 static HRESULT WINAPI MLangConvertCharset_QueryInterface(IMLangConvertCharset *iface, REFIID riid, void **obj)
3511 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3513 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
3515 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMLangConvertCharset))
3517 *obj = &This->IMLangConvertCharset_iface;
3518 IMLangConvertCharset_AddRef(iface);
3519 return S_OK;
3522 *obj = NULL;
3523 return E_NOINTERFACE;
3526 static ULONG WINAPI MLangConvertCharset_AddRef(IMLangConvertCharset *iface)
3528 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3529 ULONG ref = InterlockedIncrement(&This->ref);
3530 TRACE("(%p)->(%u)\n", This, ref);
3531 return ref;
3534 static ULONG WINAPI MLangConvertCharset_Release(IMLangConvertCharset *iface)
3536 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3537 ULONG ref = InterlockedDecrement(&This->ref);
3539 TRACE("(%p)->(%u)\n", This, ref);
3540 if (!ref)
3542 HeapFree(GetProcessHeap(), 0, This);
3543 UnlockModule();
3546 return ref;
3549 static HRESULT WINAPI MLangConvertCharset_Initialize(IMLangConvertCharset *iface,
3550 UINT src_cp, UINT dst_cp, DWORD prop)
3552 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3554 TRACE("(%p)->(%u %u 0x%08x)\n", This, src_cp, dst_cp, prop);
3556 prop &= ~MLCONVCHARF_USEDEFCHAR;
3557 if (prop)
3558 FIXME("property 0x%08x not supported\n", prop);
3560 This->src_cp = src_cp;
3561 This->dst_cp = dst_cp;
3563 return S_OK;
3566 static HRESULT WINAPI MLangConvertCharset_GetSourceCodePage(IMLangConvertCharset *iface, UINT *src_cp)
3568 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3570 TRACE("(%p)->(%p)\n", This, src_cp);
3572 if (!src_cp) return E_INVALIDARG;
3573 *src_cp = This->src_cp;
3574 return S_OK;
3577 static HRESULT WINAPI MLangConvertCharset_GetDestinationCodePage(IMLangConvertCharset *iface, UINT *dst_cp)
3579 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3581 TRACE("(%p)->(%p)\n", This, dst_cp);
3583 if (!dst_cp) return E_INVALIDARG;
3584 *dst_cp = This->dst_cp;
3585 return S_OK;
3588 static HRESULT WINAPI MLangConvertCharset_GetProperty(IMLangConvertCharset *iface, DWORD *prop)
3590 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3591 FIXME("(%p)->(%p): stub\n", This, prop);
3592 return E_NOTIMPL;
3595 static HRESULT WINAPI MLangConvertCharset_DoConversion(IMLangConvertCharset *iface, BYTE *src,
3596 UINT *src_size, BYTE *dest, UINT *dest_size)
3598 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3599 FIXME("(%p)->(%p %p %p %p): stub\n", This, src, src_size, dest, dest_size);
3600 return E_NOTIMPL;
3603 static HRESULT WINAPI MLangConvertCharset_DoConversionToUnicode(IMLangConvertCharset *iface, CHAR *src,
3604 UINT *src_size, WCHAR *dest, UINT *dest_size)
3606 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3607 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3608 return ConvertINetMultiByteToUnicode(NULL, This->src_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3611 static HRESULT WINAPI MLangConvertCharset_DoConversionFromUnicode(IMLangConvertCharset *iface,
3612 WCHAR *src, UINT *src_size, CHAR *dest, UINT *dest_size)
3614 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3615 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3616 return ConvertINetUnicodeToMultiByte(NULL, This->dst_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3619 static const IMLangConvertCharsetVtbl MLangConvertCharsetVtbl =
3621 MLangConvertCharset_QueryInterface,
3622 MLangConvertCharset_AddRef,
3623 MLangConvertCharset_Release,
3624 MLangConvertCharset_Initialize,
3625 MLangConvertCharset_GetSourceCodePage,
3626 MLangConvertCharset_GetDestinationCodePage,
3627 MLangConvertCharset_GetProperty,
3628 MLangConvertCharset_DoConversion,
3629 MLangConvertCharset_DoConversionToUnicode,
3630 MLangConvertCharset_DoConversionFromUnicode
3633 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3635 MLang_impl *mlang;
3636 UINT i;
3638 TRACE("Creating MultiLanguage object\n");
3640 if( pUnkOuter )
3641 return CLASS_E_NOAGGREGATION;
3643 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3644 mlang->IMLangFontLink_iface.lpVtbl = &IMLangFontLink_vtbl;
3645 mlang->IMultiLanguage_iface.lpVtbl = &IMultiLanguage_vtbl;
3646 mlang->IMultiLanguage3_iface.lpVtbl = &IMultiLanguage3_vtbl;
3647 mlang->IMLangFontLink2_iface.lpVtbl = &IMLangFontLink2_vtbl;
3648 mlang->IMLangLineBreakConsole_iface.lpVtbl = &IMLangLineBreakConsole_vtbl;
3650 mlang->total_cp = 0;
3651 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3652 mlang->total_cp += mlang_data[i].number_of_cp;
3654 /* do not enumerate unicode flavours */
3655 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3657 mlang->ref = 1;
3658 *ppObj = &mlang->IMultiLanguage_iface;
3659 TRACE("returning %p\n", mlang);
3661 LockModule();
3663 return S_OK;
3666 static HRESULT MLangConvertCharset_create(IUnknown *outer, void **obj)
3668 struct convert_charset *convert;
3670 if (outer)
3671 return CLASS_E_NOAGGREGATION;
3673 *obj = NULL;
3675 convert = HeapAlloc(GetProcessHeap(), 0, sizeof(struct convert_charset));
3676 if (!convert) return E_OUTOFMEMORY;
3678 convert->IMLangConvertCharset_iface.lpVtbl = &MLangConvertCharsetVtbl;
3679 convert->ref = 1;
3681 *obj = &convert->IMLangConvertCharset_iface;
3683 LockModule();
3685 return S_OK;
3688 /******************************************************************************/
3690 HRESULT WINAPI DllCanUnloadNow(void)
3692 return dll_count == 0 ? S_OK : S_FALSE;
3696 /***********************************************************************
3697 * DllRegisterServer (MLANG.@)
3699 HRESULT WINAPI DllRegisterServer(void)
3701 return __wine_register_resources( instance );
3704 /***********************************************************************
3705 * DllUnregisterServer (MLANG.@)
3707 HRESULT WINAPI DllUnregisterServer(void)
3709 return __wine_unregister_resources( instance );
3712 HRESULT WINAPI GetGlobalFontLinkObject(void **unknown)
3714 if (!unknown) return E_INVALIDARG;
3716 FIXME("%p: stub\n", unknown);
3718 return S_FALSE;