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 (!(codepage
= kernel_get_thread_data()->code_page
)) return ansi_cptable
;
228 if (codepage
== ansi_cptable
->info
.codepage
) return ansi_cptable
;
229 if (codepage
== oem_cptable
->info
.codepage
) return oem_cptable
;
230 if (codepage
== mac_cptable
->info
.codepage
) return mac_cptable
;
231 ret
= wine_cp_get_table( codepage
);
238 /***********************************************************************
239 * charset_cmp (internal)
241 static int charset_cmp( const void *name
, const void *entry
)
243 const struct charset_entry
*charset
= entry
;
244 return strcasecmp( name
, charset
->charset_name
);
247 /***********************************************************************
250 static UINT
find_charset( const WCHAR
*name
)
252 const struct charset_entry
*entry
;
253 char charset_name
[16];
256 /* remove punctuation characters from charset name */
257 for (i
= j
= 0; name
[i
] && j
< sizeof(charset_name
)-1; i
++)
258 if (isalnum((unsigned char)name
[i
])) charset_name
[j
++] = name
[i
];
261 entry
= bsearch( charset_name
, charset_names
,
262 sizeof(charset_names
)/sizeof(charset_names
[0]),
263 sizeof(charset_names
[0]), charset_cmp
);
264 if (entry
) return entry
->codepage
;
269 /***********************************************************************
270 * find_locale_id_callback
272 static BOOL CALLBACK
find_locale_id_callback( HMODULE hModule
, LPCWSTR type
,
273 LPCWSTR name
, WORD LangID
, LPARAM lParam
)
275 struct locale_name
*data
= (struct locale_name
*)lParam
;
278 LCID lcid
= MAKELCID( LangID
, SORT_DEFAULT
); /* FIXME: handle sort order */
280 if (PRIMARYLANGID(LangID
) == LANG_NEUTRAL
) return TRUE
; /* continue search */
282 /* first check exact name */
283 if (data
->win_name
[0] &&
284 GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
,
285 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
287 if (!strcmpW( data
->win_name
, buffer
))
289 matches
= 4; /* everything matches */
294 if (!GetLocaleInfoW( lcid
, LOCALE_SISO639LANGNAME
| LOCALE_NOUSEROVERRIDE
,
295 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
297 if (strcmpW( buffer
, data
->lang
)) return TRUE
;
298 matches
++; /* language name matched */
302 if (GetLocaleInfoW( lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
303 buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
305 if (strcmpW( buffer
, data
->country
)) goto done
;
306 matches
++; /* country name matched */
309 else /* match default language */
311 if (SUBLANGID(LangID
) == SUBLANG_DEFAULT
) matches
++;
317 if (GetLocaleInfoW( lcid
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
318 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) ))
320 if (unix_cp
== data
->codepage
) matches
++;
324 /* FIXME: check sort order */
327 if (matches
> data
->matches
)
330 data
->matches
= matches
;
332 return (data
->matches
< 4); /* no need to continue for perfect match */
336 /***********************************************************************
339 * Parse a locale name into a struct locale_name, handling both Windows and Unix formats.
340 * Unix format is: lang[_country][.charset][@modifier]
341 * Windows format is: lang[-script][-country][_modifier]
343 static void parse_locale_name( const WCHAR
*str
, struct locale_name
*name
)
345 static const WCHAR sepW
[] = {'-','_','.','@',0};
346 static const WCHAR winsepW
[] = {'-','_',0};
347 static const WCHAR posixW
[] = {'P','O','S','I','X',0};
348 static const WCHAR cW
[] = {'C',0};
349 static const WCHAR latinW
[] = {'l','a','t','i','n',0};
350 static const WCHAR latnW
[] = {'-','L','a','t','n',0};
353 TRACE("%s\n", debugstr_w(str
));
355 name
->country
= name
->charset
= name
->script
= name
->modifier
= NULL
;
356 name
->lcid
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
359 name
->win_name
[0] = 0;
360 lstrcpynW( name
->lang
, str
, sizeof(name
->lang
)/sizeof(WCHAR
) );
362 if (!(p
= strpbrkW( name
->lang
, sepW
)))
364 if (!strcmpW( name
->lang
, posixW
) || !strcmpW( name
->lang
, cW
))
366 name
->matches
= 4; /* perfect match for default English lcid */
369 strcpyW( name
->win_name
, name
->lang
);
371 else if (*p
== '-') /* Windows format */
373 strcpyW( name
->win_name
, name
->lang
);
376 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
380 name
->script
= name
->country
;
382 if (!(p
= strpbrkW( p
, winsepW
))) goto done
;
387 else /* Unix format */
393 p
= strpbrkW( p
, sepW
+ 2 );
399 p
= strchrW( p
, '@' );
408 name
->codepage
= find_charset( name
->charset
);
410 /* rebuild a Windows name if possible */
412 if (name
->charset
) goto done
; /* can't specify charset in Windows format */
413 if (name
->modifier
&& strcmpW( name
->modifier
, latinW
))
414 goto done
; /* only Latn script supported for now */
415 strcpyW( name
->win_name
, name
->lang
);
416 if (name
->modifier
) strcatW( name
->win_name
, latnW
);
419 p
= name
->win_name
+ strlenW(name
->win_name
);
421 strcpyW( p
, name
->country
);
425 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
, (LPCWSTR
)LOCALE_ILANGUAGE
,
426 find_locale_id_callback
, (LPARAM
)name
);
430 /***********************************************************************
431 * convert_default_lcid
433 * Get the default LCID to use for a given lctype in GetLocaleInfo.
435 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
437 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
438 lcid
== LOCALE_USER_DEFAULT
||
439 lcid
== LOCALE_NEUTRAL
)
443 switch(lctype
& 0xffff)
445 case LOCALE_SSORTNAME
:
446 default_id
= lcid_LC_COLLATE
;
449 case LOCALE_FONTSIGNATURE
:
450 case LOCALE_IDEFAULTANSICODEPAGE
:
451 case LOCALE_IDEFAULTCODEPAGE
:
452 case LOCALE_IDEFAULTEBCDICCODEPAGE
:
453 case LOCALE_IDEFAULTMACCODEPAGE
:
454 case LOCALE_IDEFAULTUNIXCODEPAGE
:
455 default_id
= lcid_LC_CTYPE
;
458 case LOCALE_ICURRDIGITS
:
459 case LOCALE_ICURRENCY
:
460 case LOCALE_IINTLCURRDIGITS
:
461 case LOCALE_INEGCURR
:
462 case LOCALE_INEGSEPBYSPACE
:
463 case LOCALE_INEGSIGNPOSN
:
464 case LOCALE_INEGSYMPRECEDES
:
465 case LOCALE_IPOSSEPBYSPACE
:
466 case LOCALE_IPOSSIGNPOSN
:
467 case LOCALE_IPOSSYMPRECEDES
:
468 case LOCALE_SCURRENCY
:
469 case LOCALE_SINTLSYMBOL
:
470 case LOCALE_SMONDECIMALSEP
:
471 case LOCALE_SMONGROUPING
:
472 case LOCALE_SMONTHOUSANDSEP
:
473 case LOCALE_SNATIVECURRNAME
:
474 default_id
= lcid_LC_MONETARY
;
478 case LOCALE_IDIGITSUBSTITUTION
:
480 case LOCALE_INEGNUMBER
:
481 case LOCALE_SDECIMAL
:
482 case LOCALE_SGROUPING
:
484 case LOCALE_SNATIVEDIGITS
:
485 case LOCALE_SNEGATIVESIGN
:
486 case LOCALE_SNEGINFINITY
:
487 case LOCALE_SPOSINFINITY
:
488 case LOCALE_SPOSITIVESIGN
:
489 case LOCALE_STHOUSAND
:
490 default_id
= lcid_LC_NUMERIC
;
493 case LOCALE_ICALENDARTYPE
:
494 case LOCALE_ICENTURY
:
496 case LOCALE_IDAYLZERO
:
497 case LOCALE_IFIRSTDAYOFWEEK
:
498 case LOCALE_IFIRSTWEEKOFYEAR
:
500 case LOCALE_IMONLZERO
:
501 case LOCALE_IOPTIONALCALENDAR
:
503 case LOCALE_ITIMEMARKPOSN
:
507 case LOCALE_SABBREVDAYNAME1
:
508 case LOCALE_SABBREVDAYNAME2
:
509 case LOCALE_SABBREVDAYNAME3
:
510 case LOCALE_SABBREVDAYNAME4
:
511 case LOCALE_SABBREVDAYNAME5
:
512 case LOCALE_SABBREVDAYNAME6
:
513 case LOCALE_SABBREVDAYNAME7
:
514 case LOCALE_SABBREVMONTHNAME1
:
515 case LOCALE_SABBREVMONTHNAME2
:
516 case LOCALE_SABBREVMONTHNAME3
:
517 case LOCALE_SABBREVMONTHNAME4
:
518 case LOCALE_SABBREVMONTHNAME5
:
519 case LOCALE_SABBREVMONTHNAME6
:
520 case LOCALE_SABBREVMONTHNAME7
:
521 case LOCALE_SABBREVMONTHNAME8
:
522 case LOCALE_SABBREVMONTHNAME9
:
523 case LOCALE_SABBREVMONTHNAME10
:
524 case LOCALE_SABBREVMONTHNAME11
:
525 case LOCALE_SABBREVMONTHNAME12
:
526 case LOCALE_SABBREVMONTHNAME13
:
528 case LOCALE_SDAYNAME1
:
529 case LOCALE_SDAYNAME2
:
530 case LOCALE_SDAYNAME3
:
531 case LOCALE_SDAYNAME4
:
532 case LOCALE_SDAYNAME5
:
533 case LOCALE_SDAYNAME6
:
534 case LOCALE_SDAYNAME7
:
535 case LOCALE_SDURATION
:
536 case LOCALE_SLONGDATE
:
537 case LOCALE_SMONTHNAME1
:
538 case LOCALE_SMONTHNAME2
:
539 case LOCALE_SMONTHNAME3
:
540 case LOCALE_SMONTHNAME4
:
541 case LOCALE_SMONTHNAME5
:
542 case LOCALE_SMONTHNAME6
:
543 case LOCALE_SMONTHNAME7
:
544 case LOCALE_SMONTHNAME8
:
545 case LOCALE_SMONTHNAME9
:
546 case LOCALE_SMONTHNAME10
:
547 case LOCALE_SMONTHNAME11
:
548 case LOCALE_SMONTHNAME12
:
549 case LOCALE_SMONTHNAME13
:
550 case LOCALE_SSHORTDATE
:
551 case LOCALE_SSHORTESTDAYNAME1
:
552 case LOCALE_SSHORTESTDAYNAME2
:
553 case LOCALE_SSHORTESTDAYNAME3
:
554 case LOCALE_SSHORTESTDAYNAME4
:
555 case LOCALE_SSHORTESTDAYNAME5
:
556 case LOCALE_SSHORTESTDAYNAME6
:
557 case LOCALE_SSHORTESTDAYNAME7
:
559 case LOCALE_STIMEFORMAT
:
560 case LOCALE_SYEARMONTH
:
561 default_id
= lcid_LC_TIME
;
564 case LOCALE_IPAPERSIZE
:
565 default_id
= lcid_LC_PAPER
;
568 case LOCALE_IMEASURE
:
569 default_id
= lcid_LC_MEASUREMENT
;
572 case LOCALE_ICOUNTRY
:
573 default_id
= lcid_LC_TELEPHONE
;
576 if (default_id
) lcid
= default_id
;
578 return ConvertDefaultLocale( lcid
);
581 /***********************************************************************
582 * is_genitive_name_supported
584 * Determine could LCTYPE basically support genitive name form or not.
586 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
588 switch(lctype
& 0xffff)
590 case LOCALE_SMONTHNAME1
:
591 case LOCALE_SMONTHNAME2
:
592 case LOCALE_SMONTHNAME3
:
593 case LOCALE_SMONTHNAME4
:
594 case LOCALE_SMONTHNAME5
:
595 case LOCALE_SMONTHNAME6
:
596 case LOCALE_SMONTHNAME7
:
597 case LOCALE_SMONTHNAME8
:
598 case LOCALE_SMONTHNAME9
:
599 case LOCALE_SMONTHNAME10
:
600 case LOCALE_SMONTHNAME11
:
601 case LOCALE_SMONTHNAME12
:
602 case LOCALE_SMONTHNAME13
:
609 /***********************************************************************
610 * create_registry_key
612 * Create the Control Panel\\International registry key.
614 static inline HANDLE
create_registry_key(void)
616 static const WCHAR intlW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
617 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
618 OBJECT_ATTRIBUTES attr
;
619 UNICODE_STRING nameW
;
622 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
624 attr
.Length
= sizeof(attr
);
625 attr
.RootDirectory
= hkey
;
626 attr
.ObjectName
= &nameW
;
628 attr
.SecurityDescriptor
= NULL
;
629 attr
.SecurityQualityOfService
= NULL
;
630 RtlInitUnicodeString( &nameW
, intlW
);
632 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) hkey
= 0;
633 NtClose( attr
.RootDirectory
);
638 /* update the registry settings for a given locale parameter */
639 /* return TRUE if an update was needed */
640 static BOOL
locale_update_registry( HKEY hkey
, const WCHAR
*name
, LCID lcid
,
641 const LCTYPE
*values
, UINT nb_values
)
643 static const WCHAR formatW
[] = { '%','0','8','x',0 };
645 UNICODE_STRING nameW
;
648 RtlInitUnicodeString( &nameW
, name
);
649 count
= sizeof(bufferW
);
650 if (!NtQueryValueKey(hkey
, &nameW
, KeyValuePartialInformation
, bufferW
, count
, &count
))
652 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
653 LPCWSTR text
= (LPCWSTR
)info
->Data
;
655 if (strtoulW( text
, NULL
, 16 ) == lcid
) return FALSE
; /* already set correctly */
656 TRACE( "updating registry, locale %s changed %s -> %08x\n",
657 debugstr_w(name
), debugstr_w(text
), lcid
);
659 else TRACE( "updating registry, locale %s changed none -> %08x\n", debugstr_w(name
), lcid
);
660 sprintfW( bufferW
, formatW
, lcid
);
661 NtSetValueKey( hkey
, &nameW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
) );
663 for (i
= 0; i
< nb_values
; i
++)
665 GetLocaleInfoW( lcid
, values
[i
] | LOCALE_NOUSEROVERRIDE
, bufferW
,
666 sizeof(bufferW
)/sizeof(WCHAR
) );
667 SetLocaleInfoW( lcid
, values
[i
], bufferW
);
673 /***********************************************************************
674 * LOCALE_InitRegistry
676 * Update registry contents on startup if the user locale has changed.
677 * This simulates the action of the Windows control panel.
679 void LOCALE_InitRegistry(void)
681 static const WCHAR acpW
[] = {'A','C','P',0};
682 static const WCHAR oemcpW
[] = {'O','E','M','C','P',0};
683 static const WCHAR maccpW
[] = {'M','A','C','C','P',0};
684 static const WCHAR localeW
[] = {'L','o','c','a','l','e',0};
685 static const WCHAR lc_ctypeW
[] = { 'L','C','_','C','T','Y','P','E',0 };
686 static const WCHAR lc_monetaryW
[] = { 'L','C','_','M','O','N','E','T','A','R','Y',0 };
687 static const WCHAR lc_numericW
[] = { 'L','C','_','N','U','M','E','R','I','C',0 };
688 static const WCHAR lc_timeW
[] = { 'L','C','_','T','I','M','E',0 };
689 static const WCHAR lc_measurementW
[] = { 'L','C','_','M','E','A','S','U','R','E','M','E','N','T',0 };
690 static const WCHAR lc_telephoneW
[] = { 'L','C','_','T','E','L','E','P','H','O','N','E',0 };
691 static const WCHAR lc_paperW
[] = { 'L','C','_','P','A','P','E','R',0};
696 } update_cp_values
[] = {
697 { acpW
, LOCALE_IDEFAULTANSICODEPAGE
},
698 { oemcpW
, LOCALE_IDEFAULTCODEPAGE
},
699 { maccpW
, LOCALE_IDEFAULTMACCODEPAGE
}
701 static const LCTYPE lc_messages_values
[] = {
702 LOCALE_SABBREVLANGNAME
,
705 static const LCTYPE lc_monetary_values
[] = {
711 LOCALE_SMONDECIMALSEP
,
713 LOCALE_SMONTHOUSANDSEP
};
714 static const LCTYPE lc_numeric_values
[] = {
718 LOCALE_IDIGITSUBSTITUTION
,
719 LOCALE_SNATIVEDIGITS
,
721 LOCALE_SNEGATIVESIGN
,
722 LOCALE_SPOSITIVESIGN
,
724 static const LCTYPE lc_time_values
[] = {
733 LOCALE_ITIMEMARKPOSN
,
734 LOCALE_ICALENDARTYPE
,
735 LOCALE_IFIRSTDAYOFWEEK
,
736 LOCALE_IFIRSTWEEKOFYEAR
,
740 static const LCTYPE lc_measurement_values
[] = { LOCALE_IMEASURE
};
741 static const LCTYPE lc_telephone_values
[] = { LOCALE_ICOUNTRY
};
742 static const LCTYPE lc_paper_values
[] = { LOCALE_IPAPERSIZE
};
744 UNICODE_STRING nameW
;
748 LCID lcid
= GetUserDefaultLCID();
750 if (!(hkey
= create_registry_key()))
751 return; /* don't do anything if we can't create the registry key */
753 locale_update_registry( hkey
, localeW
, lcid_LC_MESSAGES
, lc_messages_values
,
754 sizeof(lc_messages_values
)/sizeof(lc_messages_values
[0]) );
755 locale_update_registry( hkey
, lc_monetaryW
, lcid_LC_MONETARY
, lc_monetary_values
,
756 sizeof(lc_monetary_values
)/sizeof(lc_monetary_values
[0]) );
757 locale_update_registry( hkey
, lc_numericW
, lcid_LC_NUMERIC
, lc_numeric_values
,
758 sizeof(lc_numeric_values
)/sizeof(lc_numeric_values
[0]) );
759 locale_update_registry( hkey
, lc_timeW
, lcid_LC_TIME
, lc_time_values
,
760 sizeof(lc_time_values
)/sizeof(lc_time_values
[0]) );
761 locale_update_registry( hkey
, lc_measurementW
, lcid_LC_MEASUREMENT
, lc_measurement_values
,
762 sizeof(lc_measurement_values
)/sizeof(lc_measurement_values
[0]) );
763 locale_update_registry( hkey
, lc_telephoneW
, lcid_LC_TELEPHONE
, lc_telephone_values
,
764 sizeof(lc_telephone_values
)/sizeof(lc_telephone_values
[0]) );
765 locale_update_registry( hkey
, lc_paperW
, lcid_LC_PAPER
, lc_paper_values
,
766 sizeof(lc_paper_values
)/sizeof(lc_paper_values
[0]) );
768 if (locale_update_registry( hkey
, lc_ctypeW
, lcid_LC_CTYPE
, NULL
, 0 ))
770 OBJECT_ATTRIBUTES attr
;
773 RtlInitUnicodeString( &nameW
, szCodepageKeyName
);
774 InitializeObjectAttributes( &attr
, &nameW
, 0, 0, NULL
);
775 if (!NtCreateKey( &nls_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
777 for (i
= 0; i
< sizeof(update_cp_values
)/sizeof(update_cp_values
[0]); i
++)
779 count
= GetLocaleInfoW( lcid
, update_cp_values
[i
].value
| LOCALE_NOUSEROVERRIDE
,
780 bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
781 RtlInitUnicodeString( &nameW
, update_cp_values
[i
].name
);
782 NtSetValueKey( nls_key
, &nameW
, 0, REG_SZ
, bufferW
, count
* sizeof(WCHAR
) );
792 /***********************************************************************
795 static UINT
setup_unix_locales(void)
797 struct locale_name locale_name
;
798 WCHAR buffer
[128], ctype_buff
[128];
802 if ((locale
= setlocale( LC_CTYPE
, NULL
)))
804 strcpynAtoW( ctype_buff
, locale
, sizeof(ctype_buff
)/sizeof(WCHAR
) );
805 parse_locale_name( ctype_buff
, &locale_name
);
806 lcid_LC_CTYPE
= locale_name
.lcid
;
807 unix_cp
= locale_name
.codepage
;
809 if (!lcid_LC_CTYPE
) /* this one needs a default value */
810 lcid_LC_CTYPE
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
);
812 TRACE( "got lcid %04x (%d matches) for LC_CTYPE=%s\n",
813 locale_name
.lcid
, locale_name
.matches
, debugstr_a(locale
) );
815 #define GET_UNIX_LOCALE(cat) do \
816 if ((locale = setlocale( cat, NULL ))) \
818 strcpynAtoW( buffer, locale, sizeof(buffer)/sizeof(WCHAR) ); \
819 if (!strcmpW( buffer, ctype_buff )) lcid_##cat = lcid_LC_CTYPE; \
821 parse_locale_name( buffer, &locale_name ); \
822 lcid_##cat = locale_name.lcid; \
823 TRACE( "got lcid %04x (%d matches) for " #cat "=%s\n", \
824 locale_name.lcid, locale_name.matches, debugstr_a(locale) ); \
828 GET_UNIX_LOCALE( LC_COLLATE
);
829 GET_UNIX_LOCALE( LC_MESSAGES
);
830 GET_UNIX_LOCALE( LC_MONETARY
);
831 GET_UNIX_LOCALE( LC_NUMERIC
);
832 GET_UNIX_LOCALE( LC_TIME
);
834 GET_UNIX_LOCALE( LC_PAPER
);
836 #ifdef LC_MEASUREMENT
837 GET_UNIX_LOCALE( LC_MEASUREMENT
);
840 GET_UNIX_LOCALE( LC_TELEPHONE
);
843 #undef GET_UNIX_LOCALE
849 /***********************************************************************
850 * GetUserDefaultLangID (KERNEL32.@)
852 * Get the default language Id for the current user.
858 * The current LANGID of the default language for the current user.
860 LANGID WINAPI
GetUserDefaultLangID(void)
862 return LANGIDFROMLCID(GetUserDefaultLCID());
866 /***********************************************************************
867 * GetSystemDefaultLangID (KERNEL32.@)
869 * Get the default language Id for the system.
875 * The current LANGID of the default language for the system.
877 LANGID WINAPI
GetSystemDefaultLangID(void)
879 return LANGIDFROMLCID(GetSystemDefaultLCID());
883 /***********************************************************************
884 * GetUserDefaultLCID (KERNEL32.@)
886 * Get the default locale Id for the current user.
892 * The current LCID of the default locale for the current user.
894 LCID WINAPI
GetUserDefaultLCID(void)
897 NtQueryDefaultLocale( TRUE
, &lcid
);
902 /***********************************************************************
903 * GetSystemDefaultLCID (KERNEL32.@)
905 * Get the default locale Id for the system.
911 * The current LCID of the default locale for the system.
913 LCID WINAPI
GetSystemDefaultLCID(void)
916 NtQueryDefaultLocale( FALSE
, &lcid
);
921 /***********************************************************************
922 * GetUserDefaultUILanguage (KERNEL32.@)
924 * Get the default user interface language Id for the current user.
930 * The current LANGID of the default UI language for the current user.
932 LANGID WINAPI
GetUserDefaultUILanguage(void)
935 NtQueryDefaultUILanguage( &lang
);
940 /***********************************************************************
941 * GetSystemDefaultUILanguage (KERNEL32.@)
943 * Get the default user interface language Id for the system.
949 * The current LANGID of the default UI language for the system. This is
950 * typically the same language used during the installation process.
952 LANGID WINAPI
GetSystemDefaultUILanguage(void)
955 NtQueryInstallUILanguage( &lang
);
960 /***********************************************************************
961 * LocaleNameToLCID (KERNEL32.@)
963 LCID WINAPI
LocaleNameToLCID( LPCWSTR name
, DWORD flags
)
965 struct locale_name locale_name
;
967 if (flags
) FIXME( "unsupported flags %x\n", flags
);
969 parse_locale_name( name
, &locale_name
);
971 TRACE( "found lcid %x for %s, matches %d\n",
972 locale_name
.lcid
, debugstr_w(name
), locale_name
.matches
);
974 if (!locale_name
.matches
)
975 WARN( "locale %s not recognized, defaulting to English\n", debugstr_w(name
) );
976 else if (locale_name
.matches
== 1)
977 WARN( "locale %s not recognized, defaulting to %s\n",
978 debugstr_w(name
), debugstr_w(locale_name
.lang
) );
980 return locale_name
.lcid
;
984 /***********************************************************************
985 * LCIDToLocaleName (KERNEL32.@)
987 INT WINAPI
LCIDToLocaleName( LCID lcid
, LPWSTR name
, INT count
, DWORD flags
)
989 if (flags
) FIXME( "unsupported flags %x\n", flags
);
991 return GetLocaleInfoW( lcid
, LOCALE_SNAME
| LOCALE_NOUSEROVERRIDE
, name
, count
);
995 /******************************************************************************
996 * get_locale_value_name
998 * Gets the registry value name for a given lctype.
1000 static const WCHAR
*get_locale_value_name( DWORD lctype
)
1002 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
1003 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
1004 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
1005 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
1006 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
1007 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
1008 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
1009 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
1010 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
1011 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
1012 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
1013 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
1014 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
1015 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
1016 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
1017 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
1018 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
1019 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
1020 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
1021 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
1022 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
1023 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
1024 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
1025 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
1026 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
1027 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
1028 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
1029 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
1030 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
1031 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
1032 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
1033 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
1034 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
1035 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
1036 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
1037 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
1038 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
1039 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
1040 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
1044 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
1045 * the values are stored in the registry, confirmed under Windows.
1047 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
1048 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
1049 case LOCALE_ICURRENCY
: return iCurrencyW
;
1050 case LOCALE_IDIGITS
: return iDigitsW
;
1051 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
1052 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
1053 case LOCALE_ILZERO
: return iLZeroW
;
1054 case LOCALE_IMEASURE
: return iMeasureW
;
1055 case LOCALE_INEGCURR
: return iNegCurrW
;
1056 case LOCALE_INEGNUMBER
: return iNegNumberW
;
1057 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
1058 case LOCALE_ITIME
: return iTimeW
;
1059 case LOCALE_S1159
: return s1159W
;
1060 case LOCALE_S2359
: return s2359W
;
1061 case LOCALE_SCURRENCY
: return sCurrencyW
;
1062 case LOCALE_SDATE
: return sDateW
;
1063 case LOCALE_SDECIMAL
: return sDecimalW
;
1064 case LOCALE_SGROUPING
: return sGroupingW
;
1065 case LOCALE_SLIST
: return sListW
;
1066 case LOCALE_SLONGDATE
: return sLongDateW
;
1067 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
1068 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
1069 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
1070 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
1071 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
1072 case LOCALE_SSHORTDATE
: return sShortDateW
;
1073 case LOCALE_STHOUSAND
: return sThousandW
;
1074 case LOCALE_STIME
: return sTimeW
;
1075 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
1076 case LOCALE_SYEARMONTH
: return sYearMonthW
;
1078 /* The following are not listed under MSDN as supported,
1079 * but seem to be used and also stored in the registry.
1081 case LOCALE_ICOUNTRY
: return iCountryW
;
1082 case LOCALE_IDATE
: return iDateW
;
1083 case LOCALE_ILDATE
: return iLDateW
;
1084 case LOCALE_ITLZERO
: return iTLZeroW
;
1085 case LOCALE_SCOUNTRY
: return sCountryW
;
1086 case LOCALE_SABBREVLANGNAME
: return sLanguageW
;
1088 /* The following are used in XP and later */
1089 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
1090 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
1091 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
1097 /******************************************************************************
1098 * get_registry_locale_info
1100 * Retrieve user-modified locale info from the registry.
1101 * Return length, 0 on error, -1 if not found.
1103 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
1109 UNICODE_STRING nameW
;
1110 KEY_VALUE_PARTIAL_INFORMATION
*info
;
1111 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
1113 if (!(hkey
= create_registry_key())) return -1;
1115 RtlInitUnicodeString( &nameW
, value
);
1116 size
= info_size
+ len
* sizeof(WCHAR
);
1118 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
1121 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1125 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
1129 ret
= (size
- info_size
) / sizeof(WCHAR
);
1130 /* append terminating null if needed */
1131 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
1133 if (ret
< len
|| !buffer
) ret
++;
1136 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1142 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
1146 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
1148 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
1150 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
1156 SetLastError( RtlNtStatusToDosError(status
) );
1160 HeapFree( GetProcessHeap(), 0, info
);
1165 /******************************************************************************
1166 * GetLocaleInfoA (KERNEL32.@)
1168 * Get information about an aspect of a locale.
1171 * lcid [I] LCID of the locale
1172 * lctype [I] LCTYPE_ flags from "winnls.h"
1173 * buffer [O] Destination for the information
1174 * len [I] Length of buffer in characters
1177 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1178 * with the information.
1179 * Failure: 0. Use GetLastError() to determine the cause.
1182 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1183 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1184 * which is a bit string.
1186 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
1191 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1193 if (len
< 0 || (len
&& !buffer
))
1195 SetLastError( ERROR_INVALID_PARAMETER
);
1198 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
)
1200 SetLastError( ERROR_INVALID_FLAGS
);
1204 if (!len
) buffer
= NULL
;
1206 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
1208 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
1210 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1213 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
1215 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
1216 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
1218 /* it's not an ASCII string, just bytes */
1219 ret
*= sizeof(WCHAR
);
1222 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
1225 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1232 UINT codepage
= CP_ACP
;
1233 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1234 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
1237 HeapFree( GetProcessHeap(), 0, bufferW
);
1242 /******************************************************************************
1243 * GetLocaleInfoW (KERNEL32.@)
1245 * See GetLocaleInfoA.
1247 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
1257 if (len
< 0 || (len
&& !buffer
))
1259 SetLastError( ERROR_INVALID_PARAMETER
);
1262 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&&
1263 !is_genitive_name_supported( lctype
))
1265 SetLastError( ERROR_INVALID_FLAGS
);
1269 if (!len
) buffer
= NULL
;
1271 lcid
= convert_default_lcid( lcid
, lctype
);
1273 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
1276 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
1278 /* first check for overrides in the registry */
1280 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
1281 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
1283 const WCHAR
*value
= get_locale_value_name(lctype
);
1287 if (lcflags
& LOCALE_RETURN_NUMBER
)
1290 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
1294 UINT number
= strtolW( tmp
, &end
, 10 );
1295 if (*end
) /* invalid number */
1297 SetLastError( ERROR_INVALID_FLAGS
);
1300 ret
= sizeof(UINT
)/sizeof(WCHAR
);
1301 if (!buffer
) return ret
;
1304 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1307 memcpy( buffer
, &number
, sizeof(number
) );
1310 else ret
= get_registry_locale_info( value
, buffer
, len
);
1312 if (ret
!= -1) return ret
;
1316 /* now load it from kernel resources */
1318 lang_id
= LANGIDFROMLCID( lcid
);
1320 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
1321 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
1322 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
1324 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1325 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
1327 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
1330 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
1333 p
= LockResource( hmem
);
1334 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
1336 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
1337 else if (is_genitive_name_supported( lctype
) && *p
)
1339 /* genitive form's stored after a null separator from a nominative */
1340 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
1342 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
1350 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
1352 if (!buffer
) return ret
;
1356 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1360 if (lcflags
& LOCALE_RETURN_NUMBER
)
1363 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
1365 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
1367 number
= strtolW( tmp
, &end
, 10 );
1369 memcpy( buffer
, &number
, sizeof(number
) );
1370 else /* invalid number */
1372 SetLastError( ERROR_INVALID_FLAGS
);
1375 HeapFree( GetProcessHeap(), 0, tmp
);
1377 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
1378 lcid
, lctype
, buffer
, len
, number
);
1382 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
1383 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
1385 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
1386 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
1392 /******************************************************************************
1393 * SetLocaleInfoA [KERNEL32.@]
1395 * Set information about an aspect of a locale.
1398 * lcid [I] LCID of the locale
1399 * lctype [I] LCTYPE_ flags from "winnls.h"
1400 * data [I] Information to set
1403 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1404 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1405 * Failure: FALSE. Use GetLastError() to determine the cause.
1408 * - Values are only be set for the current user locale; the system locale
1409 * settings cannot be changed.
1410 * - Any settings changed by this call are lost when the locale is changed by
1411 * the control panel (in Wine, this happens every time you change LANG).
1412 * - The native implementation of this function does not check that lcid matches
1413 * the current user locale, and simply sets the new values. Wine warns you in
1414 * this case, but behaves the same.
1416 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
1418 UINT codepage
= CP_ACP
;
1423 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1427 SetLastError( ERROR_INVALID_PARAMETER
);
1430 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
1431 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1433 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1436 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
1437 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
1438 HeapFree( GetProcessHeap(), 0, strW
);
1443 /******************************************************************************
1444 * SetLocaleInfoW (KERNEL32.@)
1446 * See SetLocaleInfoA.
1448 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
1451 static const WCHAR intlW
[] = {'i','n','t','l',0 };
1452 UNICODE_STRING valueW
;
1457 value
= get_locale_value_name( lctype
);
1459 if (!data
|| !value
)
1461 SetLastError( ERROR_INVALID_PARAMETER
);
1465 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
1467 SetLastError( ERROR_INVALID_FLAGS
);
1471 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
1473 /* FIXME: should check that data to set is sane */
1475 /* FIXME: profile functions should map to registry */
1476 WriteProfileStringW( intlW
, value
, data
);
1478 if (!(hkey
= create_registry_key())) return FALSE
;
1479 RtlInitUnicodeString( &valueW
, value
);
1480 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
1482 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
1484 /* Set I-value from S value */
1485 WCHAR
*lpD
, *lpM
, *lpY
;
1488 lpD
= strrchrW(data
, 'd');
1489 lpM
= strrchrW(data
, 'M');
1490 lpY
= strrchrW(data
, 'y');
1494 szBuff
[0] = '1'; /* D-M-Y */
1499 szBuff
[0] = '2'; /* Y-M-D */
1501 szBuff
[0] = '0'; /* M-D-Y */
1506 if (lctype
== LOCALE_SSHORTDATE
)
1507 lctype
= LOCALE_IDATE
;
1509 lctype
= LOCALE_ILDATE
;
1511 value
= get_locale_value_name( lctype
);
1513 WriteProfileStringW( intlW
, value
, szBuff
);
1515 RtlInitUnicodeString( &valueW
, value
);
1516 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1521 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1526 /******************************************************************************
1527 * GetACP (KERNEL32.@)
1529 * Get the current Ansi code page Id for the system.
1535 * The current Ansi code page identifier for the system.
1537 UINT WINAPI
GetACP(void)
1539 assert( ansi_cptable
);
1540 return ansi_cptable
->info
.codepage
;
1544 /******************************************************************************
1545 * SetCPGlobal (KERNEL32.@)
1547 * Set the current Ansi code page Id for the system.
1550 * acp [I] code page ID to be the new ACP.
1555 UINT WINAPI
SetCPGlobal( UINT acp
)
1557 UINT ret
= GetACP();
1558 const union cptable
*new_cptable
= wine_cp_get_table( acp
);
1560 if (new_cptable
) ansi_cptable
= new_cptable
;
1565 /***********************************************************************
1566 * GetOEMCP (KERNEL32.@)
1568 * Get the current OEM code page Id for the system.
1574 * The current OEM code page identifier for the system.
1576 UINT WINAPI
GetOEMCP(void)
1578 assert( oem_cptable
);
1579 return oem_cptable
->info
.codepage
;
1583 /***********************************************************************
1584 * IsValidCodePage (KERNEL32.@)
1586 * Determine if a given code page identifier is valid.
1589 * codepage [I] Code page Id to verify.
1592 * TRUE, If codepage is valid and available on the system,
1595 BOOL WINAPI
IsValidCodePage( UINT codepage
)
1602 return wine_cp_get_table( codepage
) != NULL
;
1607 /***********************************************************************
1608 * IsDBCSLeadByteEx (KERNEL32.@)
1610 * Determine if a character is a lead byte in a given code page.
1613 * codepage [I] Code page for the test.
1614 * testchar [I] Character to test
1617 * TRUE, if testchar is a lead byte in codepage,
1620 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
1622 const union cptable
*table
= get_codepage_table( codepage
);
1623 return table
&& wine_is_dbcs_leadbyte( table
, testchar
);
1627 /***********************************************************************
1628 * IsDBCSLeadByte (KERNEL32.@)
1629 * IsDBCSLeadByte (KERNEL.207)
1631 * Determine if a character is a lead byte.
1634 * testchar [I] Character to test
1637 * TRUE, if testchar is a lead byte in the Ansii code page,
1640 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
1642 if (!ansi_cptable
) return FALSE
;
1643 return wine_is_dbcs_leadbyte( ansi_cptable
, testchar
);
1647 /***********************************************************************
1648 * GetCPInfo (KERNEL32.@)
1650 * Get information about a code page.
1653 * codepage [I] Code page number
1654 * cpinfo [O] Destination for code page information
1657 * Success: TRUE. cpinfo is updated with the information about codepage.
1658 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1660 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
1662 const union cptable
*table
;
1666 SetLastError( ERROR_INVALID_PARAMETER
);
1670 if (!(table
= get_codepage_table( codepage
)))
1676 cpinfo
->DefaultChar
[0] = 0x3f;
1677 cpinfo
->DefaultChar
[1] = 0;
1678 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1679 cpinfo
->MaxCharSize
= (codepage
== CP_UTF7
) ? 5 : 4;
1683 SetLastError( ERROR_INVALID_PARAMETER
);
1686 if (table
->info
.def_char
& 0xff00)
1688 cpinfo
->DefaultChar
[0] = (table
->info
.def_char
& 0xff00) >> 8;
1689 cpinfo
->DefaultChar
[1] = table
->info
.def_char
& 0x00ff;
1693 cpinfo
->DefaultChar
[0] = table
->info
.def_char
& 0xff;
1694 cpinfo
->DefaultChar
[1] = 0;
1696 if ((cpinfo
->MaxCharSize
= table
->info
.char_size
) == 2)
1697 memcpy( cpinfo
->LeadByte
, table
->dbcs
.lead_bytes
, sizeof(cpinfo
->LeadByte
) );
1699 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1704 /***********************************************************************
1705 * GetCPInfoExA (KERNEL32.@)
1707 * Get extended information about a code page.
1710 * codepage [I] Code page number
1711 * dwFlags [I] Reserved, must to 0.
1712 * cpinfo [O] Destination for code page information
1715 * Success: TRUE. cpinfo is updated with the information about codepage.
1716 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1718 BOOL WINAPI
GetCPInfoExA( UINT codepage
, DWORD dwFlags
, LPCPINFOEXA cpinfo
)
1722 if (!GetCPInfoExW( codepage
, dwFlags
, &cpinfoW
))
1725 /* the layout is the same except for CodePageName */
1726 memcpy(cpinfo
, &cpinfoW
, sizeof(CPINFOEXA
));
1727 WideCharToMultiByte(CP_ACP
, 0, cpinfoW
.CodePageName
, -1, cpinfo
->CodePageName
, sizeof(cpinfo
->CodePageName
), NULL
, NULL
);
1731 /***********************************************************************
1732 * GetCPInfoExW (KERNEL32.@)
1734 * Unicode version of GetCPInfoExA.
1736 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD dwFlags
, LPCPINFOEXW cpinfo
)
1738 if (!GetCPInfo( codepage
, (LPCPINFO
)cpinfo
))
1745 static const WCHAR utf7
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
1747 cpinfo
->CodePage
= CP_UTF7
;
1748 cpinfo
->UnicodeDefaultChar
= 0x3f;
1749 strcpyW(cpinfo
->CodePageName
, utf7
);
1755 static const WCHAR utf8
[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
1757 cpinfo
->CodePage
= CP_UTF8
;
1758 cpinfo
->UnicodeDefaultChar
= 0x3f;
1759 strcpyW(cpinfo
->CodePageName
, utf8
);
1765 const union cptable
*table
= get_codepage_table( codepage
);
1767 cpinfo
->CodePage
= table
->info
.codepage
;
1768 cpinfo
->UnicodeDefaultChar
= table
->info
.def_unicode_char
;
1769 MultiByteToWideChar( CP_ACP
, 0, table
->info
.name
, -1, cpinfo
->CodePageName
,
1770 sizeof(cpinfo
->CodePageName
)/sizeof(WCHAR
));
1777 /***********************************************************************
1778 * EnumSystemCodePagesA (KERNEL32.@)
1780 * Call a user defined function for every code page installed on the system.
1783 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1784 * flags [I] Reserved, set to 0.
1787 * TRUE, If all code pages have been enumerated, or
1788 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1790 BOOL WINAPI
EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum
, DWORD flags
)
1792 const union cptable
*table
;
1798 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1799 sprintf( buffer
, "%d", table
->info
.codepage
);
1800 if (!lpfnCodePageEnum( buffer
)) break;
1806 /***********************************************************************
1807 * EnumSystemCodePagesW (KERNEL32.@)
1809 * See EnumSystemCodePagesA.
1811 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
, DWORD flags
)
1813 const union cptable
*table
;
1814 WCHAR buffer
[10], *p
;
1815 int page
, index
= 0;
1819 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1820 p
= buffer
+ sizeof(buffer
)/sizeof(WCHAR
);
1822 page
= table
->info
.codepage
;
1825 *--p
= '0' + (page
% 10);
1828 if (!lpfnCodePageEnum( p
)) break;
1834 /***********************************************************************
1835 * MultiByteToWideChar (KERNEL32.@)
1837 * Convert a multibyte character string into a Unicode string.
1840 * page [I] Codepage character set to convert from
1841 * flags [I] Character mapping flags
1842 * src [I] Source string buffer
1843 * srclen [I] Length of src (in bytes), or -1 if src is NUL terminated
1844 * dst [O] Destination buffer
1845 * dstlen [I] Length of dst (in WCHARs), or 0 to compute the required length
1848 * Success: If dstlen > 0, the number of characters written to dst.
1849 * If dstlen == 0, the number of characters needed to perform the
1850 * conversion. In both cases the count includes the terminating NUL.
1851 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1852 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1853 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1854 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1857 INT WINAPI
MultiByteToWideChar( UINT page
, DWORD flags
, LPCSTR src
, INT srclen
,
1858 LPWSTR dst
, INT dstlen
)
1860 const union cptable
*table
;
1863 if (!src
|| (!dst
&& dstlen
))
1865 SetLastError( ERROR_INVALID_PARAMETER
);
1869 if (srclen
< 0) srclen
= strlen(src
) + 1;
1876 SetLastError( ERROR_INVALID_PARAMETER
);
1879 ret
= wine_cpsymbol_mbstowcs( src
, srclen
, dst
, dstlen
);
1882 FIXME("UTF-7 not supported\n");
1883 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1888 ret
= wine_cp_mbstowcs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
);
1892 flags
|= MB_COMPOSITE
; /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
1896 ret
= wine_utf8_mbstowcs( flags
, src
, srclen
, dst
, dstlen
);
1899 if (!(table
= get_codepage_table( page
)))
1901 SetLastError( ERROR_INVALID_PARAMETER
);
1904 ret
= wine_cp_mbstowcs( table
, flags
, src
, srclen
, dst
, dstlen
);
1912 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1913 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1917 TRACE("cp %d %s -> %s, ret = %d\n",
1918 page
, debugstr_an(src
, srclen
), debugstr_wn(dst
, ret
), ret
);
1923 /***********************************************************************
1924 * WideCharToMultiByte (KERNEL32.@)
1926 * Convert a Unicode character string into a multibyte string.
1929 * page [I] Code page character set to convert to
1930 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1931 * src [I] Source string buffer
1932 * srclen [I] Length of src (in WCHARs), or -1 if src is NUL terminated
1933 * dst [O] Destination buffer
1934 * dstlen [I] Length of dst (in bytes), or 0 to compute the required length
1935 * defchar [I] Default character to use for conversion if no exact
1936 * conversion can be made
1937 * used [O] Set if default character was used in the conversion
1940 * Success: If dstlen > 0, the number of characters written to dst.
1941 * If dstlen == 0, number of characters needed to perform the
1942 * conversion. In both cases the count includes the terminating NUL.
1943 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1944 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1945 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1946 * parameter was given.
1948 INT WINAPI
WideCharToMultiByte( UINT page
, DWORD flags
, LPCWSTR src
, INT srclen
,
1949 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
1951 const union cptable
*table
;
1954 if (!src
|| (!dst
&& dstlen
))
1956 SetLastError( ERROR_INVALID_PARAMETER
);
1960 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1965 if( flags
|| defchar
|| used
)
1967 SetLastError( ERROR_INVALID_PARAMETER
);
1970 ret
= wine_cpsymbol_wcstombs( src
, srclen
, dst
, dstlen
);
1973 FIXME("UTF-7 not supported\n");
1974 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1979 ret
= wine_cp_wcstombs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
,
1980 defchar
, used
? &used_tmp
: NULL
);
1985 if (used
) *used
= FALSE
; /* all chars are valid for UTF-8 */
1986 ret
= wine_utf8_wcstombs( flags
, src
, srclen
, dst
, dstlen
);
1989 if (!(table
= get_codepage_table( page
)))
1991 SetLastError( ERROR_INVALID_PARAMETER
);
1994 ret
= wine_cp_wcstombs( table
, flags
, src
, srclen
, dst
, dstlen
,
1995 defchar
, used
? &used_tmp
: NULL
);
1996 if (used
) *used
= used_tmp
;
2004 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
2005 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
2009 TRACE("cp %d %s -> %s, ret = %d\n",
2010 page
, debugstr_wn(src
, srclen
), debugstr_an(dst
, ret
), ret
);
2015 /***********************************************************************
2016 * GetThreadLocale (KERNEL32.@)
2018 * Get the current threads locale.
2024 * The LCID currently associated with the calling thread.
2026 LCID WINAPI
GetThreadLocale(void)
2028 LCID ret
= NtCurrentTeb()->CurrentLocale
;
2029 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
2033 /**********************************************************************
2034 * SetThreadLocale (KERNEL32.@)
2036 * Set the current threads locale.
2039 * lcid [I] LCID of the locale to set
2042 * Success: TRUE. The threads locale is set to lcid.
2043 * Failure: FALSE. Use GetLastError() to determine the cause.
2045 BOOL WINAPI
SetThreadLocale( LCID lcid
)
2047 TRACE("(0x%04X)\n", lcid
);
2049 lcid
= ConvertDefaultLocale(lcid
);
2051 if (lcid
!= GetThreadLocale())
2053 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
2055 SetLastError(ERROR_INVALID_PARAMETER
);
2059 NtCurrentTeb()->CurrentLocale
= lcid
;
2060 kernel_get_thread_data()->code_page
= get_lcid_codepage( 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 CFArrayRef preferred_locales
, all_locales
;
2930 CFStringRef user_language_string_ref
= NULL
;
2931 char user_locale
[50];
2933 CFLocaleRef user_locale_ref
= CFLocaleCopyCurrent();
2934 CFStringRef user_locale_lang_ref
= CFLocaleGetValue( user_locale_ref
, kCFLocaleLanguageCode
);
2935 CFStringRef user_locale_country_ref
= CFLocaleGetValue( user_locale_ref
, kCFLocaleCountryCode
);
2936 CFStringRef user_locale_string_ref
;
2938 if (user_locale_country_ref
)
2940 user_locale_string_ref
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@_%@.UTF-8"),
2941 user_locale_lang_ref
, user_locale_country_ref
);
2945 user_locale_string_ref
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@.UTF-8"),
2946 user_locale_lang_ref
);
2949 CFStringGetCString( user_locale_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2950 CFRelease( user_locale_ref
);
2951 CFRelease( user_locale_string_ref
);
2953 unix_cp
= CP_UTF8
; /* default to utf-8 even if we don't get a valid locale */
2954 setenv( "LANG", user_locale
, 0 );
2955 TRACE( "setting locale to '%s'\n", user_locale
);
2957 /* We still want to set the retrieve the preferred language as chosen in
2958 System Preferences.app, because it can differ from CFLocaleCopyCurrent().
2960 all_locales
= CFLocaleCopyAvailableLocaleIdentifiers();
2961 preferred_locales
= CFBundleCopyLocalizationsForPreferences( all_locales
, NULL
);
2962 if (preferred_locales
&& CFArrayGetCount( preferred_locales
))
2963 user_language_string_ref
= CFArrayGetValueAtIndex( preferred_locales
, 0 );
2964 CFRelease( all_locales
);
2965 #endif /* __APPLE__ */
2967 setlocale( LC_ALL
, "" );
2969 unix_cp
= setup_unix_locales();
2970 if (!lcid_LC_MESSAGES
) lcid_LC_MESSAGES
= lcid_LC_CTYPE
;
2973 /* Override lcid_LC_MESSAGES with user_language if LC_MESSAGES is set to default */
2974 if (user_language_string_ref
&& !getenv("LC_ALL") && !getenv("LC_MESSAGES"))
2976 struct locale_name locale_name
;
2978 CFStringGetCString( user_language_string_ref
, user_locale
, sizeof(user_locale
), kCFStringEncodingUTF8
);
2979 strcpynAtoW( buffer
, user_locale
, sizeof(buffer
)/sizeof(WCHAR
) );
2980 parse_locale_name( buffer
, &locale_name
);
2981 lcid_LC_MESSAGES
= locale_name
.lcid
;
2982 TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale
);
2984 if (preferred_locales
)
2985 CFRelease( preferred_locales
);
2988 NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES
) );
2989 NtSetDefaultLocale( TRUE
, lcid_LC_MESSAGES
);
2990 NtSetDefaultLocale( FALSE
, lcid_LC_CTYPE
);
2992 ansi_cp
= get_lcid_codepage( LOCALE_USER_DEFAULT
);
2993 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
2994 (LPWSTR
)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
2995 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
2996 (LPWSTR
)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
2998 GetLocaleInfoW( LOCALE_USER_DEFAULT
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
2999 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) );
3001 if (!(ansi_cptable
= wine_cp_get_table( ansi_cp
)))
3002 ansi_cptable
= wine_cp_get_table( 1252 );
3003 if (!(oem_cptable
= wine_cp_get_table( oem_cp
)))
3004 oem_cptable
= wine_cp_get_table( 437 );
3005 if (!(mac_cptable
= wine_cp_get_table( mac_cp
)))
3006 mac_cptable
= wine_cp_get_table( 10000 );
3007 if (unix_cp
!= CP_UTF8
)
3009 if (!(unix_cptable
= wine_cp_get_table( unix_cp
)))
3010 unix_cptable
= wine_cp_get_table( 28591 );
3013 __wine_init_codepages( ansi_cptable
, oem_cptable
, unix_cptable
);
3015 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
3016 ansi_cptable
->info
.codepage
, oem_cptable
->info
.codepage
,
3017 mac_cptable
->info
.codepage
, unix_cp
);
3019 setlocale(LC_NUMERIC
, "C"); /* FIXME: oleaut32 depends on this */
3022 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
3024 UNICODE_STRING keyName
;
3025 OBJECT_ATTRIBUTES attr
;
3028 RtlInitUnicodeString( &keyName
, szKeyName
);
3029 InitializeObjectAttributes(&attr
, &keyName
, 0, hRootKey
, NULL
);
3031 if (NtOpenKey( &hkey
, KEY_READ
, &attr
) != STATUS_SUCCESS
)
3037 static BOOL
NLS_RegEnumSubKey(HANDLE hKey
, UINT ulIndex
, LPWSTR szKeyName
,
3041 KEY_BASIC_INFORMATION
*info
= (KEY_BASIC_INFORMATION
*)buffer
;
3044 if (NtEnumerateKey( hKey
, ulIndex
, KeyBasicInformation
, buffer
,
3045 sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
3046 info
->NameLength
> keyNameSize
)
3051 TRACE("info->Name %s info->NameLength %d\n", debugstr_w(info
->Name
), info
->NameLength
);
3053 memcpy( szKeyName
, info
->Name
, info
->NameLength
);
3054 szKeyName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
3056 TRACE("returning %s\n", debugstr_w(szKeyName
));
3060 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
3061 LPWSTR szValueName
, ULONG valueNameSize
,
3062 LPWSTR szValueData
, ULONG valueDataSize
)
3065 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
3068 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
3069 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
3070 info
->NameLength
> valueNameSize
||
3071 info
->DataLength
> valueDataSize
)
3076 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
3078 memcpy( szValueName
, info
->Name
, info
->NameLength
);
3079 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
3080 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
3081 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
3083 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
3087 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
3090 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
3091 DWORD dwSize
= sizeof(buffer
);
3092 UNICODE_STRING valueName
;
3094 RtlInitUnicodeString( &valueName
, szValueName
);
3096 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
3097 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
3098 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
3099 info
->DataLength
== sizeof(DWORD
))
3101 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
3108 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
3111 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
3115 /* FIXME: Is it correct to use the system default langid? */
3116 langId
= GetSystemDefaultLangID();
3118 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
3119 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
3121 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
3125 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
3129 ULONG iResourceIndex
= lgrpid
& 0xf;
3130 LPCWSTR lpResEntry
= LockResource( hResDir
);
3133 for (i
= 0; i
< iResourceIndex
; i
++)
3134 lpResEntry
+= *lpResEntry
+ 1;
3136 if (*lpResEntry
< nameSize
)
3138 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
3139 szName
[*lpResEntry
] = '\0';
3144 FreeResource( hResource
);
3149 /* Registry keys for NLS related information */
3151 static const WCHAR szCountryListName
[] = {
3152 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
3153 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
3154 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3155 'T','e','l','e','p','h','o','n','y','\\',
3156 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
3160 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
3163 LANGUAGEGROUP_ENUMPROCA procA
;
3164 LANGUAGEGROUP_ENUMPROCW procW
;
3167 } ENUMLANGUAGEGROUP_CALLBACKS
;
3169 /* Internal implementation of EnumSystemLanguageGroupsA/W */
3170 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
3172 WCHAR szNumber
[10], szValue
[4];
3174 BOOL bContinue
= TRUE
;
3179 SetLastError(ERROR_INVALID_PARAMETER
);
3183 switch (lpProcs
->dwFlags
)
3186 /* Default to LGRPID_INSTALLED */
3187 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
3188 /* Fall through... */
3189 case LGRPID_INSTALLED
:
3190 case LGRPID_SUPPORTED
:
3193 SetLastError(ERROR_INVALID_FLAGS
);
3197 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3200 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3204 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3205 szValue
, sizeof(szValue
) ))
3207 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
3208 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
3210 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
3211 bInstalled
? "" : "not ");
3213 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
3215 WCHAR szGrpName
[48];
3217 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
3218 szGrpName
[0] = '\0';
3221 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
3225 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3226 char szGrpNameA
[48];
3228 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
3229 * or whether the language names are ever localised. Assume CP_ACP.
3232 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3233 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
3235 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
3255 /******************************************************************************
3256 * EnumSystemLanguageGroupsA (KERNEL32.@)
3258 * Call a users function for each language group available on the system.
3261 * pLangGrpEnumProc [I] Callback function to call for each language group
3262 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
3263 * lParam [I] User parameter to pass to pLangGrpEnumProc
3267 * Failure: FALSE. Use GetLastError() to determine the cause.
3269 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
3270 DWORD dwFlags
, LONG_PTR lParam
)
3272 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3274 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3276 procs
.procA
= pLangGrpEnumProc
;
3278 procs
.dwFlags
= dwFlags
;
3279 procs
.lParam
= lParam
;
3281 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3284 /******************************************************************************
3285 * EnumSystemLanguageGroupsW (KERNEL32.@)
3287 * See EnumSystemLanguageGroupsA.
3289 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
3290 DWORD dwFlags
, LONG_PTR lParam
)
3292 ENUMLANGUAGEGROUP_CALLBACKS procs
;
3294 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
3297 procs
.procW
= pLangGrpEnumProc
;
3298 procs
.dwFlags
= dwFlags
;
3299 procs
.lParam
= lParam
;
3301 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
3304 /******************************************************************************
3305 * IsValidLanguageGroup (KERNEL32.@)
3307 * Determine if a language group is supported and/or installed.
3310 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
3311 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
3314 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
3317 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
3319 static const WCHAR szFormat
[] = { '%','x','\0' };
3320 WCHAR szValueName
[16], szValue
[2];
3321 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
3327 case LGRPID_INSTALLED
:
3328 case LGRPID_SUPPORTED
:
3330 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
3332 sprintfW( szValueName
, szFormat
, lgrpid
);
3334 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)szValue
))
3338 if (szValue
[0] == '1')
3348 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
3349 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
3355 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
3358 LANGGROUPLOCALE_ENUMPROCA procA
;
3359 LANGGROUPLOCALE_ENUMPROCW procW
;
3363 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
3365 /* Internal implementation of EnumLanguageGrouplocalesA/W */
3366 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
3368 static const WCHAR szAlternateSortsKeyName
[] = {
3369 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
3371 WCHAR szNumber
[10], szValue
[4];
3373 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
3375 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
3377 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
3379 SetLastError(ERROR_INVALID_PARAMETER
);
3383 if (lpProcs
->dwFlags
)
3385 SetLastError(ERROR_INVALID_FLAGS
);
3389 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
3392 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3396 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
3397 szValue
, sizeof(szValue
) ))
3399 lgrpid
= strtoulW( szValue
, NULL
, 16 );
3401 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
3402 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
3404 if (lgrpid
== lpProcs
->lgrpid
)
3408 lcid
= strtoulW( szNumber
, NULL
, 16 );
3410 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
3411 * '00000437 ;Georgian'
3412 * At present we only pass the LCID string.
3416 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
3419 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
3421 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
3423 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
3431 /* Finished enumerating this key */
3434 /* Enumerate alternate sorts also */
3435 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
3440 bContinue
= FALSE
; /* Finished both keys */
3453 /******************************************************************************
3454 * EnumLanguageGroupLocalesA (KERNEL32.@)
3456 * Call a users function for every locale in a language group available on the system.
3459 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3460 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3461 * dwFlags [I] Reserved, set to 0
3462 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3466 * Failure: FALSE. Use GetLastError() to determine the cause.
3468 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
3469 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3471 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3473 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3475 callbacks
.procA
= pLangGrpLcEnumProc
;
3476 callbacks
.procW
= NULL
;
3477 callbacks
.dwFlags
= dwFlags
;
3478 callbacks
.lgrpid
= lgrpid
;
3479 callbacks
.lParam
= lParam
;
3481 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3484 /******************************************************************************
3485 * EnumLanguageGroupLocalesW (KERNEL32.@)
3487 * See EnumLanguageGroupLocalesA.
3489 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
3490 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
3492 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
3494 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
3496 callbacks
.procA
= NULL
;
3497 callbacks
.procW
= pLangGrpLcEnumProc
;
3498 callbacks
.dwFlags
= dwFlags
;
3499 callbacks
.lgrpid
= lgrpid
;
3500 callbacks
.lParam
= lParam
;
3502 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
3505 /******************************************************************************
3506 * EnumSystemGeoID (KERNEL32.@)
3508 * Call a users function for every location available on the system.
3511 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3512 * reserved [I] Reserved, set to 0
3513 * pGeoEnumProc [I] Callback function to call for each location
3517 * Failure: FALSE. Use GetLastError() to determine the cause.
3519 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID reserved
, GEO_ENUMPROC pGeoEnumProc
)
3521 static const WCHAR szCountryCodeValueName
[] = {
3522 'C','o','u','n','t','r','y','C','o','d','e','\0'
3528 TRACE("(0x%08X,0x%08X,%p)\n", geoclass
, reserved
, pGeoEnumProc
);
3530 if (geoclass
!= GEOCLASS_NATION
|| reserved
|| !pGeoEnumProc
)
3532 SetLastError(ERROR_INVALID_PARAMETER
);
3536 hKey
= NLS_RegOpenKey( 0, szCountryListName
);
3538 while (NLS_RegEnumSubKey( hKey
, ulIndex
, szNumber
, sizeof(szNumber
) ))
3540 BOOL bContinue
= TRUE
;
3542 HANDLE hSubKey
= NLS_RegOpenKey( hKey
, szNumber
);
3546 if (NLS_RegGetDword( hSubKey
, szCountryCodeValueName
, &dwGeoId
))
3548 TRACE("Got geoid %d\n", dwGeoId
);
3550 if (!pGeoEnumProc( dwGeoId
))
3569 /******************************************************************************
3570 * InvalidateNLSCache (KERNEL32.@)
3572 * Invalidate the cache of NLS values.
3581 BOOL WINAPI
InvalidateNLSCache(void)
3587 /******************************************************************************
3588 * GetUserGeoID (KERNEL32.@)
3590 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
3592 GEOID ret
= GEOID_NOT_AVAILABLE
;
3593 static const WCHAR geoW
[] = {'G','e','o',0};
3594 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3595 WCHAR bufferW
[40], *end
;
3597 HANDLE hkey
, hSubkey
= 0;
3598 UNICODE_STRING keyW
;
3599 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
3600 RtlInitUnicodeString( &keyW
, nationW
);
3601 count
= sizeof(bufferW
);
3603 if(!(hkey
= create_registry_key())) return ret
;
3606 case GEOCLASS_NATION
:
3607 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
3609 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
3610 bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
3611 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
3614 case GEOCLASS_REGION
:
3615 FIXME("GEOCLASS_REGION not handled yet\n");
3620 if (hSubkey
) NtClose(hSubkey
);
3624 /******************************************************************************
3625 * SetUserGeoID (KERNEL32.@)
3627 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
3629 static const WCHAR geoW
[] = {'G','e','o',0};
3630 static const WCHAR nationW
[] = {'N','a','t','i','o','n',0};
3631 static const WCHAR formatW
[] = {'%','i',0};
3632 UNICODE_STRING nameW
,keyW
;
3634 OBJECT_ATTRIBUTES attr
;
3637 if(!(hkey
= create_registry_key())) return FALSE
;
3639 attr
.Length
= sizeof(attr
);
3640 attr
.RootDirectory
= hkey
;
3641 attr
.ObjectName
= &nameW
;
3642 attr
.Attributes
= 0;
3643 attr
.SecurityDescriptor
= NULL
;
3644 attr
.SecurityQualityOfService
= NULL
;
3645 RtlInitUnicodeString( &nameW
, geoW
);
3646 RtlInitUnicodeString( &keyW
, nationW
);
3648 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
3651 NtClose(attr
.RootDirectory
);
3655 sprintfW(bufferW
, formatW
, GeoID
);
3656 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
3657 NtClose(attr
.RootDirectory
);
3666 UILANGUAGE_ENUMPROCA procA
;
3667 UILANGUAGE_ENUMPROCW procW
;
3671 } ENUM_UILANG_CALLBACK
;
3673 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
3674 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
3676 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3679 sprintf(buf
, "%08x", (UINT
)LangID
);
3680 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
3683 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
3684 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
3686 static const WCHAR formatW
[] = {'%','0','8','x',0};
3687 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
3690 sprintfW( buf
, formatW
, (UINT
)LangID
);
3691 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
3694 /******************************************************************************
3695 * EnumUILanguagesA (KERNEL32.@)
3697 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3699 ENUM_UILANG_CALLBACK enum_uilang
;
3701 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3703 if(!pUILangEnumProc
) {
3704 SetLastError(ERROR_INVALID_PARAMETER
);
3708 SetLastError(ERROR_INVALID_FLAGS
);
3712 enum_uilang
.u
.procA
= pUILangEnumProc
;
3713 enum_uilang
.flags
= dwFlags
;
3714 enum_uilang
.param
= lParam
;
3716 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
3717 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
3718 (LONG_PTR
)&enum_uilang
);
3722 /******************************************************************************
3723 * EnumUILanguagesW (KERNEL32.@)
3725 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
3727 ENUM_UILANG_CALLBACK enum_uilang
;
3729 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
3732 if(!pUILangEnumProc
) {
3733 SetLastError(ERROR_INVALID_PARAMETER
);
3737 SetLastError(ERROR_INVALID_FLAGS
);
3741 enum_uilang
.u
.procW
= pUILangEnumProc
;
3742 enum_uilang
.flags
= dwFlags
;
3743 enum_uilang
.param
= lParam
;
3745 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
3746 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
3747 (LONG_PTR
)&enum_uilang
);
3751 INT WINAPI
GetGeoInfoW(GEOID GeoId
, GEOTYPE GeoType
, LPWSTR lpGeoData
,
3752 int cchData
, LANGID language
)
3754 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);
3758 INT WINAPI
GetGeoInfoA(GEOID GeoId
, GEOTYPE GeoType
, LPSTR lpGeoData
,
3759 int cchData
, LANGID language
)
3761 FIXME("%d %d %p %d %d\n", GeoId
, GeoType
, lpGeoData
, cchData
, language
);