Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenadd.c
Go to the documentation of this file.
00001 /* 00002 * 00003 * PROJECT: input.dll 00004 * FILE: dll/win32/input/add.c 00005 * PURPOSE: input.dll 00006 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org) 00007 * Colin Finck 00008 * UPDATE HISTORY: 00009 * 06-09-2007 Created 00010 */ 00011 00012 #include "resource.h" 00013 #include "input.h" 00014 00015 static HWND hLangList; 00016 static HWND hLayoutList; 00017 00018 static VOID 00019 SelectLayoutByLang(VOID) 00020 { 00021 TCHAR Layout[MAX_PATH], Lang[MAX_PATH], LangID[CCH_LAYOUT_ID + 1]; 00022 INT iIndex; 00023 LCID Lcid; 00024 00025 iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0); 00026 Lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0); 00027 00028 GetLocaleInfo(MAKELCID(Lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR)); 00029 00030 wsprintf(LangID, _T("0000%s"), Lang); 00031 00032 if (GetLayoutName(LangID, Layout)) 00033 { 00034 SendMessage(hLayoutList, CB_SELECTSTRING, 00035 (WPARAM) -1, (LPARAM)Layout); 00036 } 00037 } 00038 00039 INT 00040 GetLayoutCount(LPTSTR szLang) 00041 { 00042 HKEY hKey; 00043 TCHAR szLayoutID[3 + 1], szPreload[CCH_LAYOUT_ID + 1], szLOLang[MAX_PATH]; 00044 DWORD dwIndex = 0, dwType, dwSize; 00045 UINT Count = 0, i, j; 00046 00047 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 00048 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 00049 { 00050 dwSize = sizeof(szLayoutID); 00051 00052 while (RegEnumValue(hKey, dwIndex, szLayoutID, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS) 00053 { 00054 dwSize = sizeof(szPreload); 00055 RegQueryValueEx(hKey, szLayoutID, NULL, NULL, (LPBYTE)szPreload, &dwSize); 00056 00057 for (i = 4, j = 0; i < _tcslen(szPreload)+1; i++, j++) 00058 szLOLang[j] = szPreload[i]; 00059 00060 if (_tcscmp(szLOLang, szLang) == 0) Count += 1; 00061 00062 dwSize = sizeof(szLayoutID); 00063 dwIndex++; 00064 } 00065 00066 RegCloseKey(hKey); 00067 } 00068 00069 return Count; 00070 } 00071 00072 static VOID 00073 AddNewLayout(HWND hwndDlg) 00074 { 00075 TCHAR NewLayout[CCH_ULONG_DEC + 1], Lang[MAX_PATH], 00076 LangID[CCH_LAYOUT_ID + 1], Layout[MAX_PATH], 00077 SubPath[CCH_LAYOUT_ID + 1], szMessage[MAX_PATH]; 00078 INT iLayout, iLang; 00079 HKEY hKey, hSubKey; 00080 DWORD cValues; 00081 PTSTR pts; 00082 LCID lcid; 00083 00084 iLayout = SendMessage(hLayoutList, CB_GETCURSEL, 0, 0); 00085 if (iLayout == CB_ERR) return; 00086 00087 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) 00088 { 00089 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &cValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00090 { 00091 _ultot(cValues + 1, NewLayout, 10); 00092 00093 iLang = SendMessage(hLangList, CB_GETCURSEL, 0, 0); 00094 lcid = SendMessage(hLangList, CB_GETITEMDATA, iLang, 0); 00095 pts = (PTSTR) SendMessage(hLayoutList, CB_GETITEMDATA, iLayout, 0); 00096 00097 GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR)); 00098 wsprintf(LangID, _T("0000%s"), Lang); 00099 00100 if (IsLayoutExists(pts, LangID)) 00101 { 00102 LoadString(hApplet, IDS_LAYOUT_EXISTS2, szMessage, sizeof(szMessage) / sizeof(TCHAR)); 00103 MessageBox(hwndDlg, szMessage, NULL, MB_OK | MB_ICONINFORMATION); 00104 00105 RegCloseKey(hKey); 00106 return; 00107 } 00108 00109 if (_tcscmp(LangID, pts) != 0) 00110 { 00111 if (!GetLayoutName(pts, Layout)) 00112 { 00113 RegCloseKey(hKey); 00114 return; 00115 } 00116 } 00117 else 00118 { 00119 if (!GetLayoutName(LangID, Layout)) 00120 { 00121 RegCloseKey(hKey); 00122 return; 00123 } 00124 } 00125 00126 if (SendMessage(hLayoutList, CB_SELECTSTRING, (WPARAM) -1, (LPARAM)Layout) != CB_ERR) 00127 { 00128 if (GetLayoutCount(Lang) >= 1) 00129 { 00130 wsprintf(SubPath, _T("d%03d%s"), GetLayoutCount(Lang), Lang); 00131 } 00132 else if ((_tcscmp(LangID, pts) != 0) && (GetLayoutCount(Lang) == 0)) 00133 { 00134 wsprintf(SubPath, _T("d%03d%s"), 0, Lang); 00135 } 00136 else SubPath[0] = '\0'; 00137 } 00138 else 00139 { 00140 RegCloseKey(hKey); 00141 return; 00142 } 00143 00144 if (_tcslen(SubPath) != 0) 00145 { 00146 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, NULL, 00147 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 00148 NULL, &hSubKey, NULL) == ERROR_SUCCESS) 00149 { 00150 if (RegSetValueEx(hSubKey, SubPath, 0, REG_SZ, (LPBYTE)pts, 00151 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) != ERROR_SUCCESS) 00152 { 00153 RegCloseKey(hSubKey); 00154 RegCloseKey(hKey); 00155 return; 00156 } 00157 RegCloseKey(hSubKey); 00158 } 00159 lstrcpy(pts, SubPath); 00160 } 00161 00162 if (RegSetValueEx(hKey, 00163 NewLayout, 00164 0, 00165 REG_SZ, 00166 (LPBYTE)pts, 00167 (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) == ERROR_SUCCESS) 00168 { 00169 UpdateLayoutsList(); 00170 } 00171 } 00172 RegCloseKey(hKey); 00173 } 00174 } 00175 00176 VOID 00177 CreateKeyboardLayoutList(HWND hItemsList) 00178 { 00179 HKEY hKey; 00180 PTSTR pstrLayoutID; 00181 TCHAR szLayoutID[CCH_LAYOUT_ID + 1], KeyName[MAX_PATH]; 00182 DWORD dwIndex = 0; 00183 DWORD dwSize; 00184 00185 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Keyboard Layouts"), 0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS) 00186 { 00187 dwSize = sizeof(szLayoutID) / sizeof(TCHAR); 00188 00189 while (RegEnumKeyEx(hKey, dwIndex, szLayoutID, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00190 { 00191 INT iIndex; 00192 00193 GetLayoutName(szLayoutID, KeyName); 00194 00195 iIndex = (INT) SendMessage(hItemsList, CB_ADDSTRING, 0, (LPARAM)KeyName); 00196 00197 pstrLayoutID = (PTSTR)HeapAlloc(hProcessHeap, 0, sizeof(szLayoutID)); 00198 lstrcpy(pstrLayoutID, szLayoutID); 00199 SendMessage(hItemsList, CB_SETITEMDATA, iIndex, (LPARAM)pstrLayoutID); 00200 00201 // FIXME! 00202 if (_tcscmp(szLayoutID, _T("00000409")) == 0) 00203 { 00204 SendMessage(hItemsList, CB_SETCURSEL, (WPARAM)iIndex, (LPARAM)0); 00205 } 00206 00207 dwIndex++; 00208 00209 dwSize = sizeof(szLayoutID) / sizeof(TCHAR); 00210 } 00211 00212 RegCloseKey(hKey); 00213 } 00214 } 00215 00216 /* Language enumerate procedure */ 00217 static BOOL CALLBACK 00218 LanguagesEnumProc(LPTSTR lpLanguage) 00219 { 00220 LCID Lcid; 00221 TCHAR Lang[1024]; 00222 INT Index; 00223 00224 Lcid = _tcstoul(lpLanguage, NULL, 16); 00225 00226 GetLocaleInfo(Lcid, LOCALE_SLANGUAGE, Lang, sizeof(Lang)); 00227 Index = (INT)SendMessage(hLangList, CB_ADDSTRING, 00228 0, (LPARAM)Lang); 00229 00230 SendMessage(hLangList, CB_SETITEMDATA, 00231 Index, (LPARAM)Lcid); 00232 00233 // FIXME! 00234 if (Lcid == 0x0409) 00235 { 00236 SendMessage(hLangList, CB_SELECTSTRING, 00237 (WPARAM) -1, (LPARAM)Lang); 00238 } 00239 00240 return TRUE; 00241 } 00242 00243 INT_PTR CALLBACK 00244 AddDlgProc(HWND hDlg, 00245 UINT message, 00246 WPARAM wParam, 00247 LPARAM lParam) 00248 { 00249 UNREFERENCED_PARAMETER(lParam); 00250 00251 switch (message) 00252 { 00253 case WM_INITDIALOG: 00254 { 00255 hLangList = GetDlgItem(hDlg, IDC_INPUT_LANG_COMBO); 00256 hLayoutList = GetDlgItem(hDlg, IDC_KEYBOARD_LO_COMBO); 00257 EnumSystemLocales(LanguagesEnumProc, LCID_INSTALLED); 00258 CreateKeyboardLayoutList(hLayoutList); 00259 } 00260 break; 00261 00262 case WM_COMMAND: 00263 { 00264 switch (LOWORD(wParam)) 00265 { 00266 case IDC_INPUT_LANG_COMBO: 00267 { 00268 if (HIWORD(wParam) == CBN_SELCHANGE) 00269 { 00270 SelectLayoutByLang(); 00271 } 00272 } 00273 break; 00274 00275 case IDOK: 00276 { 00277 AddNewLayout(hDlg); 00278 EndDialog(hDlg, LOWORD(wParam)); 00279 } 00280 break; 00281 00282 case IDCANCEL: 00283 { 00284 EndDialog(hDlg, LOWORD(wParam)); 00285 } 00286 } 00287 } 00288 break; 00289 00290 case WM_DESTROY: 00291 { 00292 INT iCount; 00293 00294 for(iCount = SendMessage(hLayoutList, CB_GETCOUNT, 0, 0); --iCount >= 0;) 00295 HeapFree(hProcessHeap, 0, (LPVOID)SendMessage(hLayoutList, CB_GETITEMDATA, iCount, 0)); 00296 } 00297 break; 00298 } 00299 00300 return FALSE; 00301 } 00302 00303 /* EOF */ Generated on Sun May 27 2012 04:18:46 for ReactOS by
1.7.6.1
|