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
);
36 extern DWORD
GetLocalisedText(DWORD dwResId
, WCHAR
*lpszDest
, DWORD dwDestSize
);
37 #define NLSRC_OFFSET 5000 /* FIXME */
39 extern HMODULE kernel32_handle
;
41 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
42 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
44 static const WCHAR szLocaleKeyName
[] = {
45 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
46 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
47 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
48 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
51 static const WCHAR szLangGroupsKeyName
[] = {
52 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
53 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
54 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
55 'C','o','n','t','r','o','l','\\','N','l','s','\\',
56 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
60 /* Charset to codepage map, sorted by name. */
61 static const struct charset_entry
63 const char *charset_name
;
102 { "ISO88591", 28591 },
103 { "ISO885910", 28600 },
104 { "ISO885913", 28603 },
105 { "ISO885914", 28604 },
106 { "ISO885915", 28605 },
107 { "ISO885916", 28606 },
108 { "ISO88592", 28592 },
109 { "ISO88593", 28593 },
110 { "ISO88594", 28594 },
111 { "ISO88595", 28595 },
112 { "ISO88596", 28596 },
113 { "ISO88597", 28597 },
114 { "ISO88598", 28598 },
115 { "ISO88599", 28599 },
124 WCHAR win_name
[128]; /* Windows name ("en-US") */
125 WCHAR lang
[128]; /* language ("en") (note: buffer contains the other strings too) */
126 WCHAR
*country
; /* country ("US") */
127 WCHAR
*charset
; /* charset ("UTF-8") for Unix format only */
128 WCHAR
*script
; /* script ("Latn") for Windows format only */
129 WCHAR
*modifier
; /* modifier or sort order */
130 LCID lcid
; /* corresponding LCID */
131 int matches
; /* number of elements matching LCID (0..4) */
132 UINT codepage
; /* codepage corresponding to charset */
135 /* locale ids corresponding to the various Unix locale parameters */
136 static LCID lcid_LC_COLLATE
;
137 static LCID lcid_LC_CTYPE
;
138 static LCID lcid_LC_MONETARY
;
139 static LCID lcid_LC_NUMERIC
;
140 static LCID lcid_LC_TIME
;
141 static LCID lcid_LC_PAPER
;
142 static LCID lcid_LC_MEASUREMENT
;
143 static LCID lcid_LC_TELEPHONE
;
146 /* Copy Ascii string to Unicode without using codepages */
147 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
149 while (n
> 1 && *src
)
151 *dst
++ = (unsigned char)*src
++;
158 /***********************************************************************
161 * Retrieve the ANSI codepage for a given locale.
163 static inline UINT
get_lcid_codepage( LCID lcid
)
166 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
167 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
171 /***********************************************************************
172 * convert_default_lcid
174 * Get the default LCID to use for a given lctype in GetLocaleInfo.
176 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
178 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
179 lcid
== LOCALE_USER_DEFAULT
||
180 lcid
== LOCALE_NEUTRAL
)
184 switch(lctype
& 0xffff)
186 case LOCALE_SSORTNAME
:
187 default_id
= lcid_LC_COLLATE
;
190 case LOCALE_FONTSIGNATURE
:
191 case LOCALE_IDEFAULTANSICODEPAGE
:
192 case LOCALE_IDEFAULTCODEPAGE
:
193 case LOCALE_IDEFAULTEBCDICCODEPAGE
:
194 case LOCALE_IDEFAULTMACCODEPAGE
:
195 case LOCALE_IDEFAULTUNIXCODEPAGE
:
196 default_id
= lcid_LC_CTYPE
;
199 case LOCALE_ICURRDIGITS
:
200 case LOCALE_ICURRENCY
:
201 case LOCALE_IINTLCURRDIGITS
:
202 case LOCALE_INEGCURR
:
203 case LOCALE_INEGSEPBYSPACE
:
204 case LOCALE_INEGSIGNPOSN
:
205 case LOCALE_INEGSYMPRECEDES
:
206 case LOCALE_IPOSSEPBYSPACE
:
207 case LOCALE_IPOSSIGNPOSN
:
208 case LOCALE_IPOSSYMPRECEDES
:
209 case LOCALE_SCURRENCY
:
210 case LOCALE_SINTLSYMBOL
:
211 case LOCALE_SMONDECIMALSEP
:
212 case LOCALE_SMONGROUPING
:
213 case LOCALE_SMONTHOUSANDSEP
:
214 case LOCALE_SNATIVECURRNAME
:
215 default_id
= lcid_LC_MONETARY
;
219 case LOCALE_IDIGITSUBSTITUTION
:
221 case LOCALE_INEGNUMBER
:
222 case LOCALE_SDECIMAL
:
223 case LOCALE_SGROUPING
:
225 case LOCALE_SNATIVEDIGITS
:
226 case LOCALE_SNEGATIVESIGN
:
227 //case LOCALE_SNEGINFINITY:
228 //case LOCALE_SPOSINFINITY:
229 case LOCALE_SPOSITIVESIGN
:
230 case LOCALE_STHOUSAND
:
231 default_id
= lcid_LC_NUMERIC
;
234 case LOCALE_ICALENDARTYPE
:
235 case LOCALE_ICENTURY
:
237 case LOCALE_IDAYLZERO
:
238 case LOCALE_IFIRSTDAYOFWEEK
:
239 case LOCALE_IFIRSTWEEKOFYEAR
:
241 case LOCALE_IMONLZERO
:
242 case LOCALE_IOPTIONALCALENDAR
:
244 case LOCALE_ITIMEMARKPOSN
:
248 case LOCALE_SABBREVDAYNAME1
:
249 case LOCALE_SABBREVDAYNAME2
:
250 case LOCALE_SABBREVDAYNAME3
:
251 case LOCALE_SABBREVDAYNAME4
:
252 case LOCALE_SABBREVDAYNAME5
:
253 case LOCALE_SABBREVDAYNAME6
:
254 case LOCALE_SABBREVDAYNAME7
:
255 case LOCALE_SABBREVMONTHNAME1
:
256 case LOCALE_SABBREVMONTHNAME2
:
257 case LOCALE_SABBREVMONTHNAME3
:
258 case LOCALE_SABBREVMONTHNAME4
:
259 case LOCALE_SABBREVMONTHNAME5
:
260 case LOCALE_SABBREVMONTHNAME6
:
261 case LOCALE_SABBREVMONTHNAME7
:
262 case LOCALE_SABBREVMONTHNAME8
:
263 case LOCALE_SABBREVMONTHNAME9
:
264 case LOCALE_SABBREVMONTHNAME10
:
265 case LOCALE_SABBREVMONTHNAME11
:
266 case LOCALE_SABBREVMONTHNAME12
:
267 case LOCALE_SABBREVMONTHNAME13
:
269 case LOCALE_SDAYNAME1
:
270 case LOCALE_SDAYNAME2
:
271 case LOCALE_SDAYNAME3
:
272 case LOCALE_SDAYNAME4
:
273 case LOCALE_SDAYNAME5
:
274 case LOCALE_SDAYNAME6
:
275 case LOCALE_SDAYNAME7
:
276 //case LOCALE_SDURATION:
277 case LOCALE_SLONGDATE
:
278 case LOCALE_SMONTHNAME1
:
279 case LOCALE_SMONTHNAME2
:
280 case LOCALE_SMONTHNAME3
:
281 case LOCALE_SMONTHNAME4
:
282 case LOCALE_SMONTHNAME5
:
283 case LOCALE_SMONTHNAME6
:
284 case LOCALE_SMONTHNAME7
:
285 case LOCALE_SMONTHNAME8
:
286 case LOCALE_SMONTHNAME9
:
287 case LOCALE_SMONTHNAME10
:
288 case LOCALE_SMONTHNAME11
:
289 case LOCALE_SMONTHNAME12
:
290 case LOCALE_SMONTHNAME13
:
291 case LOCALE_SSHORTDATE
:
292 //case LOCALE_SSHORTESTDAYNAME1:
293 //case LOCALE_SSHORTESTDAYNAME2:
294 //case LOCALE_SSHORTESTDAYNAME3:
295 //case LOCALE_SSHORTESTDAYNAME4:
296 //case LOCALE_SSHORTESTDAYNAME5:
297 //case LOCALE_SSHORTESTDAYNAME6:
298 //case LOCALE_SSHORTESTDAYNAME7:
300 case LOCALE_STIMEFORMAT
:
301 case LOCALE_SYEARMONTH
:
302 default_id
= lcid_LC_TIME
;
305 case LOCALE_IPAPERSIZE
:
306 default_id
= lcid_LC_PAPER
;
309 case LOCALE_IMEASURE
:
310 default_id
= lcid_LC_MEASUREMENT
;
313 case LOCALE_ICOUNTRY
:
314 default_id
= lcid_LC_TELEPHONE
;
317 if (default_id
) lcid
= default_id
;
319 return ConvertDefaultLocale( lcid
);
322 /***********************************************************************
323 * is_genitive_name_supported
325 * Determine could LCTYPE basically support genitive name form or not.
327 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
329 switch(lctype
& 0xffff)
331 case LOCALE_SMONTHNAME1
:
332 case LOCALE_SMONTHNAME2
:
333 case LOCALE_SMONTHNAME3
:
334 case LOCALE_SMONTHNAME4
:
335 case LOCALE_SMONTHNAME5
:
336 case LOCALE_SMONTHNAME6
:
337 case LOCALE_SMONTHNAME7
:
338 case LOCALE_SMONTHNAME8
:
339 case LOCALE_SMONTHNAME9
:
340 case LOCALE_SMONTHNAME10
:
341 case LOCALE_SMONTHNAME11
:
342 case LOCALE_SMONTHNAME12
:
343 case LOCALE_SMONTHNAME13
:
350 /***********************************************************************
351 * create_registry_key
353 * Create the Control Panel\\International registry key.
355 static inline HANDLE
create_registry_key(void)
357 static const WCHAR cplW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
358 static const WCHAR intlW
[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
359 OBJECT_ATTRIBUTES attr
;
360 UNICODE_STRING nameW
;
361 HANDLE cpl_key
, hkey
= 0;
363 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
365 attr
.Length
= sizeof(attr
);
366 attr
.RootDirectory
= hkey
;
367 attr
.ObjectName
= &nameW
;
369 attr
.SecurityDescriptor
= NULL
;
370 attr
.SecurityQualityOfService
= NULL
;
371 RtlInitUnicodeString( &nameW
, cplW
);
373 if (!NtCreateKey( &cpl_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
375 NtClose( attr
.RootDirectory
);
376 attr
.RootDirectory
= cpl_key
;
377 RtlInitUnicodeString( &nameW
, intlW
);
378 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
)) hkey
= 0;
380 NtClose( attr
.RootDirectory
);
384 /***********************************************************************
385 * GetUserDefaultLangID (KERNEL32.@)
387 * Get the default language Id for the current user.
393 * The current LANGID of the default language for the current user.
395 LANGID WINAPI
GetUserDefaultLangID(void)
397 return LANGIDFROMLCID(GetUserDefaultLCID());
401 /***********************************************************************
402 * GetSystemDefaultLangID (KERNEL32.@)
404 * Get the default language Id for the system.
410 * The current LANGID of the default language for the system.
412 LANGID WINAPI
GetSystemDefaultLangID(void)
414 return LANGIDFROMLCID(GetSystemDefaultLCID());
418 /***********************************************************************
419 * GetUserDefaultLCID (KERNEL32.@)
421 * Get the default locale Id for the current user.
427 * The current LCID of the default locale for the current user.
429 LCID WINAPI
GetUserDefaultLCID(void)
432 NtQueryDefaultLocale( TRUE
, &lcid
);
437 /***********************************************************************
438 * GetSystemDefaultLCID (KERNEL32.@)
440 * Get the default locale Id for the system.
446 * The current LCID of the default locale for the system.
448 LCID WINAPI
GetSystemDefaultLCID(void)
451 NtQueryDefaultLocale( FALSE
, &lcid
);
456 /***********************************************************************
457 * GetUserDefaultUILanguage (KERNEL32.@)
459 * Get the default user interface language Id for the current user.
465 * The current LANGID of the default UI language for the current user.
467 LANGID WINAPI
GetUserDefaultUILanguage(void)
470 NtQueryDefaultUILanguage( &lang
);
475 /***********************************************************************
476 * GetSystemDefaultUILanguage (KERNEL32.@)
478 * Get the default user interface language Id for the system.
484 * The current LANGID of the default UI language for the system. This is
485 * typically the same language used during the installation process.
487 LANGID WINAPI
GetSystemDefaultUILanguage(void)
490 NtQueryInstallUILanguage( &lang
);
494 /******************************************************************************
495 * get_locale_value_name
497 * Gets the registry value name for a given lctype.
499 static const WCHAR
*get_locale_value_name( DWORD lctype
)
501 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
502 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
503 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
504 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
505 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
506 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
507 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
508 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
509 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
510 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
511 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
512 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
513 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
514 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
515 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
516 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
517 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
518 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
519 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
520 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
521 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
522 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
523 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
524 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
525 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
526 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
527 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
528 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
529 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
530 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
531 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
532 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
533 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
534 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
535 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
536 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
537 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
538 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
539 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
543 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
544 * the values are stored in the registry, confirmed under Windows.
546 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
547 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
548 case LOCALE_ICURRENCY
: return iCurrencyW
;
549 case LOCALE_IDIGITS
: return iDigitsW
;
550 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
551 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
552 case LOCALE_ILZERO
: return iLZeroW
;
553 case LOCALE_IMEASURE
: return iMeasureW
;
554 case LOCALE_INEGCURR
: return iNegCurrW
;
555 case LOCALE_INEGNUMBER
: return iNegNumberW
;
556 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
557 case LOCALE_ITIME
: return iTimeW
;
558 case LOCALE_S1159
: return s1159W
;
559 case LOCALE_S2359
: return s2359W
;
560 case LOCALE_SCURRENCY
: return sCurrencyW
;
561 case LOCALE_SDATE
: return sDateW
;
562 case LOCALE_SDECIMAL
: return sDecimalW
;
563 case LOCALE_SGROUPING
: return sGroupingW
;
564 case LOCALE_SLIST
: return sListW
;
565 case LOCALE_SLONGDATE
: return sLongDateW
;
566 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
567 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
568 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
569 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
570 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
571 case LOCALE_SSHORTDATE
: return sShortDateW
;
572 case LOCALE_STHOUSAND
: return sThousandW
;
573 case LOCALE_STIME
: return sTimeW
;
574 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
575 case LOCALE_SYEARMONTH
: return sYearMonthW
;
577 /* The following are not listed under MSDN as supported,
578 * but seem to be used and also stored in the registry.
580 case LOCALE_ICOUNTRY
: return iCountryW
;
581 case LOCALE_IDATE
: return iDateW
;
582 case LOCALE_ILDATE
: return iLDateW
;
583 case LOCALE_ITLZERO
: return iTLZeroW
;
584 case LOCALE_SCOUNTRY
: return sCountryW
;
585 case LOCALE_SABBREVLANGNAME
: return sLanguageW
;
587 /* The following are used in XP and later */
588 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
589 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
590 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
596 /******************************************************************************
597 * get_registry_locale_info
599 * Retrieve user-modified locale info from the registry.
600 * Return length, 0 on error, -1 if not found.
602 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
608 UNICODE_STRING nameW
;
609 KEY_VALUE_PARTIAL_INFORMATION
*info
;
610 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
612 if (!(hkey
= create_registry_key())) return -1;
614 RtlInitUnicodeString( &nameW
, value
);
615 size
= info_size
+ len
* sizeof(WCHAR
);
617 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
620 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
624 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
628 ret
= (size
- info_size
) / sizeof(WCHAR
);
629 /* append terminating null if needed */
630 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
632 if (ret
< len
|| !buffer
) ret
++;
635 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
641 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
645 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
647 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
649 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
655 SetLastError( RtlNtStatusToDosError(status
) );
659 HeapFree( GetProcessHeap(), 0, info
);
664 /******************************************************************************
665 * GetLocaleInfoA (KERNEL32.@)
667 * Get information about an aspect of a locale.
670 * lcid [I] LCID of the locale
671 * lctype [I] LCTYPE_ flags from "winnls.h"
672 * buffer [O] Destination for the information
673 * len [I] Length of buffer in characters
676 * Success: The size of the data requested. If buffer is non-NULL, it is filled
677 * with the information.
678 * Failure: 0. Use GetLastError() to determine the cause.
681 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
682 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
683 * which is a bit string.
685 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
690 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
692 if (len
< 0 || (len
&& !buffer
))
694 SetLastError( ERROR_INVALID_PARAMETER
);
697 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
)
699 SetLastError( ERROR_INVALID_FLAGS
);
703 if (!len
) buffer
= NULL
;
705 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
707 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
709 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
712 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
714 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
715 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
717 /* it's not an ASCII string, just bytes */
718 ret
*= sizeof(WCHAR
);
721 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
724 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
731 UINT codepage
= CP_ACP
;
732 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
733 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
736 HeapFree( GetProcessHeap(), 0, bufferW
);
740 static int get_value_base_by_lctype( LCTYPE lctype
)
742 return lctype
== LOCALE_ILANGUAGE
|| lctype
== LOCALE_IDEFAULTLANGUAGE
? 16 : 10;
745 /******************************************************************************
746 * GetLocaleInfoW (KERNEL32.@)
748 * See GetLocaleInfoA.
750 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
760 if (len
< 0 || (len
&& !buffer
))
762 SetLastError( ERROR_INVALID_PARAMETER
);
765 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&&
766 !is_genitive_name_supported( lctype
))
768 SetLastError( ERROR_INVALID_FLAGS
);
772 if (!len
) buffer
= NULL
;
774 lcid
= convert_default_lcid( lcid
, lctype
);
776 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
779 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
781 /* first check for overrides in the registry */
783 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
784 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
786 const WCHAR
*value
= get_locale_value_name(lctype
);
790 if (lcflags
& LOCALE_RETURN_NUMBER
)
793 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
797 UINT number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
798 if (*end
) /* invalid number */
800 SetLastError( ERROR_INVALID_FLAGS
);
803 ret
= sizeof(UINT
)/sizeof(WCHAR
);
804 if (!buffer
) return ret
;
807 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
810 memcpy( buffer
, &number
, sizeof(number
) );
813 else ret
= get_registry_locale_info( value
, buffer
, len
);
815 if (ret
!= -1) return ret
;
819 /* now load it from kernel resources */
821 lang_id
= LANGIDFROMLCID( lcid
);
823 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
824 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
825 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
827 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
828 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
830 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
833 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
836 p
= LockResource( hmem
);
837 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
839 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
840 else if (is_genitive_name_supported( lctype
) && *p
)
842 /* genitive form's stored after a null separator from a nominative */
843 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
845 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
853 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
855 if (!buffer
) return ret
;
859 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
863 if (lcflags
& LOCALE_RETURN_NUMBER
)
866 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
868 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
870 number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
872 memcpy( buffer
, &number
, sizeof(number
) );
873 else /* invalid number */
875 SetLastError( ERROR_INVALID_FLAGS
);
878 HeapFree( GetProcessHeap(), 0, tmp
);
880 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
881 lcid
, lctype
, buffer
, len
, number
);
885 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
886 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
888 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
889 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
895 /******************************************************************************
896 * SetLocaleInfoA [KERNEL32.@]
898 * Set information about an aspect of a locale.
901 * lcid [I] LCID of the locale
902 * lctype [I] LCTYPE_ flags from "winnls.h"
903 * data [I] Information to set
906 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
907 * whenever it is called without LOCALE_NOUSEROVERRIDE.
908 * Failure: FALSE. Use GetLastError() to determine the cause.
911 * - Values are only be set for the current user locale; the system locale
912 * settings cannot be changed.
913 * - Any settings changed by this call are lost when the locale is changed by
914 * the control panel (in Wine, this happens every time you change LANG).
915 * - The native implementation of this function does not check that lcid matches
916 * the current user locale, and simply sets the new values. Wine warns you in
917 * this case, but behaves the same.
919 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
921 UINT codepage
= CP_ACP
;
926 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
930 SetLastError( ERROR_INVALID_PARAMETER
);
933 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
934 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
936 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
939 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
940 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
941 HeapFree( GetProcessHeap(), 0, strW
);
946 /******************************************************************************
947 * SetLocaleInfoW (KERNEL32.@)
949 * See SetLocaleInfoA.
951 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
954 static const WCHAR intlW
[] = {'i','n','t','l',0 };
955 UNICODE_STRING valueW
;
960 value
= get_locale_value_name( lctype
);
964 SetLastError( ERROR_INVALID_PARAMETER
);
968 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
970 SetLastError( ERROR_INVALID_FLAGS
);
974 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
976 /* FIXME: should check that data to set is sane */
978 /* FIXME: profile functions should map to registry */
979 WriteProfileStringW( intlW
, value
, data
);
981 if (!(hkey
= create_registry_key())) return FALSE
;
982 RtlInitUnicodeString( &valueW
, value
);
983 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, (PVOID
)data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
985 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
987 /* Set I-value from S value */
988 WCHAR
*lpD
, *lpM
, *lpY
;
991 lpD
= strrchrW(data
, 'd');
992 lpM
= strrchrW(data
, 'M');
993 lpY
= strrchrW(data
, 'y');
997 szBuff
[0] = '1'; /* D-M-Y */
1002 szBuff
[0] = '2'; /* Y-M-D */
1004 szBuff
[0] = '0'; /* M-D-Y */
1009 if (lctype
== LOCALE_SSHORTDATE
)
1010 lctype
= LOCALE_IDATE
;
1012 lctype
= LOCALE_ILDATE
;
1014 value
= get_locale_value_name( lctype
);
1016 WriteProfileStringW( intlW
, value
, szBuff
);
1018 RtlInitUnicodeString( &valueW
, value
);
1019 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1024 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1028 /***********************************************************************
1029 * GetThreadLocale (KERNEL32.@)
1031 * Get the current threads locale.
1037 * The LCID currently associated with the calling thread.
1039 LCID WINAPI
GetThreadLocale(void)
1041 LCID ret
= NtCurrentTeb()->CurrentLocale
;
1042 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
1046 /**********************************************************************
1047 * SetThreadLocale (KERNEL32.@)
1049 * Set the current threads locale.
1052 * lcid [I] LCID of the locale to set
1055 * Success: TRUE. The threads locale is set to lcid.
1056 * Failure: FALSE. Use GetLastError() to determine the cause.
1058 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1060 TRACE("(0x%04X)\n", lcid
);
1062 lcid
= ConvertDefaultLocale(lcid
);
1064 if (lcid
!= GetThreadLocale())
1066 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1068 SetLastError(ERROR_INVALID_PARAMETER
);
1072 NtCurrentTeb()->CurrentLocale
= lcid
;
1077 /******************************************************************************
1078 * ConvertDefaultLocale (KERNEL32.@)
1080 * Convert a default locale identifier into a real identifier.
1083 * lcid [I] LCID identifier of the locale to convert
1086 * lcid unchanged, if not a default locale or its sublanguage is
1087 * not SUBLANG_NEUTRAL.
1088 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1089 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1090 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1092 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
1098 case LOCALE_SYSTEM_DEFAULT
:
1099 lcid
= GetSystemDefaultLCID();
1101 case LOCALE_USER_DEFAULT
:
1102 case LOCALE_NEUTRAL
:
1103 lcid
= GetUserDefaultLCID();
1106 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1107 langid
= LANGIDFROMLCID(lcid
);
1108 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
1110 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
1111 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
1118 /******************************************************************************
1119 * IsValidLocale (KERNEL32.@)
1121 * Determine if a locale is valid.
1124 * lcid [I] LCID of the locale to check
1125 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1128 * TRUE, if lcid is valid,
1132 * Wine does not currently make the distinction between supported and installed. All
1133 * languages supported are installed by default.
1135 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
1137 /* check if language is registered in the kernel32 resources */
1138 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1139 (LPCWSTR
)LOCALE_ILANGUAGE
, LANGIDFROMLCID(lcid
)) != 0;
1143 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
1144 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
1146 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
1149 sprintf(buf
, "%08x", (UINT
)LangID
);
1150 return lpfnLocaleEnum( buf
);
1153 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
1154 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
1156 static const WCHAR formatW
[] = {'%','0','8','x',0};
1157 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
1159 sprintfW( buf
, formatW
, (UINT
)LangID
);
1160 return lpfnLocaleEnum( buf
);
1163 /******************************************************************************
1164 * EnumSystemLocalesA (KERNEL32.@)
1166 * Call a users function for each locale available on the system.
1169 * lpfnLocaleEnum [I] Callback function to call for each locale
1170 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1174 * Failure: FALSE. Use GetLastError() to determine the cause.
1176 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
1178 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
1179 EnumResourceLanguagesA( kernel32_handle
, (LPSTR
)RT_STRING
,
1180 (LPCSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_a
,
1181 (LONG_PTR
)lpfnLocaleEnum
);
1186 /******************************************************************************
1187 * EnumSystemLocalesW (KERNEL32.@)
1189 * See EnumSystemLocalesA.
1191 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
1193 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
1194 EnumResourceLanguagesW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1195 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_w
,
1196 (LONG_PTR
)lpfnLocaleEnum
);
1200 /***********************************************************************
1201 * VerLanguageNameA (KERNEL32.@)
1203 * Get the name of a language.
1206 * wLang [I] LANGID of the language
1207 * szLang [O] Destination for the language name
1210 * Success: The size of the language name. If szLang is non-NULL, it is filled
1212 * Failure: 0. Use GetLastError() to determine the cause.
1215 DWORD WINAPI
VerLanguageNameA( DWORD wLang
, LPSTR szLang
, DWORD nSize
)
1217 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1221 /***********************************************************************
1222 * VerLanguageNameW (KERNEL32.@)
1224 * See VerLanguageNameA.
1226 DWORD WINAPI
VerLanguageNameW( DWORD wLang
, LPWSTR szLang
, DWORD nSize
)
1228 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1231 /******************************************************************************
1232 * GetStringTypeW (KERNEL32.@)
1234 * See GetStringTypeA.
1236 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1238 static const unsigned char type2_map
[16] =
1240 C2_NOTAPPLICABLE
, /* unassigned */
1241 C2_LEFTTORIGHT
, /* L */
1242 C2_RIGHTTOLEFT
, /* R */
1243 C2_EUROPENUMBER
, /* EN */
1244 C2_EUROPESEPARATOR
, /* ES */
1245 C2_EUROPETERMINATOR
, /* ET */
1246 C2_ARABICNUMBER
, /* AN */
1247 C2_COMMONSEPARATOR
, /* CS */
1248 C2_BLOCKSEPARATOR
, /* B */
1249 C2_SEGMENTSEPARATOR
, /* S */
1250 C2_WHITESPACE
, /* WS */
1251 C2_OTHERNEUTRAL
, /* ON */
1252 C2_RIGHTTOLEFT
, /* AL */
1253 C2_NOTAPPLICABLE
, /* NSM */
1254 C2_NOTAPPLICABLE
, /* BN */
1255 C2_OTHERNEUTRAL
/* LRE, LRO, RLE, RLO, PDF */
1258 if (count
== -1) count
= strlenW(src
) + 1;
1262 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
1265 while (count
--) *chartype
++ = type2_map
[get_char_typeW( *src
++ ) >> 12];
1269 WARN("CT_CTYPE3: semi-stub.\n");
1273 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
1275 type1
= get_char_typeW( *src
++ ) & 0xfff;
1276 /* try to construct type3 from type1 */
1277 if(type1
& C1_SPACE
) type3
|= C3_SYMBOL
;
1278 if(type1
& C1_ALPHA
) type3
|= C3_ALPHA
;
1279 if ((c
>=0x30A0)&&(c
<=0x30FF)) type3
|= C3_KATAKANA
;
1280 if ((c
>=0x3040)&&(c
<=0x309F)) type3
|= C3_HIRAGANA
;
1281 if ((c
>=0x4E00)&&(c
<=0x9FAF)) type3
|= C3_IDEOGRAPH
;
1282 if ((c
>=0x0600)&&(c
<=0x06FF)) type3
|= C3_KASHIDA
;
1283 if ((c
>=0x3000)&&(c
<=0x303F)) type3
|= C3_SYMBOL
;
1285 if ((c
>=0xD800)&&(c
<=0xDBFF)) type3
|= C3_HIGHSURROGATE
;
1286 if ((c
>=0xDC00)&&(c
<=0xDFFF)) type3
|= C3_LOWSURROGATE
;
1288 if ((c
>=0xFF00)&&(c
<=0xFF60)) type3
|= C3_FULLWIDTH
;
1289 if ((c
>=0xFF00)&&(c
<=0xFF20)) type3
|= C3_SYMBOL
;
1290 if ((c
>=0xFF3B)&&(c
<=0xFF40)) type3
|= C3_SYMBOL
;
1291 if ((c
>=0xFF5B)&&(c
<=0xFF60)) type3
|= C3_SYMBOL
;
1292 if ((c
>=0xFF21)&&(c
<=0xFF3A)) type3
|= C3_ALPHA
;
1293 if ((c
>=0xFF41)&&(c
<=0xFF5A)) type3
|= C3_ALPHA
;
1294 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_FULLWIDTH
;
1295 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_SYMBOL
;
1297 if ((c
>=0xFF61)&&(c
<=0xFFDC)) type3
|= C3_HALFWIDTH
;
1298 if ((c
>=0xFF61)&&(c
<=0xFF64)) type3
|= C3_SYMBOL
;
1299 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_KATAKANA
;
1300 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_ALPHA
;
1301 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_HALFWIDTH
;
1302 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_SYMBOL
;
1303 *chartype
++ = type3
;
1308 SetLastError( ERROR_INVALID_PARAMETER
);
1315 /******************************************************************************
1316 * GetStringTypeExW (KERNEL32.@)
1318 * See GetStringTypeExA.
1320 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1322 /* locale is ignored for Unicode */
1323 return GetStringTypeW( type
, src
, count
, chartype
);
1327 /******************************************************************************
1328 * GetStringTypeA (KERNEL32.@)
1330 * Get characteristics of the characters making up a string.
1333 * locale [I] Locale Id for the string
1334 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1335 * src [I] String to analyse
1336 * count [I] Length of src in chars, or -1 if src is NUL terminated
1337 * chartype [O] Destination for the calculated characteristics
1340 * Success: TRUE. chartype is filled with the requested characteristics of each char
1342 * Failure: FALSE. Use GetLastError() to determine the cause.
1344 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1351 if(count
== -1) count
= strlen(src
) + 1;
1353 if (!(cp
= get_lcid_codepage( locale
)))
1355 FIXME("For locale %04x using current ANSI code page\n", locale
);
1359 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
1360 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
1362 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
1364 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1365 * string, with multibyte characters there maybe be more bytes in count
1366 * than character space in the buffer!
1368 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
1369 HeapFree(GetProcessHeap(), 0, srcW
);
1374 /******************************************************************************
1375 * GetStringTypeExA (KERNEL32.@)
1377 * Get characteristics of the characters making up a string.
1380 * locale [I] Locale Id for the string
1381 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1382 * src [I] String to analyse
1383 * count [I] Length of src in chars, or -1 if src is NUL terminated
1384 * chartype [O] Destination for the calculated characteristics
1387 * Success: TRUE. chartype is filled with the requested characteristics of each char
1389 * Failure: FALSE. Use GetLastError() to determine the cause.
1391 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1393 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
1396 /*************************************************************************
1397 * LCMapStringEx (KERNEL32.@)
1399 * Map characters in a locale sensitive string.
1402 * name [I] Locale name for the conversion.
1403 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
1404 * src [I] String to map
1405 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1406 * dst [O] Destination for mapped string
1407 * dstlen [I] Length of dst in characters
1408 * version [I] reserved, must be NULL
1409 * reserved [I] reserved, must be NULL
1410 * lparam [I] reserved, must be 0
1413 * Success: The length of the mapped string in dst, including the NUL terminator.
1414 * Failure: 0. Use GetLastError() to determine the cause.
1416 INT WINAPI
LCMapStringEx(LPCWSTR name
, DWORD flags
, LPCWSTR src
, INT srclen
, LPWSTR dst
, INT dstlen
,
1417 LPNLSVERSIONINFO version
, LPVOID reserved
, LPARAM lparam
)
1421 if (version
) FIXME("unsupported version structure %p\n", version
);
1422 if (reserved
) FIXME("unsupported reserved pointer %p\n", reserved
);
1423 if (lparam
) FIXME("unsupported lparam %lx\n", lparam
);
1425 if (!src
|| !srclen
|| dstlen
< 0)
1427 SetLastError(ERROR_INVALID_PARAMETER
);
1431 /* mutually exclusive flags */
1432 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
1433 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
1434 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
1435 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
))
1437 SetLastError(ERROR_INVALID_FLAGS
);
1441 if (!dstlen
) dst
= NULL
;
1443 if (flags
& LCMAP_SORTKEY
)
1448 SetLastError(ERROR_INVALID_FLAGS
);
1452 if (srclen
< 0) srclen
= strlenW(src
);
1454 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1455 debugstr_w(name
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1457 ret
= wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
1459 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1465 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1466 if (flags
& SORT_STRINGSORT
)
1468 SetLastError(ERROR_INVALID_FLAGS
);
1472 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1474 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1475 debugstr_w(name
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1477 if (!dst
) /* return required string length */
1481 for (len
= 0; srclen
; src
++, srclen
--)
1484 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1485 * and skips white space and punctuation characters for
1486 * NORM_IGNORESYMBOLS.
1488 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1495 if (flags
& LCMAP_UPPERCASE
)
1497 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1500 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1502 *dst_ptr
++ = toupperW(wch
);
1506 else if (flags
& LCMAP_LOWERCASE
)
1508 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1511 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1513 *dst_ptr
++ = tolowerW(wch
);
1521 SetLastError(ERROR_INVALID_FLAGS
);
1524 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1527 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1536 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1540 return dst_ptr
- dst
;
1543 /*************************************************************************
1544 * LCMapStringW (KERNEL32.@)
1548 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
1549 LPWSTR dst
, INT dstlen
)
1551 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1552 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1554 return LCMapStringEx(NULL
, flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
, 0);
1557 /*************************************************************************
1558 * LCMapStringA (KERNEL32.@)
1560 * Map characters in a locale sensitive string.
1563 * lcid [I] LCID for the conversion.
1564 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1565 * src [I] String to map
1566 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1567 * dst [O] Destination for mapped string
1568 * dstlen [I] Length of dst in characters
1571 * Success: The length of the mapped string in dst, including the NUL terminator.
1572 * Failure: 0. Use GetLastError() to determine the cause.
1574 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
1575 LPSTR dst
, INT dstlen
)
1577 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
1579 INT ret
= 0, srclenW
, dstlenW
;
1580 UINT locale_cp
= CP_ACP
;
1582 if (!src
|| !srclen
|| dstlen
< 0)
1584 SetLastError(ERROR_INVALID_PARAMETER
);
1588 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1590 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
1595 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
1596 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1599 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1602 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
1605 if (flags
& LCMAP_SORTKEY
)
1609 SetLastError(ERROR_INVALID_FLAGS
);
1610 goto map_string_exit
;
1612 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
1614 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1617 goto map_string_exit
;
1620 if (flags
& SORT_STRINGSORT
)
1622 SetLastError(ERROR_INVALID_FLAGS
);
1623 goto map_string_exit
;
1626 dstlenW
= LCMapStringEx(NULL
, flags
, srcW
, srclenW
, NULL
, 0, NULL
, NULL
, 0);
1628 goto map_string_exit
;
1630 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
1633 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1634 goto map_string_exit
;
1637 LCMapStringEx(NULL
, flags
, srcW
, srclenW
, dstW
, dstlenW
, NULL
, NULL
, 0);
1638 ret
= WideCharToMultiByte(locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
1639 HeapFree(GetProcessHeap(), 0, dstW
);
1642 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
1646 /*************************************************************************
1647 * FoldStringA (KERNEL32.@)
1649 * Map characters in a string.
1652 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1653 * src [I] String to map
1654 * srclen [I] Length of src, or -1 if src is NUL terminated
1655 * dst [O] Destination for mapped string
1656 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1659 * Success: The length of the string written to dst, including the terminating NUL. If
1660 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1661 * and dst may be NULL.
1662 * Failure: 0. Use GetLastError() to determine the cause.
1664 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
1665 LPSTR dst
, INT dstlen
)
1667 INT ret
= 0, srclenW
= 0;
1668 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
1670 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1672 SetLastError(ERROR_INVALID_PARAMETER
);
1676 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1677 src
, srclen
, NULL
, 0);
1678 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1682 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1683 goto FoldStringA_exit
;
1686 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1687 src
, srclen
, srcW
, srclenW
);
1689 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
1691 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
1694 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
1698 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1699 goto FoldStringA_exit
;
1702 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
1703 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
1706 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1710 HeapFree(GetProcessHeap(), 0, dstW
);
1713 HeapFree(GetProcessHeap(), 0, srcW
);
1717 /*************************************************************************
1718 * FoldStringW (KERNEL32.@)
1722 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
1723 LPWSTR dst
, INT dstlen
)
1727 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
1732 /* Fall through for dwFlags == 0 */
1733 case MAP_PRECOMPOSED
|MAP_COMPOSITE
:
1734 case MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
:
1735 case MAP_COMPOSITE
|MAP_EXPAND_LIGATURES
:
1736 SetLastError(ERROR_INVALID_FLAGS
);
1740 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1742 SetLastError(ERROR_INVALID_PARAMETER
);
1746 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
1748 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1752 /******************************************************************************
1753 * CompareStringW (KERNEL32.@)
1755 * See CompareStringA.
1757 INT WINAPI
CompareStringW(LCID lcid
, DWORD style
,
1758 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
1764 SetLastError(ERROR_INVALID_PARAMETER
);
1768 if( style
& ~(NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
|
1769 SORT_STRINGSORT
|NORM_IGNOREKANATYPE
|NORM_IGNOREWIDTH
|LOCALE_USE_CP_ACP
|0x10000000) )
1771 SetLastError(ERROR_INVALID_FLAGS
);
1775 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
1776 if (style
& 0x10000000)
1777 WARN("Ignoring unknown style 0x10000000\n");
1779 if (len1
< 0) len1
= strlenW(str1
);
1780 if (len2
< 0) len2
= strlenW(str2
);
1782 ret
= wine_compare_string(style
, str1
, len1
, str2
, len2
);
1784 if (ret
) /* need to translate result */
1785 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
1789 /******************************************************************************
1790 * CompareStringA (KERNEL32.@)
1792 * Compare two locale sensitive strings.
1795 * lcid [I] LCID for the comparison
1796 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
1797 * str1 [I] First string to compare
1798 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1799 * str2 [I] Second string to compare
1800 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1803 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1804 * str1 is less than, equal to or greater than str2 respectively.
1805 * Failure: FALSE. Use GetLastError() to determine the cause.
1807 INT WINAPI
CompareStringA(LCID lcid
, DWORD flags
,
1808 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
1810 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
1811 WCHAR
*buf2W
= buf1W
+ 130;
1812 LPWSTR str1W
, str2W
;
1813 INT len1W
= 0, len2W
= 0, ret
;
1814 UINT locale_cp
= CP_ACP
;
1818 SetLastError(ERROR_INVALID_PARAMETER
);
1821 if (len1
< 0) len1
= strlen(str1
);
1822 if (len2
< 0) len2
= strlen(str2
);
1824 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1828 if (len1
<= 130) len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
1833 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
1834 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
1837 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1840 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
1851 if (len2
<= 130) len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
1856 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
1857 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
1860 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1861 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1864 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
1873 ret
= CompareStringW(lcid
, flags
, str1W
, len1W
, str2W
, len2W
);
1875 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1876 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
1880 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
1882 UNICODE_STRING keyName
;
1883 OBJECT_ATTRIBUTES attr
;
1886 RtlInitUnicodeString( &keyName
, szKeyName
);
1887 InitializeObjectAttributes(&attr
, &keyName
, OBJ_CASE_INSENSITIVE
, hRootKey
, NULL
);
1889 if (NtOpenKey( &hkey
, KEY_READ
, &attr
) != STATUS_SUCCESS
)
1895 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
1896 LPWSTR szValueName
, ULONG valueNameSize
,
1897 LPWSTR szValueData
, ULONG valueDataSize
)
1900 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
1903 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
1904 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
1905 info
->NameLength
> valueNameSize
||
1906 info
->DataLength
> valueDataSize
)
1911 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
1913 memcpy( szValueName
, info
->Name
, info
->NameLength
);
1914 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
1915 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
1916 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
1918 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
1922 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
1925 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
1926 DWORD dwSize
= sizeof(buffer
);
1927 UNICODE_STRING valueName
;
1929 RtlInitUnicodeString( &valueName
, szValueName
);
1931 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
1932 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
1933 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
1934 info
->DataLength
== sizeof(DWORD
))
1936 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
1943 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
1946 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
1950 /* FIXME: Is it correct to use the system default langid? */
1951 langId
= GetSystemDefaultLangID();
1953 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
1954 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
1956 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
1960 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
1964 ULONG iResourceIndex
= lgrpid
& 0xf;
1965 LPCWSTR lpResEntry
= LockResource( hResDir
);
1968 for (i
= 0; i
< iResourceIndex
; i
++)
1969 lpResEntry
+= *lpResEntry
+ 1;
1971 if (*lpResEntry
< nameSize
)
1973 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
1974 szName
[*lpResEntry
] = '\0';
1979 FreeResource( hResource
);
1984 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1987 LANGUAGEGROUP_ENUMPROCA procA
;
1988 LANGUAGEGROUP_ENUMPROCW procW
;
1991 } ENUMLANGUAGEGROUP_CALLBACKS
;
1993 /* Internal implementation of EnumSystemLanguageGroupsA/W */
1994 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
1996 WCHAR szNumber
[10], szValue
[4];
1998 BOOL bContinue
= TRUE
;
2003 SetLastError(ERROR_INVALID_PARAMETER
);
2007 switch (lpProcs
->dwFlags
)
2010 /* Default to LGRPID_INSTALLED */
2011 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
2012 /* Fall through... */
2013 case LGRPID_INSTALLED
:
2014 case LGRPID_SUPPORTED
:
2017 SetLastError(ERROR_INVALID_FLAGS
);
2021 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2024 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2028 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2029 szValue
, sizeof(szValue
) ))
2031 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
2032 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
2034 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
2035 bInstalled
? "" : "not ");
2037 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
2039 WCHAR szGrpName
[48];
2041 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
2042 szGrpName
[0] = '\0';
2045 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
2049 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2050 char szGrpNameA
[48];
2052 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2053 * or whether the language names are ever localised. Assume CP_ACP.
2056 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2057 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
2059 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
2079 /******************************************************************************
2080 * EnumSystemLanguageGroupsA (KERNEL32.@)
2082 * Call a users function for each language group available on the system.
2085 * pLangGrpEnumProc [I] Callback function to call for each language group
2086 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2087 * lParam [I] User parameter to pass to pLangGrpEnumProc
2091 * Failure: FALSE. Use GetLastError() to determine the cause.
2093 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
2094 DWORD dwFlags
, LONG_PTR lParam
)
2096 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2098 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2100 procs
.procA
= pLangGrpEnumProc
;
2102 procs
.dwFlags
= dwFlags
;
2103 procs
.lParam
= lParam
;
2105 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2108 /******************************************************************************
2109 * EnumSystemLanguageGroupsW (KERNEL32.@)
2111 * See EnumSystemLanguageGroupsA.
2113 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
2114 DWORD dwFlags
, LONG_PTR lParam
)
2116 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2118 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2121 procs
.procW
= pLangGrpEnumProc
;
2122 procs
.dwFlags
= dwFlags
;
2123 procs
.lParam
= lParam
;
2125 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2128 /******************************************************************************
2129 * IsValidLanguageGroup (KERNEL32.@)
2131 * Determine if a language group is supported and/or installed.
2134 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2135 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2138 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2141 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
2143 static const WCHAR szFormat
[] = { '%','x','\0' };
2144 WCHAR szValueName
[16], szValue
[2];
2145 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
2151 case LGRPID_INSTALLED
:
2152 case LGRPID_SUPPORTED
:
2154 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2156 sprintfW( szValueName
, szFormat
, lgrpid
);
2158 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)szValue
))
2162 if (szValue
[0] == '1')
2172 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
2173 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
2179 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2182 LANGGROUPLOCALE_ENUMPROCA procA
;
2183 LANGGROUPLOCALE_ENUMPROCW procW
;
2187 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
2189 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2190 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
2192 static const WCHAR szAlternateSortsKeyName
[] = {
2193 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2195 WCHAR szNumber
[10], szValue
[4];
2197 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
2199 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
2201 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
2203 SetLastError(ERROR_INVALID_PARAMETER
);
2207 if (lpProcs
->dwFlags
)
2209 SetLastError(ERROR_INVALID_FLAGS
);
2213 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
2216 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2220 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2221 szValue
, sizeof(szValue
) ))
2223 lgrpid
= strtoulW( szValue
, NULL
, 16 );
2225 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
2226 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
2228 if (lgrpid
== lpProcs
->lgrpid
)
2232 lcid
= strtoulW( szNumber
, NULL
, 16 );
2234 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2235 * '00000437 ;Georgian'
2236 * At present we only pass the LCID string.
2240 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
2243 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2245 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2247 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
2255 /* Finished enumerating this key */
2258 /* Enumerate alternate sorts also */
2259 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
2264 bContinue
= FALSE
; /* Finished both keys */
2278 LOCATION_NATION
= 0,
2289 enum locationkind kind
;
2292 static const struct geoinfo_t geoinfodata
[] = {
2293 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
2294 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
2295 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
2296 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
2297 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
2298 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
2299 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
2300 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
2301 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
2302 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
2303 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
2304 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
2305 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
2306 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
2307 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
2308 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
2309 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
2310 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
2311 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
2312 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
2313 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
2314 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
2315 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
2316 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
2317 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
2318 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
2319 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
2320 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
2321 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
2322 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
2323 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
2324 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
2325 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
2326 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
2327 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
2328 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
2329 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
2330 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
2331 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
2332 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
2333 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
2334 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
2335 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
2336 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
2337 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
2338 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
2339 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
2340 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
2341 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
2342 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
2343 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
2344 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
2345 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
2346 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
2347 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
2348 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
2349 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
2350 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
2351 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
2352 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
2353 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
2354 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
2355 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
2356 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
2357 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
2358 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
2359 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
2360 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
2361 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
2362 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
2363 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
2364 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
2365 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
2366 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
2367 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
2368 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
2369 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
2370 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
2371 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
2372 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
2373 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
2374 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
2375 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
2376 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
2377 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
2378 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
2379 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
2380 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
2381 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
2382 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
2383 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
2384 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
2385 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
2386 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
2387 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
2388 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
2389 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
2390 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
2391 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
2392 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
2393 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
2394 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
2395 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
2396 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
2397 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
2398 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
2399 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
2400 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
2401 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
2402 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
2403 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
2404 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
2405 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
2406 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
2407 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
2408 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
2409 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
2410 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
2411 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
2412 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
2413 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
2414 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
2415 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
2416 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
2417 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
2418 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
2419 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
2420 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
2421 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
2422 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
2423 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
2424 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
2425 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
2426 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
2427 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
2428 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
2429 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
2430 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
2431 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
2432 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
2433 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
2434 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
2435 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
2436 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
2437 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
2438 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
2439 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
2440 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
2441 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
2442 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
2443 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
2444 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
2445 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
2446 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
2447 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
2448 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
2449 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
2450 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
2451 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
2452 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
2453 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
2454 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
2455 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
2456 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
2457 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
2458 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
2459 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
2460 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
2461 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
2462 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
2463 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
2464 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
2465 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
2466 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
2467 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
2468 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
2469 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
2470 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
2471 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
2472 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
2473 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
2474 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
2475 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
2476 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
2477 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
2478 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
2479 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
2480 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
2481 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
2482 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
2483 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
2484 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
2485 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
2486 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
2487 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
2488 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
2489 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
2490 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
2491 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
2492 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
2493 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
2494 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
2495 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
2496 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
2497 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
2498 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
2499 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
2500 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
2501 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
2502 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
2503 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
2504 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
2505 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
2506 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
2507 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
2508 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
2509 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
2510 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
2511 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
2512 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
2513 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
2514 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH
}, /* Channel Islands */
2515 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
2516 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
2517 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
2518 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
2519 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
2520 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
2521 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
2522 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
2523 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
2524 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
2525 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
2526 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
2527 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
2528 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
2529 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
2530 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */
2531 { 327, {'X','X',0}, {'X','X',0}, 161832256 }, /* Jarvis Island */
2532 { 328, {'J','E',0}, {'J','E','Y',0}, 308, 832 }, /* Jersey */
2533 { 329, {'X','X',0}, {'X','X',0}, 161832256 }, /* Kingman Reef */
2534 { 330, {'M','Q',0}, {'M','T','Q',0}, 10039880, 474 }, /* Martinique */
2535 { 331, {'Y','T',0}, {'M','Y','T',0}, 47603, 175 }, /* Mayotte */
2536 { 332, {'M','S',0}, {'M','S','R',0}, 10039880, 500 }, /* Montserrat */
2537 { 333, {'A','N',0}, {'A','N','T',0}, 10039880, 530, LOCATION_BOTH
}, /* Netherlands Antilles (Former) */
2538 { 334, {'N','C',0}, {'N','C','L',0}, 20900, 540 }, /* New Caledonia */
2539 { 335, {'N','U',0}, {'N','I','U',0}, 26286, 570 }, /* Niue */
2540 { 336, {'N','F',0}, {'N','F','K',0}, 10210825, 574 }, /* Norfolk Island */
2541 { 337, {'M','P',0}, {'M','N','P',0}, 21206, 580 }, /* Northern Mariana Islands */
2542 { 338, {'X','X',0}, {'X','X',0}, 161832256 }, /* Palmyra Atoll */
2543 { 339, {'P','N',0}, {'P','C','N',0}, 26286, 612 }, /* Pitcairn Islands */
2544 { 340, {'X','X',0}, {'X','X',0}, 337 }, /* Rota Island */
2545 { 341, {'X','X',0}, {'X','X',0}, 337 }, /* Saipan */
2546 { 342, {'G','S',0}, {'S','G','S',0}, 39070, 239 }, /* South Georgia and the South Sandwich Islands */
2547 { 343, {'S','H',0}, {'S','H','N',0}, 42483, 654 }, /* St. Helena */
2548 { 346, {'X','X',0}, {'X','X',0}, 337 }, /* Tinian Island */
2549 { 347, {'T','K',0}, {'T','K','L',0}, 26286, 772 }, /* Tokelau */
2550 { 348, {'X','X',0}, {'X','X',0}, 39070 }, /* Tristan da Cunha */
2551 { 349, {'T','C',0}, {'T','C','A',0}, 10039880, 796 }, /* Turks and Caicos Islands */
2552 { 351, {'V','G',0}, {'V','G','B',0}, 10039880, 92 }, /* Virgin Islands, British */
2553 { 352, {'W','F',0}, {'W','L','F',0}, 26286, 876 }, /* Wallis and Futuna */
2554 { 742, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* Africa */
2555 { 2129, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* Asia */
2556 { 10541, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* Europe */
2557 { 15126, {'I','M',0}, {'I','M','N',0}, 10039882, 833 }, /* Man, Isle of */
2558 { 19618, {'M','K',0}, {'M','K','D',0}, 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
2559 { 20900, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION
}, /* Melanesia */
2560 { 21206, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION
}, /* Micronesia */
2561 { 21242, {'X','X',0}, {'X','X',0}, 161832256 }, /* Midway Islands */
2562 { 23581, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION
}, /* Northern America */
2563 { 26286, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION
}, /* Polynesia */
2564 { 27082, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION
}, /* Central America */
2565 { 27114, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* Oceania */
2566 { 30967, {'S','X',0}, {'S','X','M',0}, 10039880, 534 }, /* Sint Maarten (Dutch part) */
2567 { 31396, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION
}, /* South America */
2568 { 31706, {'M','F',0}, {'M','A','F',0}, 10039880, 663 }, /* Saint Martin (French part) */
2569 { 39070, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* World */
2570 { 42483, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION
}, /* Western Africa */
2571 { 42484, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION
}, /* Middle Africa */
2572 { 42487, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION
}, /* Northern Africa */
2573 { 47590, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION
}, /* Central Asia */
2574 { 47599, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION
}, /* South-Eastern Asia */
2575 { 47600, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION
}, /* Eastern Asia */
2576 { 47603, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION
}, /* Eastern Africa */
2577 { 47609, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION
}, /* Eastern Europe */
2578 { 47610, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION
}, /* Southern Europe */
2579 { 47611, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION
}, /* Middle East */
2580 { 47614, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION
}, /* Southern Asia */
2581 { 7299303, {'T','L',0}, {'T','L','S',0}, 47599, 626 }, /* Democratic Republic of Timor-Leste */
2582 { 10026358, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION
}, /* Americas */
2583 { 10028789, {'A','X',0}, {'A','L','A',0}, 10039882, 248 }, /* Åland Islands */
2584 { 10039880, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION
}, /* Caribbean */
2585 { 10039882, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION
}, /* Northern Europe */
2586 { 10039883, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION
}, /* Southern Africa */
2587 { 10210824, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION
}, /* Western Europe */
2588 { 10210825, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION
}, /* Australia and New Zealand */
2589 { 161832015, {'B','L',0}, {'B','L','M',0}, 10039880, 652 }, /* Saint Barthélemy */
2590 { 161832256, {'U','M',0}, {'U','M','I',0}, 27114, 581 }, /* U.S. Minor Outlying Islands */
2591 { 161832257, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION
}, /* Latin America and the Caribbean */
2594 /******************************************************************************
2595 * EnumLanguageGroupLocalesA (KERNEL32.@)
2597 * Call a users function for every locale in a language group available on the system.
2600 * pLangGrpLcEnumProc [I] Callback function to call for each locale
2601 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
2602 * dwFlags [I] Reserved, set to 0
2603 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
2607 * Failure: FALSE. Use GetLastError() to determine the cause.
2609 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
2610 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2612 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2614 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2616 callbacks
.procA
= pLangGrpLcEnumProc
;
2617 callbacks
.procW
= NULL
;
2618 callbacks
.dwFlags
= dwFlags
;
2619 callbacks
.lgrpid
= lgrpid
;
2620 callbacks
.lParam
= lParam
;
2622 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2625 /******************************************************************************
2626 * EnumLanguageGroupLocalesW (KERNEL32.@)
2628 * See EnumLanguageGroupLocalesA.
2630 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
2631 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2633 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2635 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2637 callbacks
.procA
= NULL
;
2638 callbacks
.procW
= pLangGrpLcEnumProc
;
2639 callbacks
.dwFlags
= dwFlags
;
2640 callbacks
.lgrpid
= lgrpid
;
2641 callbacks
.lParam
= lParam
;
2643 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2646 /* Callback function ptrs for EnumSystemCodePagesA/W */
2649 CODEPAGE_ENUMPROCA procA
;
2650 CODEPAGE_ENUMPROCW procW
;
2652 } ENUMSYSTEMCODEPAGES_CALLBACKS
;
2654 /* Internal implementation of EnumSystemCodePagesA/W */
2655 static BOOL
NLS_EnumSystemCodePages(ENUMSYSTEMCODEPAGES_CALLBACKS
*lpProcs
)
2657 WCHAR szNumber
[5 + 1], szValue
[MAX_PATH
];
2659 BOOL bContinue
= TRUE
;
2664 SetLastError(ERROR_INVALID_PARAMETER
);
2668 switch (lpProcs
->dwFlags
)
2674 SetLastError(ERROR_INVALID_FLAGS
);
2678 hKey
= NLS_RegOpenKey(0, L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
2681 WARN("NLS_RegOpenKey() failed\n");
2687 if (NLS_RegEnumValue(hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2688 szValue
, sizeof(szValue
)))
2690 if ((lpProcs
->dwFlags
== CP_SUPPORTED
)||
2691 ((lpProcs
->dwFlags
== CP_INSTALLED
)&&(wcslen(szValue
) > 2)))
2695 bContinue
= lpProcs
->procW(szNumber
);
2699 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2701 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2702 bContinue
= lpProcs
->procA(szNumberA
);
2708 } else bContinue
= FALSE
;
2725 EnumSystemCodePagesW (
2726 CODEPAGE_ENUMPROCW lpCodePageEnumProc
,
2730 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2732 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2735 procs
.procW
= lpCodePageEnumProc
;
2736 procs
.dwFlags
= dwFlags
;
2738 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2747 EnumSystemCodePagesA (
2748 CODEPAGE_ENUMPROCA lpCodePageEnumProc
,
2752 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2754 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2756 procs
.procA
= lpCodePageEnumProc
;
2758 procs
.dwFlags
= dwFlags
;
2760 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2763 /******************************************************************************
2764 * EnumSystemGeoID (KERNEL32.@)
2766 * Call a users function for every location available on the system.
2769 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
2770 * parent [I] GEOID for the parent
2771 * enumproc [I] Callback function to call for each location
2775 * Failure: FALSE. Use GetLastError() to determine the cause.
2777 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID parent
, GEO_ENUMPROC enumproc
)
2781 TRACE("(%d, %d, %p)\n", geoclass
, parent
, enumproc
);
2784 SetLastError(ERROR_INVALID_PARAMETER
);
2788 if (geoclass
!= GEOCLASS_NATION
&& geoclass
!= GEOCLASS_REGION
) {
2789 SetLastError(ERROR_INVALID_FLAGS
);
2793 for (i
= 0; i
< sizeof(geoinfodata
)/sizeof(struct geoinfo_t
); i
++) {
2794 const struct geoinfo_t
*ptr
= &geoinfodata
[i
];
2796 if (geoclass
== GEOCLASS_NATION
&& (ptr
->kind
== LOCATION_REGION
))
2799 if (geoclass
== GEOCLASS_REGION
&& (ptr
->kind
== LOCATION_NATION
))
2802 if (parent
&& ptr
->parent
!= parent
)
2805 if (!enumproc(ptr
->id
))
2812 /******************************************************************************
2813 * InvalidateNLSCache (KERNEL32.@)
2815 * Invalidate the cache of NLS values.
2824 BOOL WINAPI
InvalidateNLSCache(void)
2830 /******************************************************************************
2831 * GetUserGeoID (KERNEL32.@)
2833 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
2835 GEOID ret
= GEOID_NOT_AVAILABLE
;
2836 static const WCHAR geoW
[] = {'G','e','o',0};
2837 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
2838 WCHAR bufferW
[40], *end
;
2840 HANDLE hkey
, hSubkey
= 0;
2841 UNICODE_STRING keyW
;
2842 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
2843 RtlInitUnicodeString( &keyW
, nationW
);
2844 count
= sizeof(bufferW
);
2846 if(!(hkey
= create_registry_key())) return ret
;
2849 case GEOCLASS_NATION
:
2850 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
2852 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
2853 bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
2854 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
2857 case GEOCLASS_REGION
:
2858 FIXME("GEOCLASS_REGION not handled yet\n");
2863 if (hSubkey
) NtClose(hSubkey
);
2867 /******************************************************************************
2868 * SetUserGeoID (KERNEL32.@)
2870 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
2872 static const WCHAR geoW
[] = {'G','e','o',0};
2873 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
2874 static const WCHAR formatW
[] = {'%','i',0};
2875 UNICODE_STRING nameW
,keyW
;
2877 OBJECT_ATTRIBUTES attr
;
2880 if(!(hkey
= create_registry_key())) return FALSE
;
2882 attr
.Length
= sizeof(attr
);
2883 attr
.RootDirectory
= hkey
;
2884 attr
.ObjectName
= &nameW
;
2885 attr
.Attributes
= 0;
2886 attr
.SecurityDescriptor
= NULL
;
2887 attr
.SecurityQualityOfService
= NULL
;
2888 RtlInitUnicodeString( &nameW
, geoW
);
2889 RtlInitUnicodeString( &keyW
, nationW
);
2891 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
2894 NtClose(attr
.RootDirectory
);
2898 sprintfW(bufferW
, formatW
, GeoID
);
2899 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
2900 NtClose(attr
.RootDirectory
);
2909 UILANGUAGE_ENUMPROCA procA
;
2910 UILANGUAGE_ENUMPROCW procW
;
2914 } ENUM_UILANG_CALLBACK
;
2916 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
2917 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
2919 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2922 sprintf(buf
, "%08x", (UINT
)LangID
);
2923 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
2926 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
2927 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
2929 static const WCHAR formatW
[] = {'%','0','8','x',0};
2930 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2933 sprintfW( buf
, formatW
, (UINT
)LangID
);
2934 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
2937 /******************************************************************************
2938 * EnumUILanguagesA (KERNEL32.@)
2940 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2942 ENUM_UILANG_CALLBACK enum_uilang
;
2944 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2946 if(!pUILangEnumProc
) {
2947 SetLastError(ERROR_INVALID_PARAMETER
);
2951 SetLastError(ERROR_INVALID_FLAGS
);
2955 enum_uilang
.u
.procA
= pUILangEnumProc
;
2956 enum_uilang
.flags
= dwFlags
;
2957 enum_uilang
.param
= lParam
;
2959 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
2960 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
2961 (LONG_PTR
)&enum_uilang
);
2965 /******************************************************************************
2966 * EnumUILanguagesW (KERNEL32.@)
2968 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2970 ENUM_UILANG_CALLBACK enum_uilang
;
2972 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2975 if(!pUILangEnumProc
) {
2976 SetLastError(ERROR_INVALID_PARAMETER
);
2980 SetLastError(ERROR_INVALID_FLAGS
);
2984 enum_uilang
.u
.procW
= pUILangEnumProc
;
2985 enum_uilang
.flags
= dwFlags
;
2986 enum_uilang
.param
= lParam
;
2988 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
2989 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
2990 (LONG_PTR
)&enum_uilang
);
2995 NLS_GetGeoFriendlyName(GEOID Location
, LPWSTR szFriendlyName
, int cchData
)
3000 /* FIXME: move *.nls resources out of kernel32 into locale.nls */
3001 Location
+= NLSRC_OFFSET
;
3004 return GetLocalisedText(Location
, NULL
, 0);
3006 dwSize
= cchData
* sizeof(WCHAR
);
3007 szBuffer
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
3011 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3015 if(GetLocalisedText(Location
, szBuffer
, dwSize
))
3017 memcpy(szFriendlyName
, szBuffer
, dwSize
);
3018 HeapFree(GetProcessHeap(), 0, szBuffer
);
3019 return strlenW(szFriendlyName
) + 1;
3022 HeapFree(GetProcessHeap(), 0, szBuffer
);
3026 static const struct geoinfo_t
*get_geoinfo_dataptr(GEOID geoid
)
3031 max
= sizeof(geoinfodata
)/sizeof(struct geoinfo_t
)-1;
3033 while (min
<= max
) {
3034 const struct geoinfo_t
*ptr
;
3035 int n
= (min
+max
)/2;
3037 ptr
= &geoinfodata
[n
];
3038 if (geoid
== ptr
->id
)
3039 /* we don't need empty entry */
3040 return *ptr
->iso2W
? ptr
: NULL
;
3042 if (ptr
->id
> geoid
)
3051 /******************************************************************************
3052 * GetGeoInfoW (KERNEL32.@)
3054 INT WINAPI
GetGeoInfoW(GEOID geoid
, GEOTYPE geotype
, LPWSTR data
, int data_len
, LANGID lang
)
3056 const struct geoinfo_t
*ptr
;
3057 const WCHAR
*str
= NULL
;
3062 TRACE("%d %d %p %d %d\n", geoid
, geotype
, data
, data_len
, lang
);
3064 if (!(ptr
= get_geoinfo_dataptr(geoid
))) {
3065 SetLastError(ERROR_INVALID_PARAMETER
);
3070 case GEO_FRIENDLYNAME
:
3072 return NLS_GetGeoFriendlyName(geoid
, data
, data_len
);
3077 case GEO_ISO_UN_NUMBER
:
3086 str
= geotype
== GEO_ISO2
? ptr
->iso2W
: ptr
->iso3W
;
3091 case GEO_OFFICIALNAME
:
3093 case GEO_OFFICIALLANGUAGES
:
3096 FIXME("type %d is not supported\n", geotype
);
3097 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3100 WARN("unrecognized type %d\n", geotype
);
3101 SetLastError(ERROR_INVALID_FLAGS
);
3106 static const WCHAR fmtW
[] = {'%','d',0};
3107 sprintfW(buffW
, fmtW
, val
);
3111 len
= strlenW(str
) + 1;
3112 if (!data
|| !data_len
)
3115 memcpy(data
, str
, min(len
, data_len
)*sizeof(WCHAR
));
3117 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3118 return data_len
< len
? 0 : len
;
3121 /******************************************************************************
3122 * GetGeoInfoA (KERNEL32.@)
3124 INT WINAPI
GetGeoInfoA(GEOID geoid
, GEOTYPE geotype
, LPSTR data
, int data_len
, LANGID lang
)
3129 TRACE("%d %d %p %d %d\n", geoid
, geotype
, data
, data_len
, lang
);
3131 len
= GetGeoInfoW(geoid
, geotype
, NULL
, 0, lang
);
3135 buffW
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
3139 GetGeoInfoW(geoid
, geotype
, buffW
, len
, lang
);
3140 len
= WideCharToMultiByte(CP_ACP
, 0, buffW
, -1, NULL
, 0, NULL
, NULL
);
3141 if (!data
|| !data_len
) {
3142 HeapFree(GetProcessHeap(), 0, buffW
);
3146 len
= WideCharToMultiByte(CP_ACP
, 0, buffW
, -1, data
, data_len
, NULL
, NULL
);
3147 HeapFree(GetProcessHeap(), 0, buffW
);
3150 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3151 return data_len
< len
? 0 : len
;