wined3d: Explicitly calculate the sub-resource level in wined3d_surface_upload_data().
[wine.git] / dlls / mlang / mlang.c
blobbada104a36f1bc4c9f99f3f50bccaacbfb43bd49
1 /*
2 * MLANG Class Factory
4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003,2004 Mike McCormack
6 * Copyright 2004,2005 Dmitry Timoshkov
7 * Copyright 2009 Detlef Riekenberg
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "ole2.h"
36 #include "objbase.h"
37 #include "rpcproxy.h"
38 #include "mlang.h"
39 #include "mimeole.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43 #include "wine/list.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mlang);
47 #include "initguid.h"
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 const WCHAR *alias;
70 } MIME_CP_INFO;
72 /* These data are based on the codepage info in libs/unicode/cpmap.pl */
73 /* FIXME: Add 28604 (Celtic), 28606 (Balkan) */
75 static const MIME_CP_INFO arabic_cp[] =
77 { "Arabic (864)",
78 864, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
79 MIMECONTF_MIME_LATEST,
80 "ibm864", "ibm864", "ibm864" },
81 { "Arabic (1006)",
82 1006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
83 MIMECONTF_MIME_LATEST,
84 "ibm1006", "ibm1006", "ibm1006" },
85 { "Arabic (Windows)",
86 1256, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
87 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
88 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
89 "windows-1256", "windows-1256", "windows-1256" },
90 { "Arabic (ISO)",
91 28596, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
92 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
93 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
94 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
95 "iso-8859-6", "iso-8859-6", "iso-8859-6" }
97 static const MIME_CP_INFO baltic_cp[] =
99 { "Baltic (DOS)",
100 775, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
101 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
102 "ibm775", "ibm775", "ibm775" },
103 { "Baltic (Windows)",
104 1257, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
105 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
106 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
107 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
108 "windows-1257", "windows-1257", "windows-1257" },
109 { "Baltic (ISO)",
110 28594, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
111 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
112 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
113 MIMECONTF_MIME_LATEST,
114 "iso-8859-4", "iso-8859-4", "iso-8859-4" },
115 { "Estonian (ISO)",
116 28603, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
117 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
118 "iso-8859-13", "iso-8859-13", "iso-8859-13" }
120 static const MIME_CP_INFO chinese_simplified_cp[] =
122 { "Chinese Simplified (Auto-Select)",
123 50936, MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
124 MIMECONTF_MIME_LATEST,
125 "_autodetect_chs", "_autodetect_chs", "_autodetect_chs" },
126 { "Chinese Simplified (GB2312)",
127 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
128 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
129 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
130 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
131 "gb2312", "gb2312", "gb2312" },
132 { "Chinese Simplified (GB2312-80)",
133 20936, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
134 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
135 "x-cp20936", "x-cp20936", "x-cp20936" },
136 { "Chinese Simplified (HZ)",
137 52936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
138 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
139 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
140 MIMECONTF_MIME_LATEST,
141 "hz-gb-2312", "hz-gb-2312", "hz-gb-2312" },
142 { "Chinese Simplified (GB18030)",
143 54936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
144 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
145 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
146 MIMECONTF_MIME_LATEST,
147 "GB18030", "GB18030", "GB18030" },
148 { "Chinese Simplified (GBK)",
149 936, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
150 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
151 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
152 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
153 "gbk", "gbk", "gbk" }
155 static const MIME_CP_INFO chinese_traditional_cp[] =
157 { "Chinese Traditional (Auto-Select)",
158 50950, MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
159 MIMECONTF_MIME_LATEST,
160 "_autodetect_cht", "_autodetect_cht", "_autodetect_cht" },
161 { "Chinese Traditional (Big5)",
162 950, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
163 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
164 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
165 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
166 "big5", "big5", "big5" },
167 { "Chinese Traditional (CNS)",
168 20000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
169 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
170 "x-Chinese-CNS", "x-Chinese-CNS", "x-Chinese-CNS" }
172 static const MIME_CP_INFO central_european_cp[] =
174 { "Central European (DOS)",
175 852, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
176 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
177 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
178 "ibm852", "ibm852", "ibm852" },
179 { "Central European (Windows)",
180 1250, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
181 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
182 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
183 MIMECONTF_MIME_LATEST,
184 "windows-1250", "windows-1250", "windows-1250" },
185 { "Central European (Mac)",
186 10029, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
187 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
188 "x-mac-ce", "x-mac-ce", "x-mac-ce" },
189 { "Central European (ISO)",
190 28592, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
191 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
192 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
193 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
194 "iso-8859-2", "iso-8859-2", "iso-8859-2" }
196 static const MIME_CP_INFO cyrillic_cp[] =
198 { "OEM Cyrillic",
199 855, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
200 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
201 "ibm855", "ibm855", "ibm855" },
202 { "Cyrillic (DOS)",
203 866, MIMECONTF_BROWSER | MIMECONTF_IMPORT | MIMECONTF_SAVABLE_BROWSER |
204 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
205 MIMECONTF_MIME_LATEST,
206 "cp866", "cp866", "cp866" },
207 #if 0 /* Windows has 20866 as an official code page for KOI8-R */
208 { "Cyrillic (KOI8-R)",
209 878, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
210 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
211 "koi8-r", "koi8-r", "koi8-r" },
212 #endif
213 { "Cyrillic (Windows)",
214 1251, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
215 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
216 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
217 "windows-1251", "windows-1251", "windows-1251" },
218 { "Cyrillic (Mac)",
219 10007, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
220 MIMECONTF_MIME_LATEST,
221 "x-mac-cyrillic", "x-mac-cyrillic", "x-mac-cyrillic" },
222 { "Cyrillic (KOI8-R)",
223 20866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
224 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
225 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
226 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
227 "koi8-r", "koi8-r", "koi8-r" },
228 { "Cyrillic (KOI8-U)",
229 21866, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
230 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
231 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
232 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
233 "koi8-u", "koi8-u", "koi8-u" },
234 { "Cyrillic (ISO)",
235 28595, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
236 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
237 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
238 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
239 "iso-8859-5", "iso-8859-5", "iso-8859-5" }
241 static const MIME_CP_INFO greek_cp[] =
243 { "Greek (DOS)",
244 737, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
245 MIMECONTF_MIME_LATEST,
246 "ibm737", "ibm737", "ibm737" },
247 { "Greek, Modern (DOS)",
248 869, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
249 MIMECONTF_MIME_LATEST,
250 "ibm869", "ibm869", "ibm869" },
251 { "IBM EBCDIC (Greek Modern)",
252 875, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
253 MIMECONTF_MIME_LATEST,
254 "cp875", "cp875", "cp875" },
255 { "Greek (Windows)",
256 1253, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
257 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
258 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
259 "windows-1253", "windows-1253", "windows-1253" },
260 { "Greek (Mac)",
261 10006, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
262 MIMECONTF_MIME_LATEST,
263 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
264 { "Greek (ISO)",
265 28597, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
266 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
267 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
268 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
269 "iso-8859-7", "iso-8859-7", "iso-8859-7" }
271 static const MIME_CP_INFO hebrew_cp[] =
273 { "Hebrew (424)",
274 424, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
275 MIMECONTF_MIME_LATEST,
276 "ibm424", "ibm424", "ibm424" },
277 { "Hebrew (856)",
278 856, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
279 MIMECONTF_MIME_LATEST,
280 "cp856", "cp856", "cp856" },
281 { "Hebrew (DOS)",
282 862, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
283 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
284 MIMECONTF_MIME_LATEST,
285 "dos-862", "dos-862", "dos-862" },
286 { "Hebrew (Windows)",
287 1255, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
288 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
289 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
290 "windows-1255", "windows-1255", "windows-1255" },
291 { "Hebrew (ISO-Visual)",
292 28598, MIMECONTF_BROWSER | MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
293 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
294 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
295 "iso-8859-8", "iso-8859-8", "iso-8859-8" }
297 static const MIME_CP_INFO japanese_cp[] =
299 { "Japanese (Auto-Select)",
300 50932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
301 MIMECONTF_IMPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
302 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
303 "_autodetect", "_autodetect", "_autodetect" },
304 { "Japanese (EUC)",
305 51932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
306 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
307 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
308 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
309 "euc-jp", "euc-jp", "euc-jp" },
310 { "Japanese (JIS)",
311 50220, MIMECONTF_IMPORT | MIMECONTF_MAILNEWS | MIMECONTF_EXPORT |
312 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
313 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST |
314 MIMECONTF_MIME_IE4,
315 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
316 { "Japanese (JIS 0208-1990 and 0212-1990)",
317 20932, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
318 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
319 "EUC-JP","EUC-JP","EUC-JP"},
320 { "Japanese (JIS-Allow 1 byte Kana)",
321 50221, MIMECONTF_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_SAVABLE_BROWSER |
322 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID_NLS |
323 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
324 "csISO2022JP","iso-2022-jp","iso-2022-jp"},
325 { "Japanese (JIS-Allow 1 byte Kana - SO/SI)",
326 50222, MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_VALID |
327 MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
328 "iso-2022-jp","iso-2022-jp","iso-2022-jp"},
329 { "Japanese (Mac)",
330 10001, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
331 MIMECONTF_VALID | MIMECONTF_PRIVCONVERTER | MIMECONTF_MIME_LATEST,
332 "x-mac-japanese","x-mac-japanese","x-mac-japanese"},
333 { "Japanese (Shift-JIS)",
334 932, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
335 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
336 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
337 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
338 "shift_jis", "iso-2022-jp", "iso-2022-jp" }
340 static const MIME_CP_INFO korean_cp[] =
342 { "Korean",
343 949, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
344 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
345 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID_NLS |
346 MIMECONTF_MIME_LATEST,
347 "ks_c_5601-1987", "ks_c_5601-1987", "ks_c_5601-1987" }
349 static const MIME_CP_INFO thai_cp[] =
351 { "Thai (Windows)",
352 874, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_MIME_LATEST,
353 "ibm-thai", "ibm-thai", "ibm-thai" }
355 static const MIME_CP_INFO turkish_cp[] =
357 { "Turkish (DOS)",
358 857, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
359 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
360 "ibm857", "ibm857", "ibm857" },
361 { "IBM EBCDIC (Turkish Latin-5)",
362 1026, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
363 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
364 "ibm1026", "ibm1026", "ibm1026" },
365 { "Turkish (Windows)",
366 1254, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
367 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
368 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
369 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
370 "windows-1254", "windows-1254", "windows-1254" },
371 { "Turkish (Mac)",
372 10081, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
373 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
374 "x-mac-turkish", "x-mac-turkish", "x-mac-turkish" },
375 { "Latin 3 (ISO)",
376 28593, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
377 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
378 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
379 "iso-8859-3", "iso-8859-3", "iso-8859-3" },
380 { "Turkish (ISO)",
381 28599, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
382 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
383 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
384 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
385 "iso-8859-9", "iso-8859-9", "iso-8859-9" }
387 static const MIME_CP_INFO vietnamese_cp[] =
389 { "Vietnamese (Windows)",
390 1258, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
391 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
392 MIMECONTF_EXPORT | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
393 MIMECONTF_MIME_LATEST,
394 "windows-1258", "windows-1258", "windows-1258" }
397 static const WCHAR asciiW[] = {'a','s','c','i','i',0};
399 static const MIME_CP_INFO western_cp[] =
401 { "IBM EBCDIC (US-Canada)",
402 37, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
403 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
404 "ibm037", "ibm037", "ibm037" },
405 { "OEM United States",
406 437, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
407 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
408 "ibm437", "ibm437", "ibm437" },
409 { "IBM EBCDIC (International)",
410 500, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
411 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
412 "ibm500", "ibm500", "ibm500" },
413 { "Western European (DOS)",
414 850, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
415 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
416 "ibm850", "ibm850", "ibm850" },
417 { "Portuguese (DOS)",
418 860, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
419 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
420 "ibm860", "ibm860", "ibm860" },
421 { "Icelandic (DOS)",
422 861, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
423 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
424 "ibm861", "ibm861", "ibm861" },
425 { "French Canadian (DOS)",
426 863, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
427 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
428 "ibm863", "ibm863", "ibm863" },
429 { "Nordic (DOS)",
430 865, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
431 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
432 "ibm865", "ibm865", "ibm865" },
433 { "Western European (Windows)",
434 1252, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_MINIMAL |
435 MIMECONTF_IMPORT | MIMECONTF_SAVABLE_MAILNEWS |
436 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT | MIMECONTF_VALID |
437 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
438 "windows-1252", "windows-1252", "iso-8859-1" },
439 { "Western European (Mac)",
440 10000, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
441 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
442 "macintosh", "macintosh", "macintosh" },
443 { "Icelandic (Mac)",
444 10079, MIMECONTF_IMPORT | MIMECONTF_EXPORT | MIMECONTF_VALID |
445 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
446 "x-mac-icelandic", "x-mac-icelandic", "x-mac-icelandic" },
447 { "US-ASCII",
448 20127, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT | MIMECONTF_EXPORT |
449 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_VALID |
450 MIMECONTF_VALID_NLS | MIMECONTF_MIME_LATEST,
451 "us-ascii", "us-ascii", "us-ascii", asciiW },
452 { "Western European (ISO)",
453 28591, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
454 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
455 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
456 MIMECONTF_MIME_LATEST,
457 "iso-8859-1", "iso-8859-1", "iso-8859-1" },
458 { "Latin 9 (ISO)",
459 28605, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
460 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
461 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
462 MIMECONTF_MIME_LATEST,
463 "iso-8859-15", "iso-8859-15", "iso-8859-15" }
465 static const MIME_CP_INFO unicode_cp[] =
467 { "Unicode",
468 CP_UNICODE, MIMECONTF_MINIMAL | MIMECONTF_IMPORT |
469 MIMECONTF_SAVABLE_BROWSER | MIMECONTF_EXPORT |
470 MIMECONTF_VALID | MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 |
471 MIMECONTF_MIME_LATEST,
472 "unicode", "unicode", "unicode" },
473 { "Unicode (UTF-7)",
474 CP_UTF7, MIMECONTF_MAILNEWS | MIMECONTF_IMPORT |
475 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_EXPORT | MIMECONTF_VALID |
476 MIMECONTF_VALID_NLS | MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
477 "utf-7", "utf-7", "utf-7" },
478 { "Unicode (UTF-8)",
479 CP_UTF8, MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_IMPORT |
480 MIMECONTF_SAVABLE_MAILNEWS | MIMECONTF_SAVABLE_BROWSER |
481 MIMECONTF_EXPORT | MIMECONTF_VALID | MIMECONTF_VALID_NLS |
482 MIMECONTF_MIME_IE4 | MIMECONTF_MIME_LATEST,
483 "utf-8", "utf-8", "utf-8" }
486 static const struct mlang_data
488 const char *description;
489 UINT family_codepage;
490 UINT number_of_cp;
491 const MIME_CP_INFO *mime_cp_info;
492 const char *fixed_font;
493 const char *proportional_font;
494 SCRIPT_ID sid;
495 } mlang_data[] =
497 { "Arabic",1256,sizeof(arabic_cp)/sizeof(arabic_cp[0]),arabic_cp,
498 "Simplified Arabic Fixed","Simplified Arabic", sidArabic },
499 { "Baltic",1257,sizeof(baltic_cp)/sizeof(baltic_cp[0]),baltic_cp,
500 "Courier New","Arial", sidAsciiLatin },
501 { "Chinese Simplified",936,sizeof(chinese_simplified_cp)/sizeof(chinese_simplified_cp[0]),chinese_simplified_cp,
502 "Simsun","Simsun", sidHan },
503 { "Chinese Traditional",950,sizeof(chinese_traditional_cp)/sizeof(chinese_traditional_cp[0]),chinese_traditional_cp,
504 "MingLiu","New MingLiu", sidBopomofo },
505 { "Central European",1250,sizeof(central_european_cp)/sizeof(central_european_cp[0]),central_european_cp,
506 "Courier New","Arial", sidAsciiLatin },
507 { "Cyrillic",1251,sizeof(cyrillic_cp)/sizeof(cyrillic_cp[0]),cyrillic_cp,
508 "Courier New","Arial", sidCyrillic },
509 { "Greek",1253,sizeof(greek_cp)/sizeof(greek_cp[0]),greek_cp,
510 "Courier New","Arial", sidGreek },
511 { "Hebrew",1255,sizeof(hebrew_cp)/sizeof(hebrew_cp[0]),hebrew_cp,
512 "Miriam Fixed","David", sidHebrew },
513 { "Japanese",932,sizeof(japanese_cp)/sizeof(japanese_cp[0]),japanese_cp,
514 "MS Gothic","MS PGothic", sidKana },
515 { "Korean",949,sizeof(korean_cp)/sizeof(korean_cp[0]),korean_cp,
516 "GulimChe","Gulim", sidHangul },
517 { "Thai",874,sizeof(thai_cp)/sizeof(thai_cp[0]),thai_cp,
518 "Tahoma","Tahoma", sidThai },
519 { "Turkish",1254,sizeof(turkish_cp)/sizeof(turkish_cp[0]),turkish_cp,
520 "Courier New","Arial", sidAsciiLatin },
521 { "Vietnamese",1258,sizeof(vietnamese_cp)/sizeof(vietnamese_cp[0]),vietnamese_cp,
522 "Courier New","Arial", sidAsciiLatin },
523 { "Western European",1252,sizeof(western_cp)/sizeof(western_cp[0]),western_cp,
524 "Courier New","Arial", sidAsciiLatin },
525 { "Unicode",CP_UNICODE,sizeof(unicode_cp)/sizeof(unicode_cp[0]),unicode_cp,
526 "Courier New","Arial" }
529 struct font_list
531 struct list list_entry;
532 HFONT base_font;
533 HFONT font;
534 UINT charset;
537 static struct list font_cache = LIST_INIT(font_cache);
538 static CRITICAL_SECTION font_cache_critical;
539 static CRITICAL_SECTION_DEBUG font_cache_critical_debug =
541 0, 0, &font_cache_critical,
542 { &font_cache_critical_debug.ProcessLocksList, &font_cache_critical_debug.ProcessLocksList },
543 0, 0, { (DWORD_PTR)(__FILE__ ": font_cache_critical") }
545 static CRITICAL_SECTION font_cache_critical = { &font_cache_critical_debug, -1, 0, 0, 0, 0 };
547 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info);
549 static LONG dll_count;
552 * Japanese Detection and Conversion Functions
555 #define HANKATA(A) ((A >= 161) && (A <= 223))
556 #define ISEUC(A) ((A >= 161) && (A <= 254))
557 #define NOTEUC(A,B) (((A >= 129) && (A <= 159)) && ((B >= 64) && (B <= 160)))
558 #define SJIS1(A) (((A >= 129) && (A <= 159)) || ((A >= 224) && (A <= 239)))
559 #define SJIS2(A) ((A >= 64) && (A <= 252))
560 #define ISMARU(A) ((A >= 202) && (A <= 206))
561 #define ISNIGORI(A) (((A >= 182) && (A <= 196)) || ((A >= 202) && (A <= 206)))
563 static UINT DetectJapaneseCode(LPCSTR input, DWORD count)
565 UINT code = 0;
566 DWORD i = 0;
567 unsigned char c1,c2;
569 while ((code == 0 || code == 51932) && i < count)
571 c1 = input[i];
572 if (c1 == 0x1b /* ESC */)
574 i++;
575 if (i >= count)
576 return code;
577 c1 = input[i];
578 if (c1 == '$')
580 i++;
581 if (i >= count)
582 return code;
583 c1 = input[i];
584 if (c1 =='B' || c1 == '@')
585 code = 50220;
587 if (c1 == 'K')
588 code = 50220;
590 else if (c1 >= 129)
592 i++;
593 if (i >= count)
594 return code;
595 c2 = input[i];
596 if NOTEUC(c1,c2)
597 code = 932;
598 else if (ISEUC(c1) && ISEUC(c2))
599 code = 51932;
600 else if (((c1 == 142)) && HANKATA(c2))
601 code = 51932;
603 i++;
605 return code;
608 static inline void jis2sjis(unsigned char *p1, unsigned char *p2)
610 unsigned char c1 = *p1;
611 unsigned char c2 = *p2;
612 int row = c1 < 95 ? 112 : 176;
613 int cell = c1 % 2 ? 31 + (c2 > 95) : 126;
615 *p1 = ((c1 + 1) >> 1) + row;
616 *p2 = c2 + cell;
619 static inline void sjis2jis(unsigned char *p1, unsigned char *p2)
621 unsigned char c1 = *p1;
622 unsigned char c2 = *p2;
623 int shift = c2 < 159;
624 int row = c1 < 160 ? 112 : 176;
625 int cell = shift ? (31 + (c2 > 127)): 126;
627 *p1 = ((c1 - row) << 1) - shift;
628 *p2 -= cell;
631 static int han2zen(unsigned char *p1, unsigned char *p2)
633 BOOL maru = FALSE;
634 BOOL nigori = FALSE;
635 static const unsigned char char1[] = {129,129,129,129,129,131,131,131,131,
636 131,131,131,131,131,131,129,131,131,131,131,131,131,131,131,131,131,
637 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
638 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
639 131,129,129 };
640 static const unsigned char char2[] = {66,117,118,65,69,146,64,66,68,70,
641 72,131,133,135,98,91,65,67,69,71,73,74,76,78,80,82,84,86,88,90,92,94,
642 96,99,101,103,105,106,107,108,109,110,113,116,119,122,125,126,128,
643 129,130,132,134,136,137,138,139,140,141,143,147,74,75};
645 if (( *p2 == 222) && ((ISNIGORI(*p1) || (*p1 == 179))))
646 nigori = TRUE;
647 else if ((*p2 == 223) && (ISMARU(*p1)))
648 maru = TRUE;
650 if (*p1 >= 161 && *p1 <= 223)
652 unsigned char index = *p1 - 161;
653 *p1 = char1[index];
654 *p2 = char2[index];
657 if (maru || nigori)
659 if (nigori)
661 if (((*p2 >= 74) && (*p2 <= 103)) || ((*p2 >= 110) && (*p2 <= 122)))
662 (*p2)++;
663 else if ((*p1 == 131) && (*p2 == 69))
664 *p2 = 148;
666 else if ((maru) && ((*p2 >= 110) && (*p2 <= 122)))
667 *p2+= 2;
669 return 1;
672 return 0;
676 static UINT ConvertJIS2SJIS(LPCSTR input, DWORD count, LPSTR output)
678 DWORD i = 0;
679 int j = 0;
680 unsigned char p2,p;
681 BOOL shifted = FALSE;
683 while (i < count)
685 p = input[i];
686 if (p == 0x1b /* ESC */)
688 i++;
689 if (i >= count)
690 return 0;
691 p2 = input[i];
692 if (p2 == '$' || p2 =='(')
693 i++;
694 if (p2 == 'K' || p2 =='$')
695 shifted = TRUE;
696 else
697 shifted = FALSE;
699 else
701 if (shifted)
703 i++;
704 if (i >= count)
705 return 0;
706 p2 = input[i];
707 jis2sjis(&p,&p2);
708 output[j++]=p;
709 output[j++]=p2;
711 else
713 output[j++] = p;
716 i++;
718 return j;
721 static inline int exit_shift(LPSTR out, int c)
723 if (out)
725 out[c] = 0x1b;
726 out[c+1] = '(';
727 out[c+2] = 'B';
729 return 3;
732 static inline int enter_shift(LPSTR out, int c)
734 if (out)
736 out[c] = 0x1b;
737 out[c+1] = '$';
738 out[c+2] = 'B';
740 return 3;
744 static UINT ConvertSJIS2JIS(LPCSTR input, DWORD count, LPSTR output)
746 DWORD i = 0;
747 int j = 0;
748 unsigned char p2,p;
749 BOOL shifted = FALSE;
751 while (i < count)
753 p = input[i] & 0xff;
754 if (p == 10 || p == 13) /* NL and CR */
756 if (shifted)
758 shifted = FALSE;
759 j += exit_shift(output,j);
761 if (output)
762 output[j++] = p;
763 else
764 j++;
766 else
768 if (SJIS1(p))
770 i++;
771 if (i >= count)
772 return 0;
773 p2 = input[i] & 0xff;
774 if (SJIS2(p2))
776 sjis2jis(&p,&p2);
777 if (!shifted)
779 shifted = TRUE;
780 j+=enter_shift(output,j);
784 if (output)
786 output[j++]=p;
787 output[j++]=p2;
789 else
790 j+=2;
792 else
794 if (HANKATA(p))
796 if ((i+1) >= count)
797 return 0;
798 p2 = input[i+1] & 0xff;
799 i+=han2zen(&p,&p2);
800 sjis2jis(&p,&p2);
801 if (!shifted)
803 shifted = TRUE;
804 j+=enter_shift(output,j);
806 if (output)
808 output[j++]=p;
809 output[j++]=p2;
811 else
812 j+=2;
814 else
816 if (shifted)
818 shifted = FALSE;
819 j += exit_shift(output,j);
821 if (output)
822 output[j++]=p;
823 else
824 j++;
828 i++;
830 if (shifted)
831 j += exit_shift(output,j);
832 return j;
835 static UINT ConvertJISJapaneseToUnicode(LPCSTR input, DWORD count,
836 LPWSTR output, DWORD out_count)
838 CHAR *sjis_string;
839 UINT rc = 0;
840 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
841 rc = ConvertJIS2SJIS(input,count,sjis_string);
842 if (rc)
844 TRACE("%s\n",debugstr_an(sjis_string,rc));
845 if (output)
846 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
847 else
848 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
850 HeapFree(GetProcessHeap(),0,sjis_string);
851 return rc;
855 static UINT ConvertUnknownJapaneseToUnicode(LPCSTR input, DWORD count,
856 LPWSTR output, DWORD out_count)
858 CHAR *sjis_string;
859 UINT rc = 0;
860 int code = DetectJapaneseCode(input,count);
861 TRACE("Japanese code %i\n",code);
863 switch (code)
865 case 0:
866 if (output)
867 rc = MultiByteToWideChar(CP_ACP,0,input,count,output,out_count);
868 else
869 rc = MultiByteToWideChar(CP_ACP,0,input,count,0,0);
870 break;
872 case 932:
873 if (output)
874 rc = MultiByteToWideChar(932,0,input,count,output,out_count);
875 else
876 rc = MultiByteToWideChar(932,0,input,count,0,0);
877 break;
879 case 51932:
880 if (output)
881 rc = MultiByteToWideChar(20932,0,input,count,output,out_count);
882 else
883 rc = MultiByteToWideChar(20932,0,input,count,0,0);
884 break;
886 case 50220:
887 sjis_string = HeapAlloc(GetProcessHeap(),0,count);
888 rc = ConvertJIS2SJIS(input,count,sjis_string);
889 if (rc)
891 TRACE("%s\n",debugstr_an(sjis_string,rc));
892 if (output)
893 rc = MultiByteToWideChar(932,0,sjis_string,rc,output,out_count);
894 else
895 rc = MultiByteToWideChar(932,0,sjis_string,rc,0,0);
897 HeapFree(GetProcessHeap(),0,sjis_string);
898 break;
900 return rc;
903 static UINT ConvertJapaneseUnicodeToJIS(LPCWSTR input, DWORD count,
904 LPSTR output, DWORD out_count)
906 CHAR *sjis_string;
907 INT len;
908 UINT rc = 0;
910 len = WideCharToMultiByte(932,0,input,count,0,0,NULL,NULL);
911 sjis_string = HeapAlloc(GetProcessHeap(),0,len);
912 WideCharToMultiByte(932,0,input,count,sjis_string,len,NULL,NULL);
913 TRACE("%s\n",debugstr_an(sjis_string,len));
915 rc = ConvertSJIS2JIS(sjis_string, len, NULL);
916 if (out_count >= rc)
918 ConvertSJIS2JIS(sjis_string, len, output);
920 HeapFree(GetProcessHeap(),0,sjis_string);
921 return rc;
926 * Dll lifetime tracking declaration
928 static void LockModule(void)
930 InterlockedIncrement(&dll_count);
933 static void UnlockModule(void)
935 InterlockedDecrement(&dll_count);
938 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
940 switch(fdwReason) {
941 case DLL_PROCESS_ATTACH:
942 instance = hInstDLL;
943 MLANG_tls_index = TlsAlloc();
944 DisableThreadLibraryCalls(hInstDLL);
945 break;
946 case DLL_PROCESS_DETACH:
947 if (lpv) break;
948 TlsFree(MLANG_tls_index);
949 break;
951 return TRUE;
954 HRESULT WINAPI ConvertINetMultiByteToUnicode(
955 LPDWORD pdwMode,
956 DWORD dwEncoding,
957 LPCSTR pSrcStr,
958 LPINT pcSrcSize,
959 LPWSTR pDstStr,
960 LPINT pcDstSize)
962 INT src_len = -1;
964 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
965 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
967 if (!pcDstSize)
968 return E_FAIL;
970 if (!pcSrcSize)
971 pcSrcSize = &src_len;
973 if (!*pcSrcSize)
975 *pcDstSize = 0;
976 return S_OK;
979 /* forwarding euc-jp to EUC-JP */
980 if (dwEncoding == 51932)
981 dwEncoding = 20932;
983 switch (dwEncoding)
985 case CP_UNICODE:
986 if (*pcSrcSize == -1)
987 *pcSrcSize = lstrlenW((LPCWSTR)pSrcStr);
988 *pcDstSize = min(*pcSrcSize, *pcDstSize);
989 *pcSrcSize *= sizeof(WCHAR);
990 if (pDstStr)
991 memmove(pDstStr, pSrcStr, *pcDstSize * sizeof(WCHAR));
992 break;
994 case 50220:
995 case 50221:
996 case 50222:
997 *pcDstSize = ConvertJISJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
998 break;
999 case 50932:
1000 *pcDstSize = ConvertUnknownJapaneseToUnicode(pSrcStr,*pcSrcSize,pDstStr,*pcDstSize);
1001 break;
1003 default:
1004 if (*pcSrcSize == -1)
1005 *pcSrcSize = lstrlenA(pSrcStr);
1007 if (pDstStr)
1008 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize);
1009 else
1010 *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0);
1011 break;
1014 if (!*pcDstSize)
1015 return E_FAIL;
1017 return S_OK;
1020 HRESULT WINAPI ConvertINetUnicodeToMultiByte(
1021 LPDWORD pdwMode,
1022 DWORD dwEncoding,
1023 LPCWSTR pSrcStr,
1024 LPINT pcSrcSize,
1025 LPSTR pDstStr,
1026 LPINT pcDstSize)
1028 INT destsz, size;
1029 INT src_len = -1;
1031 TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
1032 debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1034 if (!pcDstSize)
1035 return S_OK;
1037 if (!pcSrcSize)
1038 pcSrcSize = &src_len;
1040 destsz = (pDstStr) ? *pcDstSize : 0;
1041 *pcDstSize = 0;
1043 if (!pSrcStr || !*pcSrcSize)
1044 return S_OK;
1046 if (*pcSrcSize == -1)
1047 *pcSrcSize = lstrlenW(pSrcStr);
1049 /* forwarding euc-jp to EUC-JP */
1050 if (dwEncoding == 51932)
1051 dwEncoding = 20932;
1053 if (dwEncoding == CP_UNICODE)
1055 if (*pcSrcSize == -1)
1056 *pcSrcSize = lstrlenW(pSrcStr);
1058 size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
1059 if (pDstStr)
1060 memmove(pDstStr, pSrcStr, size);
1062 if (size >= destsz)
1063 goto fail;
1065 else if (dwEncoding == 50220 || dwEncoding == 50221 || dwEncoding == 50222)
1067 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, NULL, 0);
1068 if (!size)
1069 goto fail;
1071 if (pDstStr)
1073 size = ConvertJapaneseUnicodeToJIS(pSrcStr, *pcSrcSize, pDstStr,
1074 destsz);
1075 if (!size)
1076 goto fail;
1080 else
1082 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1083 NULL, 0, NULL, NULL);
1084 if (!size)
1085 goto fail;
1087 if (pDstStr)
1089 size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
1090 pDstStr, destsz, NULL, NULL);
1091 if (!size)
1092 goto fail;
1096 *pcDstSize = size;
1097 return S_OK;
1099 fail:
1100 *pcSrcSize = 0;
1101 *pcDstSize = 0;
1102 return E_FAIL;
1105 HRESULT WINAPI ConvertINetString(
1106 LPDWORD pdwMode,
1107 DWORD dwSrcEncoding,
1108 DWORD dwDstEncoding,
1109 LPCSTR pSrcStr,
1110 LPINT pcSrcSize,
1111 LPSTR pDstStr,
1112 LPINT pcDstSize
1115 TRACE("%p %d %d %s %p %p %p\n", pdwMode, dwSrcEncoding, dwDstEncoding,
1116 debugstr_a(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
1118 if (dwSrcEncoding == CP_UNICODE)
1120 INT cSrcSizeW;
1121 if (pcSrcSize && *pcSrcSize != -1)
1123 cSrcSizeW = *pcSrcSize / sizeof(WCHAR);
1124 pcSrcSize = &cSrcSizeW;
1126 return ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, (LPCWSTR)pSrcStr, pcSrcSize, pDstStr, pcDstSize);
1128 else if (dwDstEncoding == CP_UNICODE)
1130 HRESULT hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, (LPWSTR)pDstStr, pcDstSize);
1131 *pcDstSize *= sizeof(WCHAR);
1132 return hr;
1134 else
1136 INT cDstSizeW;
1137 LPWSTR pDstStrW;
1138 HRESULT hr;
1140 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr), dwSrcEncoding, dwDstEncoding);
1142 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, NULL, &cDstSizeW);
1143 if (hr != S_OK)
1144 return hr;
1146 pDstStrW = HeapAlloc(GetProcessHeap(), 0, cDstSizeW * sizeof(WCHAR));
1147 hr = ConvertINetMultiByteToUnicode(pdwMode, dwSrcEncoding, pSrcStr, pcSrcSize, pDstStrW, &cDstSizeW);
1148 if (hr == S_OK)
1149 hr = ConvertINetUnicodeToMultiByte(pdwMode, dwDstEncoding, pDstStrW, &cDstSizeW, pDstStr, pcDstSize);
1151 HeapFree(GetProcessHeap(), 0, pDstStrW);
1152 return hr;
1156 static HRESULT GetFamilyCodePage(
1157 UINT uiCodePage,
1158 UINT* puiFamilyCodePage)
1160 UINT i, n;
1162 TRACE("%u %p\n", uiCodePage, puiFamilyCodePage);
1164 if (!puiFamilyCodePage) return S_FALSE;
1166 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1168 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1170 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
1172 *puiFamilyCodePage = mlang_data[i].family_codepage;
1173 return S_OK;
1178 return S_FALSE;
1181 HRESULT WINAPI IsConvertINetStringAvailable(
1182 DWORD dwSrcEncoding,
1183 DWORD dwDstEncoding)
1185 UINT src_family, dst_family;
1187 TRACE("%d %d\n", dwSrcEncoding, dwDstEncoding);
1189 if (GetFamilyCodePage(dwSrcEncoding, &src_family) != S_OK ||
1190 GetFamilyCodePage(dwDstEncoding, &dst_family) != S_OK)
1191 return S_FALSE;
1193 if (src_family == dst_family) return S_OK;
1195 /* we can convert any codepage to/from unicode */
1196 if (src_family == CP_UNICODE || dst_family == CP_UNICODE) return S_OK;
1198 return S_FALSE;
1201 static inline HRESULT lcid_to_rfc1766A( LCID lcid, LPSTR rfc1766, INT len )
1203 CHAR buffer[MAX_RFC1766_NAME];
1204 INT n = GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1205 INT i;
1207 if (n)
1209 i = PRIMARYLANGID(lcid);
1210 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1211 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1212 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1214 buffer[n - 1] = '-';
1215 i = GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1216 if (!i)
1217 buffer[n - 1] = '\0';
1219 else
1220 i = 0;
1222 LCMapStringA( LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len );
1223 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1225 return E_FAIL;
1228 static inline HRESULT lcid_to_rfc1766W( LCID lcid, LPWSTR rfc1766, INT len )
1230 WCHAR buffer[MAX_RFC1766_NAME];
1231 INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, MAX_RFC1766_NAME);
1232 INT i;
1234 if (n)
1236 i = PRIMARYLANGID(lcid);
1237 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
1238 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
1239 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
1241 buffer[n - 1] = '-';
1242 i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, MAX_RFC1766_NAME - n);
1243 if (!i)
1244 buffer[n - 1] = '\0';
1246 else
1247 i = 0;
1249 LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
1250 return ((n + i) > len) ? E_INVALIDARG : S_OK;
1252 return E_FAIL;
1255 HRESULT WINAPI LcidToRfc1766A(
1256 LCID lcid,
1257 LPSTR pszRfc1766,
1258 INT nChar)
1260 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1261 if (!pszRfc1766)
1262 return E_INVALIDARG;
1264 return lcid_to_rfc1766A(lcid, pszRfc1766, nChar);
1267 HRESULT WINAPI LcidToRfc1766W(
1268 LCID lcid,
1269 LPWSTR pszRfc1766,
1270 INT nChar)
1272 TRACE("%04x %p %u\n", lcid, pszRfc1766, nChar);
1273 if (!pszRfc1766)
1274 return E_INVALIDARG;
1276 return lcid_to_rfc1766W(lcid, pszRfc1766, nChar);
1279 static HRESULT lcid_from_rfc1766(IEnumRfc1766 *iface, LCID *lcid, LPCWSTR rfc1766)
1281 RFC1766INFO info;
1282 ULONG num;
1284 while (IEnumRfc1766_Next(iface, 1, &info, &num) == S_OK)
1286 if (!strcmpiW(info.wszRfc1766, rfc1766))
1288 *lcid = info.lcid;
1289 return S_OK;
1291 if (strlenW(rfc1766) == 2 && !memcmp(info.wszRfc1766, rfc1766, 2 * sizeof(WCHAR)))
1293 *lcid = PRIMARYLANGID(info.lcid);
1294 return S_OK;
1298 return E_FAIL;
1301 HRESULT WINAPI Rfc1766ToLcidW(LCID *pLocale, LPCWSTR pszRfc1766)
1303 IEnumRfc1766 *enumrfc1766;
1304 HRESULT hr;
1306 TRACE("(%p, %s)\n", pLocale, debugstr_w(pszRfc1766));
1308 if (!pLocale || !pszRfc1766)
1309 return E_INVALIDARG;
1311 hr = EnumRfc1766_create(0, &enumrfc1766);
1312 if (FAILED(hr))
1313 return hr;
1315 hr = lcid_from_rfc1766(enumrfc1766, pLocale, pszRfc1766);
1316 IEnumRfc1766_Release(enumrfc1766);
1318 return hr;
1321 HRESULT WINAPI Rfc1766ToLcidA(LCID *lcid, LPCSTR rfc1766A)
1323 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1325 if (!rfc1766A)
1326 return E_INVALIDARG;
1328 MultiByteToWideChar(CP_ACP, 0, rfc1766A, -1, rfc1766W, MAX_RFC1766_NAME);
1329 rfc1766W[MAX_RFC1766_NAME] = 0;
1331 return Rfc1766ToLcidW(lcid, rfc1766W);
1334 static HRESULT map_font(HDC hdc, DWORD codepages, HFONT src_font, HFONT *dst_font)
1336 struct font_list *font_list_entry;
1337 CHARSETINFO charset_info;
1338 HFONT new_font, old_font;
1339 LOGFONTW font_attr;
1340 DWORD mask, Csb[2];
1341 BOOL found_cached;
1342 UINT charset;
1343 BOOL ret;
1344 UINT i;
1346 if (hdc == NULL || src_font == NULL) return E_FAIL;
1348 for (i = 0; i < 32; i++)
1350 mask = (DWORD)(1 << i);
1351 if (codepages & mask)
1353 Csb[0] = mask;
1354 Csb[1] = 0x0;
1355 ret = TranslateCharsetInfo(Csb, &charset_info, TCI_SRCFONTSIG);
1356 if (!ret) continue;
1358 /* use cached font if possible */
1359 found_cached = FALSE;
1360 EnterCriticalSection(&font_cache_critical);
1361 LIST_FOR_EACH_ENTRY(font_list_entry, &font_cache, struct font_list, list_entry)
1363 if (font_list_entry->charset == charset_info.ciCharset &&
1364 font_list_entry->base_font == src_font)
1366 if (dst_font != NULL)
1367 *dst_font = font_list_entry->font;
1368 found_cached = TRUE;
1371 LeaveCriticalSection(&font_cache_critical);
1372 if (found_cached) return S_OK;
1374 GetObjectW(src_font, sizeof(font_attr), &font_attr);
1375 font_attr.lfCharSet = (BYTE)charset_info.ciCharset;
1376 font_attr.lfWidth = 0;
1377 font_attr.lfFaceName[0] = 0;
1378 new_font = CreateFontIndirectW(&font_attr);
1379 if (new_font == NULL) continue;
1381 old_font = SelectObject(hdc, new_font);
1382 charset = GetTextCharset(hdc);
1383 SelectObject(hdc, old_font);
1384 if (charset == charset_info.ciCharset)
1386 font_list_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*font_list_entry));
1387 if (font_list_entry == NULL) return E_OUTOFMEMORY;
1389 font_list_entry->base_font = src_font;
1390 font_list_entry->font = new_font;
1391 font_list_entry->charset = charset;
1393 EnterCriticalSection(&font_cache_critical);
1394 list_add_tail(&font_cache, &font_list_entry->list_entry);
1395 LeaveCriticalSection(&font_cache_critical);
1397 if (dst_font != NULL)
1398 *dst_font = new_font;
1399 return S_OK;
1404 return E_FAIL;
1407 static HRESULT release_font(HFONT font)
1409 struct font_list *font_list_entry;
1410 HRESULT hr;
1412 hr = E_FAIL;
1413 EnterCriticalSection(&font_cache_critical);
1414 LIST_FOR_EACH_ENTRY(font_list_entry, &font_cache, struct font_list, list_entry)
1416 if (font_list_entry->font == font)
1418 list_remove(&font_list_entry->list_entry);
1419 DeleteObject(font);
1420 HeapFree(GetProcessHeap(), 0, font_list_entry);
1421 hr = S_OK;
1422 break;
1425 LeaveCriticalSection(&font_cache_critical);
1427 return hr;
1430 static HRESULT clear_font_cache(void)
1432 struct font_list *font_list_entry;
1433 struct font_list *font_list_entry2;
1435 EnterCriticalSection(&font_cache_critical);
1436 LIST_FOR_EACH_ENTRY_SAFE(font_list_entry, font_list_entry2, &font_cache, struct font_list, list_entry)
1438 list_remove(&font_list_entry->list_entry);
1439 DeleteObject(font_list_entry->font);
1440 HeapFree(GetProcessHeap(), 0, font_list_entry);
1442 LeaveCriticalSection(&font_cache_critical);
1444 return S_OK;
1447 /******************************************************************************
1448 * MLANG ClassFactory
1450 typedef struct {
1451 IClassFactory IClassFactory_iface;
1452 LONG ref;
1453 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1454 } IClassFactoryImpl;
1456 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
1458 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
1461 struct object_creation_info
1463 const CLSID *clsid;
1464 LPCSTR szClassName;
1465 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
1468 static const struct object_creation_info object_creation[] =
1470 { &CLSID_CMultiLanguage, "CLSID_CMultiLanguage", MultiLanguage_create },
1471 { &CLSID_CMLangConvertCharset, "CLSID_CMLangConvertCharset", MLangConvertCharset_create }
1474 static HRESULT WINAPI MLANGCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
1476 TRACE("%s\n", debugstr_guid(riid) );
1478 if (IsEqualGUID(riid, &IID_IUnknown)
1479 || IsEqualGUID(riid, &IID_IClassFactory))
1481 IClassFactory_AddRef(iface);
1482 *ppobj = iface;
1483 return S_OK;
1486 *ppobj = NULL;
1487 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
1488 return E_NOINTERFACE;
1491 static ULONG WINAPI MLANGCF_AddRef(IClassFactory *iface)
1493 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1494 return InterlockedIncrement(&This->ref);
1497 static ULONG WINAPI MLANGCF_Release(IClassFactory *iface)
1499 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1500 ULONG ref = InterlockedDecrement(&This->ref);
1502 if (ref == 0)
1504 TRACE("Destroying %p\n", This);
1505 HeapFree(GetProcessHeap(), 0, This);
1508 return ref;
1511 static HRESULT WINAPI MLANGCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1512 REFIID riid, void **ppobj)
1514 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
1515 HRESULT hres;
1516 LPUNKNOWN punk;
1518 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1520 *ppobj = NULL;
1521 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
1522 if (SUCCEEDED(hres)) {
1523 hres = IUnknown_QueryInterface(punk, riid, ppobj);
1524 IUnknown_Release(punk);
1526 TRACE("returning (%p) -> %x\n", *ppobj, hres);
1527 return hres;
1530 static HRESULT WINAPI MLANGCF_LockServer(IClassFactory *iface, BOOL dolock)
1532 if (dolock)
1533 LockModule();
1534 else
1535 UnlockModule();
1537 return S_OK;
1540 static const IClassFactoryVtbl MLANGCF_Vtbl =
1542 MLANGCF_QueryInterface,
1543 MLANGCF_AddRef,
1544 MLANGCF_Release,
1545 MLANGCF_CreateInstance,
1546 MLANGCF_LockServer
1549 /******************************************************************
1550 * DllGetClassObject (MLANG.@)
1552 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
1554 unsigned int i;
1555 IClassFactoryImpl *factory;
1557 TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
1559 if ( !IsEqualGUID( &IID_IClassFactory, iid )
1560 && ! IsEqualGUID( &IID_IUnknown, iid) )
1561 return E_NOINTERFACE;
1563 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
1565 if (IsEqualGUID(object_creation[i].clsid, rclsid))
1566 break;
1569 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
1571 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
1572 return CLASS_E_CLASSNOTAVAILABLE;
1575 TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
1577 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
1578 if (factory == NULL) return E_OUTOFMEMORY;
1580 factory->IClassFactory_iface.lpVtbl = &MLANGCF_Vtbl;
1581 factory->ref = 1;
1583 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
1585 *ppv = &factory->IClassFactory_iface;
1587 TRACE("(%p) <- %p\n", ppv, &factory->IClassFactory_iface);
1589 return S_OK;
1593 /******************************************************************************/
1595 typedef struct tagMLang_impl
1597 IMLangFontLink IMLangFontLink_iface;
1598 IMultiLanguage IMultiLanguage_iface;
1599 IMultiLanguage3 IMultiLanguage3_iface;
1600 IMLangFontLink2 IMLangFontLink2_iface;
1601 IMLangLineBreakConsole IMLangLineBreakConsole_iface;
1602 LONG ref;
1603 DWORD total_cp, total_scripts;
1604 } MLang_impl;
1606 /******************************************************************************/
1608 typedef struct tagEnumCodePage_impl
1610 IEnumCodePage IEnumCodePage_iface;
1611 LONG ref;
1612 MIMECPINFO *cpinfo;
1613 DWORD total, pos;
1614 } EnumCodePage_impl;
1616 static inline EnumCodePage_impl *impl_from_IEnumCodePage( IEnumCodePage *iface )
1618 return CONTAINING_RECORD( iface, EnumCodePage_impl, IEnumCodePage_iface );
1621 static HRESULT WINAPI fnIEnumCodePage_QueryInterface(
1622 IEnumCodePage* iface,
1623 REFIID riid,
1624 void** ppvObject)
1626 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1628 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1630 if (IsEqualGUID(riid, &IID_IUnknown)
1631 || IsEqualGUID(riid, &IID_IEnumCodePage))
1633 IEnumCodePage_AddRef(iface);
1634 TRACE("Returning IID_IEnumCodePage %p ref = %d\n", This, This->ref);
1635 *ppvObject = &This->IEnumCodePage_iface;
1636 return S_OK;
1639 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1640 return E_NOINTERFACE;
1643 static ULONG WINAPI fnIEnumCodePage_AddRef(
1644 IEnumCodePage* iface)
1646 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1647 return InterlockedIncrement(&This->ref);
1650 static ULONG WINAPI fnIEnumCodePage_Release(
1651 IEnumCodePage* iface)
1653 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1654 ULONG ref = InterlockedDecrement(&This->ref);
1656 TRACE("%p ref = %d\n", This, ref);
1657 if (ref == 0)
1659 TRACE("Destroying %p\n", This);
1660 HeapFree(GetProcessHeap(), 0, This->cpinfo);
1661 HeapFree(GetProcessHeap(), 0, This);
1664 return ref;
1667 static HRESULT WINAPI fnIEnumCodePage_Clone(
1668 IEnumCodePage* iface,
1669 IEnumCodePage** ppEnum)
1671 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1672 FIXME("%p %p\n", This, ppEnum);
1673 return E_NOTIMPL;
1676 static HRESULT WINAPI fnIEnumCodePage_Next(
1677 IEnumCodePage* iface,
1678 ULONG celt,
1679 PMIMECPINFO rgelt,
1680 ULONG* pceltFetched)
1682 ULONG i;
1683 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1685 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1687 if (!pceltFetched) return S_FALSE;
1688 *pceltFetched = 0;
1690 if (!rgelt) return S_FALSE;
1692 if (This->pos + celt > This->total)
1693 celt = This->total - This->pos;
1695 if (!celt) return S_FALSE;
1697 memcpy(rgelt, This->cpinfo + This->pos, celt * sizeof(MIMECPINFO));
1698 *pceltFetched = celt;
1699 This->pos += celt;
1701 for (i = 0; i < celt; i++)
1703 TRACE("#%u: %08x %u %u %s %s %s %s %s %s %d\n",
1704 i, rgelt[i].dwFlags, rgelt[i].uiCodePage,
1705 rgelt[i].uiFamilyCodePage,
1706 wine_dbgstr_w(rgelt[i].wszDescription),
1707 wine_dbgstr_w(rgelt[i].wszWebCharset),
1708 wine_dbgstr_w(rgelt[i].wszHeaderCharset),
1709 wine_dbgstr_w(rgelt[i].wszBodyCharset),
1710 wine_dbgstr_w(rgelt[i].wszFixedWidthFont),
1711 wine_dbgstr_w(rgelt[i].wszProportionalFont),
1712 rgelt[i].bGDICharset);
1714 return S_OK;
1717 static HRESULT WINAPI fnIEnumCodePage_Reset(
1718 IEnumCodePage* iface)
1720 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1722 TRACE("%p\n", This);
1724 This->pos = 0;
1725 return S_OK;
1728 static HRESULT WINAPI fnIEnumCodePage_Skip(
1729 IEnumCodePage* iface,
1730 ULONG celt)
1732 EnumCodePage_impl *This = impl_from_IEnumCodePage( iface );
1734 TRACE("%p %u\n", This, celt);
1736 if (celt >= This->total) return S_FALSE;
1738 This->pos += celt;
1739 return S_OK;
1742 static const IEnumCodePageVtbl IEnumCodePage_vtbl =
1744 fnIEnumCodePage_QueryInterface,
1745 fnIEnumCodePage_AddRef,
1746 fnIEnumCodePage_Release,
1747 fnIEnumCodePage_Clone,
1748 fnIEnumCodePage_Next,
1749 fnIEnumCodePage_Reset,
1750 fnIEnumCodePage_Skip
1753 static HRESULT EnumCodePage_create( MLang_impl* mlang, DWORD grfFlags,
1754 LANGID LangId, IEnumCodePage** ppEnumCodePage )
1756 EnumCodePage_impl *ecp;
1757 MIMECPINFO *cpinfo;
1758 UINT i, n;
1760 TRACE("%p, %08x, %04x, %p\n", mlang, grfFlags, LangId, ppEnumCodePage);
1762 if (!grfFlags) /* enumerate internal data base of encodings */
1763 grfFlags = MIMECONTF_MIME_LATEST;
1765 ecp = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumCodePage_impl) );
1766 ecp->IEnumCodePage_iface.lpVtbl = &IEnumCodePage_vtbl;
1767 ecp->ref = 1;
1768 ecp->pos = 0;
1769 ecp->total = 0;
1770 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1772 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1774 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1775 ecp->total++;
1779 ecp->cpinfo = HeapAlloc(GetProcessHeap(), 0,
1780 sizeof(MIMECPINFO) * ecp->total);
1781 cpinfo = ecp->cpinfo;
1783 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
1785 for (n = 0; n < mlang_data[i].number_of_cp; n++)
1787 if (mlang_data[i].mime_cp_info[n].flags & grfFlags)
1788 fill_cp_info(&mlang_data[i], n, cpinfo++);
1792 TRACE("enumerated %d codepages with flags %08x\n", ecp->total, grfFlags);
1794 *ppEnumCodePage = &ecp->IEnumCodePage_iface;
1796 return S_OK;
1799 /******************************************************************************/
1801 typedef struct tagEnumScript_impl
1803 IEnumScript IEnumScript_iface;
1804 LONG ref;
1805 SCRIPTINFO *script_info;
1806 DWORD total, pos;
1807 } EnumScript_impl;
1809 static inline EnumScript_impl *impl_from_IEnumScript( IEnumScript *iface )
1811 return CONTAINING_RECORD( iface, EnumScript_impl, IEnumScript_iface );
1814 static HRESULT WINAPI fnIEnumScript_QueryInterface(
1815 IEnumScript* iface,
1816 REFIID riid,
1817 void** ppvObject)
1819 EnumScript_impl *This = impl_from_IEnumScript( iface );
1821 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
1823 if (IsEqualGUID(riid, &IID_IUnknown)
1824 || IsEqualGUID(riid, &IID_IEnumScript))
1826 IEnumScript_AddRef(iface);
1827 TRACE("Returning IID_IEnumScript %p ref = %d\n", This, This->ref);
1828 *ppvObject = &This->IEnumScript_iface;
1829 return S_OK;
1832 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1833 return E_NOINTERFACE;
1836 static ULONG WINAPI fnIEnumScript_AddRef(
1837 IEnumScript* iface)
1839 EnumScript_impl *This = impl_from_IEnumScript( iface );
1840 return InterlockedIncrement(&This->ref);
1843 static ULONG WINAPI fnIEnumScript_Release(
1844 IEnumScript* iface)
1846 EnumScript_impl *This = impl_from_IEnumScript( iface );
1847 ULONG ref = InterlockedDecrement(&This->ref);
1849 TRACE("%p ref = %d\n", This, ref);
1850 if (ref == 0)
1852 TRACE("Destroying %p\n", This);
1853 HeapFree(GetProcessHeap(), 0, This->script_info);
1854 HeapFree(GetProcessHeap(), 0, This);
1857 return ref;
1860 static HRESULT WINAPI fnIEnumScript_Clone(
1861 IEnumScript* iface,
1862 IEnumScript** ppEnum)
1864 EnumScript_impl *This = impl_from_IEnumScript( iface );
1865 FIXME("%p %p: stub!\n", This, ppEnum);
1866 return E_NOTIMPL;
1869 static HRESULT WINAPI fnIEnumScript_Next(
1870 IEnumScript* iface,
1871 ULONG celt,
1872 PSCRIPTINFO rgelt,
1873 ULONG* pceltFetched)
1875 EnumScript_impl *This = impl_from_IEnumScript( iface );
1877 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
1879 if (!pceltFetched || !rgelt) return E_FAIL;
1881 *pceltFetched = 0;
1883 if (This->pos + celt > This->total)
1884 celt = This->total - This->pos;
1886 if (!celt) return S_FALSE;
1888 memcpy(rgelt, This->script_info + This->pos, celt * sizeof(SCRIPTINFO));
1889 *pceltFetched = celt;
1890 This->pos += celt;
1892 return S_OK;
1895 static HRESULT WINAPI fnIEnumScript_Reset(
1896 IEnumScript* iface)
1898 EnumScript_impl *This = impl_from_IEnumScript( iface );
1900 TRACE("%p\n", This);
1902 This->pos = 0;
1903 return S_OK;
1906 static HRESULT WINAPI fnIEnumScript_Skip(
1907 IEnumScript* iface,
1908 ULONG celt)
1910 EnumScript_impl *This = impl_from_IEnumScript( iface );
1912 TRACE("%p %u\n", This, celt);
1914 if (celt >= This->total) return S_FALSE;
1916 This->pos += celt;
1917 return S_OK;
1920 static const IEnumScriptVtbl IEnumScript_vtbl =
1922 fnIEnumScript_QueryInterface,
1923 fnIEnumScript_AddRef,
1924 fnIEnumScript_Release,
1925 fnIEnumScript_Clone,
1926 fnIEnumScript_Next,
1927 fnIEnumScript_Reset,
1928 fnIEnumScript_Skip
1931 static HRESULT EnumScript_create( MLang_impl* mlang, DWORD dwFlags,
1932 LANGID LangId, IEnumScript** ppEnumScript )
1934 EnumScript_impl *es;
1935 UINT i;
1937 TRACE("%p, %08x, %04x, %p\n", mlang, dwFlags, LangId, ppEnumScript);
1939 if (!dwFlags) /* enumerate all available scripts */
1940 dwFlags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
1942 es = HeapAlloc( GetProcessHeap(), 0, sizeof (EnumScript_impl) );
1943 es->IEnumScript_iface.lpVtbl = &IEnumScript_vtbl;
1944 es->ref = 1;
1945 es->pos = 0;
1946 /* do not enumerate unicode flavours */
1947 es->total = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
1948 es->script_info = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPTINFO) * es->total);
1950 for (i = 0; i < es->total; i++)
1952 es->script_info[i].ScriptId = i;
1953 es->script_info[i].uiCodePage = mlang_data[i].family_codepage;
1954 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].description, -1,
1955 es->script_info[i].wszDescription, MAX_SCRIPT_NAME);
1956 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
1957 es->script_info[i].wszFixedWidthFont, MAX_MIMEFACE_NAME);
1958 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
1959 es->script_info[i].wszProportionalFont, MAX_MIMEFACE_NAME);
1962 TRACE("enumerated %d scripts with flags %08x\n", es->total, dwFlags);
1964 *ppEnumScript = &es->IEnumScript_iface;
1966 return S_OK;
1969 /******************************************************************************/
1971 static inline MLang_impl *impl_from_IMLangFontLink( IMLangFontLink *iface )
1973 return CONTAINING_RECORD( iface, MLang_impl, IMLangFontLink_iface );
1976 static HRESULT WINAPI fnIMLangFontLink_QueryInterface(
1977 IMLangFontLink* iface,
1978 REFIID riid,
1979 void** ppvObject)
1981 MLang_impl *This = impl_from_IMLangFontLink( iface );
1982 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
1985 static ULONG WINAPI fnIMLangFontLink_AddRef(
1986 IMLangFontLink* iface)
1988 MLang_impl *This = impl_from_IMLangFontLink( iface );
1989 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
1992 static ULONG WINAPI fnIMLangFontLink_Release(
1993 IMLangFontLink* iface)
1995 MLang_impl *This = impl_from_IMLangFontLink( iface );
1996 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
1999 static HRESULT WINAPI fnIMLangFontLink_GetCharCodePages(
2000 IMLangFontLink* iface,
2001 WCHAR ch_src,
2002 DWORD* codepages)
2004 MLang_impl *This = impl_from_IMLangFontLink( iface );
2005 return IMLangFontLink2_GetCharCodePages(&This->IMLangFontLink2_iface, ch_src, codepages);
2008 static HRESULT WINAPI fnIMLangFontLink_GetStrCodePages(
2009 IMLangFontLink* iface,
2010 const WCHAR* src,
2011 LONG src_len,
2012 DWORD priority_cp,
2013 DWORD* codepages,
2014 LONG* ret_len)
2016 MLang_impl *This = impl_from_IMLangFontLink( iface );
2017 return IMLangFontLink2_GetStrCodePages(&This->IMLangFontLink2_iface, src, src_len, priority_cp,
2018 codepages, ret_len);
2021 static HRESULT WINAPI fnIMLangFontLink_CodePageToCodePages(
2022 IMLangFontLink* iface,
2023 UINT codepage,
2024 DWORD* codepages)
2026 MLang_impl *This = impl_from_IMLangFontLink( iface );
2027 return IMLangFontLink2_CodePageToCodePages(&This->IMLangFontLink2_iface, codepage, codepages);
2030 static HRESULT WINAPI fnIMLangFontLink_CodePagesToCodePage(
2031 IMLangFontLink* iface,
2032 DWORD codepages,
2033 UINT def_codepage,
2034 UINT* codepage)
2036 MLang_impl *This = impl_from_IMLangFontLink(iface);
2037 return IMLangFontLink2_CodePagesToCodePage(&This->IMLangFontLink2_iface, codepages,
2038 def_codepage, codepage);
2041 static HRESULT WINAPI fnIMLangFontLink_GetFontCodePages(
2042 IMLangFontLink* iface,
2043 HDC hdc,
2044 HFONT hfont,
2045 DWORD* codepages)
2047 MLang_impl *This = impl_from_IMLangFontLink(iface);
2048 return IMLangFontLink2_GetFontCodePages(&This->IMLangFontLink2_iface, hdc, hfont, codepages);
2051 static HRESULT WINAPI fnIMLangFontLink_MapFont(
2052 IMLangFontLink* iface,
2053 HDC hDC,
2054 DWORD dwCodePages,
2055 HFONT hSrcFont,
2056 HFONT* phDestFont)
2058 TRACE("(%p)->%p %08x %p %p\n",iface, hDC, dwCodePages, hSrcFont, phDestFont);
2060 return map_font(hDC, dwCodePages, hSrcFont, phDestFont);
2063 static HRESULT WINAPI fnIMLangFontLink_ReleaseFont(
2064 IMLangFontLink* iface,
2065 HFONT hFont)
2067 TRACE("(%p)->%p\n",iface, hFont);
2069 return release_font(hFont);
2072 static HRESULT WINAPI fnIMLangFontLink_ResetFontMapping(
2073 IMLangFontLink* iface)
2075 TRACE("(%p)\n",iface);
2077 return clear_font_cache();
2081 static const IMLangFontLinkVtbl IMLangFontLink_vtbl =
2083 fnIMLangFontLink_QueryInterface,
2084 fnIMLangFontLink_AddRef,
2085 fnIMLangFontLink_Release,
2086 fnIMLangFontLink_GetCharCodePages,
2087 fnIMLangFontLink_GetStrCodePages,
2088 fnIMLangFontLink_CodePageToCodePages,
2089 fnIMLangFontLink_CodePagesToCodePage,
2090 fnIMLangFontLink_GetFontCodePages,
2091 fnIMLangFontLink_MapFont,
2092 fnIMLangFontLink_ReleaseFont,
2093 fnIMLangFontLink_ResetFontMapping,
2096 /******************************************************************************/
2098 static inline MLang_impl *impl_from_IMultiLanguage( IMultiLanguage *iface )
2100 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage_iface );
2103 static HRESULT WINAPI fnIMultiLanguage_QueryInterface(
2104 IMultiLanguage* iface,
2105 REFIID riid,
2106 void** obj)
2108 MLang_impl *This = impl_from_IMultiLanguage( iface );
2109 return IMultiLanguage3_QueryInterface(&This->IMultiLanguage3_iface, riid, obj);
2112 static ULONG WINAPI fnIMultiLanguage_AddRef( IMultiLanguage* iface )
2114 MLang_impl *This = impl_from_IMultiLanguage( iface );
2115 return IMultiLanguage3_AddRef(&This->IMultiLanguage3_iface);
2118 static ULONG WINAPI fnIMultiLanguage_Release( IMultiLanguage* iface )
2120 MLang_impl *This = impl_from_IMultiLanguage( iface );
2121 return IMultiLanguage3_Release(&This->IMultiLanguage3_iface);
2124 static HRESULT WINAPI fnIMultiLanguage_GetNumberOfCodePageInfo(
2125 IMultiLanguage* iface,
2126 UINT* cp)
2128 MLang_impl *This = impl_from_IMultiLanguage( iface );
2129 TRACE("(%p, %p)\n", This, cp);
2130 return IMultiLanguage3_GetNumberOfCodePageInfo(&This->IMultiLanguage3_iface, cp);
2133 static HRESULT WINAPI fnIMultiLanguage_GetCodePageInfo(
2134 IMultiLanguage* iface,
2135 UINT uiCodePage,
2136 PMIMECPINFO pCodePageInfo)
2138 UINT i, n;
2139 MLang_impl *This = impl_from_IMultiLanguage( iface );
2141 TRACE("%p, %u, %p\n", This, uiCodePage, pCodePageInfo);
2143 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2145 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2147 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2149 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2150 return S_OK;
2155 return S_FALSE;
2158 static HRESULT WINAPI fnIMultiLanguage_GetFamilyCodePage(
2159 IMultiLanguage* iface,
2160 UINT cp,
2161 UINT* family_cp)
2163 MLang_impl *This = impl_from_IMultiLanguage( iface );
2164 return IMultiLanguage3_GetFamilyCodePage(&This->IMultiLanguage3_iface, cp, family_cp);
2167 static HRESULT WINAPI fnIMultiLanguage_EnumCodePages(
2168 IMultiLanguage* iface,
2169 DWORD grfFlags,
2170 IEnumCodePage** ppEnumCodePage)
2172 MLang_impl *This = impl_from_IMultiLanguage( iface );
2174 TRACE("%p %08x %p\n", This, grfFlags, ppEnumCodePage);
2176 return EnumCodePage_create( This, grfFlags, 0, ppEnumCodePage );
2179 static HRESULT WINAPI fnIMultiLanguage_GetCharsetInfo(
2180 IMultiLanguage* iface,
2181 BSTR Charset,
2182 PMIMECSETINFO pCharsetInfo)
2184 MLang_impl *This = impl_from_IMultiLanguage( iface );
2185 return IMultiLanguage3_GetCharsetInfo( &This->IMultiLanguage3_iface, Charset, pCharsetInfo );
2188 static HRESULT WINAPI fnIMultiLanguage_IsConvertible(
2189 IMultiLanguage* iface,
2190 DWORD src_enc,
2191 DWORD dst_enc)
2193 MLang_impl *This = impl_from_IMultiLanguage( iface );
2194 return IMultiLanguage3_IsConvertible(&This->IMultiLanguage3_iface, src_enc, dst_enc);
2197 static HRESULT WINAPI fnIMultiLanguage_ConvertString(
2198 IMultiLanguage* iface,
2199 DWORD* mode,
2200 DWORD src_enc,
2201 DWORD dst_enc,
2202 BYTE* src,
2203 UINT* src_size,
2204 BYTE* dest,
2205 UINT* dest_size)
2207 MLang_impl *This = impl_from_IMultiLanguage( iface );
2208 return IMultiLanguage3_ConvertString(&This->IMultiLanguage3_iface, mode, src_enc,
2209 dst_enc, src, src_size, dest, dest_size);
2212 static HRESULT WINAPI fnIMultiLanguage_ConvertStringToUnicode(
2213 IMultiLanguage* iface,
2214 DWORD* mode,
2215 DWORD src_enc,
2216 CHAR* src,
2217 UINT* src_size,
2218 WCHAR* dest,
2219 UINT* dest_size)
2221 MLang_impl *This = impl_from_IMultiLanguage( iface );
2222 return IMultiLanguage3_ConvertStringToUnicode(&This->IMultiLanguage3_iface,
2223 mode, src_enc, src, src_size, dest, dest_size);
2226 static HRESULT WINAPI fnIMultiLanguage_ConvertStringFromUnicode(
2227 IMultiLanguage* iface,
2228 DWORD* mode,
2229 DWORD encoding,
2230 WCHAR* src,
2231 UINT* src_size,
2232 CHAR* dest,
2233 UINT* dest_size)
2235 MLang_impl *This = impl_from_IMultiLanguage(iface);
2236 return IMultiLanguage3_ConvertStringFromUnicode(&This->IMultiLanguage3_iface,
2237 mode, encoding, src, src_size, dest, dest_size);
2240 static HRESULT WINAPI fnIMultiLanguage_ConvertStringReset(
2241 IMultiLanguage* iface)
2243 MLang_impl *This = impl_from_IMultiLanguage( iface );
2244 return IMultiLanguage3_ConvertStringReset(&This->IMultiLanguage3_iface);
2247 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766FromLcid(
2248 IMultiLanguage* iface,
2249 LCID lcid,
2250 BSTR* pbstrRfc1766)
2252 MLang_impl *This = impl_from_IMultiLanguage(iface);
2253 return IMultiLanguage3_GetRfc1766FromLcid(&This->IMultiLanguage3_iface, lcid, pbstrRfc1766);
2256 static HRESULT WINAPI fnIMultiLanguage_GetLcidFromRfc1766(
2257 IMultiLanguage* iface,
2258 LCID* locale,
2259 BSTR rfc1766)
2261 MLang_impl *This = impl_from_IMultiLanguage(iface);
2262 return IMultiLanguage3_GetLcidFromRfc1766(&This->IMultiLanguage3_iface, locale, rfc1766);
2265 /******************************************************************************/
2267 typedef struct tagEnumRfc1766_impl
2269 IEnumRfc1766 IEnumRfc1766_iface;
2270 LONG ref;
2271 RFC1766INFO *info;
2272 DWORD total, pos;
2273 } EnumRfc1766_impl;
2275 static inline EnumRfc1766_impl *impl_from_IEnumRfc1766( IEnumRfc1766 *iface )
2277 return CONTAINING_RECORD( iface, EnumRfc1766_impl, IEnumRfc1766_iface );
2280 static HRESULT WINAPI fnIEnumRfc1766_QueryInterface(
2281 IEnumRfc1766 *iface,
2282 REFIID riid,
2283 void** ppvObject)
2285 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2287 TRACE("%p -> %s\n", This, debugstr_guid(riid) );
2289 if (IsEqualGUID(riid, &IID_IUnknown)
2290 || IsEqualGUID(riid, &IID_IEnumRfc1766))
2292 IEnumRfc1766_AddRef(iface);
2293 TRACE("Returning IID_IEnumRfc1766 %p ref = %d\n", This, This->ref);
2294 *ppvObject = &This->IEnumRfc1766_iface;
2295 return S_OK;
2298 WARN("(%p) -> (%s,%p), not found\n",This,debugstr_guid(riid),ppvObject);
2299 return E_NOINTERFACE;
2302 static ULONG WINAPI fnIEnumRfc1766_AddRef(
2303 IEnumRfc1766 *iface)
2305 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2306 return InterlockedIncrement(&This->ref);
2309 static ULONG WINAPI fnIEnumRfc1766_Release(
2310 IEnumRfc1766 *iface)
2312 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2313 ULONG ref = InterlockedDecrement(&This->ref);
2315 TRACE("%p ref = %d\n", This, ref);
2316 if (ref == 0)
2318 TRACE("Destroying %p\n", This);
2319 HeapFree(GetProcessHeap(), 0, This->info);
2320 HeapFree(GetProcessHeap(), 0, This);
2322 return ref;
2325 static HRESULT WINAPI fnIEnumRfc1766_Clone(
2326 IEnumRfc1766 *iface,
2327 IEnumRfc1766 **ppEnum)
2329 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2331 FIXME("%p %p\n", This, ppEnum);
2332 return E_NOTIMPL;
2335 static HRESULT WINAPI fnIEnumRfc1766_Next(
2336 IEnumRfc1766 *iface,
2337 ULONG celt,
2338 PRFC1766INFO rgelt,
2339 ULONG *pceltFetched)
2341 ULONG i;
2342 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2344 TRACE("%p %u %p %p\n", This, celt, rgelt, pceltFetched);
2346 if (!pceltFetched) return S_FALSE;
2347 *pceltFetched = 0;
2349 if (!rgelt) return S_FALSE;
2351 if (This->pos + celt > This->total)
2352 celt = This->total - This->pos;
2354 if (!celt) return S_FALSE;
2356 memcpy(rgelt, This->info + This->pos, celt * sizeof(RFC1766INFO));
2357 *pceltFetched = celt;
2358 This->pos += celt;
2360 for (i = 0; i < celt; i++)
2362 TRACE("#%u: %08x %s %s\n",
2363 i, rgelt[i].lcid,
2364 wine_dbgstr_w(rgelt[i].wszRfc1766),
2365 wine_dbgstr_w(rgelt[i].wszLocaleName));
2367 return S_OK;
2370 static HRESULT WINAPI fnIEnumRfc1766_Reset(
2371 IEnumRfc1766 *iface)
2373 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2375 TRACE("%p\n", This);
2377 This->pos = 0;
2378 return S_OK;
2381 static HRESULT WINAPI fnIEnumRfc1766_Skip(
2382 IEnumRfc1766 *iface,
2383 ULONG celt)
2385 EnumRfc1766_impl *This = impl_from_IEnumRfc1766( iface );
2387 TRACE("%p %u\n", This, celt);
2389 if (celt >= This->total) return S_FALSE;
2391 This->pos += celt;
2392 return S_OK;
2395 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl =
2397 fnIEnumRfc1766_QueryInterface,
2398 fnIEnumRfc1766_AddRef,
2399 fnIEnumRfc1766_Release,
2400 fnIEnumRfc1766_Clone,
2401 fnIEnumRfc1766_Next,
2402 fnIEnumRfc1766_Reset,
2403 fnIEnumRfc1766_Skip
2406 struct enum_locales_data
2408 RFC1766INFO *info;
2409 DWORD total, allocated;
2412 static BOOL CALLBACK enum_locales_proc(LPWSTR locale)
2414 WCHAR *end;
2415 struct enum_locales_data *data = TlsGetValue(MLANG_tls_index);
2416 RFC1766INFO *info;
2418 TRACE("%s\n", debugstr_w(locale));
2420 if (data->total >= data->allocated)
2422 data->allocated += 32;
2423 data->info = HeapReAlloc(GetProcessHeap(), 0, data->info, data->allocated * sizeof(RFC1766INFO));
2424 if (!data->info) return FALSE;
2427 info = &data->info[data->total];
2429 info->lcid = strtolW(locale, &end, 16);
2430 if (*end) /* invalid number */
2431 return FALSE;
2433 info->wszRfc1766[0] = 0;
2434 lcid_to_rfc1766W( info->lcid, info->wszRfc1766, MAX_RFC1766_NAME );
2436 info->wszLocaleName[0] = 0;
2437 GetLocaleInfoW(info->lcid, LOCALE_SLANGUAGE, info->wszLocaleName, MAX_LOCALE_NAME);
2438 TRACE("ISO639: %s SLANGUAGE: %s\n", wine_dbgstr_w(info->wszRfc1766), wine_dbgstr_w(info->wszLocaleName));
2440 data->total++;
2442 return TRUE;
2445 static HRESULT EnumRfc1766_create(LANGID LangId, IEnumRfc1766 **ppEnum)
2447 EnumRfc1766_impl *rfc;
2448 struct enum_locales_data data;
2450 TRACE("%04x, %p\n", LangId, ppEnum);
2452 rfc = HeapAlloc( GetProcessHeap(), 0, sizeof(EnumRfc1766_impl) );
2453 rfc->IEnumRfc1766_iface.lpVtbl = &IEnumRfc1766_vtbl;
2454 rfc->ref = 1;
2455 rfc->pos = 0;
2456 rfc->total = 0;
2458 data.total = 0;
2459 data.allocated = 160;
2460 data.info = HeapAlloc(GetProcessHeap(), 0, data.allocated * sizeof(RFC1766INFO));
2461 if (!data.info)
2463 HeapFree(GetProcessHeap(), 0, rfc);
2464 return E_OUTOFMEMORY;
2467 TlsSetValue(MLANG_tls_index, &data);
2468 EnumSystemLocalesW(enum_locales_proc, 0/*LOCALE_SUPPORTED*/);
2469 TlsSetValue(MLANG_tls_index, NULL);
2471 TRACE("enumerated %d rfc1766 structures\n", data.total);
2473 if (!data.total)
2475 HeapFree(GetProcessHeap(), 0, data.info);
2476 HeapFree(GetProcessHeap(), 0, rfc);
2477 return E_FAIL;
2480 rfc->info = data.info;
2481 rfc->total = data.total;
2483 *ppEnum = &rfc->IEnumRfc1766_iface;
2484 return S_OK;
2487 static HRESULT WINAPI fnIMultiLanguage_EnumRfc1766(
2488 IMultiLanguage *iface,
2489 IEnumRfc1766 **ppEnumRfc1766)
2491 MLang_impl *This = impl_from_IMultiLanguage( iface );
2493 TRACE("%p %p\n", This, ppEnumRfc1766);
2495 return EnumRfc1766_create(0, ppEnumRfc1766);
2498 /******************************************************************************/
2500 static HRESULT WINAPI fnIMultiLanguage_GetRfc1766Info(
2501 IMultiLanguage* iface,
2502 LCID Locale,
2503 PRFC1766INFO pRfc1766Info)
2505 LCTYPE type = LOCALE_SLANGUAGE;
2507 TRACE("(%p, 0x%04x, %p)\n", iface, Locale, pRfc1766Info);
2509 if (!pRfc1766Info)
2510 return E_INVALIDARG;
2512 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2513 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2514 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2516 if (!SUBLANGID(Locale))
2517 type = LOCALE_SENGLANGUAGE; /* suppress country */
2519 else
2521 if (!SUBLANGID(Locale)) {
2522 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2523 return E_FAIL;
2527 pRfc1766Info->lcid = Locale;
2528 pRfc1766Info->wszRfc1766[0] = 0;
2529 pRfc1766Info->wszLocaleName[0] = 0;
2531 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2532 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2533 return S_OK;
2535 /* Locale not supported */
2536 return E_INVALIDARG;
2539 static HRESULT WINAPI fnIMultiLanguage_CreateConvertCharset(
2540 IMultiLanguage* iface,
2541 UINT src_cp,
2542 UINT dst_cp,
2543 DWORD prop,
2544 IMLangConvertCharset** convert_charset)
2546 MLang_impl *This = impl_from_IMultiLanguage(iface);
2547 return IMultiLanguage3_CreateConvertCharset(&This->IMultiLanguage3_iface, src_cp, dst_cp, prop, convert_charset);
2550 static const IMultiLanguageVtbl IMultiLanguage_vtbl =
2552 fnIMultiLanguage_QueryInterface,
2553 fnIMultiLanguage_AddRef,
2554 fnIMultiLanguage_Release,
2555 fnIMultiLanguage_GetNumberOfCodePageInfo,
2556 fnIMultiLanguage_GetCodePageInfo,
2557 fnIMultiLanguage_GetFamilyCodePage,
2558 fnIMultiLanguage_EnumCodePages,
2559 fnIMultiLanguage_GetCharsetInfo,
2560 fnIMultiLanguage_IsConvertible,
2561 fnIMultiLanguage_ConvertString,
2562 fnIMultiLanguage_ConvertStringToUnicode,
2563 fnIMultiLanguage_ConvertStringFromUnicode,
2564 fnIMultiLanguage_ConvertStringReset,
2565 fnIMultiLanguage_GetRfc1766FromLcid,
2566 fnIMultiLanguage_GetLcidFromRfc1766,
2567 fnIMultiLanguage_EnumRfc1766,
2568 fnIMultiLanguage_GetRfc1766Info,
2569 fnIMultiLanguage_CreateConvertCharset,
2573 /******************************************************************************/
2575 static inline MLang_impl *impl_from_IMultiLanguage3( IMultiLanguage3 *iface )
2577 return CONTAINING_RECORD( iface, MLang_impl, IMultiLanguage3_iface );
2580 static HRESULT WINAPI fnIMultiLanguage3_QueryInterface(
2581 IMultiLanguage3* iface,
2582 REFIID riid,
2583 void** obj)
2585 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2587 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
2589 if (IsEqualGUID(riid, &IID_IUnknown) ||
2590 IsEqualGUID(riid, &IID_IMultiLanguage))
2592 *obj = &This->IMultiLanguage_iface;
2594 else if (IsEqualGUID(riid, &IID_IMLangCodePages) ||
2595 IsEqualGUID(riid, &IID_IMLangFontLink))
2597 *obj = &This->IMLangFontLink_iface;
2599 else if (IsEqualGUID(riid, &IID_IMLangFontLink2))
2601 *obj = &This->IMLangFontLink2_iface;
2603 else if (IsEqualGUID(riid, &IID_IMultiLanguage2) ||
2604 IsEqualGUID(riid, &IID_IMultiLanguage3))
2606 *obj = &This->IMultiLanguage3_iface;
2608 else if (IsEqualGUID(riid, &IID_IMLangLineBreakConsole))
2610 *obj = &This->IMLangLineBreakConsole_iface;
2612 else
2614 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), obj);
2615 *obj = NULL;
2616 return E_NOINTERFACE;
2619 IMultiLanguage3_AddRef(iface);
2620 return S_OK;
2623 static ULONG WINAPI fnIMultiLanguage3_AddRef( IMultiLanguage3* iface )
2625 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2626 return InterlockedIncrement(&This->ref);
2629 static ULONG WINAPI fnIMultiLanguage3_Release( IMultiLanguage3* iface )
2631 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2632 ULONG ref = InterlockedDecrement(&This->ref);
2634 TRACE("(%p)->(%d)\n", This, ref);
2635 if (ref == 0)
2637 HeapFree(GetProcessHeap(), 0, This);
2638 UnlockModule();
2641 return ref;
2644 static HRESULT WINAPI fnIMultiLanguage3_GetNumberOfCodePageInfo(
2645 IMultiLanguage3* iface,
2646 UINT* pcCodePage)
2648 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2650 TRACE("%p, %p\n", This, pcCodePage);
2652 if (!pcCodePage) return E_INVALIDARG;
2654 *pcCodePage = This->total_cp;
2655 return S_OK;
2658 static void fill_cp_info(const struct mlang_data *ml_data, UINT index, MIMECPINFO *mime_cp_info)
2660 CHARSETINFO csi;
2662 if (TranslateCharsetInfo((DWORD*)(DWORD_PTR)ml_data->family_codepage, &csi,
2663 TCI_SRCCODEPAGE))
2664 mime_cp_info->bGDICharset = csi.ciCharset;
2665 else
2666 mime_cp_info->bGDICharset = DEFAULT_CHARSET;
2668 mime_cp_info->dwFlags = ml_data->mime_cp_info[index].flags;
2669 mime_cp_info->uiCodePage = ml_data->mime_cp_info[index].cp;
2670 mime_cp_info->uiFamilyCodePage = ml_data->family_codepage;
2671 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].description, -1,
2672 mime_cp_info->wszDescription, sizeof(mime_cp_info->wszDescription)/sizeof(WCHAR));
2673 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].web_charset, -1,
2674 mime_cp_info->wszWebCharset, sizeof(mime_cp_info->wszWebCharset)/sizeof(WCHAR));
2675 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].header_charset, -1,
2676 mime_cp_info->wszHeaderCharset, sizeof(mime_cp_info->wszHeaderCharset)/sizeof(WCHAR));
2677 MultiByteToWideChar(CP_ACP, 0, ml_data->mime_cp_info[index].body_charset, -1,
2678 mime_cp_info->wszBodyCharset, sizeof(mime_cp_info->wszBodyCharset)/sizeof(WCHAR));
2680 MultiByteToWideChar(CP_ACP, 0, ml_data->fixed_font, -1,
2681 mime_cp_info->wszFixedWidthFont, sizeof(mime_cp_info->wszFixedWidthFont)/sizeof(WCHAR));
2682 MultiByteToWideChar(CP_ACP, 0, ml_data->proportional_font, -1,
2683 mime_cp_info->wszProportionalFont, sizeof(mime_cp_info->wszProportionalFont)/sizeof(WCHAR));
2685 TRACE("%08x %u %u %s %s %s %s %s %s %d\n",
2686 mime_cp_info->dwFlags, mime_cp_info->uiCodePage,
2687 mime_cp_info->uiFamilyCodePage,
2688 wine_dbgstr_w(mime_cp_info->wszDescription),
2689 wine_dbgstr_w(mime_cp_info->wszWebCharset),
2690 wine_dbgstr_w(mime_cp_info->wszHeaderCharset),
2691 wine_dbgstr_w(mime_cp_info->wszBodyCharset),
2692 wine_dbgstr_w(mime_cp_info->wszFixedWidthFont),
2693 wine_dbgstr_w(mime_cp_info->wszProportionalFont),
2694 mime_cp_info->bGDICharset);
2697 static HRESULT WINAPI fnIMultiLanguage3_GetCodePageInfo(
2698 IMultiLanguage3* iface,
2699 UINT uiCodePage,
2700 LANGID LangId,
2701 PMIMECPINFO pCodePageInfo)
2703 UINT i, n;
2704 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2706 TRACE("%p, %u, %04x, %p\n", This, uiCodePage, LangId, pCodePageInfo);
2708 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2710 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2712 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
2714 fill_cp_info(&mlang_data[i], n, pCodePageInfo);
2715 return S_OK;
2720 return S_FALSE;
2723 static HRESULT WINAPI fnIMultiLanguage3_GetFamilyCodePage(
2724 IMultiLanguage3* iface,
2725 UINT uiCodePage,
2726 UINT* puiFamilyCodePage)
2728 return GetFamilyCodePage(uiCodePage, puiFamilyCodePage);
2731 static HRESULT WINAPI fnIMultiLanguage3_EnumCodePages(
2732 IMultiLanguage3* iface,
2733 DWORD grfFlags,
2734 LANGID LangId,
2735 IEnumCodePage** ppEnumCodePage)
2737 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2739 TRACE("%p %08x %04x %p\n", This, grfFlags, LangId, ppEnumCodePage);
2741 return EnumCodePage_create( This, grfFlags, LangId, ppEnumCodePage );
2744 static HRESULT WINAPI fnIMultiLanguage3_GetCharsetInfo(
2745 IMultiLanguage3* iface,
2746 BSTR Charset,
2747 PMIMECSETINFO pCharsetInfo)
2749 UINT i, n;
2750 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2752 TRACE("%p %s %p\n", This, debugstr_w(Charset), pCharsetInfo);
2754 if (!pCharsetInfo) return E_FAIL;
2756 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2758 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2760 WCHAR csetW[MAX_MIMECSET_NAME];
2762 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].web_charset, -1, csetW, MAX_MIMECSET_NAME);
2763 if (!lstrcmpiW(Charset, csetW))
2765 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2766 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2767 strcpyW(pCharsetInfo->wszCharset, csetW);
2768 return S_OK;
2770 if (mlang_data[i].mime_cp_info[n].alias && !lstrcmpiW(Charset, mlang_data[i].mime_cp_info[n].alias))
2772 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2773 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2774 strcpyW(pCharsetInfo->wszCharset, mlang_data[i].mime_cp_info[n].alias);
2775 return S_OK;
2780 /* FIXME:
2781 * Since we do not support charsets like iso-2022-jp and do not have
2782 * them in our database as a primary (web_charset) encoding this loop
2783 * does an attempt to 'approximate' charset name by header_charset.
2785 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
2787 for (n = 0; n < mlang_data[i].number_of_cp; n++)
2789 WCHAR csetW[MAX_MIMECSET_NAME];
2791 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].mime_cp_info[n].header_charset, -1, csetW, MAX_MIMECSET_NAME);
2792 if (!lstrcmpiW(Charset, csetW))
2794 pCharsetInfo->uiCodePage = mlang_data[i].family_codepage;
2795 pCharsetInfo->uiInternetEncoding = mlang_data[i].mime_cp_info[n].cp;
2796 strcpyW(pCharsetInfo->wszCharset, csetW);
2797 return S_OK;
2802 return E_FAIL;
2805 static HRESULT WINAPI fnIMultiLanguage3_IsConvertible(
2806 IMultiLanguage3* iface,
2807 DWORD dwSrcEncoding,
2808 DWORD dwDstEncoding)
2810 return IsConvertINetStringAvailable(dwSrcEncoding, dwDstEncoding);
2813 static HRESULT WINAPI fnIMultiLanguage3_ConvertString(
2814 IMultiLanguage3* iface,
2815 DWORD* pdwMode,
2816 DWORD dwSrcEncoding,
2817 DWORD dwDstEncoding,
2818 BYTE* pSrcStr,
2819 UINT* pcSrcSize,
2820 BYTE* pDstStr,
2821 UINT* pcDstSize)
2823 return ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding,
2824 (LPCSTR)pSrcStr, (LPINT)pcSrcSize, (LPSTR)pDstStr, (LPINT)pcDstSize);
2827 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringToUnicode(
2828 IMultiLanguage3* iface,
2829 DWORD* pdwMode,
2830 DWORD dwEncoding,
2831 CHAR* pSrcStr,
2832 UINT* pcSrcSize,
2833 WCHAR* pDstStr,
2834 UINT* pcDstSize)
2836 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
2837 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2840 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringFromUnicode(
2841 IMultiLanguage3* iface,
2842 DWORD* pdwMode,
2843 DWORD dwEncoding,
2844 WCHAR* pSrcStr,
2845 UINT* pcSrcSize,
2846 CHAR* pDstStr,
2847 UINT* pcDstSize)
2849 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
2850 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
2853 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringReset(
2854 IMultiLanguage3* iface)
2856 FIXME("\n");
2857 return E_NOTIMPL;
2860 static HRESULT WINAPI fnIMultiLanguage3_GetRfc1766FromLcid(
2861 IMultiLanguage3* iface,
2862 LCID lcid,
2863 BSTR* pbstrRfc1766)
2865 WCHAR buf[MAX_RFC1766_NAME];
2867 TRACE("%p %04x %p\n", iface, lcid, pbstrRfc1766);
2868 if (!pbstrRfc1766)
2869 return E_INVALIDARG;
2871 if (!lcid_to_rfc1766W( lcid, buf, MAX_RFC1766_NAME ))
2873 *pbstrRfc1766 = SysAllocString( buf );
2874 return S_OK;
2876 return E_FAIL;
2879 static HRESULT WINAPI fnIMultiLanguage3_GetLcidFromRfc1766(
2880 IMultiLanguage3* iface,
2881 LCID* pLocale,
2882 BSTR bstrRfc1766)
2884 HRESULT hr;
2885 IEnumRfc1766 *rfc1766;
2887 TRACE("%p %p %s\n", iface, pLocale, debugstr_w(bstrRfc1766));
2889 if (!pLocale || !bstrRfc1766)
2890 return E_INVALIDARG;
2892 hr = IMultiLanguage3_EnumRfc1766(iface, 0, &rfc1766);
2893 if (FAILED(hr))
2894 return hr;
2896 hr = lcid_from_rfc1766(rfc1766, pLocale, bstrRfc1766);
2898 IEnumRfc1766_Release(rfc1766);
2899 return hr;
2902 static HRESULT WINAPI fnIMultiLanguage3_EnumRfc1766(
2903 IMultiLanguage3* iface,
2904 LANGID LangId,
2905 IEnumRfc1766** ppEnumRfc1766)
2907 MLang_impl *This = impl_from_IMultiLanguage3( iface );
2909 TRACE("%p %p\n", This, ppEnumRfc1766);
2911 return EnumRfc1766_create(LangId, ppEnumRfc1766);
2914 static HRESULT WINAPI fnIMultiLanguage3_GetRfc1766Info(
2915 IMultiLanguage3* iface,
2916 LCID Locale,
2917 LANGID LangId,
2918 PRFC1766INFO pRfc1766Info)
2920 static LANGID last_lang = -1;
2921 LCTYPE type = LOCALE_SLANGUAGE;
2923 TRACE("(%p, 0x%04x, 0x%04x, %p)\n", iface, Locale, LangId, pRfc1766Info);
2925 if (!pRfc1766Info)
2926 return E_INVALIDARG;
2928 if ((PRIMARYLANGID(Locale) == LANG_ENGLISH) ||
2929 (PRIMARYLANGID(Locale) == LANG_CHINESE) ||
2930 (PRIMARYLANGID(Locale) == LANG_ARABIC)) {
2932 if (!SUBLANGID(Locale))
2933 type = LOCALE_SENGLANGUAGE; /* suppress country */
2935 else
2937 if (!SUBLANGID(Locale)) {
2938 TRACE("SUBLANGID missing in 0x%04x\n", Locale);
2939 return E_FAIL;
2943 pRfc1766Info->lcid = Locale;
2944 pRfc1766Info->wszRfc1766[0] = 0;
2945 pRfc1766Info->wszLocaleName[0] = 0;
2947 if ((PRIMARYLANGID(LangId) != LANG_ENGLISH) &&
2948 (last_lang != LangId)) {
2949 FIXME("Only English names supported (requested: 0x%04x)\n", LangId);
2950 last_lang = LangId;
2953 if ((!lcid_to_rfc1766W(Locale, pRfc1766Info->wszRfc1766, MAX_RFC1766_NAME)) &&
2954 (GetLocaleInfoW(Locale, type, pRfc1766Info->wszLocaleName, MAX_LOCALE_NAME) > 0))
2955 return S_OK;
2957 /* Locale not supported */
2958 return E_INVALIDARG;
2961 static HRESULT WINAPI fnIMultiLanguage3_CreateConvertCharset(
2962 IMultiLanguage3* iface,
2963 UINT src_cp,
2964 UINT dst_cp,
2965 DWORD prop,
2966 IMLangConvertCharset** convert_charset)
2968 HRESULT hr;
2970 TRACE("(%u %u 0x%08x %p)\n", src_cp, dst_cp, prop, convert_charset);
2972 hr = MLangConvertCharset_create(NULL, (void**)convert_charset);
2973 if (FAILED(hr)) return hr;
2975 return IMLangConvertCharset_Initialize(*convert_charset, src_cp, dst_cp, prop);
2978 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringInIStream(
2979 IMultiLanguage3* iface,
2980 DWORD* pdwMode,
2981 DWORD dwFlag,
2982 WCHAR* lpFallBack,
2983 DWORD dwSrcEncoding,
2984 DWORD dwDstEncoding,
2985 IStream* pstmIn,
2986 IStream* pstmOut)
2988 char *src, *dst = NULL;
2989 INT srclen, dstlen;
2990 STATSTG stat;
2991 HRESULT hr;
2993 TRACE("%p %0x8 %s %u %u %p %p\n",
2994 pdwMode, dwFlag, debugstr_w(lpFallBack), dwSrcEncoding, dwDstEncoding, pstmIn, pstmOut);
2996 FIXME("dwFlag and lpFallBack not handled\n");
2998 hr = IStream_Stat(pstmIn, &stat, STATFLAG_NONAME);
2999 if (FAILED(hr)) return hr;
3001 if (stat.cbSize.QuadPart > MAXLONG) return E_INVALIDARG;
3002 if (!(src = HeapAlloc(GetProcessHeap(), 0, stat.cbSize.QuadPart))) return E_OUTOFMEMORY;
3004 hr = IStream_Read(pstmIn, src, stat.cbSize.QuadPart, (ULONG *)&srclen);
3005 if (FAILED(hr)) goto exit;
3007 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, NULL, &dstlen);
3008 if (FAILED(hr)) goto exit;
3010 if (!(dst = HeapAlloc(GetProcessHeap(), 0, dstlen)))
3012 hr = E_OUTOFMEMORY;
3013 goto exit;
3015 hr = ConvertINetString(pdwMode, dwSrcEncoding, dwDstEncoding, src, &srclen, dst, &dstlen);
3016 if (FAILED(hr)) goto exit;
3018 hr = IStream_Write(pstmOut, dst, dstlen, NULL);
3020 exit:
3021 HeapFree(GetProcessHeap(), 0, src);
3022 HeapFree(GetProcessHeap(), 0, dst);
3023 return hr;
3026 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringToUnicodeEx(
3027 IMultiLanguage3* iface,
3028 DWORD* pdwMode,
3029 DWORD dwEncoding,
3030 CHAR* pSrcStr,
3031 UINT* pcSrcSize,
3032 WCHAR* pDstStr,
3033 UINT* pcDstSize,
3034 DWORD dwFlag,
3035 WCHAR* lpFallBack)
3037 if (dwFlag || lpFallBack)
3038 FIXME("Ignoring dwFlag (0x%x/%d) and lpFallBack (%p)\n",
3039 dwFlag, dwFlag, lpFallBack);
3041 return ConvertINetMultiByteToUnicode(pdwMode, dwEncoding,
3042 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
3045 /*****************************************************************************
3046 * MultiLanguage2::ConvertStringToUnicodeEx
3048 * Translates the multibyte string from the specified code page to Unicode.
3050 * PARAMS
3051 * see ConvertStringToUnicode
3052 * dwFlag
3053 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
3054 * instead unconvertible characters.
3056 * RETURNS
3057 * S_OK Success.
3058 * S_FALSE The conversion is not supported.
3059 * E_FAIL Some error has occurred.
3061 * TODO: handle dwFlag and lpFallBack
3063 static HRESULT WINAPI fnIMultiLanguage3_ConvertStringFromUnicodeEx(
3064 IMultiLanguage3* This,
3065 DWORD* pdwMode,
3066 DWORD dwEncoding,
3067 WCHAR* pSrcStr,
3068 UINT* pcSrcSize,
3069 CHAR* pDstStr,
3070 UINT* pcDstSize,
3071 DWORD dwFlag,
3072 WCHAR* lpFallBack)
3074 FIXME("\n");
3075 return ConvertINetUnicodeToMultiByte(pdwMode, dwEncoding,
3076 pSrcStr, (LPINT)pcSrcSize, pDstStr, (LPINT)pcDstSize);
3079 static HRESULT WINAPI fnIMultiLanguage3_DetectCodepageInIStream(
3080 IMultiLanguage3* iface,
3081 DWORD dwFlag,
3082 DWORD dwPrefWinCodePage,
3083 IStream* pstmIn,
3084 DetectEncodingInfo* lpEncoding,
3085 INT* pnScores)
3087 FIXME("\n");
3088 return E_NOTIMPL;
3091 static HRESULT WINAPI fnIMultiLanguage3_DetectInputCodepage(
3092 IMultiLanguage3* iface,
3093 DWORD dwFlag,
3094 DWORD dwPrefWinCodePage,
3095 CHAR* pSrcStr,
3096 INT* pcSrcSize,
3097 DetectEncodingInfo* lpEncoding,
3098 INT* pnScores)
3100 FIXME("\n");
3101 return E_NOTIMPL;
3104 static HRESULT WINAPI fnIMultiLanguage3_ValidateCodePage(
3105 IMultiLanguage3* iface,
3106 UINT uiCodePage,
3107 HWND hwnd)
3109 return IMultiLanguage3_ValidateCodePageEx(iface,uiCodePage,hwnd,0);
3112 static HRESULT WINAPI fnIMultiLanguage3_GetCodePageDescription(
3113 IMultiLanguage3* iface,
3114 UINT uiCodePage,
3115 LCID lcid,
3116 LPWSTR lpWideCharStr,
3117 int cchWideChar)
3119 /* Find first instance */
3120 unsigned int i,n;
3122 TRACE ("%u, %04x, %p, %d\n", uiCodePage, lcid, lpWideCharStr, cchWideChar);
3123 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3125 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3127 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3129 MultiByteToWideChar(CP_ACP, 0,
3130 mlang_data[i].mime_cp_info[n].description,
3131 -1, lpWideCharStr, cchWideChar);
3132 return S_OK;
3137 return S_FALSE;
3140 static HRESULT WINAPI fnIMultiLanguage3_IsCodePageInstallable(
3141 IMultiLanguage3* iface,
3142 UINT uiCodePage)
3144 TRACE("%u\n", uiCodePage);
3146 /* FIXME: the installable set is usually larger than the set of valid codepages */
3147 return IMultiLanguage3_ValidateCodePageEx(iface, uiCodePage, NULL, CPIOD_PEEK);
3150 static HRESULT WINAPI fnIMultiLanguage3_SetMimeDBSource(
3151 IMultiLanguage3* iface,
3152 MIMECONTF dwSource)
3154 FIXME("0x%08x\n", dwSource);
3155 return S_OK;
3158 static HRESULT WINAPI fnIMultiLanguage3_GetNumberOfScripts(
3159 IMultiLanguage3* iface,
3160 UINT* pnScripts)
3162 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3164 TRACE("%p %p\n", This, pnScripts);
3166 if (!pnScripts) return S_FALSE;
3168 *pnScripts = This->total_scripts;
3169 return S_OK;
3172 static HRESULT WINAPI fnIMultiLanguage3_EnumScripts(
3173 IMultiLanguage3* iface,
3174 DWORD dwFlags,
3175 LANGID LangId,
3176 IEnumScript** ppEnumScript)
3178 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3180 TRACE("%p %08x %04x %p\n", This, dwFlags, LangId, ppEnumScript);
3182 return EnumScript_create( This, dwFlags, LangId, ppEnumScript );
3185 static HRESULT WINAPI fnIMultiLanguage3_ValidateCodePageEx(
3186 IMultiLanguage3* iface,
3187 UINT uiCodePage,
3188 HWND hwnd,
3189 DWORD dwfIODControl)
3191 unsigned int i;
3192 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3194 TRACE("%p %u %p %08x\n", This, uiCodePage, hwnd, dwfIODControl);
3196 /* quick check for kernel32 supported code pages */
3197 if (IsValidCodePage(uiCodePage))
3198 return S_OK;
3200 /* check for mlang supported code pages */
3201 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3203 UINT n;
3204 for (n = 0; n < mlang_data[i].number_of_cp; n++)
3206 if (mlang_data[i].mime_cp_info[n].cp == uiCodePage)
3207 return S_OK;
3211 if (dwfIODControl != CPIOD_PEEK)
3212 FIXME("Request to install codepage language pack not handled\n");
3214 return S_FALSE;
3217 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePage(
3218 IMultiLanguage3 *iface,
3219 DWORD dwFlags,
3220 LPCWSTR lpWideCharStr,
3221 UINT cchWideChar,
3222 UINT *puiPreferredCodePages,
3223 UINT nPreferredCodePages,
3224 UINT *puiDetectedCodePages,
3225 UINT *pnDetectedCodePages,
3226 WCHAR *lpSpecialChar)
3228 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3230 FIXME("(%p)->(%08x %s %p %u %p %p(%u) %s)\n", This, dwFlags, debugstr_w(lpWideCharStr),
3231 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3232 pnDetectedCodePages, pnDetectedCodePages ? *pnDetectedCodePages : 0,
3233 debugstr_w(lpSpecialChar));
3235 if (!puiDetectedCodePages || !pnDetectedCodePages || !*pnDetectedCodePages)
3236 return E_INVALIDARG;
3238 puiDetectedCodePages[0] = CP_UTF8;
3239 *pnDetectedCodePages = 1;
3240 return S_OK;
3243 static HRESULT WINAPI fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3244 IMultiLanguage3 *iface,
3245 DWORD dwFlags,
3246 IStream *pStrIn,
3247 UINT *puiPreferredCodePages,
3248 UINT nPreferredCodePages,
3249 UINT *puiDetectedCodePages,
3250 UINT *pnDetectedCodePages,
3251 WCHAR *lpSpecialChar)
3253 MLang_impl *This = impl_from_IMultiLanguage3( iface );
3255 FIXME("(%p)->(%08x %p %p %u %p %p(%u) %s)\n", This, dwFlags, pStrIn,
3256 puiPreferredCodePages, nPreferredCodePages, puiDetectedCodePages,
3257 pnDetectedCodePages, pnDetectedCodePages ? *pnDetectedCodePages : 0,
3258 debugstr_w(lpSpecialChar));
3260 if (!puiDetectedCodePages || !pnDetectedCodePages || !*pnDetectedCodePages)
3261 return E_INVALIDARG;
3263 puiDetectedCodePages[0] = CP_UTF8;
3264 *pnDetectedCodePages = 1;
3265 return S_OK;
3268 static const IMultiLanguage3Vtbl IMultiLanguage3_vtbl =
3270 fnIMultiLanguage3_QueryInterface,
3271 fnIMultiLanguage3_AddRef,
3272 fnIMultiLanguage3_Release,
3273 fnIMultiLanguage3_GetNumberOfCodePageInfo,
3274 fnIMultiLanguage3_GetCodePageInfo,
3275 fnIMultiLanguage3_GetFamilyCodePage,
3276 fnIMultiLanguage3_EnumCodePages,
3277 fnIMultiLanguage3_GetCharsetInfo,
3278 fnIMultiLanguage3_IsConvertible,
3279 fnIMultiLanguage3_ConvertString,
3280 fnIMultiLanguage3_ConvertStringToUnicode,
3281 fnIMultiLanguage3_ConvertStringFromUnicode,
3282 fnIMultiLanguage3_ConvertStringReset,
3283 fnIMultiLanguage3_GetRfc1766FromLcid,
3284 fnIMultiLanguage3_GetLcidFromRfc1766,
3285 fnIMultiLanguage3_EnumRfc1766,
3286 fnIMultiLanguage3_GetRfc1766Info,
3287 fnIMultiLanguage3_CreateConvertCharset,
3288 fnIMultiLanguage3_ConvertStringInIStream,
3289 fnIMultiLanguage3_ConvertStringToUnicodeEx,
3290 fnIMultiLanguage3_ConvertStringFromUnicodeEx,
3291 fnIMultiLanguage3_DetectCodepageInIStream,
3292 fnIMultiLanguage3_DetectInputCodepage,
3293 fnIMultiLanguage3_ValidateCodePage,
3294 fnIMultiLanguage3_GetCodePageDescription,
3295 fnIMultiLanguage3_IsCodePageInstallable,
3296 fnIMultiLanguage3_SetMimeDBSource,
3297 fnIMultiLanguage3_GetNumberOfScripts,
3298 fnIMultiLanguage3_EnumScripts,
3299 fnIMultiLanguage3_ValidateCodePageEx,
3300 fnIMultiLanguage3_DetectOutboundCodePage,
3301 fnIMultiLanguage3_DetectOutboundCodePageInIStream
3304 /******************************************************************************/
3306 static inline MLang_impl *impl_from_IMLangFontLink2( IMLangFontLink2 *iface )
3308 return CONTAINING_RECORD( iface, MLang_impl, IMLangFontLink2_iface );
3311 static HRESULT WINAPI fnIMLangFontLink2_QueryInterface(
3312 IMLangFontLink2 * iface,
3313 REFIID riid,
3314 void** ppvObject)
3316 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3317 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3320 static ULONG WINAPI fnIMLangFontLink2_AddRef( IMLangFontLink2* iface )
3322 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3323 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3326 static ULONG WINAPI fnIMLangFontLink2_Release( IMLangFontLink2* iface )
3328 MLang_impl *This = impl_from_IMLangFontLink2( iface );
3329 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3332 static HRESULT WINAPI fnIMLangFontLink2_GetCharCodePages( IMLangFontLink2* iface,
3333 WCHAR ch_src, DWORD *ret_codepages)
3335 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3336 unsigned int i;
3338 TRACE("(%p)->(%s %p)\n", This, debugstr_wn(&ch_src, 1), ret_codepages);
3340 *ret_codepages = 0;
3342 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3344 BOOL used_dc;
3345 CHAR buf;
3347 WideCharToMultiByte(mlang_data[i].family_codepage, WC_NO_BEST_FIT_CHARS,
3348 &ch_src, 1, &buf, 1, NULL, &used_dc);
3350 /* If default char is not used, current codepage include the given symbol */
3351 if (!used_dc)
3353 DWORD codepages;
3355 IMLangFontLink2_CodePageToCodePages(iface,
3356 mlang_data[i].family_codepage, &codepages);
3357 *ret_codepages |= codepages;
3360 return S_OK;
3363 static HRESULT WINAPI fnIMLangFontLink2_GetStrCodePages( IMLangFontLink2* iface,
3364 const WCHAR *src, LONG src_len, DWORD priority_cp,
3365 DWORD *codepages, LONG *ret_len)
3367 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3368 LONG i;
3369 DWORD cps = 0;
3371 TRACE("(%p)->(%s:%d %x %p %p)\n", This, debugstr_wn(src, src_len), src_len, priority_cp,
3372 codepages, ret_len);
3374 if (codepages) *codepages = 0;
3375 if (ret_len) *ret_len = 0;
3377 if (!src || !src_len || src_len < 0)
3378 return E_INVALIDARG;
3380 for (i = 0; i < src_len; i++)
3382 DWORD cp;
3383 HRESULT ret;
3385 ret = IMLangFontLink2_GetCharCodePages(iface, src[i], &cp);
3386 if (ret != S_OK) return E_FAIL;
3388 if (!cps) cps = cp;
3389 else cps &= cp;
3391 /* FIXME: not tested */
3392 if (priority_cp & cps) break;
3395 if (codepages) *codepages = cps;
3396 if (ret_len) *ret_len = min( i + 1, src_len );
3397 return S_OK;
3400 static HRESULT WINAPI fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2* iface,
3401 UINT codepage,
3402 DWORD *codepages)
3404 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3405 CHARSETINFO cs;
3406 BOOL rc;
3408 TRACE("(%p)->(%u %p)\n", This, codepage, codepages);
3410 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)codepage, &cs, TCI_SRCCODEPAGE);
3411 if (rc)
3413 *codepages = cs.fs.fsCsb[0];
3414 TRACE("resulting codepages 0x%x\n", *codepages);
3415 return S_OK;
3418 TRACE("codepage not found\n");
3419 *codepages = 0;
3420 return E_FAIL;
3423 static HRESULT WINAPI fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2* iface,
3424 DWORD codepages, UINT def_codepage, UINT *codepage)
3426 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3427 DWORD mask = 0;
3428 CHARSETINFO cs;
3429 BOOL rc;
3430 UINT i;
3432 TRACE("(%p)->(0x%x %u %p)\n", This, codepages, def_codepage, codepage);
3434 *codepage = 0;
3436 rc = TranslateCharsetInfo((DWORD*)(DWORD_PTR)def_codepage, &cs, TCI_SRCCODEPAGE);
3437 if (rc && (codepages & cs.fs.fsCsb[0]))
3439 TRACE("Found Default Codepage\n");
3440 *codepage = def_codepage;
3441 return S_OK;
3444 for (i = 0; i < 32; i++)
3446 mask = 1 << i;
3447 if (codepages & mask)
3449 DWORD Csb[2];
3450 Csb[0] = mask;
3451 Csb[1] = 0x0;
3452 rc = TranslateCharsetInfo(Csb, &cs, TCI_SRCFONTSIG);
3453 if (!rc)
3454 continue;
3456 TRACE("Falling back to least significant found CodePage %u\n",
3457 cs.ciACP);
3458 *codepage = cs.ciACP;
3459 return S_OK;
3463 TRACE("no codepage found\n");
3464 return E_FAIL;
3467 static HRESULT WINAPI fnIMLangFontLink2_GetFontCodePages(IMLangFontLink2 *iface,
3468 HDC hdc, HFONT hfont, DWORD *codepages)
3470 MLang_impl *This = impl_from_IMLangFontLink2(iface);
3471 FONTSIGNATURE fontsig;
3472 HFONT old_font;
3474 TRACE("(%p)->(%p %p %p)\n", This, hdc, hfont, codepages);
3476 old_font = SelectObject(hdc, hfont);
3477 GetTextCharsetInfo(hdc, &fontsig, 0);
3478 SelectObject(hdc, old_font);
3480 *codepages = fontsig.fsCsb[0];
3481 TRACE("ret 0x%x\n", fontsig.fsCsb[0]);
3483 return S_OK;
3486 static HRESULT WINAPI fnIMLangFontLink2_ReleaseFont(IMLangFontLink2* This,
3487 HFONT hFont)
3489 TRACE("(%p)->%p\n",This, hFont);
3491 return release_font(hFont);
3494 static HRESULT WINAPI fnIMLangFontLink2_ResetFontMapping(IMLangFontLink2* This)
3496 TRACE("(%p)\n",This);
3498 return clear_font_cache();
3501 static HRESULT WINAPI fnIMLangFontLink2_MapFont(IMLangFontLink2* This,
3502 HDC hDC, DWORD dwCodePages, WCHAR chSrc, HFONT *pFont)
3504 HFONT old_font;
3506 TRACE("(%p)->%p %08x %04x %p\n",This, hDC, dwCodePages, chSrc, pFont);
3508 if (!hDC) return E_FAIL;
3510 if (dwCodePages != 0)
3512 old_font = GetCurrentObject(hDC, OBJ_FONT);
3513 return map_font(hDC, dwCodePages, old_font, pFont);
3515 else
3517 if (pFont == NULL) return E_INVALIDARG;
3518 FIXME("the situation where dwCodepages is set to zero is not implemented\n");
3519 return E_FAIL;
3523 static HRESULT WINAPI fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2* This,
3524 HDC hDC, UINT *puiRanges, UNICODERANGE *pUranges)
3526 DWORD size;
3527 GLYPHSET *gs;
3529 TRACE("(%p)->%p %p %p\n", This, hDC, puiRanges, pUranges);
3531 if (!puiRanges) return E_INVALIDARG;
3532 if (!(size = GetFontUnicodeRanges(hDC, NULL))) return E_FAIL;
3533 if (!(gs = HeapAlloc(GetProcessHeap(), 0, size))) return E_OUTOFMEMORY;
3535 GetFontUnicodeRanges(hDC, gs);
3536 *puiRanges = gs->cRanges;
3537 if (pUranges)
3539 UINT i;
3540 for (i = 0; i < gs->cRanges; i++)
3542 if (i >= *puiRanges) break;
3543 pUranges[i].wcFrom = gs->ranges[i].wcLow;
3544 pUranges[i].wcTo = gs->ranges[i].wcLow + gs->ranges[i].cGlyphs;
3546 *puiRanges = i;
3548 HeapFree(GetProcessHeap(), 0, gs);
3549 return S_OK;
3552 static HRESULT WINAPI fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2* This,
3553 SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts,
3554 SCRIPTFONTINFO *pScriptFont)
3556 UINT i, j;
3558 TRACE("(%p)->%u %x %p %p\n", This, sid, dwFlags, puiFonts, pScriptFont);
3560 if (!dwFlags) dwFlags = SCRIPTCONTF_PROPORTIONAL_FONT;
3562 for (i = 0, j = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3564 if (sid == mlang_data[i].sid)
3566 if (pScriptFont)
3568 if (j >= *puiFonts) break;
3570 pScriptFont[j].scripts = 1 << mlang_data[i].sid;
3571 if (dwFlags == SCRIPTCONTF_FIXED_FONT)
3573 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].fixed_font, -1,
3574 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3576 else if (dwFlags == SCRIPTCONTF_PROPORTIONAL_FONT)
3578 MultiByteToWideChar(CP_ACP, 0, mlang_data[i].proportional_font, -1,
3579 pScriptFont[j].wszFont, MAX_MIMEFACE_NAME);
3582 j++;
3585 *puiFonts = j;
3586 return S_OK;
3589 static HRESULT WINAPI fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2* This,
3590 UINT uiCodePage, SCRIPT_ID *pSid)
3592 UINT i;
3594 TRACE("(%p)->%i %p\n", This, uiCodePage, pSid);
3596 if (uiCodePage == CP_UNICODE) return E_FAIL;
3598 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3600 if (uiCodePage == mlang_data[i].family_codepage)
3602 if (pSid) *pSid = mlang_data[i].sid;
3603 return S_OK;
3606 return E_FAIL;
3609 static const IMLangFontLink2Vtbl IMLangFontLink2_vtbl =
3611 fnIMLangFontLink2_QueryInterface,
3612 fnIMLangFontLink2_AddRef,
3613 fnIMLangFontLink2_Release,
3614 fnIMLangFontLink2_GetCharCodePages,
3615 fnIMLangFontLink2_GetStrCodePages,
3616 fnIMLangFontLink2_CodePageToCodePages,
3617 fnIMLangFontLink2_CodePagesToCodePage,
3618 fnIMLangFontLink2_GetFontCodePages,
3619 fnIMLangFontLink2_ReleaseFont,
3620 fnIMLangFontLink2_ResetFontMapping,
3621 fnIMLangFontLink2_MapFont,
3622 fnIMLangFontLink2_GetFontUnicodeRanges,
3623 fnIMLangFontLink2_GetScriptFontInfo,
3624 fnIMLangFontLink2_CodePageToScriptID
3627 /******************************************************************************/
3629 static inline MLang_impl *impl_from_IMLangLineBreakConsole( IMLangLineBreakConsole *iface )
3631 return CONTAINING_RECORD( iface, MLang_impl, IMLangLineBreakConsole_iface );
3634 static HRESULT WINAPI fnIMLangLineBreakConsole_QueryInterface(
3635 IMLangLineBreakConsole* iface,
3636 REFIID riid,
3637 void** ppvObject)
3639 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3640 return IMultiLanguage3_QueryInterface( &This->IMultiLanguage3_iface, riid, ppvObject );
3643 static ULONG WINAPI fnIMLangLineBreakConsole_AddRef(
3644 IMLangLineBreakConsole* iface )
3646 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3647 return IMultiLanguage3_AddRef( &This->IMultiLanguage3_iface );
3650 static ULONG WINAPI fnIMLangLineBreakConsole_Release(
3651 IMLangLineBreakConsole* iface )
3653 MLang_impl *This = impl_from_IMLangLineBreakConsole( iface );
3654 return IMultiLanguage3_Release( &This->IMultiLanguage3_iface );
3657 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineML(
3658 IMLangLineBreakConsole* iface,
3659 IMLangString* pSrcMLStr,
3660 LONG lSrcPos,
3661 LONG lSrcLen,
3662 LONG cMinColumns,
3663 LONG cMaxColumns,
3664 LONG* plLineLen,
3665 LONG* plSkipLen)
3667 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface, pSrcMLStr, lSrcPos, lSrcLen, cMinColumns, cMaxColumns, plLineLen, plSkipLen);
3668 return E_NOTIMPL;
3671 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineW(
3672 IMLangLineBreakConsole* iface,
3673 LCID locale,
3674 const WCHAR* pszSrc,
3675 LONG cchSrc,
3676 LONG cMaxColumns,
3677 LONG* pcchLine,
3678 LONG* pcchSkip )
3680 FIXME("(%p)->%i %s %i %i %p %p\n", iface, locale, debugstr_wn(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3682 *pcchLine = cchSrc;
3683 *pcchSkip = 0;
3684 return S_OK;
3687 static HRESULT WINAPI fnIMLangLineBreakConsole_BreakLineA(
3688 IMLangLineBreakConsole* iface,
3689 LCID locale,
3690 UINT uCodePage,
3691 const CHAR* pszSrc,
3692 LONG cchSrc,
3693 LONG cMaxColumns,
3694 LONG* pcchLine,
3695 LONG* pcchSkip)
3697 LONG i, line = cchSrc, skip = 0;
3699 FIXME("(%p)->%i %i %s %i %i %p %p\n", iface, locale, uCodePage, debugstr_an(pszSrc,cchSrc), cchSrc, cMaxColumns, pcchLine, pcchSkip);
3701 if (uCodePage == CP_USASCII && cchSrc > cMaxColumns)
3703 for (line = cMaxColumns, i = cMaxColumns - 1; i >= 0; i--)
3705 if (pszSrc[i] == ' ')
3707 while (i >= 0 && pszSrc[i] == ' ')
3709 i--;
3710 line--;
3711 skip++;
3713 break;
3717 *pcchLine = line;
3718 *pcchSkip = skip;
3719 return S_OK;
3722 static const IMLangLineBreakConsoleVtbl IMLangLineBreakConsole_vtbl =
3724 fnIMLangLineBreakConsole_QueryInterface,
3725 fnIMLangLineBreakConsole_AddRef,
3726 fnIMLangLineBreakConsole_Release,
3727 fnIMLangLineBreakConsole_BreakLineML,
3728 fnIMLangLineBreakConsole_BreakLineW,
3729 fnIMLangLineBreakConsole_BreakLineA
3732 struct convert_charset {
3733 IMLangConvertCharset IMLangConvertCharset_iface;
3734 LONG ref;
3736 UINT src_cp;
3737 UINT dst_cp;
3740 static inline struct convert_charset *impl_from_IMLangConvertCharset(IMLangConvertCharset *iface)
3742 return CONTAINING_RECORD(iface, struct convert_charset, IMLangConvertCharset_iface);
3745 static HRESULT WINAPI MLangConvertCharset_QueryInterface(IMLangConvertCharset *iface, REFIID riid, void **obj)
3747 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3749 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
3751 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMLangConvertCharset))
3753 *obj = &This->IMLangConvertCharset_iface;
3754 IMLangConvertCharset_AddRef(iface);
3755 return S_OK;
3758 *obj = NULL;
3759 return E_NOINTERFACE;
3762 static ULONG WINAPI MLangConvertCharset_AddRef(IMLangConvertCharset *iface)
3764 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3765 ULONG ref = InterlockedIncrement(&This->ref);
3766 TRACE("(%p)->(%u)\n", This, ref);
3767 return ref;
3770 static ULONG WINAPI MLangConvertCharset_Release(IMLangConvertCharset *iface)
3772 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3773 ULONG ref = InterlockedDecrement(&This->ref);
3775 TRACE("(%p)->(%u)\n", This, ref);
3776 if (!ref)
3778 HeapFree(GetProcessHeap(), 0, This);
3779 UnlockModule();
3782 return ref;
3785 static HRESULT WINAPI MLangConvertCharset_Initialize(IMLangConvertCharset *iface,
3786 UINT src_cp, UINT dst_cp, DWORD prop)
3788 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3790 TRACE("(%p)->(%u %u 0x%08x)\n", This, src_cp, dst_cp, prop);
3792 prop &= ~MLCONVCHARF_USEDEFCHAR;
3793 if (prop)
3794 FIXME("property 0x%08x not supported\n", prop);
3796 This->src_cp = src_cp;
3797 This->dst_cp = dst_cp;
3799 return S_OK;
3802 static HRESULT WINAPI MLangConvertCharset_GetSourceCodePage(IMLangConvertCharset *iface, UINT *src_cp)
3804 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3806 TRACE("(%p)->(%p)\n", This, src_cp);
3808 if (!src_cp) return E_INVALIDARG;
3809 *src_cp = This->src_cp;
3810 return S_OK;
3813 static HRESULT WINAPI MLangConvertCharset_GetDestinationCodePage(IMLangConvertCharset *iface, UINT *dst_cp)
3815 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3817 TRACE("(%p)->(%p)\n", This, dst_cp);
3819 if (!dst_cp) return E_INVALIDARG;
3820 *dst_cp = This->dst_cp;
3821 return S_OK;
3824 static HRESULT WINAPI MLangConvertCharset_GetProperty(IMLangConvertCharset *iface, DWORD *prop)
3826 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3827 FIXME("(%p)->(%p): stub\n", This, prop);
3828 return E_NOTIMPL;
3831 static HRESULT WINAPI MLangConvertCharset_DoConversion(IMLangConvertCharset *iface, BYTE *src,
3832 UINT *src_size, BYTE *dest, UINT *dest_size)
3834 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3835 FIXME("(%p)->(%p %p %p %p): stub\n", This, src, src_size, dest, dest_size);
3836 return E_NOTIMPL;
3839 static HRESULT WINAPI MLangConvertCharset_DoConversionToUnicode(IMLangConvertCharset *iface, CHAR *src,
3840 UINT *src_size, WCHAR *dest, UINT *dest_size)
3842 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3843 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3844 return ConvertINetMultiByteToUnicode(NULL, This->src_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3847 static HRESULT WINAPI MLangConvertCharset_DoConversionFromUnicode(IMLangConvertCharset *iface,
3848 WCHAR *src, UINT *src_size, CHAR *dest, UINT *dest_size)
3850 struct convert_charset *This = impl_from_IMLangConvertCharset(iface);
3851 TRACE("(%p)->(%p %p %p %p)\n", This, src, src_size, dest, dest_size);
3852 return ConvertINetUnicodeToMultiByte(NULL, This->dst_cp, src, (INT*)src_size, dest, (INT*)dest_size);
3855 static const IMLangConvertCharsetVtbl MLangConvertCharsetVtbl =
3857 MLangConvertCharset_QueryInterface,
3858 MLangConvertCharset_AddRef,
3859 MLangConvertCharset_Release,
3860 MLangConvertCharset_Initialize,
3861 MLangConvertCharset_GetSourceCodePage,
3862 MLangConvertCharset_GetDestinationCodePage,
3863 MLangConvertCharset_GetProperty,
3864 MLangConvertCharset_DoConversion,
3865 MLangConvertCharset_DoConversionToUnicode,
3866 MLangConvertCharset_DoConversionFromUnicode
3869 static HRESULT MultiLanguage_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3871 MLang_impl *mlang;
3872 UINT i;
3874 TRACE("Creating MultiLanguage object\n");
3876 if( pUnkOuter )
3877 return CLASS_E_NOAGGREGATION;
3879 mlang = HeapAlloc( GetProcessHeap(), 0, sizeof (MLang_impl) );
3880 mlang->IMLangFontLink_iface.lpVtbl = &IMLangFontLink_vtbl;
3881 mlang->IMultiLanguage_iface.lpVtbl = &IMultiLanguage_vtbl;
3882 mlang->IMultiLanguage3_iface.lpVtbl = &IMultiLanguage3_vtbl;
3883 mlang->IMLangFontLink2_iface.lpVtbl = &IMLangFontLink2_vtbl;
3884 mlang->IMLangLineBreakConsole_iface.lpVtbl = &IMLangLineBreakConsole_vtbl;
3886 mlang->total_cp = 0;
3887 for (i = 0; i < sizeof(mlang_data)/sizeof(mlang_data[0]); i++)
3888 mlang->total_cp += mlang_data[i].number_of_cp;
3890 /* do not enumerate unicode flavours */
3891 mlang->total_scripts = sizeof(mlang_data)/sizeof(mlang_data[0]) - 1;
3893 mlang->ref = 1;
3894 *ppObj = &mlang->IMultiLanguage_iface;
3895 TRACE("returning %p\n", mlang);
3897 LockModule();
3899 return S_OK;
3902 static HRESULT MLangConvertCharset_create(IUnknown *outer, void **obj)
3904 struct convert_charset *convert;
3906 if (outer)
3907 return CLASS_E_NOAGGREGATION;
3909 *obj = NULL;
3911 convert = HeapAlloc(GetProcessHeap(), 0, sizeof(struct convert_charset));
3912 if (!convert) return E_OUTOFMEMORY;
3914 convert->IMLangConvertCharset_iface.lpVtbl = &MLangConvertCharsetVtbl;
3915 convert->ref = 1;
3917 *obj = &convert->IMLangConvertCharset_iface;
3919 LockModule();
3921 return S_OK;
3924 /******************************************************************************/
3926 HRESULT WINAPI DllCanUnloadNow(void)
3928 return dll_count == 0 ? S_OK : S_FALSE;
3932 /***********************************************************************
3933 * DllRegisterServer (MLANG.@)
3935 HRESULT WINAPI DllRegisterServer(void)
3937 return __wine_register_resources( instance );
3940 /***********************************************************************
3941 * DllUnregisterServer (MLANG.@)
3943 HRESULT WINAPI DllUnregisterServer(void)
3945 return __wine_unregister_resources( instance );
3948 HRESULT WINAPI GetGlobalFontLinkObject(void **unknown)
3950 if (!unknown) return E_INVALIDARG;
3952 FIXME("%p: stub\n", unknown);
3954 return S_FALSE;