58642f54a8629d9bb94f7012c1f92c1f7643a78c
[reactos.git] / dll / cpl / input / settings.c
1 /*
2 *
3 * PROJECT: input.dll
4 * FILE: dll/win32/input/settings.c
5 * PURPOSE: input.dll
6 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
7 * Colin Finck
8 * UPDATE HISTORY:
9 * 06-09-2007 Created
10 */
11
12 #include "resource.h"
13 #include "input.h"
14
15 static HWND MainDlgWnd;
16 static HIMAGELIST hImgList;
17 // for SaveInputLang()
18 static INT OldLayoutNum;
19
20 typedef struct
21 {
22 LANGID LangId;
23 TCHAR LangName[MAX_PATH];
24 TCHAR LayoutName[MAX_PATH];
25 TCHAR ValName[CCH_ULONG_DEC + 1];
26 TCHAR IndName[MAX_PATH];
27 } LAYOUT_ITEM, *LPLAYOUT_ITEM;
28
29
30 static INT
31 IsLayoutSelected()
32 {
33 INT iIndex = (INT) SendMessage(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST),
34 LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
35
36 return iIndex;
37 }
38
39 BOOL
40 IsLayoutExists(LPTSTR szLayoutID, LPTSTR szLangID)
41 {
42 HKEY hKey, hSubKey;
43 TCHAR szPreload[CCH_LAYOUT_ID + 1], szLayoutNum[3 + 1],
44 szTmp[CCH_LAYOUT_ID + 1], szOldLangID[CCH_LAYOUT_ID + 1];
45 DWORD dwIndex = 0, dwType, dwSize;
46 BOOL IsLangExists = FALSE;
47 LANGID langid;
48
49 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
50 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
51 {
52 dwSize = sizeof(szLayoutNum);
53
54 while (RegEnumValue(hKey, dwIndex, szLayoutNum, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
55 {
56 dwSize = sizeof(szPreload);
57 if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize) != ERROR_SUCCESS)
58 {
59 RegCloseKey(hKey);
60 return FALSE;
61 }
62
63 langid = (LANGID)_tcstoul(szPreload, NULL, 16);
64 GetLocaleInfo(langid, LOCALE_ILANGUAGE, szTmp, sizeof(szTmp) / sizeof(TCHAR));
65 wsprintf(szOldLangID, _T("0000%s"), szTmp);
66
67 if (_tcscmp(szOldLangID, szLangID) == 0)
68 IsLangExists = TRUE;
69 else
70 IsLangExists = FALSE;
71
72 if (szPreload[0] == 'd')
73 {
74 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"),
75 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
76 {
77 dwSize = sizeof(szTmp);
78 RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szTmp, &dwSize);
79
80 if ((_tcscmp(szTmp, szLayoutID) == 0)&&(IsLangExists))
81 {
82 RegCloseKey(hSubKey);
83 RegCloseKey(hKey);
84 return TRUE;
85 }
86 }
87 }
88 else
89 {
90 if ((_tcscmp(szPreload, szLayoutID) == 0) && (IsLangExists))
91 {
92 RegCloseKey(hKey);
93 return TRUE;
94 }
95 }
96
97 IsLangExists = FALSE;
98 dwSize = sizeof(szLayoutNum);
99 dwIndex++;
100 }
101
102 RegCloseKey(hKey);
103 }
104
105 return FALSE;
106 }
107
108 static HICON
109 CreateLayoutIcon(LPTSTR szInd)
110 {
111 HDC hdc, hdcsrc;
112 HBITMAP hBitmap, hBmpNew, hBmpOld;
113 RECT rect;
114 DWORD bkColor, bkText;
115 HFONT hFont = NULL;
116 ICONINFO IconInfo;
117 HICON hIcon = NULL;
118
119 hdcsrc = GetDC(NULL);
120 hdc = CreateCompatibleDC(hdcsrc);
121 hBitmap = CreateCompatibleBitmap(hdcsrc, 16, 16);
122 ReleaseDC(NULL, hdcsrc);
123
124 if (hdc && hBitmap)
125 {
126 hBmpNew = CreateBitmap(16, 16, 1, 1, NULL);
127 if (hBmpNew)
128 {
129 hBmpOld = SelectObject(hdc, hBitmap);
130 rect.right = 16;
131 rect.left = 0;
132 rect.bottom = 16;
133 rect.top = 0;
134
135 bkColor = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
136 bkText = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
137
138 ExtTextOut(hdc, rect.left, rect.top, ETO_OPAQUE, &rect, _T(""), 0, NULL);
139
140 hFont = CreateFont(-11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
141 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
142 DEFAULT_QUALITY, FF_DONTCARE, _T("Tahoma"));
143
144 SelectObject(hdc, hFont);
145 DrawText(hdc, _tcsupr(szInd), 2, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
146 SelectObject(hdc, hBmpNew);
147 PatBlt(hdc, 0, 0, 16, 16, BLACKNESS);
148 SelectObject(hdc, hBmpOld);
149
150 IconInfo.hbmColor = hBitmap;
151 IconInfo.hbmMask = hBmpNew;
152 IconInfo.fIcon = TRUE;
153
154 hIcon = CreateIconIndirect(&IconInfo);
155
156 DeleteObject(hBmpNew);
157 DeleteObject(hBmpOld);
158 DeleteObject(hFont);
159 }
160 }
161
162 DeleteDC(hdc);
163 DeleteObject(hBitmap);
164
165 return hIcon;
166 }
167
168 static BOOL
169 GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID)
170 {
171 DWORD dwBufLen;
172 DWORD dwRes;
173 HKEY hKey;
174 TCHAR szTempLCID[CCH_LAYOUT_ID + 1];
175
176 // Get the Layout ID
177 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
178 {
179 dwBufLen = sizeof(szTempLCID);
180 dwRes = RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID, &dwBufLen);
181
182 if (dwRes != ERROR_SUCCESS)
183 {
184 RegCloseKey(hKey);
185 return FALSE;
186 }
187
188 RegCloseKey(hKey);
189 }
190
191 // Look for a substitude of this layout
192 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
193 {
194 dwBufLen = sizeof(szTempLCID);
195
196 if (RegQueryValueEx(hKey, szTempLCID, NULL, NULL, (LPBYTE)szLCID, &dwBufLen) != ERROR_SUCCESS)
197 {
198 // No substitute found, then use the old LCID
199 lstrcpy(szLCID, szTempLCID);
200 }
201
202 RegCloseKey(hKey);
203 }
204 else
205 {
206 // Substitutes key couldn't be opened, so use the old LCID
207 lstrcpy(szLCID, szTempLCID);
208 }
209
210 return TRUE;
211 }
212
213 BOOL
214 GetLayoutName(LPCTSTR szLCID, LPTSTR szName)
215 {
216 HKEY hKey;
217 DWORD dwBufLen;
218 TCHAR szBuf[MAX_PATH], szDispName[MAX_PATH], szIndex[MAX_PATH], szPath[MAX_PATH];
219 HANDLE hLib;
220 unsigned i, j, k;
221
222 wsprintf(szBuf, _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szLCID);
223
224 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)szBuf, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
225 {
226 dwBufLen = sizeof(szBuf);
227
228 if (RegQueryValueEx(hKey, _T("Layout Display Name"), NULL, NULL, (LPBYTE)szDispName, &dwBufLen) == ERROR_SUCCESS)
229 {
230 if (szDispName[0] == '@')
231 {
232 for (i = 0; i < _tcslen(szDispName); i++)
233 {
234 if ((szDispName[i] == ',') && (szDispName[i + 1] == '-'))
235 {
236 for (j = i + 2, k = 0; j < _tcslen(szDispName)+1; j++, k++)
237 {
238 szIndex[k] = szDispName[j];
239 }
240 szDispName[i - 1] = '\0';
241 break;
242 }
243 else szDispName[i] = szDispName[i + 1];
244 }
245
246 if (ExpandEnvironmentStrings(szDispName, szPath, MAX_PATH))
247 {
248 hLib = LoadLibrary(szPath);
249 if (hLib)
250 {
251 if (LoadString(hLib, _ttoi(szIndex), szPath, sizeof(szPath) / sizeof(TCHAR)) != 0)
252 {
253 _tcscpy(szName, szPath);
254 RegCloseKey(hKey);
255 return TRUE;
256 }
257 FreeLibrary(hLib);
258 }
259 }
260 }
261 }
262
263 dwBufLen = sizeof(szBuf);
264
265 if (RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL, (LPBYTE)szName, &dwBufLen) == ERROR_SUCCESS)
266 {
267 RegCloseKey(hKey);
268 return TRUE;
269 }
270 }
271
272 return FALSE;
273 }
274
275 static VOID
276 AddListColumn(HWND hWnd)
277 {
278 LV_COLUMN column;
279 TCHAR szBuf[MAX_PATH];
280 HWND hList = GetDlgItem(hWnd, IDC_KEYLAYOUT_LIST);
281
282 ZeroMemory(&column, sizeof(LV_COLUMN));
283 column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
284
285 column.fmt = LVCFMT_LEFT;
286 column.iSubItem = 0;
287 LoadString(hApplet, IDS_LANGUAGE, szBuf, sizeof(szBuf) / sizeof(TCHAR));
288 column.pszText = szBuf;
289 column.cx = 175;
290 (VOID) ListView_InsertColumn(hList, 0, &column);
291
292 column.fmt = LVCFMT_RIGHT;
293 column.cx = 155;
294 column.iSubItem = 1;
295 LoadString(hApplet, IDS_LAYOUT, szBuf, sizeof(szBuf) / sizeof(TCHAR));
296 column.pszText = szBuf;
297 (VOID) ListView_InsertColumn(hList, 1, &column);
298 }
299
300 static VOID
301 InitLangList(HWND hWnd)
302 {
303 HKEY hKey, hSubKey;
304 TCHAR szBuf[MAX_PATH], szPreload[CCH_LAYOUT_ID + 1], szSub[CCH_LAYOUT_ID + 1];
305 LAYOUT_ITEM lItem;
306 DWORD dwIndex = 0, dwType, dwSize;
307 LV_ITEM item = {0};
308 HWND hList = GetDlgItem(hWnd, IDC_KEYLAYOUT_LIST);
309 INT i, imgIndex;
310
311 item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
312
313 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
314 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
315 {
316 dwSize = sizeof(lItem.ValName);
317
318 while (RegEnumValue(hKey, dwIndex, lItem.ValName, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
319 {
320 dwSize = sizeof(szPreload);
321 RegQueryValueEx(hKey, lItem.ValName, NULL, NULL, (LPBYTE)szPreload, &dwSize);
322
323 lItem.LangId = (LANGID)_tcstoul(szPreload, NULL, 16);
324
325 GetLocaleInfo(lItem.LangId, LOCALE_SISO639LANGNAME, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR));
326 lstrcpy(lItem.IndName, _tcsupr(szBuf));
327 imgIndex = ImageList_AddIcon(hImgList, CreateLayoutIcon(lItem.IndName));
328
329 GetLocaleInfo(lItem.LangId, LOCALE_SLANGUAGE, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR));
330 lstrcpy(lItem.LangName, szBuf);
331
332 // Does this keyboard layout have a substitute?
333 // Then add the substitute instead of the Layout ID
334 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"),
335 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
336 {
337 dwSize = sizeof(szSub);
338
339 if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szSub, &dwSize) == ERROR_SUCCESS)
340 {
341 lstrcpy(szPreload, szSub);
342 }
343
344 RegCloseKey(hSubKey);
345 }
346
347 GetLayoutName(szPreload, lItem.LayoutName);
348
349 item.pszText = lItem.LangName;
350 item.iItem = (INT) dwIndex;
351 item.lParam = (LPARAM)_ttoi(lItem.ValName);
352 item.iImage = imgIndex;
353 i = ListView_InsertItem(hList, &item);
354
355 ListView_SetItemText(hList, i, 1, lItem.LayoutName);
356
357 dwIndex++;
358
359 if (lstrcmp(lItem.ValName, _T("1")) == 0)
360 {
361 (VOID) ListView_SetHotItem(hList, i);
362 }
363 }
364
365 RegCloseKey(hKey);
366 }
367 }
368
369 VOID
370 UpdateLayoutsList(VOID)
371 {
372 (VOID) ImageList_Destroy(hImgList);
373 (VOID) ListView_DeleteAllItems(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST));
374 hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 0, 1);
375 InitLangList(MainDlgWnd);
376 (VOID) ListView_SetImageList(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), hImgList, LVSIL_SMALL);
377 }
378
379 static VOID
380 DeleteLayout(VOID)
381 {
382 INT iIndex, LayoutNum;
383 LVITEM item;
384 HKEY hKey, hSubKey;
385 HWND hLayoutList = GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST);
386 TCHAR szLayoutNum[3 + 1], szTitle[MAX_PATH],
387 szConf[MAX_PATH], szPreload[CCH_LAYOUT_ID + 1];
388 DWORD dwSize;
389
390 iIndex = (INT) SendMessage(hLayoutList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
391
392 if (iIndex != -1)
393 {
394 LoadString(hApplet, IDS_REM_QUESTION, szConf, sizeof(szConf) / sizeof(TCHAR));
395 LoadString(hApplet, IDS_CONFIRMATION, szTitle, sizeof(szTitle) / sizeof(TCHAR));
396
397 if (MessageBox(MainDlgWnd, szConf, szTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
398 {
399 ZeroMemory(&item, sizeof(LVITEM));
400
401 item.mask = LVIF_PARAM;
402 item.iItem = iIndex;
403
404 (VOID) ListView_GetItem(hLayoutList, &item);
405 LayoutNum = (INT) item.lParam;
406
407 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
408 KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
409 {
410 _ultot(LayoutNum, szLayoutNum, 10);
411
412 dwSize = sizeof(szPreload);
413 RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize);
414
415 if (szPreload[0] == 'd')
416 {
417 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
418 KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
419 {
420 if (RegDeleteValue(hSubKey, szPreload) != ERROR_SUCCESS)
421 {
422 RegCloseKey(hSubKey);
423 RegCloseKey(hKey);
424 return;
425 }
426 RegCloseKey(hSubKey);
427 }
428 }
429
430 if (RegDeleteValue(hKey, szLayoutNum) == ERROR_SUCCESS)
431 {
432 UpdateLayoutsList();
433 }
434 }
435 RegCloseKey(hKey);
436 }
437 }
438 }
439
440 static VOID
441 SetDefaultLayout()
442 {
443 HKL hKl;
444 TCHAR szLCID[CCH_LAYOUT_ID + 1], szLayoutNum[CCH_ULONG_DEC + 1];
445 LVITEM item;
446 INT LayoutNum;
447
448 if (IsLayoutSelected() != -1)
449 {
450 ZeroMemory(&item, sizeof(LVITEM));
451
452 item.mask = LVIF_PARAM;
453 item.iItem = IsLayoutSelected();
454
455 (VOID) ListView_GetItem(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), &item);
456
457 LayoutNum = (INT) item.lParam;
458 _ultot(LayoutNum, szLayoutNum, 10);
459
460 if (GetLayoutID(szLayoutNum, szLCID))
461 {
462 hKl = LoadKeyboardLayout(szLCID, KLF_ACTIVATE);
463 SystemParametersInfo(SPI_SETDEFAULTINPUTLANG, 0, &hKl, SPIF_SENDWININICHANGE);
464 }
465 }
466 }
467
468 static VOID
469 SaveInputLang(HWND hDlg)
470 {
471 HKEY hKey, hSubKey;
472 TCHAR szLayoutID[CCH_LAYOUT_ID + 1], szLayoutNum[CCH_ULONG_DEC + 1],
473 szPreload[CCH_LAYOUT_ID + 1], LangID[CCH_LAYOUT_ID + 1], szMessage[MAX_PATH],
474 Lang[MAX_PATH], SubPath[MAX_PATH];
475 PTSTR pts;
476 INT iLayout;
477 DWORD dwSize;
478 LANGID langid;
479
480 iLayout = SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO), CB_GETCURSEL, 0, 0);
481 if (iLayout == CB_ERR) return;
482
483 pts = (PTSTR) SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO), CB_GETITEMDATA, iLayout, 0);
484
485 _ultot(OldLayoutNum, szLayoutNum, 10);
486 if (!GetLayoutID(szLayoutNum, szLayoutID)) return;
487
488 // if old layout = selected layout
489 if (_tcscmp(szLayoutID, pts) == 0) return;
490
491 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
492 KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
493 {
494 dwSize = sizeof(szPreload);
495 if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize) != ERROR_SUCCESS)
496 {
497 RegCloseKey(hKey);
498 return;
499 }
500
501 langid = (LANGID)_tcstoul(szPreload, NULL, 16);
502 GetLocaleInfo(langid, LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR));
503 wsprintf(LangID, _T("0000%s"), Lang);
504
505 if (IsLayoutExists(pts, LangID))
506 {
507 LoadString(hApplet, IDS_LAYOUT_EXISTS, szMessage, sizeof(szMessage) / sizeof(TCHAR));
508 MessageBox(hDlg, szMessage, NULL, MB_OK | MB_ICONINFORMATION);
509
510 RegCloseKey(hKey);
511 return;
512 }
513
514 if (szPreload[0] == 'd')
515 {
516 if (_tcscmp(LangID, pts) == 0)
517 {
518 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
519 KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
520 {
521 if (RegDeleteValue(hSubKey, szPreload) != ERROR_SUCCESS)
522 {
523 RegCloseKey(hSubKey);
524 RegCloseKey(hKey);
525 return;
526 }
527 RegCloseKey(hSubKey);
528
529 RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)pts,
530 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
531 }
532 }
533 else
534 {
535 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
536 KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
537 {
538 RegSetValueEx(hSubKey, szPreload, 0, REG_SZ, (LPBYTE)pts,
539 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
540
541 RegCloseKey(hSubKey);
542 }
543 }
544 }
545 else
546 {
547 if (_tcscmp(LangID, pts) == 0)
548 {
549 RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)pts,
550 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
551 }
552 else
553 {
554 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, NULL,
555 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
556 NULL, &hSubKey, NULL) == ERROR_SUCCESS)
557 {
558 wsprintf(SubPath, _T("d%03d%s"), GetLayoutCount(Lang)-1, Lang);
559
560 RegSetValueEx(hSubKey, SubPath, 0, REG_SZ, (LPBYTE)pts,
561 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
562
563 RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)SubPath,
564 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
565
566 RegCloseKey(hSubKey);
567 }
568 }
569 }
570
571 RegCloseKey(hKey);
572 }
573 }
574
575 static VOID
576 InitInputLangPropDlg(HWND hDlg)
577 {
578 HKEY hKey, hSubKey;
579 LVITEM item;
580 INT LayoutNum;
581 TCHAR szLayoutNum[10 + 1], szPreload[CCH_LAYOUT_ID + 1],
582 szTmp[CCH_LAYOUT_ID + 1], szName[MAX_PATH];
583 DWORD dwSize;
584 LANGID langid;
585
586 ZeroMemory(&item, sizeof(LVITEM));
587
588 item.mask = LVIF_PARAM;
589 item.iItem = IsLayoutSelected();
590
591 (VOID) ListView_GetItem(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), &item);
592 LayoutNum = (INT) item.lParam;
593 OldLayoutNum = LayoutNum;
594
595 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
596 KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
597 {
598 _ultot(LayoutNum, szLayoutNum, 10);
599
600 dwSize = sizeof(szPreload);
601 RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize);
602
603 langid = (LANGID)_tcstoul(szPreload, NULL, 16);
604 GetLocaleInfo(langid, LOCALE_SLANGUAGE, (LPTSTR)szName, sizeof(szName) / sizeof(TCHAR));
605 SetWindowText(GetDlgItem(hDlg, IDC_INPUT_LANG_STR), szName);
606
607 if (szPreload[0] == 'd')
608 {
609 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
610 KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
611 {
612 if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szTmp, &dwSize) != ERROR_SUCCESS)
613 {
614 RegCloseKey(hSubKey);
615 RegCloseKey(hKey);
616 return;
617 }
618 lstrcpy(szPreload, szTmp);
619 RegCloseKey(hSubKey);
620 }
621 }
622
623 if (GetLayoutName(szPreload, szName))
624 {
625 SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO),
626 CB_SELECTSTRING, (WPARAM)-1, (LPARAM)szName);
627 }
628 }
629 RegCloseKey(hKey);
630 }
631
632 INT_PTR CALLBACK
633 InputLangPropDlgProc(HWND hDlg,
634 UINT message,
635 WPARAM wParam,
636 LPARAM lParam)
637 {
638 UNREFERENCED_PARAMETER(lParam);
639
640 switch (message)
641 {
642 case WM_INITDIALOG:
643 CreateKeyboardLayoutList(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO));
644 InitInputLangPropDlg(hDlg);
645 break;
646
647 case WM_COMMAND:
648 switch (LOWORD(wParam))
649 {
650 case IDOK:
651 SaveInputLang(hDlg);
652 UpdateLayoutsList();
653 EndDialog(hDlg,LOWORD(wParam));
654 break;
655
656 case IDCANCEL:
657 EndDialog(hDlg,LOWORD(wParam));
658 break;
659 }
660 break;
661 }
662
663 return FALSE;
664 }
665
666 /* Property page dialog callback */
667 INT_PTR CALLBACK
668 SettingPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
669 {
670 UNREFERENCED_PARAMETER(lParam);
671
672 switch (uMsg)
673 {
674 case WM_INITDIALOG:
675 {
676 MainDlgWnd = hwndDlg;
677 AddListColumn(hwndDlg);
678 (VOID) ListView_SetExtendedListViewStyle(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST),
679 LVS_EX_FULLROWSELECT);
680 hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 0, 1);
681 InitLangList(hwndDlg);
682 (VOID) ListView_SetImageList(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), hImgList, LVSIL_SMALL);
683 }
684 break;
685 case WM_NOTIFY:
686 {
687 switch (LOWORD(wParam))
688 {
689
690 }
691 }
692 break;
693 case WM_COMMAND:
694 switch (LOWORD(wParam))
695 {
696 case IDC_REMOVE_BUTTON:
697 DeleteLayout();
698 break;
699
700 case IDC_KEY_SET_BTN:
701 DialogBox(hApplet,
702 MAKEINTRESOURCE(IDD_KEYSETTINGS),
703 hwndDlg,
704 KeySettingsDlgProc);
705 break;
706
707 case IDC_ADD_BUTTON:
708 DialogBox(hApplet,
709 MAKEINTRESOURCE(IDD_ADD),
710 hwndDlg,
711 AddDlgProc);
712 break;
713
714 case IDC_PROP_BUTTON:
715 if (IsLayoutSelected() != -1)
716 DialogBox(hApplet,
717 MAKEINTRESOURCE(IDD_INPUT_LANG_PROP),
718 hwndDlg,
719 InputLangPropDlgProc);
720 break;
721
722 case IDC_SET_DEFAULT:
723 SetDefaultLayout();
724 UpdateLayoutsList();
725 break;
726 }
727 break;
728 case WM_DESTROY:
729 (VOID) ImageList_Destroy(hImgList);
730 break;
731 }
732
733 return FALSE;
734 }
735
736 /* EOF */