2 * PROJECT: ReactOS user mode libraries
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: reactos/lib/kernel32/misc/lang.c
12 #include "../include/debug.h"
14 /* FIXME: these are included in winnls.h, however including this file causes alot of
15 conflicting type errors. */
17 #define LOCALE_SYEARMONTH 0x1006
18 #define LOCALE_IPAPERSIZE 0x100A
19 #define LOCALE_RETURN_NUMBER 0x20000000
20 #define LOCALE_USE_CP_ACP 0x40000000
21 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
23 //static LCID SystemLocale = MAKELCID(LANG_ENGLISH, SORT_DEFAULT);
25 //static RTL_CRITICAL_SECTION LocalesListLock;
27 /******************************************************************************
29 * RIPPED FROM WINE's dlls\kernel\locale.c rev 1.42
31 * ConvertDefaultLocale (KERNEL32.@)
33 * Convert a default locale identifier into a real identifier.
36 * lcid [I] LCID identifier of the locale to convert
39 * lcid unchanged, if not a default locale or its sublanguage is
40 * not SUBLANG_NEUTRAL.
41 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
42 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
43 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
46 ConvertDefaultLocale(LCID lcid
)
52 case LOCALE_SYSTEM_DEFAULT
:
53 lcid
= GetSystemDefaultLCID();
56 case LOCALE_USER_DEFAULT
:
58 lcid
= GetUserDefaultLCID();
62 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
63 langid
= LANGIDFROMLCID(lcid
);
64 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
66 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
67 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
81 CALINFO_ENUMPROCEXA lpCalInfoEnumProcEx
,
86 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
97 CALINFO_ENUMPROCEXW lpCalInfoEnumProcEx
,
102 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
112 CALINFO_ENUMPROCW lpCalInfoEnumProcEx
,
117 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
127 DATEFMT_ENUMPROCEXA lpDateFmtEnumProcEx
,
131 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
142 DATEFMT_ENUMPROCEXW lpDateFmtEnumProcEx
,
146 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
156 EnumLanguageGroupLocalesA(
157 LANGGROUPLOCALE_ENUMPROCA lpLangGroupLocaleEnumProc
,
158 LGRPID LanguageGroup
,
162 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
172 EnumLanguageGroupLocalesW(
173 LANGGROUPLOCALE_ENUMPROCW lpLangGroupLocaleEnumProc
,
174 LGRPID LanguageGroup
,
178 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
188 EnumSystemCodePagesW (
189 CODEPAGE_ENUMPROCW lpCodePageEnumProc
,
193 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
203 EnumSystemCodePagesA (
204 CODEPAGE_ENUMPROCA lpCodePageEnumProc
,
208 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
221 GEO_ENUMPROC lpGeoEnumProc
)
225 SetLastError(ERROR_INVALID_PARAMETER
);
231 case GEOCLASS_NATION
:
232 /*RtlEnterCriticalSection(&DllLock);
234 FIXME - Get GEO IDs calling Csr
236 RtlLeaveCriticalSection(&DllLock);*/
238 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
242 SetLastError(ERROR_INVALID_FLAGS
);
255 EnumSystemLanguageGroupsA(
256 LANGUAGEGROUP_ENUMPROCA pLangGroupEnumProc
,
260 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
270 EnumSystemLanguageGroupsW(
271 LANGUAGEGROUP_ENUMPROCW pLangGroupEnumProc
,
275 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
286 LOCALE_ENUMPROCA lpLocaleEnumProc
,
290 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
301 LOCALE_ENUMPROCW lpLocaleEnumProc
,
307 UNICODE_STRING langKeyName
= RTL_CONSTANT_STRING(
308 L
"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\Locale");
309 OBJECT_ATTRIBUTES objectAttributes
;
311 unsigned char fullInfo
[sizeof(KEY_VALUE_FULL_INFORMATION
)+255*2]; //FIXME: MAX_PATH*2
312 PKEY_VALUE_FULL_INFORMATION pFullInfo
;
314 //TODO: Combine with EnumSystemLocalesA - maybe by having one common part, driven by some
315 // unicode/non-unicode flag.
317 //FIXME: dwFlags is really not used, sorry
319 // Check if enum proc is a real one
320 if (lpLocaleEnumProc
== NULL
)
322 SetLastError(ERROR_INVALID_PARAMETER
);
326 // Open language registry key
327 //FIXME: Should we use critical section here?
329 InitializeObjectAttributes(&objectAttributes
,
331 OBJ_CASE_INSENSITIVE
,
335 result
= NtOpenKey(&langKey
,
339 if (!NT_SUCCESS(result
))
342 DPRINT1("Registry key succesfully opened\n");
344 length
= sizeof(KEY_VALUE_FULL_INFORMATION
) + 255*2;//MAX_PATH*sizeof(WCHAR);
345 pFullInfo
= (PKEY_VALUE_FULL_INFORMATION
)&fullInfo
;
346 RtlZeroMemory(pFullInfo
, length
);
350 result
= NtEnumerateValueKey(langKey
,
352 KeyValueFullInformation
,
357 DPRINT1("First enumerate call result=%x\n", result
);
358 while (result
!= STATUS_NO_MORE_ENTRIES
)
363 // TODO: Here we should check, in case dwFlags & LCID_INSTALLED is specified,
364 // if this locale is really installed
365 // but for now we skip it
368 lpLocale
[i
] = pFullInfo
->Name
[i
];
372 DPRINT1("Locale=%S\n", lpLocale
);
375 if (!lpLocaleEnumProc((LPWSTR
)lpLocale
))
378 // Zero previous values
379 RtlZeroMemory(pFullInfo
, length
);
382 result
= NtEnumerateValueKey(langKey
, index
,KeyValueFullInformation
, pFullInfo
, length
, &length
);
387 return STATUS_SUCCESS
;
397 UILANGUAGE_ENUMPROCA lpUILanguageEnumProc
,
401 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
412 UILANGUAGE_ENUMPROCW lpUILanguageEnumProc
,
416 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
433 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
451 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
463 LPCPINFO CodePageInfo
468 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
470 CodePageInfo
->MaxCharSize
= 1;
471 CodePageInfo
->DefaultChar
[0] = '?';
472 for (i
= 1; i
< MAX_DEFAULTCHAR
; i
++)
474 CodePageInfo
->DefaultChar
[i
] = 0;
476 for (i
= 0; i
< MAX_LEADBYTES
; i
++)
478 CodePageInfo
->LeadByte
[i
] = 0;
493 LPCPINFOEXW lpCPInfoEx
)
495 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
508 LPCPINFOEXA lpCPInfoEx
)
510 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
527 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
544 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
548 const WCHAR
*RosGetLocaleValueName( DWORD lctype
)
550 switch (lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
)
552 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
553 * the values are stored in the registry, confirmed under Windows.
555 case LOCALE_ICALENDARTYPE
: return L
"iCalendarType";
556 case LOCALE_ICURRDIGITS
: return L
"iCurrDigits";
557 case LOCALE_ICURRENCY
: return L
"iCurrency";
558 case LOCALE_IDIGITS
: return L
"iDigits";
559 case LOCALE_IFIRSTDAYOFWEEK
: return L
"iFirstDayOfWeek";
560 case LOCALE_IFIRSTWEEKOFYEAR
: return L
"iFirstWeekOfYear";
561 case LOCALE_ILZERO
: return L
"iLZero";
562 case LOCALE_IMEASURE
: return L
"iMeasure";
563 case LOCALE_INEGCURR
: return L
"iNegCurr";
564 case LOCALE_INEGNUMBER
: return L
"iNegNumber";
565 case LOCALE_IPAPERSIZE
: return L
"iPaperSize";
566 case LOCALE_ITIME
: return L
"iTime";
567 case LOCALE_S1159
: return L
"s1159";
568 case LOCALE_S2359
: return L
"s2359";
569 case LOCALE_SCURRENCY
: return L
"sCurrency";
570 case LOCALE_SDATE
: return L
"sDate";
571 case LOCALE_SDECIMAL
: return L
"sDecimal";
572 case LOCALE_SGROUPING
: return L
"sGrouping";
573 case LOCALE_SLIST
: return L
"sList";
574 case LOCALE_SLONGDATE
: return L
"sLongDate";
575 case LOCALE_SMONDECIMALSEP
: return L
"sMonDecimalSep";
576 case LOCALE_SMONGROUPING
: return L
"sMonGrouping";
577 case LOCALE_SMONTHOUSANDSEP
: return L
"sMonThousandSep";
578 case LOCALE_SNEGATIVESIGN
: return L
"sNegativeSign";
579 case LOCALE_SPOSITIVESIGN
: return L
"sPositiveSign";
580 case LOCALE_SSHORTDATE
: return L
"sShortDate";
581 case LOCALE_STHOUSAND
: return L
"sThousand";
582 case LOCALE_STIME
: return L
"sTime";
583 case LOCALE_STIMEFORMAT
: return L
"sTimeFormat";
584 case LOCALE_SYEARMONTH
: return L
"sYearMonth";
586 /* The following are not listed under MSDN as supported,
587 * but seem to be used and also stored in the registry.
589 case LOCALE_ICOUNTRY
: return L
"iCountry";
590 case LOCALE_IDATE
: return L
"iDate";
591 case LOCALE_ILDATE
: return L
"iLDate";
592 case LOCALE_ITLZERO
: return L
"iTLZero";
593 case LOCALE_SCOUNTRY
: return L
"sCountry";
594 case LOCALE_SLANGUAGE
: return L
"sLanguage";
599 HKEY
RosCreateRegistryKey(void)
601 OBJECT_ATTRIBUTES objAttr
;
602 UNICODE_STRING nameW
;
605 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hKey
) != STATUS_SUCCESS
) return 0;
607 objAttr
.Length
= sizeof(objAttr
);
608 objAttr
.RootDirectory
= hKey
;
609 objAttr
.ObjectName
= &nameW
;
610 objAttr
.Attributes
= 0;
611 objAttr
.SecurityDescriptor
= NULL
;
612 objAttr
.SecurityQualityOfService
= NULL
;
613 RtlInitUnicodeString( &nameW
, L
"Control Panel\\International");
615 if (NtCreateKey( &hKey
, KEY_ALL_ACCESS
, &objAttr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) hKey
= 0;
616 NtClose( objAttr
.RootDirectory
);
620 INT
RosGetRegistryLocaleInfo( LPCWSTR lpValue
, LPWSTR lpBuffer
, INT nLen
)
626 UNICODE_STRING usNameW
;
627 KEY_VALUE_PARTIAL_INFORMATION
*kvpiInfo
;
628 const int nInfoSize
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
630 if (!(hKey
= RosCreateRegistryKey())) return -1;
632 RtlInitUnicodeString( &usNameW
, lpValue
);
633 dwSize
= nInfoSize
+ nLen
* sizeof(WCHAR
);
635 if (!(kvpiInfo
= HeapAlloc( GetProcessHeap(), 0, dwSize
)))
638 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
642 ntStatus
= NtQueryValueKey( hKey
, &usNameW
, KeyValuePartialInformation
, kvpiInfo
, dwSize
, &dwSize
);
643 if (ntStatus
== STATUS_BUFFER_OVERFLOW
&& !lpBuffer
) ntStatus
= 0;
647 nRet
= (dwSize
- nInfoSize
) / sizeof(WCHAR
);
649 if (!nRet
|| ((WCHAR
*)kvpiInfo
->Data
)[nRet
- 1])
651 if (nRet
< nLen
|| !lpBuffer
) nRet
++;
654 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
658 if (nRet
&& lpBuffer
)
660 memcpy( lpBuffer
, kvpiInfo
->Data
, (nRet
- 1) * sizeof(WCHAR
) );
661 lpBuffer
[nRet
- 1] = 0;
666 if (ntStatus
== STATUS_OBJECT_NAME_NOT_FOUND
) nRet
= -1;
669 SetLastError( RtlNtStatusToDosError(ntStatus
) );
674 HeapFree( GetProcessHeap(), 0, kvpiInfo
);
699 if (cchData
< 0 || (cchData
&& !lpLCData
))
701 SetLastError( ERROR_INVALID_PARAMETER
);
704 if (!cchData
) lpLCData
= NULL
;
706 if (Locale
== LOCALE_NEUTRAL
|| Locale
== LOCALE_SYSTEM_DEFAULT
) Locale
= GetSystemDefaultLCID();
707 else if (Locale
== LOCALE_USER_DEFAULT
) Locale
= GetUserDefaultLCID();
709 uiFlags
= LCType
& LOCALE_LOCALEINFOFLAGSMASK
;
710 LCType
&= ~LOCALE_LOCALEINFOFLAGSMASK
;
712 if (!(uiFlags
& LOCALE_NOUSEROVERRIDE
) && Locale
== GetUserDefaultLCID())
714 const WCHAR
*value
= RosGetLocaleValueName(LCType
);
716 if (value
&& ((nRet
= RosGetRegistryLocaleInfo( value
, lpLCData
, cchData
)) != -1)) return nRet
;
719 liLangID
= LANGIDFROMLCID( Locale
);
721 if (SUBLANGID(liLangID
) == SUBLANG_NEUTRAL
)
722 liLangID
= MAKELANGID(PRIMARYLANGID(liLangID
), SUBLANG_DEFAULT
);
724 hModule
= GetModuleHandleW( L
"kernel32.dll" );
725 if (!(hRsrc
= FindResourceExW( hModule
, (LPWSTR
)RT_STRING
, (LPCWSTR
)((LCType
>> 4) + 1), liLangID
)))
727 SetLastError( ERROR_INVALID_FLAGS
);
730 if (!(hMem
= LoadResource( hModule
, hRsrc
)))
733 ch
= LockResource( hMem
);
734 for (i
= 0; i
< (int)(LCType
& 0x0f); i
++) ch
+= *ch
+ 1;
736 if (uiFlags
& LOCALE_RETURN_NUMBER
) nRet
= sizeof(UINT
) / sizeof(WCHAR
);
737 else nRet
= (LCType
== LOCALE_FONTSIGNATURE
) ? *ch
: *ch
+ 1;
739 if (!lpLCData
) return nRet
;
743 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
747 if (uiFlags
& LOCALE_RETURN_NUMBER
)
750 WCHAR
*chEnd
, *chTmp
= HeapAlloc( GetProcessHeap(), 0, (*ch
+ 1) * sizeof(WCHAR
) );
755 memcpy( chTmp
, ch
+ 1, *ch
* sizeof(WCHAR
) );
757 uiNum
= wcstol( chTmp
, &chEnd
, 10 );
760 memcpy( lpLCData
, &uiNum
, sizeof(uiNum
) );
763 SetLastError( ERROR_INVALID_FLAGS
);
766 HeapFree( GetProcessHeap(), 0, chTmp
);
770 memcpy( lpLCData
, ch
+ 1, *ch
* sizeof(WCHAR
) );
771 if (LCType
!= LOCALE_FONTSIGNATURE
) lpLCData
[nRet
-1] = 0;
778 /***********************************************************************
781 * Retrieve the ANSI codepage for a given locale.
783 __inline
static UINT
get_lcid_codepage( LCID lcid
)
786 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
787 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
806 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
807 WCHAR
*buf2W
= buf1W
+ 130;
809 INT len1W
, len2W
, ret
;
812 if (!lpString1
|| !lpString2
)
814 SetLastError(ERROR_INVALID_PARAMETER
);
817 if (cchCount1
< 0) cchCount1
= strlen(lpString1
);
818 if (cchCount2
< 0) cchCount2
= strlen(lpString2
);
820 locale_cp
= get_lcid_codepage(Locale
);
822 len1W
= MultiByteToWideChar(locale_cp
, 0, lpString1
, cchCount1
, buf1W
, 130);
827 len1W
= MultiByteToWideChar(locale_cp
, 0, lpString1
, cchCount1
, NULL
, 0);
828 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
831 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
834 MultiByteToWideChar(locale_cp
, 0, lpString1
, cchCount1
, str1W
, len1W
);
836 len2W
= MultiByteToWideChar(locale_cp
, 0, lpString2
, cchCount2
, buf2W
, 130);
841 len2W
= MultiByteToWideChar(locale_cp
, 0, lpString2
, cchCount2
, NULL
, 0);
842 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
845 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
846 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
849 MultiByteToWideChar(locale_cp
, 0, lpString2
, cchCount2
, str2W
, len2W
);
852 ret
= CompareStringW(Locale
, dwCmpFlags
, str1W
, len1W
, str2W
, len2W
);
854 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
855 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
860 static int compare_unicode_string(
861 PUNICODE_STRING String1
,
862 PUNICODE_STRING String2
,
870 if (String1
&& String2
)
872 len1
= String1
->Length
/ sizeof(WCHAR
);
873 len2
= String2
->Length
/ sizeof(WCHAR
);
874 s1
= String1
->Buffer
;
875 s2
= String2
->Buffer
;
877 while (len1
> 0 && len2
> 0)
879 if (Flags
& NORM_IGNORESYMBOLS
)
882 /* FIXME: not tested */
883 if (iswctype(*s1
, _SPACE
| _PUNCT
))
889 if (iswctype(*s2
, _SPACE
| _PUNCT
))
898 /* hyphen and apostrophe are treated differently depending on
899 * whether SORT_STRINGSORT specified or not
901 if (!(Flags
& SORT_STRINGSORT
))
903 if (*s1
== '-' || *s1
== '\'')
905 if (*s2
!= '-' && *s2
!= '\'')
912 else if (*s2
== '-' || *s2
== '\'')
919 if (Flags
& NORM_IGNORECASE
)
921 c1
= len1
-- ? RtlUpcaseUnicodeChar(*s1
++) : 0;
922 c2
= len2
-- ? RtlUpcaseUnicodeChar(*s2
++) : 0;
923 if (!c1
|| !c2
|| c1
!= c2
)
928 c1
= len1
-- ? *s1
++ : 0;
929 c2
= len2
-- ? *s2
++ : 0;
930 if (!c1
|| !c2
|| c1
!= c2
)
934 return (int) len1
- (int) len2
;
955 UNICODE_STRING String1
, String2
;
957 if (!lpString1
|| !lpString2
)
959 SetLastError(ERROR_INVALID_PARAMETER
);
963 if (dwCmpFlags
& ~(NORM_IGNORECASE
| NORM_IGNORENONSPACE
|
964 NORM_IGNORESYMBOLS
| SORT_STRINGSORT
| NORM_IGNOREKANATYPE
|
965 NORM_IGNOREWIDTH
| 0x10000000))
967 SetLastError(ERROR_INVALID_FLAGS
);
971 if (cchCount1
< 0) cchCount1
= lstrlenW(lpString1
);
972 if (cchCount2
< 0) cchCount2
= lstrlenW(lpString2
);
974 String1
.Length
= String1
.MaximumLength
= cchCount1
* sizeof(WCHAR
);
975 String1
.Buffer
= (LPWSTR
)lpString1
;
976 String2
.Length
= String2
.MaximumLength
= cchCount2
* sizeof(WCHAR
);
977 String2
.Buffer
= (LPWSTR
)lpString2
;
980 if (dwCmpFlags
& ~NORM_IGNORECASE
)
982 DPRINT("CompareString: STUB flags - 0x%x\n", dwCmpFlags
);
983 Result
= compare_unicode_string(&String1
, &String2
, dwCmpFlags
);
986 Result
= RtlCompareUnicodeString(
987 &String1
, &String2
, dwCmpFlags
& NORM_IGNORECASE
);
990 if (Result
) /* need to translate result */
991 return (Result
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
1002 * Get information about an aspect of a locale.
1005 * lcid [I] LCID of the locale
1006 * lctype [I] LCTYPE_ flags from "winnls.h"
1007 * buffer [O] Destination for the information
1008 * len [I] Length of buffer in characters
1011 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1012 * with the information.
1013 * Failure: 0. Use GetLastError() to determine the cause.
1016 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1017 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1018 * which is a bit string.
1020 INT STDCALL
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
1025 if (len
< 0 || (len
&& !buffer
))
1027 SetLastError( ERROR_INVALID_PARAMETER
);
1030 if (!len
) buffer
= NULL
;
1032 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
1034 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
1036 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1039 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
1041 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
1042 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
1044 /* it's not an ASCII string, just bytes */
1045 ret
*= sizeof(WCHAR
);
1048 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
1051 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1058 UINT codepage
= CP_ACP
;
1059 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1060 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
1063 HeapFree( GetProcessHeap(), 0, bufferW
);
1072 GetSystemDefaultLangID(VOID
)
1074 return LANGIDFROMLCID(GetSystemDefaultLCID());
1082 GetSystemDefaultLCID(VOID
)
1086 NtQueryDefaultLocale(FALSE
, &lcid
);
1096 GetSystemDefaultUILanguage(VOID
)
1101 Status
= NtQueryInstallUILanguage(&LanguageId
);
1102 if (!NT_SUCCESS(Status
))
1104 SetLastErrorByStatus(Status
);
1116 GetThreadLocale(VOID
)
1118 return NtCurrentTeb()->CurrentLocale
;
1126 GetUserDefaultLangID(VOID
)
1128 return LANGIDFROMLCID(GetUserDefaultLCID());
1136 GetUserDefaultLCID(VOID
)
1141 Status
= NtQueryDefaultLocale(TRUE
, &lcid
);
1142 if (!NT_SUCCESS(Status
))
1144 SetLastErrorByStatus(Status
);
1156 GetUserDefaultUILanguage(VOID
)
1161 Status
= NtQueryDefaultUILanguage(&LangId
);
1162 if (!NT_SUCCESS(Status
))
1164 SetLastErrorByStatus(Status
);
1180 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1190 IsValidLanguageGroup(
1191 LGRPID LanguageGroup
,
1194 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1199 /******************************************************************************
1202 * Determine if a locale is valid.
1205 * Locale [I] LCID of the locale to check
1206 * dwFlags [I] LCID_SUPPORTED = Valid
1207 * LCID_INSTALLED = Valid and installed on the system
1210 * TRUE, if Locale is valid,
1216 IsValidLocale(LCID Locale
,
1219 OBJECT_ATTRIBUTES ObjectAttributes
;
1220 PKEY_VALUE_PARTIAL_INFORMATION KeyInfo
;
1221 WCHAR ValueNameBuffer
[9];
1222 UNICODE_STRING KeyName
;
1223 UNICODE_STRING ValueName
;
1230 DPRINT("IsValidLocale() called\n");
1232 if ((dwFlags
& ~(LCID_SUPPORTED
| LCID_INSTALLED
)) ||
1233 (dwFlags
== (LCID_SUPPORTED
| LCID_INSTALLED
)))
1235 DPRINT("Invalid flags: %lx\n", dwFlags
);
1239 if (Locale
& 0xFFFF0000)
1241 RtlInitUnicodeString(&KeyName
,
1242 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Locale\\Alternate Sorts");
1246 RtlInitUnicodeString(&KeyName
,
1247 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Locale");
1250 InitializeObjectAttributes(&ObjectAttributes
,
1252 OBJ_CASE_INSENSITIVE
,
1256 Status
= NtOpenKey(&KeyHandle
,
1259 if (!NT_SUCCESS(Status
))
1261 DPRINT("NtOpenKey() failed (Status %lx)\n", Status
);
1265 swprintf(ValueNameBuffer
, L
"%08lx", (ULONG
)Locale
);
1266 RtlInitUnicodeString(&ValueName
, ValueNameBuffer
);
1268 KeyInfoSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 4 * sizeof(WCHAR
);
1269 KeyInfo
= RtlAllocateHeap(RtlGetProcessHeap(),
1272 if (KeyInfo
== NULL
)
1274 DPRINT("RtlAllocateHeap() failed (Status %lx)\n", Status
);
1279 Status
= NtQueryValueKey(KeyHandle
,
1281 KeyValuePartialInformation
,
1287 if (!NT_SUCCESS(Status
))
1289 DPRINT("NtQueryValueKey() failed (Status %lx)\n", Status
);
1290 RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo
);
1294 if (dwFlags
& LCID_SUPPORTED
)
1296 DPRINT("Locale is supported\n");
1297 RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo
);
1301 ValueData
= (PWSTR
)&KeyInfo
->Data
[0];
1302 if ((dwFlags
& LCID_INSTALLED
) &&
1303 (KeyInfo
->Type
== REG_SZ
) &&
1304 (KeyInfo
->DataLength
== 2 * sizeof(WCHAR
)) &&
1305 (ValueData
[0] == L
'1'))
1307 DPRINT("Locale is supported and installed\n");
1308 RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo
);
1312 RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo
);
1314 DPRINT("IsValidLocale() called\n");
1334 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1369 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1384 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1400 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1416 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1421 /**********************************************************************
1423 * RIPPED FROM WINE's dlls\kernel\locale.c rev 1.42
1425 * SetThreadLocale (KERNEL32.@)
1427 * Set the current threads locale.
1430 * lcid [I] LCID of the locale to set
1433 * Success: TRUE. The threads locale is set to lcid.
1434 * Failure: FALSE. Use GetLastError() to determine the cause.
1437 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1439 DPRINT("SetThreadLocale(0x%04lX)\n", lcid
);
1441 lcid
= ConvertDefaultLocale(lcid
);
1443 if (lcid
!= GetThreadLocale())
1445 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1447 SetLastError(ERROR_INVALID_PARAMETER
);
1451 NtCurrentTeb()->CurrentLocale
= lcid
;
1452 /* FIXME: NtCurrentTeb()->code_page = get_lcid_codepage( lcid );
1453 * Wine save the acp for easy/fast access, but ROS has no such Teb member.
1454 * Maybe add this member to ros as well?
1458 Lag test app for å se om locale etc, endres i en app. etter at prosessen er
1459 startet, eller om bare nye prosesser blir berørt.
1474 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1490 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1505 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);