2004-05-30 14:54:02 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-05-30 14:54:02 +00:00
|
|
|
*/
|
2005-09-19 08:11:43 +00:00
|
|
|
/* COPYRIGHT: See COPYING in the top level directory
|
2004-05-30 14:54:02 +00:00
|
|
|
* PROJECT: ReactOS text-mode setup
|
2015-09-13 16:40:36 +00:00
|
|
|
* FILE: base/setup/usetup/settings.c
|
2004-05-30 14:54:02 +00:00
|
|
|
* PURPOSE: Device settings support functions
|
2018-05-27 19:33:07 +00:00
|
|
|
* PROGRAMMERS: Colin Finck
|
2004-05-30 14:54:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2006-08-31 09:13:03 +00:00
|
|
|
#include "usetup.h"
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2010-06-07 21:38:49 +00:00
|
|
|
#define NDEBUG
|
2004-05-30 14:54:02 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
2014-05-12 16:14:19 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
|
|
|
ULONG DefaultLanguageIndex = 0;
|
|
|
|
|
2004-05-30 14:54:02 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2008-06-02 15:34:57 +00:00
|
|
|
ULONG
|
|
|
|
GetDefaultLanguageIndex(VOID)
|
|
|
|
{
|
|
|
|
return DefaultLanguageIndex;
|
|
|
|
}
|
|
|
|
|
2017-08-28 14:01:30 +00:00
|
|
|
typedef struct _LANG_ENTRY_PARAM
|
|
|
|
{
|
|
|
|
ULONG uIndex;
|
|
|
|
PWCHAR DefaultLanguage;
|
|
|
|
} LANG_ENTRY_PARAM, *PLANG_ENTRY_PARAM;
|
|
|
|
|
|
|
|
static UCHAR
|
|
|
|
NTAPI
|
|
|
|
ProcessLangEntry(
|
|
|
|
IN PWCHAR KeyName,
|
|
|
|
IN PWCHAR KeyValue,
|
|
|
|
IN PCHAR DisplayText,
|
|
|
|
IN SIZE_T DisplayTextSize,
|
|
|
|
OUT PVOID* UserData,
|
|
|
|
OUT PBOOLEAN Current,
|
|
|
|
IN PVOID Parameter OPTIONAL)
|
|
|
|
{
|
|
|
|
PLANG_ENTRY_PARAM LangEntryParam = (PLANG_ENTRY_PARAM)Parameter;
|
|
|
|
|
|
|
|
if (!IsLanguageAvailable(KeyName))
|
|
|
|
{
|
|
|
|
/* The specified language is unavailable, skip the entry */
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
*UserData = RtlAllocateHeap(ProcessHeap, 0,
|
|
|
|
(wcslen(KeyName) + 1) * sizeof(WCHAR));
|
|
|
|
if (*UserData == NULL)
|
|
|
|
{
|
|
|
|
/* Failure, stop enumeration */
|
|
|
|
DPRINT1("RtlAllocateHeap() failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcscpy((PWCHAR)*UserData, KeyName);
|
|
|
|
sprintf(DisplayText, "%S", KeyValue);
|
|
|
|
|
|
|
|
*Current = FALSE;
|
|
|
|
|
|
|
|
if (!_wcsicmp(KeyName, LangEntryParam->DefaultLanguage))
|
|
|
|
DefaultLanguageIndex = LangEntryParam->uIndex;
|
|
|
|
|
|
|
|
LangEntryParam->uIndex++;
|
|
|
|
|
|
|
|
/* Add the entry */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-02 15:34:57 +00:00
|
|
|
PGENERIC_LIST
|
2014-05-12 16:14:19 +00:00
|
|
|
CreateLanguageList(
|
|
|
|
HINF InfFile,
|
2015-03-29 11:29:02 +00:00
|
|
|
WCHAR *DefaultLanguage)
|
2008-01-07 17:22:05 +00:00
|
|
|
{
|
|
|
|
PGENERIC_LIST List;
|
|
|
|
INFCONTEXT Context;
|
|
|
|
PWCHAR KeyValue;
|
2017-08-28 14:01:30 +00:00
|
|
|
|
|
|
|
LANG_ENTRY_PARAM LangEntryParam;
|
|
|
|
|
|
|
|
LangEntryParam.uIndex = 0;
|
|
|
|
LangEntryParam.DefaultLanguage = DefaultLanguage;
|
2008-01-07 17:22:05 +00:00
|
|
|
|
|
|
|
/* Get default language id */
|
2017-08-28 13:50:40 +00:00
|
|
|
if (!SetupFindFirstLineW(InfFile, L"NLS", L"DefaultLanguage", &Context))
|
2008-01-07 17:22:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-08-28 13:50:40 +00:00
|
|
|
if (!INF_GetData(&Context, NULL, &KeyValue))
|
2008-01-07 17:22:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wcscpy(DefaultLanguage, KeyValue);
|
2007-12-25 20:24:19 +00:00
|
|
|
SelectedLanguageId = KeyValue;
|
2007-12-23 20:29:52 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
List = CreateGenericList();
|
|
|
|
if (List == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2017-08-28 14:01:30 +00:00
|
|
|
if (AddEntriesFromInfSection(List,
|
|
|
|
InfFile,
|
|
|
|
L"Language",
|
|
|
|
&Context,
|
|
|
|
ProcessLangEntry,
|
|
|
|
&LangEntryParam) == -1)
|
2008-01-07 17:22:05 +00:00
|
|
|
{
|
2017-08-28 14:01:30 +00:00
|
|
|
DestroyGenericList(List, TRUE);
|
2015-03-29 11:29:02 +00:00
|
|
|
return NULL;
|
2008-01-07 17:22:05 +00:00
|
|
|
}
|
|
|
|
|
2012-02-27 22:46:20 +00:00
|
|
|
/* Only one language available, make it the default one */
|
2017-08-28 14:01:30 +00:00
|
|
|
if (LangEntryParam.uIndex == 1)
|
2012-02-27 22:46:20 +00:00
|
|
|
{
|
|
|
|
DefaultLanguageIndex = 0;
|
2017-08-28 14:01:30 +00:00
|
|
|
wcscpy(DefaultLanguage,
|
|
|
|
(PWSTR)GetListEntryUserData(GetFirstListEntry(List)));
|
2012-02-27 22:46:20 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
return List;
|
2007-12-23 20:29:52 +00:00
|
|
|
}
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2017-08-28 14:46:49 +00:00
|
|
|
|
2004-05-30 14:54:02 +00:00
|
|
|
PGENERIC_LIST
|
2014-05-12 16:14:19 +00:00
|
|
|
CreateKeyboardLayoutList(
|
|
|
|
HINF InfFile,
|
|
|
|
WCHAR *DefaultKBLayout)
|
2004-05-30 14:54:02 +00:00
|
|
|
{
|
2008-01-07 17:22:05 +00:00
|
|
|
PGENERIC_LIST List;
|
|
|
|
INFCONTEXT Context;
|
|
|
|
PWCHAR KeyValue;
|
2008-06-01 12:52:18 +00:00
|
|
|
const MUI_LAYOUTS * LayoutsList;
|
|
|
|
ULONG uIndex = 0;
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
/* Get default layout id */
|
2017-08-28 13:50:40 +00:00
|
|
|
if (!SetupFindFirstLineW(InfFile, L"NLS", L"DefaultLayout", &Context))
|
2008-01-07 17:22:05 +00:00
|
|
|
return NULL;
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2017-08-28 13:50:40 +00:00
|
|
|
if (!INF_GetData(&Context, NULL, &KeyValue))
|
2008-01-07 17:22:05 +00:00
|
|
|
return NULL;
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
wcscpy(DefaultKBLayout, KeyValue);
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
List = CreateGenericList();
|
|
|
|
if (List == NULL)
|
|
|
|
return NULL;
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
LayoutsList = MUIGetLayoutsList();
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
do
|
|
|
|
{
|
2017-08-28 14:01:30 +00:00
|
|
|
// NOTE: See https://svn.reactos.org/svn/reactos?view=revision&revision=68354
|
|
|
|
if (AddEntriesFromInfSection(List,
|
|
|
|
InfFile,
|
|
|
|
L"KeyboardLayout",
|
|
|
|
&Context,
|
|
|
|
DefaultProcessEntry,
|
|
|
|
DefaultKBLayout) == -1)
|
2008-01-07 17:22:05 +00:00
|
|
|
{
|
2017-08-28 14:01:30 +00:00
|
|
|
DestroyGenericList(List, TRUE);
|
2008-06-01 12:52:18 +00:00
|
|
|
return NULL;
|
2008-01-07 17:22:05 +00:00
|
|
|
}
|
2004-05-30 14:54:02 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
uIndex++;
|
|
|
|
|
|
|
|
} while (LayoutsList[uIndex].LangID != NULL);
|
2004-06-02 22:18:06 +00:00
|
|
|
|
2017-08-28 14:01:30 +00:00
|
|
|
/* Check whether some keyboard layouts have been found */
|
2009-04-20 03:16:12 +00:00
|
|
|
/* FIXME: Handle this case */
|
2017-08-28 14:01:30 +00:00
|
|
|
if (GetNumberOfListEntries(List) == 0)
|
2009-04-20 03:16:12 +00:00
|
|
|
{
|
|
|
|
DPRINT1("No keyboard layouts have been found\n");
|
2017-08-28 14:01:30 +00:00
|
|
|
DestroyGenericList(List, TRUE);
|
2009-04-20 03:16:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
return List;
|
|
|
|
}
|
2004-06-02 22:18:06 +00:00
|
|
|
|
2014-05-12 16:14:19 +00:00
|
|
|
|
2008-01-07 17:22:05 +00:00
|
|
|
BOOLEAN
|
2014-05-12 16:14:19 +00:00
|
|
|
ProcessKeyboardLayoutRegistry(
|
|
|
|
PGENERIC_LIST List)
|
2008-01-07 17:22:05 +00:00
|
|
|
{
|
|
|
|
PGENERIC_LIST_ENTRY Entry;
|
2008-06-01 12:52:18 +00:00
|
|
|
PWCHAR LayoutId;
|
|
|
|
const MUI_LAYOUTS * LayoutsList;
|
|
|
|
MUI_LAYOUTS NewLayoutsList[20];
|
2008-12-18 12:26:47 +00:00
|
|
|
ULONG uIndex;
|
2008-06-01 12:52:18 +00:00
|
|
|
ULONG uOldPos = 0;
|
2008-01-07 17:22:05 +00:00
|
|
|
|
2008-05-11 21:17:57 +00:00
|
|
|
Entry = GetCurrentListEntry(List);
|
2008-01-07 17:22:05 +00:00
|
|
|
if (Entry == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
LayoutId = (PWCHAR)GetListEntryUserData(Entry);
|
|
|
|
if (LayoutId == NULL)
|
2008-01-07 17:22:05 +00:00
|
|
|
return FALSE;
|
2008-04-28 14:04:22 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
LayoutsList = MUIGetLayoutsList();
|
2008-04-28 14:04:22 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
if (_wcsicmp(LayoutsList[0].LayoutID, LayoutId) != 0)
|
2008-01-07 17:22:05 +00:00
|
|
|
{
|
2008-12-18 12:26:47 +00:00
|
|
|
for (uIndex = 1; LayoutsList[uIndex].LangID != NULL; uIndex++)
|
2008-04-28 14:04:22 +00:00
|
|
|
{
|
2008-06-01 12:52:18 +00:00
|
|
|
if (_wcsicmp(LayoutsList[uIndex].LayoutID, LayoutId) == 0)
|
|
|
|
{
|
|
|
|
uOldPos = uIndex;
|
2008-12-18 12:26:47 +00:00
|
|
|
continue;
|
2008-06-01 12:52:18 +00:00
|
|
|
}
|
2008-04-28 14:04:22 +00:00
|
|
|
|
2008-12-18 12:26:47 +00:00
|
|
|
NewLayoutsList[uIndex].LangID = LayoutsList[uIndex].LangID;
|
|
|
|
NewLayoutsList[uIndex].LayoutID = LayoutsList[uIndex].LayoutID;
|
|
|
|
}
|
2008-04-28 14:04:22 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
NewLayoutsList[uIndex].LangID = NULL;
|
|
|
|
NewLayoutsList[uIndex].LayoutID = NULL;
|
|
|
|
NewLayoutsList[uOldPos].LangID = LayoutsList[0].LangID;
|
|
|
|
NewLayoutsList[uOldPos].LayoutID = LayoutsList[0].LayoutID;
|
|
|
|
NewLayoutsList[0].LangID = LayoutsList[uOldPos].LangID;
|
|
|
|
NewLayoutsList[0].LayoutID = LayoutsList[uOldPos].LayoutID;
|
2008-01-07 17:22:05 +00:00
|
|
|
|
2008-06-01 12:52:18 +00:00
|
|
|
return AddKbLayoutsToRegistry(NewLayoutsList);
|
|
|
|
}
|
2008-01-07 17:22:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2004-05-30 14:54:02 +00:00
|
|
|
}
|
|
|
|
|
2004-06-07 12:24:00 +00:00
|
|
|
#if 0
|
2004-05-30 14:54:02 +00:00
|
|
|
BOOLEAN
|
2014-05-12 16:14:19 +00:00
|
|
|
ProcessKeyboardLayoutFiles(
|
|
|
|
PGENERIC_LIST List)
|
2004-05-30 14:54:02 +00:00
|
|
|
{
|
2008-01-07 17:22:05 +00:00
|
|
|
return TRUE;
|
2004-05-30 14:54:02 +00:00
|
|
|
}
|
2004-06-07 12:24:00 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-30 14:54:02 +00:00
|
|
|
/* EOF */
|