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|\
57 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
59 /* current code pages */
60 static const union cptable
*ansi_cptable
;
61 static const union cptable
*oem_cptable
;
62 static const union cptable
*mac_cptable
;
63 static const union cptable
*unix_cptable
; /* NULL if UTF8 */
65 static const WCHAR szNlsKeyName
[] = {
66 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
68 'C','o','n','t','r','o','l','\\','N','l','s','\0'
71 static const WCHAR szLocaleKeyName
[] = {
72 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
73 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
74 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
77 static const WCHAR szCodepageKeyName
[] = {
78 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
79 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
80 'C','o','n','t','r','o','l','\\','N','l','s','\\','C','o','d','e','p','a','g','e',0
83 static const WCHAR szLangGroupsKeyName
[] = {
84 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
85 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
86 'C','o','n','t','r','o','l','\\','N','l','s','\\',
87 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
90 /* Charset to codepage map, sorted by name. */
91 static const struct charset_entry
93 const char *charset_name
;
132 { "ISO88591", 28591 },
133 { "ISO885910", 28600 },
134 { "ISO885913", 28603 },
135 { "ISO885914", 28604 },
136 { "ISO885915", 28605 },
137 { "ISO885916", 28606 },
138 { "ISO88592", 28592 },
139 { "ISO88593", 28593 },
140 { "ISO88594", 28594 },
141 { "ISO88595", 28595 },
142 { "ISO88596", 28596 },
143 { "ISO88597", 28597 },
144 { "ISO88598", 28598 },
145 { "ISO88599", 28599 },
154 WCHAR win_name
[128]; /* Windows name ("en-US") */
155 WCHAR lang
[128]; /* language ("en") (note: buffer contains the other strings too) */
156 WCHAR
*country
; /* country ("US") */
157 WCHAR
*charset
; /* charset ("UTF-8") for Unix format only */
158 WCHAR
*script
; /* script ("Latn") for Windows format only */
159 WCHAR
*modifier
; /* modifier or sort order */
160 LCID lcid
; /* corresponding LCID */
161 int matches
; /* number of elements matching LCID (0..4) */
162 UINT codepage
; /* codepage corresponding to charset */
165 /* locale ids corresponding to the various Unix locale parameters */
166 static LCID lcid_LC_COLLATE
;
167 static LCID lcid_LC_CTYPE
;
168 static LCID lcid_LC_MESSAGES
;
169 static LCID lcid_LC_MONETARY
;
170 static LCID lcid_LC_NUMERIC
;
171 static LCID lcid_LC_TIME
;
172 static LCID lcid_LC_PAPER
;
173 static LCID lcid_LC_MEASUREMENT
;
174 static LCID lcid_LC_TELEPHONE
;
176 /* Copy Ascii string to Unicode without using codepages */
177 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
179 while (n
> 1 && *src
)
181 *dst
++ = (unsigned char)*src
++;
188 /***********************************************************************
191 * Retrieve the ANSI codepage for a given locale.
193 static inline UINT
get_lcid_codepage( LCID lcid
)
196 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
197 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
202 /***********************************************************************
205 * Find the table for a given codepage, handling CP_ACP etc. pseudo-codepages
207 static const union cptable
*get_codepage_table( unsigned int codepage
)
209 const union cptable
*ret
= NULL
;
211 assert( ansi_cptable
); /* init must have been done already */
225 if (NtCurrentTeb()->CurrentLocale
== GetUserDefaultLCID()) return ansi_cptable
;
226 codepage
= get_lcid_codepage( NtCurrentTeb()->CurrentLocale
);
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
= entry
;
245 return strcasecmp( 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 TRACE("%s\n", debugstr_w(str
));
356 name
->country
= name
->charset
= name
->script
= name
->modifier
= NULL
;
357 name
->lcid
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
360 name
->win_name
[0] = 0;
361 lstrcpynW( name
->lang
, str
, sizeof(name
->lang
)/sizeof(WCHAR
) );
363 if (!(p
= strpbrkW( name
->lang
, sepW
)))
365 if (!strcmpW( name
->lang
, posixW
) || !strcmpW( name
->lang
, cW
))
367 name
->matches
= 4; /* perfect match for default English lcid */
370 strcpyW( name
->win_name
, name
->lang
);
372 else if (*p
== '-') /* Windows format */
374 strcpyW( name
->win_name
, name
->lang
);
377 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
381 name
->script
= name
->country
;
383 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
388 else /* Unix format */
394 p
= strpbrkW( p
, sepW
+ 2 );
400 p
= strchrW( p
, '@' );
409 name
->codepage
= find_charset( name
->charset
);
411 /* rebuild a Windows name if possible */
413 if (name
->charset
) goto done
; /* can't specify charset in Windows format */
414 if (name
->modifier
&& strcmpW( name
->modifier
, latinW
))
415 goto done
; /* only Latn script supported for now */
416 strcpyW( name
->win_name
, name
->lang
);
417 if (name
->modifier
) strcatW( name
->win_name
, latnW
);
420 p
= name
->win_name
+ strlenW(name
->win_name
);
422 strcpyW( p
, name
->country
);
426 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
, (LPCWSTR
)LOCALE_ILANGUAGE
,
427 find_locale_id_callback
, (LPARAM
)name
);
431 /***********************************************************************
432 * convert_default_lcid
434 * Get the default LCID to use for a given lctype in GetLocaleInfo.
436 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
438 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
439 lcid
== LOCALE_USER_DEFAULT
||
440 lcid
== LOCALE_NEUTRAL
)
444 switch(lctype
& 0xffff)
446 case LOCALE_SSORTNAME
:
447 default_id
= lcid_LC_COLLATE
;
450 case LOCALE_FONTSIGNATURE
:
451 case LOCALE_IDEFAULTANSICODEPAGE
:
452 case LOCALE_IDEFAULTCODEPAGE
:
453 case LOCALE_IDEFAULTEBCDICCODEPAGE
:
454 case LOCALE_IDEFAULTMACCODEPAGE
:
455 case LOCALE_IDEFAULTUNIXCODEPAGE
:
456 default_id
= lcid_LC_CTYPE
;
459 case LOCALE_ICURRDIGITS
:
460 case LOCALE_ICURRENCY
:
461 case LOCALE_IINTLCURRDIGITS
:
462 case LOCALE_INEGCURR
:
463 case LOCALE_INEGSEPBYSPACE
:
464 case LOCALE_INEGSIGNPOSN
:
465 case LOCALE_INEGSYMPRECEDES
:
466 case LOCALE_IPOSSEPBYSPACE
:
467 case LOCALE_IPOSSIGNPOSN
:
468 case LOCALE_IPOSSYMPRECEDES
:
469 case LOCALE_SCURRENCY
:
470 case LOCALE_SINTLSYMBOL
:
471 case LOCALE_SMONDECIMALSEP
:
472 case LOCALE_SMONGROUPING
:
473 case LOCALE_SMONTHOUSANDSEP
:
474 case LOCALE_SNATIVECURRNAME
:
475 default_id
= lcid_LC_MONETARY
;
479 case LOCALE_IDIGITSUBSTITUTION
:
481 case LOCALE_INEGNUMBER
:
482 case LOCALE_SDECIMAL
:
483 case LOCALE_SGROUPING
:
485 case LOCALE_SNATIVEDIGITS
:
486 case LOCALE_SNEGATIVESIGN
:
487 case LOCALE_SNEGINFINITY
:
488 case LOCALE_SPOSINFINITY
:
489 case LOCALE_SPOSITIVESIGN
:
490 case LOCALE_STHOUSAND
:
491 default_id
= lcid_LC_NUMERIC
;
494 case LOCALE_ICALENDARTYPE
:
495 case LOCALE_ICENTURY
:
497 case LOCALE_IDAYLZERO
:
498 case LOCALE_IFIRSTDAYOFWEEK
:
499 case LOCALE_IFIRSTWEEKOFYEAR
:
501 case LOCALE_IMONLZERO
:
502 case LOCALE_IOPTIONALCALENDAR
:
504 case LOCALE_ITIMEMARKPOSN
:
508 case LOCALE_SABBREVDAYNAME1
:
509 case LOCALE_SABBREVDAYNAME2
:
510 case LOCALE_SABBREVDAYNAME3
:
511 case LOCALE_SABBREVDAYNAME4
:
512 case LOCALE_SABBREVDAYNAME5
:
513 case LOCALE_SABBREVDAYNAME6
:
514 case LOCALE_SABBREVDAYNAME7
:
515 case LOCALE_SABBREVMONTHNAME1
:
516 case LOCALE_SABBREVMONTHNAME2
:
517 case LOCALE_SABBREVMONTHNAME3
:
518 case LOCALE_SABBREVMONTHNAME4
:
519 case LOCALE_SABBREVMONTHNAME5
:
520 case LOCALE_SABBREVMONTHNAME6
:
521 case LOCALE_SABBREVMONTHNAME7
:
522 case LOCALE_SABBREVMONTHNAME8
:
523 case LOCALE_SABBREVMONTHNAME9
:
524 case LOCALE_SABBREVMONTHNAME10
:
525 case LOCALE_SABBREVMONTHNAME11
:
526 case LOCALE_SABBREVMONTHNAME12
:
527 case LOCALE_SABBREVMONTHNAME13
:
529 case LOCALE_SDAYNAME1
:
530 case LOCALE_SDAYNAME2
:
531 case LOCALE_SDAYNAME3
:
532 case LOCALE_SDAYNAME4
:
533 case LOCALE_SDAYNAME5
:
534 case LOCALE_SDAYNAME6
:
535 case LOCALE_SDAYNAME7
:
536 case LOCALE_SDURATION
:
537 case LOCALE_SLONGDATE
:
538 case LOCALE_SMONTHNAME1
:
539 case LOCALE_SMONTHNAME2
:
540 case LOCALE_SMONTHNAME3
:
541 case LOCALE_SMONTHNAME4
:
542 case LOCALE_SMONTHNAME5
:
543 case LOCALE_SMONTHNAME6
:
544 case LOCALE_SMONTHNAME7
:
545 case LOCALE_SMONTHNAME8
:
546 case LOCALE_SMONTHNAME9
:
547 case LOCALE_SMONTHNAME10
:
548 case LOCALE_SMONTHNAME11
:
549 case LOCALE_SMONTHNAME12
:
550 case LOCALE_SMONTHNAME13
:
551 case LOCALE_SSHORTDATE
:
552 case LOCALE_SSHORTESTDAYNAME1
:
553 case LOCALE_SSHORTESTDAYNAME2
:
554 case LOCALE_SSHORTESTDAYNAME3
:
555 case LOCALE_SSHORTESTDAYNAME4
:
556 case LOCALE_SSHORTESTDAYNAME5
:
557 case LOCALE_SSHORTESTDAYNAME6
:
558 case LOCALE_SSHORTESTDAYNAME7
:
560 case LOCALE_STIMEFORMAT
:
561 case LOCALE_SYEARMONTH
:
562 default_id
= lcid_LC_TIME
;
565 case LOCALE_IPAPERSIZE
:
566 default_id
= lcid_LC_PAPER
;
569 case LOCALE_IMEASURE
:
570 default_id
= lcid_LC_MEASUREMENT
;
573 case LOCALE_ICOUNTRY
:
574 default_id
= lcid_LC_TELEPHONE
;
577 if (default_id
) lcid
= default_id
;
579 return ConvertDefaultLocale( lcid
);
582 /***********************************************************************
583 * is_genitive_name_supported
585 * Determine could LCTYPE basically support genitive name form or not.
587 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
589 switch(lctype
& 0xffff)
591 case LOCALE_SMONTHNAME1
:
592 case LOCALE_SMONTHNAME2
:
593 case LOCALE_SMONTHNAME3
:
594 case LOCALE_SMONTHNAME4
:
595 case LOCALE_SMONTHNAME5
:
596 case LOCALE_SMONTHNAME6
:
597 case LOCALE_SMONTHNAME7
:
598 case LOCALE_SMONTHNAME8
:
599 case LOCALE_SMONTHNAME9
:
600 case LOCALE_SMONTHNAME10
:
601 case LOCALE_SMONTHNAME11
:
602 case LOCALE_SMONTHNAME12
:
603 case LOCALE_SMONTHNAME13
:
610 /***********************************************************************
611 * create_registry_key
613 * Create the Control Panel\\International registry key.
615 static inline HANDLE
create_registry_key(void)
617 static const WCHAR intlW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
618 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
619 OBJECT_ATTRIBUTES attr
;
620 UNICODE_STRING nameW
;
623 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
625 attr
.Length
= sizeof(attr
);
626 attr
.RootDirectory
= hkey
;
627 attr
.ObjectName
= &nameW
;
629 attr
.SecurityDescriptor
= NULL
;
630 attr
.SecurityQualityOfService
= NULL
;
631 RtlInitUnicodeString( &nameW
, intlW
);
633 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) hkey
= 0;
634 NtClose( attr
.RootDirectory
);
639 /* update the registry settings for a given locale parameter */
640 /* return TRUE if an update was needed */
641 static BOOL
locale_update_registry( HKEY hkey
, const WCHAR
*name
, LCID lcid
,
642 const LCTYPE
*values
, UINT nb_values
)
644 static const WCHAR formatW
[] = { '%','0','8','x',0 };
646 UNICODE_STRING nameW
;
649 RtlInitUnicodeString( &nameW
, name
);
650 count
= sizeof(bufferW
);
651 if (!NtQueryValueKey(hkey
, &nameW
, KeyValuePartialInformation
, bufferW
, count
, &count
))
653 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
654 LPCWSTR text
= (LPCWSTR
)info
->Data
;
656 if (strtoulW( text
, NULL
, 16 ) == lcid
) return FALSE
; /* already set correctly */
657 TRACE( "updating registry, locale %s changed %s -> %08x\n",
658 debugstr_w(name
), debugstr_w(text
), lcid
);
660 else TRACE( "updating registry, locale %s changed none -> %08x\n", debugstr_w(name
), lcid
);
661 sprintfW( bufferW
, formatW
, lcid
);
662 NtSetValueKey( hkey
, &nameW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
) );
664 for (i
= 0; i
< nb_values
; i
++)
666 GetLocaleInfoW( lcid
, values
[i
] | LOCALE_NOUSEROVERRIDE
, bufferW
,
667 sizeof(bufferW
)/sizeof(WCHAR
) );
668 SetLocaleInfoW( lcid
, values
[i
], bufferW
);
674 /***********************************************************************
675 * LOCALE_InitRegistry
677 * Update registry contents on startup if the user locale has changed.
678 * This simulates the action of the Windows control panel.
680 void LOCALE_InitRegistry(void)
682 static const WCHAR acpW
[] = {'A','C','P',0};
683 static const WCHAR oemcpW
[] = {'O','E','M','C','P',0};
684 static const WCHAR maccpW
[] = {'M','A','C','C','P',0};
685 static const WCHAR localeW
[] = {'L','o','c','a','l','e',0};
686 static const WCHAR lc_ctypeW
[] = { 'L','C','_','C','T','Y','P','E',0 };
687 static const WCHAR lc_monetaryW
[] = { 'L','C','_','M','O','N','E','T','A','R','Y',0 };
688 static const WCHAR lc_numericW
[] = { 'L','C','_','N','U','M','E','R','I','C',0 };
689 static const WCHAR lc_timeW
[] = { 'L','C','_','T','I','M','E',0 };
690 static const WCHAR lc_measurementW
[] = { 'L','C','_','M','E','A','S','U','R','E','M','E','N','T',0 };
691 static const WCHAR lc_telephoneW
[] = { 'L','C','_','T','E','L','E','P','H','O','N','E',0 };
692 static const WCHAR lc_paperW
[] = { 'L','C','_','P','A','P','E','R',0};
697 } update_cp_values
[] = {
698 { acpW
, LOCALE_IDEFAULTANSICODEPAGE
},
699 { oemcpW
, LOCALE_IDEFAULTCODEPAGE
},
700 { maccpW
, LOCALE_IDEFAULTMACCODEPAGE
}
702 static const LCTYPE lc_messages_values
[] = {
703 LOCALE_SABBREVLANGNAME
,
706 static const LCTYPE lc_monetary_values
[] = {
712 LOCALE_SMONDECIMALSEP
,
714 LOCALE_SMONTHOUSANDSEP
};
715 static const LCTYPE lc_numeric_values
[] = {
719 LOCALE_IDIGITSUBSTITUTION
,
720 LOCALE_SNATIVEDIGITS
,
722 LOCALE_SNEGATIVESIGN
,
723 LOCALE_SPOSITIVESIGN
,
725 static const LCTYPE lc_time_values
[] = {
734 LOCALE_ITIMEMARKPOSN
,
735 LOCALE_ICALENDARTYPE
,
736 LOCALE_IFIRSTDAYOFWEEK
,
737 LOCALE_IFIRSTWEEKOFYEAR
,
741 static const LCTYPE lc_measurement_values
[] = { LOCALE_IMEASURE
};
742 static const LCTYPE lc_telephone_values
[] = { LOCALE_ICOUNTRY
};
743 static const LCTYPE lc_paper_values
[] = { LOCALE_IPAPERSIZE
};
745 UNICODE_STRING nameW
;
749 LCID lcid
= GetUserDefaultLCID();
751 if (!(hkey
= create_registry_key()))
752 return; /* don't do anything if we can't create the registry key */
754 locale_update_registry( hkey
, localeW
, lcid_LC_MESSAGES
, lc_messages_values
,
755 sizeof(lc_messages_values
)/sizeof(lc_messages_values
[0]) );
756 locale_update_registry( hkey
, lc_monetaryW
, lcid_LC_MONETARY
, lc_monetary_values
,
757 sizeof(lc_monetary_values
)/sizeof(lc_monetary_values
[0]) );
758 locale_update_registry( hkey
, lc_numericW
, lcid_LC_NUMERIC
, lc_numeric_values
,
759 sizeof(lc_numeric_values
)/sizeof(lc_numeric_values
[0]) );
760 locale_update_registry( hkey
, lc_timeW
, lcid_LC_TIME
, lc_time_values
,
761 sizeof(lc_time_values
)/sizeof(lc_time_values
[0]) );
762 locale_update_registry( hkey
, lc_measurementW
, lcid_LC_MEASUREMENT
, lc_measurement_values
,
763 sizeof(lc_measurement_values
)/sizeof(lc_measurement_values
[0]) );
764 locale_update_registry( hkey
, lc_telephoneW
, lcid_LC_TELEPHONE
, lc_telephone_values
,
765 sizeof(lc_telephone_values
)/sizeof(lc_telephone_values
[0]) );
766 locale_update_registry( hkey
, lc_paperW
, lcid_LC_PAPER
, lc_paper_values
,
767 sizeof(lc_paper_values
)/sizeof(lc_paper_values
[0]) );
769 if (locale_update_registry( hkey
, lc_ctypeW
, lcid_LC_CTYPE
, NULL
, 0 ))
771 OBJECT_ATTRIBUTES attr
;
774 RtlInitUnicodeString( &nameW
, szCodepageKeyName
);
775 InitializeObjectAttributes( &attr
, &nameW
, 0, 0, NULL
);
776 if (!NtCreateKey( &nls_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
778 for (i
= 0; i
< sizeof(update_cp_values
)/sizeof(update_cp_values
[0]); i
++)
780 count
= GetLocaleInfoW( lcid
, update_cp_values
[i
].value
| LOCALE_NOUSEROVERRIDE
,
781 bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
782 RtlInitUnicodeString( &nameW
, update_cp_values
[i
].name
);
783 NtSetValueKey( nls_key
, &nameW
, 0, REG_SZ
, bufferW
, count
* sizeof(WCHAR
) );
793 /***********************************************************************
796 static UINT
setup_unix_locales(void)
798 struct locale_name locale_name
;
799 WCHAR buffer
[128], ctype_buff
[128];
803 if ((locale
= setlocale( LC_CTYPE
, NULL
)))
805 strcpynAtoW( ctype_buff
, locale
, sizeof(ctype_buff
)/sizeof(WCHAR
) );
806 parse_locale_name( ctype_buff
, &locale_name
);
807 lcid_LC_CTYPE
= locale_name
.lcid
;
808 unix_cp
= locale_name
.codepage
;
810 if (!lcid_LC_CTYPE
) /* this one needs a default value */
811 lcid_LC_CTYPE
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
813 TRACE( "got lcid %04x (%d matches) for LC_CTYPE=%s\n",
814 locale_name
.lcid
, locale_name
.matches
, debugstr_a(locale
) );
816 #define GET_UNIX_LOCALE(cat) do \
817 if ((locale = setlocale( cat, NULL ))) \
819 strcpynAtoW( buffer, locale, sizeof(buffer)/sizeof(WCHAR) ); \
820 if (!strcmpW( buffer, ctype_buff )) lcid_##cat = lcid_LC_CTYPE; \
822 parse_locale_name( buffer, &locale_name ); \
823 lcid_##cat = locale_name.lcid; \
824 TRACE( "got lcid %04x (%d matches) for " #cat "=%s\n", \
825 locale_name.lcid, locale_name.matches, debugstr_a(locale) ); \
829 GET_UNIX_LOCALE( LC_COLLATE
);
830 GET_UNIX_LOCALE( LC_MESSAGES
);
831 GET_UNIX_LOCALE( LC_MONETARY
);
832 GET_UNIX_LOCALE( LC_NUMERIC
);
833 GET_UNIX_LOCALE( LC_TIME
);
835 GET_UNIX_LOCALE( LC_PAPER
);
837 #ifdef LC_MEASUREMENT
838 GET_UNIX_LOCALE( LC_MEASUREMENT
);
841 GET_UNIX_LOCALE( LC_TELEPHONE
);
844 #undef GET_UNIX_LOCALE
850 /***********************************************************************
851 * GetUserDefaultLangID (KERNEL32.@)
853 * Get the default language Id for the current user.
859 * The current LANGID of the default language for the current user.
861 LANGID WINAPI
GetUserDefaultLangID(void)
863 return LANGIDFROMLCID(GetUserDefaultLCID());
867 /***********************************************************************
868 * GetSystemDefaultLangID (KERNEL32.@)
870 * Get the default language Id for the system.
876 * The current LANGID of the default language for the system.
878 LANGID WINAPI
GetSystemDefaultLangID(void)
880 return LANGIDFROMLCID(GetSystemDefaultLCID());
884 /***********************************************************************
885 * GetUserDefaultLCID (KERNEL32.@)
887 * Get the default locale Id for the current user.
893 * The current LCID of the default locale for the current user.
895 LCID WINAPI
GetUserDefaultLCID(void)
898 NtQueryDefaultLocale( TRUE
, &lcid
);
903 /***********************************************************************
904 * GetSystemDefaultLCID (KERNEL32.@)
906 * Get the default locale Id for the system.
912 * The current LCID of the default locale for the system.
914 LCID WINAPI
GetSystemDefaultLCID(void)
917 NtQueryDefaultLocale( FALSE
, &lcid
);
922 /***********************************************************************
923 * GetUserDefaultUILanguage (KERNEL32.@)
925 * Get the default user interface language Id for the current user.
931 * The current LANGID of the default UI language for the current user.
933 LANGID WINAPI
GetUserDefaultUILanguage(void)
936 NtQueryDefaultUILanguage( &lang
);
941 /***********************************************************************
942 * GetSystemDefaultUILanguage (KERNEL32.@)
944 * Get the default user interface language Id for the system.
950 * The current LANGID of the default UI language for the system. This is
951 * typically the same language used during the installation process.
953 LANGID WINAPI
GetSystemDefaultUILanguage(void)
956 NtQueryInstallUILanguage( &lang
);
961 /***********************************************************************
962 * LocaleNameToLCID (KERNEL32.@)
964 LCID WINAPI
LocaleNameToLCID( LPCWSTR name
, DWORD flags
)
966 struct locale_name locale_name
;
968 if (flags
) FIXME( "unsupported flags %x\n", flags
);
970 parse_locale_name( name
, &locale_name
);
972 TRACE( "found lcid %x for %s, matches %d\n",
973 locale_name
.lcid
, debugstr_w(name
), locale_name
.matches
);
975 if (!locale_name
.matches
)
976 WARN( "locale %s not recognized, defaulting to English\n", debugstr_w(name
) );
977 else if (locale_name
.matches
== 1)
978 WARN( "locale %s not recognized, defaulting to %s\n",
979 debugstr_w(name
), debugstr_w(locale_name
.lang
) );
981 return locale_name
.lcid
;
985 /***********************************************************************
986 * LCIDToLocaleName (KERNEL32.@)
988 INT WINAPI
LCIDToLocaleName( LCID lcid
, LPWSTR name
, INT count
, DWORD flags
)
990 if (flags
) FIXME( "unsupported flags %x\n", flags
);
992 return GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, name
, count
);
996 /******************************************************************************
997 * get_locale_value_name
999 * Gets the registry value name for a given lctype.
1001 static const WCHAR
*get_locale_value_name( DWORD lctype
)
1003 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
1004 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
1005 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
1006 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
1007 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
1008 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
1009 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
1010 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
1011 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
1012 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
1013 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
1014 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
1015 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
1016 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
1017 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
1018 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
1019 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
1020 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
1021 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
1022 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
1023 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
1024 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
1025 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
1026 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
1027 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
1028 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
1029 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
1030 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
1031 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
1032 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
1033 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
1034 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
1035 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
1036 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
1037 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
1038 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
1039 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
1040 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
1041 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
1045 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
1046 * the values are stored in the registry, confirmed under Windows.
1048 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
1049 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
1050 case LOCALE_ICURRENCY
: return iCurrencyW
;
1051 case LOCALE_IDIGITS
: return iDigitsW
;
1052 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
1053 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
1054 case LOCALE_ILZERO
: return iLZeroW
;
1055 case LOCALE_IMEASURE
: return iMeasureW
;
1056 case LOCALE_INEGCURR
: return iNegCurrW
;
1057 case LOCALE_INEGNUMBER
: return iNegNumberW
;
1058 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
1059 case LOCALE_ITIME
: return iTimeW
;
1060 case LOCALE_S1159
: return s1159W
;
1061 case LOCALE_S2359
: return s2359W
;
1062 case LOCALE_SCURRENCY
: return sCurrencyW
;
1063 case LOCALE_SDATE
: return sDateW
;
1064 case LOCALE_SDECIMAL
: return sDecimalW
;
1065 case LOCALE_SGROUPING
: return sGroupingW
;
1066 case LOCALE_SLIST
: return sListW
;
1067 case LOCALE_SLONGDATE
: return sLongDateW
;
1068 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
1069 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
1070 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
1071 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
1072 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
1073 case LOCALE_SSHORTDATE
: return sShortDateW
;
1074 case LOCALE_STHOUSAND
: return sThousandW
;
1075 case LOCALE_STIME
: return sTimeW
;
1076 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
1077 case LOCALE_SYEARMONTH
: return sYearMonthW
;
1079 /* The following are not listed under MSDN as supported,
1080 * but seem to be used and also stored in the registry.
1082 case LOCALE_ICOUNTRY
: return iCountryW
;
1083 case LOCALE_IDATE
: return iDateW
;
1084 case LOCALE_ILDATE
: return iLDateW
;
1085 case LOCALE_ITLZERO
: return iTLZeroW
;
1086 case LOCALE_SCOUNTRY
: return sCountryW
;
1087 case LOCALE_SABBREVLANGNAME
: return sLanguageW
;
1089 /* The following are used in XP and later */
1090 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
1091 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
1092 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
1098 /******************************************************************************
1099 * get_registry_locale_info
1101 * Retrieve user-modified locale info from the registry.
1102 * Return length, 0 on error, -1 if not found.
1104 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
1110 UNICODE_STRING nameW
;
1111 KEY_VALUE_PARTIAL_INFORMATION
*info
;
1112 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
1114 if (!(hkey
= create_registry_key())) return -1;
1116 RtlInitUnicodeString( &nameW
, value
);
1117 size
= info_size
+ len
* sizeof(WCHAR
);
1119 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
1122 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1126 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
1130 ret
= (size
- info_size
) / sizeof(WCHAR
);
1131 /* append terminating null if needed */
1132 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
1134 if (ret
< len
|| !buffer
) ret
++;
1137 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1143 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
1147 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
1149 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
1151 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
1157 SetLastError( RtlNtStatusToDosError(status
) );
1161 HeapFree( GetProcessHeap(), 0, info
);
1166 /******************************************************************************
1167 * GetLocaleInfoA (KERNEL32.@)
1169 * Get information about an aspect of a locale.
1172 * lcid [I] LCID of the locale
1173 * lctype [I] LCTYPE_ flags from "winnls.h"
1174 * buffer [O] Destination for the information
1175 * len [I] Length of buffer in characters
1178 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1179 * with the information.
1180 * Failure: 0. Use GetLastError() to determine the cause.
1183 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1184 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1185 * which is a bit string.
1187 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
1192 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1194 if (len
< 0 || (len
&& !buffer
))
1196 SetLastError( ERROR_INVALID_PARAMETER
);
1199 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
)
1201 SetLastError( ERROR_INVALID_FLAGS
);
1205 if (!len
) buffer
= NULL
;
1207 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
1209 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
1211 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1214 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
1216 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
1217 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
1219 /* it's not an ASCII string, just bytes */
1220 ret
*= sizeof(WCHAR
);
1223 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
1226 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1233 UINT codepage
= CP_ACP
;
1234 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1235 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
1238 HeapFree( GetProcessHeap(), 0, bufferW
);
1243 /******************************************************************************
1244 * GetLocaleInfoW (KERNEL32.@)
1246 * See GetLocaleInfoA.
1248 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
1258 if (len
< 0 || (len
&& !buffer
))
1260 SetLastError( ERROR_INVALID_PARAMETER
);
1263 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&&
1264 !is_genitive_name_supported( lctype
))
1266 SetLastError( ERROR_INVALID_FLAGS
);
1270 if (!len
) buffer
= NULL
;
1272 lcid
= convert_default_lcid( lcid
, lctype
);
1274 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
1277 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1279 /* first check for overrides in the registry */
1281 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
1282 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
1284 const WCHAR
*value
= get_locale_value_name(lctype
);
1288 if (lcflags
& LOCALE_RETURN_NUMBER
)
1291 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
1295 UINT number
= strtolW( tmp
, &end
, 10 );
1296 if (*end
) /* invalid number */
1298 SetLastError( ERROR_INVALID_FLAGS
);
1301 ret
= sizeof(UINT
)/sizeof(WCHAR
);
1302 if (!buffer
) return ret
;
1305 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1308 memcpy( buffer
, &number
, sizeof(number
) );
1311 else ret
= get_registry_locale_info( value
, buffer
, len
);
1313 if (ret
!= -1) return ret
;
1317 /* now load it from kernel resources */
1319 lang_id
= LANGIDFROMLCID( lcid
);
1321 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
1322 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
1323 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
1325 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1326 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
1328 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
1331 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
1334 p
= LockResource( hmem
);
1335 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
1337 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
1338 else if (is_genitive_name_supported( lctype
) && *p
)
1340 /* genitive form's stored after a null separator from a nominative */
1341 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
1343 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
1351 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
1353 if (!buffer
) return ret
;
1357 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1361 if (lcflags
& LOCALE_RETURN_NUMBER
)
1364 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
1366 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
1368 number
= strtolW( tmp
, &end
, 10 );
1370 memcpy( buffer
, &number
, sizeof(number
) );
1371 else /* invalid number */
1373 SetLastError( ERROR_INVALID_FLAGS
);
1376 HeapFree( GetProcessHeap(), 0, tmp
);
1378 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
1379 lcid
, lctype
, buffer
, len
, number
);
1383 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
1384 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
1386 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
1387 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
1393 /******************************************************************************
1394 * SetLocaleInfoA [KERNEL32.@]
1396 * Set information about an aspect of a locale.
1399 * lcid [I] LCID of the locale
1400 * lctype [I] LCTYPE_ flags from "winnls.h"
1401 * data [I] Information to set
1404 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1405 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1406 * Failure: FALSE. Use GetLastError() to determine the cause.
1409 * - Values are only be set for the current user locale; the system locale
1410 * settings cannot be changed.
1411 * - Any settings changed by this call are lost when the locale is changed by
1412 * the control panel (in Wine, this happens every time you change LANG).
1413 * - The native implementation of this function does not check that lcid matches
1414 * the current user locale, and simply sets the new values. Wine warns you in
1415 * this case, but behaves the same.
1417 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
1419 UINT codepage
= CP_ACP
;
1424 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1428 SetLastError( ERROR_INVALID_PARAMETER
);
1431 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
1432 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1434 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1437 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
1438 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
1439 HeapFree( GetProcessHeap(), 0, strW
);
1444 /******************************************************************************
1445 * SetLocaleInfoW (KERNEL32.@)
1447 * See SetLocaleInfoA.
1449 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
1452 static const WCHAR intlW
[] = {'i','n','t','l',0 };
1453 UNICODE_STRING valueW
;
1458 value
= get_locale_value_name( lctype
);
1460 if (!data
|| !value
)
1462 SetLastError( ERROR_INVALID_PARAMETER
);
1466 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
1468 SetLastError( ERROR_INVALID_FLAGS
);
1472 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
1474 /* FIXME: should check that data to set is sane */
1476 /* FIXME: profile functions should map to registry */
1477 WriteProfileStringW( intlW
, value
, data
);
1479 if (!(hkey
= create_registry_key())) return FALSE
;
1480 RtlInitUnicodeString( &valueW
, value
);
1481 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
1483 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
1485 /* Set I-value from S value */
1486 WCHAR
*lpD
, *lpM
, *lpY
;
1489 lpD
= strrchrW(data
, 'd');
1490 lpM
= strrchrW(data
, 'M');
1491 lpY
= strrchrW(data
, 'y');
1495 szBuff
[0] = '1'; /* D-M-Y */
1500 szBuff
[0] = '2'; /* Y-M-D */
1502 szBuff
[0] = '0'; /* M-D-Y */
1507 if (lctype
== LOCALE_SSHORTDATE
)
1508 lctype
= LOCALE_IDATE
;
1510 lctype
= LOCALE_ILDATE
;
1512 value
= get_locale_value_name( lctype
);
1514 WriteProfileStringW( intlW
, value
, szBuff
);
1516 RtlInitUnicodeString( &valueW
, value
);
1517 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1522 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1527 /******************************************************************************
1528 * GetACP (KERNEL32.@)
1530 * Get the current Ansi code page Id for the system.
1536 * The current Ansi code page identifier for the system.
1538 UINT WINAPI
GetACP(void)
1540 assert( ansi_cptable
);
1541 return ansi_cptable
->info
.codepage
;
1545 /******************************************************************************
1546 * SetCPGlobal (KERNEL32.@)
1548 * Set the current Ansi code page Id for the system.
1551 * acp [I] code page ID to be the new ACP.
1556 UINT WINAPI
SetCPGlobal( UINT acp
)
1558 UINT ret
= GetACP();
1559 const union cptable
*new_cptable
= wine_cp_get_table( acp
);
1561 if (new_cptable
) ansi_cptable
= new_cptable
;
1566 /***********************************************************************
1567 * GetOEMCP (KERNEL32.@)
1569 * Get the current OEM code page Id for the system.
1575 * The current OEM code page identifier for the system.
1577 UINT WINAPI
GetOEMCP(void)
1579 assert( oem_cptable
);
1580 return oem_cptable
->info
.codepage
;
1584 /***********************************************************************
1585 * IsValidCodePage (KERNEL32.@)
1587 * Determine if a given code page identifier is valid.
1590 * codepage [I] Code page Id to verify.
1593 * TRUE, If codepage is valid and available on the system,
1596 BOOL WINAPI
IsValidCodePage( UINT codepage
)
1603 return wine_cp_get_table( codepage
) != NULL
;
1608 /***********************************************************************
1609 * IsDBCSLeadByteEx (KERNEL32.@)
1611 * Determine if a character is a lead byte in a given code page.
1614 * codepage [I] Code page for the test.
1615 * testchar [I] Character to test
1618 * TRUE, if testchar is a lead byte in codepage,
1621 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
1623 const union cptable
*table
= get_codepage_table( codepage
);
1624 return table
&& wine_is_dbcs_leadbyte( table
, testchar
);
1628 /***********************************************************************
1629 * IsDBCSLeadByte (KERNEL32.@)
1630 * IsDBCSLeadByte (KERNEL.207)
1632 * Determine if a character is a lead byte.
1635 * testchar [I] Character to test
1638 * TRUE, if testchar is a lead byte in the Ansii code page,
1641 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
1643 if (!ansi_cptable
) return FALSE
;
1644 return wine_is_dbcs_leadbyte( ansi_cptable
, testchar
);
1648 /***********************************************************************
1649 * GetCPInfo (KERNEL32.@)
1651 * Get information about a code page.
1654 * codepage [I] Code page number
1655 * cpinfo [O] Destination for code page information
1658 * Success: TRUE. cpinfo is updated with the information about codepage.
1659 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1661 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
1663 const union cptable
*table
;
1667 SetLastError( ERROR_INVALID_PARAMETER
);
1671 if (!(table
= get_codepage_table( codepage
)))
1677 cpinfo
->DefaultChar
[0] = 0x3f;
1678 cpinfo
->DefaultChar
[1] = 0;
1679 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1680 cpinfo
->MaxCharSize
= (codepage
== CP_UTF7
) ? 5 : 4;
1684 SetLastError( ERROR_INVALID_PARAMETER
);
1687 if (table
->info
.def_char
& 0xff00)
1689 cpinfo
->DefaultChar
[0] = (table
->info
.def_char
& 0xff00) >> 8;
1690 cpinfo
->DefaultChar
[1] = table
->info
.def_char
& 0x00ff;
1694 cpinfo
->DefaultChar
[0] = table
->info
.def_char
& 0xff;
1695 cpinfo
->DefaultChar
[1] = 0;
1697 if ((cpinfo
->MaxCharSize
= table
->info
.char_size
) == 2)
1698 memcpy( cpinfo
->LeadByte
, table
->dbcs
.lead_bytes
, sizeof(cpinfo
->LeadByte
) );
1700 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1705 /***********************************************************************
1706 * GetCPInfoExA (KERNEL32.@)
1708 * Get extended information about a code page.
1711 * codepage [I] Code page number
1712 * dwFlags [I] Reserved, must to 0.
1713 * cpinfo [O] Destination for code page information
1716 * Success: TRUE. cpinfo is updated with the information about codepage.
1717 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1719 BOOL WINAPI
GetCPInfoExA( UINT codepage
, DWORD dwFlags
, LPCPINFOEXA cpinfo
)
1723 if (!GetCPInfoExW( codepage
, dwFlags
, &cpinfoW
))
1726 /* the layout is the same except for CodePageName */
1727 memcpy(cpinfo
, &cpinfoW
, sizeof(CPINFOEXA
));
1728 WideCharToMultiByte(CP_ACP
, 0, cpinfoW
.CodePageName
, -1, cpinfo
->CodePageName
, sizeof(cpinfo
->CodePageName
), NULL
, NULL
);
1732 /***********************************************************************
1733 * GetCPInfoExW (KERNEL32.@)
1735 * Unicode version of GetCPInfoExA.
1737 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD dwFlags
, LPCPINFOEXW cpinfo
)
1739 if (!GetCPInfo( codepage
, (LPCPINFO
)cpinfo
))
1746 static const WCHAR utf7
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
1748 cpinfo
->CodePage
= CP_UTF7
;
1749 cpinfo
->UnicodeDefaultChar
= 0x3f;
1750 strcpyW(cpinfo
->CodePageName
, utf7
);
1756 static const WCHAR utf8
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
1758 cpinfo
->CodePage
= CP_UTF8
;
1759 cpinfo
->UnicodeDefaultChar
= 0x3f;
1760 strcpyW(cpinfo
->CodePageName
, utf8
);
1766 const union cptable
*table
= get_codepage_table( codepage
);
1768 cpinfo
->CodePage
= table
->info
.codepage
;
1769 cpinfo
->UnicodeDefaultChar
= table
->info
.def_unicode_char
;
1770 MultiByteToWideChar( CP_ACP
, 0, table
->info
.name
, -1, cpinfo
->CodePageName
,
1771 sizeof(cpinfo
->CodePageName
)/sizeof(WCHAR
));
1778 /***********************************************************************
1779 * EnumSystemCodePagesA (KERNEL32.@)
1781 * Call a user defined function for every code page installed on the system.
1784 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1785 * flags [I] Reserved, set to 0.
1788 * TRUE, If all code pages have been enumerated, or
1789 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1791 BOOL WINAPI
EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum
, DWORD flags
)
1793 const union cptable
*table
;
1799 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1800 sprintf( buffer
, "%d", table
->info
.codepage
);
1801 if (!lpfnCodePageEnum( buffer
)) break;
1807 /***********************************************************************
1808 * EnumSystemCodePagesW (KERNEL32.@)
1810 * See EnumSystemCodePagesA.
1812 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
, DWORD flags
)
1814 const union cptable
*table
;
1815 WCHAR buffer
[10], *p
;
1816 int page
, index
= 0;
1820 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1821 p
= buffer
+ sizeof(buffer
)/sizeof(WCHAR
);
1823 page
= table
->info
.codepage
;
1826 *--p
= '0' + (page
% 10);
1829 if (!lpfnCodePageEnum( p
)) break;
1835 /***********************************************************************
1836 * MultiByteToWideChar (KERNEL32.@)
1838 * Convert a multibyte character string into a Unicode string.
1841 * page [I] Codepage character set to convert from
1842 * flags [I] Character mapping flags
1843 * src [I] Source string buffer
1844 * srclen [I] Length of src (in bytes), or -1 if src is NUL terminated
1845 * dst [O] Destination buffer
1846 * dstlen [I] Length of dst (in WCHARs), or 0 to compute the required length
1849 * Success: If dstlen > 0, the number of characters written to dst.
1850 * If dstlen == 0, the number of characters needed to perform the
1851 * conversion. In both cases the count includes the terminating NUL.
1852 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1853 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1854 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1855 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1858 INT WINAPI
MultiByteToWideChar( UINT page
, DWORD flags
, LPCSTR src
, INT srclen
,
1859 LPWSTR dst
, INT dstlen
)
1861 const union cptable
*table
;
1864 if (!src
|| (!dst
&& dstlen
))
1866 SetLastError( ERROR_INVALID_PARAMETER
);
1870 if (srclen
< 0) srclen
= strlen(src
) + 1;
1877 SetLastError( ERROR_INVALID_PARAMETER
);
1880 ret
= wine_cpsymbol_mbstowcs( src
, srclen
, dst
, dstlen
);
1883 FIXME("UTF-7 not supported\n");
1884 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1889 ret
= wine_cp_mbstowcs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
);
1893 flags
|= MB_COMPOSITE
; /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
1897 ret
= wine_utf8_mbstowcs( flags
, src
, srclen
, dst
, dstlen
);
1900 if (!(table
= get_codepage_table( page
)))
1902 SetLastError( ERROR_INVALID_PARAMETER
);
1905 ret
= wine_cp_mbstowcs( table
, flags
, src
, srclen
, dst
, dstlen
);
1913 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1914 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1918 TRACE("cp %d %s -> %s, ret = %d\n",
1919 page
, debugstr_an(src
, srclen
), debugstr_wn(dst
, ret
), ret
);
1924 /***********************************************************************
1925 * WideCharToMultiByte (KERNEL32.@)
1927 * Convert a Unicode character string into a multibyte string.
1930 * page [I] Code page character set to convert to
1931 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1932 * src [I] Source string buffer
1933 * srclen [I] Length of src (in WCHARs), or -1 if src is NUL terminated
1934 * dst [O] Destination buffer
1935 * dstlen [I] Length of dst (in bytes), or 0 to compute the required length
1936 * defchar [I] Default character to use for conversion if no exact
1937 * conversion can be made
1938 * used [O] Set if default character was used in the conversion
1941 * Success: If dstlen > 0, the number of characters written to dst.
1942 * If dstlen == 0, number of characters needed to perform the
1943 * conversion. In both cases the count includes the terminating NUL.
1944 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1945 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1946 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1947 * parameter was given.
1949 INT WINAPI
WideCharToMultiByte( UINT page
, DWORD flags
, LPCWSTR src
, INT srclen
,
1950 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
1952 const union cptable
*table
;
1955 if (!src
|| (!dst
&& dstlen
))
1957 SetLastError( ERROR_INVALID_PARAMETER
);
1961 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1966 if( flags
|| defchar
|| used
)
1968 SetLastError( ERROR_INVALID_PARAMETER
);
1971 ret
= wine_cpsymbol_wcstombs( src
, srclen
, dst
, dstlen
);
1974 FIXME("UTF-7 not supported\n");
1975 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1980 ret
= wine_cp_wcstombs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
,
1981 defchar
, used
? &used_tmp
: NULL
);
1986 if (used
) *used
= FALSE
; /* all chars are valid for UTF-8 */
1987 ret
= wine_utf8_wcstombs( flags
, src
, srclen
, dst
, dstlen
);
1990 if (!(table
= get_codepage_table( page
)))
1992 SetLastError( ERROR_INVALID_PARAMETER
);
1995 ret
= wine_cp_wcstombs( table
, flags
, src
, srclen
, dst
, dstlen
,
1996 defchar
, used
? &used_tmp
: NULL
);
1997 if (used
) *used
= used_tmp
;
2005 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
2006 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
2010 TRACE("cp %d %s -> %s, ret = %d\n",
2011 page
, debugstr_wn(src
, srclen
), debugstr_an(dst
, ret
), ret
);
2016 /***********************************************************************
2017 * GetThreadLocale (KERNEL32.@)
2019 * Get the current threads locale.
2025 * The LCID currently associated with the calling thread.
2027 LCID WINAPI
GetThreadLocale(void)
2029 LCID ret
= NtCurrentTeb()->CurrentLocale
;
2030 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
2034 /**********************************************************************
2035 * SetThreadLocale (KERNEL32.@)
2037 * Set the current threads locale.
2040 * lcid [I] LCID of the locale to set
2043 * Success: TRUE. The threads locale is set to lcid.
2044 * Failure: FALSE. Use GetLastError() to determine the cause.
2046 BOOL WINAPI
SetThreadLocale( LCID lcid
)
2048 TRACE("(0x%04X)\n", lcid
);
2050 lcid
= ConvertDefaultLocale(lcid
);
2052 if (lcid
!= GetThreadLocale())
2054 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
2056 SetLastError(ERROR_INVALID_PARAMETER
);
2060 NtCurrentTeb()->CurrentLocale
= lcid
;
2065 /**********************************************************************
2066 * SetThreadUILanguage (KERNEL32.@)
2068 * Set the current threads UI language.
2071 * langid [I] LANGID of the language to set, or 0 to use
2072 * the available language which is best supported
2073 * for console applications
2076 * Success: The return value is the same as the input value.
2077 * Failure: The return value differs from the input value.
2078 * Use GetLastError() to determine the cause.
2080 LANGID WINAPI
SetThreadUILanguage( LANGID langid
)
2082 TRACE("(0x%04x) stub - returning success\n", langid
);
2086 /******************************************************************************
2087 * ConvertDefaultLocale (KERNEL32.@)
2089 * Convert a default locale identifier into a real identifier.
2092 * lcid [I] LCID identifier of the locale to convert
2095 * lcid unchanged, if not a default locale or its sublanguage is
2096 * not SUBLANG_NEUTRAL.
2097 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
2098 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
2099 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
2101 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
2107 case LOCALE_SYSTEM_DEFAULT
:
2108 lcid
= GetSystemDefaultLCID();
2110 case LOCALE_USER_DEFAULT
:
2111 case LOCALE_NEUTRAL
:
2112 lcid
= GetUserDefaultLCID();
2115 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
2116 langid
= LANGIDFROMLCID(lcid
);
2117 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
2119 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
2120 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
2127 /******************************************************************************
2128 * IsValidLocale (KERNEL32.@)
2130 * Determine if a locale is valid.
2133 * lcid [I] LCID of the locale to check
2134 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
2137 * TRUE, if lcid is valid,
2141 * Wine does not currently make the distinction between supported and installed. All
2142 * languages supported are installed by default.
2144 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
2146 /* check if language is registered in the kernel32 resources */
2147 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
2148 (LPCWSTR
)LOCALE_ILANGUAGE
, LANGIDFROMLCID(lcid
)) != 0;
2152 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
2153 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
2155 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
2158 sprintf(buf
, "%08x", (UINT
)LangID
);
2159 return lpfnLocaleEnum( buf
);
2162 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
2163 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
2165 static const WCHAR formatW
[] = {'%','0','8','x',0};
2166 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
2168 sprintfW( buf
, formatW
, (UINT
)LangID
);
2169 return lpfnLocaleEnum( buf
);
2172 /******************************************************************************
2173 * EnumSystemLocalesA (KERNEL32.@)
2175 * Call a users function for each locale available on the system.
2178 * lpfnLocaleEnum [I] Callback function to call for each locale
2179 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
2183 * Failure: FALSE. Use GetLastError() to determine the cause.
2185 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
2187 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
2188 EnumResourceLanguagesA( kernel32_handle
, (LPSTR
)RT_STRING
,
2189 (LPCSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_a
,
2190 (LONG_PTR
)lpfnLocaleEnum
);
2195 /******************************************************************************
2196 * EnumSystemLocalesW (KERNEL32.@)
2198 * See EnumSystemLocalesA.
2200 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
2202 TRACE("(%p,%08x)\n", lpfnLocaleEnum
, dwFlags
);
2203 EnumResourceLanguagesW( kernel32_handle
, (LPWSTR
)RT_STRING
,
2204 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_w
,
2205 (LONG_PTR
)lpfnLocaleEnum
);
2210 /***********************************************************************
2211 * VerLanguageNameA (KERNEL32.@)
2213 * Get the name of a language.
2216 * wLang [I] LANGID of the language
2217 * szLang [O] Destination for the language name
2220 * Success: The size of the language name. If szLang is non-NULL, it is filled
2222 * Failure: 0. Use GetLastError() to determine the cause.
2225 DWORD WINAPI
VerLanguageNameA( DWORD wLang
, LPSTR szLang
, DWORD nSize
)
2227 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
2231 /***********************************************************************
2232 * VerLanguageNameW (KERNEL32.@)
2234 * See VerLanguageNameA.
2236 DWORD WINAPI
VerLanguageNameW( DWORD wLang
, LPWSTR szLang
, DWORD nSize
)
2238 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
2242 /******************************************************************************
2243 * GetStringTypeW (KERNEL32.@)
2245 * See GetStringTypeA.
2247 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
2249 if (count
== -1) count
= strlenW(src
) + 1;
2253 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
2256 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) >> 12;
2260 WARN("CT_CTYPE3: semi-stub.\n");
2264 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
2266 type1
= get_char_typeW( *src
++ ) & 0xfff;
2267 /* try to construct type3 from type1 */
2268 if(type1
& C1_SPACE
) type3
|= C3_SYMBOL
;
2269 if(type1
& C1_ALPHA
) type3
|= C3_ALPHA
;
2270 if ((c
>=0x30A0)&&(c
<=0x30FF)) type3
|= C3_KATAKANA
;
2271 if ((c
>=0x3040)&&(c
<=0x309F)) type3
|= C3_HIRAGANA
;
2272 if ((c
>=0x4E00)&&(c
<=0x9FAF)) type3
|= C3_IDEOGRAPH
;
2273 if ((c
>=0x0600)&&(c
<=0x06FF)) type3
|= C3_KASHIDA
;
2274 if ((c
>=0x3000)&&(c
<=0x303F)) type3
|= C3_SYMBOL
;
2276 if ((c
>=0xFF00)&&(c
<=0xFF60)) type3
|= C3_FULLWIDTH
;
2277 if ((c
>=0xFF00)&&(c
<=0xFF20)) type3
|= C3_SYMBOL
;
2278 if ((c
>=0xFF3B)&&(c
<=0xFF40)) type3
|= C3_SYMBOL
;
2279 if ((c
>=0xFF5B)&&(c
<=0xFF60)) type3
|= C3_SYMBOL
;
2280 if ((c
>=0xFF21)&&(c
<=0xFF3A)) type3
|= C3_ALPHA
;
2281 if ((c
>=0xFF41)&&(c
<=0xFF5A)) type3
|= C3_ALPHA
;
2282 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_FULLWIDTH
;
2283 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_SYMBOL
;
2285 if ((c
>=0xFF61)&&(c
<=0xFFDC)) type3
|= C3_HALFWIDTH
;
2286 if ((c
>=0xFF61)&&(c
<=0xFF64)) type3
|= C3_SYMBOL
;
2287 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_KATAKANA
;
2288 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_ALPHA
;
2289 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_HALFWIDTH
;
2290 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_SYMBOL
;
2291 *chartype
++ = type3
;
2296 SetLastError( ERROR_INVALID_PARAMETER
);
2303 /******************************************************************************
2304 * GetStringTypeExW (KERNEL32.@)
2306 * See GetStringTypeExA.
2308 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
2310 /* locale is ignored for Unicode */
2311 return GetStringTypeW( type
, src
, count
, chartype
);
2315 /******************************************************************************
2316 * GetStringTypeA (KERNEL32.@)
2318 * Get characteristics of the characters making up a string.
2321 * locale [I] Locale Id for the string
2322 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2323 * src [I] String to analyse
2324 * count [I] Length of src in chars, or -1 if src is NUL terminated
2325 * chartype [O] Destination for the calculated characteristics
2328 * Success: TRUE. chartype is filled with the requested characteristics of each char
2330 * Failure: FALSE. Use GetLastError() to determine the cause.
2332 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
2339 if(count
== -1) count
= strlen(src
) + 1;
2341 if (!(cp
= get_lcid_codepage( locale
)))
2343 FIXME("For locale %04x using current ANSI code page\n", locale
);
2347 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
2348 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
2350 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
2352 * NOTE: the target buffer has 1 word for each CHARACTER in the source
2353 * string, with multibyte characters there maybe be more bytes in count
2354 * than character space in the buffer!
2356 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
2357 HeapFree(GetProcessHeap(), 0, srcW
);
2362 /******************************************************************************
2363 * GetStringTypeExA (KERNEL32.@)
2365 * Get characteristics of the characters making up a string.
2368 * locale [I] Locale Id for the string
2369 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2370 * src [I] String to analyse
2371 * count [I] Length of src in chars, or -1 if src is NUL terminated
2372 * chartype [O] Destination for the calculated characteristics
2375 * Success: TRUE. chartype is filled with the requested characteristics of each char
2377 * Failure: FALSE. Use GetLastError() to determine the cause.
2379 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
2381 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
2385 /*************************************************************************
2386 * LCMapStringW (KERNEL32.@)
2390 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
2391 LPWSTR dst
, INT dstlen
)
2395 if (!src
|| !srclen
|| dstlen
< 0)
2397 SetLastError(ERROR_INVALID_PARAMETER
);
2401 /* mutually exclusive flags */
2402 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
2403 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
2404 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
2405 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
))
2407 SetLastError(ERROR_INVALID_FLAGS
);
2411 if (!dstlen
) dst
= NULL
;
2413 lcid
= ConvertDefaultLocale(lcid
);
2415 if (flags
& LCMAP_SORTKEY
)
2420 SetLastError(ERROR_INVALID_FLAGS
);
2424 if (srclen
< 0) srclen
= strlenW(src
);
2426 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2427 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
2429 ret
= wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
2431 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2437 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
2438 if (flags
& SORT_STRINGSORT
)
2440 SetLastError(ERROR_INVALID_FLAGS
);
2444 if (srclen
< 0) srclen
= strlenW(src
) + 1;
2446 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2447 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
2449 if (!dst
) /* return required string length */
2453 for (len
= 0; srclen
; src
++, srclen
--)
2456 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
2457 * and skips white space and punctuation characters for
2458 * NORM_IGNORESYMBOLS.
2460 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2467 if (flags
& LCMAP_UPPERCASE
)
2469 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2472 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2474 *dst_ptr
++ = toupperW(wch
);
2478 else if (flags
& LCMAP_LOWERCASE
)
2480 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2483 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2485 *dst_ptr
++ = tolowerW(wch
);
2493 SetLastError(ERROR_INVALID_FLAGS
);
2496 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2499 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2508 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2512 return dst_ptr
- dst
;
2515 /*************************************************************************
2516 * LCMapStringA (KERNEL32.@)
2518 * Map characters in a locale sensitive string.
2521 * lcid [I] LCID for the conversion.
2522 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2523 * src [I] String to map
2524 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2525 * dst [O] Destination for mapped string
2526 * dstlen [I] Length of dst in characters
2529 * Success: The length of the mapped string in dst, including the NUL terminator.
2530 * Failure: 0. Use GetLastError() to determine the cause.
2532 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
2533 LPSTR dst
, INT dstlen
)
2535 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
2537 INT ret
= 0, srclenW
, dstlenW
;
2538 UINT locale_cp
= CP_ACP
;
2540 if (!src
|| !srclen
|| dstlen
< 0)
2542 SetLastError(ERROR_INVALID_PARAMETER
);
2546 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
2548 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
2553 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
2554 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2557 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2560 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
2563 if (flags
& LCMAP_SORTKEY
)
2567 SetLastError(ERROR_INVALID_FLAGS
);
2568 goto map_string_exit
;
2570 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
2572 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2575 goto map_string_exit
;
2578 if (flags
& SORT_STRINGSORT
)
2580 SetLastError(ERROR_INVALID_FLAGS
);
2581 goto map_string_exit
;
2584 dstlenW
= LCMapStringW(lcid
, flags
, srcW
, srclenW
, NULL
, 0);
2586 goto map_string_exit
;
2588 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
2591 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2592 goto map_string_exit
;
2595 LCMapStringW(lcid
, flags
, srcW
, srclenW
, dstW
, dstlenW
);
2596 ret
= WideCharToMultiByte(locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
2597 HeapFree(GetProcessHeap(), 0, dstW
);
2600 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
2604 /*************************************************************************
2605 * FoldStringA (KERNEL32.@)
2607 * Map characters in a string.
2610 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2611 * src [I] String to map
2612 * srclen [I] Length of src, or -1 if src is NUL terminated
2613 * dst [O] Destination for mapped string
2614 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2617 * Success: The length of the string written to dst, including the terminating NUL. If
2618 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2619 * and dst may be NULL.
2620 * Failure: 0. Use GetLastError() to determine the cause.
2622 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
2623 LPSTR dst
, INT dstlen
)
2625 INT ret
= 0, srclenW
= 0;
2626 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
2628 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2630 SetLastError(ERROR_INVALID_PARAMETER
);
2634 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2635 src
, srclen
, NULL
, 0);
2636 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2640 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2641 goto FoldStringA_exit
;
2644 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2645 src
, srclen
, srcW
, srclenW
);
2647 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
2649 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
2652 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
2656 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2657 goto FoldStringA_exit
;
2660 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
2661 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
2664 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2668 HeapFree(GetProcessHeap(), 0, dstW
);
2671 HeapFree(GetProcessHeap(), 0, srcW
);
2675 /*************************************************************************
2676 * FoldStringW (KERNEL32.@)
2680 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
2681 LPWSTR dst
, INT dstlen
)
2685 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
2690 /* Fall through for dwFlags == 0 */
2691 case MAP_PRECOMPOSED
|MAP_COMPOSITE
:
2692 case MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
:
2693 case MAP_COMPOSITE
|MAP_EXPAND_LIGATURES
:
2694 SetLastError(ERROR_INVALID_FLAGS
);
2698 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2700 SetLastError(ERROR_INVALID_PARAMETER
);
2704 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
2706 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2710 /******************************************************************************
2711 * CompareStringW (KERNEL32.@)
2713 * See CompareStringA.
2715 INT WINAPI
CompareStringW(LCID lcid
, DWORD style
,
2716 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
2722 SetLastError(ERROR_INVALID_PARAMETER
);
2726 if( style
& ~(NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
|
2727 SORT_STRINGSORT
|NORM_IGNOREKANATYPE
|NORM_IGNOREWIDTH
|LOCALE_USE_CP_ACP
|0x10000000) )
2729 SetLastError(ERROR_INVALID_FLAGS
);
2733 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
2734 if (style
& 0x10000000)
2735 WARN("Ignoring unknown style 0x10000000\n");
2737 if (len1
< 0) len1
= strlenW(str1
);
2738 if (len2
< 0) len2
= strlenW(str2
);
2740 ret
= wine_compare_string(style
, str1
, len1
, str2
, len2
);
2742 if (ret
) /* need to translate result */
2743 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
2747 /******************************************************************************
2748 * CompareStringA (KERNEL32.@)
2750 * Compare two locale sensitive strings.
2753 * lcid [I] LCID for the comparison
2754 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
2755 * str1 [I] First string to compare
2756 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2757 * str2 [I] Second string to compare
2758 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2761 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2762 * str2 is less than, equal to or greater than str1 respectively.
2763 * Failure: FALSE. Use GetLastError() to determine the cause.
2765 INT WINAPI
CompareStringA(LCID lcid
, DWORD style
,
2766 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
2768 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
2769 WCHAR
*buf2W
= buf1W
+ 130;
2770 LPWSTR str1W
, str2W
;
2771 INT len1W
, len2W
, ret
;
2772 UINT locale_cp
= CP_ACP
;
2776 SetLastError(ERROR_INVALID_PARAMETER
);
2779 if (len1
< 0) len1
= strlen(str1
);
2780 if (len2
< 0) len2
= strlen(str2
);
2782 if (!(style
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
2784 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
2789 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
2790 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
2793 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2796 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
2798 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
2803 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
2804 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
2807 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2808 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2811 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
2814 ret
= CompareStringW(lcid
, style
, str1W
, len1W
, str2W
, len2W
);
2816 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2817 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
2821 /*************************************************************************
2822 * lstrcmp (KERNEL32.@)
2823 * lstrcmpA (KERNEL32.@)
2825 * Compare two strings using the current thread locale.
2828 * str1 [I] First string to compare
2829 * str2 [I] Second string to compare
2832 * Success: A number less than, equal to or greater than 0 depending on whether
2833 * str2 is less than, equal to or greater than str1 respectively.
2834 * Failure: FALSE. Use GetLastError() to determine the cause.
2836 int WINAPI
lstrcmpA(LPCSTR str1
, LPCSTR str2
)
2840 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2841 if (str1
== NULL
) return -1;
2842 if (str2
== NULL
) return 1;
2844 ret
= CompareStringA(GetThreadLocale(), LOCALE_USE_CP_ACP
, str1
, -1, str2
, -1);
2850 /*************************************************************************
2851 * lstrcmpi (KERNEL32.@)
2852 * lstrcmpiA (KERNEL32.@)
2854 * Compare two strings using the current thread locale, ignoring case.
2857 * str1 [I] First string to compare
2858 * str2 [I] Second string to compare
2861 * Success: A number less than, equal to or greater than 0 depending on whether
2862 * str2 is less than, equal to or greater than str1 respectively.
2863 * Failure: FALSE. Use GetLastError() to determine the cause.
2865 int WINAPI
lstrcmpiA(LPCSTR str1
, LPCSTR str2
)
2869 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2870 if (str1
== NULL
) return -1;
2871 if (str2
== NULL
) return 1;
2873 ret
= CompareStringA(GetThreadLocale(), NORM_IGNORECASE
|LOCALE_USE_CP_ACP
, str1
, -1, str2
, -1);
2879 /*************************************************************************
2880 * lstrcmpW (KERNEL32.@)
2884 int WINAPI
lstrcmpW(LPCWSTR str1
, LPCWSTR str2
)
2888 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2889 if (str1
== NULL
) return -1;
2890 if (str2
== NULL
) return 1;
2892 ret
= CompareStringW(GetThreadLocale(), 0, str1
, -1, str2
, -1);
2898 /*************************************************************************
2899 * lstrcmpiW (KERNEL32.@)
2903 int WINAPI
lstrcmpiW(LPCWSTR str1
, LPCWSTR str2
)
2907 if ((str1
== NULL
) && (str2
== NULL
)) return 0;
2908 if (str1
== NULL
) return -1;
2909 if (str2
== NULL
) return 1;
2911 ret
= CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, str1
, -1, str2
, -1);
2917 /******************************************************************************
2920 void LOCALE_Init(void)
2922 extern void CDECL
__wine_init_codepages( const union cptable
*ansi_cp
, const union cptable
*oem_cp
,
2923 const union cptable
*unix_cp
);
2925 UINT ansi_cp
= 1252, oem_cp
= 437, mac_cp
= 10000, unix_cp
;
2928 /* MacOS doesn't set the locale environment variables so we have to do it ourselves */
2929 char user_locale
[50];
2931 CFLocaleRef user_locale_ref
= CFLocaleCopyCurrent();
2932 CFStringRef user_locale_lang_ref
= CFLocaleGetValue( user_locale_ref
, kCFLocaleLanguageCode
);
2933 CFStringRef user_locale_country_ref
= CFLocaleGetValue( user_locale_ref
, kCFLocaleCountryCode
);
2934 CFStringRef user_locale_string_ref
;
2936 if (user_locale_country_ref
)
2938 user_locale_string_ref
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@_%@.UTF-8"),
2939 user_locale_lang_ref
, user_locale_country_ref
);
2943 user_locale_string_ref
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@.UTF-8"),
2944 user_locale_lang_ref
);
2947 CFStringGetCString( user_locale_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2949 unix_cp
= CP_UTF8
; /* default to utf-8 even if we don't get a valid locale */
2950 setenv( "LANG", user_locale
, 0 );
2951 TRACE( "setting locale to '%s'\n", user_locale
);
2952 #endif /* __APPLE__ */
2954 setlocale( LC_ALL
, "" );
2956 unix_cp
= setup_unix_locales();
2957 if (!lcid_LC_MESSAGES
) lcid_LC_MESSAGES
= lcid_LC_CTYPE
;
2960 /* Override lcid_LC_MESSAGES with user's preferred language if LC_MESSAGES is set to default */
2961 if (!getenv("LC_ALL") && !getenv("LC_MESSAGES"))
2963 /* Retrieve the preferred language as chosen in System Preferences. */
2964 /* If language is a less specific variant of locale (e.g. 'en' vs. 'en_US'),
2966 CFArrayRef all_locales
= CFLocaleCopyAvailableLocaleIdentifiers();
2967 CFArrayRef preferred_locales
= CFBundleCopyLocalizationsForPreferences( all_locales
, NULL
);
2968 CFStringRef user_language_string_ref
;
2969 if (preferred_locales
&& CFArrayGetCount( preferred_locales
) &&
2970 (user_language_string_ref
= CFArrayGetValueAtIndex( preferred_locales
, 0 )) &&
2971 !CFEqual(user_language_string_ref
, user_locale_lang_ref
))
2973 struct locale_name locale_name
;
2975 CFStringGetCString( user_language_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2976 strcpynAtoW( buffer
, user_locale
, sizeof(buffer
)/sizeof(WCHAR
) );
2977 parse_locale_name( buffer
, &locale_name
);
2978 lcid_LC_MESSAGES
= locale_name
.lcid
;
2979 TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale
);
2981 CFRelease( all_locales
);
2982 if (preferred_locales
)
2983 CFRelease( preferred_locales
);
2986 CFRelease( user_locale_ref
);
2987 CFRelease( user_locale_string_ref
);
2990 NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES
) );
2991 NtSetDefaultLocale( TRUE
, lcid_LC_MESSAGES
);
2992 NtSetDefaultLocale( FALSE
, lcid_LC_CTYPE
);
2994 ansi_cp
= get_lcid_codepage( LOCALE_USER_DEFAULT
);
2995 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
2996 (LPWSTR
)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
2997 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
2998 (LPWSTR
)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
3000 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
3001 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) );
3003 if (!(ansi_cptable
= wine_cp_get_table( ansi_cp
)))
3004 ansi_cptable
= wine_cp_get_table( 1252 );
3005 if (!(oem_cptable
= wine_cp_get_table( oem_cp
)))
3006 oem_cptable
= wine_cp_get_table( 437 );
3007 if (!(mac_cptable
= wine_cp_get_table( mac_cp
)))
3008 mac_cptable
= wine_cp_get_table( 10000 );
3009 if (unix_cp
!= CP_UTF8
)
3011 if (!(unix_cptable
= wine_cp_get_table( unix_cp
)))
3012 unix_cptable
= wine_cp_get_table( 28591 );
3015 __wine_init_codepages( ansi_cptable
, oem_cptable
, unix_cptable
);
3017 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
3018 ansi_cptable
->info
.codepage
, oem_cptable
->info
.codepage
,
3019 mac_cptable
->info
.codepage
, unix_cp
);
3021 setlocale(LC_NUMERIC
, "C"); /* FIXME: oleaut32 depends on this */
3024 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
3026 UNICODE_STRING keyName
;
3027 OBJECT_ATTRIBUTES attr
;
3030 RtlInitUnicodeString( &keyName
, szKeyName
);
3031 InitializeObjectAttributes(&attr
, &keyName
, 0, hRootKey
, NULL
);
3033 if (NtOpenKey( &hkey
, KEY_READ
, &attr
) != STATUS_SUCCESS
)
3039 static BOOL
NLS_RegEnumSubKey(HANDLE hKey
, UINT ulIndex
, LPWSTR szKeyName
,
3043 KEY_BASIC_INFORMATION
*info
= (KEY_BASIC_INFORMATION
*)buffer
;
3046 if (NtEnumerateKey( hKey
, ulIndex
, KeyBasicInformation
, buffer
,
3047 sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
3048 info
->NameLength
> keyNameSize
)
3053 TRACE("info->Name %s info->NameLength %d\n", debugstr_w(info
->Name
), info
->NameLength
);
3055 memcpy( szKeyName
, info
->Name
, info
->NameLength
);
3056 szKeyName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
3058 TRACE("returning %s\n", debugstr_w(szKeyName
));
3062 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
3063 LPWSTR szValueName
, ULONG valueNameSize
,
3064 LPWSTR szValueData
, ULONG valueDataSize
)
3067 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
3070 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
3071 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
3072 info
->NameLength
> valueNameSize
||
3073 info
->DataLength
> valueDataSize
)
3078 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
3080 memcpy( szValueName
, info
->Name
, info
->NameLength
);
3081 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
3082 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
3083 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
3085 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
3089 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
3092 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
3093 DWORD dwSize
= sizeof(buffer
);
3094 UNICODE_STRING valueName
;
3096 RtlInitUnicodeString( &valueName
, szValueName
);
3098 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
3099 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
3100 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
3101 info
->DataLength
== sizeof(DWORD
))
3103 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
3110 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
3113 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
3117 /* FIXME: Is it correct to use the system default langid? */
3118 langId
= GetSystemDefaultLangID();
3120 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
3121 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
3123 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
3127 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
3131 ULONG iResourceIndex
= lgrpid
& 0xf;
3132 LPCWSTR lpResEntry
= LockResource( hResDir
);
3135 for (i
= 0; i
< iResourceIndex
; i
++)
3136 lpResEntry
+= *lpResEntry
+ 1;
3138 if (*lpResEntry
< nameSize
)
3140 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
3141 szName
[*lpResEntry
] = '\0';
3146 FreeResource( hResource
);
3151 /* Registry keys for NLS related information */
3153 static const WCHAR szCountryListName
[] = {
3154 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
3155 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
3156 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3157 'T','e','l','e','p','h','o','n','y','\\',
3158 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
3162 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
3165 LANGUAGEGROUP_ENUMPROCA procA
;
3166 LANGUAGEGROUP_ENUMPROCW procW
;
3169 } ENUMLANGUAGEGROUP_CALLBACKS
;
3171 /* Internal implementation of EnumSystemLanguageGroupsA/W */
3172 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
3174 WCHAR szNumber
[10], szValue
[4];
3176 BOOL bContinue
= TRUE
;
3181 SetLastError(ERROR_INVALID_PARAMETER
);
3185 switch (lpProcs
->dwFlags
)
3188 /* Default to LGRPID_INSTALLED */
3189 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
3190 /* Fall through... */
3191 case LGRPID_INSTALLED
:
3192 case LGRPID_SUPPORTED
:
3195 SetLastError(ERROR_INVALID_FLAGS
);
3199 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3202 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3206 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3207 szValue
, sizeof(szValue
) ))
3209 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
3210 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
3212 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
3213 bInstalled
? "" : "not ");
3215 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
3217 WCHAR szGrpName
[48];
3219 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
3220 szGrpName
[0] = '\0';
3223 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
3227 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3228 char szGrpNameA
[48];
3230 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
3231 * or whether the language names are ever localised. Assume CP_ACP.
3234 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3235 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
3237 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
3257 /******************************************************************************
3258 * EnumSystemLanguageGroupsA (KERNEL32.@)
3260 * Call a users function for each language group available on the system.
3263 * pLangGrpEnumProc [I] Callback function to call for each language group
3264 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
3265 * lParam [I] User parameter to pass to pLangGrpEnumProc
3269 * Failure: FALSE. Use GetLastError() to determine the cause.
3271 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
3272 DWORD dwFlags
, LONG_PTR lParam
)
3274 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3276 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3278 procs
.procA
= pLangGrpEnumProc
;
3280 procs
.dwFlags
= dwFlags
;
3281 procs
.lParam
= lParam
;
3283 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3286 /******************************************************************************
3287 * EnumSystemLanguageGroupsW (KERNEL32.@)
3289 * See EnumSystemLanguageGroupsA.
3291 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
3292 DWORD dwFlags
, LONG_PTR lParam
)
3294 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3296 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3299 procs
.procW
= pLangGrpEnumProc
;
3300 procs
.dwFlags
= dwFlags
;
3301 procs
.lParam
= lParam
;
3303 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3306 /******************************************************************************
3307 * IsValidLanguageGroup (KERNEL32.@)
3309 * Determine if a language group is supported and/or installed.
3312 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
3313 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
3316 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
3319 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
3321 static const WCHAR szFormat
[] = { '%','x','\0' };
3322 WCHAR szValueName
[16], szValue
[2];
3323 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
3329 case LGRPID_INSTALLED
:
3330 case LGRPID_SUPPORTED
:
3332 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3334 sprintfW( szValueName
, szFormat
, lgrpid
);
3336 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)szValue
))
3340 if (szValue
[0] == '1')
3350 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
3351 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
3357 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
3360 LANGGROUPLOCALE_ENUMPROCA procA
;
3361 LANGGROUPLOCALE_ENUMPROCW procW
;
3365 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
3367 /* Internal implementation of EnumLanguageGrouplocalesA/W */
3368 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
3370 static const WCHAR szAlternateSortsKeyName
[] = {
3371 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
3373 WCHAR szNumber
[10], szValue
[4];
3375 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
3377 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
3379 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
3381 SetLastError(ERROR_INVALID_PARAMETER
);
3385 if (lpProcs
->dwFlags
)
3387 SetLastError(ERROR_INVALID_FLAGS
);
3391 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
3394 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3398 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3399 szValue
, sizeof(szValue
) ))
3401 lgrpid
= strtoulW( szValue
, NULL
, 16 );
3403 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
3404 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
3406 if (lgrpid
== lpProcs
->lgrpid
)
3410 lcid
= strtoulW( szNumber
, NULL
, 16 );
3412 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
3413 * '00000437 ;Georgian'
3414 * At present we only pass the LCID string.
3418 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
3421 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3423 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3425 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
3433 /* Finished enumerating this key */
3436 /* Enumerate alternate sorts also */
3437 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
3442 bContinue
= FALSE
; /* Finished both keys */
3455 /******************************************************************************
3456 * EnumLanguageGroupLocalesA (KERNEL32.@)
3458 * Call a users function for every locale in a language group available on the system.
3461 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3462 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3463 * dwFlags [I] Reserved, set to 0
3464 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3468 * Failure: FALSE. Use GetLastError() to determine the cause.
3470 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
3471 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3473 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3475 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3477 callbacks
.procA
= pLangGrpLcEnumProc
;
3478 callbacks
.procW
= NULL
;
3479 callbacks
.dwFlags
= dwFlags
;
3480 callbacks
.lgrpid
= lgrpid
;
3481 callbacks
.lParam
= lParam
;
3483 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3486 /******************************************************************************
3487 * EnumLanguageGroupLocalesW (KERNEL32.@)
3489 * See EnumLanguageGroupLocalesA.
3491 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
3492 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3494 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3496 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3498 callbacks
.procA
= NULL
;
3499 callbacks
.procW
= pLangGrpLcEnumProc
;
3500 callbacks
.dwFlags
= dwFlags
;
3501 callbacks
.lgrpid
= lgrpid
;
3502 callbacks
.lParam
= lParam
;
3504 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3507 /******************************************************************************
3508 * EnumSystemGeoID (KERNEL32.@)
3510 * Call a users function for every location available on the system.
3513 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3514 * reserved [I] Reserved, set to 0
3515 * pGeoEnumProc [I] Callback function to call for each location
3519 * Failure: FALSE. Use GetLastError() to determine the cause.
3521 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID reserved
, GEO_ENUMPROC pGeoEnumProc
)
3523 static const WCHAR szCountryCodeValueName
[] = {
3524 'C','o','u','n','t','r','y','C','o','d','e','\0'
3530 TRACE("(0x%08X,0x%08X,%p)\n", geoclass
, reserved
, pGeoEnumProc
);
3532 if (geoclass
!= GEOCLASS_NATION
|| reserved
|| !pGeoEnumProc
)
3534 SetLastError(ERROR_INVALID_PARAMETER
);
3538 hKey
= NLS_RegOpenKey( 0, szCountryListName
);
3540 while (NLS_RegEnumSubKey( hKey
, ulIndex
, szNumber
, sizeof(szNumber
) ))
3542 BOOL bContinue
= TRUE
;
3544 HANDLE hSubKey
= NLS_RegOpenKey( hKey
, szNumber
);
3548 if (NLS_RegGetDword( hSubKey
, szCountryCodeValueName
, &dwGeoId
))
3550 TRACE("Got geoid %d\n", dwGeoId
);
3552 if (!pGeoEnumProc( dwGeoId
))
3571 /******************************************************************************
3572 * InvalidateNLSCache (KERNEL32.@)
3574 * Invalidate the cache of NLS values.
3583 BOOL WINAPI
InvalidateNLSCache(void)
3589 /******************************************************************************
3590 * GetUserGeoID (KERNEL32.@)
3592 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
3594 GEOID ret
= GEOID_NOT_AVAILABLE
;
3595 static const WCHAR geoW
[] = {'G','e','o',0};
3596 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3597 WCHAR bufferW
[40], *end
;
3599 HANDLE hkey
, hSubkey
= 0;
3600 UNICODE_STRING keyW
;
3601 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
3602 RtlInitUnicodeString( &keyW
, nationW
);
3603 count
= sizeof(bufferW
);
3605 if(!(hkey
= create_registry_key())) return ret
;
3608 case GEOCLASS_NATION
:
3609 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
3611 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
3612 bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
3613 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
3616 case GEOCLASS_REGION
:
3617 FIXME("GEOCLASS_REGION not handled yet\n");
3622 if (hSubkey
) NtClose(hSubkey
);
3626 /******************************************************************************
3627 * SetUserGeoID (KERNEL32.@)
3629 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
3631 static const WCHAR geoW
[] = {'G','e','o',0};
3632 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3633 static const WCHAR formatW
[] = {'%','i',0};
3634 UNICODE_STRING nameW
,keyW
;
3636 OBJECT_ATTRIBUTES attr
;
3639 if(!(hkey
= create_registry_key())) return FALSE
;
3641 attr
.Length
= sizeof(attr
);
3642 attr
.RootDirectory
= hkey
;
3643 attr
.ObjectName
= &nameW
;
3644 attr
.Attributes
= 0;
3645 attr
.SecurityDescriptor
= NULL
;
3646 attr
.SecurityQualityOfService
= NULL
;
3647 RtlInitUnicodeString( &nameW
, geoW
);
3648 RtlInitUnicodeString( &keyW
, nationW
);
3650 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
3653 NtClose(attr
.RootDirectory
);
3657 sprintfW(bufferW
, formatW
, GeoID
);
3658 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
3659 NtClose(attr
.RootDirectory
);
3668 UILANGUAGE_ENUMPROCA procA
;
3669 UILANGUAGE_ENUMPROCW procW
;
3673 } ENUM_UILANG_CALLBACK
;
3675 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
3676 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
3678 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3681 sprintf(buf
, "%08x", (UINT
)LangID
);
3682 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
3685 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
3686 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
3688 static const WCHAR formatW
[] = {'%','0','8','x',0};
3689 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3692 sprintfW( buf
, formatW
, (UINT
)LangID
);
3693 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
3696 /******************************************************************************
3697 * EnumUILanguagesA (KERNEL32.@)
3699 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3701 ENUM_UILANG_CALLBACK enum_uilang
;
3703 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3705 if(!pUILangEnumProc
) {
3706 SetLastError(ERROR_INVALID_PARAMETER
);
3710 SetLastError(ERROR_INVALID_FLAGS
);
3714 enum_uilang
.u
.procA
= pUILangEnumProc
;
3715 enum_uilang
.flags
= dwFlags
;
3716 enum_uilang
.param
= lParam
;
3718 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
3719 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
3720 (LONG_PTR
)&enum_uilang
);
3724 /******************************************************************************
3725 * EnumUILanguagesW (KERNEL32.@)
3727 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3729 ENUM_UILANG_CALLBACK enum_uilang
;
3731 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3734 if(!pUILangEnumProc
) {
3735 SetLastError(ERROR_INVALID_PARAMETER
);
3739 SetLastError(ERROR_INVALID_FLAGS
);
3743 enum_uilang
.u
.procW
= pUILangEnumProc
;
3744 enum_uilang
.flags
= dwFlags
;
3745 enum_uilang
.param
= lParam
;
3747 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
3748 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
3749 (LONG_PTR
)&enum_uilang
);
3753 INT WINAPI
GetGeoInfoW(GEOID GeoId
, GEOTYPE GeoType
, LPWSTR lpGeoData
,
3754 int cchData
, LANGID language
)
3756 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);
3760 INT WINAPI
GetGeoInfoA(GEOID GeoId
, GEOTYPE GeoType
, LPSTR lpGeoData
,
3761 int cchData
, LANGID language
)
3763 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);