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

kblayouts.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS International Control Panel
00003  * FILE:            dll/cpl/intl/kblayouts.c
00004  * PURPOSE:         Functions for manipulation with keyboard layouts
00005  * PROGRAMMER:      Dmitry Chapyshev (dmitry@reactos.org)
00006  */
00007 
00008 #include "intl.h"
00009 
00010 /* Character Count of a layout ID like "00000409" */
00011 #define CCH_LAYOUT_ID    8
00012 
00013 /* Maximum Character Count of a ULONG in decimal */
00014 #define CCH_ULONG_DEC    10
00015 
00016 
00017 /* szLayoutID like 00000409, szLangID like 00000409 */
00018 static BOOL
00019 IsLayoutExists(LPTSTR szLayoutID, LPTSTR szLangID)
00020 {
00021     HKEY hKey, hSubKey;
00022     TCHAR szPreload[CCH_LAYOUT_ID + 1], szLayoutNum[3 + 1],
00023           szTmp[CCH_LAYOUT_ID + 1], szOldLangID[CCH_LAYOUT_ID + 1];
00024     DWORD dwIndex = 0, dwType, dwSize;
00025     BOOL IsLangExists = FALSE;
00026     LANGID langid;
00027 
00028     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
00029         0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00030     {
00031         dwSize = sizeof(szLayoutNum);
00032 
00033         while (RegEnumValue(hKey, dwIndex, szLayoutNum, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
00034         {
00035             dwSize = sizeof(szPreload);
00036             if (RegQueryValueEx(hKey, szLayoutNum, NULL, NULL, (LPBYTE)szPreload, &dwSize) != ERROR_SUCCESS)
00037             {
00038                 RegCloseKey(hKey);
00039                 return FALSE;
00040             }
00041 
00042             langid = (LANGID)_tcstoul(szPreload, NULL, 16);
00043             GetLocaleInfo(langid, LOCALE_ILANGUAGE, szTmp, sizeof(szTmp) / sizeof(TCHAR));
00044             wsprintf(szOldLangID, _T("0000%s"), szTmp);
00045 
00046             if (_tcscmp(szOldLangID, szLangID) == 0)
00047                 IsLangExists = TRUE;
00048             else
00049                 IsLangExists = FALSE;
00050 
00051             if (szPreload[0] == 'd')
00052             {
00053                 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"),
00054                                  0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
00055                 {
00056                     dwSize = sizeof(szTmp);
00057                     RegQueryValueEx(hSubKey, szPreload, NULL, NULL, (LPBYTE)szTmp, &dwSize);
00058 
00059                     if ((_tcscmp(szTmp, szLayoutID) == 0)&&(IsLangExists))
00060                     {
00061                         RegCloseKey(hSubKey);
00062                         RegCloseKey(hKey);
00063                         return TRUE;
00064                     }
00065                 }
00066             }
00067             else
00068             {
00069                 if ((_tcscmp(szPreload, szLayoutID) == 0) && (IsLangExists))
00070                 {
00071                     RegCloseKey(hKey);
00072                     return TRUE;
00073                 }
00074             }
00075 
00076             IsLangExists = FALSE;
00077             dwSize = sizeof(szLayoutNum);
00078             dwIndex++;
00079         }
00080 
00081         RegCloseKey(hKey);
00082     }
00083 
00084     return FALSE;
00085 }
00086 
00087 static INT
00088 GetLayoutCount(LPTSTR szLang)
00089 {
00090     HKEY hKey;
00091     TCHAR szLayoutID[3 + 1], szPreload[CCH_LAYOUT_ID + 1], szLOLang[MAX_PATH];
00092     DWORD dwIndex = 0, dwType, dwSize;
00093     UINT Count = 0, i, j;
00094 
00095     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
00096         0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00097     {
00098         dwSize = sizeof(szLayoutID);
00099 
00100         while (RegEnumValue(hKey, dwIndex, szLayoutID, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
00101         {
00102             dwSize = sizeof(szPreload);
00103             RegQueryValueEx(hKey, szLayoutID, NULL, NULL, (LPBYTE)szPreload, &dwSize);
00104 
00105             for (i = 4, j = 0; i < _tcslen(szPreload)+1; i++, j++)
00106                 szLOLang[j] = szPreload[i];
00107 
00108             if (_tcscmp(szLOLang, szLang) == 0) Count += 1;
00109 
00110             dwSize = sizeof(szLayoutID);
00111             dwIndex++;
00112         }
00113 
00114         RegCloseKey(hKey);
00115     }
00116 
00117     return Count;
00118 }
00119 
00120 /* szLayoutID like 00000409, szLangID like 00000409 */
00121 static BOOL
00122 AddNewLayout(LPTSTR szLayoutID, LPTSTR szLangID)
00123 {
00124     TCHAR NewLayout[CCH_ULONG_DEC + 1], Lang[MAX_PATH],
00125           LangID[CCH_LAYOUT_ID + 1], SubPath[CCH_LAYOUT_ID + 1];
00126     HKEY hKey, hSubKey;
00127     DWORD cValues;
00128     LCID lcid;
00129 
00130     if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
00131     {
00132         if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &cValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
00133         {
00134             _ultot(cValues + 1, NewLayout, 10);
00135 
00136             lcid = _tcstoul(szLangID, NULL, 16);
00137 
00138             GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, Lang, sizeof(Lang) / sizeof(TCHAR));
00139             wsprintf(LangID, _T("0000%s"), Lang);
00140 
00141             if (IsLayoutExists(szLayoutID, LangID))
00142             {
00143                 RegCloseKey(hKey);
00144                 return FALSE;
00145             }
00146 
00147             if (GetLayoutCount(Lang) >= 1)
00148             {
00149                 wsprintf(SubPath, _T("d%03d%s"), GetLayoutCount(Lang), Lang);
00150             }
00151             else if ((_tcscmp(LangID, szLayoutID) != 0) && (GetLayoutCount(Lang) == 0))
00152             {
00153                 wsprintf(SubPath, _T("d%03d%s"), 0, Lang);
00154             }
00155             else SubPath[0] = '\0';
00156 
00157             if (_tcslen(SubPath) != 0)
00158             {
00159                 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Substitutes"), 0, NULL,
00160                                    REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
00161                                    NULL, &hSubKey, NULL) == ERROR_SUCCESS)
00162                 {
00163                     if (RegSetValueEx(hSubKey, SubPath, 0, REG_SZ, (LPBYTE)szLayoutID,
00164                                       (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR))) != ERROR_SUCCESS)
00165                     {
00166                         RegCloseKey(hSubKey);
00167                         RegCloseKey(hKey);
00168                         return FALSE;
00169                     }
00170                     RegCloseKey(hSubKey);
00171                 }
00172                 lstrcpy(szLayoutID, SubPath);
00173             }
00174 
00175             RegSetValueEx(hKey,
00176                           NewLayout,
00177                           0,
00178                           REG_SZ,
00179                           (LPBYTE)szLayoutID,
00180                           (DWORD)((CCH_LAYOUT_ID + 1) * sizeof(TCHAR)));
00181         }
00182         RegCloseKey(hKey);
00183     }
00184 
00185     return TRUE;
00186 }
00187 
00188 VOID
00189 AddNewKbLayoutsByLcid(LCID Lcid)
00190 {
00191     HINF hIntlInf;
00192     TCHAR szLang[CCH_LAYOUT_ID + 1], szLangID[CCH_LAYOUT_ID + 1];
00193     TCHAR szLangStr[MAX_STR_SIZE], szLayoutStr[MAX_STR_SIZE], szStr[MAX_STR_SIZE];
00194     INFCONTEXT InfContext;
00195     LONG Count;
00196     DWORD FieldCount, Index;
00197 
00198     GetLocaleInfo(MAKELCID(Lcid, SORT_DEFAULT), LOCALE_ILANGUAGE, szLang, sizeof(szLang) / sizeof(TCHAR));
00199     wsprintf(szLangID, _T("0000%s"), szLang);
00200 
00201     hIntlInf = SetupOpenInfFile(_T("intl.inf"), NULL, INF_STYLE_WIN4, NULL);
00202 
00203     if (hIntlInf == INVALID_HANDLE_VALUE)
00204         return;
00205 
00206     if (!SetupOpenAppendInfFile(NULL, hIntlInf, NULL))
00207     {
00208         SetupCloseInfFile(hIntlInf);
00209         hIntlInf = NULL;
00210         return;
00211     }
00212 
00213     Count = SetupGetLineCount(hIntlInf, _T("Locales"));
00214     if (Count <= 0) return;
00215 
00216     if (SetupFindFirstLine(hIntlInf, _T("Locales"), szLangID, &InfContext))
00217     {
00218         FieldCount = SetupGetFieldCount(&InfContext);
00219 
00220         if (FieldCount != 0)
00221         {
00222             for (Index = 5; Index <= FieldCount; Index++)
00223             {
00224                 if (SetupGetStringField(&InfContext, Index, szStr, MAX_STR_SIZE, NULL))
00225                 {
00226                     INT i, j;
00227 
00228                     if (_tcslen(szStr) != 13) continue;
00229 
00230                     wsprintf(szLangStr, _T("0000%s"), szStr);
00231                     szLangStr[8] = '\0';
00232 
00233                     for (i = 5, j = 0; i <= _tcslen(szStr); i++, j++)
00234                         szLayoutStr[j] = szStr[i];
00235 
00236                     AddNewLayout(szLayoutStr, szLangStr);
00237                 }
00238             }
00239         }
00240     }
00241     SetupCloseInfFile(hIntlInf);
00242 }

Generated on Sun May 27 2012 04:20:57 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.