4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
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
30 #include "lcformat_private.h"
33 extern int wine_fold_string(int flags
, const WCHAR
*src
, int srclen
, WCHAR
*dst
, int dstlen
);
34 extern int wine_get_sortkey(int flags
, const WCHAR
*src
, int srclen
, char *dst
, int dstlen
);
35 extern int wine_compare_string(int flags
, const WCHAR
*str1
, int len1
, const WCHAR
*str2
, int len2
);
37 extern HMODULE kernel32_handle
;
39 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
40 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
42 static const WCHAR szLocaleKeyName
[] = {
43 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
44 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
45 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
46 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
49 static const WCHAR szLangGroupsKeyName
[] = {
50 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
51 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
52 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
53 'C','o','n','t','r','o','l','\\','N','l','s','\\',
54 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
57 /* Charset to codepage map, sorted by name. */
58 static const struct charset_entry
60 const char *charset_name
;
99 { "ISO88591", 28591 },
100 { "ISO885910", 28600 },
101 { "ISO885913", 28603 },
102 { "ISO885914", 28604 },
103 { "ISO885915", 28605 },
104 { "ISO885916", 28606 },
105 { "ISO88592", 28592 },
106 { "ISO88593", 28593 },
107 { "ISO88594", 28594 },
108 { "ISO88595", 28595 },
109 { "ISO88596", 28596 },
110 { "ISO88597", 28597 },
111 { "ISO88598", 28598 },
112 { "ISO88599", 28599 },
121 WCHAR win_name
[128]; /* Windows name ("en-US") */
122 WCHAR lang
[128]; /* language ("en") (note: buffer contains the other strings too) */
123 WCHAR
*country
; /* country ("US") */
124 WCHAR
*charset
; /* charset ("UTF-8") for Unix format only */
125 WCHAR
*script
; /* script ("Latn") for Windows format only */
126 WCHAR
*modifier
; /* modifier or sort order */
127 LCID lcid
; /* corresponding LCID */
128 int matches
; /* number of elements matching LCID (0..4) */
129 UINT codepage
; /* codepage corresponding to charset */
132 /* locale ids corresponding to the various Unix locale parameters */
133 static LCID lcid_LC_COLLATE
;
134 static LCID lcid_LC_CTYPE
;
135 static LCID lcid_LC_MONETARY
;
136 static LCID lcid_LC_NUMERIC
;
137 static LCID lcid_LC_TIME
;
138 static LCID lcid_LC_PAPER
;
139 static LCID lcid_LC_MEASUREMENT
;
140 static LCID lcid_LC_TELEPHONE
;
142 /* Copy Ascii string to Unicode without using codepages */
143 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
145 while (n
> 1 && *src
)
147 *dst
++ = (unsigned char)*src
++;
154 /***********************************************************************
157 * Retrieve the ANSI codepage for a given locale.
159 static inline UINT
get_lcid_codepage( LCID lcid
)
162 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
163 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
167 /***********************************************************************
168 * convert_default_lcid
170 * Get the default LCID to use for a given lctype in GetLocaleInfo.
172 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
174 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
175 lcid
== LOCALE_USER_DEFAULT
||
176 lcid
== LOCALE_NEUTRAL
)
180 switch(lctype
& 0xffff)
182 case LOCALE_SSORTNAME
:
183 default_id
= lcid_LC_COLLATE
;
186 case LOCALE_FONTSIGNATURE
:
187 case LOCALE_IDEFAULTANSICODEPAGE
:
188 case LOCALE_IDEFAULTCODEPAGE
:
189 case LOCALE_IDEFAULTEBCDICCODEPAGE
:
190 case LOCALE_IDEFAULTMACCODEPAGE
:
191 case LOCALE_IDEFAULTUNIXCODEPAGE
:
192 default_id
= lcid_LC_CTYPE
;
195 case LOCALE_ICURRDIGITS
:
196 case LOCALE_ICURRENCY
:
197 case LOCALE_IINTLCURRDIGITS
:
198 case LOCALE_INEGCURR
:
199 case LOCALE_INEGSEPBYSPACE
:
200 case LOCALE_INEGSIGNPOSN
:
201 case LOCALE_INEGSYMPRECEDES
:
202 case LOCALE_IPOSSEPBYSPACE
:
203 case LOCALE_IPOSSIGNPOSN
:
204 case LOCALE_IPOSSYMPRECEDES
:
205 case LOCALE_SCURRENCY
:
206 case LOCALE_SINTLSYMBOL
:
207 case LOCALE_SMONDECIMALSEP
:
208 case LOCALE_SMONGROUPING
:
209 case LOCALE_SMONTHOUSANDSEP
:
210 case LOCALE_SNATIVECURRNAME
:
211 default_id
= lcid_LC_MONETARY
;
215 case LOCALE_IDIGITSUBSTITUTION
:
217 case LOCALE_INEGNUMBER
:
218 case LOCALE_SDECIMAL
:
219 case LOCALE_SGROUPING
:
221 case LOCALE_SNATIVEDIGITS
:
222 case LOCALE_SNEGATIVESIGN
:
223 //case LOCALE_SNEGINFINITY:
224 //case LOCALE_SPOSINFINITY:
225 case LOCALE_SPOSITIVESIGN
:
226 case LOCALE_STHOUSAND
:
227 default_id
= lcid_LC_NUMERIC
;
230 case LOCALE_ICALENDARTYPE
:
231 case LOCALE_ICENTURY
:
233 case LOCALE_IDAYLZERO
:
234 case LOCALE_IFIRSTDAYOFWEEK
:
235 case LOCALE_IFIRSTWEEKOFYEAR
:
237 case LOCALE_IMONLZERO
:
238 case LOCALE_IOPTIONALCALENDAR
:
240 case LOCALE_ITIMEMARKPOSN
:
244 case LOCALE_SABBREVDAYNAME1
:
245 case LOCALE_SABBREVDAYNAME2
:
246 case LOCALE_SABBREVDAYNAME3
:
247 case LOCALE_SABBREVDAYNAME4
:
248 case LOCALE_SABBREVDAYNAME5
:
249 case LOCALE_SABBREVDAYNAME6
:
250 case LOCALE_SABBREVDAYNAME7
:
251 case LOCALE_SABBREVMONTHNAME1
:
252 case LOCALE_SABBREVMONTHNAME2
:
253 case LOCALE_SABBREVMONTHNAME3
:
254 case LOCALE_SABBREVMONTHNAME4
:
255 case LOCALE_SABBREVMONTHNAME5
:
256 case LOCALE_SABBREVMONTHNAME6
:
257 case LOCALE_SABBREVMONTHNAME7
:
258 case LOCALE_SABBREVMONTHNAME8
:
259 case LOCALE_SABBREVMONTHNAME9
:
260 case LOCALE_SABBREVMONTHNAME10
:
261 case LOCALE_SABBREVMONTHNAME11
:
262 case LOCALE_SABBREVMONTHNAME12
:
263 case LOCALE_SABBREVMONTHNAME13
:
265 case LOCALE_SDAYNAME1
:
266 case LOCALE_SDAYNAME2
:
267 case LOCALE_SDAYNAME3
:
268 case LOCALE_SDAYNAME4
:
269 case LOCALE_SDAYNAME5
:
270 case LOCALE_SDAYNAME6
:
271 case LOCALE_SDAYNAME7
:
272 //case LOCALE_SDURATION:
273 case LOCALE_SLONGDATE
:
274 case LOCALE_SMONTHNAME1
:
275 case LOCALE_SMONTHNAME2
:
276 case LOCALE_SMONTHNAME3
:
277 case LOCALE_SMONTHNAME4
:
278 case LOCALE_SMONTHNAME5
:
279 case LOCALE_SMONTHNAME6
:
280 case LOCALE_SMONTHNAME7
:
281 case LOCALE_SMONTHNAME8
:
282 case LOCALE_SMONTHNAME9
:
283 case LOCALE_SMONTHNAME10
:
284 case LOCALE_SMONTHNAME11
:
285 case LOCALE_SMONTHNAME12
:
286 case LOCALE_SMONTHNAME13
:
287 case LOCALE_SSHORTDATE
:
288 //case LOCALE_SSHORTESTDAYNAME1:
289 //case LOCALE_SSHORTESTDAYNAME2:
290 //case LOCALE_SSHORTESTDAYNAME3:
291 //case LOCALE_SSHORTESTDAYNAME4:
292 //case LOCALE_SSHORTESTDAYNAME5:
293 //case LOCALE_SSHORTESTDAYNAME6:
294 //case LOCALE_SSHORTESTDAYNAME7:
296 case LOCALE_STIMEFORMAT
:
297 case LOCALE_SYEARMONTH
:
298 default_id
= lcid_LC_TIME
;
301 case LOCALE_IPAPERSIZE
:
302 default_id
= lcid_LC_PAPER
;
305 case LOCALE_IMEASURE
:
306 default_id
= lcid_LC_MEASUREMENT
;
309 case LOCALE_ICOUNTRY
:
310 default_id
= lcid_LC_TELEPHONE
;
313 if (default_id
) lcid
= default_id
;
315 return ConvertDefaultLocale( lcid
);
318 /***********************************************************************
319 * is_genitive_name_supported
321 * Determine could LCTYPE basically support genitive name form or not.
323 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
325 switch(lctype
& 0xffff)
327 case LOCALE_SMONTHNAME1
:
328 case LOCALE_SMONTHNAME2
:
329 case LOCALE_SMONTHNAME3
:
330 case LOCALE_SMONTHNAME4
:
331 case LOCALE_SMONTHNAME5
:
332 case LOCALE_SMONTHNAME6
:
333 case LOCALE_SMONTHNAME7
:
334 case LOCALE_SMONTHNAME8
:
335 case LOCALE_SMONTHNAME9
:
336 case LOCALE_SMONTHNAME10
:
337 case LOCALE_SMONTHNAME11
:
338 case LOCALE_SMONTHNAME12
:
339 case LOCALE_SMONTHNAME13
:
346 /***********************************************************************
347 * create_registry_key
349 * Create the Control Panel\\International registry key.
351 static inline HANDLE
create_registry_key(void)
353 static const WCHAR cplW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
354 static const WCHAR intlW
[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
355 OBJECT_ATTRIBUTES attr
;
356 UNICODE_STRING nameW
;
357 HANDLE cpl_key
, hkey
= 0;
359 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
361 attr
.Length
= sizeof(attr
);
362 attr
.RootDirectory
= hkey
;
363 attr
.ObjectName
= &nameW
;
365 attr
.SecurityDescriptor
= NULL
;
366 attr
.SecurityQualityOfService
= NULL
;
367 RtlInitUnicodeString( &nameW
, cplW
);
369 if (!NtCreateKey( &cpl_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
371 NtClose( attr
.RootDirectory
);
372 attr
.RootDirectory
= cpl_key
;
373 RtlInitUnicodeString( &nameW
, intlW
);
374 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
)) hkey
= 0;
376 NtClose( attr
.RootDirectory
);
380 /***********************************************************************
381 * GetUserDefaultLangID (KERNEL32.@)
383 * Get the default language Id for the current user.
389 * The current LANGID of the default language for the current user.
391 LANGID WINAPI
GetUserDefaultLangID(void)
393 return LANGIDFROMLCID(GetUserDefaultLCID());
397 /***********************************************************************
398 * GetSystemDefaultLangID (KERNEL32.@)
400 * Get the default language Id for the system.
406 * The current LANGID of the default language for the system.
408 LANGID WINAPI
GetSystemDefaultLangID(void)
410 return LANGIDFROMLCID(GetSystemDefaultLCID());
414 /***********************************************************************
415 * GetUserDefaultLCID (KERNEL32.@)
417 * Get the default locale Id for the current user.
423 * The current LCID of the default locale for the current user.
425 LCID WINAPI
GetUserDefaultLCID(void)
428 NtQueryDefaultLocale( TRUE
, &lcid
);
433 /***********************************************************************
434 * GetSystemDefaultLCID (KERNEL32.@)
436 * Get the default locale Id for the system.
442 * The current LCID of the default locale for the system.
444 LCID WINAPI
GetSystemDefaultLCID(void)
447 NtQueryDefaultLocale( FALSE
, &lcid
);
452 /***********************************************************************
453 * GetUserDefaultUILanguage (KERNEL32.@)
455 * Get the default user interface language Id for the current user.
461 * The current LANGID of the default UI language for the current user.
463 LANGID WINAPI
GetUserDefaultUILanguage(void)
466 NtQueryDefaultUILanguage( &lang
);
471 /***********************************************************************
472 * GetSystemDefaultUILanguage (KERNEL32.@)
474 * Get the default user interface language Id for the system.
480 * The current LANGID of the default UI language for the system. This is
481 * typically the same language used during the installation process.
483 LANGID WINAPI
GetSystemDefaultUILanguage(void)
486 NtQueryInstallUILanguage( &lang
);
490 /******************************************************************************
491 * get_locale_value_name
493 * Gets the registry value name for a given lctype.
495 static const WCHAR
*get_locale_value_name( DWORD lctype
)
497 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
498 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
499 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
500 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
501 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
502 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
503 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
504 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
505 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
506 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
507 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
508 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
509 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
510 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
511 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
512 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
513 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
514 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
515 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
516 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
517 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
518 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
519 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
520 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
521 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
522 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
523 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
524 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
525 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
526 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
527 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
528 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
529 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
530 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
531 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
532 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
533 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
534 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
535 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
539 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
540 * the values are stored in the registry, confirmed under Windows.
542 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
543 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
544 case LOCALE_ICURRENCY
: return iCurrencyW
;
545 case LOCALE_IDIGITS
: return iDigitsW
;
546 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
547 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
548 case LOCALE_ILZERO
: return iLZeroW
;
549 case LOCALE_IMEASURE
: return iMeasureW
;
550 case LOCALE_INEGCURR
: return iNegCurrW
;
551 case LOCALE_INEGNUMBER
: return iNegNumberW
;
552 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
553 case LOCALE_ITIME
: return iTimeW
;
554 case LOCALE_S1159
: return s1159W
;
555 case LOCALE_S2359
: return s2359W
;
556 case LOCALE_SCURRENCY
: return sCurrencyW
;
557 case LOCALE_SDATE
: return sDateW
;
558 case LOCALE_SDECIMAL
: return sDecimalW
;
559 case LOCALE_SGROUPING
: return sGroupingW
;
560 case LOCALE_SLIST
: return sListW
;
561 case LOCALE_SLONGDATE
: return sLongDateW
;
562 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
563 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
564 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
565 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
566 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
567 case LOCALE_SSHORTDATE
: return sShortDateW
;
568 case LOCALE_STHOUSAND
: return sThousandW
;
569 case LOCALE_STIME
: return sTimeW
;
570 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
571 case LOCALE_SYEARMONTH
: return sYearMonthW
;
573 /* The following are not listed under MSDN as supported,
574 * but seem to be used and also stored in the registry.
576 case LOCALE_ICOUNTRY
: return iCountryW
;
577 case LOCALE_IDATE
: return iDateW
;
578 case LOCALE_ILDATE
: return iLDateW
;
579 case LOCALE_ITLZERO
: return iTLZeroW
;
580 case LOCALE_SCOUNTRY
: return sCountryW
;
581 case LOCALE_SABBREVLANGNAME
: return sLanguageW
;
583 /* The following are used in XP and later */
584 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
585 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
586 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
592 /******************************************************************************
593 * get_registry_locale_info
595 * Retrieve user-modified locale info from the registry.
596 * Return length, 0 on error, -1 if not found.
598 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
604 UNICODE_STRING nameW
;
605 KEY_VALUE_PARTIAL_INFORMATION
*info
;
606 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
608 if (!(hkey
= create_registry_key())) return -1;
610 RtlInitUnicodeString( &nameW
, value
);
611 size
= info_size
+ len
* sizeof(WCHAR
);
613 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
616 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
620 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
624 ret
= (size
- info_size
) / sizeof(WCHAR
);
625 /* append terminating null if needed */
626 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
628 if (ret
< len
|| !buffer
) ret
++;
631 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
637 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
641 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
643 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
645 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
651 SetLastError( RtlNtStatusToDosError(status
) );
655 HeapFree( GetProcessHeap(), 0, info
);
660 /******************************************************************************
661 * GetLocaleInfoA (KERNEL32.@)
663 * Get information about an aspect of a locale.
666 * lcid [I] LCID of the locale
667 * lctype [I] LCTYPE_ flags from "winnls.h"
668 * buffer [O] Destination for the information
669 * len [I] Length of buffer in characters
672 * Success: The size of the data requested. If buffer is non-NULL, it is filled
673 * with the information.
674 * Failure: 0. Use GetLastError() to determine the cause.
677 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
678 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
679 * which is a bit string.
681 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
686 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
688 if (len
< 0 || (len
&& !buffer
))
690 SetLastError( ERROR_INVALID_PARAMETER
);
693 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
)
695 SetLastError( ERROR_INVALID_FLAGS
);
699 if (!len
) buffer
= NULL
;
701 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
703 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
705 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
708 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
710 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
711 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
713 /* it's not an ASCII string, just bytes */
714 ret
*= sizeof(WCHAR
);
717 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
720 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
727 UINT codepage
= CP_ACP
;
728 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
729 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
732 HeapFree( GetProcessHeap(), 0, bufferW
);
736 static int get_value_base_by_lctype( LCTYPE lctype
)
738 return lctype
== LOCALE_ILANGUAGE
|| lctype
== LOCALE_IDEFAULTLANGUAGE
? 16 : 10;
741 /******************************************************************************
742 * GetLocaleInfoW (KERNEL32.@)
744 * See GetLocaleInfoA.
746 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
756 if (len
< 0 || (len
&& !buffer
))
758 SetLastError( ERROR_INVALID_PARAMETER
);
761 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&&
762 !is_genitive_name_supported( lctype
))
764 SetLastError( ERROR_INVALID_FLAGS
);
768 if (!len
) buffer
= NULL
;
770 lcid
= convert_default_lcid( lcid
, lctype
);
772 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
775 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
777 /* first check for overrides in the registry */
779 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
780 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
782 const WCHAR
*value
= get_locale_value_name(lctype
);
786 if (lcflags
& LOCALE_RETURN_NUMBER
)
789 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
793 UINT number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
794 if (*end
) /* invalid number */
796 SetLastError( ERROR_INVALID_FLAGS
);
799 ret
= sizeof(UINT
)/sizeof(WCHAR
);
800 if (!buffer
) return ret
;
803 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
806 memcpy( buffer
, &number
, sizeof(number
) );
809 else ret
= get_registry_locale_info( value
, buffer
, len
);
811 if (ret
!= -1) return ret
;
815 /* now load it from kernel resources */
817 lang_id
= LANGIDFROMLCID( lcid
);
819 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
820 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
821 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
823 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
824 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
826 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
829 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
832 p
= LockResource( hmem
);
833 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
835 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
836 else if (is_genitive_name_supported( lctype
) && *p
)
838 /* genitive form's stored after a null separator from a nominative */
839 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
841 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
849 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
851 if (!buffer
) return ret
;
855 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
859 if (lcflags
& LOCALE_RETURN_NUMBER
)
862 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
864 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
866 number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
868 memcpy( buffer
, &number
, sizeof(number
) );
869 else /* invalid number */
871 SetLastError( ERROR_INVALID_FLAGS
);
874 HeapFree( GetProcessHeap(), 0, tmp
);
876 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
877 lcid
, lctype
, buffer
, len
, number
);
881 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
882 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
884 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
885 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
891 /******************************************************************************
892 * SetLocaleInfoA [KERNEL32.@]
894 * Set information about an aspect of a locale.
897 * lcid [I] LCID of the locale
898 * lctype [I] LCTYPE_ flags from "winnls.h"
899 * data [I] Information to set
902 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
903 * whenever it is called without LOCALE_NOUSEROVERRIDE.
904 * Failure: FALSE. Use GetLastError() to determine the cause.
907 * - Values are only be set for the current user locale; the system locale
908 * settings cannot be changed.
909 * - Any settings changed by this call are lost when the locale is changed by
910 * the control panel (in Wine, this happens every time you change LANG).
911 * - The native implementation of this function does not check that lcid matches
912 * the current user locale, and simply sets the new values. Wine warns you in
913 * this case, but behaves the same.
915 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
917 UINT codepage
= CP_ACP
;
922 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
926 SetLastError( ERROR_INVALID_PARAMETER
);
929 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
930 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
932 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
935 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
936 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
937 HeapFree( GetProcessHeap(), 0, strW
);
942 /******************************************************************************
943 * SetLocaleInfoW (KERNEL32.@)
945 * See SetLocaleInfoA.
947 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
950 static const WCHAR intlW
[] = {'i','n','t','l',0 };
951 UNICODE_STRING valueW
;
956 value
= get_locale_value_name( lctype
);
960 SetLastError( ERROR_INVALID_PARAMETER
);
964 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
966 SetLastError( ERROR_INVALID_FLAGS
);
970 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
972 /* FIXME: should check that data to set is sane */
974 /* FIXME: profile functions should map to registry */
975 WriteProfileStringW( intlW
, value
, data
);
977 if (!(hkey
= create_registry_key())) return FALSE
;
978 RtlInitUnicodeString( &valueW
, value
);
979 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, (PVOID
)data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
981 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
983 /* Set I-value from S value */
984 WCHAR
*lpD
, *lpM
, *lpY
;
987 lpD
= strrchrW(data
, 'd');
988 lpM
= strrchrW(data
, 'M');
989 lpY
= strrchrW(data
, 'y');
993 szBuff
[0] = '1'; /* D-M-Y */
998 szBuff
[0] = '2'; /* Y-M-D */
1000 szBuff
[0] = '0'; /* M-D-Y */
1005 if (lctype
== LOCALE_SSHORTDATE
)
1006 lctype
= LOCALE_IDATE
;
1008 lctype
= LOCALE_ILDATE
;
1010 value
= get_locale_value_name( lctype
);
1012 WriteProfileStringW( intlW
, value
, szBuff
);
1014 RtlInitUnicodeString( &valueW
, value
);
1015 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1020 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1024 /***********************************************************************
1025 * GetThreadLocale (KERNEL32.@)
1027 * Get the current threads locale.
1033 * The LCID currently associated with the calling thread.
1035 LCID WINAPI
GetThreadLocale(void)
1037 LCID ret
= NtCurrentTeb()->CurrentLocale
;
1038 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
1042 /**********************************************************************
1043 * SetThreadLocale (KERNEL32.@)
1045 * Set the current threads locale.
1048 * lcid [I] LCID of the locale to set
1051 * Success: TRUE. The threads locale is set to lcid.
1052 * Failure: FALSE. Use GetLastError() to determine the cause.
1054 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1056 TRACE("(0x%04X)\n", lcid
);
1058 lcid
= ConvertDefaultLocale(lcid
);
1060 if (lcid
!= GetThreadLocale())
1062 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1064 SetLastError(ERROR_INVALID_PARAMETER
);
1068 NtCurrentTeb()->CurrentLocale
= lcid
;
1073 /******************************************************************************
1074 * ConvertDefaultLocale (KERNEL32.@)
1076 * Convert a default locale identifier into a real identifier.
1079 * lcid [I] LCID identifier of the locale to convert
1082 * lcid unchanged, if not a default locale or its sublanguage is
1083 * not SUBLANG_NEUTRAL.
1084 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1085 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1086 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1088 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
1094 case LOCALE_SYSTEM_DEFAULT
:
1095 lcid
= GetSystemDefaultLCID();
1097 case LOCALE_USER_DEFAULT
:
1098 case LOCALE_NEUTRAL
:
1099 lcid
= GetUserDefaultLCID();
1102 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1103 langid
= LANGIDFROMLCID(lcid
);
1104 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
1106 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
1107 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
1114 /******************************************************************************
1115 * IsValidLocale (KERNEL32.@)
1117 * Determine if a locale is valid.
1120 * lcid [I] LCID of the locale to check
1121 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1124 * TRUE, if lcid is valid,
1128 * Wine does not currently make the distinction between supported and installed. All
1129 * languages supported are installed by default.
1131 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
1133 /* check if language is registered in the kernel32 resources */
1134 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1135 (LPCWSTR
)LOCALE_ILANGUAGE
, LANGIDFROMLCID(lcid
)) != 0;
1139 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
1140 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
1142 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
1145 sprintf(buf
, "%08x", (UINT
)LangID
);
1146 return lpfnLocaleEnum( buf
);
1149 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
1150 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
1152 static const WCHAR formatW
[] = {'%','0','8','x',0};
1153 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
1155 sprintfW( buf
, formatW
, (UINT
)LangID
);
1156 return lpfnLocaleEnum( buf
);
1159 /******************************************************************************
1160 * EnumSystemLocalesA (KERNEL32.@)
1162 * Call a users function for each locale available on the system.
1165 * lpfnLocaleEnum [I] Callback function to call for each locale
1166 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1170 * Failure: FALSE. Use GetLastError() to determine the cause.
1172 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
1174 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
1175 EnumResourceLanguagesA( kernel32_handle
, (LPSTR
)RT_STRING
,
1176 (LPCSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_a
,
1177 (LONG_PTR
)lpfnLocaleEnum
);
1182 /******************************************************************************
1183 * EnumSystemLocalesW (KERNEL32.@)
1185 * See EnumSystemLocalesA.
1187 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
1189 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
1190 EnumResourceLanguagesW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1191 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_w
,
1192 (LONG_PTR
)lpfnLocaleEnum
);
1196 /***********************************************************************
1197 * VerLanguageNameA (KERNEL32.@)
1199 * Get the name of a language.
1202 * wLang [I] LANGID of the language
1203 * szLang [O] Destination for the language name
1206 * Success: The size of the language name. If szLang is non-NULL, it is filled
1208 * Failure: 0. Use GetLastError() to determine the cause.
1211 DWORD WINAPI
VerLanguageNameA( DWORD wLang
, LPSTR szLang
, DWORD nSize
)
1213 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1217 /***********************************************************************
1218 * VerLanguageNameW (KERNEL32.@)
1220 * See VerLanguageNameA.
1222 DWORD WINAPI
VerLanguageNameW( DWORD wLang
, LPWSTR szLang
, DWORD nSize
)
1224 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1227 /******************************************************************************
1228 * GetStringTypeW (KERNEL32.@)
1230 * See GetStringTypeA.
1232 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1234 static const unsigned char type2_map
[16] =
1236 C2_NOTAPPLICABLE
, /* unassigned */
1237 C2_LEFTTORIGHT
, /* L */
1238 C2_RIGHTTOLEFT
, /* R */
1239 C2_EUROPENUMBER
, /* EN */
1240 C2_EUROPESEPARATOR
, /* ES */
1241 C2_EUROPETERMINATOR
, /* ET */
1242 C2_ARABICNUMBER
, /* AN */
1243 C2_COMMONSEPARATOR
, /* CS */
1244 C2_BLOCKSEPARATOR
, /* B */
1245 C2_SEGMENTSEPARATOR
, /* S */
1246 C2_WHITESPACE
, /* WS */
1247 C2_OTHERNEUTRAL
, /* ON */
1248 C2_RIGHTTOLEFT
, /* AL */
1249 C2_NOTAPPLICABLE
, /* NSM */
1250 C2_NOTAPPLICABLE
, /* BN */
1251 C2_OTHERNEUTRAL
/* LRE, LRO, RLE, RLO, PDF */
1254 if (count
== -1) count
= strlenW(src
) + 1;
1258 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
1261 while (count
--) *chartype
++ = type2_map
[get_char_typeW( *src
++ ) >> 12];
1265 WARN("CT_CTYPE3: semi-stub.\n");
1269 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
1271 type1
= get_char_typeW( *src
++ ) & 0xfff;
1272 /* try to construct type3 from type1 */
1273 if(type1
& C1_SPACE
) type3
|= C3_SYMBOL
;
1274 if(type1
& C1_ALPHA
) type3
|= C3_ALPHA
;
1275 if ((c
>=0x30A0)&&(c
<=0x30FF)) type3
|= C3_KATAKANA
;
1276 if ((c
>=0x3040)&&(c
<=0x309F)) type3
|= C3_HIRAGANA
;
1277 if ((c
>=0x4E00)&&(c
<=0x9FAF)) type3
|= C3_IDEOGRAPH
;
1278 if ((c
>=0x0600)&&(c
<=0x06FF)) type3
|= C3_KASHIDA
;
1279 if ((c
>=0x3000)&&(c
<=0x303F)) type3
|= C3_SYMBOL
;
1281 if ((c
>=0xFF00)&&(c
<=0xFF60)) type3
|= C3_FULLWIDTH
;
1282 if ((c
>=0xFF00)&&(c
<=0xFF20)) type3
|= C3_SYMBOL
;
1283 if ((c
>=0xFF3B)&&(c
<=0xFF40)) type3
|= C3_SYMBOL
;
1284 if ((c
>=0xFF5B)&&(c
<=0xFF60)) type3
|= C3_SYMBOL
;
1285 if ((c
>=0xFF21)&&(c
<=0xFF3A)) type3
|= C3_ALPHA
;
1286 if ((c
>=0xFF41)&&(c
<=0xFF5A)) type3
|= C3_ALPHA
;
1287 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_FULLWIDTH
;
1288 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_SYMBOL
;
1290 if ((c
>=0xFF61)&&(c
<=0xFFDC)) type3
|= C3_HALFWIDTH
;
1291 if ((c
>=0xFF61)&&(c
<=0xFF64)) type3
|= C3_SYMBOL
;
1292 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_KATAKANA
;
1293 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_ALPHA
;
1294 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_HALFWIDTH
;
1295 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_SYMBOL
;
1296 *chartype
++ = type3
;
1301 SetLastError( ERROR_INVALID_PARAMETER
);
1308 /******************************************************************************
1309 * GetStringTypeExW (KERNEL32.@)
1311 * See GetStringTypeExA.
1313 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1315 /* locale is ignored for Unicode */
1316 return GetStringTypeW( type
, src
, count
, chartype
);
1320 /******************************************************************************
1321 * GetStringTypeA (KERNEL32.@)
1323 * Get characteristics of the characters making up a string.
1326 * locale [I] Locale Id for the string
1327 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1328 * src [I] String to analyse
1329 * count [I] Length of src in chars, or -1 if src is NUL terminated
1330 * chartype [O] Destination for the calculated characteristics
1333 * Success: TRUE. chartype is filled with the requested characteristics of each char
1335 * Failure: FALSE. Use GetLastError() to determine the cause.
1337 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1344 if(count
== -1) count
= strlen(src
) + 1;
1346 if (!(cp
= get_lcid_codepage( locale
)))
1348 FIXME("For locale %04x using current ANSI code page\n", locale
);
1352 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
1353 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
1355 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
1357 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1358 * string, with multibyte characters there maybe be more bytes in count
1359 * than character space in the buffer!
1361 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
1362 HeapFree(GetProcessHeap(), 0, srcW
);
1367 /******************************************************************************
1368 * GetStringTypeExA (KERNEL32.@)
1370 * Get characteristics of the characters making up a string.
1373 * locale [I] Locale Id for the string
1374 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1375 * src [I] String to analyse
1376 * count [I] Length of src in chars, or -1 if src is NUL terminated
1377 * chartype [O] Destination for the calculated characteristics
1380 * Success: TRUE. chartype is filled with the requested characteristics of each char
1382 * Failure: FALSE. Use GetLastError() to determine the cause.
1384 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1386 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
1390 /*************************************************************************
1391 * LCMapStringW (KERNEL32.@)
1395 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
1396 LPWSTR dst
, INT dstlen
)
1400 if (!src
|| !srclen
|| dstlen
< 0)
1402 SetLastError(ERROR_INVALID_PARAMETER
);
1406 /* mutually exclusive flags */
1407 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
1408 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
1409 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
1410 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
))
1412 SetLastError(ERROR_INVALID_FLAGS
);
1416 if (!dstlen
) dst
= NULL
;
1418 lcid
= ConvertDefaultLocale(lcid
);
1420 if (flags
& LCMAP_SORTKEY
)
1425 SetLastError(ERROR_INVALID_FLAGS
);
1429 if (srclen
< 0) srclen
= strlenW(src
);
1431 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1432 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1434 ret
= wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
1436 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1442 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1443 if (flags
& SORT_STRINGSORT
)
1445 SetLastError(ERROR_INVALID_FLAGS
);
1449 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1451 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1452 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1454 if (!dst
) /* return required string length */
1458 for (len
= 0; srclen
; src
++, srclen
--)
1461 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1462 * and skips white space and punctuation characters for
1463 * NORM_IGNORESYMBOLS.
1465 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1472 if (flags
& LCMAP_UPPERCASE
)
1474 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1477 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1479 *dst_ptr
++ = toupperW(wch
);
1483 else if (flags
& LCMAP_LOWERCASE
)
1485 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1488 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1490 *dst_ptr
++ = tolowerW(wch
);
1498 SetLastError(ERROR_INVALID_FLAGS
);
1501 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1504 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1513 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1517 return dst_ptr
- dst
;
1520 /*************************************************************************
1521 * LCMapStringA (KERNEL32.@)
1523 * Map characters in a locale sensitive string.
1526 * lcid [I] LCID for the conversion.
1527 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1528 * src [I] String to map
1529 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1530 * dst [O] Destination for mapped string
1531 * dstlen [I] Length of dst in characters
1534 * Success: The length of the mapped string in dst, including the NUL terminator.
1535 * Failure: 0. Use GetLastError() to determine the cause.
1537 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
1538 LPSTR dst
, INT dstlen
)
1540 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
1542 INT ret
= 0, srclenW
, dstlenW
;
1543 UINT locale_cp
= CP_ACP
;
1545 if (!src
|| !srclen
|| dstlen
< 0)
1547 SetLastError(ERROR_INVALID_PARAMETER
);
1551 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1553 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
1558 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
1559 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1562 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1565 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
1568 if (flags
& LCMAP_SORTKEY
)
1572 SetLastError(ERROR_INVALID_FLAGS
);
1573 goto map_string_exit
;
1575 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
1577 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1580 goto map_string_exit
;
1583 if (flags
& SORT_STRINGSORT
)
1585 SetLastError(ERROR_INVALID_FLAGS
);
1586 goto map_string_exit
;
1589 dstlenW
= LCMapStringW(lcid
, flags
, srcW
, srclenW
, NULL
, 0);
1591 goto map_string_exit
;
1593 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
1596 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1597 goto map_string_exit
;
1600 LCMapStringW(lcid
, flags
, srcW
, srclenW
, dstW
, dstlenW
);
1601 ret
= WideCharToMultiByte(locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
1602 HeapFree(GetProcessHeap(), 0, dstW
);
1605 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
1609 /*************************************************************************
1610 * FoldStringA (KERNEL32.@)
1612 * Map characters in a string.
1615 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1616 * src [I] String to map
1617 * srclen [I] Length of src, or -1 if src is NUL terminated
1618 * dst [O] Destination for mapped string
1619 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1622 * Success: The length of the string written to dst, including the terminating NUL. If
1623 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1624 * and dst may be NULL.
1625 * Failure: 0. Use GetLastError() to determine the cause.
1627 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
1628 LPSTR dst
, INT dstlen
)
1630 INT ret
= 0, srclenW
= 0;
1631 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
1633 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1635 SetLastError(ERROR_INVALID_PARAMETER
);
1639 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1640 src
, srclen
, NULL
, 0);
1641 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1645 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1646 goto FoldStringA_exit
;
1649 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1650 src
, srclen
, srcW
, srclenW
);
1652 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
1654 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
1657 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
1661 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1662 goto FoldStringA_exit
;
1665 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
1666 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
1669 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1673 HeapFree(GetProcessHeap(), 0, dstW
);
1676 HeapFree(GetProcessHeap(), 0, srcW
);
1680 /*************************************************************************
1681 * FoldStringW (KERNEL32.@)
1685 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
1686 LPWSTR dst
, INT dstlen
)
1690 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
1695 /* Fall through for dwFlags == 0 */
1696 case MAP_PRECOMPOSED
|MAP_COMPOSITE
:
1697 case MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
:
1698 case MAP_COMPOSITE
|MAP_EXPAND_LIGATURES
:
1699 SetLastError(ERROR_INVALID_FLAGS
);
1703 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1705 SetLastError(ERROR_INVALID_PARAMETER
);
1709 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
1711 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1715 /******************************************************************************
1716 * CompareStringW (KERNEL32.@)
1718 * See CompareStringA.
1720 INT WINAPI
CompareStringW(LCID lcid
, DWORD style
,
1721 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
1727 SetLastError(ERROR_INVALID_PARAMETER
);
1731 if( style
& ~(NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
|
1732 SORT_STRINGSORT
|NORM_IGNOREKANATYPE
|NORM_IGNOREWIDTH
|LOCALE_USE_CP_ACP
|0x10000000) )
1734 SetLastError(ERROR_INVALID_FLAGS
);
1738 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
1739 if (style
& 0x10000000)
1740 WARN("Ignoring unknown style 0x10000000\n");
1742 if (len1
< 0) len1
= strlenW(str1
);
1743 if (len2
< 0) len2
= strlenW(str2
);
1745 ret
= wine_compare_string(style
, str1
, len1
, str2
, len2
);
1747 if (ret
) /* need to translate result */
1748 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
1752 /******************************************************************************
1753 * CompareStringA (KERNEL32.@)
1755 * Compare two locale sensitive strings.
1758 * lcid [I] LCID for the comparison
1759 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
1760 * str1 [I] First string to compare
1761 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1762 * str2 [I] Second string to compare
1763 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1766 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1767 * str1 is less than, equal to or greater than str2 respectively.
1768 * Failure: FALSE. Use GetLastError() to determine the cause.
1770 INT WINAPI
CompareStringA(LCID lcid
, DWORD flags
,
1771 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
1773 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
1774 WCHAR
*buf2W
= buf1W
+ 130;
1775 LPWSTR str1W
, str2W
;
1776 INT len1W
= 0, len2W
= 0, ret
;
1777 UINT locale_cp
= CP_ACP
;
1781 SetLastError(ERROR_INVALID_PARAMETER
);
1784 if (len1
< 0) len1
= strlen(str1
);
1785 if (len2
< 0) len2
= strlen(str2
);
1787 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1791 if (len1
<= 130) len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
1796 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
1797 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
1800 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1803 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
1814 if (len2
<= 130) len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
1819 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
1820 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
1823 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1824 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1827 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
1836 ret
= CompareStringW(lcid
, flags
, str1W
, len1W
, str2W
, len2W
);
1838 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1839 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
1843 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
1845 UNICODE_STRING keyName
;
1846 OBJECT_ATTRIBUTES attr
;
1849 RtlInitUnicodeString( &keyName
, szKeyName
);
1850 InitializeObjectAttributes(&attr
, &keyName
, OBJ_CASE_INSENSITIVE
, hRootKey
, NULL
);
1852 if (NtOpenKey( &hkey
, KEY_READ
, &attr
) != STATUS_SUCCESS
)
1858 static BOOL
NLS_RegEnumSubKey(HANDLE hKey
, UINT ulIndex
, LPWSTR szKeyName
,
1862 KEY_BASIC_INFORMATION
*info
= (KEY_BASIC_INFORMATION
*)buffer
;
1865 if (NtEnumerateKey( hKey
, ulIndex
, KeyBasicInformation
, buffer
,
1866 sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
1867 info
->NameLength
> keyNameSize
)
1872 TRACE("info->Name %s info->NameLength %d\n", debugstr_w(info
->Name
), info
->NameLength
);
1874 memcpy( szKeyName
, info
->Name
, info
->NameLength
);
1875 szKeyName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
1877 TRACE("returning %s\n", debugstr_w(szKeyName
));
1881 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
1882 LPWSTR szValueName
, ULONG valueNameSize
,
1883 LPWSTR szValueData
, ULONG valueDataSize
)
1886 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
1889 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
1890 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
1891 info
->NameLength
> valueNameSize
||
1892 info
->DataLength
> valueDataSize
)
1897 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
1899 memcpy( szValueName
, info
->Name
, info
->NameLength
);
1900 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
1901 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
1902 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
1904 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
1908 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
1911 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
1912 DWORD dwSize
= sizeof(buffer
);
1913 UNICODE_STRING valueName
;
1915 RtlInitUnicodeString( &valueName
, szValueName
);
1917 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
1918 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
1919 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
1920 info
->DataLength
== sizeof(DWORD
))
1922 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
1929 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
1932 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
1936 /* FIXME: Is it correct to use the system default langid? */
1937 langId
= GetSystemDefaultLangID();
1939 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
1940 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
1942 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
1946 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
1950 ULONG iResourceIndex
= lgrpid
& 0xf;
1951 LPCWSTR lpResEntry
= LockResource( hResDir
);
1954 for (i
= 0; i
< iResourceIndex
; i
++)
1955 lpResEntry
+= *lpResEntry
+ 1;
1957 if (*lpResEntry
< nameSize
)
1959 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
1960 szName
[*lpResEntry
] = '\0';
1965 FreeResource( hResource
);
1970 /* Registry keys for NLS related information */
1972 static const WCHAR szCountryListName
[] = {
1973 '\\','R','e','g','i','s','t','r','y','\\',
1974 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
1975 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1976 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1977 'T','e','l','e','p','h','o','n','y','\\',
1978 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
1982 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1985 LANGUAGEGROUP_ENUMPROCA procA
;
1986 LANGUAGEGROUP_ENUMPROCW procW
;
1989 } ENUMLANGUAGEGROUP_CALLBACKS
;
1991 /* Internal implementation of EnumSystemLanguageGroupsA/W */
1992 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
1994 WCHAR szNumber
[10], szValue
[4];
1996 BOOL bContinue
= TRUE
;
2001 SetLastError(ERROR_INVALID_PARAMETER
);
2005 switch (lpProcs
->dwFlags
)
2008 /* Default to LGRPID_INSTALLED */
2009 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
2010 /* Fall through... */
2011 case LGRPID_INSTALLED
:
2012 case LGRPID_SUPPORTED
:
2015 SetLastError(ERROR_INVALID_FLAGS
);
2019 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2022 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2026 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2027 szValue
, sizeof(szValue
) ))
2029 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
2030 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
2032 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
2033 bInstalled
? "" : "not ");
2035 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
2037 WCHAR szGrpName
[48];
2039 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
2040 szGrpName
[0] = '\0';
2043 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
2047 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2048 char szGrpNameA
[48];
2050 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2051 * or whether the language names are ever localised. Assume CP_ACP.
2054 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2055 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
2057 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
2077 /******************************************************************************
2078 * EnumSystemLanguageGroupsA (KERNEL32.@)
2080 * Call a users function for each language group available on the system.
2083 * pLangGrpEnumProc [I] Callback function to call for each language group
2084 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2085 * lParam [I] User parameter to pass to pLangGrpEnumProc
2089 * Failure: FALSE. Use GetLastError() to determine the cause.
2091 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
2092 DWORD dwFlags
, LONG_PTR lParam
)
2094 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2096 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2098 procs
.procA
= pLangGrpEnumProc
;
2100 procs
.dwFlags
= dwFlags
;
2101 procs
.lParam
= lParam
;
2103 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2106 /******************************************************************************
2107 * EnumSystemLanguageGroupsW (KERNEL32.@)
2109 * See EnumSystemLanguageGroupsA.
2111 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
2112 DWORD dwFlags
, LONG_PTR lParam
)
2114 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2116 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2119 procs
.procW
= pLangGrpEnumProc
;
2120 procs
.dwFlags
= dwFlags
;
2121 procs
.lParam
= lParam
;
2123 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2126 /******************************************************************************
2127 * IsValidLanguageGroup (KERNEL32.@)
2129 * Determine if a language group is supported and/or installed.
2132 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2133 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2136 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2139 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
2141 static const WCHAR szFormat
[] = { '%','x','\0' };
2142 WCHAR szValueName
[16], szValue
[2];
2143 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
2149 case LGRPID_INSTALLED
:
2150 case LGRPID_SUPPORTED
:
2152 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2154 sprintfW( szValueName
, szFormat
, lgrpid
);
2156 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)szValue
))
2160 if (szValue
[0] == '1')
2170 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
2171 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
2177 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2180 LANGGROUPLOCALE_ENUMPROCA procA
;
2181 LANGGROUPLOCALE_ENUMPROCW procW
;
2185 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
2187 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2188 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
2190 static const WCHAR szAlternateSortsKeyName
[] = {
2191 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2193 WCHAR szNumber
[10], szValue
[4];
2195 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
2197 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
2199 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
2201 SetLastError(ERROR_INVALID_PARAMETER
);
2205 if (lpProcs
->dwFlags
)
2207 SetLastError(ERROR_INVALID_FLAGS
);
2211 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
2214 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2218 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2219 szValue
, sizeof(szValue
) ))
2221 lgrpid
= strtoulW( szValue
, NULL
, 16 );
2223 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
2224 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
2226 if (lgrpid
== lpProcs
->lgrpid
)
2230 lcid
= strtoulW( szNumber
, NULL
, 16 );
2232 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2233 * '00000437 ;Georgian'
2234 * At present we only pass the LCID string.
2238 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
2241 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2243 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2245 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
2253 /* Finished enumerating this key */
2256 /* Enumerate alternate sorts also */
2257 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
2262 bContinue
= FALSE
; /* Finished both keys */
2275 /******************************************************************************
2276 * EnumLanguageGroupLocalesA (KERNEL32.@)
2278 * Call a users function for every locale in a language group available on the system.
2281 * pLangGrpLcEnumProc [I] Callback function to call for each locale
2282 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
2283 * dwFlags [I] Reserved, set to 0
2284 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
2288 * Failure: FALSE. Use GetLastError() to determine the cause.
2290 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
2291 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2293 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2295 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2297 callbacks
.procA
= pLangGrpLcEnumProc
;
2298 callbacks
.procW
= NULL
;
2299 callbacks
.dwFlags
= dwFlags
;
2300 callbacks
.lgrpid
= lgrpid
;
2301 callbacks
.lParam
= lParam
;
2303 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2306 /******************************************************************************
2307 * EnumLanguageGroupLocalesW (KERNEL32.@)
2309 * See EnumLanguageGroupLocalesA.
2311 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
2312 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2314 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2316 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2318 callbacks
.procA
= NULL
;
2319 callbacks
.procW
= pLangGrpLcEnumProc
;
2320 callbacks
.dwFlags
= dwFlags
;
2321 callbacks
.lgrpid
= lgrpid
;
2322 callbacks
.lParam
= lParam
;
2324 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2327 /* Callback function ptrs for EnumSystemCodePagesA/W */
2330 CODEPAGE_ENUMPROCA procA
;
2331 CODEPAGE_ENUMPROCW procW
;
2333 } ENUMSYSTEMCODEPAGES_CALLBACKS
;
2335 /* Internal implementation of EnumSystemCodePagesA/W */
2336 static BOOL
NLS_EnumSystemCodePages(ENUMSYSTEMCODEPAGES_CALLBACKS
*lpProcs
)
2338 WCHAR szNumber
[5 + 1], szValue
[MAX_PATH
];
2340 BOOL bContinue
= TRUE
;
2345 SetLastError(ERROR_INVALID_PARAMETER
);
2349 switch (lpProcs
->dwFlags
)
2355 SetLastError(ERROR_INVALID_FLAGS
);
2359 hKey
= NLS_RegOpenKey(0, L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
2362 WARN("NLS_RegOpenKey() failed\n");
2368 if (NLS_RegEnumValue(hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2369 szValue
, sizeof(szValue
)))
2371 if ((lpProcs
->dwFlags
== CP_SUPPORTED
)||
2372 ((lpProcs
->dwFlags
== CP_INSTALLED
)&&(wcslen(szValue
) > 2)))
2376 bContinue
= lpProcs
->procW(szNumber
);
2380 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2382 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2383 bContinue
= lpProcs
->procA(szNumberA
);
2389 } else bContinue
= FALSE
;
2406 EnumSystemCodePagesW (
2407 CODEPAGE_ENUMPROCW lpCodePageEnumProc
,
2411 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2413 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2416 procs
.procW
= lpCodePageEnumProc
;
2417 procs
.dwFlags
= dwFlags
;
2419 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2428 EnumSystemCodePagesA (
2429 CODEPAGE_ENUMPROCA lpCodePageEnumProc
,
2433 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2435 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2437 procs
.procA
= lpCodePageEnumProc
;
2439 procs
.dwFlags
= dwFlags
;
2441 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2443 /******************************************************************************
2444 * EnumSystemGeoID (KERNEL32.@)
2446 * Call a users function for every location available on the system.
2449 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
2450 * reserved [I] Reserved, set to 0
2451 * pGeoEnumProc [I] Callback function to call for each location
2455 * Failure: FALSE. Use GetLastError() to determine the cause.
2457 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID reserved
, GEO_ENUMPROC pGeoEnumProc
)
2459 static const WCHAR szCountryCodeValueName
[] = {
2460 'C','o','u','n','t','r','y','C','o','d','e','\0'
2466 TRACE("(0x%08X,0x%08X,%p)\n", geoclass
, reserved
, pGeoEnumProc
);
2468 if (geoclass
!= GEOCLASS_NATION
|| reserved
|| !pGeoEnumProc
)
2470 SetLastError(ERROR_INVALID_PARAMETER
);
2474 hKey
= NLS_RegOpenKey( 0, szCountryListName
);
2476 while (NLS_RegEnumSubKey( hKey
, ulIndex
, szNumber
, sizeof(szNumber
) ))
2478 BOOL bContinue
= TRUE
;
2480 HANDLE hSubKey
= NLS_RegOpenKey( hKey
, szNumber
);
2484 if (NLS_RegGetDword( hSubKey
, szCountryCodeValueName
, &dwGeoId
))
2486 TRACE("Got geoid %d\n", dwGeoId
);
2488 if (!pGeoEnumProc( dwGeoId
))
2507 /******************************************************************************
2508 * InvalidateNLSCache (KERNEL32.@)
2510 * Invalidate the cache of NLS values.
2519 BOOL WINAPI
InvalidateNLSCache(void)
2525 /******************************************************************************
2526 * GetUserGeoID (KERNEL32.@)
2528 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
2530 GEOID ret
= GEOID_NOT_AVAILABLE
;
2531 static const WCHAR geoW
[] = {'G','e','o',0};
2532 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
2533 WCHAR bufferW
[40], *end
;
2535 HANDLE hkey
, hSubkey
= 0;
2536 UNICODE_STRING keyW
;
2537 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
2538 RtlInitUnicodeString( &keyW
, nationW
);
2539 count
= sizeof(bufferW
);
2541 if(!(hkey
= create_registry_key())) return ret
;
2544 case GEOCLASS_NATION
:
2545 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
2547 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
2548 bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
2549 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
2552 case GEOCLASS_REGION
:
2553 FIXME("GEOCLASS_REGION not handled yet\n");
2558 if (hSubkey
) NtClose(hSubkey
);
2562 /******************************************************************************
2563 * SetUserGeoID (KERNEL32.@)
2565 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
2567 static const WCHAR geoW
[] = {'G','e','o',0};
2568 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
2569 static const WCHAR formatW
[] = {'%','i',0};
2570 UNICODE_STRING nameW
,keyW
;
2572 OBJECT_ATTRIBUTES attr
;
2575 if(!(hkey
= create_registry_key())) return FALSE
;
2577 attr
.Length
= sizeof(attr
);
2578 attr
.RootDirectory
= hkey
;
2579 attr
.ObjectName
= &nameW
;
2580 attr
.Attributes
= 0;
2581 attr
.SecurityDescriptor
= NULL
;
2582 attr
.SecurityQualityOfService
= NULL
;
2583 RtlInitUnicodeString( &nameW
, geoW
);
2584 RtlInitUnicodeString( &keyW
, nationW
);
2586 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
2589 NtClose(attr
.RootDirectory
);
2593 sprintfW(bufferW
, formatW
, GeoID
);
2594 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
2595 NtClose(attr
.RootDirectory
);
2604 UILANGUAGE_ENUMPROCA procA
;
2605 UILANGUAGE_ENUMPROCW procW
;
2609 } ENUM_UILANG_CALLBACK
;
2611 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
2612 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
2614 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2617 sprintf(buf
, "%08x", (UINT
)LangID
);
2618 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
2621 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
2622 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
2624 static const WCHAR formatW
[] = {'%','0','8','x',0};
2625 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2628 sprintfW( buf
, formatW
, (UINT
)LangID
);
2629 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
2632 /******************************************************************************
2633 * EnumUILanguagesA (KERNEL32.@)
2635 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2637 ENUM_UILANG_CALLBACK enum_uilang
;
2639 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2641 if(!pUILangEnumProc
) {
2642 SetLastError(ERROR_INVALID_PARAMETER
);
2646 SetLastError(ERROR_INVALID_FLAGS
);
2650 enum_uilang
.u
.procA
= pUILangEnumProc
;
2651 enum_uilang
.flags
= dwFlags
;
2652 enum_uilang
.param
= lParam
;
2654 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
2655 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
2656 (LONG_PTR
)&enum_uilang
);
2660 /******************************************************************************
2661 * EnumUILanguagesW (KERNEL32.@)
2663 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2665 ENUM_UILANG_CALLBACK enum_uilang
;
2667 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2670 if(!pUILangEnumProc
) {
2671 SetLastError(ERROR_INVALID_PARAMETER
);
2675 SetLastError(ERROR_INVALID_FLAGS
);
2679 enum_uilang
.u
.procW
= pUILangEnumProc
;
2680 enum_uilang
.flags
= dwFlags
;
2681 enum_uilang
.param
= lParam
;
2683 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
2684 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
2685 (LONG_PTR
)&enum_uilang
);
2690 NLS_GetGeoFriendlyName(GEOID Location
, LPWSTR szFriendlyName
, int cchData
)
2693 WCHAR szPath
[MAX_PATH
];
2694 UNICODE_STRING ValueName
;
2695 KEY_VALUE_PARTIAL_INFORMATION
*info
;
2696 const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
2701 swprintf(szPath
, L
"\\REGISTRY\\Machine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Country List\\%lu", Location
);
2703 hKey
= NLS_RegOpenKey(0, szPath
);
2706 WARN("NLS_RegOpenKey() failed\n");
2710 dwSize
= info_size
+ cchData
* sizeof(WCHAR
);
2712 if (!(info
= HeapAlloc(GetProcessHeap(), 0, dwSize
)))
2715 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2719 RtlInitUnicodeString(&ValueName
, L
"Name");
2721 Status
= NtQueryValueKey(hKey
, &ValueName
, KeyValuePartialInformation
,
2722 (LPBYTE
)info
, dwSize
, &dwSize
);
2726 Ret
= (dwSize
- info_size
) / sizeof(WCHAR
);
2728 if (!Ret
|| ((WCHAR
*)info
->Data
)[Ret
-1])
2730 if (Ret
< cchData
|| !szFriendlyName
) Ret
++;
2733 WARN("ERROR_INSUFFICIENT_BUFFER\n");
2734 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2739 if (Ret
&& szFriendlyName
)
2741 memcpy(szFriendlyName
, info
->Data
, (Ret
-1) * sizeof(WCHAR
));
2742 szFriendlyName
[Ret
-1] = 0;
2745 else if (Status
== STATUS_BUFFER_OVERFLOW
&& !szFriendlyName
)
2747 Ret
= (dwSize
- info_size
) / sizeof(WCHAR
) + 1;
2749 else if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
2755 SetLastError(RtlNtStatusToDosError(Status
));
2760 HeapFree(GetProcessHeap(), 0, info
);
2768 INT WINAPI
GetGeoInfoW(GEOID GeoId
, GEOTYPE GeoType
, LPWSTR lpGeoData
,
2769 int cchData
, LANGID LangId
)
2771 TRACE("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, LangId
);
2775 case GEO_FRIENDLYNAME
:
2777 return NLS_GetGeoFriendlyName(GeoId
, lpGeoData
, cchData
);
2787 case GEO_OFFICIALNAME
:
2788 case GEO_OFFICIALLANGUAGES
:
2789 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, LangId
);
2790 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2800 INT WINAPI
GetGeoInfoA(GEOID GeoId
, GEOTYPE GeoType
, LPSTR lpGeoData
,
2801 int cchData
, LANGID LangId
)
2803 WCHAR szBuffer
[MAX_PATH
];
2804 char szBufferA
[sizeof(szBuffer
)/sizeof(WCHAR
)];
2807 TRACE("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, LangId
);
2811 case GEO_FRIENDLYNAME
:
2813 Ret
= NLS_GetGeoFriendlyName(GeoId
, szBuffer
, cchData
);
2814 WideCharToMultiByte(CP_ACP
, 0, szBuffer
, -1, szBufferA
, sizeof(szBufferA
), 0, 0);
2815 strcpy(lpGeoData
, szBufferA
);
2826 case GEO_OFFICIALNAME
:
2827 case GEO_OFFICIALLANGUAGES
:
2828 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, LangId
);
2829 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);