Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygengeneralp.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS 00003 * Copyright (C) 2004, 2005 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 /* $Id: generalp.c 54972 2012-01-15 13:37:25Z rharabien $ 00020 * 00021 * PROJECT: ReactOS International Control Panel 00022 * FILE: dll/cpl/intl/generalp.c 00023 * PURPOSE: General property page 00024 * PROGRAMMER: Eric Kohl 00025 * Klemens Friedl 00026 * Aleksey Bragin 00027 */ 00028 00029 #include "intl.h" 00030 00031 #define SAMPLE_NUMBER _T("123456789") 00032 #define NO_FLAG 0 00033 00034 HWND hList; 00035 HWND hLocaleList, hGeoList; 00036 BOOL bSpain = FALSE; 00037 00038 static BOOL CALLBACK 00039 LocalesEnumProc(LPTSTR lpLocale) 00040 { 00041 LCID lcid; 00042 TCHAR lang[255]; 00043 INT index; 00044 BOOL bNoShow = FALSE; 00045 00046 lcid = _tcstoul(lpLocale, NULL, 16); 00047 00048 /* Display only languages with installed support */ 00049 /* See bug #4898. 00050 if (!IsValidLocale(lcid, LCID_INSTALLED)) 00051 return TRUE; 00052 */ 00053 00054 if (lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT) || 00055 lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT)) 00056 { 00057 if (bSpain == FALSE) 00058 { 00059 LoadString(hApplet, IDS_SPAIN, lang, 255); 00060 bSpain = TRUE; 00061 } 00062 else 00063 { 00064 bNoShow = TRUE; 00065 } 00066 } 00067 else 00068 { 00069 GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(TCHAR)); 00070 } 00071 00072 if (bNoShow == FALSE) 00073 { 00074 index = SendMessage(hList, 00075 CB_ADDSTRING, 00076 0, 00077 (LPARAM)lang); 00078 00079 SendMessage(hList, 00080 CB_SETITEMDATA, 00081 index, 00082 (LPARAM)lcid); 00083 } 00084 00085 return TRUE; 00086 } 00087 00088 /* Update all locale samples */ 00089 static VOID 00090 UpdateLocaleSample(HWND hwndDlg, LCID lcidLocale) 00091 { 00092 TCHAR OutBuffer[MAX_SAMPLES_STR_SIZE]; 00093 00094 /* Get number format sample */ 00095 GetNumberFormat(lcidLocale, NO_FLAG, SAMPLE_NUMBER, NULL, OutBuffer, 00096 MAX_SAMPLES_STR_SIZE); 00097 SendMessage(GetDlgItem(hwndDlg, IDC_NUMSAMPLE_EDIT), 00098 WM_SETTEXT, 0, (LPARAM)OutBuffer); 00099 00100 /* Get monetary format sample */ 00101 GetCurrencyFormat(lcidLocale, LOCALE_USE_CP_ACP, SAMPLE_NUMBER, NULL, 00102 OutBuffer, MAX_SAMPLES_STR_SIZE); 00103 SendMessage(GetDlgItem(hwndDlg, IDC_MONEYSAMPLE_EDIT), 00104 WM_SETTEXT, 0, (LPARAM)OutBuffer); 00105 00106 /* Get time format sample */ 00107 GetTimeFormat(lcidLocale, NO_FLAG, NULL, NULL, OutBuffer, MAX_SAMPLES_STR_SIZE); 00108 SendMessage(GetDlgItem(hwndDlg, IDC_TIMESAMPLE_EDIT), 00109 WM_SETTEXT, 00110 0, 00111 (LPARAM)OutBuffer); 00112 00113 /* Get short date format sample */ 00114 GetDateFormat(lcidLocale, DATE_SHORTDATE, NULL, NULL, OutBuffer, 00115 MAX_SAMPLES_STR_SIZE); 00116 SendMessage(GetDlgItem(hwndDlg, IDC_SHORTTIMESAMPLE_EDIT), WM_SETTEXT, 00117 0, (LPARAM)OutBuffer); 00118 00119 /* Get long date sample */ 00120 GetDateFormat(lcidLocale, DATE_LONGDATE, NULL, NULL, OutBuffer, 00121 MAX_SAMPLES_STR_SIZE); 00122 SendMessage(GetDlgItem(hwndDlg, IDC_FULLTIMESAMPLE_EDIT), 00123 WM_SETTEXT, 0, (LPARAM)OutBuffer); 00124 } 00125 00126 static VOID 00127 CreateLanguagesList(HWND hwnd) 00128 { 00129 TCHAR langSel[255]; 00130 00131 hList = hwnd; 00132 bSpain = FALSE; 00133 EnumSystemLocales(LocalesEnumProc, LCID_SUPPORTED); 00134 00135 /* Select current locale */ 00136 /* or should it be System and not user? */ 00137 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)/sizeof(TCHAR)); 00138 00139 SendMessage(hList, 00140 CB_SELECTSTRING, 00141 -1, 00142 (LPARAM)langSel); 00143 } 00144 00145 /* Sets new locale */ 00146 VOID 00147 SetNewLocale(LCID lcid) 00148 { 00149 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0) 00150 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0) 00151 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0) 00152 00153 // Set locale 00154 HKEY localeKey; 00155 HKEY langKey; 00156 DWORD ret; 00157 TCHAR value[9]; 00158 DWORD valuesize; 00159 TCHAR ACPPage[9]; 00160 TCHAR OEMPage[9]; 00161 00162 ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, OEMPage, sizeof(OEMPage)/sizeof(TCHAR)); 00163 if (ret == 0) 00164 { 00165 MessageBox(NULL, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK); 00166 return; 00167 } 00168 00169 ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, ACPPage, sizeof(ACPPage)/sizeof(TCHAR)); 00170 if (ret == 0) 00171 { 00172 MessageBox(NULL, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK); 00173 return; 00174 } 00175 00176 ret = RegOpenKey(HKEY_CURRENT_USER, _T("Control Panel\\International"), &localeKey); 00177 if (ret != ERROR_SUCCESS) 00178 { 00179 // Some serious error 00180 MessageBox(NULL, _T("Problem opening HKCU\\Control Panel\\International key"), 00181 _T("Big Problem"), MB_OK); 00182 return; 00183 } 00184 00185 wsprintf(value, _T("%04X"), (DWORD)lcid); 00186 valuesize = (_tcslen(value) + 1) * sizeof(TCHAR); 00187 00188 RegSetValueEx(localeKey, _T("Locale"), 0, REG_SZ, (LPBYTE)value, valuesize); 00189 RegCloseKey(localeKey); 00190 00191 ret = RegOpenKey(HKEY_USERS, _T(".DEFAULT\\Control Panel\\International"), &localeKey); 00192 if (ret != ERROR_SUCCESS) 00193 { 00194 // Some serious error 00195 MessageBox(NULL, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"), 00196 _T("Big Problem"), MB_OK); 00197 return; 00198 } 00199 00200 wsprintf(value, _T("%04X"), (DWORD)lcid); 00201 valuesize = (_tcslen(value) + 1) * sizeof(TCHAR); 00202 00203 RegSetValueEx(localeKey, _T("Locale"), 0, REG_SZ, (BYTE *)value, valuesize); 00204 RegCloseKey(localeKey); 00205 00206 // Set language 00207 ret = RegOpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey); 00208 if (ret != ERROR_SUCCESS) 00209 { 00210 MessageBoxW(NULL, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"), 00211 _T("Big Problem"), MB_OK); 00212 return; 00213 } 00214 00215 RegSetValueEx(langKey, _T("Default"), 0, REG_SZ, (BYTE *)value, valuesize ); 00216 RegSetValueEx(langKey, _T("InstallLanguage"), 0, REG_SZ, (BYTE *)value, valuesize ); 00217 00218 RegCloseKey(langKey); 00219 00220 00221 /* Set language */ 00222 ret = RegOpenKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey); 00223 if (ret != ERROR_SUCCESS) 00224 { 00225 MessageBox(NULL, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"), 00226 _T("Big Problem"), MB_OK); 00227 return; 00228 } 00229 00230 RegSetValueExW(langKey, _T("OEMCP"), 0, REG_SZ, (BYTE *)OEMPage, (_tcslen(OEMPage) +1 ) * sizeof(TCHAR)); 00231 RegSetValueExW(langKey, _T("ACP"), 0, REG_SZ, (BYTE *)ACPPage, (_tcslen(ACPPage) +1 ) * sizeof(TCHAR)); 00232 00233 RegCloseKey(langKey); 00234 } 00235 00236 /* Location enumerate procedure */ 00237 BOOL 00238 CALLBACK 00239 LocationsEnumProc(GEOID gId) 00240 { 00241 TCHAR loc[MAX_STR_SIZE]; 00242 INT index; 00243 00244 GetGeoInfo(gId, GEO_FRIENDLYNAME, loc, MAX_STR_SIZE, LANG_SYSTEM_DEFAULT); 00245 index = (INT)SendMessage(hGeoList, 00246 CB_ADDSTRING, 00247 0, 00248 (LPARAM)loc); 00249 00250 SendMessage(hGeoList, 00251 CB_SETITEMDATA, 00252 index, 00253 (LPARAM)gId); 00254 00255 return TRUE; 00256 } 00257 00258 /* Enumerate all system locations identifiers */ 00259 static 00260 VOID 00261 CreateLocationsList(HWND hWnd) 00262 { 00263 GEOID userGeoID; 00264 TCHAR loc[MAX_STR_SIZE]; 00265 00266 hGeoList = hWnd; 00267 00268 EnumSystemGeoID(GEOCLASS_NATION, 0, LocationsEnumProc); 00269 00270 /* Select current location */ 00271 userGeoID = GetUserGeoID(GEOCLASS_NATION); 00272 GetGeoInfo(userGeoID, 00273 GEO_FRIENDLYNAME, 00274 loc, 00275 MAX_STR_SIZE, 00276 LANG_SYSTEM_DEFAULT); 00277 00278 SendMessage(hGeoList, 00279 CB_SELECTSTRING, 00280 (WPARAM) -1, 00281 (LPARAM)loc); 00282 } 00283 00284 DWORD 00285 VerifyUnattendLCID(HWND hwndDlg) 00286 { 00287 LRESULT lCount, lIndex, lResult; 00288 00289 lCount = SendMessage(hList, CB_GETCOUNT, (WPARAM)0, (LPARAM)0); 00290 if (lCount == CB_ERR) 00291 { 00292 return 0; 00293 } 00294 00295 for (lIndex = 0; lIndex < lCount; lIndex++) 00296 { 00297 lResult = SendMessage(hList, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0); 00298 if (lResult == CB_ERR) 00299 { 00300 continue; 00301 } 00302 00303 if (lResult == (LRESULT)UnattendLCID) 00304 { 00305 SendMessage(hList, CB_SETCURSEL, (WPARAM)lIndex, (LPARAM)0); 00306 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00307 return 1; 00308 } 00309 } 00310 00311 return 0; 00312 } 00313 00314 00315 /* Property page dialog callback */ 00316 INT_PTR CALLBACK 00317 GeneralPageProc(HWND hwndDlg, 00318 UINT uMsg, 00319 WPARAM wParam, 00320 LPARAM lParam) 00321 { 00322 switch(uMsg) 00323 { 00324 case WM_INITDIALOG: 00325 CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST)); 00326 UpdateLocaleSample(hwndDlg, LOCALE_USER_DEFAULT); 00327 CreateLocationsList(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO)); 00328 if (IsUnattendedSetupEnabled) 00329 { 00330 if (VerifyUnattendLCID(hwndDlg)) 00331 { 00332 SetNewLocale(UnattendLCID); 00333 PostQuitMessage(0); 00334 } else 00335 DPRINT1("VerifyUnattendLCID failed\n"); 00336 return TRUE; 00337 } 00338 break; 00339 00340 case WM_COMMAND: 00341 switch (LOWORD(wParam)) 00342 { 00343 case IDC_LANGUAGELIST: 00344 if (HIWORD(wParam) == CBN_SELCHANGE) 00345 { 00346 LCID NewLcid; 00347 INT iCurSel; 00348 00349 iCurSel = SendMessage(hList, 00350 CB_GETCURSEL, 00351 0, 00352 0); 00353 if (iCurSel == CB_ERR) 00354 break; 00355 00356 NewLcid = SendMessage(hList, 00357 CB_GETITEMDATA, 00358 iCurSel, 00359 0); 00360 if (NewLcid == (LCID)CB_ERR) 00361 break; 00362 00363 UpdateLocaleSample(hwndDlg, NewLcid); 00364 00365 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00366 } 00367 break; 00368 00369 case IDC_LOCATION_COMBO: 00370 if (HIWORD(wParam) == CBN_SELCHANGE) 00371 { 00372 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00373 } 00374 break; 00375 case IDC_SETUP_BUTTON: 00376 { 00377 LCID NewLcid; 00378 INT iCurSel; 00379 00380 iCurSel = SendMessage(hList, 00381 CB_GETCURSEL, 00382 0, 00383 0); 00384 if (iCurSel == CB_ERR) 00385 break; 00386 00387 NewLcid = SendMessage(hList, 00388 CB_GETITEMDATA, 00389 iCurSel, 00390 0); 00391 if (NewLcid == (LCID)CB_ERR) 00392 break; 00393 00394 SetupApplet(GetParent(hwndDlg), NewLcid); 00395 } 00396 break; 00397 } 00398 break; 00399 00400 case WM_NOTIFY: 00401 { 00402 LPNMHDR lpnm = (LPNMHDR)lParam; 00403 00404 if (lpnm->code == (UINT)PSN_APPLY) 00405 { 00406 /* Apply changes */ 00407 LCID NewLcid; 00408 GEOID NewGeoID; 00409 INT iCurSel; 00410 00411 PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg); 00412 00413 /* Acquire new value */ 00414 iCurSel = SendMessage(hList, 00415 CB_GETCURSEL, 00416 0, 00417 0); 00418 if (iCurSel == CB_ERR) 00419 break; 00420 00421 NewLcid = SendMessage(hList, 00422 CB_GETITEMDATA, 00423 iCurSel, 00424 0); 00425 if (NewLcid == (LCID)CB_ERR) 00426 break; 00427 00428 iCurSel = SendMessage(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO), 00429 CB_GETCURSEL, 00430 0, 00431 0); 00432 if (iCurSel == CB_ERR) 00433 break; 00434 00435 NewGeoID = SendMessage(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO), 00436 CB_GETITEMDATA, 00437 iCurSel, 00438 0); 00439 if (NewGeoID == (GEOID)CB_ERR) 00440 break; 00441 00442 /* Set new locale */ 00443 SetNewLocale(NewLcid); 00444 AddNewKbLayoutsByLcid(NewLcid); 00445 SetUserGeoID(NewGeoID); 00446 SetNonUnicodeLang(hwndDlg, NewLcid); 00447 } 00448 } 00449 break; 00450 } 00451 00452 return FALSE; 00453 } 00454 00455 /* EOF */ Generated on Sun May 27 2012 04:20:57 for ReactOS by
1.7.6.1
|