2007-09-07 18:22:43 +00:00
|
|
|
/*
|
|
|
|
*
|
2007-10-20 11:08:23 +00:00
|
|
|
* PROJECT: input.dll
|
|
|
|
* FILE: dll/win32/input/add.c
|
|
|
|
* PURPOSE: input.dll
|
2008-03-11 15:52:27 +00:00
|
|
|
* PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
|
2008-04-20 07:34:59 +00:00
|
|
|
* Colin Finck
|
2007-09-07 18:22:43 +00:00
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 06-09-2007 Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
#include "input.h"
|
|
|
|
|
2008-03-11 15:52:27 +00:00
|
|
|
static HWND hLangList;
|
|
|
|
static HWND hLayoutList;
|
2007-10-06 11:47:06 +00:00
|
|
|
|
2008-03-11 15:52:27 +00:00
|
|
|
static VOID
|
|
|
|
SelectLayoutByLang(VOID)
|
2007-10-06 11:47:06 +00:00
|
|
|
{
|
2008-04-24 17:57:48 +00:00
|
|
|
TCHAR Layout[MAX_PATH], Lang[MAX_PATH], LangID[CCH_LAYOUT_ID + 1];
|
2008-03-12 13:50:30 +00:00
|
|
|
INT iIndex;
|
|
|
|
LCID Lcid;
|
2007-10-06 11:47:06 +00:00
|
|
|
|
2008-03-11 15:52:27 +00:00
|
|
|
iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0);
|
|
|
|
Lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0);
|
2007-10-06 11:47:06 +00:00
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
GetLocaleInfo(MAKELCID(Lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR));
|
2007-10-06 11:47:06 +00:00
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
wsprintf(LangID, _T("0000%s"), Lang);
|
2007-10-06 11:47:06 +00:00
|
|
|
|
2008-03-12 13:50:30 +00:00
|
|
|
if (GetLayoutName(LangID, Layout))
|
|
|
|
{
|
|
|
|
SendMessage(hLayoutList, CB_SELECTSTRING,
|
|
|
|
(WPARAM) -1, (LPARAM)Layout);
|
|
|
|
}
|
2007-10-06 11:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:23:23 +00:00
|
|
|
INT
|
2008-05-08 10:47:30 +00:00
|
|
|
GetLayoutCount(LPTSTR szLang)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
TCHAR szLayoutID[3 + 1], szPreload[CCH_LAYOUT_ID + 1], szLOLang[MAX_PATH];
|
|
|
|
DWORD dwIndex = 0, dwType, dwSize;
|
2008-12-07 21:52:22 +00:00
|
|
|
UINT Count = 0, i, j;
|
2008-05-08 10:47:30 +00:00
|
|
|
|
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
|
|
|
|
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwSize = sizeof(szLayoutID);
|
|
|
|
|
|
|
|
while (RegEnumValue(hKey, dwIndex, szLayoutID, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwSize = sizeof(szPreload);
|
|
|
|
RegQueryValueEx(hKey, szLayoutID, NULL, NULL, (LPBYTE)szPreload, &dwSize);
|
|
|
|
|
|
|
|
for (i = 4, j = 0; i < _tcslen(szPreload)+1; i++, j++)
|
|
|
|
szLOLang[j] = szPreload[i];
|
|
|
|
|
|
|
|
if (_tcscmp(szLOLang, szLang) == 0) Count += 1;
|
|
|
|
|
|
|
|
dwSize = sizeof(szLayoutID);
|
|
|
|
dwIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
2008-03-11 15:52:27 +00:00
|
|
|
static VOID
|
|
|
|
AddNewLayout(HWND hwndDlg)
|
2007-10-06 11:47:06 +00:00
|
|
|
{
|
2008-05-08 10:47:30 +00:00
|
|
|
TCHAR NewLayout[CCH_ULONG_DEC + 1], Lang[MAX_PATH],
|
|
|
|
LangID[CCH_LAYOUT_ID + 1], Layout[MAX_PATH],
|
2008-05-14 15:51:53 +00:00
|
|
|
SubPath[CCH_LAYOUT_ID + 1], szMessage[MAX_PATH];
|
2008-05-08 10:47:30 +00:00
|
|
|
INT iLayout, iLang;
|
|
|
|
HKEY hKey, hSubKey;
|
2008-04-20 07:57:28 +00:00
|
|
|
DWORD cValues;
|
|
|
|
PTSTR pts;
|
2008-05-08 10:47:30 +00:00
|
|
|
LCID lcid;
|
2008-04-20 07:57:28 +00:00
|
|
|
|
|
|
|
iLayout = SendMessage(hLayoutList, CB_GETCURSEL, 0, 0);
|
|
|
|
if (iLayout == CB_ERR) return;
|
|
|
|
|
2008-05-13 20:23:23 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
|
2008-04-20 07:57:28 +00:00
|
|
|
{
|
|
|
|
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &cValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
2008-04-24 17:57:48 +00:00
|
|
|
_ultot(cValues + 1, NewLayout, 10);
|
2008-04-20 07:57:28 +00:00
|
|
|
|
2008-05-08 10:47:30 +00:00
|
|
|
iLang = SendMessage(hLangList, CB_GETCURSEL, 0, 0);
|
|
|
|
lcid = SendMessage(hLangList, CB_GETITEMDATA, iLang, 0);
|
2008-05-14 15:51:53 +00:00
|
|
|
pts = (PTSTR) SendMessage(hLayoutList, CB_GETITEMDATA, iLayout, 0);
|
2008-05-08 10:47:30 +00:00
|
|
|
|
|
|
|
GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR));
|
|
|
|
wsprintf(LangID, _T("0000%s"), Lang);
|
|
|
|
|
2008-05-14 15:51:53 +00:00
|
|
|
if (IsLayoutExists(pts, LangID))
|
|
|
|
{
|
|
|
|
LoadString(hApplet, IDS_LAYOUT_EXISTS2, szMessage, sizeof(szMessage) / sizeof(TCHAR));
|
|
|
|
MessageBox(hwndDlg, szMessage, NULL, MB_OK | MB_ICONINFORMATION);
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-18 11:20:32 +00:00
|
|
|
if (_tcscmp(LangID, pts) != 0)
|
2008-05-08 10:47:30 +00:00
|
|
|
{
|
2009-01-18 11:20:32 +00:00
|
|
|
if (!GetLayoutName(pts, Layout))
|
2008-05-08 10:47:30 +00:00
|
|
|
{
|
2009-01-18 11:20:32 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!GetLayoutName(LangID, Layout))
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SendMessage(hLayoutList, CB_SELECTSTRING, (WPARAM) -1, (LPARAM)Layout) != CB_ERR)
|
|
|
|
{
|
|
|
|
if (GetLayoutCount(Lang) >= 1)
|
|
|
|
{
|
|
|
|
wsprintf(SubPath, _T("d%03d%s"), GetLayoutCount(Lang), Lang);
|
|
|
|
}
|
|
|
|
else if ((_tcscmp(LangID, pts) != 0) && (GetLayoutCount(Lang) == 0))
|
|
|
|
{
|
|
|
|
wsprintf(SubPath, _T("d%03d%s"), 0, Lang);
|
2008-05-08 10:47:30 +00:00
|
|
|
}
|
|
|
|
else SubPath[0] = '\0';
|
|
|
|
}
|
2009-01-18 11:20:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-08 10:47:30 +00:00
|
|
|
|
|
|
|
if (_tcslen(SubPath) != 0)
|
|
|
|
{
|
|
|
|
if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, NULL,
|
2008-05-13 20:23:23 +00:00
|
|
|
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
|
2008-05-08 10:47:30 +00:00
|
|
|
NULL, &hSubKey, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (RegSetValueEx(hSubKey, SubPath, 0, REG_SZ, (LPBYTE)pts,
|
|
|
|
(DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
2008-05-13 20:23:23 +00:00
|
|
|
lstrcpy(pts, SubPath);
|
2008-05-08 10:47:30 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 07:57:28 +00:00
|
|
|
if (RegSetValueEx(hKey,
|
|
|
|
NewLayout,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPBYTE)pts,
|
2008-04-24 17:57:48 +00:00
|
|
|
(DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) == ERROR_SUCCESS)
|
2008-04-20 07:57:28 +00:00
|
|
|
{
|
|
|
|
UpdateLayoutsList();
|
|
|
|
}
|
|
|
|
}
|
2008-05-08 10:47:30 +00:00
|
|
|
RegCloseKey(hKey);
|
2008-04-20 07:57:28 +00:00
|
|
|
}
|
2007-10-06 11:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2008-05-13 20:23:23 +00:00
|
|
|
CreateKeyboardLayoutList(HWND hItemsList)
|
2008-03-11 15:52:27 +00:00
|
|
|
{
|
2008-05-02 06:41:59 +00:00
|
|
|
HKEY hKey;
|
2008-04-24 17:57:48 +00:00
|
|
|
PTSTR pstrLayoutID;
|
|
|
|
TCHAR szLayoutID[CCH_LAYOUT_ID + 1], KeyName[MAX_PATH];
|
2008-03-12 13:50:30 +00:00
|
|
|
DWORD dwIndex = 0;
|
2008-04-24 17:57:48 +00:00
|
|
|
DWORD dwSize;
|
2008-03-12 13:50:30 +00:00
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Keyboard Layouts"), 0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS)
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
2008-04-24 17:57:48 +00:00
|
|
|
dwSize = sizeof(szLayoutID) / sizeof(TCHAR);
|
2008-04-20 07:34:59 +00:00
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
while (RegEnumKeyEx(hKey, dwIndex, szLayoutID, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
2009-08-02 17:38:27 +00:00
|
|
|
INT iIndex;
|
|
|
|
|
2008-05-02 06:41:59 +00:00
|
|
|
GetLayoutName(szLayoutID, KeyName);
|
2008-03-12 13:50:30 +00:00
|
|
|
|
2009-08-02 17:38:27 +00:00
|
|
|
iIndex = (INT) SendMessage(hItemsList, CB_ADDSTRING, 0, (LPARAM)KeyName);
|
2008-03-12 13:50:30 +00:00
|
|
|
|
2008-05-02 06:41:59 +00:00
|
|
|
pstrLayoutID = (PTSTR)HeapAlloc(hProcessHeap, 0, sizeof(szLayoutID));
|
|
|
|
lstrcpy(pstrLayoutID, szLayoutID);
|
2008-05-13 20:23:23 +00:00
|
|
|
SendMessage(hItemsList, CB_SETITEMDATA, iIndex, (LPARAM)pstrLayoutID);
|
2008-03-12 13:50:30 +00:00
|
|
|
|
2008-05-02 06:41:59 +00:00
|
|
|
// FIXME!
|
|
|
|
if (_tcscmp(szLayoutID, _T("00000409")) == 0)
|
|
|
|
{
|
2008-05-13 20:23:23 +00:00
|
|
|
SendMessage(hItemsList, CB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0);
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
2008-04-20 07:34:59 +00:00
|
|
|
|
2008-05-02 06:41:59 +00:00
|
|
|
dwIndex++;
|
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
dwSize = sizeof(szLayoutID) / sizeof(TCHAR);
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 17:57:48 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2008-03-11 15:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Language enumerate procedure */
|
|
|
|
static BOOL CALLBACK
|
|
|
|
LanguagesEnumProc(LPTSTR lpLanguage)
|
2007-10-06 11:47:06 +00:00
|
|
|
{
|
2008-03-11 15:52:27 +00:00
|
|
|
LCID Lcid;
|
|
|
|
TCHAR Lang[1024];
|
|
|
|
INT Index;
|
|
|
|
|
|
|
|
Lcid = _tcstoul(lpLanguage, NULL, 16);
|
|
|
|
|
|
|
|
GetLocaleInfo(Lcid, LOCALE_SLANGUAGE, Lang, sizeof(Lang));
|
|
|
|
Index = (INT)SendMessage(hLangList, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)Lang);
|
|
|
|
|
|
|
|
SendMessage(hLangList, CB_SETITEMDATA,
|
|
|
|
Index, (LPARAM)Lcid);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2008-03-12 13:50:30 +00:00
|
|
|
// FIXME!
|
|
|
|
if (Lcid == 0x0409)
|
|
|
|
{
|
|
|
|
SendMessage(hLangList, CB_SELECTSTRING,
|
2008-03-11 15:52:27 +00:00
|
|
|
(WPARAM) -1, (LPARAM)Lang);
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
2008-03-11 15:52:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2007-10-06 11:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-07 18:22:43 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
AddDlgProc(HWND hDlg,
|
2007-10-20 11:08:23 +00:00
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2007-09-07 18:22:43 +00:00
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(lParam);
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
|
|
|
hLangList = GetDlgItem(hDlg, IDC_INPUT_LANG_COMBO);
|
|
|
|
hLayoutList = GetDlgItem(hDlg, IDC_KEYBOARD_LO_COMBO);
|
2008-03-11 15:52:27 +00:00
|
|
|
EnumSystemLocales(LanguagesEnumProc, LCID_INSTALLED);
|
2008-05-13 20:23:23 +00:00
|
|
|
CreateKeyboardLayoutList(hLayoutList);
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
2008-03-11 15:52:27 +00:00
|
|
|
break;
|
2007-10-20 11:08:23 +00:00
|
|
|
|
2007-09-07 18:22:43 +00:00
|
|
|
case WM_COMMAND:
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
2007-10-20 11:08:23 +00:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2008-03-11 15:52:27 +00:00
|
|
|
case IDC_INPUT_LANG_COMBO:
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
2007-10-20 11:08:23 +00:00
|
|
|
if (HIWORD(wParam) == CBN_SELCHANGE)
|
|
|
|
{
|
2008-03-11 15:52:27 +00:00
|
|
|
SelectLayoutByLang();
|
2007-10-20 11:08:23 +00:00
|
|
|
}
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
2008-03-11 15:52:27 +00:00
|
|
|
break;
|
2007-10-20 11:08:23 +00:00
|
|
|
|
|
|
|
case IDOK:
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
|
|
|
AddNewLayout(hDlg);
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
}
|
2008-03-11 15:52:27 +00:00
|
|
|
break;
|
2007-10-20 11:08:23 +00:00
|
|
|
|
|
|
|
case IDCANCEL:
|
2008-03-12 13:50:30 +00:00
|
|
|
{
|
2007-10-20 11:08:23 +00:00
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
2007-10-20 11:08:23 +00:00
|
|
|
}
|
2008-03-12 13:50:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-04-20 07:34:59 +00:00
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
INT iCount;
|
|
|
|
|
|
|
|
for(iCount = SendMessage(hLayoutList, CB_GETCOUNT, 0, 0); --iCount >= 0;)
|
|
|
|
HeapFree(hProcessHeap, 0, (LPVOID)SendMessage(hLayoutList, CB_GETITEMDATA, iCount, 0));
|
|
|
|
}
|
|
|
|
break;
|
2007-09-07 18:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|