2016-08-07 23:28:50 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: input.dll
|
|
|
|
* FILE: dll/cpl/input/settings_page.c
|
|
|
|
* PURPOSE: input.dll
|
2017-11-13 01:36:52 +00:00
|
|
|
* PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
|
|
|
|
* Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
2016-08-07 23:28:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
#include "layout_list.h"
|
|
|
|
#include "locale_list.h"
|
2016-08-08 20:30:36 +00:00
|
|
|
#include "input_list.h"
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static INT s_nAliveLeafCount = 0;
|
|
|
|
static INT s_nRootCount = 0;
|
|
|
|
static INT s_iKeyboardImage = -1;
|
|
|
|
static INT s_iDotImage = -1;
|
|
|
|
|
2016-08-07 23:28:50 +00:00
|
|
|
static HICON
|
2022-09-28 22:31:43 +00:00
|
|
|
CreateLayoutIcon(LANGID LangID)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
WCHAR szBuf[4];
|
2022-09-29 02:06:17 +00:00
|
|
|
HDC hdcScreen, hdc;
|
2022-09-28 22:31:43 +00:00
|
|
|
HBITMAP hbmColor, hbmMono, hBmpOld;
|
2022-09-29 02:06:17 +00:00
|
|
|
HFONT hFont, hFontOld;
|
|
|
|
LOGFONTW lf;
|
2022-09-28 22:31:43 +00:00
|
|
|
RECT rect;
|
|
|
|
ICONINFO IconInfo;
|
|
|
|
HICON hIcon;
|
|
|
|
INT cxIcon = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
INT cyIcon = GetSystemMetrics(SM_CYSMICON);
|
|
|
|
|
|
|
|
/* Getting "EN", "FR", etc. from English, French, ... */
|
2022-09-29 02:06:17 +00:00
|
|
|
if (GetLocaleInfoW(LangID,
|
|
|
|
LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE,
|
|
|
|
szBuf,
|
|
|
|
ARRAYSIZE(szBuf)) == 0)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-29 02:06:17 +00:00
|
|
|
szBuf[0] = szBuf[1] = L'?';
|
2022-09-28 22:31:43 +00:00
|
|
|
}
|
|
|
|
szBuf[2] = UNICODE_NULL; /* Truncate the identifier to two characters: "ENG" --> "EN" etc. */
|
|
|
|
|
|
|
|
/* Create hdc, hbmColor and hbmMono */
|
2022-09-29 02:06:17 +00:00
|
|
|
hdcScreen = GetDC(NULL);
|
|
|
|
hdc = CreateCompatibleDC(hdcScreen);
|
|
|
|
hbmColor = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
|
|
|
|
ReleaseDC(NULL, hdcScreen);
|
2022-09-28 22:31:43 +00:00
|
|
|
hbmMono = CreateBitmap(cxIcon, cyIcon, 1, 1, NULL);
|
|
|
|
|
|
|
|
/* Checking NULL */
|
2022-09-29 02:06:17 +00:00
|
|
|
if (!hdc || !hbmColor || !hbmMono)
|
2022-09-28 22:31:43 +00:00
|
|
|
{
|
|
|
|
if (hbmMono)
|
|
|
|
DeleteObject(hbmMono);
|
2022-09-29 02:06:17 +00:00
|
|
|
if (hbmColor)
|
|
|
|
DeleteObject(hbmColor);
|
|
|
|
if (hdc)
|
|
|
|
DeleteDC(hdc);
|
2022-09-28 22:31:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-29 02:06:17 +00:00
|
|
|
/* Create a font */
|
|
|
|
hFont = NULL;
|
|
|
|
if (SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
|
|
|
|
{
|
|
|
|
/* Override the current size with something manageable */
|
|
|
|
lf.lfHeight = -11;
|
|
|
|
lf.lfWidth = 0;
|
|
|
|
hFont = CreateFontIndirectW(&lf);
|
|
|
|
}
|
|
|
|
if (!hFont)
|
|
|
|
hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
SetRect(&rect, 0, 0, cxIcon, cyIcon);
|
|
|
|
|
|
|
|
/* Draw hbmColor */
|
|
|
|
hBmpOld = SelectObject(hdc, hbmColor);
|
|
|
|
SetDCBrushColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
|
|
|
|
FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH));
|
|
|
|
hFontOld = SelectObject(hdc, hFont);
|
|
|
|
SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
|
|
|
|
SetBkMode(hdc, TRANSPARENT);
|
|
|
|
DrawTextW(hdc, szBuf, 2, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
|
|
|
SelectObject(hdc, hFontOld);
|
|
|
|
|
2022-09-29 02:06:17 +00:00
|
|
|
/* Fill hbmMono with black */
|
|
|
|
SelectObject(hdc, hbmMono);
|
2022-09-28 22:31:43 +00:00
|
|
|
PatBlt(hdc, 0, 0, cxIcon, cyIcon, BLACKNESS);
|
|
|
|
SelectObject(hdc, hBmpOld);
|
|
|
|
|
|
|
|
/* Create an icon from hbmColor and hbmMono */
|
2022-09-29 02:06:17 +00:00
|
|
|
IconInfo.fIcon = TRUE;
|
|
|
|
IconInfo.xHotspot = IconInfo.yHotspot = 0;
|
2022-09-28 22:31:43 +00:00
|
|
|
IconInfo.hbmColor = hbmColor;
|
|
|
|
IconInfo.hbmMask = hbmMono;
|
|
|
|
hIcon = CreateIconIndirect(&IconInfo);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
DeleteObject(hFont);
|
2022-09-29 02:06:17 +00:00
|
|
|
DeleteObject(hbmMono);
|
|
|
|
DeleteObject(hbmColor);
|
2022-09-28 22:31:43 +00:00
|
|
|
DeleteDC(hdc);
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
return hIcon;
|
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static VOID InitDefaultLangComboBox(HWND hwndCombo)
|
|
|
|
{
|
|
|
|
WCHAR szText[256];
|
|
|
|
INPUT_LIST_NODE *pNode;
|
|
|
|
INT iIndex, nCount, iDefault = (INT)SendMessageW(hwndCombo, CB_GETCURSEL, 0, 0);
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
SendMessageW(hwndCombo, CB_RESETCONTENT, 0, 0);
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
for (pNode = InputList_GetFirst(); pNode != NULL; pNode = pNode->pNext)
|
|
|
|
{
|
|
|
|
if (pNode->wFlags & INPUT_LIST_NODE_FLAG_DELETED)
|
|
|
|
continue;
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
StringCchPrintfW(szText, _countof(szText), L"%s - %s",
|
|
|
|
pNode->pLocale->pszName, pNode->pLayout->pszName);
|
|
|
|
iIndex = (INT)SendMessageW(hwndCombo, CB_ADDSTRING, 0, (LPARAM)szText);
|
|
|
|
SendMessageW(hwndCombo, CB_SETITEMDATA, iIndex, (LPARAM)pNode);
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
if (pNode->wFlags & INPUT_LIST_NODE_FLAG_DEFAULT)
|
|
|
|
iDefault = iIndex;
|
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
nCount = (INT)SendMessageW(hwndCombo, CB_GETCOUNT, 0, 0);
|
|
|
|
if (iDefault >= nCount)
|
|
|
|
SendMessageW(hwndCombo, CB_SETCURSEL, nCount - 1, 0);
|
|
|
|
else
|
|
|
|
SendMessageW(hwndCombo, CB_SETCURSEL, iDefault, 0);
|
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static VOID
|
|
|
|
SetControlsState(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST);
|
|
|
|
HWND hwndCombo = GetDlgItem(hwndDlg, IDC_DEFAULT_LANGUAGE);
|
|
|
|
BOOL bIsLeaf, bCanRemove, bCanProp;
|
|
|
|
HTREEITEM hSelected = TreeView_GetSelection(hwndList);
|
|
|
|
TV_ITEM item = { TVIF_PARAM | TVIF_HANDLE };
|
|
|
|
item.hItem = hSelected;
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
bIsLeaf = (hSelected && TreeView_GetItem(hwndList, &item) && HIWORD(item.lParam));
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
bCanRemove = (bIsLeaf && (s_nAliveLeafCount > 1)) || (s_nRootCount > 1);
|
|
|
|
bCanProp = bIsLeaf;
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVE_BUTTON), bCanRemove);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_PROP_BUTTON), bCanProp);
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
InitDefaultLangComboBox(hwndCombo);
|
|
|
|
}
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static BOOL CALLBACK
|
|
|
|
EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam)
|
|
|
|
{
|
|
|
|
HICON* phIconSm = (HICON*)lParam;
|
|
|
|
if (*phIconSm)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*phIconSm = (HICON)LoadImageW(hModule, lpszName, IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON),
|
|
|
|
GetSystemMetrics(SM_CYSMICON),
|
|
|
|
0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static HICON LoadIMEIcon(LPCTSTR pszImeFile)
|
|
|
|
{
|
|
|
|
WCHAR szSysDir[MAX_PATH], szPath[MAX_PATH];
|
|
|
|
HINSTANCE hImeInst;
|
|
|
|
HICON hIconSm = NULL;
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
GetSystemDirectoryW(szSysDir, _countof(szSysDir));
|
|
|
|
StringCchPrintfW(szPath, _countof(szPath), L"%s\\%s", szSysDir, pszImeFile);
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
hImeInst = LoadLibraryExW(szPath, NULL, DONT_RESOLVE_DLL_REFERENCES);
|
|
|
|
if (hImeInst == NULL)
|
|
|
|
return NULL;
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
EnumResourceNamesW(hImeInst, RT_GROUP_ICON, EnumResNameProc, (LPARAM)&hIconSm);
|
|
|
|
FreeLibrary(hImeInst);
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
return hIconSm;
|
|
|
|
}
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static HTREEITEM FindLanguageInList(HWND hwndList, LPCTSTR pszLangName)
|
|
|
|
{
|
|
|
|
TV_ITEM item;
|
|
|
|
TCHAR szText[128];
|
|
|
|
HTREEITEM hItem;
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
hItem = TreeView_GetRoot(hwndList);
|
|
|
|
while (hItem)
|
|
|
|
{
|
|
|
|
szText[0] = 0;
|
|
|
|
item.mask = TVIF_TEXT | TVIF_HANDLE;
|
|
|
|
item.pszText = szText;
|
|
|
|
item.cchTextMax = _countof(szText);
|
|
|
|
item.hItem = hItem;
|
|
|
|
TreeView_GetItem(hwndList, &item);
|
|
|
|
if (_wcsicmp(szText, pszLangName) == 0)
|
|
|
|
return hItem;
|
|
|
|
|
|
|
|
hItem = TreeView_GetNextSibling(hwndList, hItem);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
return NULL;
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 18:26:43 +00:00
|
|
|
static VOID
|
2022-09-28 22:31:43 +00:00
|
|
|
AddToInputListView(HWND hwndList, INPUT_LIST_NODE *pInputNode)
|
2016-08-09 18:26:43 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
TV_ITEM item;
|
|
|
|
TV_INSERTSTRUCT insert;
|
|
|
|
HIMAGELIST hImageList = TreeView_GetImageList(hwndList, TVSIL_NORMAL);
|
|
|
|
WCHAR szKeyboard[64];
|
|
|
|
HTREEITEM hItem;
|
|
|
|
BOOL bBold = !!(pInputNode->wFlags & INPUT_LIST_NODE_FLAG_DEFAULT);
|
|
|
|
|
|
|
|
hItem = FindLanguageInList(hwndList, pInputNode->pLocale->pszName);
|
|
|
|
if (hItem == NULL)
|
2022-09-15 23:09:37 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
// Language icon
|
|
|
|
INT LangImageIndex = -1;
|
|
|
|
HICON hLangIcon = CreateLayoutIcon(LOWORD(pInputNode->pLocale->dwId));
|
|
|
|
if (hLangIcon)
|
|
|
|
{
|
|
|
|
LangImageIndex = ImageList_AddIcon(hImageList, hLangIcon);
|
|
|
|
DestroyIcon(hLangIcon);
|
|
|
|
}
|
2022-09-15 23:09:37 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// Language
|
|
|
|
ZeroMemory(&item, sizeof(item));
|
|
|
|
item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_STATE;
|
|
|
|
item.pszText = pInputNode->pLocale->pszName;
|
|
|
|
item.iImage = LangImageIndex;
|
|
|
|
item.iSelectedImage = LangImageIndex;
|
|
|
|
item.lParam = LOWORD(pInputNode->pLocale->dwId); // HIWORD(item.lParam) == 0
|
|
|
|
if (bBold)
|
2022-09-15 23:09:37 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
item.state = item.stateMask = TVIS_BOLD;
|
2022-09-15 23:09:37 +00:00
|
|
|
}
|
2022-09-28 22:31:43 +00:00
|
|
|
insert.hParent = TVI_ROOT;
|
|
|
|
insert.hInsertAfter = TVI_LAST;
|
|
|
|
insert.item = item;
|
|
|
|
hItem = TreeView_InsertItem(hwndList, &insert);
|
|
|
|
|
|
|
|
// The type of input method (currently keyboard only)
|
|
|
|
LoadStringW(hApplet, IDS_KEYBOARD, szKeyboard, _countof(szKeyboard));
|
|
|
|
ZeroMemory(&item, sizeof(item));
|
|
|
|
item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE;
|
|
|
|
item.pszText = szKeyboard;
|
|
|
|
item.iImage = s_iKeyboardImage;
|
|
|
|
item.iSelectedImage = s_iKeyboardImage;
|
|
|
|
item.lParam = 0; // HIWORD(item.lParam) == 0
|
|
|
|
insert.hParent = hItem;
|
|
|
|
insert.hInsertAfter = TVI_LAST;
|
|
|
|
insert.item = item;
|
|
|
|
hItem = TreeView_InsertItem(hwndList, &insert);
|
2022-09-15 23:09:37 +00:00
|
|
|
}
|
2022-09-28 22:31:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Language
|
|
|
|
ZeroMemory(&item, sizeof(item));
|
|
|
|
item.mask = TVIF_STATE | TVIF_HANDLE;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.stateMask = TVIS_BOLD;
|
|
|
|
if (TreeView_GetItem(hwndList, &item) && bBold && !(item.state & TVIS_BOLD))
|
|
|
|
{
|
|
|
|
// Make the item bold
|
|
|
|
item.mask = TVIF_STATE | TVIF_HANDLE;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.state = item.stateMask = TVIS_BOLD;
|
|
|
|
TreeView_SetItem(hwndList, &item);
|
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// The type of input method (currently keyboard only)
|
|
|
|
hItem = TreeView_GetChild(hwndList, hItem);
|
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// Input method
|
|
|
|
if (hItem)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
INT ImeImageIndex = s_iDotImage;
|
|
|
|
if (IS_IME_HKL(pInputNode->hkl) && pInputNode->pLayout->pszImeFile) // IME?
|
|
|
|
{
|
|
|
|
HICON hImeIcon = LoadIMEIcon(pInputNode->pLayout->pszImeFile);
|
|
|
|
if (hImeIcon)
|
|
|
|
{
|
|
|
|
ImeImageIndex = ImageList_AddIcon(hImageList, hImeIcon);
|
|
|
|
DestroyIcon(hImeIcon);
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
ZeroMemory(&item, sizeof(item));
|
|
|
|
item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_STATE;
|
|
|
|
item.pszText = pInputNode->pLayout->pszName;
|
|
|
|
item.iImage = ImeImageIndex;
|
|
|
|
item.iSelectedImage = ImeImageIndex;
|
|
|
|
item.lParam = (LPARAM)pInputNode; // HIWORD(item.lParam) != 0
|
|
|
|
if (bBold)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
item.state = item.stateMask = TVIS_BOLD; // Make the item bold
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
2022-09-28 22:31:43 +00:00
|
|
|
insert.hParent = hItem;
|
|
|
|
insert.hInsertAfter = TVI_LAST;
|
|
|
|
insert.item = item;
|
|
|
|
hItem = TreeView_InsertItem(hwndList, &insert);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static VOID ExpandTreeItem(HWND hwndTree, HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
TreeView_Expand(hwndTree, hItem, TVE_EXPAND);
|
|
|
|
hItem = TreeView_GetChild(hwndTree, hItem);
|
|
|
|
while (hItem)
|
|
|
|
{
|
|
|
|
ExpandTreeItem(hwndTree, hItem);
|
|
|
|
hItem = TreeView_GetNextSibling(hwndTree, hItem);
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 23:28:50 +00:00
|
|
|
|
|
|
|
static VOID
|
2016-08-08 20:30:36 +00:00
|
|
|
UpdateInputListView(HWND hwndList)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
INPUT_LIST_NODE *pNode;
|
2022-09-28 22:31:43 +00:00
|
|
|
HIMAGELIST hImageList = TreeView_GetImageList(hwndList, TVSIL_NORMAL);
|
|
|
|
HTREEITEM hItem;
|
|
|
|
HICON hKeyboardIcon, hDotIcon;
|
|
|
|
|
|
|
|
ImageList_RemoveAll(hImageList);
|
|
|
|
TreeView_DeleteAllItems(hwndList);
|
|
|
|
|
|
|
|
// Add keyboard icon
|
|
|
|
s_iKeyboardImage = -1;
|
|
|
|
hKeyboardIcon = (HICON)LoadImageW(hApplet, MAKEINTRESOURCEW(IDI_KEYBOARD), IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
|
|
|
|
0);
|
|
|
|
if (hKeyboardIcon)
|
|
|
|
{
|
|
|
|
s_iKeyboardImage = ImageList_AddIcon(hImageList, hKeyboardIcon);
|
|
|
|
DestroyIcon(hKeyboardIcon);
|
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// Add dot icon
|
|
|
|
s_iDotImage = -1;
|
|
|
|
hDotIcon = (HICON)LoadImageW(hApplet, MAKEINTRESOURCEW(IDI_DOT), IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
|
|
|
|
0);
|
|
|
|
if (hDotIcon)
|
2016-08-07 23:28:50 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
s_iDotImage = ImageList_AddIcon(hImageList, hDotIcon);
|
|
|
|
DestroyIcon(hDotIcon);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
InputList_Sort();
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
s_nAliveLeafCount = InputList_GetAliveCount();
|
|
|
|
|
|
|
|
// Add items to the list
|
|
|
|
for (pNode = InputList_GetFirst(); pNode; pNode = pNode->pNext)
|
2016-08-08 20:30:36 +00:00
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
if (pNode->wFlags & INPUT_LIST_NODE_FLAG_DELETED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
AddToInputListView(hwndList, pNode);
|
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// Expand all (with counting s_nRootCount)
|
|
|
|
s_nRootCount = 0;
|
|
|
|
hItem = TreeView_GetRoot(hwndList);
|
|
|
|
while (hItem)
|
2022-09-15 23:09:37 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
++s_nRootCount;
|
|
|
|
ExpandTreeItem(hwndList, hItem);
|
|
|
|
hItem = TreeView_GetNextSibling(hwndList, hItem);
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
2022-09-15 23:09:37 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
// Redraw
|
2022-09-15 23:09:37 +00:00
|
|
|
InvalidateRect(hwndList, NULL, TRUE);
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
OnInitSettingsPage(HWND hwndDlg)
|
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
HWND hwndInputList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST);
|
2022-09-28 22:31:43 +00:00
|
|
|
HIMAGELIST hLayoutImageList, hOldImageList;
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2016-08-07 23:28:50 +00:00
|
|
|
LayoutList_Create();
|
|
|
|
LocaleList_Create();
|
2016-08-08 20:30:36 +00:00
|
|
|
InputList_Create();
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_LANGUAGE_BAR), FALSE);
|
2016-08-07 23:28:50 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
hLayoutImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
|
|
|
|
GetSystemMetrics(SM_CYSMICON),
|
|
|
|
ILC_COLOR8 | ILC_MASK, 0, 0);
|
|
|
|
if (hLayoutImageList != NULL)
|
|
|
|
{
|
|
|
|
hOldImageList = TreeView_SetImageList(hwndInputList, hLayoutImageList, TVSIL_NORMAL);
|
|
|
|
ImageList_Destroy(hOldImageList);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
UpdateInputListView(hwndInputList);
|
|
|
|
|
2022-09-15 23:09:37 +00:00
|
|
|
SetControlsState(hwndDlg);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
OnDestroySettingsPage(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
LayoutList_Destroy();
|
|
|
|
LocaleList_Destroy();
|
2016-08-08 20:30:36 +00:00
|
|
|
InputList_Destroy();
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-08 20:30:36 +00:00
|
|
|
VOID
|
|
|
|
OnCommandSettingsPage(HWND hwndDlg, WPARAM wParam)
|
|
|
|
{
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_ADD_BUTTON:
|
|
|
|
{
|
|
|
|
if (DialogBoxW(hApplet,
|
|
|
|
MAKEINTRESOURCEW(IDD_ADD),
|
|
|
|
hwndDlg,
|
|
|
|
AddDialogProc) == IDOK)
|
|
|
|
{
|
|
|
|
UpdateInputListView(GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST));
|
2022-09-15 23:09:37 +00:00
|
|
|
SetControlsState(hwndDlg);
|
2016-08-08 20:30:36 +00:00
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_REMOVE_BUTTON:
|
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST);
|
|
|
|
if (hwndList)
|
2016-08-09 14:01:52 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
HTREEITEM hItem = TreeView_GetSelection(hwndList);
|
|
|
|
TV_ITEM item = { TVIF_HANDLE | TVIF_PARAM };
|
|
|
|
item.hItem = hItem;
|
2016-08-09 14:01:52 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
if (hItem && TreeView_GetItem(hwndList, &item))
|
2016-08-09 14:01:52 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
if (item.lParam == 0) // Branch? (currently branch is keyboard only)
|
|
|
|
{
|
|
|
|
// Get root of branch
|
|
|
|
item.hItem = TreeView_GetParent(hwndList, hItem);
|
|
|
|
TreeView_GetItem(hwndList, &item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HIWORD(item.lParam)) // Leaf?
|
|
|
|
{
|
|
|
|
if (InputList_Remove((INPUT_LIST_NODE*)item.lParam))
|
2023-11-19 12:39:06 +00:00
|
|
|
g_bRebootNeeded = TRUE;
|
2022-09-28 22:31:43 +00:00
|
|
|
}
|
|
|
|
else // Root?
|
|
|
|
{
|
|
|
|
if (InputList_RemoveByLang(LOWORD(item.lParam)))
|
2023-11-19 12:39:06 +00:00
|
|
|
g_bRebootNeeded = TRUE;
|
2022-09-28 22:31:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 18:26:43 +00:00
|
|
|
UpdateInputListView(hwndList);
|
2022-09-15 23:09:37 +00:00
|
|
|
SetControlsState(hwndDlg);
|
2016-08-09 14:01:52 +00:00
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_PROP_BUTTON:
|
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST);
|
|
|
|
if (hwndList)
|
2016-08-09 14:01:52 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
HTREEITEM hItem = TreeView_GetSelection(hwndList);
|
|
|
|
TV_ITEM item = { TVIF_HANDLE | TVIF_PARAM };
|
|
|
|
item.hItem = hItem;
|
2016-08-09 18:26:43 +00:00
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
if (hItem && TreeView_GetItem(hwndList, &item) && HIWORD(item.lParam))
|
2016-08-09 18:26:43 +00:00
|
|
|
{
|
|
|
|
if (DialogBoxParamW(hApplet,
|
|
|
|
MAKEINTRESOURCEW(IDD_INPUT_LANG_PROP),
|
|
|
|
hwndDlg,
|
|
|
|
EditDialogProc,
|
|
|
|
item.lParam) == IDOK)
|
|
|
|
{
|
|
|
|
UpdateInputListView(hwndList);
|
2022-09-15 23:09:37 +00:00
|
|
|
SetControlsState(hwndDlg);
|
2016-08-09 18:26:43 +00:00
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
2016-08-09 14:01:52 +00:00
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_KEY_SET_BTN:
|
|
|
|
{
|
2016-08-09 21:03:55 +00:00
|
|
|
DialogBoxW(hApplet,
|
|
|
|
MAKEINTRESOURCEW(IDD_KEYSETTINGS),
|
|
|
|
hwndDlg,
|
|
|
|
KeySettingsDialogProc);
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-09-28 22:31:43 +00:00
|
|
|
|
|
|
|
case IDC_LANGUAGE_BAR:
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IDC_DEFAULT_LANGUAGE:
|
|
|
|
{
|
|
|
|
if (HIWORD(wParam) == CBN_SELENDOK)
|
|
|
|
{
|
|
|
|
HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST);
|
|
|
|
HWND hwndCombo = GetDlgItem(hwndDlg, IDC_DEFAULT_LANGUAGE);
|
|
|
|
INT iSelected = (INT)SendMessageW(hwndCombo, CB_GETCURSEL, 0, 0);
|
|
|
|
if (iSelected != CB_ERR)
|
|
|
|
{
|
|
|
|
LPARAM lParam = SendMessageW(hwndCombo, CB_GETITEMDATA, iSelected, 0);
|
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
INPUT_LIST_NODE* pNode = (INPUT_LIST_NODE*)lParam;
|
|
|
|
if (!(pNode->wFlags & INPUT_LIST_NODE_FLAG_DEFAULT))
|
|
|
|
{
|
2023-11-19 12:39:06 +00:00
|
|
|
g_bRebootNeeded = TRUE;
|
2022-09-28 22:31:43 +00:00
|
|
|
InputList_SetDefault(pNode);
|
|
|
|
UpdateInputListView(hwndList);
|
|
|
|
SetControlsState(hwndDlg);
|
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 23:26:22 +00:00
|
|
|
BOOL EnableProcessPrivileges(LPCWSTR lpPrivilegeName, BOOL bEnable)
|
|
|
|
{
|
|
|
|
HANDLE hToken;
|
|
|
|
LUID luid;
|
|
|
|
TOKEN_PRIVILEGES tokenPrivileges;
|
|
|
|
BOOL Ret;
|
|
|
|
|
|
|
|
Ret = OpenProcessToken(GetCurrentProcess(),
|
|
|
|
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
|
|
|
|
&hToken);
|
|
|
|
if (!Ret)
|
|
|
|
return Ret; // failure
|
|
|
|
|
|
|
|
Ret = LookupPrivilegeValueW(NULL, lpPrivilegeName, &luid);
|
|
|
|
if (Ret)
|
|
|
|
{
|
|
|
|
tokenPrivileges.PrivilegeCount = 1;
|
|
|
|
tokenPrivileges.Privileges[0].Luid = luid;
|
|
|
|
tokenPrivileges.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
|
|
|
|
|
|
|
|
Ret = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
static INT_PTR
|
2016-08-08 20:30:36 +00:00
|
|
|
OnNotifySettingsPage(HWND hwndDlg, LPARAM lParam)
|
|
|
|
{
|
2022-09-15 23:09:37 +00:00
|
|
|
LPNMHDR header = (LPNMHDR)lParam;
|
2016-08-09 18:26:43 +00:00
|
|
|
|
|
|
|
switch (header->code)
|
2016-08-08 20:30:36 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
case TVN_SELCHANGED:
|
|
|
|
{
|
|
|
|
SetControlsState(hwndDlg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TVN_ITEMEXPANDING:
|
2016-08-09 18:26:43 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
// FIXME: Prevent collapse (COMCTL32 is buggy)
|
|
|
|
// https://bugs.winehq.org/show_bug.cgi?id=53727
|
|
|
|
NM_TREEVIEW* pTreeView = (NM_TREEVIEW*)lParam;
|
|
|
|
if ((pTreeView->action & TVE_TOGGLE) == TVE_COLLAPSE)
|
2016-08-09 18:26:43 +00:00
|
|
|
{
|
2022-09-28 22:31:43 +00:00
|
|
|
SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, TRUE);
|
|
|
|
return TRUE;
|
2016-08-09 18:26:43 +00:00
|
|
|
}
|
2022-09-28 22:31:43 +00:00
|
|
|
break;
|
2016-08-09 18:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PSN_APPLY:
|
|
|
|
{
|
2016-08-09 21:03:55 +00:00
|
|
|
/* Write Input Methods list to registry */
|
2023-11-19 12:39:06 +00:00
|
|
|
g_bRebootNeeded |= InputList_Process();
|
2022-09-28 22:31:43 +00:00
|
|
|
break;
|
2016-08-09 18:26:43 +00:00
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-08-08 20:30:36 +00:00
|
|
|
|
2016-08-07 23:28:50 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
SettingsPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
OnInitSettingsPage(hwndDlg);
|
2022-10-29 23:01:50 +00:00
|
|
|
return TRUE;
|
2016-08-07 23:28:50 +00:00
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
OnDestroySettingsPage(hwndDlg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
2016-08-08 20:30:36 +00:00
|
|
|
OnCommandSettingsPage(hwndDlg, wParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
2022-09-28 22:31:43 +00:00
|
|
|
return OnNotifySettingsPage(hwndDlg, lParam);
|
2016-08-07 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|