ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

settings.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * PROJECT:         input.dll
00004  * FILE:            dll/win32/input/settings.c
00005  * PURPOSE:         input.dll
00006  * PROGRAMMER:      Dmitry Chapyshev (dmitry@reactos.org)
00007  *                  Colin Finck
00008  *                  Gregor Schneider
00009  * UPDATE HISTORY:
00010  *      06-09-2007  Created
00011  */
00012 
00013 #include "input.h"
00014 
00015 static HWND MainDlgWnd;
00016 // for SaveInputLang()
00017 static INT OldLayoutNum;
00018 
00019 typedef struct
00020 {
00021     LANGID LangId;
00022     TCHAR LangName[MAX_PATH];
00023     TCHAR LayoutName[MAX_PATH];
00024     TCHAR ValName[CCH_ULONG_DEC + 1];
00025     TCHAR IndName[MAX_PATH];
00026 } LAYOUT_ITEM, *LPLAYOUT_ITEM;
00027 
00028 
00029 static INT
00030 IsLayoutSelected()
00031 {
00032     INT iIndex = (INT) SendMessage(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST),
00033                                    LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
00034 
00035     return iIndex;
00036 }
00037 
00038 BOOL
00039 IsLayoutExists(LPTSTR szLayoutID, LPTSTR szLangID)
00040 {
00041     HKEY hKey, hSubKey;
00042     TCHAR szPreload[CCH_LAYOUT_ID + 1], szLayoutNum[3 + 1],
00043           szTmp[CCH_LAYOUT_ID + 1], szOldLangID[CCH_LAYOUT_ID + 1];
00044     DWORD dwIndex = 0, dwType, dwSize;
00045     BOOL IsLangExists = FALSE;
00046     LANGID langid;
00047 
00048     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
00049         0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00050     {
00051         dwSize = sizeof(szLayoutNum);
00052 
00053         while (RegEnumValue(hKey, dwIndex, szLayoutNum, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
00054         {
00055             dwSize = sizeof(szPreload);
00056             if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize) != ERROR_SUCCESS)
00057             {
00058                 RegCloseKey(hKey);
00059                 return FALSE;
00060             }
00061 
00062             langid = (LANGID)_tcstoul(szPreload, NULL, 16);
00063             GetLocaleInfo(langid, LOCALE_ILANGUAGE, szTmp, sizeof(szTmp) / sizeof(TCHAR));
00064             wsprintf(szOldLangID, _T("0000%s"), szTmp);
00065 
00066             if (_tcscmp(szOldLangID, szLangID) == 0)
00067                 IsLangExists = TRUE;
00068             else
00069                 IsLangExists = FALSE;
00070 
00071             if (szPreload[0] == 'd')
00072             {
00073                 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"),
00074                                  0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
00075                 {
00076                     dwSize = sizeof(szTmp);
00077                     RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szTmp, &dwSize);
00078 
00079                     if ((_tcscmp(szTmp, szLayoutID) == 0)&&(IsLangExists))
00080                     {
00081                         RegCloseKey(hSubKey);
00082                         RegCloseKey(hKey);
00083                         return TRUE;
00084                     }
00085                 }
00086             }
00087             else
00088             {
00089                 if ((_tcscmp(szPreload, szLayoutID) == 0) && (IsLangExists))
00090                 {
00091                     RegCloseKey(hKey);
00092                     return TRUE;
00093                 }
00094             }
00095 
00096             IsLangExists = FALSE;
00097             dwSize = sizeof(szLayoutNum);
00098             dwIndex++;
00099         }
00100 
00101         RegCloseKey(hKey);
00102     }
00103 
00104     return FALSE;
00105 }
00106 
00107 static HICON
00108 CreateLayoutIcon(LPTSTR szInd)
00109 {
00110     HDC hdc, hdcsrc;
00111     HBITMAP hBitmap, hBmpNew, hBmpOld;
00112     RECT rect;
00113     HFONT hFont = NULL;
00114     ICONINFO IconInfo;
00115     HICON hIcon = NULL;
00116 
00117     hdcsrc = GetDC(NULL);
00118     hdc = CreateCompatibleDC(hdcsrc);
00119     hBitmap = CreateCompatibleBitmap(hdcsrc, 16, 16);
00120     ReleaseDC(NULL, hdcsrc);
00121 
00122     if (hdc && hBitmap)
00123     {
00124         hBmpNew = CreateBitmap(16, 16, 1, 1, NULL);
00125         if (hBmpNew)
00126         {
00127             hBmpOld = SelectObject(hdc, hBitmap);
00128             rect.right = 16;
00129             rect.left = 0;
00130             rect.bottom = 16;
00131             rect.top = 0;
00132 
00133             SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
00134             SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
00135 
00136             ExtTextOut(hdc, rect.left, rect.top, ETO_OPAQUE, &rect, _T(""), 0, NULL);
00137 
00138             hFont = CreateFont(-11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
00139                                OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
00140                                DEFAULT_QUALITY, FF_DONTCARE, _T("Tahoma"));
00141 
00142             SelectObject(hdc, hFont);
00143             DrawText(hdc, _tcsupr(szInd), 2, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
00144             SelectObject(hdc, hBmpNew);
00145             PatBlt(hdc, 0, 0, 16, 16, BLACKNESS);
00146             SelectObject(hdc, hBmpOld);
00147 
00148             IconInfo.hbmColor = hBitmap;
00149             IconInfo.hbmMask = hBmpNew;
00150             IconInfo.fIcon = TRUE;
00151 
00152             hIcon = CreateIconIndirect(&IconInfo);
00153 
00154             DeleteObject(hBmpNew);
00155             DeleteObject(hBmpOld);
00156             DeleteObject(hFont);
00157         }
00158     }
00159 
00160     DeleteDC(hdc);
00161     DeleteObject(hBitmap);
00162 
00163     return hIcon;
00164 }
00165 
00166 static BOOL
00167 GetLayoutID(LPTSTR szLayoutNum, LPTSTR szLCID)
00168 {
00169     DWORD dwBufLen;
00170     DWORD dwRes;
00171     HKEY hKey;
00172     TCHAR szTempLCID[CCH_LAYOUT_ID + 1];
00173 
00174     // Get the Layout ID
00175     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00176     {
00177         dwBufLen = sizeof(szTempLCID);
00178         dwRes = RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szTempLCID, &dwBufLen);
00179 
00180         if (dwRes != ERROR_SUCCESS)
00181         {
00182             RegCloseKey(hKey);
00183             return FALSE;
00184         }
00185 
00186         RegCloseKey(hKey);
00187     }
00188 
00189     // Look for a substitude of this layout
00190     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00191     {
00192         dwBufLen = sizeof(szTempLCID);
00193 
00194         if (RegQueryValueEx(hKey, szTempLCID, NULL, NULL, (LPBYTE)szLCID, &dwBufLen) != ERROR_SUCCESS)
00195         {
00196             // No substitute found, then use the old LCID
00197             lstrcpy(szLCID, szTempLCID);
00198         }
00199 
00200         RegCloseKey(hKey);
00201     }
00202     else
00203     {
00204         // Substitutes key couldn't be opened, so use the old LCID
00205         lstrcpy(szLCID, szTempLCID);
00206     }
00207 
00208     return TRUE;
00209 }
00210 
00211 BOOL
00212 GetLayoutName(LPCTSTR szLCID, LPTSTR szName)
00213 {
00214     HKEY hKey;
00215     DWORD dwBufLen;
00216     TCHAR szBuf[MAX_PATH], szDispName[MAX_PATH], szIndex[MAX_PATH], szPath[MAX_PATH];
00217     HANDLE hLib;
00218     unsigned i, j, k;
00219 
00220     wsprintf(szBuf, _T("SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s"), szLCID);
00221 
00222     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)szBuf, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00223     {
00224         dwBufLen = sizeof(szBuf);
00225 
00226         if (RegQueryValueEx(hKey, _T("Layout Display Name"), NULL, NULL, (LPBYTE)szDispName, &dwBufLen) == ERROR_SUCCESS)
00227         {
00228             if (szDispName[0] == '@')
00229             {
00230                 for (i = 0; i < _tcslen(szDispName); i++)
00231                 {
00232                     if ((szDispName[i] == ',') && (szDispName[i + 1] == '-'))
00233                     {
00234                         for (j = i + 2, k = 0; j < _tcslen(szDispName)+1; j++, k++)
00235                         {
00236                             szIndex[k] = szDispName[j];
00237                         }
00238                         szDispName[i - 1] = '\0';
00239                         break;
00240                     }
00241                     else szDispName[i] = szDispName[i + 1];
00242                 }
00243 
00244                 if (ExpandEnvironmentStrings(szDispName, szPath, MAX_PATH))
00245                 {
00246                     hLib = LoadLibrary(szPath);
00247                     if (hLib)
00248                     {
00249                         if (LoadString(hLib, _ttoi(szIndex), szPath, sizeof(szPath) / sizeof(TCHAR)) != 0)
00250                         {
00251                             _tcscpy(szName, szPath);
00252                             RegCloseKey(hKey);
00253                             return TRUE;
00254                         }
00255                         FreeLibrary(hLib);
00256                     }
00257                 }
00258             }
00259         }
00260 
00261         dwBufLen = sizeof(szBuf);
00262 
00263         if (RegQueryValueEx(hKey, _T("Layout Text"), NULL, NULL, (LPBYTE)szName, &dwBufLen) == ERROR_SUCCESS)
00264         {
00265             RegCloseKey(hKey);
00266             return TRUE;
00267         }
00268     }
00269 
00270     return FALSE;
00271 }
00272 
00273 static VOID
00274 AddListColumn(HWND hWnd)
00275 {
00276     LV_COLUMN column;
00277     TCHAR szBuf[MAX_PATH];
00278     HWND hList = GetDlgItem(hWnd, IDC_KEYLAYOUT_LIST);
00279 
00280     ZeroMemory(&column, sizeof(LV_COLUMN));
00281     column.mask         = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
00282 
00283     column.fmt          = LVCFMT_LEFT;
00284     column.iSubItem     = 0;
00285     LoadString(hApplet, IDS_LANGUAGE, szBuf, sizeof(szBuf) / sizeof(TCHAR));
00286     column.pszText      = szBuf;
00287     column.cx           = 175;
00288     (VOID) ListView_InsertColumn(hList, 0, &column);
00289 
00290     column.fmt          = LVCFMT_RIGHT;
00291     column.cx           = 155;
00292     column.iSubItem     = 1;
00293     LoadString(hApplet, IDS_LAYOUT, szBuf, sizeof(szBuf) / sizeof(TCHAR));
00294     column.pszText      = szBuf;
00295     (VOID) ListView_InsertColumn(hList, 1, &column);
00296 }
00297 
00298 static VOID
00299 InitLangList(HWND hWnd, HIMAGELIST hImgList)
00300 {
00301     HKEY hKey, hSubKey;
00302     TCHAR szBuf[MAX_PATH], szPreload[CCH_LAYOUT_ID + 1], szSub[CCH_LAYOUT_ID + 1];
00303     LAYOUT_ITEM lItem;
00304     DWORD dwIndex = 0, dwType, dwSize;
00305     LV_ITEM item = {0};
00306     HWND hList = GetDlgItem(hWnd, IDC_KEYLAYOUT_LIST);
00307     INT i, imgIndex;
00308 
00309     item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
00310 
00311     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
00312         0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00313     {
00314         dwSize = sizeof(lItem.ValName);
00315 
00316         while (RegEnumValue(hKey, dwIndex, lItem.ValName, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
00317         {
00318             dwSize = sizeof(szPreload);
00319             RegQueryValueEx(hKey, lItem.ValName, NULL, NULL, (LPBYTE)szPreload, &dwSize);
00320 
00321             lItem.LangId = (LANGID)_tcstoul(szPreload, NULL, 16);
00322 
00323             GetLocaleInfo(lItem.LangId, LOCALE_SISO639LANGNAME, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR));
00324             lstrcpy(lItem.IndName, _tcsupr(szBuf));
00325             imgIndex = ImageList_AddIcon(hImgList, CreateLayoutIcon(lItem.IndName));
00326 
00327             GetLocaleInfo(lItem.LangId, LOCALE_SLANGUAGE, (LPTSTR)szBuf, sizeof(szBuf) / sizeof(TCHAR));
00328             lstrcpy(lItem.LangName, szBuf);
00329 
00330             // Does this keyboard layout have a substitute?
00331             // Then add the substitute instead of the Layout ID
00332             if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"),
00333                              0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
00334             {
00335                 dwSize = sizeof(szSub);
00336 
00337                 if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szSub, &dwSize) == ERROR_SUCCESS)
00338                 {
00339                     lstrcpy(szPreload, szSub);
00340                 }
00341 
00342                 RegCloseKey(hSubKey);
00343             }
00344 
00345             GetLayoutName(szPreload, lItem.LayoutName);
00346 
00347             item.pszText = lItem.LangName;
00348             item.iItem   = (INT) dwIndex;
00349             item.lParam  = (LPARAM)_ttoi(lItem.ValName);
00350             item.iImage  = imgIndex;
00351             i = ListView_InsertItem(hList, &item);
00352 
00353             ListView_SetItemText(hList, i, 1, lItem.LayoutName);
00354 
00355             dwIndex++;
00356 
00357             if (lstrcmp(lItem.ValName, _T("1")) == 0)
00358             {
00359                 (VOID) ListView_SetHotItem(hList, i);
00360             }
00361         }
00362 
00363         RegCloseKey(hKey);
00364     }
00365 }
00366 
00367 VOID
00368 UpdateLayoutsList(VOID)
00369 {
00370     HIMAGELIST hImgList;
00371 
00372     /* Clear the list */
00373     (VOID) ListView_DeleteAllItems(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST));
00374 
00375     /* Crate new list */
00376     hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 0, 1);
00377     InitLangList(MainDlgWnd, hImgList);
00378     hImgList = ListView_SetImageList(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), hImgList, LVSIL_SMALL);
00379 
00380     /* Destroy old image list */
00381     if(hImgList)
00382         (VOID) ImageList_Destroy(hImgList);
00383 }
00384 
00385 typedef struct _REG_KB_ENTRY_
00386 {
00387     TCHAR szLayoutID[3];
00388     DWORD dwType;
00389     TCHAR szData[CCH_LAYOUT_ID + 1];
00390     DWORD dwDataSize;
00391 } REG_KB_ENTRY;
00392 
00393 /* Layouts were deleted so we have to order the existing ones */
00394 static VOID
00395 UpdateRegValueNames(HKEY hKey)
00396 {
00397     DWORD dwIndex = 0, dwGot = 0, dwLayoutSize;
00398     DWORD dwSets = 5;
00399     REG_KB_ENTRY* data = HeapAlloc(GetProcessHeap(), 0, dwSets * sizeof(REG_KB_ENTRY));
00400 
00401     /* Get all existing entries and delete them */
00402     dwLayoutSize = sizeof(data[0].szLayoutID);
00403     while (RegEnumValue(hKey,
00404                         dwIndex,
00405                         data[dwGot].szLayoutID, 
00406                         &dwLayoutSize,
00407                         NULL, 
00408                         &data[dwGot].dwType,
00409                         (PBYTE)data[dwGot].szData, 
00410                         &data[dwGot].dwDataSize) != ERROR_NO_MORE_ITEMS)
00411     {
00412         if (_tcslen(data[dwGot].szLayoutID) <= 2 && _tcslen(data[dwGot].szData) == CCH_LAYOUT_ID)
00413         {
00414             RegDeleteValue(hKey, data[dwGot].szLayoutID);
00415             dwGot++;
00416             if (dwGot == dwSets)
00417             {
00418                 dwSets += 5;
00419                 data = HeapReAlloc(GetProcessHeap(), 0, data, dwSets * sizeof(REG_KB_ENTRY));
00420             }
00421         }
00422         dwIndex++;
00423         dwLayoutSize = sizeof(data[0].szLayoutID);
00424     }
00425 
00426     /* Set all entries with an updated value name */
00427     for (dwIndex = 0; dwIndex < dwGot; dwIndex++)
00428     {
00429         TCHAR szNewLayoutID[3];
00430 
00431         _stprintf(szNewLayoutID, TEXT("%u"), dwIndex + 1);
00432         RegSetValueEx(hKey, szNewLayoutID, 0, data[dwIndex].dwType, 
00433                       (PBYTE)data[dwIndex].szData, data[dwIndex].dwDataSize);
00434     }
00435     HeapFree(GetProcessHeap(), 0, data);
00436 }
00437 
00438 static VOID
00439 DeleteLayout(VOID)
00440 {
00441     INT iIndex, LayoutNum;
00442     LVITEM item;
00443     HKEY hKey, hSubKey;
00444     HWND hLayoutList = GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST);
00445     TCHAR szLayoutNum[3 + 1], szTitle[MAX_PATH],
00446           szConf[MAX_PATH], szPreload[CCH_LAYOUT_ID + 1];
00447     DWORD dwSize;
00448 
00449     iIndex = (INT) SendMessage(hLayoutList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
00450 
00451     if (iIndex != -1)
00452     {
00453         LoadString(hApplet, IDS_REM_QUESTION, szConf, sizeof(szConf) / sizeof(TCHAR));
00454         LoadString(hApplet, IDS_CONFIRMATION, szTitle, sizeof(szTitle) / sizeof(TCHAR));
00455 
00456         if (MessageBox(MainDlgWnd, szConf, szTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
00457         {
00458             ZeroMemory(&item, sizeof(LVITEM));
00459 
00460             item.mask = LVIF_PARAM;
00461             item.iItem = iIndex;
00462 
00463             (VOID) ListView_GetItem(hLayoutList, &item);
00464             LayoutNum = (INT) item.lParam;
00465 
00466             if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
00467                              KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
00468             {
00469                 _ultot(LayoutNum, szLayoutNum, 10);
00470 
00471                 dwSize = sizeof(szPreload);
00472                 RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize);
00473 
00474                 if (szPreload[0] == 'd')
00475                 {
00476                     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
00477                                      KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
00478                     {
00479                         if (RegDeleteValue(hSubKey, szPreload) != ERROR_SUCCESS)
00480                         {
00481                             RegCloseKey(hSubKey);
00482                             RegCloseKey(hKey);
00483                             return;
00484                         }
00485                         RegCloseKey(hSubKey);
00486                     }
00487                 }
00488 
00489                 if (RegDeleteValue(hKey, szLayoutNum) == ERROR_SUCCESS)
00490                 {
00491                     UpdateLayoutsList();
00492                     UpdateRegValueNames(hKey);
00493                 }
00494             }
00495             RegCloseKey(hKey);
00496         }
00497     }
00498 }
00499 
00500 static VOID
00501 SetDefaultLayout()
00502 {
00503     HKL hKl;
00504     TCHAR szLCID[CCH_LAYOUT_ID + 1], szLayoutNum[CCH_ULONG_DEC + 1];
00505     LVITEM item;
00506     INT LayoutNum;
00507 
00508     if (IsLayoutSelected() != -1)
00509     {
00510         ZeroMemory(&item, sizeof(LVITEM));
00511 
00512         item.mask = LVIF_PARAM;
00513         item.iItem = IsLayoutSelected();
00514 
00515         (VOID) ListView_GetItem(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), &item);
00516 
00517         LayoutNum = (INT) item.lParam;
00518         _ultot(LayoutNum, szLayoutNum, 10);
00519 
00520         if (GetLayoutID(szLayoutNum, szLCID))
00521         {
00522             hKl = LoadKeyboardLayout(szLCID, KLF_ACTIVATE);
00523             SystemParametersInfo(SPI_SETDEFAULTINPUTLANG, 0, &hKl, SPIF_SENDWININICHANGE);
00524         }
00525     }
00526 }
00527 
00528 static VOID
00529 SaveInputLang(HWND hDlg)
00530 {
00531     HKEY hKey, hSubKey;
00532     TCHAR szLayoutID[CCH_LAYOUT_ID + 1], szLayoutNum[CCH_ULONG_DEC + 1],
00533           szPreload[CCH_LAYOUT_ID + 1], LangID[CCH_LAYOUT_ID + 1], szMessage[MAX_PATH],
00534           Lang[MAX_PATH], SubPath[MAX_PATH];
00535     PTSTR pts;
00536     INT iLayout;
00537     DWORD dwSize;
00538     LANGID langid;
00539 
00540     iLayout = SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO), CB_GETCURSEL, 0, 0);
00541     if (iLayout == CB_ERR) return;
00542 
00543     pts = (PTSTR) SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO), CB_GETITEMDATA, iLayout, 0);
00544 
00545     _ultot(OldLayoutNum, szLayoutNum, 10);
00546     if (!GetLayoutID(szLayoutNum, szLayoutID)) return;
00547 
00548     // If old layout = selected layout
00549     if (_tcscmp(szLayoutID, pts) == 0) return;
00550 
00551     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
00552                      KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
00553     {
00554         dwSize = sizeof(szPreload);
00555         if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize) != ERROR_SUCCESS)
00556         {
00557             RegCloseKey(hKey);
00558             return;
00559         }
00560 
00561         langid = (LANGID)_tcstoul(szPreload, NULL, 16);
00562         GetLocaleInfo(langid, LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR));
00563         wsprintf(LangID, _T("0000%s"), Lang);
00564 
00565         if (IsLayoutExists(pts, LangID))
00566         {
00567             LoadString(hApplet, IDS_LAYOUT_EXISTS, szMessage, sizeof(szMessage) / sizeof(TCHAR));
00568             MessageBox(hDlg, szMessage, NULL, MB_OK | MB_ICONINFORMATION);
00569 
00570             RegCloseKey(hKey);
00571             return;
00572         }
00573 
00574         if (szPreload[0] == 'd')
00575         {
00576             if (_tcscmp(LangID, pts) == 0)
00577             {
00578                 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
00579                                  KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
00580                 {
00581                     if (RegDeleteValue(hSubKey, szPreload) != ERROR_SUCCESS)
00582                     {
00583                         RegCloseKey(hSubKey);
00584                         RegCloseKey(hKey);
00585                         return;
00586                     }
00587                     RegCloseKey(hSubKey);
00588 
00589                     RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)pts,
00590                                   (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00591                 }
00592             }
00593             else
00594             {
00595                 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
00596                                  KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
00597                 {
00598                     RegSetValueEx(hSubKey, szPreload, 0, REG_SZ, (LPBYTE)pts,
00599                                   (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00600 
00601                     RegCloseKey(hSubKey);
00602                 }
00603             }
00604         }
00605         else
00606         {
00607             if (_tcscmp(LangID, pts) == 0)
00608             {
00609                 RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)pts,
00610                               (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00611             }
00612             else
00613             {
00614                 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, NULL,
00615                                    REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
00616                                    NULL, &hSubKey, NULL) == ERROR_SUCCESS)
00617                 {
00618                     wsprintf(SubPath, _T("d%03d%s"), GetLayoutCount(Lang)-1, Lang);
00619 
00620                     RegSetValueEx(hSubKey, SubPath, 0, REG_SZ, (LPBYTE)pts,
00621                                   (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00622 
00623                     RegSetValueEx(hKey, szLayoutNum, 0, REG_SZ, (LPBYTE)SubPath,
00624                                   (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00625 
00626                     RegCloseKey(hSubKey);
00627                 }
00628             }
00629         }
00630 
00631         RegCloseKey(hKey);
00632     }
00633 }
00634 
00635 static VOID
00636 InitInputLangPropDlg(HWND hDlg)
00637 {
00638     HKEY hKey, hSubKey;
00639     LVITEM item;
00640     INT LayoutNum;
00641     TCHAR szLayoutNum[10 + 1], szPreload[CCH_LAYOUT_ID + 1],
00642           szTmp[CCH_LAYOUT_ID + 1], szName[MAX_PATH];
00643     DWORD dwSize;
00644     LANGID langid;
00645 
00646     ZeroMemory(&item, sizeof(LVITEM));
00647 
00648     item.mask = LVIF_PARAM;
00649     item.iItem = IsLayoutSelected();
00650 
00651     (VOID) ListView_GetItem(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), &item);
00652     LayoutNum = (INT) item.lParam;
00653     OldLayoutNum = LayoutNum;
00654 
00655     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
00656                      KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
00657     {
00658         _ultot(LayoutNum, szLayoutNum, 10);
00659 
00660         dwSize = sizeof(szPreload);
00661         RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize);
00662 
00663         langid = (LANGID)_tcstoul(szPreload, NULL, 16);
00664         GetLocaleInfo(langid, LOCALE_SLANGUAGE, (LPTSTR)szName, sizeof(szName) / sizeof(TCHAR));
00665         SetWindowText(GetDlgItem(hDlg, IDC_INPUT_LANG_STR), szName);
00666 
00667         if (szPreload[0] == 'd')
00668         {
00669             if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0,
00670                                      KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
00671             {
00672                 if (RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szTmp, &dwSize) != ERROR_SUCCESS)
00673                 {
00674                     RegCloseKey(hSubKey);
00675                     RegCloseKey(hKey);
00676                     return;
00677                 }
00678                 lstrcpy(szPreload, szTmp);
00679                 RegCloseKey(hSubKey);
00680             }
00681         }
00682 
00683         if (GetLayoutName(szPreload, szName))
00684         {
00685             SendMessage(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO),
00686                         CB_SELECTSTRING, (WPARAM)-1, (LPARAM)szName);
00687         }
00688     }
00689     RegCloseKey(hKey);
00690 }
00691 
00692 INT_PTR CALLBACK
00693 InputLangPropDlgProc(HWND hDlg,
00694                UINT message,
00695                WPARAM wParam,
00696                LPARAM lParam)
00697 {
00698     UNREFERENCED_PARAMETER(lParam);
00699 
00700     switch (message)
00701     {
00702         case WM_INITDIALOG:
00703             CreateKeyboardLayoutList(GetDlgItem(hDlg, IDC_KB_LAYOUT_IME_COMBO));
00704             InitInputLangPropDlg(hDlg);
00705             break;
00706 
00707         case WM_COMMAND:
00708             switch (LOWORD(wParam))
00709             {
00710                 case IDOK:
00711                     SaveInputLang(hDlg);
00712                     UpdateLayoutsList();
00713                     EndDialog(hDlg,LOWORD(wParam));
00714                     break;
00715 
00716                 case IDCANCEL:
00717                     EndDialog(hDlg,LOWORD(wParam));
00718                     break;
00719             }
00720             break;
00721     }
00722 
00723     return FALSE;
00724 }
00725 
00726 /* Property page dialog callback */
00727 INT_PTR CALLBACK
00728 SettingPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
00729 {
00730     UNREFERENCED_PARAMETER(lParam);
00731 
00732     switch (uMsg)
00733     {
00734         case WM_INITDIALOG:
00735         {
00736             HIMAGELIST hImgList;
00737 
00738             MainDlgWnd = hwndDlg;
00739             AddListColumn(hwndDlg);
00740             (VOID) ListView_SetExtendedListViewStyle(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST),
00741                                                      LVS_EX_FULLROWSELECT);
00742             hImgList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 0, 1);
00743             InitLangList(hwndDlg, hImgList);
00744             (VOID) ListView_SetImageList(GetDlgItem(MainDlgWnd, IDC_KEYLAYOUT_LIST), hImgList, LVSIL_SMALL);
00745         }
00746             break;
00747         case WM_NOTIFY:
00748         {
00749             switch (LOWORD(wParam))
00750             {
00751 
00752             }
00753         }
00754             break;
00755         case WM_COMMAND:
00756             switch (LOWORD(wParam))
00757             {
00758                 case IDC_REMOVE_BUTTON:
00759                     DeleteLayout();
00760                     break;
00761 
00762                 case IDC_KEY_SET_BTN:
00763                     DialogBox(hApplet,
00764                               MAKEINTRESOURCE(IDD_KEYSETTINGS),
00765                               hwndDlg,
00766                               KeySettingsDlgProc);
00767                     break;
00768 
00769                 case IDC_ADD_BUTTON:
00770                     DialogBox(hApplet,
00771                               MAKEINTRESOURCE(IDD_ADD),
00772                               hwndDlg,
00773                               AddDlgProc);
00774                     break;
00775 
00776                 case IDC_PROP_BUTTON:
00777                     if (IsLayoutSelected() != -1)
00778                     DialogBox(hApplet,
00779                               MAKEINTRESOURCE(IDD_INPUT_LANG_PROP),
00780                               hwndDlg,
00781                               InputLangPropDlgProc);
00782                     break;
00783 
00784                 case IDC_SET_DEFAULT:
00785                     SetDefaultLayout();
00786                     UpdateLayoutsList();
00787                     break;
00788             }
00789             break;
00790         case WM_DESTROY:
00791             break;
00792     }
00793 
00794     return FALSE;
00795 }
00796 
00797 /* EOF */

Generated on Sat May 26 2012 04:15:32 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.