Skip to content

Commit b6b0074

Browse files
committed
[INPUT]
- Reorder keyboard layouts in the registry after one was deleted - Fixes changing keyboard layouts from regional options See issue reactos#3317 for more details. svn path=/trunk/; revision=47147
1 parent 9cb27f4 commit b6b0074

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

reactos/dll/cpl/input/settings.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* PURPOSE: input.dll
66
* PROGRAMMER: Dmitry Chapyshev ([email protected])
77
* Colin Finck
8+
* Gregor Schneider
89
* UPDATE HISTORY:
910
* 06-09-2007 Created
1011
*/
@@ -376,6 +377,59 @@ UpdateLayoutsList(VOID)
376377
(VOID) ListView_SetImageList(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), hImgList, LVSIL_SMALL);
377378
}
378379

380+
typedef struct _REG_KB_ENTRY_
381+
{
382+
TCHAR szLayoutID[3];
383+
DWORD dwType;
384+
TCHAR szData[CCH_LAYOUT_ID + 1];
385+
DWORD dwDataSize;
386+
} REG_KB_ENTRY;
387+
388+
/* Layouts were deleted so we have to order the existing ones */
389+
static VOID
390+
UpdateRegValueNames(HKEY hKey)
391+
{
392+
DWORD dwIndex = 0, dwGot = 0, dwLayoutSize;
393+
DWORD dwSets = 5;
394+
REG_KB_ENTRY* data = HeapAlloc(GetProcessHeap(), 0, dwSets * sizeof(REG_KB_ENTRY));
395+
396+
/* Get all existing entries and delete them */
397+
dwLayoutSize = sizeof(data[0].szLayoutID);
398+
while (RegEnumValue(hKey,
399+
dwIndex,
400+
data[dwGot].szLayoutID,
401+
&dwLayoutSize,
402+
NULL,
403+
&data[dwGot].dwType,
404+
(PBYTE)data[dwGot].szData,
405+
&data[dwGot].dwDataSize) != ERROR_NO_MORE_ITEMS)
406+
{
407+
if (_tcslen(data[dwGot].szLayoutID) <= 2 && _tcslen(data[dwGot].szData) == CCH_LAYOUT_ID)
408+
{
409+
RegDeleteValue(hKey, data[dwGot].szLayoutID);
410+
dwGot++;
411+
if (dwGot == dwSets)
412+
{
413+
dwSets += 5;
414+
data = HeapReAlloc(GetProcessHeap(), 0, data, dwSets * sizeof(REG_KB_ENTRY));
415+
}
416+
}
417+
dwIndex++;
418+
dwLayoutSize = sizeof(data[0].szLayoutID);
419+
}
420+
421+
/* Set all entries with an updated value name */
422+
for (dwIndex = 0; dwIndex < dwGot; dwIndex++)
423+
{
424+
TCHAR szNewLayoutID[3];
425+
426+
_stprintf(szNewLayoutID, TEXT("%u"), dwIndex + 1);
427+
RegSetValueEx(hKey, szNewLayoutID, 0, data[dwIndex].dwType,
428+
(PBYTE)data[dwIndex].szData, data[dwIndex].dwDataSize);
429+
}
430+
HeapFree(GetProcessHeap(), 0, data);
431+
}
432+
379433
static VOID
380434
DeleteLayout(VOID)
381435
{
@@ -430,6 +484,7 @@ DeleteLayout(VOID)
430484
if (RegDeleteValue(hKey, szLayoutNum) == ERROR_SUCCESS)
431485
{
432486
UpdateLayoutsList();
487+
UpdateRegValueNames(hKey);
433488
}
434489
}
435490
RegCloseKey(hKey);

0 commit comments

Comments
 (0)