ddraw: Some drivers return a refresh rate of 0.
[wine/winequartzdrv.git] / dlls / mlang / mlang.c
blob42da54e84258bbf074706f1f4d56c020e9b4f835
1 /*
2 * MLANG Class Factory
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003,2004 Mike McCormack
6 * Copyright 2004,2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "mlang.h"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
42 #include "initguid.h"
44 #define CP_UNICODE 1200
46 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
48 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj);
49 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum);
51 static DWORD MLANG_tls_index; /* to store various per thead data */
53 /* FIXME:
54 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
55 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
58 typedef struct
60 const char *description;
61 UINT cp;
62 DWORD flags;
63 const char *web_charset;
64 const char *header_charset;
65 const char *body_charset;
66 } MIME_CP_INFO;
68 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
69 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
71 static const MIME_CP_INFO arabic_cp[] =
73 { "Arabic (864)",
74 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
75 MIMECONTF_MIME_LATEST,
76 "ibm864", "ibm864", "ibm864" },
77 { "Arabic (1006)",
78 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
79 MIMECONTF_MIME_LATEST,
80 "ibm1006", "ibm1006", "ibm1006" },
81 { "Arabic (Windows)",
82 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
83 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
84 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
85 "windows-1256", "windows-1256", "windows-1256" },
86 { "Arabic (ISO)",
87 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
88 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
89 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
90 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
91 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
93 static const MIME_CP_INFO baltic_cp[] =
95 { "Baltic (DOS)",
96 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
97 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
98 "ibm775", "ibm775", "ibm775" },
99 { "Baltic (Windows)",
100 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
101 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
102 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
103 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
104 "windows-1257", "windows-1257", "windows-1257" },
105 { "Baltic (ISO)",
106 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
107 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
108 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
109 MIMECONTF_MIME_LATEST,
110 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
111 { "Estonian (ISO)",
112 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
113 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
114 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
116 static const MIME_CP_INFO chinese_simplified_cp[] =
118 { "Chinese Simplified (GB2312)",
119 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
120 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
121 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
122 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
123 "gb2312", "gb2312", "gb2312" }
125 static const MIME_CP_INFO chinese_traditional_cp[] =
127 { "Chinese Traditional (Big5)",
128 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
129 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
130 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
131 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
132 "big5", "big5", "big5" }
134 static const MIME_CP_INFO central_european_cp[] =
136 { "Central European (DOS)",
137 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
138 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
139 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
140 "ibm852", "ibm852", "ibm852" },
141 { "Central European (Windows)",
142 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
143 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
144 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
145 MIMECONTF_MIME_LATEST,
146 "windows-1250", "windows-1250", "windows-1250" },
147 { "Central European (Mac)",
148 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
149 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
150 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
151 { "Central European (ISO)",
152 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
153 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
154 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
155 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
156 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
158 static const MIME_CP_INFO cyrillic_cp[] =
160 { "OEM Cyrillic",
161 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
162 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
163 "ibm855", "ibm855", "ibm855" },
164 { "Cyrillic (DOS)",
165 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
166 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
167 MIMECONTF_MIME_LATEST,
168 "cp866", "cp866", "cp866" },
169 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
170 { "Cyrillic (KOI8-R)",
171 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
172 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
173 "koi8-r", "koi8-r", "koi8-r" },
174 #endif
175 { "Cyrillic (Windows)",
176 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
177 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
178 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
179 "windows-1251", "windows-1251", "windows-1251" },
180 { "Cyrillic (Mac)",
181 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
182 MIMECONTF_MIME_LATEST,
183 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
184 { "Cyrillic (KOI8-R)",
185 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
186 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
187 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
188 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
189 "koi8-r", "koi8-r", "koi8-r" },
190 { "Cyrillic (KOI8-U)",
191 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
192 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
193 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
194 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
195 "koi8-u", "koi8-u", "koi8-u" },
196 { "Cyrillic (ISO)",
197 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
198 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
199 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
200 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
201 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
203 static const MIME_CP_INFO greek_cp[] =
205 { "Greek (DOS)",
206 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
207 MIMECONTF_MIME_LATEST,
208 "ibm737", "ibm737", "ibm737" },
209 { "Greek, Modern (DOS)",
210 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
211 MIMECONTF_MIME_LATEST,
212 "ibm869", "ibm869", "ibm869" },
213 { "IBM EBCDIC (Greek Modern)",
214 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
215 MIMECONTF_MIME_LATEST,
216 "cp875", "cp875", "cp875" },
217 { "Greek (Windows)",
218 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
219 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
220 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
221 "windows-1253", "windows-1253", "windows-1253" },
222 { "Greek (Mac)",
223 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
224 MIMECONTF_MIME_LATEST,
225 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
226 { "Greek (ISO)",
227 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
228 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
229 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
230 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
231 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
233 static const MIME_CP_INFO hebrew_cp[] =
235 { "Hebrew (424)",
236 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
237 MIMECONTF_MIME_LATEST,
238 "ibm424", "ibm424", "ibm424" },
239 { "Hebrew (856)",
240 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
241 MIMECONTF_MIME_LATEST,
242 "cp856", "cp856", "cp856" },
243 { "Hebrew (DOS)",
244 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
245 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
246 MIMECONTF_MIME_LATEST,
247 "dos-862", "dos-862", "dos-862" },
248 { "Hebrew (Windows)",
249 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
250 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
251 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
252 "windows-1255", "windows-1255", "windows-1255" },
253 { "Hebrew (ISO-Visual)",
254 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
255 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
256 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
257 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
259 static const MIME_CP_INFO japanese_cp[] =
261 { "Japanese (Shift-JIS)",
262 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
263 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
264 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
265 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
266 "shift_jis", "iso-2022-jp", "iso-2022-jp" },
267 { "Japanese (JIS 0208-1990 and 0212-1990)",
268 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
269 MIMECONTF_MIME_LATEST,
270 "euc-jp", "euc-jp", "euc-jp" }
272 static const MIME_CP_INFO korean_cp[] =
274 { "Korean",
275 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
276 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
277 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
278 MIMECONTF_MIME_LATEST,
279 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
281 static const MIME_CP_INFO thai_cp[] =
283 { "Thai (Windows)",
284 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
285 "ibm-thai", "ibm-thai", "ibm-thai" }
287 static const MIME_CP_INFO turkish_cp[] =
289 { "Turkish (DOS)",
290 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
291 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
292 "ibm857", "ibm857", "ibm857" },
293 { "IBM EBCDIC (Turkish Latin-5)",
294 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
295 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
296 "ibm1026", "ibm1026", "ibm1026" },
297 { "Turkish (Windows)",
298 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
299 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
300 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
301 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
302 "windows-1254", "windows-1254", "windows-1254" },
303 { "Turkish (Mac)",
304 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
305 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
306 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
307 { "Latin 3 (ISO)",
308 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
309 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
310 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
311 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
312 { "Turkish (ISO)",
313 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
314 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
315 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
316 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
317 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
319 static const MIME_CP_INFO vietnamese_cp[] =
321 { "Vietnamese (Windows)",
322 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
323 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
324 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
325 MIMECONTF_MIME_LATEST,
326 "windows-1258", "windows-1258", "windows-1258" }
328 static const MIME_CP_INFO western_cp[] =
330 { "IBM EBCDIC (US-Canada)",
331 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
332 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
333 "ibm037", "ibm037", "ibm037" },
334 { "OEM United States",
335 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
336 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
337 "ibm437", "ibm437", "ibm437" },
338 { "IBM EBCDIC (International)",
339 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
340 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
341 "ibm500", "ibm500", "ibm500" },
342 { "Western European (DOS)",
343 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
344 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
345 "ibm850", "ibm850", "ibm850" },
346 { "Portuguese (DOS)",
347 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
348 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
349 "ibm860", "ibm860", "ibm860" },
350 { "Icelandic (DOS)",
351 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
352 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
353 "ibm861", "ibm861", "ibm861" },
354 { "French Canadian (DOS)",
355 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
356 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
357 "ibm863", "ibm863", "ibm863" },
358 { "Nordic (DOS)",
359 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
360 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
361 "ibm865", "ibm865", "ibm865" },
362 { "Western European (Windows)",
363 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
364 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
365 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
366 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
367 "windows-1252", "windows-1252", "iso-8859-1" },
368 { "Western European (Mac)",
369 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
370 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
371 "macintosh", "macintosh", "macintosh" },
372 { "Icelandic (Mac)",
373 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
374 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
375 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
376 { "US-ASCII",
377 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
378 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
379 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
380 "us-ascii", "us-ascii", "us-ascii" },
381 { "Western European (ISO)",
382 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
383 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
384 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
385 MIMECONTF_MIME_LATEST,
386 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
387 { "Latin 9 (ISO)",
388 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
389 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
390 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
391 MIMECONTF_MIME_LATEST,
392 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
394 static const MIME_CP_INFO unicode_cp[] =
396 { "Unicode",
397 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
398 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
399 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
400 MIMECONTF_MIME_LATEST,
401 "unicode", "unicode", "unicode" },
402 { "Unicode (UTF-7)",
403 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
404 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
405 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
406 "utf-7", "utf-7", "utf-7" },
407 { "Unicode (UTF-8)",
408 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
409 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
410 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
411 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
412 "utf-8", "utf-8", "utf-8" }
415 static const struct mlang_data
417 const char *description;
418 UINT family_codepage;
419 UINT number_of_cp;
420 const MIME_CP_INFO *mime_cp_info;
421 const char *fixed_font;
422 const char *proportional_font;
423 } mlang_data[] =
425 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
426 "Courier","Arial" }, /* FIXME */
427 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
428 "Courier","Arial" }, /* FIXME */
429 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
430 "Courier","Arial" }, /* FIXME */
431 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
432 "Courier","Arial" }, /* FIXME */
433 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
434 "Courier","Arial" }, /* FIXME */
435 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
436 "Courier","Arial" }, /* FIXME */
437 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
438 "Courier","Arial" }, /* FIXME */
439 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
440 "Courier","Arial" }, /* FIXME */
441 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
442 "Courier","Arial" }, /* FIXME */
443 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
444 "Courier","Arial" }, /* FIXME */
445 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
446 "Courier","Arial" }, /* FIXME */
447 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
448 "Courier","Arial" }, /* FIXME */
449 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
450 "Courier","Arial" }, /* FIXME */
451 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
452 "Courier","Arial" }, /* FIXME */
453 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
454 "Courier","Arial" } /* FIXME */
457 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
459 static LONG dll_count;
462 * Dll lifetime tracking declaration
464 static void LockModule(void)
466 InterlockedIncrement(&dll_count);
469 static void UnlockModule(void)
471 InterlockedDecrement(&dll_count);
474 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
476 switch(fdwReason) {
477 case DLL_PROCESS_ATTACH:
478 MLANG_tls_index = TlsAlloc();
479 DisableThreadLibraryCalls(hInstDLL);
480 break;
481 case DLL_PROCESS_DETACH:
482 TlsFree(MLANG_tls_index);
483 break;
485 return TRUE;
488 HRESULT WINAPI ConvertINetMultiByteToUnicode(
489 LPDWORD pdwMode,
490 DWORD dwEncoding,
491 LPCSTR pSrcStr,
492 LPINT pcSrcSize,
493 LPWSTR pDstStr,
494 LPINT pcDstSize)
496 INT src_len = -1;
498 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
499 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
501 if (!pcDstSize)
502 return E_FAIL;
504 if (!pcSrcSize)
505 pcSrcSize = &src_len;
507 if (!*pcSrcSize)
509 *pcDstSize = 0;
510 return S_OK;
513 switch (dwEncoding)
515 case CP_UNICODE:
516 if (*pcSrcSize == -1)
517 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
518 *pcDstSize = min(*pcSrcSize, *pcDstSize);
519 *pcSrcSize *= sizeof(WCHAR);
520 if (pDstStr)
521 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
522 break;
524 default:
525 if (*pcSrcSize == -1)
526 *pcSrcSize = lstrlenA(pSrcStr);
528 if (pDstStr)
529 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
530 else
531 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
532 break;
535 if (!*pcDstSize)
536 return E_FAIL;
538 return S_OK;
541 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
542 LPDWORD pdwMode,
543 DWORD dwEncoding,
544 LPCWSTR pSrcStr,
545 LPINT pcSrcSize,
546 LPSTR pDstStr,
547 LPINT pcDstSize)
550 INT src_len = -1;
552 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
553 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
555 if (!pcDstSize)
556 return E_FAIL;
558 if (!pcSrcSize)
559 pcSrcSize = &src_len;
561 if (!*pcSrcSize)
563 *pcDstSize = 0;
564 return S_OK;
567 switch (dwEncoding)
569 case CP_UNICODE:
570 if (*pcSrcSize == -1)
571 *pcSrcSize = lstrlenW(pSrcStr);
572 *pcDstSize = min(*pcSrcSize * sizeof(WCHAR), *pcDstSize);
573 if (pDstStr)
574 memmove(pDstStr, pSrcStr, *pcDstSize);
575 break;
577 default:
578 if (*pcSrcSize == -1)
579 *pcSrcSize = lstrlenW(pSrcStr);
581 if (pDstStr)
582 *pcDstSize = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize, NULL, NULL);
583 else
584 *pcDstSize = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0, NULL, NULL);
585 break;
589 if (!*pcDstSize)
590 return E_FAIL;
592 return S_OK;
595 HRESULT WINAPI ConvertINetString(
596 LPDWORD pdwMode,
597 DWORD dwSrcEncoding,
598 DWORD dwDstEncoding,
599 LPCSTR pSrcStr,
600 LPINT pcSrcSize,
601 LPSTR pDstStr,
602 LPINT pcDstSize
605 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
606 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
608 if (dwSrcEncoding == CP_UNICODE)
610 INT cSrcSizeW;
611 if (pcSrcSize && *pcSrcSize != -1)
613 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
614 pcSrcSize = &cSrcSizeW;
616 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
618 else if (dwDstEncoding == CP_UNICODE)
620 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
621 *pcDstSize *= sizeof(WCHAR);
622 return hr;
624 else
626 INT cDstSizeW;
627 LPWSTR pDstStrW;
628 HRESULT hr;
630 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
632 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
633 if (hr != S_OK)
634 return hr;
636 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
637 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
638 if (hr == S_OK)
639 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
641 HeapFree(GetProcessHeap(), 0, pDstStrW);
642 return hr;
646 static HRESULT GetFamilyCodePage(
647 UINT uiCodePage,
648 UINT* puiFamilyCodePage)
650 UINT i, n;
652 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
654 if (!puiFamilyCodePage) return S_FALSE;
656 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
658 for (n = 0; n < mlang_data[i].number_of_cp; n++)
660 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
662 *puiFamilyCodePage = mlang_data[i].family_codepage;
663 return S_OK;
668 return S_FALSE;
671 HRESULT WINAPI IsConvertINetStringAvailable(
672 DWORD dwSrcEncoding,
673 DWORD dwDstEncoding)
675 UINT src_family, dst_family;
677 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
679 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
680 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
681 return S_FALSE;
683 if (src_family == dst_family) return S_OK;
685 /* we can convert any codepage to/from unicode */
686 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
688 return S_FALSE;
691 static inline INT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
693 INT n = GetLocaleInfoA( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
694 if (n)
696 rfc1766[n - 1] = '-';
697 n += GetLocaleInfoA( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
698 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
699 return n;
701 return 0;
704 static inline INT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
706 INT n = GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME, rfc1766, len );
707 if (n)
709 rfc1766[n - 1] = '-';
710 n += GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME, rfc1766 + n, len - n );
711 LCMapStringW( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, rfc1766, n, rfc1766, len );
712 return n;
714 return 0;
717 HRESULT WINAPI LcidToRfc1766A(
718 LCID lcid,
719 LPSTR pszRfc1766,
720 INT nChar)
722 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
724 if (lcid_to_rfc1766A( lcid, pszRfc1766, nChar ))
725 return S_OK;
727 return S_FALSE;
730 HRESULT WINAPI LcidToRfc1766W(
731 LCID lcid,
732 LPWSTR pszRfc1766,
733 INT nChar)
735 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
737 if (lcid_to_rfc1766W( lcid, pszRfc1766, nChar ))
738 return S_OK;
740 return S_FALSE;
743 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
745 RFC1766INFO info;
746 ULONG num;
748 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
750 if (!strcmpW(info.wszRfc1766, rfc1766))
752 *lcid = info.lcid;
753 return S_OK;
755 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
757 *lcid = PRIMARYLANGID(info.lcid);
758 return S_OK;
762 return E_FAIL;
765 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
767 IEnumRfc1766 *enumrfc1766;
768 HRESULT hr;
770 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
772 if (!pLocale || !pszRfc1766)
773 return E_INVALIDARG;
775 *pLocale = 0;
777 hr = EnumRfc1766_create(0, &enumrfc1766);
778 if (FAILED(hr))
779 return hr;
781 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
782 IEnumRfc1766_Release(enumrfc1766);
784 return hr;
787 /******************************************************************************
788 * MLANG ClassFactory
790 typedef struct {
791 IClassFactory ITF_IClassFactory;
793 LONG ref;
794 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
795 } IClassFactoryImpl;
797 struct object_creation_info
799 const CLSID *clsid;
800 LPCSTR szClassName;
801 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
804 static const struct object_creation_info object_creation[] =
806 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
809 static HRESULT WINAPI
810 MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
812 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
814 TRACE("%s\n", debugstr_guid(riid) );
816 if (IsEqualGUID(riid, &IID_IUnknown)
817 || IsEqualGUID(riid, &IID_IClassFactory))
819 IClassFactory_AddRef(iface);
820 *ppobj = This;
821 return S_OK;
824 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
825 return E_NOINTERFACE;
828 static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
830 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
831 return InterlockedIncrement(&This->ref);
834 static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
836 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
838 ULONG ref = InterlockedDecrement(&This->ref);
840 if (ref == 0)
842 TRACE("Destroying %p\n", This);
843 HeapFree(GetProcessHeap(), 0, This);
846 return ref;
849 static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
850 REFIID riid, LPVOID *ppobj)
852 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
853 HRESULT hres;
854 LPUNKNOWN punk;
856 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
858 *ppobj = NULL;
859 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
860 if (SUCCEEDED(hres)) {
861 hres = IUnknown_QueryInterface(punk, riid, ppobj);
862 IUnknown_Release(punk);
864 TRACE("returning (%p) -> %x\n", *ppobj, hres);
865 return hres;
868 static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
870 if (dolock)
871 LockModule();
872 else
873 UnlockModule();
875 return S_OK;
878 static const IClassFactoryVtbl MLANGCF_Vtbl =
880 MLANGCF_QueryInterface,
881 MLANGCF_AddRef,
882 MLANGCF_Release,
883 MLANGCF_CreateInstance,
884 MLANGCF_LockServer
887 /******************************************************************
888 * DllGetClassObject (MLANG.@)
890 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
892 int i;
893 IClassFactoryImpl *factory;
895 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
897 if ( !IsEqualGUID( &IID_IClassFactory, iid )
898 && ! IsEqualGUID( &IID_IUnknown, iid) )
899 return E_NOINTERFACE;
901 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
903 if (IsEqualGUID(object_creation[i].clsid, rclsid))
904 break;
907 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
909 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
910 return CLASS_E_CLASSNOTAVAILABLE;
913 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
915 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
916 if (factory == NULL) return E_OUTOFMEMORY;
918 factory->ITF_IClassFactory.lpVtbl = &MLANGCF_Vtbl;
919 factory->ref = 1;
921 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
923 *ppv = &(factory->ITF_IClassFactory);
925 TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
927 return S_OK;
931 /******************************************************************************/
933 typedef struct tagMLang_impl
935 const IMLangFontLinkVtbl *vtbl_IMLangFontLink;
936 const IMultiLanguageVtbl *vtbl_IMultiLanguage;
937 const IMultiLanguage3Vtbl *vtbl_IMultiLanguage3;
938 LONG ref;
939 DWORD total_cp, total_scripts;
940 } MLang_impl;
942 static ULONG WINAPI MLang_AddRef( MLang_impl* This)
944 return InterlockedIncrement(&This->ref);
947 static ULONG WINAPI MLang_Release( MLang_impl* This )
949 ULONG ref = InterlockedDecrement(&This->ref);
951 TRACE("%p ref = %d\n", This, ref);
952 if (ref == 0)
954 TRACE("Destroying %p\n", This);
955 HeapFree(GetProcessHeap(), 0, This);
956 UnlockModule();
959 return ref;
962 static HRESULT WINAPI MLang_QueryInterface(
963 MLang_impl* This,
964 REFIID riid,
965 void** ppvObject)
967 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
969 if (IsEqualGUID(riid, &IID_IUnknown)
970 || IsEqualGUID(riid, &IID_IMLangCodePages)
971 || IsEqualGUID(riid, &IID_IMLangFontLink))
973 MLang_AddRef(This);
974 TRACE("Returning IID_IMLangFontLink %p ref = %d\n", This, This->ref);
975 *ppvObject = &(This->vtbl_IMLangFontLink);
976 return S_OK;
979 if (IsEqualGUID(riid, &IID_IMultiLanguage) )
981 MLang_AddRef(This);
982 TRACE("Returning IID_IMultiLanguage %p ref = %d\n", This, This->ref);
983 *ppvObject = &(This->vtbl_IMultiLanguage);
984 return S_OK;
987 if (IsEqualGUID(riid, &IID_IMultiLanguage2) )
989 MLang_AddRef(This);
990 *ppvObject = &(This->vtbl_IMultiLanguage3);
991 TRACE("Returning IID_IMultiLanguage2 %p ref = %d\n", This, This->ref);
992 return S_OK;
995 if (IsEqualGUID(riid, &IID_IMultiLanguage3) )
997 MLang_AddRef(This);
998 *ppvObject = &(This->vtbl_IMultiLanguage3);
999 TRACE("Returning IID_IMultiLanguage3 %p ref = %d\n", This, This->ref);
1000 return S_OK;
1003 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1004 return E_NOINTERFACE;
1007 /******************************************************************************/
1009 typedef struct tagEnumCodePage_impl
1011 const IEnumCodePageVtbl *vtbl_IEnumCodePage;
1012 LONG ref;
1013 MIMECPINFO *cpinfo;
1014 DWORD total, pos;
1015 } EnumCodePage_impl;
1017 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1018 IEnumCodePage* iface,
1019 REFIID riid,
1020 void** ppvObject)
1022 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1024 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1026 if (IsEqualGUID(riid, &IID_IUnknown)
1027 || IsEqualGUID(riid, &IID_IEnumCodePage))
1029 IEnumCodePage_AddRef(iface);
1030 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1031 *ppvObject = &(This->vtbl_IEnumCodePage);
1032 return S_OK;
1035 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1036 return E_NOINTERFACE;
1039 static ULONG WINAPI fnIEnumCodePage_AddRef(
1040 IEnumCodePage* iface)
1042 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1043 return InterlockedIncrement(&This->ref);
1046 static ULONG WINAPI fnIEnumCodePage_Release(
1047 IEnumCodePage* iface)
1049 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1050 ULONG ref = InterlockedDecrement(&This->ref);
1052 TRACE("%p ref = %d\n", This, ref);
1053 if (ref == 0)
1055 TRACE("Destroying %p\n", This);
1056 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1057 HeapFree(GetProcessHeap(), 0, This);
1060 return ref;
1063 static HRESULT WINAPI fnIEnumCodePage_Clone(
1064 IEnumCodePage* iface,
1065 IEnumCodePage** ppEnum)
1067 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1068 FIXME("%p %p\n", This, ppEnum);
1069 return E_NOTIMPL;
1072 static HRESULT WINAPI fnIEnumCodePage_Next(
1073 IEnumCodePage* iface,
1074 ULONG celt,
1075 PMIMECPINFO rgelt,
1076 ULONG* pceltFetched)
1078 ULONG i;
1080 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1081 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1083 if (!pceltFetched) return S_FALSE;
1084 *pceltFetched = 0;
1086 if (!rgelt) return S_FALSE;
1088 if (This->pos + celt > This->total)
1089 celt = This->total - This->pos;
1091 if (!celt) return S_FALSE;
1093 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1094 *pceltFetched = celt;
1095 This->pos += celt;
1097 for (i = 0; i < celt; i++)
1099 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1100 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1101 rgelt[i].uiFamilyCodePage,
1102 wine_dbgstr_w(rgelt[i].wszDescription),
1103 wine_dbgstr_w(rgelt[i].wszWebCharset),
1104 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1105 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1106 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1107 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1108 rgelt[i].bGDICharset);
1110 return S_OK;
1113 static HRESULT WINAPI fnIEnumCodePage_Reset(
1114 IEnumCodePage* iface)
1116 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1117 TRACE("%p\n", This);
1119 This->pos = 0;
1120 return S_OK;
1123 static HRESULT WINAPI fnIEnumCodePage_Skip(
1124 IEnumCodePage* iface,
1125 ULONG celt)
1127 ICOM_THIS_MULTI(EnumCodePage_impl, vtbl_IEnumCodePage, iface);
1128 TRACE("%p %u\n", This, celt);
1130 if (celt >= This->total) return S_FALSE;
1132 This->pos += celt;
1133 return S_OK;
1136 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1138 fnIEnumCodePage_QueryInterface,
1139 fnIEnumCodePage_AddRef,
1140 fnIEnumCodePage_Release,
1141 fnIEnumCodePage_Clone,
1142 fnIEnumCodePage_Next,
1143 fnIEnumCodePage_Reset,
1144 fnIEnumCodePage_Skip
1147 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1148 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1150 EnumCodePage_impl *ecp;
1151 MIMECPINFO *cpinfo;
1152 UINT i, n;
1154 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1156 if (!grfFlags) /* enumerate internal data base of encodings */
1157 grfFlags = MIMECONTF_MIME_LATEST;
1159 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1160 ecp->vtbl_IEnumCodePage = &IEnumCodePage_vtbl;
1161 ecp->ref = 1;
1162 ecp->pos = 0;
1163 ecp->total = 0;
1164 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1166 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1168 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1169 ecp->total++;
1173 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1174 sizeof(MIMECPINFO) * ecp->total);
1175 cpinfo = ecp->cpinfo;
1177 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1179 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1181 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1182 fill_cp_info(&mlang_data[i], n, cpinfo++);
1186 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1188 *ppEnumCodePage = (IEnumCodePage*) ecp;
1190 return S_OK;
1193 /******************************************************************************/
1195 typedef struct tagEnumScript_impl
1197 const IEnumScriptVtbl *vtbl_IEnumScript;
1198 LONG ref;
1199 SCRIPTINFO *script_info;
1200 DWORD total, pos;
1201 } EnumScript_impl;
1203 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1204 IEnumScript* iface,
1205 REFIID riid,
1206 void** ppvObject)
1208 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1210 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1212 if (IsEqualGUID(riid, &IID_IUnknown)
1213 || IsEqualGUID(riid, &IID_IEnumScript))
1215 IEnumScript_AddRef(iface);
1216 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1217 *ppvObject = &(This->vtbl_IEnumScript);
1218 return S_OK;
1221 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1222 return E_NOINTERFACE;
1225 static ULONG WINAPI fnIEnumScript_AddRef(
1226 IEnumScript* iface)
1228 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1229 return InterlockedIncrement(&This->ref);
1232 static ULONG WINAPI fnIEnumScript_Release(
1233 IEnumScript* iface)
1235 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1236 ULONG ref = InterlockedDecrement(&This->ref);
1238 TRACE("%p ref = %d\n", This, ref);
1239 if (ref == 0)
1241 TRACE("Destroying %p\n", This);
1242 HeapFree(GetProcessHeap(), 0, This->script_info);
1243 HeapFree(GetProcessHeap(), 0, This);
1246 return ref;
1249 static HRESULT WINAPI fnIEnumScript_Clone(
1250 IEnumScript* iface,
1251 IEnumScript** ppEnum)
1253 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1254 FIXME("%p %p: stub!\n", This, ppEnum);
1255 return E_NOTIMPL;
1258 static HRESULT WINAPI fnIEnumScript_Next(
1259 IEnumScript* iface,
1260 ULONG celt,
1261 PSCRIPTINFO rgelt,
1262 ULONG* pceltFetched)
1264 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1265 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1267 if (!pceltFetched || !rgelt) return E_FAIL;
1269 *pceltFetched = 0;
1271 if (This->pos + celt > This->total)
1272 celt = This->total - This->pos;
1274 if (!celt) return S_FALSE;
1276 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1277 *pceltFetched = celt;
1278 This->pos += celt;
1280 return S_OK;
1283 static HRESULT WINAPI fnIEnumScript_Reset(
1284 IEnumScript* iface)
1286 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1287 TRACE("%p\n", This);
1289 This->pos = 0;
1290 return S_OK;
1293 static HRESULT WINAPI fnIEnumScript_Skip(
1294 IEnumScript* iface,
1295 ULONG celt)
1297 ICOM_THIS_MULTI(EnumScript_impl, vtbl_IEnumScript, iface);
1298 TRACE("%p %u\n", This, celt);
1300 if (celt >= This->total) return S_FALSE;
1302 This->pos += celt;
1303 return S_OK;
1306 static const IEnumScriptVtbl IEnumScript_vtbl =
1308 fnIEnumScript_QueryInterface,
1309 fnIEnumScript_AddRef,
1310 fnIEnumScript_Release,
1311 fnIEnumScript_Clone,
1312 fnIEnumScript_Next,
1313 fnIEnumScript_Reset,
1314 fnIEnumScript_Skip
1317 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1318 LANGID LangId, IEnumScript** ppEnumScript )
1320 EnumScript_impl *es;
1321 UINT i;
1323 TRACE("%p, %08x, %04x, %p: stub!\n", mlang, dwFlags, LangId, ppEnumScript);
1325 if (!dwFlags) /* enumerate all available scripts */
1326 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1328 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1329 es->vtbl_IEnumScript = &IEnumScript_vtbl;
1330 es->ref = 1;
1331 es->pos = 0;
1332 /* do not enumerate unicode flavours */
1333 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1334 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1336 for (i = 0; i < es->total; i++)
1338 es->script_info[i].ScriptId = i;
1339 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1340 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1341 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1342 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1343 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1344 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1345 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1348 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1350 *ppEnumScript = (IEnumScript *)es;
1352 return S_OK;
1355 /******************************************************************************/
1357 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1358 IMLangFontLink* iface,
1359 REFIID riid,
1360 void** ppvObject)
1362 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1363 return MLang_QueryInterface( This, riid, ppvObject );
1366 static ULONG WINAPI fnIMLangFontLink_AddRef(
1367 IMLangFontLink* iface)
1369 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1370 return MLang_AddRef( This );
1373 static ULONG WINAPI fnIMLangFontLink_Release(
1374 IMLangFontLink* iface)
1376 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1377 return MLang_Release( This );
1380 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
1381 IMLangFontLink* iface,
1382 WCHAR chSrc,
1383 DWORD* pdwCodePages)
1385 FIXME("\n");
1386 return E_NOTIMPL;
1389 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
1390 IMLangFontLink* iface,
1391 const WCHAR* pszSrc,
1392 long cchSrc,
1393 DWORD dwPriorityCodePages,
1394 DWORD* pdwCodePages,
1395 long* pcchCodePages)
1397 FIXME("(pszSrc=%s, cchSrc=%ld, dwPriorityCodePages=%d) stub\n", debugstr_w(pszSrc), cchSrc, dwPriorityCodePages);
1398 *pdwCodePages = 0;
1399 *pcchCodePages = 1;
1400 return S_OK;
1403 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
1404 IMLangFontLink* iface,
1405 UINT uCodePage,
1406 DWORD* pdwCodePages)
1408 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1409 CHARSETINFO cs;
1410 BOOL rc;
1412 TRACE("(%p) Seeking %u\n",This, uCodePage);
1413 memset(&cs, 0, sizeof(cs));
1415 rc = TranslateCharsetInfo((DWORD*)uCodePage, &cs, TCI_SRCCODEPAGE);
1417 if (rc)
1419 *pdwCodePages = cs.fs.fsCsb[0];
1420 TRACE("resulting CodePages 0x%x\n",*pdwCodePages);
1422 else
1423 TRACE("CodePage Not Found\n");
1425 return S_OK;
1428 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
1429 IMLangFontLink* iface,
1430 DWORD dwCodePages,
1431 UINT uDefaultCodePage,
1432 UINT* puCodePage)
1434 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1435 DWORD mask = 0x00000000;
1436 UINT i;
1437 CHARSETINFO cs;
1438 BOOL rc;
1440 TRACE("(%p) scanning 0x%x default page %u\n",This, dwCodePages,
1441 uDefaultCodePage);
1443 *puCodePage = 0x00000000;
1445 rc = TranslateCharsetInfo((DWORD*)uDefaultCodePage, &cs, TCI_SRCCODEPAGE);
1447 if (rc && (dwCodePages & cs.fs.fsCsb[0]))
1449 TRACE("Found Default Codepage\n");
1450 *puCodePage = uDefaultCodePage;
1451 return S_OK;
1455 for (i = 0; i < 32; i++)
1458 mask = 1 << i;
1459 if (dwCodePages & mask)
1461 DWORD Csb[2];
1462 Csb[0] = mask;
1463 Csb[1] = 0x0;
1464 rc = TranslateCharsetInfo((DWORD*)Csb, &cs, TCI_SRCFONTSIG);
1465 if (!rc)
1466 continue;
1468 TRACE("Falling back to least significant found CodePage %u\n",
1469 cs.ciACP);
1470 *puCodePage = cs.ciACP;
1471 return S_OK;
1475 TRACE("no codepage found\n");
1476 return E_FAIL;
1479 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
1480 IMLangFontLink* iface,
1481 HDC hDC,
1482 HFONT hFont,
1483 DWORD* pdwCodePages)
1485 HFONT old_font;
1486 FONTSIGNATURE fontsig;
1487 ICOM_THIS_MULTI(MLang_impl, vtbl_IMLangFontLink, iface);
1489 TRACE("(%p)\n",This);
1491 old_font = SelectObject(hDC,hFont);
1492 GetTextCharsetInfo(hDC,&fontsig, 0);
1493 SelectObject(hDC,old_font);
1495 *pdwCodePages = fontsig.fsCsb[0];
1496 TRACE("CodePages is 0x%x\n",fontsig.fsCsb[0]);
1498 return S_OK;
1501 static HRESULT WINAPI fnIMLangFontLink_MapFont(
1502 IMLangFontLink* iface,
1503 HDC hDC,
1504 DWORD dwCodePages,
1505 HFONT hSrcFont,
1506 HFONT* phDestFont)
1508 FIXME("\n");
1509 return E_NOTIMPL;
1512 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
1513 IMLangFontLink* iface,
1514 HFONT hFont)
1516 FIXME("\n");
1517 return E_NOTIMPL;
1520 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
1521 IMLangFontLink* iface)
1523 FIXME("\n");
1524 return E_NOTIMPL;
1528 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
1530 fnIMLangFontLink_QueryInterface,
1531 fnIMLangFontLink_AddRef,
1532 fnIMLangFontLink_Release,
1533 fnIMLangFontLink_GetCharCodePages,
1534 fnIMLangFontLink_GetStrCodePages,
1535 fnIMLangFontLink_CodePageToCodePages,
1536 fnIMLangFontLink_CodePagesToCodePage,
1537 fnIMLangFontLink_GetFontCodePages,
1538 fnIMLangFontLink_MapFont,
1539 fnIMLangFontLink_ReleaseFont,
1540 fnIMLangFontLink_ResetFontMapping,
1543 /******************************************************************************/
1545 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
1546 IMultiLanguage* iface,
1547 REFIID riid,
1548 void** ppvObject)
1550 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1551 return MLang_QueryInterface( This, riid, ppvObject );
1554 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
1556 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1557 return IMLangFontLink_AddRef( ((IMLangFontLink*)This) );
1560 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
1562 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1563 return IMLangFontLink_Release( ((IMLangFontLink*)This) );
1566 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
1567 IMultiLanguage* iface,
1568 UINT* pcCodePage)
1570 FIXME("\n");
1571 return E_NOTIMPL;
1574 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
1575 IMultiLanguage* iface,
1576 UINT uiCodePage,
1577 PMIMECPINFO pCodePageInfo)
1579 UINT i, n;
1581 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1582 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
1584 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1586 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1588 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1590 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
1591 return S_OK;
1596 return S_FALSE;
1599 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
1600 IMultiLanguage* iface,
1601 UINT uiCodePage,
1602 UINT* puiFamilyCodePage)
1604 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
1607 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
1608 IMultiLanguage* iface,
1609 DWORD grfFlags,
1610 IEnumCodePage** ppEnumCodePage)
1612 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1613 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
1615 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
1618 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
1619 IMultiLanguage* iface,
1620 BSTR Charset,
1621 PMIMECSETINFO pCharsetInfo)
1623 FIXME("\n");
1624 return E_NOTIMPL;
1627 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
1628 IMultiLanguage* iface,
1629 DWORD dwSrcEncoding,
1630 DWORD dwDstEncoding)
1632 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
1635 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
1636 IMultiLanguage* iface,
1637 DWORD* pdwMode,
1638 DWORD dwSrcEncoding,
1639 DWORD dwDstEncoding,
1640 BYTE* pSrcStr,
1641 UINT* pcSrcSize,
1642 BYTE* pDstStr,
1643 UINT* pcDstSize)
1645 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
1646 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
1649 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
1650 IMultiLanguage* iface,
1651 DWORD* pdwMode,
1652 DWORD dwEncoding,
1653 CHAR* pSrcStr,
1654 UINT* pcSrcSize,
1655 WCHAR* pDstStr,
1656 UINT* pcDstSize)
1658 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
1659 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
1662 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
1663 IMultiLanguage* iface,
1664 DWORD* pdwMode,
1665 DWORD dwEncoding,
1666 WCHAR* pSrcStr,
1667 UINT* pcSrcSize,
1668 CHAR* pDstStr,
1669 UINT* pcDstSize)
1671 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
1672 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
1675 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
1676 IMultiLanguage* iface)
1678 FIXME("\n");
1679 return E_NOTIMPL;
1682 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
1683 IMultiLanguage* iface,
1684 LCID lcid,
1685 BSTR* pbstrRfc1766)
1687 WCHAR buf[MAX_RFC1766_NAME];
1689 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
1691 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
1693 *pbstrRfc1766 = SysAllocString( buf );
1694 return S_OK;
1696 return E_FAIL;
1699 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
1700 IMultiLanguage* iface,
1701 LCID* pLocale,
1702 BSTR bstrRfc1766)
1704 HRESULT hr;
1705 IEnumRfc1766 *rfc1766;
1707 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
1709 if (!pLocale || !bstrRfc1766)
1710 return E_INVALIDARG;
1712 hr = IMultiLanguage_EnumRfc1766(iface, &rfc1766);
1713 if (FAILED(hr))
1714 return hr;
1716 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
1718 IEnumRfc1766_Release(rfc1766);
1719 return hr;
1722 /******************************************************************************/
1724 typedef struct tagEnumRfc1766_impl
1726 const IEnumRfc1766Vtbl *vtbl_IEnumRfc1766;
1727 LONG ref;
1728 RFC1766INFO *info;
1729 DWORD total, pos;
1730 } EnumRfc1766_impl;
1732 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
1733 IEnumRfc1766 *iface,
1734 REFIID riid,
1735 void** ppvObject)
1737 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1739 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1741 if (IsEqualGUID(riid, &IID_IUnknown)
1742 || IsEqualGUID(riid, &IID_IEnumRfc1766))
1744 IEnumRfc1766_AddRef(iface);
1745 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
1746 *ppvObject = &(This->vtbl_IEnumRfc1766);
1747 return S_OK;
1750 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
1751 return E_NOINTERFACE;
1754 static ULONG WINAPI fnIEnumRfc1766_AddRef(
1755 IEnumRfc1766 *iface)
1757 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1758 return InterlockedIncrement(&This->ref);
1761 static ULONG WINAPI fnIEnumRfc1766_Release(
1762 IEnumRfc1766 *iface)
1764 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1765 ULONG ref = InterlockedDecrement(&This->ref);
1767 TRACE("%p ref = %d\n", This, ref);
1768 if (ref == 0)
1770 TRACE("Destroying %p\n", This);
1771 HeapFree(GetProcessHeap(), 0, This->info);
1772 HeapFree(GetProcessHeap(), 0, This);
1774 return ref;
1777 static HRESULT WINAPI fnIEnumRfc1766_Clone(
1778 IEnumRfc1766 *iface,
1779 IEnumRfc1766 **ppEnum)
1781 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1782 FIXME("%p %p\n", This, ppEnum);
1783 return E_NOTIMPL;
1786 static HRESULT WINAPI fnIEnumRfc1766_Next(
1787 IEnumRfc1766 *iface,
1788 ULONG celt,
1789 PRFC1766INFO rgelt,
1790 ULONG *pceltFetched)
1792 ULONG i;
1794 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1795 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1797 if (!pceltFetched) return S_FALSE;
1798 *pceltFetched = 0;
1800 if (!rgelt) return S_FALSE;
1802 if (This->pos + celt > This->total)
1803 celt = This->total - This->pos;
1805 if (!celt) return S_FALSE;
1807 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
1808 *pceltFetched = celt;
1809 This->pos += celt;
1811 for (i = 0; i < celt; i++)
1813 TRACE("#%u: %08x %s %s\n",
1814 i, rgelt[i].lcid,
1815 wine_dbgstr_w(rgelt[i].wszRfc1766),
1816 wine_dbgstr_w(rgelt[i].wszLocaleName));
1818 return S_OK;
1821 static HRESULT WINAPI fnIEnumRfc1766_Reset(
1822 IEnumRfc1766 *iface)
1824 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1825 TRACE("%p\n", This);
1827 This->pos = 0;
1828 return S_OK;
1831 static HRESULT WINAPI fnIEnumRfc1766_Skip(
1832 IEnumRfc1766 *iface,
1833 ULONG celt)
1835 ICOM_THIS_MULTI(EnumRfc1766_impl, vtbl_IEnumRfc1766, iface);
1836 TRACE("%p %u\n", This, celt);
1838 if (celt >= This->total) return S_FALSE;
1840 This->pos += celt;
1841 return S_OK;
1844 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
1846 fnIEnumRfc1766_QueryInterface,
1847 fnIEnumRfc1766_AddRef,
1848 fnIEnumRfc1766_Release,
1849 fnIEnumRfc1766_Clone,
1850 fnIEnumRfc1766_Next,
1851 fnIEnumRfc1766_Reset,
1852 fnIEnumRfc1766_Skip
1855 struct enum_locales_data
1857 RFC1766INFO *info;
1858 DWORD total, allocated;
1861 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
1863 WCHAR *end;
1864 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
1865 RFC1766INFO *info;
1867 TRACE("%s\n", debugstr_w(locale));
1869 if (data->total >= data->allocated)
1871 data->allocated += 32;
1872 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
1873 if (!data->info) return FALSE;
1876 info = &data->info[data->total];
1878 info->lcid = strtolW(locale, &end, 16);
1879 if (*end) /* invalid number */
1880 return FALSE;
1882 info->wszRfc1766[0] = 0;
1883 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
1885 info->wszLocaleName[0] = 0;
1886 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
1887 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
1889 data->total++;
1891 return TRUE;
1894 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
1896 EnumRfc1766_impl *rfc;
1897 struct enum_locales_data data;
1899 TRACE("%04x, %p\n", LangId, ppEnum);
1901 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
1902 rfc->vtbl_IEnumRfc1766 = &IEnumRfc1766_vtbl;
1903 rfc->ref = 1;
1904 rfc->pos = 0;
1905 rfc->total = 0;
1907 data.total = 0;
1908 data.allocated = 32;
1909 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
1910 if (!data.info)
1912 HeapFree(GetProcessHeap(), 0, rfc);
1913 return S_FALSE;
1916 TlsSetValue(MLANG_tls_index, &data);
1917 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
1918 TlsSetValue(MLANG_tls_index, NULL);
1920 TRACE("enumerated %d rfc1766 structures\n", data.total);
1922 if (!data.total)
1924 HeapFree(GetProcessHeap(), 0, data.info);
1925 HeapFree(GetProcessHeap(), 0, rfc);
1926 return FALSE;
1929 rfc->info = data.info;
1930 rfc->total = data.total;
1932 *ppEnum = (IEnumRfc1766 *)rfc;
1933 return S_OK;
1936 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
1937 IMultiLanguage *iface,
1938 IEnumRfc1766 **ppEnumRfc1766)
1940 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
1941 TRACE("%p %p\n", This, ppEnumRfc1766);
1943 return EnumRfc1766_create(0, ppEnumRfc1766);
1946 /******************************************************************************/
1948 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
1949 IMultiLanguage* iface,
1950 LCID Locale,
1951 PRFC1766INFO pRfc1766Info)
1953 FIXME("\n");
1954 return E_NOTIMPL;
1957 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
1958 IMultiLanguage* iface,
1959 UINT uiSrcCodePage,
1960 UINT uiDstCodePage,
1961 DWORD dwProperty,
1962 IMLangConvertCharset** ppMLangConvertCharset)
1964 FIXME("\n");
1965 return E_NOTIMPL;
1968 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
1970 fnIMultiLanguage_QueryInterface,
1971 fnIMultiLanguage_AddRef,
1972 fnIMultiLanguage_Release,
1973 fnIMultiLanguage_GetNumberOfCodePageInfo,
1974 fnIMultiLanguage_GetCodePageInfo,
1975 fnIMultiLanguage_GetFamilyCodePage,
1976 fnIMultiLanguage_EnumCodePages,
1977 fnIMultiLanguage_GetCharsetInfo,
1978 fnIMultiLanguage_IsConvertible,
1979 fnIMultiLanguage_ConvertString,
1980 fnIMultiLanguage_ConvertStringToUnicode,
1981 fnIMultiLanguage_ConvertStringFromUnicode,
1982 fnIMultiLanguage_ConvertStringReset,
1983 fnIMultiLanguage_GetRfc1766FromLcid,
1984 fnIMultiLanguage_GetLcidFromRfc1766,
1985 fnIMultiLanguage_EnumRfc1766,
1986 fnIMultiLanguage_GetRfc1766Info,
1987 fnIMultiLanguage_CreateConvertCharset,
1991 /******************************************************************************/
1993 static HRESULT WINAPI fnIMultiLanguage2_QueryInterface(
1994 IMultiLanguage3* iface,
1995 REFIID riid,
1996 void** ppvObject)
1998 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
1999 return MLang_QueryInterface( This, riid, ppvObject );
2002 static ULONG WINAPI fnIMultiLanguage2_AddRef( IMultiLanguage3* iface )
2004 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2005 return MLang_AddRef( This );
2008 static ULONG WINAPI fnIMultiLanguage2_Release( IMultiLanguage3* iface )
2010 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2011 return MLang_Release( This );
2014 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfCodePageInfo(
2015 IMultiLanguage3* iface,
2016 UINT* pcCodePage)
2018 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2019 TRACE("%p, %p\n", This, pcCodePage);
2021 if (!pcCodePage) return S_FALSE;
2023 *pcCodePage = This->total_cp;
2024 return S_OK;
2027 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2029 CHARSETINFO csi;
2031 if (TranslateCharsetInfo((DWORD *)ml_data->family_codepage, &csi, TCI_SRCCODEPAGE))
2032 mime_cp_info->bGDICharset = csi.ciCharset;
2033 else
2034 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2036 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2037 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2038 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2039 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2040 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2041 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2042 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2043 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2044 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2045 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2046 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2048 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2049 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2050 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2051 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2053 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2054 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2055 mime_cp_info->uiFamilyCodePage,
2056 wine_dbgstr_w(mime_cp_info->wszDescription),
2057 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2058 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2059 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2060 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2061 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2062 mime_cp_info->bGDICharset);
2065 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageInfo(
2066 IMultiLanguage3* iface,
2067 UINT uiCodePage,
2068 LANGID LangId,
2069 PMIMECPINFO pCodePageInfo)
2071 UINT i, n;
2073 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2074 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2076 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2078 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2080 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2082 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2083 return S_OK;
2088 return S_FALSE;
2091 static HRESULT WINAPI fnIMultiLanguage2_GetFamilyCodePage(
2092 IMultiLanguage3* iface,
2093 UINT uiCodePage,
2094 UINT* puiFamilyCodePage)
2096 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2099 static HRESULT WINAPI fnIMultiLanguage2_EnumCodePages(
2100 IMultiLanguage3* iface,
2101 DWORD grfFlags,
2102 LANGID LangId,
2103 IEnumCodePage** ppEnumCodePage)
2105 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2106 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2108 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2111 static HRESULT WINAPI fnIMultiLanguage2_GetCharsetInfo(
2112 IMultiLanguage3* iface,
2113 BSTR Charset,
2114 PMIMECSETINFO pCharsetInfo)
2116 UINT i, n;
2118 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2119 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2121 if (!pCharsetInfo) return E_FAIL;
2123 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2125 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2127 WCHAR csetW[MAX_MIMECSET_NAME];
2129 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2130 if (!lstrcmpiW(Charset, csetW))
2132 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2133 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2134 strcpyW(pCharsetInfo->wszCharset, csetW);
2135 return S_OK;
2140 /* FIXME:
2141 * Since we do not support charsets like iso-2022-jp and do not have
2142 * them in our database as a primary (web_charset) encoding this loop
2143 * does an attempt to 'approximate' charset name by header_charset.
2145 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2147 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2149 WCHAR csetW[MAX_MIMECSET_NAME];
2151 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2152 if (!lstrcmpiW(Charset, csetW))
2154 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2155 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2156 strcpyW(pCharsetInfo->wszCharset, csetW);
2157 return S_OK;
2162 return E_FAIL;
2165 static HRESULT WINAPI fnIMultiLanguage2_IsConvertible(
2166 IMultiLanguage3* iface,
2167 DWORD dwSrcEncoding,
2168 DWORD dwDstEncoding)
2170 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2173 static HRESULT WINAPI fnIMultiLanguage2_ConvertString(
2174 IMultiLanguage3* iface,
2175 DWORD* pdwMode,
2176 DWORD dwSrcEncoding,
2177 DWORD dwDstEncoding,
2178 BYTE* pSrcStr,
2179 UINT* pcSrcSize,
2180 BYTE* pDstStr,
2181 UINT* pcDstSize)
2183 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2184 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2187 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicode(
2188 IMultiLanguage3* iface,
2189 DWORD* pdwMode,
2190 DWORD dwEncoding,
2191 CHAR* pSrcStr,
2192 UINT* pcSrcSize,
2193 WCHAR* pDstStr,
2194 UINT* pcDstSize)
2196 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2197 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2200 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicode(
2201 IMultiLanguage3* iface,
2202 DWORD* pdwMode,
2203 DWORD dwEncoding,
2204 WCHAR* pSrcStr,
2205 UINT* pcSrcSize,
2206 CHAR* pDstStr,
2207 UINT* pcDstSize)
2209 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2210 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2213 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringReset(
2214 IMultiLanguage3* iface)
2216 FIXME("\n");
2217 return E_NOTIMPL;
2220 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766FromLcid(
2221 IMultiLanguage3* iface,
2222 LCID lcid,
2223 BSTR* pbstrRfc1766)
2225 WCHAR buf[MAX_RFC1766_NAME];
2227 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2229 if (lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2231 *pbstrRfc1766 = SysAllocString( buf );
2232 return S_OK;
2234 return E_FAIL;
2237 static HRESULT WINAPI fnIMultiLanguage2_GetLcidFromRfc1766(
2238 IMultiLanguage3* iface,
2239 LCID* pLocale,
2240 BSTR bstrRfc1766)
2242 HRESULT hr;
2243 IEnumRfc1766 *rfc1766;
2245 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2247 if (!pLocale || !bstrRfc1766)
2248 return E_INVALIDARG;
2250 hr = IMultiLanguage2_EnumRfc1766(iface, 0, &rfc1766);
2251 if (FAILED(hr))
2252 return hr;
2254 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2256 IEnumRfc1766_Release(rfc1766);
2257 return hr;
2260 static HRESULT WINAPI fnIMultiLanguage2_EnumRfc1766(
2261 IMultiLanguage3* iface,
2262 LANGID LangId,
2263 IEnumRfc1766** ppEnumRfc1766)
2265 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage, iface);
2266 TRACE("%p %p\n", This, ppEnumRfc1766);
2268 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2271 static HRESULT WINAPI fnIMultiLanguage2_GetRfc1766Info(
2272 IMultiLanguage3* iface,
2273 LCID Locale,
2274 LANGID LangId,
2275 PRFC1766INFO pRfc1766Info)
2277 FIXME("\n");
2278 return E_NOTIMPL;
2281 static HRESULT WINAPI fnIMultiLanguage2_CreateConvertCharset(
2282 IMultiLanguage3* iface,
2283 UINT uiSrcCodePage,
2284 UINT uiDstCodePage,
2285 DWORD dwProperty,
2286 IMLangConvertCharset** ppMLangConvertCharset)
2288 FIXME("\n");
2289 return E_NOTIMPL;
2292 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringInIStream(
2293 IMultiLanguage3* iface,
2294 DWORD* pdwMode,
2295 DWORD dwFlag,
2296 WCHAR* lpFallBack,
2297 DWORD dwSrcEncoding,
2298 DWORD dwDstEncoding,
2299 IStream* pstmIn,
2300 IStream* pstmOut)
2302 FIXME("\n");
2303 return E_NOTIMPL;
2307 * TODO: handle dwFlag and lpFallBack
2309 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringToUnicodeEx(
2310 IMultiLanguage3* iface,
2311 DWORD* pdwMode,
2312 DWORD dwEncoding,
2313 CHAR* pSrcStr,
2314 UINT* pcSrcSize,
2315 WCHAR* pDstStr,
2316 UINT* pcDstSize,
2317 DWORD dwFlag,
2318 WCHAR* lpFallBack)
2320 FIXME("\n");
2321 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2322 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2325 /*****************************************************************************
2326 * MultiLanguage2::ConvertStringToUnicodeEx
2328 * Translates the multibyte string from the specified code page to Unicode.
2330 * PARAMS
2331 * see ConvertStringToUnicode
2332 * dwFlag
2333 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
2334 * instead unconvertible characters.
2336 * RETURNS
2337 * S_OK Success.
2338 * S_FALSE The conversion is not supported.
2339 * E_FAIL Some error has occurred.
2341 * TODO: handle dwFlag and lpFallBack
2343 static HRESULT WINAPI fnIMultiLanguage2_ConvertStringFromUnicodeEx(
2344 IMultiLanguage3* This,
2345 DWORD* pdwMode,
2346 DWORD dwEncoding,
2347 WCHAR* pSrcStr,
2348 UINT* pcSrcSize,
2349 CHAR* pDstStr,
2350 UINT* pcDstSize,
2351 DWORD dwFlag,
2352 WCHAR* lpFallBack)
2354 FIXME("\n");
2355 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2356 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2359 static HRESULT WINAPI fnIMultiLanguage2_DetectCodepageInIStream(
2360 IMultiLanguage3* iface,
2361 DWORD dwFlag,
2362 DWORD dwPrefWinCodePage,
2363 IStream* pstmIn,
2364 DetectEncodingInfo* lpEncoding,
2365 INT* pnScores)
2367 FIXME("\n");
2368 return E_NOTIMPL;
2371 static HRESULT WINAPI fnIMultiLanguage2_DetectInputCodepage(
2372 IMultiLanguage3* iface,
2373 DWORD dwFlag,
2374 DWORD dwPrefWinCodePage,
2375 CHAR* pSrcStr,
2376 INT* pcSrcSize,
2377 DetectEncodingInfo* lpEncoding,
2378 INT* pnScores)
2380 FIXME("\n");
2381 return E_NOTIMPL;
2384 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePage(
2385 IMultiLanguage3* iface,
2386 UINT uiCodePage,
2387 HWND hwnd)
2389 FIXME("%u, %p\n", uiCodePage, hwnd);
2390 return E_NOTIMPL;
2393 static HRESULT WINAPI fnIMultiLanguage2_GetCodePageDescription(
2394 IMultiLanguage3* iface,
2395 UINT uiCodePage,
2396 LCID lcid,
2397 LPWSTR lpWideCharStr,
2398 int cchWideChar)
2400 FIXME("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
2401 return E_NOTIMPL;
2404 static HRESULT WINAPI fnIMultiLanguage2_IsCodePageInstallable(
2405 IMultiLanguage3* iface,
2406 UINT uiCodePage)
2408 FIXME("%u\n", uiCodePage);
2409 return E_NOTIMPL;
2412 static HRESULT WINAPI fnIMultiLanguage2_SetMimeDBSource(
2413 IMultiLanguage3* iface,
2414 MIMECONTF dwSource)
2416 FIXME("0x%08x\n", dwSource);
2417 return S_OK;
2420 static HRESULT WINAPI fnIMultiLanguage2_GetNumberOfScripts(
2421 IMultiLanguage3* iface,
2422 UINT* pnScripts)
2424 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2425 TRACE("%p %p\n", This, pnScripts);
2427 if (!pnScripts) return S_FALSE;
2429 *pnScripts = This->total_scripts;
2430 return S_OK;
2433 static HRESULT WINAPI fnIMultiLanguage2_EnumScripts(
2434 IMultiLanguage3* iface,
2435 DWORD dwFlags,
2436 LANGID LangId,
2437 IEnumScript** ppEnumScript)
2439 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2440 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
2442 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
2445 static HRESULT WINAPI fnIMultiLanguage2_ValidateCodePageEx(
2446 IMultiLanguage3* iface,
2447 UINT uiCodePage,
2448 HWND hwnd,
2449 DWORD dwfIODControl)
2451 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2452 FIXME("%p %u %p %08x: stub!\n", This, uiCodePage, hwnd, dwfIODControl);
2454 return S_FALSE;
2457 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
2458 IMultiLanguage3 *iface,
2459 DWORD dwFlags,
2460 LPCWSTR lpWideCharStr,
2461 UINT cchWideChar,
2462 UINT *puiPreferredCodePages,
2463 UINT nPreferredCodePages,
2464 UINT *puiDetectedCodePages,
2465 UINT *pnDetectedCodePages,
2466 WCHAR *lpSpecialChar)
2468 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2469 FIXME("(%p)->(%08x %s %u %p %u %p %p %p)\n", This, dwFlags, debugstr_w(lpWideCharStr),
2470 cchWideChar, puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
2471 pnDetectedCodePages, lpSpecialChar);
2472 return E_NOTIMPL;
2475 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
2476 IMultiLanguage3 *iface,
2477 DWORD dwFlags,
2478 IStream *pStrIn,
2479 UINT *puiPreferredCodePages,
2480 UINT nPreferredCodePages,
2481 UINT *puiDetectedCodePages,
2482 UINT *pnDetectedCodePages,
2483 WCHAR *lpSpecialChar)
2485 ICOM_THIS_MULTI(MLang_impl, vtbl_IMultiLanguage3, iface);
2486 FIXME("(%p)->(%08x %p %p %u %p %p %p)\n", This, dwFlags, pStrIn,
2487 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
2488 pnDetectedCodePages, lpSpecialChar);
2489 return E_NOTIMPL;
2492 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
2494 fnIMultiLanguage2_QueryInterface,
2495 fnIMultiLanguage2_AddRef,
2496 fnIMultiLanguage2_Release,
2497 fnIMultiLanguage2_GetNumberOfCodePageInfo,
2498 fnIMultiLanguage2_GetCodePageInfo,
2499 fnIMultiLanguage2_GetFamilyCodePage,
2500 fnIMultiLanguage2_EnumCodePages,
2501 fnIMultiLanguage2_GetCharsetInfo,
2502 fnIMultiLanguage2_IsConvertible,
2503 fnIMultiLanguage2_ConvertString,
2504 fnIMultiLanguage2_ConvertStringToUnicode,
2505 fnIMultiLanguage2_ConvertStringFromUnicode,
2506 fnIMultiLanguage2_ConvertStringReset,
2507 fnIMultiLanguage2_GetRfc1766FromLcid,
2508 fnIMultiLanguage2_GetLcidFromRfc1766,
2509 fnIMultiLanguage2_EnumRfc1766,
2510 fnIMultiLanguage2_GetRfc1766Info,
2511 fnIMultiLanguage2_CreateConvertCharset,
2512 fnIMultiLanguage2_ConvertStringInIStream,
2513 fnIMultiLanguage2_ConvertStringToUnicodeEx,
2514 fnIMultiLanguage2_ConvertStringFromUnicodeEx,
2515 fnIMultiLanguage2_DetectCodepageInIStream,
2516 fnIMultiLanguage2_DetectInputCodepage,
2517 fnIMultiLanguage2_ValidateCodePage,
2518 fnIMultiLanguage2_GetCodePageDescription,
2519 fnIMultiLanguage2_IsCodePageInstallable,
2520 fnIMultiLanguage2_SetMimeDBSource,
2521 fnIMultiLanguage2_GetNumberOfScripts,
2522 fnIMultiLanguage2_EnumScripts,
2523 fnIMultiLanguage2_ValidateCodePageEx,
2524 fnIMultiLanguage3_DetectOutboundCodePage,
2525 fnIMultiLanguage3_DetectOutboundCodePageInIStream
2528 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2530 MLang_impl *mlang;
2531 UINT i;
2533 TRACE("Creating MultiLanguage object\n");
2535 if( pUnkOuter )
2536 return CLASS_E_NOAGGREGATION;
2538 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
2539 mlang->vtbl_IMLangFontLink = &IMLangFontLink_vtbl;
2540 mlang->vtbl_IMultiLanguage = &IMultiLanguage_vtbl;
2541 mlang->vtbl_IMultiLanguage3 = &IMultiLanguage3_vtbl;
2543 mlang->total_cp = 0;
2544 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2545 mlang->total_cp += mlang_data[i].number_of_cp;
2547 /* do not enumerate unicode flavours */
2548 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
2550 mlang->ref = 1;
2551 *ppObj = (LPVOID) mlang;
2552 TRACE("returning %p\n", mlang);
2554 LockModule();
2556 return S_OK;
2559 /******************************************************************************/
2561 HRESULT WINAPI DllCanUnloadNow(void)
2563 return dll_count == 0 ? S_OK : S_FALSE;
2566 HRESULT WINAPI GetGlobalFontLinkObject(void)
2568 FIXME("\n");
2569 return S_FALSE;