[LIBMPG123] Update to version 1.26.2. CORE-17158
[reactos.git] / dll / cpl / input / add_dialog.c
1 /*
2 * PROJECT: input.dll
3 * FILE: dll/cpl/input/add_dialog.c
4 * PURPOSE: input.dll
5 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6 */
7
8 #include "input.h"
9 #include "locale_list.h"
10 #include "layout_list.h"
11 #include "input_list.h"
12
13
14 static DWORD
15 GetDefaultLayoutForLocale(DWORD dwLocaleId)
16 {
17 DWORD dwResult = 0;
18 HINF hIntlInf;
19
20 hIntlInf = SetupOpenInfFileW(L"intl.inf", NULL, INF_STYLE_WIN4, NULL);
21 if (hIntlInf != INVALID_HANDLE_VALUE)
22 {
23 WCHAR szLangID[MAX_STR_LEN];
24 INFCONTEXT InfContext;
25
26 StringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"%08X", dwLocaleId);
27
28 if (SetupFindFirstLineW(hIntlInf, L"Locales", szLangID, &InfContext))
29 {
30 if (SetupGetFieldCount(&InfContext) >= 5)
31 {
32 WCHAR szField[MAX_STR_LEN];
33
34 if (SetupGetStringFieldW(&InfContext, 5, szField, ARRAYSIZE(szField), NULL))
35 {
36 if (wcslen(szField) == 13) // like 0409:00000409 (13 chars)
37 {
38 WCHAR *pszSeparator = L":";
39 WCHAR *pszToken;
40
41 pszToken = wcstok(szField, pszSeparator);
42 if (pszToken != NULL)
43 pszToken = wcstok(NULL, pszSeparator);
44
45 if (pszToken != NULL)
46 {
47 dwResult = DWORDfromString(pszToken);
48 }
49 }
50 }
51 }
52 }
53
54 SetupCloseInfFile(hIntlInf);
55 }
56
57 return dwResult;
58 }
59
60
61 static VOID
62 OnInitAddDialog(HWND hwndDlg)
63 {
64 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
65 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
66 LOCALE_LIST_NODE *pCurrentLocale;
67 LAYOUT_LIST_NODE *pCurrentLayout;
68 DWORD dwDefaultLocaleId;
69 DWORD dwDefaultLayoutId;
70 INT iItemIndex;
71
72 dwDefaultLocaleId = GetSystemDefaultLCID();
73
74 for (pCurrentLocale = LocaleList_GetFirst();
75 pCurrentLocale != NULL;
76 pCurrentLocale = pCurrentLocale->pNext)
77 {
78 iItemIndex = ComboBox_AddString(hwndLocaleCombo, pCurrentLocale->pszName);
79 ComboBox_SetItemData(hwndLocaleCombo, iItemIndex, pCurrentLocale);
80
81 if (pCurrentLocale->dwId == dwDefaultLocaleId)
82 {
83 ComboBox_SetCurSel(hwndLocaleCombo, iItemIndex);
84 }
85 }
86
87 dwDefaultLayoutId = GetDefaultLayoutForLocale(dwDefaultLocaleId);
88
89 for (pCurrentLayout = LayoutList_GetFirst();
90 pCurrentLayout != NULL;
91 pCurrentLayout = pCurrentLayout->pNext)
92 {
93 iItemIndex = ComboBox_AddString(hwndLayoutCombo, pCurrentLayout->pszName);
94 ComboBox_SetItemData(hwndLayoutCombo, iItemIndex, pCurrentLayout);
95
96 if (pCurrentLayout->dwId == dwDefaultLayoutId)
97 {
98 ComboBox_SetCurSel(hwndLayoutCombo, iItemIndex);
99 }
100 }
101
102 if (dwDefaultLayoutId == 0)
103 ComboBox_SetCurSel(hwndLayoutCombo, 0);
104 }
105
106
107 static VOID
108 OnCommandAddDialog(HWND hwndDlg, WPARAM wParam)
109 {
110 switch (LOWORD(wParam))
111 {
112 case IDOK:
113 {
114 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
115 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
116 LOCALE_LIST_NODE *pCurrentLocale;
117 LAYOUT_LIST_NODE *pCurrentLayout;
118
119 pCurrentLocale = (LOCALE_LIST_NODE*)ComboBox_GetItemData(hwndLocaleCombo,
120 ComboBox_GetCurSel(hwndLocaleCombo));
121 pCurrentLayout = (LAYOUT_LIST_NODE*)ComboBox_GetItemData(hwndLayoutCombo,
122 ComboBox_GetCurSel(hwndLayoutCombo));
123
124 InputList_Add(pCurrentLocale, pCurrentLayout);
125
126 EndDialog(hwndDlg, LOWORD(wParam));
127 }
128 break;
129
130 case IDCANCEL:
131 {
132 EndDialog(hwndDlg, LOWORD(wParam));
133 }
134 break;
135
136 case IDC_INPUT_LANG_COMBO:
137 {
138 if (HIWORD(wParam) == CBN_SELCHANGE)
139 {
140 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
141 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
142 LOCALE_LIST_NODE *pCurrentLocale;
143
144 pCurrentLocale = (LOCALE_LIST_NODE*)ComboBox_GetItemData(hwndLocaleCombo,
145 ComboBox_GetCurSel(hwndLocaleCombo));
146 if (pCurrentLocale != NULL)
147 {
148 DWORD dwLayoutId;
149 INT iIndex;
150 INT iCount;
151
152 dwLayoutId = GetDefaultLayoutForLocale(pCurrentLocale->dwId);
153
154 iCount = ComboBox_GetCount(hwndLayoutCombo);
155
156 for (iIndex = 0; iIndex < iCount; iIndex++)
157 {
158 LAYOUT_LIST_NODE *pCurrentLayout;
159
160 pCurrentLayout = (LAYOUT_LIST_NODE*)ComboBox_GetItemData(hwndLayoutCombo, iIndex);
161
162 if (pCurrentLayout != NULL && pCurrentLayout->dwId == dwLayoutId)
163 {
164 ComboBox_SetCurSel(hwndLayoutCombo, iIndex);
165 break;
166 }
167 }
168 }
169 }
170 }
171 break;
172 }
173 }
174
175
176 INT_PTR CALLBACK
177 AddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
178 {
179 switch (uMsg)
180 {
181 case WM_INITDIALOG:
182 OnInitAddDialog(hwndDlg);
183 break;
184
185 case WM_COMMAND:
186 OnCommandAddDialog(hwndDlg, wParam);
187 break;
188
189 case WM_DESTROY:
190 break;
191 }
192
193 return FALSE;
194 }