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
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43 #include "wine/list.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mlang
);
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 */
57 * Under what circumstances HKEY_CLASSES_ROOT\MIME\Database\Codepage and
58 * HKEY_CLASSES_ROOT\MIME\Database\Charset are used?
63 const char *description
;
66 const char *web_charset
;
67 const char *header_charset
;
68 const char *body_charset
;
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
[] =
78 864, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID_NLS
|
79 MIMECONTF_MIME_LATEST
,
80 "ibm864", "ibm864", "ibm864" },
82 1006, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID_NLS
|
83 MIMECONTF_MIME_LATEST
,
84 "ibm1006", "ibm1006", "ibm1006" },
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" },
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
[] =
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" },
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" },
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
[] =
199 855, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID
|
200 MIMECONTF_VALID_NLS
| MIMECONTF_MIME_LATEST
,
201 "ibm855", "ibm855", "ibm855" },
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" },
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" },
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" },
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
[] =
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" },
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" },
261 10006, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID_NLS
|
262 MIMECONTF_MIME_LATEST
,
263 "x-mac-greek", "x-mac-greek", "x-mac-greek" },
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
[] =
274 424, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID_NLS
|
275 MIMECONTF_MIME_LATEST
,
276 "ibm424", "ibm424", "ibm424" },
278 856, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_VALID_NLS
|
279 MIMECONTF_MIME_LATEST
,
280 "cp856", "cp856", "cp856" },
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" },
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" },
311 50220, MIMECONTF_IMPORT
| MIMECONTF_MAILNEWS
| MIMECONTF_EXPORT
|
312 MIMECONTF_SAVABLE_MAILNEWS
| MIMECONTF_VALID_NLS
|
313 MIMECONTF_PRIVCONVERTER
| MIMECONTF_MIME_LATEST
|
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"},
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
[] =
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
[] =
352 874, MIMECONTF_IMPORT
| MIMECONTF_EXPORT
| MIMECONTF_MIME_LATEST
,
353 "ibm-thai", "ibm-thai", "ibm-thai" }
355 static const MIME_CP_INFO turkish_cp
[] =
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" },
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" },
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" },
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" },
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" },
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" },
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" },
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" },
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
[] =
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" },
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" },
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
;
491 const MIME_CP_INFO
*mime_cp_info
;
492 const char *fixed_font
;
493 const char *proportional_font
;
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" }
531 struct list list_entry
;
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
)
569 while ((code
== 0 || code
== 51932) && i
< count
)
572 if (c1
== 0x1b /* ESC */)
584 if (c1
=='B' || c1
== '@')
598 else if (ISEUC(c1
) && ISEUC(c2
))
600 else if (((c1
== 142)) && HANKATA(c2
))
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
;
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
;
631 static int han2zen(unsigned char *p1
, unsigned char *p2
)
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,
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))))
647 else if ((*p2
== 223) && (ISMARU(*p1
)))
650 if (*p1
>= 161 && *p1
<= 223)
652 unsigned char index
= *p1
- 161;
661 if (((*p2
>= 74) && (*p2
<= 103)) || ((*p2
>= 110) && (*p2
<= 122)))
663 else if ((*p1
== 131) && (*p2
== 69))
666 else if ((maru
) && ((*p2
>= 110) && (*p2
<= 122)))
676 static UINT
ConvertJIS2SJIS(LPCSTR input
, DWORD count
, LPSTR output
)
681 BOOL shifted
= FALSE
;
686 if (p
== 0x1b /* ESC */)
692 if (p2
== '$' || p2
=='(')
694 if (p2
== 'K' || p2
=='$')
721 static inline int exit_shift(LPSTR out
, int c
)
732 static inline int enter_shift(LPSTR out
, int c
)
744 static UINT
ConvertSJIS2JIS(LPCSTR input
, DWORD count
, LPSTR output
)
749 BOOL shifted
= FALSE
;
754 if (p
== 10 || p
== 13) /* NL and CR */
759 j
+= exit_shift(output
,j
);
773 p2
= input
[i
] & 0xff;
780 j
+=enter_shift(output
,j
);
798 p2
= input
[i
+1] & 0xff;
804 j
+=enter_shift(output
,j
);
819 j
+= exit_shift(output
,j
);
831 j
+= exit_shift(output
,j
);
835 static UINT
ConvertJISJapaneseToUnicode(LPCSTR input
, DWORD count
,
836 LPWSTR output
, DWORD out_count
)
840 sjis_string
= HeapAlloc(GetProcessHeap(),0,count
);
841 rc
= ConvertJIS2SJIS(input
,count
,sjis_string
);
844 TRACE("%s\n",debugstr_an(sjis_string
,rc
));
846 rc
= MultiByteToWideChar(932,0,sjis_string
,rc
,output
,out_count
);
848 rc
= MultiByteToWideChar(932,0,sjis_string
,rc
,0,0);
850 HeapFree(GetProcessHeap(),0,sjis_string
);
855 static UINT
ConvertUnknownJapaneseToUnicode(LPCSTR input
, DWORD count
,
856 LPWSTR output
, DWORD out_count
)
860 int code
= DetectJapaneseCode(input
,count
);
861 TRACE("Japanese code %i\n",code
);
867 rc
= MultiByteToWideChar(CP_ACP
,0,input
,count
,output
,out_count
);
869 rc
= MultiByteToWideChar(CP_ACP
,0,input
,count
,0,0);
874 rc
= MultiByteToWideChar(932,0,input
,count
,output
,out_count
);
876 rc
= MultiByteToWideChar(932,0,input
,count
,0,0);
881 rc
= MultiByteToWideChar(20932,0,input
,count
,output
,out_count
);
883 rc
= MultiByteToWideChar(20932,0,input
,count
,0,0);
887 sjis_string
= HeapAlloc(GetProcessHeap(),0,count
);
888 rc
= ConvertJIS2SJIS(input
,count
,sjis_string
);
891 TRACE("%s\n",debugstr_an(sjis_string
,rc
));
893 rc
= MultiByteToWideChar(932,0,sjis_string
,rc
,output
,out_count
);
895 rc
= MultiByteToWideChar(932,0,sjis_string
,rc
,0,0);
897 HeapFree(GetProcessHeap(),0,sjis_string
);
903 static UINT
ConvertJapaneseUnicodeToJIS(LPCWSTR input
, DWORD count
,
904 LPSTR output
, DWORD out_count
)
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
);
918 ConvertSJIS2JIS(sjis_string
, len
, output
);
920 HeapFree(GetProcessHeap(),0,sjis_string
);
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
)
941 case DLL_PROCESS_ATTACH
:
943 MLANG_tls_index
= TlsAlloc();
944 DisableThreadLibraryCalls(hInstDLL
);
946 case DLL_PROCESS_DETACH
:
948 TlsFree(MLANG_tls_index
);
954 HRESULT WINAPI
ConvertINetMultiByteToUnicode(
964 TRACE("%p %d %s %p %p %p\n", pdwMode
, dwEncoding
,
965 debugstr_a(pSrcStr
), pcSrcSize
, pDstStr
, pcDstSize
);
971 pcSrcSize
= &src_len
;
979 /* forwarding euc-jp to EUC-JP */
980 if (dwEncoding
== 51932)
986 if (*pcSrcSize
== -1)
987 *pcSrcSize
= lstrlenW((LPCWSTR
)pSrcStr
);
988 *pcDstSize
= min(*pcSrcSize
, *pcDstSize
);
989 *pcSrcSize
*= sizeof(WCHAR
);
991 memmove(pDstStr
, pSrcStr
, *pcDstSize
* sizeof(WCHAR
));
997 *pcDstSize
= ConvertJISJapaneseToUnicode(pSrcStr
,*pcSrcSize
,pDstStr
,*pcDstSize
);
1000 *pcDstSize
= ConvertUnknownJapaneseToUnicode(pSrcStr
,*pcSrcSize
,pDstStr
,*pcDstSize
);
1004 if (*pcSrcSize
== -1)
1005 *pcSrcSize
= lstrlenA(pSrcStr
);
1008 *pcDstSize
= MultiByteToWideChar(dwEncoding
, 0, pSrcStr
, *pcSrcSize
, pDstStr
, *pcDstSize
);
1010 *pcDstSize
= MultiByteToWideChar(dwEncoding
, 0, pSrcStr
, *pcSrcSize
, NULL
, 0);
1020 HRESULT WINAPI
ConvertINetUnicodeToMultiByte(
1031 TRACE("%p %d %s %p %p %p\n", pdwMode
, dwEncoding
,
1032 debugstr_w(pSrcStr
), pcSrcSize
, pDstStr
, pcDstSize
);
1038 pcSrcSize
= &src_len
;
1040 destsz
= (pDstStr
) ? *pcDstSize
: 0;
1043 if (!pSrcStr
|| !*pcSrcSize
)
1046 if (*pcSrcSize
== -1)
1047 *pcSrcSize
= lstrlenW(pSrcStr
);
1049 /* forwarding euc-jp to EUC-JP */
1050 if (dwEncoding
== 51932)
1053 if (dwEncoding
== CP_UNICODE
)
1055 if (*pcSrcSize
== -1)
1056 *pcSrcSize
= lstrlenW(pSrcStr
);
1058 size
= min(*pcSrcSize
, destsz
) * sizeof(WCHAR
);
1060 memmove(pDstStr
, pSrcStr
, size
);
1065 else if (dwEncoding
== 50220 || dwEncoding
== 50221 || dwEncoding
== 50222)
1067 size
= ConvertJapaneseUnicodeToJIS(pSrcStr
, *pcSrcSize
, NULL
, 0);
1073 size
= ConvertJapaneseUnicodeToJIS(pSrcStr
, *pcSrcSize
, pDstStr
,
1082 size
= WideCharToMultiByte(dwEncoding
, 0, pSrcStr
, *pcSrcSize
,
1083 NULL
, 0, NULL
, NULL
);
1089 size
= WideCharToMultiByte(dwEncoding
, 0, pSrcStr
, *pcSrcSize
,
1090 pDstStr
, destsz
, NULL
, NULL
);
1105 HRESULT WINAPI
ConvertINetString(
1107 DWORD dwSrcEncoding
,
1108 DWORD dwDstEncoding
,
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
)
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
);
1140 TRACE("convert %s from %d to %d\n", debugstr_a(pSrcStr
), dwSrcEncoding
, dwDstEncoding
);
1142 hr
= ConvertINetMultiByteToUnicode(pdwMode
, dwSrcEncoding
, pSrcStr
, pcSrcSize
, NULL
, &cDstSizeW
);
1146 pDstStrW
= HeapAlloc(GetProcessHeap(), 0, cDstSizeW
* sizeof(WCHAR
));
1147 hr
= ConvertINetMultiByteToUnicode(pdwMode
, dwSrcEncoding
, pSrcStr
, pcSrcSize
, pDstStrW
, &cDstSizeW
);
1149 hr
= ConvertINetUnicodeToMultiByte(pdwMode
, dwDstEncoding
, pDstStrW
, &cDstSizeW
, pDstStr
, pcDstSize
);
1151 HeapFree(GetProcessHeap(), 0, pDstStrW
);
1156 static HRESULT
GetFamilyCodePage(
1158 UINT
* puiFamilyCodePage
)
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
;
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
)
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
;
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
);
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
);
1217 buffer
[n
- 1] = '\0';
1222 LCMapStringA( LOCALE_USER_DEFAULT
, LCMAP_LOWERCASE
, buffer
, n
+ i
, rfc1766
, len
);
1223 return ((n
+ i
) > len
) ? E_INVALIDARG
: S_OK
;
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
);
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
);
1244 buffer
[n
- 1] = '\0';
1249 LCMapStringW(LOCALE_USER_DEFAULT
, LCMAP_LOWERCASE
, buffer
, n
+ i
, rfc1766
, len
);
1250 return ((n
+ i
) > len
) ? E_INVALIDARG
: S_OK
;
1255 HRESULT WINAPI
LcidToRfc1766A(
1260 TRACE("%04x %p %u\n", lcid
, pszRfc1766
, nChar
);
1262 return E_INVALIDARG
;
1264 return lcid_to_rfc1766A(lcid
, pszRfc1766
, nChar
);
1267 HRESULT WINAPI
LcidToRfc1766W(
1272 TRACE("%04x %p %u\n", lcid
, pszRfc1766
, nChar
);
1274 return E_INVALIDARG
;
1276 return lcid_to_rfc1766W(lcid
, pszRfc1766
, nChar
);
1279 static HRESULT
lcid_from_rfc1766(IEnumRfc1766
*iface
, LCID
*lcid
, LPCWSTR rfc1766
)
1284 while (IEnumRfc1766_Next(iface
, 1, &info
, &num
) == S_OK
)
1286 if (!strcmpiW(info
.wszRfc1766
, rfc1766
))
1291 if (strlenW(rfc1766
) == 2 && !memcmp(info
.wszRfc1766
, rfc1766
, 2 * sizeof(WCHAR
)))
1293 *lcid
= PRIMARYLANGID(info
.lcid
);
1301 HRESULT WINAPI
Rfc1766ToLcidW(LCID
*pLocale
, LPCWSTR pszRfc1766
)
1303 IEnumRfc1766
*enumrfc1766
;
1306 TRACE("(%p, %s)\n", pLocale
, debugstr_w(pszRfc1766
));
1308 if (!pLocale
|| !pszRfc1766
)
1309 return E_INVALIDARG
;
1311 hr
= EnumRfc1766_create(0, &enumrfc1766
);
1315 hr
= lcid_from_rfc1766(enumrfc1766
, pLocale
, pszRfc1766
);
1316 IEnumRfc1766_Release(enumrfc1766
);
1321 HRESULT WINAPI
Rfc1766ToLcidA(LCID
*lcid
, LPCSTR rfc1766A
)
1323 WCHAR rfc1766W
[MAX_RFC1766_NAME
+ 1];
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
;
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
)
1355 ret
= TranslateCharsetInfo(Csb
, &charset_info
, TCI_SRCFONTSIG
);
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
;
1407 static HRESULT
release_font(HFONT font
)
1409 struct font_list
*font_list_entry
;
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
);
1420 HeapFree(GetProcessHeap(), 0, font_list_entry
);
1425 LeaveCriticalSection(&font_cache_critical
);
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
);
1447 /******************************************************************************
1448 * MLANG ClassFactory
1451 IClassFactory IClassFactory_iface
;
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
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
);
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
);
1504 TRACE("Destroying %p\n", This
);
1505 HeapFree(GetProcessHeap(), 0, This
);
1511 static HRESULT WINAPI
MLANGCF_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
1512 REFIID riid
, void **ppobj
)
1514 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1518 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
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
);
1530 static HRESULT WINAPI
MLANGCF_LockServer(IClassFactory
*iface
, BOOL dolock
)
1540 static const IClassFactoryVtbl MLANGCF_Vtbl
=
1542 MLANGCF_QueryInterface
,
1545 MLANGCF_CreateInstance
,
1549 /******************************************************************
1550 * DllGetClassObject (MLANG.@)
1552 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
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
))
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
;
1583 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
1585 *ppv
= &factory
->IClassFactory_iface
;
1587 TRACE("(%p) <- %p\n", ppv
, &factory
->IClassFactory_iface
);
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
;
1603 DWORD total_cp
, total_scripts
;
1606 /******************************************************************************/
1608 typedef struct tagEnumCodePage_impl
1610 IEnumCodePage IEnumCodePage_iface
;
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
,
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
;
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
);
1659 TRACE("Destroying %p\n", This
);
1660 HeapFree(GetProcessHeap(), 0, This
->cpinfo
);
1661 HeapFree(GetProcessHeap(), 0, This
);
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
);
1676 static HRESULT WINAPI
fnIEnumCodePage_Next(
1677 IEnumCodePage
* iface
,
1680 ULONG
* pceltFetched
)
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
;
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
;
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
);
1717 static HRESULT WINAPI
fnIEnumCodePage_Reset(
1718 IEnumCodePage
* iface
)
1720 EnumCodePage_impl
*This
= impl_from_IEnumCodePage( iface
);
1722 TRACE("%p\n", This
);
1728 static HRESULT WINAPI
fnIEnumCodePage_Skip(
1729 IEnumCodePage
* iface
,
1732 EnumCodePage_impl
*This
= impl_from_IEnumCodePage( iface
);
1734 TRACE("%p %u\n", This
, celt
);
1736 if (celt
>= This
->total
) return S_FALSE
;
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
;
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
;
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
)
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
;
1799 /******************************************************************************/
1801 typedef struct tagEnumScript_impl
1803 IEnumScript IEnumScript_iface
;
1805 SCRIPTINFO
*script_info
;
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(
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
;
1832 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
1833 return E_NOINTERFACE
;
1836 static ULONG WINAPI
fnIEnumScript_AddRef(
1839 EnumScript_impl
*This
= impl_from_IEnumScript( iface
);
1840 return InterlockedIncrement(&This
->ref
);
1843 static ULONG WINAPI
fnIEnumScript_Release(
1846 EnumScript_impl
*This
= impl_from_IEnumScript( iface
);
1847 ULONG ref
= InterlockedDecrement(&This
->ref
);
1849 TRACE("%p ref = %d\n", This
, ref
);
1852 TRACE("Destroying %p\n", This
);
1853 HeapFree(GetProcessHeap(), 0, This
->script_info
);
1854 HeapFree(GetProcessHeap(), 0, This
);
1860 static HRESULT WINAPI
fnIEnumScript_Clone(
1862 IEnumScript
** ppEnum
)
1864 EnumScript_impl
*This
= impl_from_IEnumScript( iface
);
1865 FIXME("%p %p: stub!\n", This
, ppEnum
);
1869 static HRESULT WINAPI
fnIEnumScript_Next(
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
;
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
;
1895 static HRESULT WINAPI
fnIEnumScript_Reset(
1898 EnumScript_impl
*This
= impl_from_IEnumScript( iface
);
1900 TRACE("%p\n", This
);
1906 static HRESULT WINAPI
fnIEnumScript_Skip(
1910 EnumScript_impl
*This
= impl_from_IEnumScript( iface
);
1912 TRACE("%p %u\n", This
, celt
);
1914 if (celt
>= This
->total
) return S_FALSE
;
1920 static const IEnumScriptVtbl IEnumScript_vtbl
=
1922 fnIEnumScript_QueryInterface
,
1923 fnIEnumScript_AddRef
,
1924 fnIEnumScript_Release
,
1925 fnIEnumScript_Clone
,
1927 fnIEnumScript_Reset
,
1931 static HRESULT
EnumScript_create( MLang_impl
* mlang
, DWORD dwFlags
,
1932 LANGID LangId
, IEnumScript
** ppEnumScript
)
1934 EnumScript_impl
*es
;
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
;
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
;
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
2136 PMIMECPINFO pCodePageInfo
)
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
);
2158 static HRESULT WINAPI
fnIMultiLanguage_GetFamilyCodePage(
2159 IMultiLanguage
* iface
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
;
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
,
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
;
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
);
2318 TRACE("Destroying %p\n", This
);
2319 HeapFree(GetProcessHeap(), 0, This
->info
);
2320 HeapFree(GetProcessHeap(), 0, This
);
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
);
2335 static HRESULT WINAPI
fnIEnumRfc1766_Next(
2336 IEnumRfc1766
*iface
,
2339 ULONG
*pceltFetched
)
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
;
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
;
2360 for (i
= 0; i
< celt
; i
++)
2362 TRACE("#%u: %08x %s %s\n",
2364 wine_dbgstr_w(rgelt
[i
].wszRfc1766
),
2365 wine_dbgstr_w(rgelt
[i
].wszLocaleName
));
2370 static HRESULT WINAPI
fnIEnumRfc1766_Reset(
2371 IEnumRfc1766
*iface
)
2373 EnumRfc1766_impl
*This
= impl_from_IEnumRfc1766( iface
);
2375 TRACE("%p\n", This
);
2381 static HRESULT WINAPI
fnIEnumRfc1766_Skip(
2382 IEnumRfc1766
*iface
,
2385 EnumRfc1766_impl
*This
= impl_from_IEnumRfc1766( iface
);
2387 TRACE("%p %u\n", This
, celt
);
2389 if (celt
>= This
->total
) return S_FALSE
;
2395 static const IEnumRfc1766Vtbl IEnumRfc1766_vtbl
=
2397 fnIEnumRfc1766_QueryInterface
,
2398 fnIEnumRfc1766_AddRef
,
2399 fnIEnumRfc1766_Release
,
2400 fnIEnumRfc1766_Clone
,
2401 fnIEnumRfc1766_Next
,
2402 fnIEnumRfc1766_Reset
,
2406 struct enum_locales_data
2409 DWORD total
, allocated
;
2412 static BOOL CALLBACK
enum_locales_proc(LPWSTR locale
)
2415 struct enum_locales_data
*data
= TlsGetValue(MLANG_tls_index
);
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 */
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
));
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
;
2459 data
.allocated
= 160;
2460 data
.info
= HeapAlloc(GetProcessHeap(), 0, data
.allocated
* sizeof(RFC1766INFO
));
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
);
2475 HeapFree(GetProcessHeap(), 0, data
.info
);
2476 HeapFree(GetProcessHeap(), 0, rfc
);
2480 rfc
->info
= data
.info
;
2481 rfc
->total
= data
.total
;
2483 *ppEnum
= &rfc
->IEnumRfc1766_iface
;
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
,
2503 PRFC1766INFO pRfc1766Info
)
2505 LCTYPE type
= LOCALE_SLANGUAGE
;
2507 TRACE("(%p, 0x%04x, %p)\n", iface
, Locale
, 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 */
2521 if (!SUBLANGID(Locale
)) {
2522 TRACE("SUBLANGID missing in 0x%04x\n", Locale
);
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))
2535 /* Locale not supported */
2536 return E_INVALIDARG
;
2539 static HRESULT WINAPI
fnIMultiLanguage_CreateConvertCharset(
2540 IMultiLanguage
* iface
,
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
,
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
;
2614 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), obj
);
2616 return E_NOINTERFACE
;
2619 IMultiLanguage3_AddRef(iface
);
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
);
2637 HeapFree(GetProcessHeap(), 0, This
);
2644 static HRESULT WINAPI
fnIMultiLanguage3_GetNumberOfCodePageInfo(
2645 IMultiLanguage3
* iface
,
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
;
2658 static void fill_cp_info(const struct mlang_data
*ml_data
, UINT index
, MIMECPINFO
*mime_cp_info
)
2662 if (TranslateCharsetInfo((DWORD
*)(DWORD_PTR
)ml_data
->family_codepage
, &csi
,
2664 mime_cp_info
->bGDICharset
= csi
.ciCharset
;
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
,
2701 PMIMECPINFO pCodePageInfo
)
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
);
2723 static HRESULT WINAPI
fnIMultiLanguage3_GetFamilyCodePage(
2724 IMultiLanguage3
* iface
,
2726 UINT
* puiFamilyCodePage
)
2728 return GetFamilyCodePage(uiCodePage
, puiFamilyCodePage
);
2731 static HRESULT WINAPI
fnIMultiLanguage3_EnumCodePages(
2732 IMultiLanguage3
* iface
,
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
,
2747 PMIMECSETINFO pCharsetInfo
)
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
);
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
);
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
);
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
,
2816 DWORD dwSrcEncoding
,
2817 DWORD dwDstEncoding
,
2823 return ConvertINetString(pdwMode
, dwSrcEncoding
, dwDstEncoding
,
2824 (LPCSTR
)pSrcStr
, (LPINT
)pcSrcSize
, (LPSTR
)pDstStr
, (LPINT
)pcDstSize
);
2827 static HRESULT WINAPI
fnIMultiLanguage3_ConvertStringToUnicode(
2828 IMultiLanguage3
* iface
,
2836 return ConvertINetMultiByteToUnicode(pdwMode
, dwEncoding
,
2837 pSrcStr
, (LPINT
)pcSrcSize
, pDstStr
, (LPINT
)pcDstSize
);
2840 static HRESULT WINAPI
fnIMultiLanguage3_ConvertStringFromUnicode(
2841 IMultiLanguage3
* iface
,
2849 return ConvertINetUnicodeToMultiByte(pdwMode
, dwEncoding
,
2850 pSrcStr
, (LPINT
)pcSrcSize
, pDstStr
, (LPINT
)pcDstSize
);
2853 static HRESULT WINAPI
fnIMultiLanguage3_ConvertStringReset(
2854 IMultiLanguage3
* iface
)
2860 static HRESULT WINAPI
fnIMultiLanguage3_GetRfc1766FromLcid(
2861 IMultiLanguage3
* iface
,
2865 WCHAR buf
[MAX_RFC1766_NAME
];
2867 TRACE("%p %04x %p\n", iface
, lcid
, pbstrRfc1766
);
2869 return E_INVALIDARG
;
2871 if (!lcid_to_rfc1766W( lcid
, buf
, MAX_RFC1766_NAME
))
2873 *pbstrRfc1766
= SysAllocString( buf
);
2879 static HRESULT WINAPI
fnIMultiLanguage3_GetLcidFromRfc1766(
2880 IMultiLanguage3
* iface
,
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
);
2896 hr
= lcid_from_rfc1766(rfc1766
, pLocale
, bstrRfc1766
);
2898 IEnumRfc1766_Release(rfc1766
);
2902 static HRESULT WINAPI
fnIMultiLanguage3_EnumRfc1766(
2903 IMultiLanguage3
* iface
,
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
,
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
);
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 */
2937 if (!SUBLANGID(Locale
)) {
2938 TRACE("SUBLANGID missing in 0x%04x\n", Locale
);
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
);
2953 if ((!lcid_to_rfc1766W(Locale
, pRfc1766Info
->wszRfc1766
, MAX_RFC1766_NAME
)) &&
2954 (GetLocaleInfoW(Locale
, type
, pRfc1766Info
->wszLocaleName
, MAX_LOCALE_NAME
) > 0))
2957 /* Locale not supported */
2958 return E_INVALIDARG
;
2961 static HRESULT WINAPI
fnIMultiLanguage3_CreateConvertCharset(
2962 IMultiLanguage3
* iface
,
2966 IMLangConvertCharset
** convert_charset
)
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
,
2983 DWORD dwSrcEncoding
,
2984 DWORD dwDstEncoding
,
2988 char *src
, *dst
= NULL
;
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
)))
3015 hr
= ConvertINetString(pdwMode
, dwSrcEncoding
, dwDstEncoding
, src
, &srclen
, dst
, &dstlen
);
3016 if (FAILED(hr
)) goto exit
;
3018 hr
= IStream_Write(pstmOut
, dst
, dstlen
, NULL
);
3021 HeapFree(GetProcessHeap(), 0, src
);
3022 HeapFree(GetProcessHeap(), 0, dst
);
3026 static HRESULT WINAPI
fnIMultiLanguage3_ConvertStringToUnicodeEx(
3027 IMultiLanguage3
* iface
,
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.
3051 * see ConvertStringToUnicode
3053 * lpFallBack if dwFlag contains MLCONVCHARF_USEDEFCHAR, lpFallBack string used
3054 * instead unconvertible characters.
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
,
3075 return ConvertINetUnicodeToMultiByte(pdwMode
, dwEncoding
,
3076 pSrcStr
, (LPINT
)pcSrcSize
, pDstStr
, (LPINT
)pcDstSize
);
3079 static HRESULT WINAPI
fnIMultiLanguage3_DetectCodepageInIStream(
3080 IMultiLanguage3
* iface
,
3082 DWORD dwPrefWinCodePage
,
3084 DetectEncodingInfo
* lpEncoding
,
3091 static HRESULT WINAPI
fnIMultiLanguage3_DetectInputCodepage(
3092 IMultiLanguage3
* iface
,
3094 DWORD dwPrefWinCodePage
,
3097 DetectEncodingInfo
* lpEncoding
,
3104 static HRESULT WINAPI
fnIMultiLanguage3_ValidateCodePage(
3105 IMultiLanguage3
* iface
,
3109 return IMultiLanguage3_ValidateCodePageEx(iface
,uiCodePage
,hwnd
,0);
3112 static HRESULT WINAPI
fnIMultiLanguage3_GetCodePageDescription(
3113 IMultiLanguage3
* iface
,
3116 LPWSTR lpWideCharStr
,
3119 /* Find first instance */
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
);
3140 static HRESULT WINAPI
fnIMultiLanguage3_IsCodePageInstallable(
3141 IMultiLanguage3
* iface
,
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
,
3154 FIXME("0x%08x\n", dwSource
);
3158 static HRESULT WINAPI
fnIMultiLanguage3_GetNumberOfScripts(
3159 IMultiLanguage3
* iface
,
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
;
3172 static HRESULT WINAPI
fnIMultiLanguage3_EnumScripts(
3173 IMultiLanguage3
* iface
,
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
,
3189 DWORD dwfIODControl
)
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
))
3200 /* check for mlang supported code pages */
3201 for (i
= 0; i
< sizeof(mlang_data
)/sizeof(mlang_data
[0]); i
++)
3204 for (n
= 0; n
< mlang_data
[i
].number_of_cp
; n
++)
3206 if (mlang_data
[i
].mime_cp_info
[n
].cp
== uiCodePage
)
3211 if (dwfIODControl
!= CPIOD_PEEK
)
3212 FIXME("Request to install codepage language pack not handled\n");
3217 static HRESULT WINAPI
fnIMultiLanguage3_DetectOutboundCodePage(
3218 IMultiLanguage3
*iface
,
3220 LPCWSTR lpWideCharStr
,
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;
3243 static HRESULT WINAPI
fnIMultiLanguage3_DetectOutboundCodePageInIStream(
3244 IMultiLanguage3
*iface
,
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;
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
,
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
);
3338 TRACE("(%p)->(%s %p)\n", This
, debugstr_wn(&ch_src
, 1), ret_codepages
);
3342 for (i
= 0; i
< sizeof(mlang_data
)/sizeof(mlang_data
[0]); i
++)
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 */
3355 IMLangFontLink2_CodePageToCodePages(iface
,
3356 mlang_data
[i
].family_codepage
, &codepages
);
3357 *ret_codepages
|= codepages
;
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
);
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
++)
3385 ret
= IMLangFontLink2_GetCharCodePages(iface
, src
[i
], &cp
);
3386 if (ret
!= S_OK
) return E_FAIL
;
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
);
3400 static HRESULT WINAPI
fnIMLangFontLink2_CodePageToCodePages(IMLangFontLink2
* iface
,
3404 MLang_impl
*This
= impl_from_IMLangFontLink2(iface
);
3408 TRACE("(%p)->(%u %p)\n", This
, codepage
, codepages
);
3410 rc
= TranslateCharsetInfo((DWORD
*)(DWORD_PTR
)codepage
, &cs
, TCI_SRCCODEPAGE
);
3413 *codepages
= cs
.fs
.fsCsb
[0];
3414 TRACE("resulting codepages 0x%x\n", *codepages
);
3418 TRACE("codepage not found\n");
3423 static HRESULT WINAPI
fnIMLangFontLink2_CodePagesToCodePage(IMLangFontLink2
* iface
,
3424 DWORD codepages
, UINT def_codepage
, UINT
*codepage
)
3426 MLang_impl
*This
= impl_from_IMLangFontLink2(iface
);
3432 TRACE("(%p)->(0x%x %u %p)\n", This
, codepages
, def_codepage
, codepage
);
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
;
3444 for (i
= 0; i
< 32; i
++)
3447 if (codepages
& mask
)
3452 rc
= TranslateCharsetInfo(Csb
, &cs
, TCI_SRCFONTSIG
);
3456 TRACE("Falling back to least significant found CodePage %u\n",
3458 *codepage
= cs
.ciACP
;
3463 TRACE("no codepage found\n");
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
;
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]);
3486 static HRESULT WINAPI
fnIMLangFontLink2_ReleaseFont(IMLangFontLink2
* This
,
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
)
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
);
3517 if (pFont
== NULL
) return E_INVALIDARG
;
3518 FIXME("the situation where dwCodepages is set to zero is not implemented\n");
3523 static HRESULT WINAPI
fnIMLangFontLink2_GetFontUnicodeRanges(IMLangFontLink2
* This
,
3524 HDC hDC
, UINT
*puiRanges
, UNICODERANGE
*pUranges
)
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
;
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
;
3548 HeapFree(GetProcessHeap(), 0, gs
);
3552 static HRESULT WINAPI
fnIMLangFontLink2_GetScriptFontInfo(IMLangFontLink2
* This
,
3553 SCRIPT_ID sid
, DWORD dwFlags
, UINT
*puiFonts
,
3554 SCRIPTFONTINFO
*pScriptFont
)
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
)
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
);
3589 static HRESULT WINAPI
fnIMLangFontLink2_CodePageToScriptID(IMLangFontLink2
* This
,
3590 UINT uiCodePage
, SCRIPT_ID
*pSid
)
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
;
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
,
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
,
3667 FIXME("(%p)->%p %i %i %i %i %p %p\n", iface
, pSrcMLStr
, lSrcPos
, lSrcLen
, cMinColumns
, cMaxColumns
, plLineLen
, plSkipLen
);
3671 static HRESULT WINAPI
fnIMLangLineBreakConsole_BreakLineW(
3672 IMLangLineBreakConsole
* iface
,
3674 const WCHAR
* pszSrc
,
3680 FIXME("(%p)->%i %s %i %i %p %p\n", iface
, locale
, debugstr_wn(pszSrc
,cchSrc
), cchSrc
, cMaxColumns
, pcchLine
, pcchSkip
);
3687 static HRESULT WINAPI
fnIMLangLineBreakConsole_BreakLineA(
3688 IMLangLineBreakConsole
* iface
,
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
] == ' ')
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
;
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
);
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
);
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
);
3778 HeapFree(GetProcessHeap(), 0, This
);
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
;
3794 FIXME("property 0x%08x not supported\n", prop
);
3796 This
->src_cp
= src_cp
;
3797 This
->dst_cp
= dst_cp
;
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
;
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
;
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
);
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
);
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
)
3874 TRACE("Creating MultiLanguage object\n");
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;
3894 *ppObj
= &mlang
->IMultiLanguage_iface
;
3895 TRACE("returning %p\n", mlang
);
3902 static HRESULT
MLangConvertCharset_create(IUnknown
*outer
, void **obj
)
3904 struct convert_charset
*convert
;
3907 return CLASS_E_NOAGGREGATION
;
3911 convert
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct convert_charset
));
3912 if (!convert
) return E_OUTOFMEMORY
;
3914 convert
->IMLangConvertCharset_iface
.lpVtbl
= &MLangConvertCharsetVtbl
;
3917 *obj
= &convert
->IMLangConvertCharset_iface
;
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
);