3 * Copyright (C) 2008 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/mui.c
23 * PURPOSE: Text-mode setup
27 /* INCLUDES *****************************************************************/
32 #include "muilanguages.h"
40 /* FUNCTIONS ****************************************************************/
49 if (LanguageId
== NULL
)
51 /* Default to en-US */
52 // return 0; // FIXME!!
53 LanguageId
= L
"00000409";
56 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
58 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
75 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
77 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
88 MUIDefaultKeyboardLayout(
91 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
92 return MUILanguageList
[lngIndex
].MuiLayouts
[0].LayoutID
;
99 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
100 return MUILanguageList
[lngIndex
].OEMCPage
;
105 IN PCWSTR LanguageId
)
107 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
108 return MUILanguageList
[lngIndex
].GeoID
;
113 IN PCWSTR LanguageId
)
115 ULONG lngIndex
= max(FindLanguageIndex(LanguageId
), 0);
116 return MUILanguageList
[lngIndex
].MuiLayouts
;
124 IN PCWSTR LangHotkey
,
125 IN PCWSTR LayoutHotkey
)
127 OBJECT_ATTRIBUTES ObjectAttributes
;
128 UNICODE_STRING KeyName
;
129 UNICODE_STRING ValueName
;
134 RtlInitUnicodeString(&KeyName
,
135 L
".DEFAULT\\Keyboard Layout\\Toggle");
136 InitializeObjectAttributes(&ObjectAttributes
,
138 OBJ_CASE_INSENSITIVE
,
139 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
142 Status
= NtCreateKey(&KeyHandle
,
147 REG_OPTION_NON_VOLATILE
,
149 if (!NT_SUCCESS(Status
))
151 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
155 RtlInitUnicodeString(&ValueName
,
158 Status
= NtSetValueKey(KeyHandle
,
163 (1 + 1) * sizeof(WCHAR
));
164 if (!NT_SUCCESS(Status
))
166 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
171 RtlInitUnicodeString(&ValueName
,
174 Status
= NtSetValueKey(KeyHandle
,
179 (1 + 1) * sizeof(WCHAR
));
180 if (!NT_SUCCESS(Status
))
182 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
187 RtlInitUnicodeString(&ValueName
,
190 Status
= NtSetValueKey(KeyHandle
,
195 (1 + 1) * sizeof(WCHAR
));
196 if (!NT_SUCCESS(Status
))
198 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
208 AddKbLayoutsToRegistry(
209 IN
const MUI_LAYOUTS
*MuiLayouts
)
211 OBJECT_ATTRIBUTES ObjectAttributes
;
212 UNICODE_STRING KeyName
;
213 UNICODE_STRING ValueName
;
220 WCHAR szKeyName
[48] = L
".DEFAULT\\Keyboard Layout";
221 WCHAR szValueName
[3 + 1];
222 WCHAR szLangID
[8 + 1];
224 // Open the keyboard layout key
225 RtlInitUnicodeString(&KeyName
, szKeyName
);
226 InitializeObjectAttributes(&ObjectAttributes
,
228 OBJ_CASE_INSENSITIVE
,
229 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
232 Status
= NtCreateKey(&KeyHandle
,
237 REG_OPTION_NON_VOLATILE
,
239 if (!NT_SUCCESS(Status
))
241 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
247 KeyName
.MaximumLength
= sizeof(szKeyName
);
248 Status
= RtlAppendUnicodeToString(&KeyName
, L
"\\Preload");
250 if (!NT_SUCCESS(Status
))
252 DPRINT1("RtlAppend failed! (%lx)\n", Status
);
253 DPRINT1("String is %wZ\n", &KeyName
);
257 InitializeObjectAttributes(&ObjectAttributes
,
259 OBJ_CASE_INSENSITIVE
,
260 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
263 Status
= NtCreateKey(&KeyHandle
,
268 REG_OPTION_NON_VOLATILE
,
270 if (!NT_SUCCESS(Status
))
272 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
276 RtlInitUnicodeString(&KeyName
, L
".DEFAULT\\Keyboard Layout\\Substitutes");
277 InitializeObjectAttributes(&ObjectAttributes
,
279 OBJ_CASE_INSENSITIVE
,
280 GetRootKeyByPredefKey(HKEY_USERS
, NULL
),
283 Status
= NtCreateKey(&SubKeyHandle
,
288 REG_OPTION_NON_VOLATILE
,
290 if (!NT_SUCCESS(Status
))
292 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
293 NtClose(SubKeyHandle
);
298 while (MuiLayouts
[uIndex
].LangID
!= NULL
)
300 if (uIndex
> 19) break;
302 RtlStringCchPrintfW(szValueName
, ARRAYSIZE(szValueName
), L
"%u", uIndex
+ 1);
303 RtlInitUnicodeString(&ValueName
, szValueName
);
305 RtlStringCchPrintfW(szLangID
, ARRAYSIZE(szLangID
), L
"0000%s", MuiLayouts
[uIndex
].LangID
);
307 if (_wcsicmp(szLangID
, MuiLayouts
[uIndex
].LayoutID
) == 0)
309 Status
= NtSetValueKey(KeyHandle
,
313 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
314 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
315 if (!NT_SUCCESS(Status
))
317 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
318 NtClose(SubKeyHandle
);
325 RtlStringCchPrintfW(szLangID
, ARRAYSIZE(szLangID
), L
"d%03lu%s", uCount
, MuiLayouts
[uIndex
].LangID
);
326 Status
= NtSetValueKey(KeyHandle
,
331 (wcslen(szLangID
)+1) * sizeof(WCHAR
));
332 if (!NT_SUCCESS(Status
))
334 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
335 NtClose(SubKeyHandle
);
340 RtlInitUnicodeString(&ValueName
, szLangID
);
342 Status
= NtSetValueKey(SubKeyHandle
,
346 (PVOID
)MuiLayouts
[uIndex
].LayoutID
,
347 (wcslen(MuiLayouts
[uIndex
].LayoutID
)+1) * sizeof(WCHAR
));
348 if (!NT_SUCCESS(Status
))
350 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status
, uIndex
);
351 NtClose(SubKeyHandle
);
363 AddHotkeySettings(L
"2", L
"2", L
"1");
365 AddHotkeySettings(L
"3", L
"3", L
"3");
367 NtClose(SubKeyHandle
);
374 IN PCWSTR LanguageId
)
378 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
380 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
382 return AddKbLayoutsToRegistry(MUILanguageList
[lngIndex
].MuiLayouts
);
393 AddCodepageToRegistry(
398 OBJECT_ATTRIBUTES ObjectAttributes
;
399 UNICODE_STRING KeyName
;
400 UNICODE_STRING ValueName
;
404 // Open the nls codepage key
405 RtlInitUnicodeString(&KeyName
,
406 L
"SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
407 InitializeObjectAttributes(&ObjectAttributes
,
409 OBJ_CASE_INSENSITIVE
,
410 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
412 Status
= NtOpenKey(&KeyHandle
,
415 if (!NT_SUCCESS(Status
))
417 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
422 RtlInitUnicodeString(&ValueName
, L
"ACP");
423 Status
= NtSetValueKey(KeyHandle
,
428 (wcslen(ACPage
)+1) * sizeof(WCHAR
));
429 if (!NT_SUCCESS(Status
))
431 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
437 RtlInitUnicodeString(&ValueName
, L
"OEMCP");
438 Status
= NtSetValueKey(KeyHandle
,
443 (wcslen(OEMCPage
)+1) * sizeof(WCHAR
));
444 if (!NT_SUCCESS(Status
))
446 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
452 RtlInitUnicodeString(&ValueName
, L
"MACCP");
453 Status
= NtSetValueKey(KeyHandle
,
458 (wcslen(MACCPage
)+1) * sizeof(WCHAR
));
459 if (!NT_SUCCESS(Status
))
461 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
473 AddFontsSettingsToRegistry(
474 IN
const MUI_SUBFONT
* MuiSubFonts
)
476 OBJECT_ATTRIBUTES ObjectAttributes
;
477 UNICODE_STRING KeyName
;
478 UNICODE_STRING ValueName
;
483 RtlInitUnicodeString(&KeyName
,
484 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
485 InitializeObjectAttributes(&ObjectAttributes
,
487 OBJ_CASE_INSENSITIVE
,
488 GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE
, NULL
),
490 Status
= NtOpenKey(&KeyHandle
,
493 if (!NT_SUCCESS(Status
))
495 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
499 while (MuiSubFonts
[uIndex
].FontName
!= NULL
)
501 RtlInitUnicodeString(&ValueName
, MuiSubFonts
[uIndex
].FontName
);
502 if (MuiSubFonts
[uIndex
].SubFontName
)
504 Status
= NtSetValueKey(KeyHandle
,
508 (PVOID
)MuiSubFonts
[uIndex
].SubFontName
,
509 (wcslen(MuiSubFonts
[uIndex
].SubFontName
)+1) * sizeof(WCHAR
));
510 if (!NT_SUCCESS(Status
))
512 DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status
, uIndex
);
519 Status
= NtDeleteValueKey(KeyHandle
, &ValueName
);
520 if (!NT_SUCCESS(Status
))
522 DPRINT1("NtDeleteValueKey failed, Status = %lx\n", Status
);
536 IN PCWSTR LanguageId
)
540 while (MUILanguageList
[lngIndex
].LanguageID
!= NULL
)
542 if (_wcsicmp(MUILanguageList
[lngIndex
].LanguageID
, LanguageId
) == 0)
544 if (AddCodepageToRegistry(MUILanguageList
[lngIndex
].ACPage
,
545 MUILanguageList
[lngIndex
].OEMCPage
,
546 MUILanguageList
[lngIndex
].MACCPage
) &&
547 AddFontsSettingsToRegistry(MUILanguageList
[lngIndex
].MuiSubFonts
))
563 #ifdef __REACTOS__ /* HACK */
565 DoRegistryFontFixup(PFONTSUBSTSETTINGS pSettings
, LANGID LangID
)
567 if (pSettings
->bFoundFontMINGLIU
)
568 AddFontsSettingsToRegistry(FontFixupMINGLIU
);
569 if (pSettings
->bFoundFontSIMSUN
)
570 AddFontsSettingsToRegistry(FontFixupSIMSUN
);
571 if (pSettings
->bFoundFontMSSONG
)
572 AddFontsSettingsToRegistry(FontFixupMSSONG
);
573 if (pSettings
->bFoundFontMSGOTHIC
)
574 AddFontsSettingsToRegistry(FontFixupMSGOTHIC
);
575 if (pSettings
->bFoundFontMSMINCHO
)
576 AddFontsSettingsToRegistry(FontFixupMSMINCHO
);
577 if (pSettings
->bFoundFontGULIM
)
578 AddFontsSettingsToRegistry(FontFixupGULIM
);
579 if (pSettings
->bFoundFontBATANG
)
580 AddFontsSettingsToRegistry(FontFixupBATANG
);
582 switch (PRIMARYLANGID(LangID
))
585 if (SUBLANGID(LangID
) == SUBLANG_CHINESE_SIMPLIFIED
)
587 if (pSettings
->bFoundFontSIMSUN
)
588 AddFontsSettingsToRegistry(SimplifiedChineseFontFixup
);
592 if (pSettings
->bFoundFontMINGLIU
)
593 AddFontsSettingsToRegistry(TraditionalChineseFontFixup
);
598 if (pSettings
->bFoundFontMSGOTHIC
)
599 AddFontsSettingsToRegistry(JapaneseFontFixup
);
603 if (pSettings
->bFoundFontBATANG
)
604 AddFontsSettingsToRegistry(KoreanFontFixup
);