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
25 #include "wine/port.h"
36 # include <CoreFoundation/CFBundle.h>
37 # include <CoreFoundation/CFLocale.h>
38 # include <CoreFoundation/CFString.h>
42 #define WIN32_NO_STATUS
45 #include "winuser.h" /* for RT_STRINGW */
47 #include "wine/unicode.h"
51 #include "kernel_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(nls
);
56 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
58 /* current code pages */
59 static const union cptable
*ansi_cptable
;
60 static const union cptable
*oem_cptable
;
61 static const union cptable
*mac_cptable
;
62 static const union cptable
*unix_cptable
; /* NULL if UTF8 */
64 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
);
66 static const WCHAR szNlsKeyName
[] = {
67 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
68 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
69 'C','o','n','t','r','o','l','\\','N','l','s','\0'
72 static const WCHAR szLocaleKeyName
[] = {
73 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
74 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
75 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
78 static const WCHAR szCodepageKeyName
[] = {
79 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
80 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
81 'C','o','n','t','r','o','l','\\','N','l','s','\\','C','o','d','e','p','a','g','e',0
84 static const WCHAR szLangGroupsKeyName
[] = {
85 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
86 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
87 'C','o','n','t','r','o','l','\\','N','l','s','\\',
88 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
91 /* Charset to codepage map, sorted by name. */
92 static const struct charset_entry
94 const char *charset_name
;
133 { "ISO88591", 28591 },
134 { "ISO885910", 28600 },
135 { "ISO885913", 28603 },
136 { "ISO885914", 28604 },
137 { "ISO885915", 28605 },
138 { "ISO885916", 28606 },
139 { "ISO88592", 28592 },
140 { "ISO88593", 28593 },
141 { "ISO88594", 28594 },
142 { "ISO88595", 28595 },
143 { "ISO88596", 28596 },
144 { "ISO88597", 28597 },
145 { "ISO88598", 28598 },
146 { "ISO88599", 28599 },
155 WCHAR win_name
[128]; /* Windows name ("en-US") */
156 WCHAR lang
[128]; /* language ("en") (note: buffer contains the other strings too) */
157 WCHAR
*country
; /* country ("US") */
158 WCHAR
*charset
; /* charset ("UTF-8") for Unix format only */
159 WCHAR
*script
; /* script ("Latn") for Windows format only */
160 WCHAR
*modifier
; /* modifier or sort order */
161 LCID lcid
; /* corresponding LCID */
162 int matches
; /* number of elements matching LCID (0..4) */
163 UINT codepage
; /* codepage corresponding to charset */
166 /* locale ids corresponding to the various Unix locale parameters */
167 static LCID lcid_LC_COLLATE
;
168 static LCID lcid_LC_CTYPE
;
169 static LCID lcid_LC_MESSAGES
;
170 static LCID lcid_LC_MONETARY
;
171 static LCID lcid_LC_NUMERIC
;
172 static LCID lcid_LC_TIME
;
173 static LCID lcid_LC_PAPER
;
174 static LCID lcid_LC_MEASUREMENT
;
175 static LCID lcid_LC_TELEPHONE
;
177 /* Copy Ascii string to Unicode without using codepages */
178 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
180 while (n
> 1 && *src
)
182 *dst
++ = (unsigned char)*src
++;
189 /***********************************************************************
192 * Retrieve the ANSI codepage for a given locale.
194 static inline UINT
get_lcid_codepage( LCID lcid
)
197 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
198 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
203 /***********************************************************************
206 * Find the table for a given codepage, handling CP_ACP etc. pseudo-codepages
208 static const union cptable
*get_codepage_table( unsigned int codepage
)
210 const union cptable
*ret
= NULL
;
212 assert( ansi_cptable
); /* init must have been done already */
226 if (!(codepage
= kernel_get_thread_data()->code_page
)) return ansi_cptable
;
229 if (codepage
== ansi_cptable
->info
.codepage
) return ansi_cptable
;
230 if (codepage
== oem_cptable
->info
.codepage
) return oem_cptable
;
231 if (codepage
== mac_cptable
->info
.codepage
) return mac_cptable
;
232 ret
= wine_cp_get_table( codepage
);
239 /***********************************************************************
240 * charset_cmp (internal)
242 static int charset_cmp( const void *name
, const void *entry
)
244 const struct charset_entry
*charset
= (const struct charset_entry
*)entry
;
245 return strcasecmp( (const char *)name
, charset
->charset_name
);
248 /***********************************************************************
251 static UINT
find_charset( const WCHAR
*name
)
253 const struct charset_entry
*entry
;
254 char charset_name
[16];
257 /* remove punctuation characters from charset name */
258 for (i
= j
= 0; name
[i
] && j
< sizeof(charset_name
)-1; i
++)
259 if (isalnum((unsigned char)name
[i
])) charset_name
[j
++] = name
[i
];
262 entry
= bsearch( charset_name
, charset_names
,
263 sizeof(charset_names
)/sizeof(charset_names
[0]),
264 sizeof(charset_names
[0]), charset_cmp
);
265 if (entry
) return entry
->codepage
;
270 /***********************************************************************
271 * find_locale_id_callback
273 static BOOL CALLBACK
find_locale_id_callback( HMODULE hModule
, LPCWSTR type
,
274 LPCWSTR name
, WORD LangID
, LPARAM lParam
)
276 struct locale_name
*data
= (struct locale_name
*)lParam
;
279 LCID lcid
= MAKELCID( LangID
, SORT_DEFAULT
); /* FIXME: handle sort order */
281 if (PRIMARYLANGID(LangID
) == LANG_NEUTRAL
) return TRUE
; /* continue search */
283 /* first check exact name */
284 if (data
->win_name
[0] &&
285 GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
,
286 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
288 if (!strcmpW( data
->win_name
, buffer
))
290 matches
= 4; /* everything matches */
295 if (!GetLocaleInfoW( lcid
, LOCALE_SISO639LANGNAME
| LOCALE_NOUSEROVERRIDE
,
296 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
298 if (strcmpW( buffer
, data
->lang
)) return TRUE
;
299 matches
++; /* language name matched */
303 if (GetLocaleInfoW( lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
304 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
306 if (strcmpW( buffer
, data
->country
)) goto done
;
307 matches
++; /* country name matched */
310 else /* match default language */
312 if (SUBLANGID(LangID
) == SUBLANG_DEFAULT
) matches
++;
318 if (GetLocaleInfoW( lcid
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
319 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) ))
321 if (unix_cp
== data
->codepage
) matches
++;
325 /* FIXME: check sort order */
328 if (matches
> data
->matches
)
331 data
->matches
= matches
;
333 return (data
->matches
< 4); /* no need to continue for perfect match */
337 /***********************************************************************
340 * Parse a locale name into a struct locale_name, handling both Windows and Unix formats.
341 * Unix format is: lang[_country][.charset][@modifier]
342 * Windows format is: lang[-script][-country][_modifier]
344 static void parse_locale_name( const WCHAR
*str
, struct locale_name
*name
)
346 static const WCHAR sepW
[] = {'-','_','.','@',0};
347 static const WCHAR winsepW
[] = {'-','_',0};
348 static const WCHAR posixW
[] = {'P','O','S','I','X',0};
349 static const WCHAR cW
[] = {'C',0};
350 static const WCHAR latinW
[] = {'l','a','t','i','n',0};
351 static const WCHAR latnW
[] = {'-','L','a','t','n',0};
354 name
->country
= name
->charset
= name
->script
= name
->modifier
= NULL
;
355 name
->lcid
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
358 name
->win_name
[0] = 0;
359 lstrcpynW( name
->lang
, str
, sizeof(name
->lang
)/sizeof(WCHAR
) );
361 if (!(p
= strpbrkW( name
->lang
, sepW
)))
363 if (!strcmpW( name
->lang
, posixW
) || !strcmpW( name
->lang
, cW
))
365 name
->matches
= 4; /* perfect match for default English lcid */
368 strcpyW( name
->win_name
, name
->lang
);
370 else if (*p
== '-') /* Windows format */
372 strcpyW( name
->win_name
, name
->lang
);
375 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
379 name
->script
= name
->country
;
381 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
386 else /* Unix format */
392 p
= strpbrkW( p
, sepW
+ 2 );
398 name
->codepage
= find_charset( name
->charset
);
399 p
= strchrW( p
, '@' );
407 /* rebuild a Windows name if possible */
409 if (name
->charset
) goto done
; /* can't specify charset in Windows format */
410 if (name
->modifier
&& strcmpW( name
->modifier
, latinW
))
411 goto done
; /* only Latn script supported for now */
412 strcpyW( name
->win_name
, name
->lang
);
413 if (name
->modifier
) strcatW( name
->win_name
, latnW
);
416 p
= name
->win_name
+ strlenW(name
->win_name
);
418 strcpyW( p
, name
->country
);
422 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
, (LPCWSTR
)LOCALE_ILANGUAGE
,
423 find_locale_id_callback
, (LPARAM
)name
);
427 /***********************************************************************
428 * convert_default_lcid
430 * Get the default LCID to use for a given lctype in GetLocaleInfo.
432 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
434 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
435 lcid
== LOCALE_USER_DEFAULT
||
436 lcid
== LOCALE_NEUTRAL
)
440 switch(lctype
& 0xffff)
442 case LOCALE_SSORTNAME
:
443 default_id
= lcid_LC_COLLATE
;
446 case LOCALE_FONTSIGNATURE
:
447 case LOCALE_IDEFAULTANSICODEPAGE
:
448 case LOCALE_IDEFAULTCODEPAGE
:
449 case LOCALE_IDEFAULTEBCDICCODEPAGE
:
450 case LOCALE_IDEFAULTMACCODEPAGE
:
451 case LOCALE_IDEFAULTUNIXCODEPAGE
:
452 default_id
= lcid_LC_CTYPE
;
455 case LOCALE_ICURRDIGITS
:
456 case LOCALE_ICURRENCY
:
457 case LOCALE_IINTLCURRDIGITS
:
458 case LOCALE_INEGCURR
:
459 case LOCALE_INEGSEPBYSPACE
:
460 case LOCALE_INEGSIGNPOSN
:
461 case LOCALE_INEGSYMPRECEDES
:
462 case LOCALE_IPOSSEPBYSPACE
:
463 case LOCALE_IPOSSIGNPOSN
:
464 case LOCALE_IPOSSYMPRECEDES
:
465 case LOCALE_SCURRENCY
:
466 case LOCALE_SINTLSYMBOL
:
467 case LOCALE_SMONDECIMALSEP
:
468 case LOCALE_SMONGROUPING
:
469 case LOCALE_SMONTHOUSANDSEP
:
470 case LOCALE_SNATIVECURRNAME
:
471 default_id
= lcid_LC_MONETARY
;
475 case LOCALE_IDIGITSUBSTITUTION
:
477 case LOCALE_INEGNUMBER
:
478 case LOCALE_SDECIMAL
:
479 case LOCALE_SGROUPING
:
481 case LOCALE_SNATIVEDIGITS
:
482 case LOCALE_SNEGATIVESIGN
:
483 case LOCALE_SNEGINFINITY
:
484 case LOCALE_SPOSINFINITY
:
485 case LOCALE_SPOSITIVESIGN
:
486 case LOCALE_STHOUSAND
:
487 default_id
= lcid_LC_NUMERIC
;
490 case LOCALE_ICALENDARTYPE
:
491 case LOCALE_ICENTURY
:
493 case LOCALE_IDAYLZERO
:
494 case LOCALE_IFIRSTDAYOFWEEK
:
495 case LOCALE_IFIRSTWEEKOFYEAR
:
497 case LOCALE_IMONLZERO
:
498 case LOCALE_IOPTIONALCALENDAR
:
500 case LOCALE_ITIMEMARKPOSN
:
504 case LOCALE_SABBREVDAYNAME1
:
505 case LOCALE_SABBREVDAYNAME2
:
506 case LOCALE_SABBREVDAYNAME3
:
507 case LOCALE_SABBREVDAYNAME4
:
508 case LOCALE_SABBREVDAYNAME5
:
509 case LOCALE_SABBREVDAYNAME6
:
510 case LOCALE_SABBREVDAYNAME7
:
511 case LOCALE_SABBREVMONTHNAME1
:
512 case LOCALE_SABBREVMONTHNAME2
:
513 case LOCALE_SABBREVMONTHNAME3
:
514 case LOCALE_SABBREVMONTHNAME4
:
515 case LOCALE_SABBREVMONTHNAME5
:
516 case LOCALE_SABBREVMONTHNAME6
:
517 case LOCALE_SABBREVMONTHNAME7
:
518 case LOCALE_SABBREVMONTHNAME8
:
519 case LOCALE_SABBREVMONTHNAME9
:
520 case LOCALE_SABBREVMONTHNAME10
:
521 case LOCALE_SABBREVMONTHNAME11
:
522 case LOCALE_SABBREVMONTHNAME12
:
523 case LOCALE_SABBREVMONTHNAME13
:
525 case LOCALE_SDAYNAME1
:
526 case LOCALE_SDAYNAME2
:
527 case LOCALE_SDAYNAME3
:
528 case LOCALE_SDAYNAME4
:
529 case LOCALE_SDAYNAME5
:
530 case LOCALE_SDAYNAME6
:
531 case LOCALE_SDAYNAME7
:
532 case LOCALE_SDURATION
:
533 case LOCALE_SLONGDATE
:
534 case LOCALE_SMONTHNAME1
:
535 case LOCALE_SMONTHNAME2
:
536 case LOCALE_SMONTHNAME3
:
537 case LOCALE_SMONTHNAME4
:
538 case LOCALE_SMONTHNAME5
:
539 case LOCALE_SMONTHNAME6
:
540 case LOCALE_SMONTHNAME7
:
541 case LOCALE_SMONTHNAME8
:
542 case LOCALE_SMONTHNAME9
:
543 case LOCALE_SMONTHNAME10
:
544 case LOCALE_SMONTHNAME11
:
545 case LOCALE_SMONTHNAME12
:
546 case LOCALE_SMONTHNAME13
:
547 case LOCALE_SSHORTDATE
:
548 case LOCALE_SSHORTESTDAYNAME1
:
549 case LOCALE_SSHORTESTDAYNAME2
:
550 case LOCALE_SSHORTESTDAYNAME3
:
551 case LOCALE_SSHORTESTDAYNAME4
:
552 case LOCALE_SSHORTESTDAYNAME5
:
553 case LOCALE_SSHORTESTDAYNAME6
:
554 case LOCALE_SSHORTESTDAYNAME7
:
556 case LOCALE_STIMEFORMAT
:
557 case LOCALE_SYEARMONTH
:
558 default_id
= lcid_LC_TIME
;
561 case LOCALE_IPAPERSIZE
:
562 default_id
= lcid_LC_PAPER
;
565 case LOCALE_IMEASURE
:
566 default_id
= lcid_LC_MEASUREMENT
;
569 case LOCALE_ICOUNTRY
:
570 default_id
= lcid_LC_TELEPHONE
;
573 if (default_id
) lcid
= default_id
;
575 return ConvertDefaultLocale( lcid
);
579 /***********************************************************************
580 * create_registry_key
582 * Create the Control Panel\\International registry key.
584 static inline HANDLE
create_registry_key(void)
586 static const WCHAR intlW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
587 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
588 OBJECT_ATTRIBUTES attr
;
589 UNICODE_STRING nameW
;
592 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
594 attr
.Length
= sizeof(attr
);
595 attr
.RootDirectory
= hkey
;
596 attr
.ObjectName
= &nameW
;
598 attr
.SecurityDescriptor
= NULL
;
599 attr
.SecurityQualityOfService
= NULL
;
600 RtlInitUnicodeString( &nameW
, intlW
);
602 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) hkey
= 0;
603 NtClose( attr
.RootDirectory
);
608 /* update the registry settings for a given locale parameter */
609 /* return TRUE if an update was needed */
610 static BOOL
locale_update_registry( HKEY hkey
, const WCHAR
*name
, LCID lcid
,
611 const LCTYPE
*values
, UINT nb_values
)
613 static const WCHAR formatW
[] = { '%','0','8','x',0 };
615 UNICODE_STRING nameW
;
618 RtlInitUnicodeString( &nameW
, name
);
619 count
= sizeof(bufferW
);
620 if (!NtQueryValueKey(hkey
, &nameW
, KeyValuePartialInformation
, (LPBYTE
)bufferW
, count
, &count
))
622 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
623 LPCWSTR text
= (LPCWSTR
)info
->Data
;
625 if (strtoulW( text
, NULL
, 16 ) == lcid
) return FALSE
; /* already set correctly */
626 TRACE( "updating registry, locale %s changed %s -> %08x\n",
627 debugstr_w(name
), debugstr_w(text
), lcid
);
629 else TRACE( "updating registry, locale %s changed none -> %08x\n", debugstr_w(name
), lcid
);
630 sprintfW( bufferW
, formatW
, lcid
);
631 NtSetValueKey( hkey
, &nameW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
) );
633 for (i
= 0; i
< nb_values
; i
++)
635 GetLocaleInfoW( lcid
, values
[i
] | LOCALE_NOUSEROVERRIDE
, bufferW
,
636 sizeof(bufferW
)/sizeof(WCHAR
) );
637 SetLocaleInfoW( lcid
, values
[i
], bufferW
);
643 /***********************************************************************
644 * LOCALE_InitRegistry
646 * Update registry contents on startup if the user locale has changed.
647 * This simulates the action of the Windows control panel.
649 void LOCALE_InitRegistry(void)
651 static const WCHAR acpW
[] = {'A','C','P',0};
652 static const WCHAR oemcpW
[] = {'O','E','M','C','P',0};
653 static const WCHAR maccpW
[] = {'M','A','C','C','P',0};
654 static const WCHAR localeW
[] = {'L','o','c','a','l','e',0};
655 static const WCHAR lc_ctypeW
[] = { 'L','C','_','C','T','Y','P','E',0 };
656 static const WCHAR lc_monetaryW
[] = { 'L','C','_','M','O','N','E','T','A','R','Y',0 };
657 static const WCHAR lc_numericW
[] = { 'L','C','_','N','U','M','E','R','I','C',0 };
658 static const WCHAR lc_timeW
[] = { 'L','C','_','T','I','M','E',0 };
659 static const WCHAR lc_measurementW
[] = { 'L','C','_','M','E','A','S','U','R','E','M','E','N','T',0 };
660 static const WCHAR lc_telephoneW
[] = { 'L','C','_','T','E','L','E','P','H','O','N','E',0 };
661 static const WCHAR lc_paperW
[] = { 'L','C','_','P','A','P','E','R',0};
666 } update_cp_values
[] = {
667 { acpW
, LOCALE_IDEFAULTANSICODEPAGE
},
668 { oemcpW
, LOCALE_IDEFAULTCODEPAGE
},
669 { maccpW
, LOCALE_IDEFAULTMACCODEPAGE
}
671 static const LCTYPE lc_messages_values
[] = {
675 static const LCTYPE lc_monetary_values
[] = {
681 LOCALE_SMONDECIMALSEP
,
683 LOCALE_SMONTHOUSANDSEP
};
684 static const LCTYPE lc_numeric_values
[] = {
688 LOCALE_IDIGITSUBSTITUTION
,
689 LOCALE_SNATIVEDIGITS
,
691 LOCALE_SNEGATIVESIGN
,
692 LOCALE_SPOSITIVESIGN
,
694 static const LCTYPE lc_time_values
[] = {
703 LOCALE_ITIMEMARKPOSN
,
704 LOCALE_ICALENDARTYPE
,
705 LOCALE_IFIRSTDAYOFWEEK
,
706 LOCALE_IFIRSTWEEKOFYEAR
,
710 static const LCTYPE lc_measurement_values
[] = { LOCALE_IMEASURE
};
711 static const LCTYPE lc_telephone_values
[] = { LOCALE_ICOUNTRY
};
712 static const LCTYPE lc_paper_values
[] = { LOCALE_IPAPERSIZE
};
714 UNICODE_STRING nameW
;
718 LCID lcid
= GetUserDefaultLCID();
720 if (!(hkey
= create_registry_key()))
721 return; /* don't do anything if we can't create the registry key */
723 locale_update_registry( hkey
, localeW
, lcid_LC_MESSAGES
, lc_messages_values
,
724 sizeof(lc_messages_values
)/sizeof(lc_messages_values
[0]) );
725 locale_update_registry( hkey
, lc_monetaryW
, lcid_LC_MONETARY
, lc_monetary_values
,
726 sizeof(lc_monetary_values
)/sizeof(lc_monetary_values
[0]) );
727 locale_update_registry( hkey
, lc_numericW
, lcid_LC_NUMERIC
, lc_numeric_values
,
728 sizeof(lc_numeric_values
)/sizeof(lc_numeric_values
[0]) );
729 locale_update_registry( hkey
, lc_timeW
, lcid_LC_TIME
, lc_time_values
,
730 sizeof(lc_time_values
)/sizeof(lc_time_values
[0]) );
731 locale_update_registry( hkey
, lc_measurementW
, lcid_LC_MEASUREMENT
, lc_measurement_values
,
732 sizeof(lc_measurement_values
)/sizeof(lc_measurement_values
[0]) );
733 locale_update_registry( hkey
, lc_telephoneW
, lcid_LC_TELEPHONE
, lc_telephone_values
,
734 sizeof(lc_telephone_values
)/sizeof(lc_telephone_values
[0]) );
735 locale_update_registry( hkey
, lc_paperW
, lcid_LC_PAPER
, lc_paper_values
,
736 sizeof(lc_paper_values
)/sizeof(lc_paper_values
[0]) );
738 if (locale_update_registry( hkey
, lc_ctypeW
, lcid_LC_CTYPE
, NULL
, 0 ))
740 HKEY nls_key
= NLS_RegOpenKey( 0, szCodepageKeyName
);
742 for (i
= 0; i
< sizeof(update_cp_values
)/sizeof(update_cp_values
[0]); i
++)
744 count
= GetLocaleInfoW( lcid
, update_cp_values
[i
].value
| LOCALE_NOUSEROVERRIDE
,
745 bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
746 RtlInitUnicodeString( &nameW
, update_cp_values
[i
].name
);
747 NtSetValueKey( nls_key
, &nameW
, 0, REG_SZ
, bufferW
, count
* sizeof(WCHAR
) );
756 /***********************************************************************
759 static UINT
setup_unix_locales(void)
761 struct locale_name locale_name
;
762 WCHAR buffer
[128], ctype_buff
[128];
766 if ((locale
= setlocale( LC_CTYPE
, NULL
)))
768 strcpynAtoW( ctype_buff
, locale
, sizeof(ctype_buff
)/sizeof(WCHAR
) );
769 parse_locale_name( ctype_buff
, &locale_name
);
770 lcid_LC_CTYPE
= locale_name
.lcid
;
771 unix_cp
= locale_name
.codepage
;
773 if (!lcid_LC_CTYPE
) /* this one needs a default value */
774 lcid_LC_CTYPE
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
776 TRACE( "got lcid %04x (%d matches) for LC_CTYPE=%s\n",
777 locale_name
.lcid
, locale_name
.matches
, debugstr_a(locale
) );
779 #define GET_UNIX_LOCALE(cat) do \
780 if ((locale = setlocale( cat, NULL ))) \
782 strcpynAtoW( buffer, locale, sizeof(buffer)/sizeof(WCHAR) ); \
783 if (!strcmpW( buffer, ctype_buff )) lcid_##cat = lcid_LC_CTYPE; \
785 parse_locale_name( buffer, &locale_name ); \
786 lcid_##cat = locale_name.lcid; \
787 TRACE( "got lcid %04x (%d matches) for " #cat "=%s\n", \
788 locale_name.lcid, locale_name.matches, debugstr_a(locale) ); \
792 GET_UNIX_LOCALE( LC_COLLATE
);
793 GET_UNIX_LOCALE( LC_MESSAGES
);
794 GET_UNIX_LOCALE( LC_MONETARY
);
795 GET_UNIX_LOCALE( LC_NUMERIC
);
796 GET_UNIX_LOCALE( LC_TIME
);
798 GET_UNIX_LOCALE( LC_PAPER
);
800 #ifdef LC_MEASUREMENT
801 GET_UNIX_LOCALE( LC_MEASUREMENT
);
804 GET_UNIX_LOCALE( LC_TELEPHONE
);
807 #undef GET_UNIX_LOCALE
813 /***********************************************************************
814 * GetUserDefaultLangID (KERNEL32.@)
816 * Get the default language Id for the current user.
822 * The current LANGID of the default language for the current user.
824 LANGID WINAPI
GetUserDefaultLangID(void)
826 return LANGIDFROMLCID(GetUserDefaultLCID());
830 /***********************************************************************
831 * GetSystemDefaultLangID (KERNEL32.@)
833 * Get the default language Id for the system.
839 * The current LANGID of the default language for the system.
841 LANGID WINAPI
GetSystemDefaultLangID(void)
843 return LANGIDFROMLCID(GetSystemDefaultLCID());
847 /***********************************************************************
848 * GetUserDefaultLCID (KERNEL32.@)
850 * Get the default locale Id for the current user.
856 * The current LCID of the default locale for the current user.
858 LCID WINAPI
GetUserDefaultLCID(void)
861 NtQueryDefaultLocale( TRUE
, &lcid
);
866 /***********************************************************************
867 * GetSystemDefaultLCID (KERNEL32.@)
869 * Get the default locale Id for the system.
875 * The current LCID of the default locale for the system.
877 LCID WINAPI
GetSystemDefaultLCID(void)
880 NtQueryDefaultLocale( FALSE
, &lcid
);
885 /***********************************************************************
886 * GetUserDefaultUILanguage (KERNEL32.@)
888 * Get the default user interface language Id for the current user.
894 * The current LANGID of the default UI language for the current user.
896 LANGID WINAPI
GetUserDefaultUILanguage(void)
899 NtQueryDefaultUILanguage( &lang
);
904 /***********************************************************************
905 * GetSystemDefaultUILanguage (KERNEL32.@)
907 * Get the default user interface language Id for the system.
913 * The current LANGID of the default UI language for the system. This is
914 * typically the same language used during the installation process.
916 LANGID WINAPI
GetSystemDefaultUILanguage(void)
919 NtQueryInstallUILanguage( &lang
);
924 /***********************************************************************
925 * LocaleNameToLCID (KERNEL32.@)
927 LCID WINAPI
LocaleNameToLCID( LPCWSTR name
, DWORD flags
)
929 struct locale_name locale_name
;
931 if (flags
) FIXME( "unsupported flags %x\n", flags
);
933 parse_locale_name( name
, &locale_name
);
935 TRACE( "found lcid %x for %s, matches %d\n",
936 locale_name
.lcid
, debugstr_w(name
), locale_name
.matches
);
938 if (!locale_name
.matches
)
939 WARN( "locale %s not recognized, defaulting to English\n", debugstr_w(name
) );
940 else if (locale_name
.matches
== 1)
941 WARN( "locale %s not recognized, defaulting to %s\n",
942 debugstr_w(name
), debugstr_w(locale_name
.lang
) );
944 return locale_name
.lcid
;
948 /***********************************************************************
949 * LCIDToLocaleName (KERNEL32.@)
951 INT WINAPI
LCIDToLocaleName( LCID lcid
, LPWSTR name
, INT count
, DWORD flags
)
953 if (flags
) FIXME( "unsupported flags %x\n", flags
);
955 return GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, name
, count
);
959 /******************************************************************************
960 * get_locale_value_name
962 * Gets the registry value name for a given lctype.
964 static const WCHAR
*get_locale_value_name( DWORD lctype
)
966 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
967 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
968 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
969 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
970 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
971 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
972 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
973 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
974 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
975 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
976 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
977 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
978 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
979 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
980 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
981 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
982 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
983 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
984 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
985 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
986 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
987 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
988 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
989 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
990 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
991 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
992 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
993 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
994 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
995 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
996 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
997 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
998 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
999 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
1000 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
1001 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
1002 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
1003 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
1004 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
1008 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
1009 * the values are stored in the registry, confirmed under Windows.
1011 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
1012 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
1013 case LOCALE_ICURRENCY
: return iCurrencyW
;
1014 case LOCALE_IDIGITS
: return iDigitsW
;
1015 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
1016 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
1017 case LOCALE_ILZERO
: return iLZeroW
;
1018 case LOCALE_IMEASURE
: return iMeasureW
;
1019 case LOCALE_INEGCURR
: return iNegCurrW
;
1020 case LOCALE_INEGNUMBER
: return iNegNumberW
;
1021 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
1022 case LOCALE_ITIME
: return iTimeW
;
1023 case LOCALE_S1159
: return s1159W
;
1024 case LOCALE_S2359
: return s2359W
;
1025 case LOCALE_SCURRENCY
: return sCurrencyW
;
1026 case LOCALE_SDATE
: return sDateW
;
1027 case LOCALE_SDECIMAL
: return sDecimalW
;
1028 case LOCALE_SGROUPING
: return sGroupingW
;
1029 case LOCALE_SLIST
: return sListW
;
1030 case LOCALE_SLONGDATE
: return sLongDateW
;
1031 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
1032 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
1033 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
1034 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
1035 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
1036 case LOCALE_SSHORTDATE
: return sShortDateW
;
1037 case LOCALE_STHOUSAND
: return sThousandW
;
1038 case LOCALE_STIME
: return sTimeW
;
1039 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
1040 case LOCALE_SYEARMONTH
: return sYearMonthW
;
1042 /* The following are not listed under MSDN as supported,
1043 * but seem to be used and also stored in the registry.
1045 case LOCALE_ICOUNTRY
: return iCountryW
;
1046 case LOCALE_IDATE
: return iDateW
;
1047 case LOCALE_ILDATE
: return iLDateW
;
1048 case LOCALE_ITLZERO
: return iTLZeroW
;
1049 case LOCALE_SCOUNTRY
: return sCountryW
;
1050 case LOCALE_SLANGUAGE
: return sLanguageW
;
1052 /* The following are used in XP and later */
1053 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
1054 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
1055 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
1061 /******************************************************************************
1062 * get_registry_locale_info
1064 * Retrieve user-modified locale info from the registry.
1065 * Return length, 0 on error, -1 if not found.
1067 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
1073 UNICODE_STRING nameW
;
1074 KEY_VALUE_PARTIAL_INFORMATION
*info
;
1075 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
1077 if (!(hkey
= create_registry_key())) return -1;
1079 RtlInitUnicodeString( &nameW
, value
);
1080 size
= info_size
+ len
* sizeof(WCHAR
);
1082 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
1085 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1089 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
1093 ret
= (size
- info_size
) / sizeof(WCHAR
);
1094 /* append terminating null if needed */
1095 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
1097 if (ret
< len
|| !buffer
) ret
++;
1100 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1106 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
1110 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
1112 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
1114 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
1120 SetLastError( RtlNtStatusToDosError(status
) );
1124 HeapFree( GetProcessHeap(), 0, info
);
1129 /******************************************************************************
1130 * GetLocaleInfoA (KERNEL32.@)
1132 * Get information about an aspect of a locale.
1135 * lcid [I] LCID of the locale
1136 * lctype [I] LCTYPE_ flags from "winnls.h"
1137 * buffer [O] Destination for the information
1138 * len [I] Length of buffer in characters
1141 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1142 * with the information.
1143 * Failure: 0. Use GetLastError() to determine the cause.
1146 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1147 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1148 * which is a bit string.
1150 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
1155 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1157 if (len
< 0 || (len
&& !buffer
))
1159 SetLastError( ERROR_INVALID_PARAMETER
);
1162 if (!len
) buffer
= NULL
;
1164 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
1166 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
1168 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1171 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
1173 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
1174 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
1176 /* it's not an ASCII string, just bytes */
1177 ret
*= sizeof(WCHAR
);
1180 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
1183 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1190 UINT codepage
= CP_ACP
;
1191 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1192 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
1195 HeapFree( GetProcessHeap(), 0, bufferW
);
1200 /******************************************************************************
1201 * GetLocaleInfoW (KERNEL32.@)
1203 * See GetLocaleInfoA.
1205 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
1215 if (len
< 0 || (len
&& !buffer
))
1217 SetLastError( ERROR_INVALID_PARAMETER
);
1220 if (!len
) buffer
= NULL
;
1222 lcid
= convert_default_lcid( lcid
, lctype
);
1224 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
1227 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1229 /* first check for overrides in the registry */
1231 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
1232 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
1234 const WCHAR
*value
= get_locale_value_name(lctype
);
1238 if (lcflags
& LOCALE_RETURN_NUMBER
)
1241 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
1245 UINT number
= strtolW( tmp
, &end
, 10 );
1246 if (*end
) /* invalid number */
1248 SetLastError( ERROR_INVALID_FLAGS
);
1251 ret
= sizeof(UINT
)/sizeof(WCHAR
);
1252 if (!buffer
) return ret
;
1255 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1258 memcpy( buffer
, &number
, sizeof(number
) );
1261 else ret
= get_registry_locale_info( value
, buffer
, len
);
1263 if (ret
!= -1) return ret
;
1267 /* now load it from kernel resources */
1269 lang_id
= LANGIDFROMLCID( lcid
);
1271 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
1272 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
1273 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
1275 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1276 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
1278 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
1281 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
1284 p
= LockResource( hmem
);
1285 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
1287 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
1288 else ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
1290 if (!buffer
) return ret
;
1294 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1298 if (lcflags
& LOCALE_RETURN_NUMBER
)
1301 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
1303 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
1305 number
= strtolW( tmp
, &end
, 10 );
1307 memcpy( buffer
, &number
, sizeof(number
) );
1308 else /* invalid number */
1310 SetLastError( ERROR_INVALID_FLAGS
);
1313 HeapFree( GetProcessHeap(), 0, tmp
);
1315 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
1316 lcid
, lctype
, buffer
, len
, number
);
1320 memcpy( buffer
, p
+ 1, *p
* sizeof(WCHAR
) );
1321 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
1323 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
1324 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
1330 /******************************************************************************
1331 * SetLocaleInfoA [KERNEL32.@]
1333 * Set information about an aspect of a locale.
1336 * lcid [I] LCID of the locale
1337 * lctype [I] LCTYPE_ flags from "winnls.h"
1338 * data [I] Information to set
1341 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1342 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1343 * Failure: FALSE. Use GetLastError() to determine the cause.
1346 * - Values are only be set for the current user locale; the system locale
1347 * settings cannot be changed.
1348 * - Any settings changed by this call are lost when the locale is changed by
1349 * the control panel (in Wine, this happens every time you change LANG).
1350 * - The native implementation of this function does not check that lcid matches
1351 * the current user locale, and simply sets the new values. Wine warns you in
1352 * this case, but behaves the same.
1354 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
1356 UINT codepage
= CP_ACP
;
1361 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1365 SetLastError( ERROR_INVALID_PARAMETER
);
1368 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
1369 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1371 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1374 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
1375 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
1376 HeapFree( GetProcessHeap(), 0, strW
);
1381 /******************************************************************************
1382 * SetLocaleInfoW (KERNEL32.@)
1384 * See SetLocaleInfoA.
1386 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
1389 static const WCHAR intlW
[] = {'i','n','t','l',0 };
1390 UNICODE_STRING valueW
;
1395 value
= get_locale_value_name( lctype
);
1397 if (!data
|| !value
)
1399 SetLastError( ERROR_INVALID_PARAMETER
);
1403 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
1405 SetLastError( ERROR_INVALID_FLAGS
);
1409 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
1411 /* FIXME: should check that data to set is sane */
1413 /* FIXME: profile functions should map to registry */
1414 WriteProfileStringW( intlW
, value
, data
);
1416 if (!(hkey
= create_registry_key())) return FALSE
;
1417 RtlInitUnicodeString( &valueW
, value
);
1418 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
1420 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
1422 /* Set I-value from S value */
1423 WCHAR
*lpD
, *lpM
, *lpY
;
1426 lpD
= strrchrW(data
, 'd');
1427 lpM
= strrchrW(data
, 'M');
1428 lpY
= strrchrW(data
, 'y');
1432 szBuff
[0] = '1'; /* D-M-Y */
1437 szBuff
[0] = '2'; /* Y-M-D */
1439 szBuff
[0] = '0'; /* M-D-Y */
1444 if (lctype
== LOCALE_SSHORTDATE
)
1445 lctype
= LOCALE_IDATE
;
1447 lctype
= LOCALE_ILDATE
;
1449 value
= get_locale_value_name( lctype
);
1451 WriteProfileStringW( intlW
, value
, szBuff
);
1453 RtlInitUnicodeString( &valueW
, value
);
1454 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1459 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1464 /******************************************************************************
1465 * GetACP (KERNEL32.@)
1467 * Get the current Ansi code page Id for the system.
1473 * The current Ansi code page identifier for the system.
1475 UINT WINAPI
GetACP(void)
1477 assert( ansi_cptable
);
1478 return ansi_cptable
->info
.codepage
;
1482 /******************************************************************************
1483 * SetCPGlobal (KERNEL32.@)
1485 * Set the current Ansi code page Id for the system.
1488 * acp [I] code page ID to be the new ACP.
1493 UINT WINAPI
SetCPGlobal( UINT acp
)
1495 UINT ret
= GetACP();
1496 const union cptable
*new_cptable
= wine_cp_get_table( acp
);
1498 if (new_cptable
) ansi_cptable
= new_cptable
;
1503 /***********************************************************************
1504 * GetOEMCP (KERNEL32.@)
1506 * Get the current OEM code page Id for the system.
1512 * The current OEM code page identifier for the system.
1514 UINT WINAPI
GetOEMCP(void)
1516 assert( oem_cptable
);
1517 return oem_cptable
->info
.codepage
;
1521 /***********************************************************************
1522 * IsValidCodePage (KERNEL32.@)
1524 * Determine if a given code page identifier is valid.
1527 * codepage [I] Code page Id to verify.
1530 * TRUE, If codepage is valid and available on the system,
1533 BOOL WINAPI
IsValidCodePage( UINT codepage
)
1540 return wine_cp_get_table( codepage
) != NULL
;
1545 /***********************************************************************
1546 * IsDBCSLeadByteEx (KERNEL32.@)
1548 * Determine if a character is a lead byte in a given code page.
1551 * codepage [I] Code page for the test.
1552 * testchar [I] Character to test
1555 * TRUE, if testchar is a lead byte in codepage,
1558 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
1560 const union cptable
*table
= get_codepage_table( codepage
);
1561 return table
&& wine_is_dbcs_leadbyte( table
, testchar
);
1565 /***********************************************************************
1566 * IsDBCSLeadByte (KERNEL32.@)
1567 * IsDBCSLeadByte (KERNEL.207)
1569 * Determine if a character is a lead byte.
1572 * testchar [I] Character to test
1575 * TRUE, if testchar is a lead byte in the Ansii code page,
1578 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
1580 if (!ansi_cptable
) return FALSE
;
1581 return wine_is_dbcs_leadbyte( ansi_cptable
, testchar
);
1585 /***********************************************************************
1586 * GetCPInfo (KERNEL32.@)
1588 * Get information about a code page.
1591 * codepage [I] Code page number
1592 * cpinfo [O] Destination for code page information
1595 * Success: TRUE. cpinfo is updated with the information about codepage.
1596 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1598 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
1600 const union cptable
*table
;
1604 SetLastError( ERROR_INVALID_PARAMETER
);
1608 if (!(table
= get_codepage_table( codepage
)))
1614 cpinfo
->DefaultChar
[0] = 0x3f;
1615 cpinfo
->DefaultChar
[1] = 0;
1616 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1617 cpinfo
->MaxCharSize
= (codepage
== CP_UTF7
) ? 5 : 4;
1621 SetLastError( ERROR_INVALID_PARAMETER
);
1624 if (table
->info
.def_char
& 0xff00)
1626 cpinfo
->DefaultChar
[0] = (table
->info
.def_char
& 0xff00) >> 8;
1627 cpinfo
->DefaultChar
[1] = table
->info
.def_char
& 0x00ff;
1631 cpinfo
->DefaultChar
[0] = table
->info
.def_char
& 0xff;
1632 cpinfo
->DefaultChar
[1] = 0;
1634 if ((cpinfo
->MaxCharSize
= table
->info
.char_size
) == 2)
1635 memcpy( cpinfo
->LeadByte
, table
->dbcs
.lead_bytes
, sizeof(cpinfo
->LeadByte
) );
1637 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1642 /***********************************************************************
1643 * GetCPInfoExA (KERNEL32.@)
1645 * Get extended information about a code page.
1648 * codepage [I] Code page number
1649 * dwFlags [I] Reserved, must to 0.
1650 * cpinfo [O] Destination for code page information
1653 * Success: TRUE. cpinfo is updated with the information about codepage.
1654 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1656 BOOL WINAPI
GetCPInfoExA( UINT codepage
, DWORD dwFlags
, LPCPINFOEXA cpinfo
)
1660 if (!GetCPInfoExW( codepage
, dwFlags
, &cpinfoW
))
1663 /* the layout is the same except for CodePageName */
1664 memcpy(cpinfo
, &cpinfoW
, sizeof(CPINFOEXA
));
1665 WideCharToMultiByte(CP_ACP
, 0, cpinfoW
.CodePageName
, -1, cpinfo
->CodePageName
, sizeof(cpinfo
->CodePageName
), NULL
, NULL
);
1669 /***********************************************************************
1670 * GetCPInfoExW (KERNEL32.@)
1672 * Unicode version of GetCPInfoExA.
1674 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD dwFlags
, LPCPINFOEXW cpinfo
)
1676 if (!GetCPInfo( codepage
, (LPCPINFO
)cpinfo
))
1683 static const WCHAR utf7
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
1685 cpinfo
->CodePage
= CP_UTF7
;
1686 cpinfo
->UnicodeDefaultChar
= 0x3f;
1687 strcpyW(cpinfo
->CodePageName
, utf7
);
1693 static const WCHAR utf8
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
1695 cpinfo
->CodePage
= CP_UTF8
;
1696 cpinfo
->UnicodeDefaultChar
= 0x3f;
1697 strcpyW(cpinfo
->CodePageName
, utf8
);
1703 const union cptable
*table
= get_codepage_table( codepage
);
1705 cpinfo
->CodePage
= table
->info
.codepage
;
1706 cpinfo
->UnicodeDefaultChar
= table
->info
.def_unicode_char
;
1707 MultiByteToWideChar( CP_ACP
, 0, table
->info
.name
, -1, cpinfo
->CodePageName
,
1708 sizeof(cpinfo
->CodePageName
)/sizeof(WCHAR
));
1715 /***********************************************************************
1716 * EnumSystemCodePagesA (KERNEL32.@)
1718 * Call a user defined function for every code page installed on the system.
1721 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1722 * flags [I] Reserved, set to 0.
1725 * TRUE, If all code pages have been enumerated, or
1726 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1728 BOOL WINAPI
EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum
, DWORD flags
)
1730 const union cptable
*table
;
1736 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1737 sprintf( buffer
, "%d", table
->info
.codepage
);
1738 if (!lpfnCodePageEnum( buffer
)) break;
1744 /***********************************************************************
1745 * EnumSystemCodePagesW (KERNEL32.@)
1747 * See EnumSystemCodePagesA.
1749 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
, DWORD flags
)
1751 const union cptable
*table
;
1752 WCHAR buffer
[10], *p
;
1753 int page
, index
= 0;
1757 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1758 p
= buffer
+ sizeof(buffer
)/sizeof(WCHAR
);
1760 page
= table
->info
.codepage
;
1763 *--p
= '0' + (page
% 10);
1766 if (!lpfnCodePageEnum( p
)) break;
1772 /***********************************************************************
1773 * MultiByteToWideChar (KERNEL32.@)
1775 * Convert a multibyte character string into a Unicode string.
1778 * page [I] Codepage character set to convert from
1779 * flags [I] Character mapping flags
1780 * src [I] Source string buffer
1781 * srclen [I] Length of src (in bytes), or -1 if src is NUL terminated
1782 * dst [O] Destination buffer
1783 * dstlen [I] Length of dst (in WCHARs), or 0 to compute the required length
1786 * Success: If dstlen > 0, the number of characters written to dst.
1787 * If dstlen == 0, the number of characters needed to perform the
1788 * conversion. In both cases the count includes the terminating NUL.
1789 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1790 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1791 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1792 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1795 INT WINAPI
MultiByteToWideChar( UINT page
, DWORD flags
, LPCSTR src
, INT srclen
,
1796 LPWSTR dst
, INT dstlen
)
1798 const union cptable
*table
;
1801 if (!src
|| (!dst
&& dstlen
))
1803 SetLastError( ERROR_INVALID_PARAMETER
);
1807 if (srclen
< 0) srclen
= strlen(src
) + 1;
1814 SetLastError( ERROR_INVALID_PARAMETER
);
1817 ret
= wine_cpsymbol_mbstowcs( src
, srclen
, dst
, dstlen
);
1820 FIXME("UTF-7 not supported\n");
1821 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1826 ret
= wine_cp_mbstowcs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
);
1831 ret
= wine_utf8_mbstowcs( flags
, src
, srclen
, dst
, dstlen
);
1834 if (!(table
= get_codepage_table( page
)))
1836 SetLastError( ERROR_INVALID_PARAMETER
);
1839 ret
= wine_cp_mbstowcs( table
, flags
, src
, srclen
, dst
, dstlen
);
1847 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1848 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1852 TRACE("cp %d %s -> %s, ret = %d\n",
1853 page
, debugstr_an(src
, srclen
), debugstr_wn(dst
, ret
), ret
);
1858 /***********************************************************************
1859 * WideCharToMultiByte (KERNEL32.@)
1861 * Convert a Unicode character string into a multibyte string.
1864 * page [I] Code page character set to convert to
1865 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1866 * src [I] Source string buffer
1867 * srclen [I] Length of src (in WCHARs), or -1 if src is NUL terminated
1868 * dst [O] Destination buffer
1869 * dstlen [I] Length of dst (in bytes), or 0 to compute the required length
1870 * defchar [I] Default character to use for conversion if no exact
1871 * conversion can be made
1872 * used [O] Set if default character was used in the conversion
1875 * Success: If dstlen > 0, the number of characters written to dst.
1876 * If dstlen == 0, number of characters needed to perform the
1877 * conversion. In both cases the count includes the terminating NUL.
1878 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1879 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1880 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1881 * parameter was given.
1883 INT WINAPI
WideCharToMultiByte( UINT page
, DWORD flags
, LPCWSTR src
, INT srclen
,
1884 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
1886 const union cptable
*table
;
1889 if (!src
|| (!dst
&& dstlen
))
1891 SetLastError( ERROR_INVALID_PARAMETER
);
1895 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1900 if( flags
|| defchar
|| used
)
1902 SetLastError( ERROR_INVALID_PARAMETER
);
1905 ret
= wine_cpsymbol_wcstombs( src
, srclen
, dst
, dstlen
);
1908 FIXME("UTF-7 not supported\n");
1909 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1914 ret
= wine_cp_wcstombs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
,
1915 defchar
, used
? &used_tmp
: NULL
);
1920 if (used
) *used
= FALSE
; /* all chars are valid for UTF-8 */
1921 ret
= wine_utf8_wcstombs( flags
, src
, srclen
, dst
, dstlen
);
1924 if (!(table
= get_codepage_table( page
)))
1926 SetLastError( ERROR_INVALID_PARAMETER
);
1929 ret
= wine_cp_wcstombs( table
, flags
, src
, srclen
, dst
, dstlen
,
1930 defchar
, used
? &used_tmp
: NULL
);
1931 if (used
) *used
= used_tmp
;
1939 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1940 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1944 TRACE("cp %d %s -> %s, ret = %d\n",
1945 page
, debugstr_wn(src
, srclen
), debugstr_an(dst
, ret
), ret
);
1950 /***********************************************************************
1951 * GetThreadLocale (KERNEL32.@)
1953 * Get the current threads locale.
1959 * The LCID currently assocated with the calling thread.
1961 LCID WINAPI
GetThreadLocale(void)
1963 LCID ret
= NtCurrentTeb()->CurrentLocale
;
1964 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
1968 /**********************************************************************
1969 * SetThreadLocale (KERNEL32.@)
1971 * Set the current threads locale.
1974 * lcid [I] LCID of the locale to set
1977 * Success: TRUE. The threads locale is set to lcid.
1978 * Failure: FALSE. Use GetLastError() to determine the cause.
1980 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1982 TRACE("(0x%04X)\n", lcid
);
1984 lcid
= ConvertDefaultLocale(lcid
);
1986 if (lcid
!= GetThreadLocale())
1988 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1990 SetLastError(ERROR_INVALID_PARAMETER
);
1994 NtCurrentTeb()->CurrentLocale
= lcid
;
1995 kernel_get_thread_data()->code_page
= get_lcid_codepage( lcid
);
2000 /**********************************************************************
2001 * SetThreadUILanguage (KERNEL32.@)
2003 * Set the current threads UI language.
2006 * langid [I] LANGID of the language to set, or 0 to use
2007 * the available language which is best supported
2008 * for console applications
2011 * Success: The return value is the same as the input value.
2012 * Failure: The return value differs from the input value.
2013 * Use GetLastError() to determine the cause.
2015 LANGID WINAPI
SetThreadUILanguage( LANGID langid
)
2017 TRACE("(0x%04x) stub - returning success\n", langid
);
2021 /******************************************************************************
2022 * ConvertDefaultLocale (KERNEL32.@)
2024 * Convert a default locale identifier into a real identifier.
2027 * lcid [I] LCID identifier of the locale to convert
2030 * lcid unchanged, if not a default locale or its sublanguage is
2031 * not SUBLANG_NEUTRAL.
2032 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
2033 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
2034 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
2036 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
2042 case LOCALE_SYSTEM_DEFAULT
:
2043 lcid
= GetSystemDefaultLCID();
2045 case LOCALE_USER_DEFAULT
:
2046 case LOCALE_NEUTRAL
:
2047 lcid
= GetUserDefaultLCID();
2050 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
2051 langid
= LANGIDFROMLCID(lcid
);
2052 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
2054 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
2055 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
2062 /******************************************************************************
2063 * IsValidLocale (KERNEL32.@)
2065 * Determine if a locale is valid.
2068 * lcid [I] LCID of the locale to check
2069 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
2072 * TRUE, if lcid is valid,
2076 * Wine does not currently make the distinction between supported and installed. All
2077 * languages supported are installed by default.
2079 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
2081 /* check if language is registered in the kernel32 resources */
2082 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
2083 (LPCWSTR
)LOCALE_ILANGUAGE
, LANGIDFROMLCID(lcid
)) != 0;
2087 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
2088 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
2090 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
2093 sprintf(buf
, "%08x", (UINT
)LangID
);
2094 return lpfnLocaleEnum( buf
);
2097 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
2098 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
2100 static const WCHAR formatW
[] = {'%','0','8','x',0};
2101 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
2103 sprintfW( buf
, formatW
, (UINT
)LangID
);
2104 return lpfnLocaleEnum( buf
);
2107 /******************************************************************************
2108 * EnumSystemLocalesA (KERNEL32.@)
2110 * Call a users function for each locale available on the system.
2113 * lpfnLocaleEnum [I] Callback function to call for each locale
2114 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
2118 * Failure: FALSE. Use GetLastError() to determine the cause.
2120 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
2122 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
2123 EnumResourceLanguagesA( kernel32_handle
, (LPSTR
)RT_STRING
,
2124 (LPCSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_a
,
2125 (LONG_PTR
)lpfnLocaleEnum
);
2130 /******************************************************************************
2131 * EnumSystemLocalesW (KERNEL32.@)
2133 * See EnumSystemLocalesA.
2135 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
2137 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
2138 EnumResourceLanguagesW( kernel32_handle
, (LPWSTR
)RT_STRING
,
2139 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_w
,
2140 (LONG_PTR
)lpfnLocaleEnum
);
2145 /***********************************************************************
2146 * VerLanguageNameA (KERNEL32.@)
2148 * Get the name of a language.
2151 * wLang [I] LANGID of the language
2152 * szLang [O] Destination for the language name
2155 * Success: The size of the language name. If szLang is non-NULL, it is filled
2157 * Failure: 0. Use GetLastError() to determine the cause.
2160 DWORD WINAPI
VerLanguageNameA( DWORD wLang
, LPSTR szLang
, DWORD nSize
)
2162 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
2166 /***********************************************************************
2167 * VerLanguageNameW (KERNEL32.@)
2169 * See VerLanguageNameA.
2171 DWORD WINAPI
VerLanguageNameW( DWORD wLang
, LPWSTR szLang
, DWORD nSize
)
2173 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
2177 /******************************************************************************
2178 * GetStringTypeW (KERNEL32.@)
2180 * See GetStringTypeA.
2182 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
2184 if (count
== -1) count
= strlenW(src
) + 1;
2188 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
2191 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) >> 12;
2195 WARN("CT_CTYPE3: semi-stub.\n");
2199 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
2201 type1
= get_char_typeW( *src
++ ) & 0xfff;
2202 /* try to construct type3 from type1 */
2203 if(type1
& C1_SPACE
) type3
|= C3_SYMBOL
;
2204 if(type1
& C1_ALPHA
) type3
|= C3_ALPHA
;
2205 if ((c
>=0x30A0)&&(c
<=0x30FF)) type3
|= C3_KATAKANA
;
2206 if ((c
>=0x3040)&&(c
<=0x309F)) type3
|= C3_HIRAGANA
;
2207 if ((c
>=0x4E00)&&(c
<=0x9FAF)) type3
|= C3_IDEOGRAPH
;
2208 if ((c
>=0x0600)&&(c
<=0x06FF)) type3
|= C3_KASHIDA
;
2209 if ((c
>=0x3000)&&(c
<=0x303F)) type3
|= C3_SYMBOL
;
2211 if ((c
>=0xFF00)&&(c
<=0xFF60)) type3
|= C3_FULLWIDTH
;
2212 if ((c
>=0xFF00)&&(c
<=0xFF20)) type3
|= C3_SYMBOL
;
2213 if ((c
>=0xFF3B)&&(c
<=0xFF40)) type3
|= C3_SYMBOL
;
2214 if ((c
>=0xFF5B)&&(c
<=0xFF60)) type3
|= C3_SYMBOL
;
2215 if ((c
>=0xFF21)&&(c
<=0xFF3A)) type3
|= C3_ALPHA
;
2216 if ((c
>=0xFF41)&&(c
<=0xFF5A)) type3
|= C3_ALPHA
;
2217 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_FULLWIDTH
;
2218 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_SYMBOL
;
2220 if ((c
>=0xFF61)&&(c
<=0xFFDC)) type3
|= C3_HALFWIDTH
;
2221 if ((c
>=0xFF61)&&(c
<=0xFF64)) type3
|= C3_SYMBOL
;
2222 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_KATAKANA
;
2223 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_ALPHA
;
2224 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_HALFWIDTH
;
2225 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_SYMBOL
;
2226 *chartype
++ = type3
;
2231 SetLastError( ERROR_INVALID_PARAMETER
);
2238 /******************************************************************************
2239 * GetStringTypeExW (KERNEL32.@)
2241 * See GetStringTypeExA.
2243 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
2245 /* locale is ignored for Unicode */
2246 return GetStringTypeW( type
, src
, count
, chartype
);
2250 /******************************************************************************
2251 * GetStringTypeA (KERNEL32.@)
2253 * Get characteristics of the characters making up a string.
2256 * locale [I] Locale Id for the string
2257 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2258 * src [I] String to analyse
2259 * count [I] Length of src in chars, or -1 if src is NUL terminated
2260 * chartype [O] Destination for the calculated characteristics
2263 * Success: TRUE. chartype is filled with the requested characteristics of each char
2265 * Failure: FALSE. Use GetLastError() to determine the cause.
2267 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
2274 if(count
== -1) count
= strlen(src
) + 1;
2276 if (!(cp
= get_lcid_codepage( locale
)))
2278 FIXME("For locale %04x using current ANSI code page\n", locale
);
2282 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
2283 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
2285 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
2287 * NOTE: the target buffer has 1 word for each CHARACTER in the source
2288 * string, with multibyte characters there maybe be more bytes in count
2289 * than character space in the buffer!
2291 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
2292 HeapFree(GetProcessHeap(), 0, srcW
);
2297 /******************************************************************************
2298 * GetStringTypeExA (KERNEL32.@)
2300 * Get characteristics of the characters making up a string.
2303 * locale [I] Locale Id for the string
2304 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2305 * src [I] String to analyse
2306 * count [I] Length of src in chars, or -1 if src is NUL terminated
2307 * chartype [O] Destination for the calculated characteristics
2310 * Success: TRUE. chartype is filled with the requested characteristics of each char
2312 * Failure: FALSE. Use GetLastError() to determine the cause.
2314 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
2316 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
2320 /*************************************************************************
2321 * LCMapStringW (KERNEL32.@)
2325 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
2326 LPWSTR dst
, INT dstlen
)
2330 if (!src
|| !srclen
|| dstlen
< 0)
2332 SetLastError(ERROR_INVALID_PARAMETER
);
2336 /* mutually exclusive flags */
2337 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
2338 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
2339 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
2340 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
))
2342 SetLastError(ERROR_INVALID_FLAGS
);
2346 if (!dstlen
) dst
= NULL
;
2348 lcid
= ConvertDefaultLocale(lcid
);
2350 if (flags
& LCMAP_SORTKEY
)
2355 SetLastError(ERROR_INVALID_FLAGS
);
2359 if (srclen
< 0) srclen
= strlenW(src
);
2361 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2362 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
2364 ret
= wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
2366 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2370 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
2371 if (flags
& SORT_STRINGSORT
)
2373 SetLastError(ERROR_INVALID_FLAGS
);
2377 if (srclen
< 0) srclen
= strlenW(src
) + 1;
2379 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2380 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
2382 if (!dst
) /* return required string length */
2386 for (len
= 0; srclen
; src
++, srclen
--)
2389 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
2390 * and skips white space and punctuation characters for
2391 * NORM_IGNORESYMBOLS.
2393 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2400 if (flags
& LCMAP_UPPERCASE
)
2402 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2405 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2407 *dst_ptr
++ = toupperW(wch
);
2411 else if (flags
& LCMAP_LOWERCASE
)
2413 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2416 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2418 *dst_ptr
++ = tolowerW(wch
);
2426 SetLastError(ERROR_INVALID_FLAGS
);
2429 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2432 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2441 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2445 return dst_ptr
- dst
;
2448 /*************************************************************************
2449 * LCMapStringA (KERNEL32.@)
2451 * Map characters in a locale sensitive string.
2454 * lcid [I] LCID for the conversion.
2455 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2456 * src [I] String to map
2457 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2458 * dst [O] Destination for mapped string
2459 * dstlen [I] Length of dst in characters
2462 * Success: The length of the mapped string in dst, including the NUL terminator.
2463 * Failure: 0. Use GetLastError() to determine the cause.
2465 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
2466 LPSTR dst
, INT dstlen
)
2468 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
2470 INT ret
= 0, srclenW
, dstlenW
;
2471 UINT locale_cp
= CP_ACP
;
2473 if (!src
|| !srclen
|| dstlen
< 0)
2475 SetLastError(ERROR_INVALID_PARAMETER
);
2479 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
2481 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
2486 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
2487 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2490 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2493 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
2496 if (flags
& LCMAP_SORTKEY
)
2500 SetLastError(ERROR_INVALID_FLAGS
);
2501 goto map_string_exit
;
2503 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
2505 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2506 goto map_string_exit
;
2509 if (flags
& SORT_STRINGSORT
)
2511 SetLastError(ERROR_INVALID_FLAGS
);
2512 goto map_string_exit
;
2515 dstlenW
= LCMapStringW(lcid
, flags
, srcW
, srclenW
, NULL
, 0);
2517 goto map_string_exit
;
2519 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
2522 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2523 goto map_string_exit
;
2526 LCMapStringW(lcid
, flags
, srcW
, srclenW
, dstW
, dstlenW
);
2527 ret
= WideCharToMultiByte(locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
2528 HeapFree(GetProcessHeap(), 0, dstW
);
2531 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
2535 /*************************************************************************
2536 * FoldStringA (KERNEL32.@)
2538 * Map characters in a string.
2541 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2542 * src [I] String to map
2543 * srclen [I] Length of src, or -1 if src is NUL terminated
2544 * dst [O] Destination for mapped string
2545 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2548 * Success: The length of the string written to dst, including the terminating NUL. If
2549 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2550 * and dst may be NULL.
2551 * Failure: 0. Use GetLastError() to determine the cause.
2553 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
2554 LPSTR dst
, INT dstlen
)
2556 INT ret
= 0, srclenW
= 0;
2557 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
2559 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2561 SetLastError(ERROR_INVALID_PARAMETER
);
2565 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2566 src
, srclen
, NULL
, 0);
2567 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2571 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2572 goto FoldStringA_exit
;
2575 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2576 src
, srclen
, srcW
, srclenW
);
2578 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
2580 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
2583 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
2587 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2588 goto FoldStringA_exit
;
2591 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
2592 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
2595 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2599 HeapFree(GetProcessHeap(), 0, dstW
);
2602 HeapFree(GetProcessHeap(), 0, srcW
);
2606 /*************************************************************************
2607 * FoldStringW (KERNEL32.@)
2611 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
2612 LPWSTR dst
, INT dstlen
)
2616 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
2621 /* Fall through for dwFlags == 0 */
2622 case MAP_PRECOMPOSED
|MAP_COMPOSITE
:
2623 case MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
:
2624 case MAP_COMPOSITE
|MAP_EXPAND_LIGATURES
:
2625 SetLastError(ERROR_INVALID_FLAGS
);
2629 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2631 SetLastError(ERROR_INVALID_PARAMETER
);
2635 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
2637 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2641 /******************************************************************************
2642 * CompareStringW (KERNEL32.@)
2644 * See CompareStringA.
2646 INT WINAPI
CompareStringW(LCID lcid
, DWORD style
,
2647 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
2653 SetLastError(ERROR_INVALID_PARAMETER
);
2657 if( style
& ~(NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
|
2658 SORT_STRINGSORT
|NORM_IGNOREKANATYPE
|NORM_IGNOREWIDTH
|LOCALE_USE_CP_ACP
|0x10000000) )
2660 SetLastError(ERROR_INVALID_FLAGS
);
2664 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
2665 if (style
& 0x10000000)
2666 WARN("Ignoring unknown style 0x10000000\n");
2668 if (len1
< 0) len1
= strlenW(str1
);
2669 if (len2
< 0) len2
= strlenW(str2
);
2671 ret
= wine_compare_string(style
, str1
, len1
, str2
, len2
);
2673 if (ret
) /* need to translate result */
2674 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
2678 /******************************************************************************
2679 * CompareStringA (KERNEL32.@)
2681 * Compare two locale sensitive strings.
2684 * lcid [I] LCID for the comparison
2685 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
2686 * str1 [I] First string to compare
2687 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2688 * str2 [I] Second string to compare
2689 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2692 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2693 * str2 is less than, equal to or greater than str1 respectively.
2694 * Failure: FALSE. Use GetLastError() to determine the cause.
2696 INT WINAPI
CompareStringA(LCID lcid
, DWORD style
,
2697 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
2699 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
2700 WCHAR
*buf2W
= buf1W
+ 130;
2701 LPWSTR str1W
, str2W
;
2702 INT len1W
, len2W
, ret
;
2703 UINT locale_cp
= CP_ACP
;
2707 SetLastError(ERROR_INVALID_PARAMETER
);
2710 if (len1
< 0) len1
= strlen(str1
);
2711 if (len2
< 0) len2
= strlen(str2
);
2713 if (!(style
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
2715 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
2720 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
2721 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
2724 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2727 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
2729 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
2734 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
2735 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
2738 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2739 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2742 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
2745 ret
= CompareStringW(lcid
, style
, str1W
, len1W
, str2W
, len2W
);
2747 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2748 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
2752 /*************************************************************************
2753 * lstrcmp (KERNEL32.@)
2754 * lstrcmpA (KERNEL32.@)
2756 * Compare two strings using the current thread locale.
2759 * str1 [I] First string to compare
2760 * str2 [I] Second string to compare
2763 * Success: A number less than, equal to or greater than 0 depending on whether
2764 * str2 is less than, equal to or greater than str1 respectively.
2765 * Failure: FALSE. Use GetLastError() to determine the cause.
2767 int WINAPI
lstrcmpA(LPCSTR str1
, LPCSTR str2
)
2771 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2772 if (str1
== NULL
) return -1;
2773 if (str2
== NULL
) return 1;
2775 ret
= CompareStringA(GetThreadLocale(), LOCALE_USE_CP_ACP
, str1
, -1, str2
, -1);
2781 /*************************************************************************
2782 * lstrcmpi (KERNEL32.@)
2783 * lstrcmpiA (KERNEL32.@)
2785 * Compare two strings using the current thread locale, ignoring case.
2788 * str1 [I] First string to compare
2789 * str2 [I] Second string to compare
2792 * Success: A number less than, equal to or greater than 0 depending on whether
2793 * str2 is less than, equal to or greater than str1 respectively.
2794 * Failure: FALSE. Use GetLastError() to determine the cause.
2796 int WINAPI
lstrcmpiA(LPCSTR str1
, LPCSTR str2
)
2800 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2801 if (str1
== NULL
) return -1;
2802 if (str2
== NULL
) return 1;
2804 ret
= CompareStringA(GetThreadLocale(), NORM_IGNORECASE
|LOCALE_USE_CP_ACP
, str1
, -1, str2
, -1);
2810 /*************************************************************************
2811 * lstrcmpW (KERNEL32.@)
2815 int WINAPI
lstrcmpW(LPCWSTR str1
, LPCWSTR str2
)
2819 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2820 if (str1
== NULL
) return -1;
2821 if (str2
== NULL
) return 1;
2823 ret
= CompareStringW(GetThreadLocale(), 0, str1
, -1, str2
, -1);
2829 /*************************************************************************
2830 * lstrcmpiW (KERNEL32.@)
2834 int WINAPI
lstrcmpiW(LPCWSTR str1
, LPCWSTR str2
)
2838 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2839 if (str1
== NULL
) return -1;
2840 if (str2
== NULL
) return 1;
2842 ret
= CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, str1
, -1, str2
, -1);
2848 /******************************************************************************
2851 void LOCALE_Init(void)
2853 extern void __wine_init_codepages( const union cptable
*ansi_cp
, const union cptable
*oem_cp
,
2854 const union cptable
*unix_cp
);
2856 UINT ansi_cp
= 1252, oem_cp
= 437, mac_cp
= 10000, unix_cp
;
2859 /* MacOS doesn't set the locale environment variables so we have to do it ourselves */
2860 CFArrayRef preferred_locales
, all_locales
;
2861 CFStringRef user_language_string_ref
= NULL
;
2862 char user_locale
[50];
2864 CFLocaleRef user_locale_ref
= CFLocaleCopyCurrent();
2865 CFStringRef user_locale_string_ref
= CFLocaleGetIdentifier( user_locale_ref
);
2867 CFStringGetCString( user_locale_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2868 CFRelease( user_locale_ref
);
2869 if (!strchr( user_locale
, '.' )) strcat( user_locale
, ".UTF-8" );
2870 unix_cp
= CP_UTF8
; /* default to utf-8 even if we don't get a valid locale */
2871 setenv( "LANG", user_locale
, 0 );
2872 TRACE( "setting locale to '%s'\n", user_locale
);
2874 /* We still want to set the retrieve the preferred language as chosen in
2875 System Preferences.app, because it can differ from CFLocaleCopyCurrent().
2877 all_locales
= CFLocaleCopyAvailableLocaleIdentifiers();
2878 preferred_locales
= CFBundleCopyLocalizationsForPreferences( all_locales
, NULL
);
2879 if (preferred_locales
&& CFArrayGetCount( preferred_locales
))
2880 user_language_string_ref
= CFArrayGetValueAtIndex( preferred_locales
, 0 );
2881 CFRelease( all_locales
);
2882 #endif /* __APPLE__ */
2884 setlocale( LC_ALL
, "" );
2886 unix_cp
= setup_unix_locales();
2887 if (!lcid_LC_MESSAGES
) lcid_LC_MESSAGES
= lcid_LC_CTYPE
;
2890 /* Override lcid_LC_MESSAGES with user_language if LC_MESSAGES is set to default */
2891 if (lcid_LC_MESSAGES
== lcid_LC_CTYPE
&& user_language_string_ref
)
2893 struct locale_name locale_name
;
2895 CFStringGetCString( user_language_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2896 strcpynAtoW( buffer
, user_locale
, sizeof(buffer
)/sizeof(WCHAR
) );
2897 parse_locale_name( buffer
, &locale_name
);
2898 lcid_LC_MESSAGES
= locale_name
.lcid
;
2899 TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale
);
2901 if (preferred_locales
)
2902 CFRelease( preferred_locales
);
2905 NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES
) );
2906 NtSetDefaultLocale( TRUE
, lcid_LC_MESSAGES
);
2907 NtSetDefaultLocale( FALSE
, lcid_LC_CTYPE
);
2909 ansi_cp
= get_lcid_codepage( LOCALE_USER_DEFAULT
);
2910 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
2911 (LPWSTR
)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
2912 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
2913 (LPWSTR
)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
2915 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
2916 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) );
2918 if (!(ansi_cptable
= wine_cp_get_table( ansi_cp
)))
2919 ansi_cptable
= wine_cp_get_table( 1252 );
2920 if (!(oem_cptable
= wine_cp_get_table( oem_cp
)))
2921 oem_cptable
= wine_cp_get_table( 437 );
2922 if (!(mac_cptable
= wine_cp_get_table( mac_cp
)))
2923 mac_cptable
= wine_cp_get_table( 10000 );
2924 if (unix_cp
!= CP_UTF8
)
2926 if (!(unix_cptable
= wine_cp_get_table( unix_cp
)))
2927 unix_cptable
= wine_cp_get_table( 28591 );
2930 __wine_init_codepages( ansi_cptable
, oem_cptable
, unix_cptable
);
2932 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
2933 ansi_cptable
->info
.codepage
, oem_cptable
->info
.codepage
,
2934 mac_cptable
->info
.codepage
, unix_cp
);
2936 setlocale(LC_NUMERIC
, "C"); /* FIXME: oleaut32 depends on this */
2939 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
2941 UNICODE_STRING keyName
;
2942 OBJECT_ATTRIBUTES attr
;
2945 RtlInitUnicodeString( &keyName
, szKeyName
);
2946 InitializeObjectAttributes(&attr
, &keyName
, 0, hRootKey
, NULL
);
2948 if (NtOpenKey( &hkey
, KEY_ALL_ACCESS
, &attr
) != STATUS_SUCCESS
)
2954 static BOOL
NLS_RegEnumSubKey(HANDLE hKey
, UINT ulIndex
, LPWSTR szKeyName
,
2958 KEY_BASIC_INFORMATION
*info
= (KEY_BASIC_INFORMATION
*)buffer
;
2961 if (NtEnumerateKey( hKey
, ulIndex
, KeyBasicInformation
, buffer
,
2962 sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
2963 info
->NameLength
> keyNameSize
)
2968 TRACE("info->Name %s info->NameLength %d\n", debugstr_w(info
->Name
), info
->NameLength
);
2970 memcpy( szKeyName
, info
->Name
, info
->NameLength
);
2971 szKeyName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
2973 TRACE("returning %s\n", debugstr_w(szKeyName
));
2977 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
2978 LPWSTR szValueName
, ULONG valueNameSize
,
2979 LPWSTR szValueData
, ULONG valueDataSize
)
2982 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
2985 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
2986 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
2987 info
->NameLength
> valueNameSize
||
2988 info
->DataLength
> valueDataSize
)
2993 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
2995 memcpy( szValueName
, info
->Name
, info
->NameLength
);
2996 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
2997 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
2998 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
3000 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
3004 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
3007 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
3008 DWORD dwSize
= sizeof(buffer
);
3009 UNICODE_STRING valueName
;
3011 RtlInitUnicodeString( &valueName
, szValueName
);
3013 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
3014 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
3015 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
3016 info
->DataLength
== sizeof(DWORD
))
3018 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
3025 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
3028 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
3032 /* FIXME: Is it correct to use the system default langid? */
3033 langId
= GetSystemDefaultLangID();
3035 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
3036 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
3038 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
3042 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
3046 ULONG iResourceIndex
= lgrpid
& 0xf;
3047 LPCWSTR lpResEntry
= LockResource( hResDir
);
3050 for (i
= 0; i
< iResourceIndex
; i
++)
3051 lpResEntry
+= *lpResEntry
+ 1;
3053 if (*lpResEntry
< nameSize
)
3055 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
3056 szName
[*lpResEntry
] = '\0';
3061 FreeResource( hResource
);
3066 /* Registry keys for NLS related information */
3068 static const WCHAR szCountryListName
[] = {
3069 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
3070 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
3071 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3072 'T','e','l','e','p','h','o','n','y','\\',
3073 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
3077 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
3080 LANGUAGEGROUP_ENUMPROCA procA
;
3081 LANGUAGEGROUP_ENUMPROCW procW
;
3084 } ENUMLANGUAGEGROUP_CALLBACKS
;
3086 /* Internal implementation of EnumSystemLanguageGroupsA/W */
3087 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
3089 WCHAR szNumber
[10], szValue
[4];
3091 BOOL bContinue
= TRUE
;
3096 SetLastError(ERROR_INVALID_PARAMETER
);
3100 switch (lpProcs
->dwFlags
)
3103 /* Default to LGRPID_INSTALLED */
3104 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
3105 /* Fall through... */
3106 case LGRPID_INSTALLED
:
3107 case LGRPID_SUPPORTED
:
3110 SetLastError(ERROR_INVALID_FLAGS
);
3114 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3117 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3121 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3122 szValue
, sizeof(szValue
) ))
3124 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
3125 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
3127 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
3128 bInstalled
? "" : "not ");
3130 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
3132 WCHAR szGrpName
[48];
3134 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
3135 szGrpName
[0] = '\0';
3138 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
3142 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3143 char szGrpNameA
[48];
3145 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
3146 * or whether the language names are ever localised. Assume CP_ACP.
3149 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3150 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
3152 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
3172 /******************************************************************************
3173 * EnumSystemLanguageGroupsA (KERNEL32.@)
3175 * Call a users function for each language group available on the system.
3178 * pLangGrpEnumProc [I] Callback function to call for each language group
3179 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
3180 * lParam [I] User parameter to pass to pLangGrpEnumProc
3184 * Failure: FALSE. Use GetLastError() to determine the cause.
3186 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
3187 DWORD dwFlags
, LONG_PTR lParam
)
3189 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3191 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3193 procs
.procA
= pLangGrpEnumProc
;
3195 procs
.dwFlags
= dwFlags
;
3196 procs
.lParam
= lParam
;
3198 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3201 /******************************************************************************
3202 * EnumSystemLanguageGroupsW (KERNEL32.@)
3204 * See EnumSystemLanguageGroupsA.
3206 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
3207 DWORD dwFlags
, LONG_PTR lParam
)
3209 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3211 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3214 procs
.procW
= pLangGrpEnumProc
;
3215 procs
.dwFlags
= dwFlags
;
3216 procs
.lParam
= lParam
;
3218 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3221 /******************************************************************************
3222 * IsValidLanguageGroup (KERNEL32.@)
3224 * Determine if a language group is supported and/or installed.
3227 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
3228 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
3231 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
3234 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
3236 static const WCHAR szFormat
[] = { '%','x','\0' };
3237 WCHAR szValueName
[16], szValue
[2];
3238 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
3244 case LGRPID_INSTALLED
:
3245 case LGRPID_SUPPORTED
:
3247 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3249 sprintfW( szValueName
, szFormat
, lgrpid
);
3251 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)&szValue
))
3255 if (szValue
[0] == '1')
3265 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
3266 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
3272 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
3275 LANGGROUPLOCALE_ENUMPROCA procA
;
3276 LANGGROUPLOCALE_ENUMPROCW procW
;
3280 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
3282 /* Internal implementation of EnumLanguageGrouplocalesA/W */
3283 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
3285 static const WCHAR szAlternateSortsKeyName
[] = {
3286 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
3288 WCHAR szNumber
[10], szValue
[4];
3290 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
3292 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
3294 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
3296 SetLastError(ERROR_INVALID_PARAMETER
);
3300 if (lpProcs
->dwFlags
)
3302 SetLastError(ERROR_INVALID_FLAGS
);
3306 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
3309 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3313 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3314 szValue
, sizeof(szValue
) ))
3316 lgrpid
= strtoulW( szValue
, NULL
, 16 );
3318 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
3319 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
3321 if (lgrpid
== lpProcs
->lgrpid
)
3325 lcid
= strtoulW( szNumber
, NULL
, 16 );
3327 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
3328 * '00000437 ;Georgian'
3329 * At present we only pass the LCID string.
3333 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
3336 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3338 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3340 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
3348 /* Finished enumerating this key */
3351 /* Enumerate alternate sorts also */
3352 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
3357 bContinue
= FALSE
; /* Finished both keys */
3370 /******************************************************************************
3371 * EnumLanguageGroupLocalesA (KERNEL32.@)
3373 * Call a users function for every locale in a language group available on the system.
3376 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3377 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3378 * dwFlags [I] Reserved, set to 0
3379 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3383 * Failure: FALSE. Use GetLastError() to determine the cause.
3385 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
3386 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3388 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3390 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3392 callbacks
.procA
= pLangGrpLcEnumProc
;
3393 callbacks
.procW
= NULL
;
3394 callbacks
.dwFlags
= dwFlags
;
3395 callbacks
.lgrpid
= lgrpid
;
3396 callbacks
.lParam
= lParam
;
3398 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3401 /******************************************************************************
3402 * EnumLanguageGroupLocalesW (KERNEL32.@)
3404 * See EnumLanguageGroupLocalesA.
3406 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
3407 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3409 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3411 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3413 callbacks
.procA
= NULL
;
3414 callbacks
.procW
= pLangGrpLcEnumProc
;
3415 callbacks
.dwFlags
= dwFlags
;
3416 callbacks
.lgrpid
= lgrpid
;
3417 callbacks
.lParam
= lParam
;
3419 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3422 /******************************************************************************
3423 * EnumSystemGeoID (KERNEL32.@)
3425 * Call a users function for every location available on the system.
3428 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3429 * reserved [I] Reserved, set to 0
3430 * pGeoEnumProc [I] Callback function to call for each location
3434 * Failure: FALSE. Use GetLastError() to determine the cause.
3436 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID reserved
, GEO_ENUMPROC pGeoEnumProc
)
3438 static const WCHAR szCountryCodeValueName
[] = {
3439 'C','o','u','n','t','r','y','C','o','d','e','\0'
3445 TRACE("(0x%08X,0x%08X,%p)\n", geoclass
, reserved
, pGeoEnumProc
);
3447 if (geoclass
!= GEOCLASS_NATION
|| reserved
|| !pGeoEnumProc
)
3449 SetLastError(ERROR_INVALID_PARAMETER
);
3453 hKey
= NLS_RegOpenKey( 0, szCountryListName
);
3455 while (NLS_RegEnumSubKey( hKey
, ulIndex
, szNumber
, sizeof(szNumber
) ))
3457 BOOL bContinue
= TRUE
;
3459 HANDLE hSubKey
= NLS_RegOpenKey( hKey
, szNumber
);
3463 if (NLS_RegGetDword( hSubKey
, szCountryCodeValueName
, &dwGeoId
))
3465 TRACE("Got geoid %d\n", dwGeoId
);
3467 if (!pGeoEnumProc( dwGeoId
))
3486 /******************************************************************************
3487 * InvalidateNLSCache (KERNEL32.@)
3489 * Invalidate the cache of NLS values.
3498 BOOL WINAPI
InvalidateNLSCache(void)
3504 /******************************************************************************
3505 * GetUserGeoID (KERNEL32.@)
3507 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
3509 GEOID ret
= GEOID_NOT_AVAILABLE
;
3510 static const WCHAR geoW
[] = {'G','e','o',0};
3511 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3512 WCHAR bufferW
[40], *end
;
3514 HANDLE hkey
, hSubkey
= 0;
3515 UNICODE_STRING keyW
;
3516 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
3517 RtlInitUnicodeString( &keyW
, nationW
);
3518 count
= sizeof(bufferW
);
3520 if(!(hkey
= create_registry_key())) return ret
;
3523 case GEOCLASS_NATION
:
3524 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
3526 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
3527 (LPBYTE
)bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
3528 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
3531 case GEOCLASS_REGION
:
3532 FIXME("GEOCLASS_REGION not handled yet\n");
3537 if (hSubkey
) NtClose(hSubkey
);
3541 /******************************************************************************
3542 * SetUserGeoID (KERNEL32.@)
3544 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
3546 static const WCHAR geoW
[] = {'G','e','o',0};
3547 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3548 static const WCHAR formatW
[] = {'%','i',0};
3549 UNICODE_STRING nameW
,keyW
;
3551 OBJECT_ATTRIBUTES attr
;
3554 if(!(hkey
= create_registry_key())) return FALSE
;
3556 attr
.Length
= sizeof(attr
);
3557 attr
.RootDirectory
= hkey
;
3558 attr
.ObjectName
= &nameW
;
3559 attr
.Attributes
= 0;
3560 attr
.SecurityDescriptor
= NULL
;
3561 attr
.SecurityQualityOfService
= NULL
;
3562 RtlInitUnicodeString( &nameW
, geoW
);
3563 RtlInitUnicodeString( &keyW
, nationW
);
3565 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
3568 NtClose(attr
.RootDirectory
);
3572 sprintfW(bufferW
, formatW
, GeoID
);
3573 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
3574 NtClose(attr
.RootDirectory
);
3583 UILANGUAGE_ENUMPROCA procA
;
3584 UILANGUAGE_ENUMPROCW procW
;
3588 } ENUM_UILANG_CALLBACK
;
3590 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
3591 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
3593 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3596 sprintf(buf
, "%08x", (UINT
)LangID
);
3597 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
3600 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
3601 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
3603 static const WCHAR formatW
[] = {'%','0','8','x',0};
3604 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3607 sprintfW( buf
, formatW
, (UINT
)LangID
);
3608 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
3611 /******************************************************************************
3612 * EnumUILanguagesA (KERNEL32.@)
3614 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3616 ENUM_UILANG_CALLBACK enum_uilang
;
3618 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3620 if(!pUILangEnumProc
) {
3621 SetLastError(ERROR_INVALID_PARAMETER
);
3625 SetLastError(ERROR_INVALID_FLAGS
);
3629 enum_uilang
.u
.procA
= pUILangEnumProc
;
3630 enum_uilang
.flags
= dwFlags
;
3631 enum_uilang
.param
= lParam
;
3633 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
3634 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
3635 (LONG_PTR
)&enum_uilang
);
3639 /******************************************************************************
3640 * EnumUILanguagesW (KERNEL32.@)
3642 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3644 ENUM_UILANG_CALLBACK enum_uilang
;
3646 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3649 if(!pUILangEnumProc
) {
3650 SetLastError(ERROR_INVALID_PARAMETER
);
3654 SetLastError(ERROR_INVALID_FLAGS
);
3658 enum_uilang
.u
.procW
= pUILangEnumProc
;
3659 enum_uilang
.flags
= dwFlags
;
3660 enum_uilang
.param
= lParam
;
3662 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
3663 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
3664 (LONG_PTR
)&enum_uilang
);
3668 INT WINAPI
GetGeoInfoW(GEOID GeoId
, GEOTYPE GeoType
, LPWSTR lpGeoData
,
3669 int cchData
, LANGID language
)
3671 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);
3675 INT WINAPI
GetGeoInfoA(GEOID GeoId
, GEOTYPE GeoType
, LPSTR lpGeoData
,
3676 int cchData
, LANGID language
)
3678 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);