diff --git a/reactos/dll/cpl/input_new/add_dialog.c b/reactos/dll/cpl/input_new/add_dialog.c index e0c0c57c481..5156b190834 100644 --- a/reactos/dll/cpl/input_new/add_dialog.c +++ b/reactos/dll/cpl/input_new/add_dialog.c @@ -71,7 +71,7 @@ OnInitAddDialog(HWND hwndDlg) dwDefaultLocaleId = GetSystemDefaultLCID(); - for (pCurrentLocale = LocaleList_Get(); + for (pCurrentLocale = LocaleList_GetFirst(); pCurrentLocale != NULL; pCurrentLocale = pCurrentLocale->pNext) { @@ -86,7 +86,7 @@ OnInitAddDialog(HWND hwndDlg) dwDefaultLayoutId = GetDefaultLayoutForLocale(dwDefaultLocaleId); - for (pCurrentLayout = LayoutList_Get(); + for (pCurrentLayout = LayoutList_GetFirst(); pCurrentLayout != NULL; pCurrentLayout = pCurrentLayout->pNext) { @@ -158,9 +158,11 @@ OnCommandAddDialog(HWND hwndDlg, WPARAM wParam) LAYOUT_LIST_NODE *pCurrentLayout; pCurrentLayout = (LAYOUT_LIST_NODE*)ComboBox_GetItemData(hwndLayoutCombo, iIndex); + if (pCurrentLayout != NULL && pCurrentLayout->dwId == dwLayoutId) { ComboBox_SetCurSel(hwndLayoutCombo, iIndex); + break; } } } diff --git a/reactos/dll/cpl/input_new/edit_dialog.c b/reactos/dll/cpl/input_new/edit_dialog.c index a9798bf195a..f0960760394 100644 --- a/reactos/dll/cpl/input_new/edit_dialog.c +++ b/reactos/dll/cpl/input_new/edit_dialog.c @@ -6,3 +6,33 @@ */ #include "input.h" + + +INT_PTR CALLBACK +EditDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + + switch (uMsg) + { + case WM_INITDIALOG: + break; + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + EndDialog(hDlg, LOWORD(wParam)); + break; + + case IDCANCEL: + EndDialog(hDlg, LOWORD(wParam)); + break; + } + } + break; + } + + return FALSE; +} diff --git a/reactos/dll/cpl/input_new/input.h b/reactos/dll/cpl/input_new/input.h index bcba8e4bd27..3ca37475ffb 100644 --- a/reactos/dll/cpl/input_new/input.h +++ b/reactos/dll/cpl/input_new/input.h @@ -51,6 +51,15 @@ AdvancedSettingsPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK AddDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +/* edit_dialog.c */ +INT_PTR CALLBACK +EditDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + +/* key_settings_dialog.c */ +INT_PTR CALLBACK +KeySettingsDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + + static inline WCHAR* DublicateString(const WCHAR *pszString) { diff --git a/reactos/dll/cpl/input_new/input_list.c b/reactos/dll/cpl/input_new/input_list.c index d4baa5ece60..a61e64954ef 100644 --- a/reactos/dll/cpl/input_new/input_list.c +++ b/reactos/dll/cpl/input_new/input_list.c @@ -44,8 +44,8 @@ InputList_AppendNode(VOID) } -VOID -InputList_Remove(INPUT_LIST_NODE *pNode) +static VOID +InputList_RemoveNode(INPUT_LIST_NODE *pNode) { INPUT_LIST_NODE *pCurrent = pNode; @@ -57,6 +57,7 @@ InputList_Remove(INPUT_LIST_NODE *pNode) INPUT_LIST_NODE *pNext = pCurrent->pNext; INPUT_LIST_NODE *pPrev = pCurrent->pPrev; + free(pCurrent->pszIndicator); free(pCurrent); if (pNext != NULL) @@ -84,6 +85,7 @@ InputList_Destroy(VOID) { INPUT_LIST_NODE *pNext = pCurrent->pNext; + free(pCurrent->pszIndicator); free(pCurrent); pCurrent = pNext; @@ -234,7 +236,7 @@ InputList_Process(VOID) if (UnloadKeyboardLayout(pCurrent->hkl)) { - InputList_Remove(pCurrent); + InputList_RemoveNode(pCurrent); } } @@ -267,12 +269,16 @@ InputList_Process(VOID) } /* Add methods to registry */ - for (pCurrent = _InputList, dwIndex = 2; pCurrent != NULL; pCurrent = pCurrent->pNext, dwIndex++) + dwIndex = 2; + + for (pCurrent = _InputList; pCurrent != NULL; pCurrent = pCurrent->pNext) { if (pCurrent->dwFlags & INPUT_LIST_NODE_FLAG_DEFAULT) continue; InputList_AddInputMethodToUserRegistry(dwIndex, pCurrent); + + dwIndex++; } } @@ -280,6 +286,7 @@ InputList_Process(VOID) VOID InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout) { + WCHAR szIndicator[MAX_STR_LEN]; INPUT_LIST_NODE *pInput; if (pLocale == NULL || pLayout == NULL) @@ -293,6 +300,64 @@ InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout) pInput->pLocale = pLocale; pInput->pLayout = pLayout; + + if (GetLocaleInfoW(LOWORD(pInput->pLocale->dwId), + LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE, + szIndicator, + ARRAYSIZE(szIndicator))) + { + size_t len = wcslen(szIndicator); + + if (len > 0) + { + szIndicator[len - 1] = 0; + pInput->pszIndicator = DublicateString(szIndicator); + } + } +} + + +VOID +InputList_SetDefault(INPUT_LIST_NODE *pNode) +{ + INPUT_LIST_NODE *pCurrent; + + if (pNode == NULL) + return; + + for (pCurrent = _InputList; pCurrent != NULL; pCurrent = pCurrent->pNext) + { + if (pCurrent == pNode) + { + pCurrent->dwFlags |= INPUT_LIST_NODE_FLAG_DEFAULT; + } + else + { + pCurrent->dwFlags &= ~INPUT_LIST_NODE_FLAG_DEFAULT; + } + } +} + + +VOID +InputList_Remove(INPUT_LIST_NODE *pNode) +{ + if (pNode == NULL) + return; + + pNode->dwFlags |= INPUT_LIST_NODE_FLAG_DELETED; + + if (pNode->dwFlags & INPUT_LIST_NODE_FLAG_DEFAULT) + { + if (pNode->pNext != NULL) + { + pNode->pNext->dwFlags |= INPUT_LIST_NODE_FLAG_DEFAULT; + } + else if (pNode->pPrev != NULL) + { + pNode->pPrev->dwFlags |= INPUT_LIST_NODE_FLAG_DEFAULT; + } + } } @@ -318,14 +383,42 @@ InputList_Create(VOID) if (pLocale != NULL && pLayout != NULL) { + WCHAR szIndicator[MAX_STR_LEN] = { 0 }; INPUT_LIST_NODE *pInput; + HKL hklDefault; pInput = InputList_AppendNode(); - pInput->dwFlags = 0; pInput->pLocale = pLocale; pInput->pLayout = pLayout; pInput->hkl = pLayoutList[iIndex]; + + if (SystemParametersInfoW(SPI_GETDEFAULTINPUTLANG, + 0, + (LPVOID)((LPDWORD)&hklDefault), + 0) == FALSE) + { + hklDefault = GetKeyboardLayout(0); + } + + if (pInput->hkl == hklDefault) + { + pInput->dwFlags |= INPUT_LIST_NODE_FLAG_DEFAULT; + } + + if (GetLocaleInfoW(LOWORD(pInput->pLocale->dwId), + LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE, + szIndicator, + ARRAYSIZE(szIndicator))) + { + size_t len = wcslen(szIndicator); + + if (len > 0) + { + szIndicator[len - 1] = 0; + pInput->pszIndicator = DublicateString(szIndicator); + } + } } } } @@ -336,7 +429,7 @@ InputList_Create(VOID) INPUT_LIST_NODE* -InputList_Get(VOID) +InputList_GetFirst(VOID) { return _InputList; } diff --git a/reactos/dll/cpl/input_new/input_list.h b/reactos/dll/cpl/input_new/input_list.h index c371d4da405..837f03e576d 100644 --- a/reactos/dll/cpl/input_new/input_list.h +++ b/reactos/dll/cpl/input_new/input_list.h @@ -20,6 +20,8 @@ typedef struct _INPUT_LIST_NODE HKL hkl; + WCHAR *pszIndicator; + struct _INPUT_LIST_NODE *pPrev; struct _INPUT_LIST_NODE *pNext; } INPUT_LIST_NODE; @@ -34,6 +36,9 @@ InputList_Process(VOID); VOID InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout); +VOID +InputList_SetDefault(INPUT_LIST_NODE *pNode); + VOID InputList_Remove(INPUT_LIST_NODE *pNode); @@ -41,4 +46,4 @@ VOID InputList_Destroy(VOID); INPUT_LIST_NODE* -InputList_Get(VOID); +InputList_GetFirst(VOID); diff --git a/reactos/dll/cpl/input_new/key_settings_dialog.c b/reactos/dll/cpl/input_new/key_settings_dialog.c index 1675da63800..619224ed348 100644 --- a/reactos/dll/cpl/input_new/key_settings_dialog.c +++ b/reactos/dll/cpl/input_new/key_settings_dialog.c @@ -6,3 +6,33 @@ */ #include "input.h" + + +INT_PTR CALLBACK +KeySettingsDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + + switch (uMsg) + { + case WM_INITDIALOG: + break; + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + EndDialog(hDlg, LOWORD(wParam)); + break; + + case IDCANCEL: + EndDialog(hDlg, LOWORD(wParam)); + break; + } + } + break; + } + + return FALSE; +} diff --git a/reactos/dll/cpl/input_new/layout_list.c b/reactos/dll/cpl/input_new/layout_list.c index a1c6255546a..631b032c791 100644 --- a/reactos/dll/cpl/input_new/layout_list.c +++ b/reactos/dll/cpl/input_new/layout_list.c @@ -12,12 +12,12 @@ static LAYOUT_LIST_NODE *_LayoutList = NULL; static LAYOUT_LIST_NODE* -LayoutList_Append(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName, const WCHAR *pszFile) +LayoutList_AppendNode(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName) { LAYOUT_LIST_NODE *pCurrent; LAYOUT_LIST_NODE *pNew; - if (pszName == NULL || pszFile == NULL) + if (pszName == NULL) return NULL; pCurrent = _LayoutList; @@ -35,14 +35,6 @@ LayoutList_Append(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName, const WCH return NULL; } - pNew->pszFile = DublicateString(pszFile); - if (pNew->pszFile == NULL) - { - free(pNew->pszName); - free(pNew); - return NULL; - } - pNew->dwId = dwId; pNew->dwSpecialId = dwSpecialId; @@ -80,7 +72,6 @@ LayoutList_Destroy(VOID) LAYOUT_LIST_NODE *pNext = pCurrent->pNext; free(pCurrent->pszName); - free(pCurrent->pszFile); free(pCurrent); pCurrent = pNext; @@ -163,10 +154,7 @@ LayoutList_Create(VOID) { DWORD dwLayoutId = DWORDfromString(szLayoutId); - LayoutList_Append(dwLayoutId, - dwSpecialId, - szBuffer, - szFilePath); + LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer); } } } @@ -215,7 +203,7 @@ LayoutList_GetByHkl(HKL hkl) LAYOUT_LIST_NODE* -LayoutList_Get(VOID) +LayoutList_GetFirst(VOID) { return _LayoutList; } diff --git a/reactos/dll/cpl/input_new/layout_list.h b/reactos/dll/cpl/input_new/layout_list.h index 26ffb59f057..bbd0a0d0740 100644 --- a/reactos/dll/cpl/input_new/layout_list.h +++ b/reactos/dll/cpl/input_new/layout_list.h @@ -5,9 +5,10 @@ typedef struct _LAYOUT_LIST_NODE { WCHAR *pszName; - WCHAR *pszFile; + DWORD dwId; DWORD dwSpecialId; + struct _LAYOUT_LIST_NODE *pPrev; struct _LAYOUT_LIST_NODE *pNext; } LAYOUT_LIST_NODE; @@ -22,4 +23,4 @@ LAYOUT_LIST_NODE* LayoutList_GetByHkl(HKL hkl); LAYOUT_LIST_NODE* -LayoutList_Get(VOID); +LayoutList_GetFirst(VOID); diff --git a/reactos/dll/cpl/input_new/locale_list.c b/reactos/dll/cpl/input_new/locale_list.c index 626439704d1..463186bb8f7 100644 --- a/reactos/dll/cpl/input_new/locale_list.c +++ b/reactos/dll/cpl/input_new/locale_list.c @@ -12,12 +12,12 @@ static LOCALE_LIST_NODE *_LocaleList = NULL; static LOCALE_LIST_NODE* -LocaleList_Append(DWORD dwId, const WCHAR *pszName, const WCHAR *pszIndicator) +LocaleList_Append(DWORD dwId, const WCHAR *pszName) { LOCALE_LIST_NODE *pCurrent; LOCALE_LIST_NODE *pNew; - if (pszName == NULL || pszIndicator == NULL) + if (pszName == NULL) return NULL; pCurrent = _LocaleList; @@ -35,14 +35,6 @@ LocaleList_Append(DWORD dwId, const WCHAR *pszName, const WCHAR *pszIndicator) return NULL; } - pNew->pszIndicator = DublicateString(pszIndicator); - if (pNew->pszIndicator == NULL) - { - free(pNew->pszName); - free(pNew); - return NULL; - } - pNew->dwId = dwId; if (pCurrent == NULL) @@ -79,7 +71,6 @@ LocaleList_Destroy(VOID) LOCALE_LIST_NODE *pNext = pCurrent->pNext; free(pCurrent->pszName); - free(pCurrent->pszIndicator); free(pCurrent); pCurrent = pNext; @@ -121,22 +112,7 @@ LocaleList_Create(VOID) LOCALE_SLANGUAGE, szName, ARRAYSIZE(szName))) { - WCHAR szIndicator[MAX_STR_LEN] = { 0 }; - - if (GetLocaleInfoW(LOWORD(dwId), - LOCALE_SABBREVLANGNAME | LOCALE_NOUSEROVERRIDE, - szIndicator, - ARRAYSIZE(szIndicator))) - { - size_t len = wcslen(szIndicator); - - if (len > 0) - { - szIndicator[len - 1] = 0; - } - } - - LocaleList_Append(dwId, szName, szIndicator); + LocaleList_Append(dwId, szName); } dwSize = sizeof(szValue); @@ -165,7 +141,7 @@ LocaleList_GetByHkl(HKL hkl) LOCALE_LIST_NODE* -LocaleList_Get(VOID) +LocaleList_GetFirst(VOID) { return _LocaleList; } diff --git a/reactos/dll/cpl/input_new/locale_list.h b/reactos/dll/cpl/input_new/locale_list.h index 6a856562c6a..296c3409d87 100644 --- a/reactos/dll/cpl/input_new/locale_list.h +++ b/reactos/dll/cpl/input_new/locale_list.h @@ -5,8 +5,9 @@ typedef struct _LOCALE_LIST_NODE { WCHAR *pszName; - WCHAR *pszIndicator; + DWORD dwId; + struct _LOCALE_LIST_NODE *pPrev; struct _LOCALE_LIST_NODE *pNext; } LOCALE_LIST_NODE; @@ -21,4 +22,4 @@ LOCALE_LIST_NODE* LocaleList_GetByHkl(HKL hkl); LOCALE_LIST_NODE* -LocaleList_Get(VOID); +LocaleList_GetFirst(VOID); diff --git a/reactos/dll/cpl/input_new/settings_page.c b/reactos/dll/cpl/input_new/settings_page.c index 47f36d028e6..6b4ed92095f 100644 --- a/reactos/dll/cpl/input_new/settings_page.c +++ b/reactos/dll/cpl/input_new/settings_page.c @@ -99,7 +99,7 @@ AddToInputListView(HWND hwndList, INPUT_LIST_NODE *pInputNode) { HICON hLayoutIcon; - hLayoutIcon = CreateLayoutIcon(pInputNode->pLocale->pszIndicator); + hLayoutIcon = CreateLayoutIcon(pInputNode->pszIndicator); if (hLayoutIcon != NULL) { @@ -136,11 +136,14 @@ UpdateInputListView(HWND hwndList) ListView_DeleteAllItems(hwndList); - for (pCurrentInputNode = InputList_Get(); + for (pCurrentInputNode = InputList_GetFirst(); pCurrentInputNode != NULL; pCurrentInputNode = pCurrentInputNode->pNext) { - AddToInputListView(hwndList, pCurrentInputNode); + if (!(pCurrentInputNode->dwFlags & INPUT_LIST_NODE_FLAG_DELETED)) + { + AddToInputListView(hwndList, pCurrentInputNode); + } } } @@ -158,7 +161,6 @@ OnInitSettingsPage(HWND hwndDlg) if (hwndInputList != NULL) { - INPUT_LIST_NODE *pCurrentInputNode; WCHAR szBuffer[MAX_STR_LEN]; HIMAGELIST hLayoutImageList; LV_COLUMN column; @@ -191,12 +193,7 @@ OnInitSettingsPage(HWND hwndDlg) ListView_SetImageList(hwndInputList, hLayoutImageList, LVSIL_SMALL); } - for (pCurrentInputNode = InputList_Get(); - pCurrentInputNode != NULL; - pCurrentInputNode = pCurrentInputNode->pNext) - { - AddToInputListView(hwndInputList, pCurrentInputNode); - } + UpdateInputListView(hwndInputList); } } @@ -239,25 +236,74 @@ OnCommandSettingsPage(HWND hwndDlg, WPARAM wParam) case IDC_REMOVE_BUTTON: { - PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST); + + if (hwndList != NULL) + { + LVITEM item = { 0 }; + + item.mask = LVIF_PARAM; + item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED); + + if (ListView_GetItem(hwndList, &item) != FALSE) + { + InputList_Remove((INPUT_LIST_NODE*)item.lParam); + UpdateInputListView(GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST)); + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + } + } } break; case IDC_PROP_BUTTON: { - + if (DialogBoxW(hApplet, + MAKEINTRESOURCEW(IDD_INPUT_LANG_PROP), + hwndDlg, + EditDialogProc) == IDOK) + { + UpdateInputListView(GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST)); + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + } } break; case IDC_SET_DEFAULT: { - PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + HWND hwndList = GetDlgItem(hwndDlg, IDC_KEYLAYOUT_LIST); + + if (hwndList != NULL) + { + LVITEM item = { 0 }; + + item.mask = LVIF_PARAM; + item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED); + + if (ListView_GetItem(hwndList, &item) != FALSE) + { + INPUT_LIST_NODE *pSelected; + + pSelected = (INPUT_LIST_NODE*) item.lParam; + if (pSelected != NULL) + { + InputList_SetDefault(pSelected); + } + + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + } + } } break; case IDC_KEY_SET_BTN: { - + if (DialogBoxW(hApplet, + MAKEINTRESOURCEW(IDD_KEYSETTINGS), + hwndDlg, + KeySettingsDialogProc) == IDOK) + { + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + } } break; }