Make it UNICODE-safe.
[reactos.git] / reactos / dll / cpl / input / settings.c
1 /*
2 * ReactOS
3 * Copyright (C) 2007 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 *
21 * PROJECT: input.dll
22 * FILE: dll/win32/input/settings.c
23 * PURPOSE: input.dll
24 * PROGRAMMER: Dmitry Chapyshev (lentind@yandex.ru)
25 * UPDATE HISTORY:
26 * 06-09-2007 Created
27 */
28
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <cpl.h>
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <tchar.h>
37 #include <process.h>
38
39 #include "resource.h"
40 #include "input.h"
41
42 #define BUFSIZE 80
43
44 static
45 BOOL
46 CreateDefaultLangList(HWND hWnd)
47 {
48 HKEY hKey;
49 TCHAR szPreload[BUFSIZE];
50 TCHAR szCount[BUFSIZE];
51 TCHAR Lang[BUFSIZE];
52 DWORD dwBufLen;
53 DWORD dwBufCLen;
54 DWORD cValues;
55 LONG lRet;
56 INT Count;
57 LCID Lcid;
58
59 if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Keyboard Layout\\Preload"), 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
60 {
61 return FALSE;
62 }
63
64 RegQueryInfoKey(hKey,NULL,NULL,NULL,NULL,NULL,NULL,&cValues,NULL,NULL,NULL,NULL);
65
66 if (cValues)
67 {
68 for (Count = 0; Count < cValues; Count++)
69 {
70 szCount[0] = TEXT('\0');
71
72 dwBufCLen = BUFSIZE;
73 lRet = RegEnumValue(hKey,Count,(LPTSTR)szCount,&dwBufCLen,NULL,NULL,NULL,NULL);
74
75 _stprintf(szCount,TEXT("%d"),Count + 1);
76
77 dwBufLen = BUFSIZE;
78 RegQueryValueEx(hKey,(LPTSTR)szCount,NULL,NULL,(LPBYTE)szPreload,&dwBufLen);
79
80 Lcid = _tcstoul(szPreload, NULL, 16);
81 GetLocaleInfo(Lcid, LOCALE_SLANGUAGE, (LPTSTR)Lang, sizeof(Lang));
82
83 SendMessage(hWnd,
84 CB_INSERTSTRING,
85 0,
86 (LPARAM)Lang);
87 if (Count == 0)
88 {
89 SendMessage(hWnd,
90 CB_SELECTSTRING,
91 (WPARAM) -1,
92 (LPARAM)Lang);
93 }
94 }
95
96 }
97
98 RegCloseKey(hKey);
99
100 return TRUE;
101 }
102
103 /* Property page dialog callback */
104 INT_PTR CALLBACK
105 SettingPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
106 {
107 UNREFERENCED_PARAMETER(lParam);
108
109 switch (uMsg)
110 {
111 case WM_INITDIALOG:
112 CreateDefaultLangList(GetDlgItem(hwndDlg, IDC_DEFAULT_INPUT_LANG));
113 break;
114
115 case WM_COMMAND:
116 switch (LOWORD(wParam))
117 {
118 case IDC_LANG_BAR_BUTTON:
119 DialogBox(hApplet,
120 MAKEINTRESOURCE(IDD_LANGBAR),
121 hwndDlg,
122 LangBarDlgProc);
123 break;
124
125 case IDC_KEY_SETTINGS_BUTTON:
126 DialogBox(hApplet,
127 MAKEINTRESOURCE(IDD_KEYSETTINGS),
128 hwndDlg,
129 KeySettingsDlgProc);
130 break;
131
132 case IDC_ADD_BUTTON:
133 DialogBox(hApplet,
134 MAKEINTRESOURCE(IDD_ADD),
135 hwndDlg,
136 AddDlgProc);
137 break;
138
139 case IDC_PROP_BUTTON:
140 DialogBox(hApplet,
141 MAKEINTRESOURCE(IDD_INPUT_LANG_PROP),
142 hwndDlg,
143 InputLangPropDlgProc);
144 break;
145
146 case IDC_DEFAULT_INPUT_LANG:
147 if (HIWORD(wParam) == CBN_SELCHANGE)
148 {
149 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
150 }
151 break;
152 }
153 break;
154 }
155
156 return FALSE;
157 }
158
159 /* EOF */