3 * Copyright (C) 2004, 2005 ReactOS Team
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * PROJECT: ReactOS International Control Panel
21 * FILE: dll/cpl/intl/generalp.c
22 * PURPOSE: General property page
23 * PROGRAMMER: Eric Kohl
32 #define SAMPLE_NUMBER _T("123456789")
36 HWND hLocaleList
, hGeoList
;
40 LocalesEnumProc(LPTSTR lpLocale
)
47 lcid
= _tcstoul(lpLocale
, NULL
, 16);
49 /* Display only languages with installed support */
50 if (!IsValidLocale(lcid
, LCID_INSTALLED
))
53 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
54 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
58 LoadString(hApplet
, IDS_SPAIN
, lang
, 255);
68 GetLocaleInfo(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
)/sizeof(TCHAR
));
73 index
= SendMessage(hList
,
87 /* Update all locale samples */
89 UpdateLocaleSample(HWND hwndDlg
, LCID lcidLocale
)
91 TCHAR OutBuffer
[MAX_SAMPLES_STR_SIZE
];
93 /* Get number format sample */
94 GetNumberFormat(lcidLocale
, NO_FLAG
, SAMPLE_NUMBER
, NULL
, OutBuffer
,
95 MAX_SAMPLES_STR_SIZE
);
96 SendMessage(GetDlgItem(hwndDlg
, IDC_NUMSAMPLE_EDIT
),
97 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
99 /* Get monetary format sample */
100 GetCurrencyFormat(lcidLocale
, LOCALE_USE_CP_ACP
, SAMPLE_NUMBER
, NULL
,
101 OutBuffer
, MAX_SAMPLES_STR_SIZE
);
102 SendMessage(GetDlgItem(hwndDlg
, IDC_MONEYSAMPLE_EDIT
),
103 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
105 /* Get time format sample */
106 GetTimeFormat(lcidLocale
, NO_FLAG
, NULL
, NULL
, OutBuffer
, MAX_SAMPLES_STR_SIZE
);
107 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE_EDIT
),
112 /* Get short date format sample */
113 GetDateFormat(lcidLocale
, DATE_SHORTDATE
, NULL
, NULL
, OutBuffer
,
114 MAX_SAMPLES_STR_SIZE
);
115 SendMessage(GetDlgItem(hwndDlg
, IDC_SHORTTIMESAMPLE_EDIT
), WM_SETTEXT
,
116 0, (LPARAM
)OutBuffer
);
118 /* Get long date sample */
119 GetDateFormat(lcidLocale
, DATE_LONGDATE
, NULL
, NULL
, OutBuffer
,
120 MAX_SAMPLES_STR_SIZE
);
121 SendMessage(GetDlgItem(hwndDlg
, IDC_FULLTIMESAMPLE_EDIT
),
122 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
126 CreateLanguagesList(HWND hwnd
)
132 EnumSystemLocales(LocalesEnumProc
, LCID_SUPPORTED
);
134 /* Select current locale */
135 /* or should it be System and not user? */
136 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
)/sizeof(TCHAR
));
144 /* Sets new locale */
146 SetNewLocale(LCID lcid
)
148 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0)
149 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0)
150 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0)
161 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTCODEPAGE
, OEMPage
, sizeof(OEMPage
)/sizeof(TCHAR
));
164 MessageBox(NULL
, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK
);
168 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, ACPPage
, sizeof(ACPPage
)/sizeof(TCHAR
));
171 MessageBox(NULL
, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK
);
175 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
176 if (ret
!= ERROR_SUCCESS
)
178 // Some serious error
179 MessageBox(NULL
, _T("Problem opening HKCU\\Control Panel\\International key"),
180 _T("Big Problem"), MB_OK
);
184 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
185 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
187 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (LPBYTE
)value
, valuesize
);
188 RegCloseKey(localeKey
);
190 ret
= RegOpenKey(HKEY_USERS
, _T(".DEFAULT\\Control Panel\\International"), &localeKey
);
191 if (ret
!= ERROR_SUCCESS
)
193 // Some serious error
194 MessageBox(NULL
, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"),
195 _T("Big Problem"), MB_OK
);
199 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
200 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
202 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
203 RegCloseKey(localeKey
);
206 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
207 if (ret
!= ERROR_SUCCESS
)
209 MessageBoxW(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"),
210 _T("Big Problem"), MB_OK
);
214 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
215 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
217 RegCloseKey(langKey
);
221 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
222 if (ret
!= ERROR_SUCCESS
)
224 MessageBox(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"),
225 _T("Big Problem"), MB_OK
);
229 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
230 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
232 RegCloseKey(langKey
);
235 /* Location enumerate procedure */
238 LocationsEnumProc(GEOID gId
)
240 TCHAR loc
[MAX_STR_SIZE
];
243 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_STR_SIZE
, LANG_SYSTEM_DEFAULT
);
244 index
= (INT
)SendMessage(hGeoList
,
249 SendMessage(hGeoList
,
257 /* Enumerate all system locations identifiers */
260 CreateLocationsList(HWND hWnd
)
263 TCHAR loc
[MAX_STR_SIZE
];
267 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
269 /* Select current location */
270 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
271 GetGeoInfo(userGeoID
,
275 LANG_SYSTEM_DEFAULT
);
277 SendMessage(hGeoList
,
284 VerifyUnattendLCID(HWND hwndDlg
)
286 LRESULT lCount
, lIndex
, lResult
;
288 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
289 if (lCount
== CB_ERR
)
294 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
296 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
297 if (lResult
== CB_ERR
)
302 if (lResult
== (LRESULT
)UnattendLCID
)
304 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
305 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
314 /* Property page dialog callback */
316 GeneralPageProc(HWND hwndDlg
,
324 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
325 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
326 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
327 if (IsUnattendedSetupEnabled
)
329 if (VerifyUnattendLCID(hwndDlg
))
331 SetNewLocale(UnattendLCID
);
334 DPRINT1("VerifyUnattendLCID failed\n");
340 switch (LOWORD(wParam
))
342 case IDC_LANGUAGELIST
:
343 if (HIWORD(wParam
) == CBN_SELCHANGE
)
348 iCurSel
= SendMessage(hList
,
352 if (iCurSel
== CB_ERR
)
355 NewLcid
= SendMessage(hList
,
359 if (NewLcid
== (LCID
)CB_ERR
)
362 UpdateLocaleSample(hwndDlg
, NewLcid
);
364 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
368 case IDC_LOCATION_COMBO
:
369 if (HIWORD(wParam
) == CBN_SELCHANGE
)
371 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
374 case IDC_SETUP_BUTTON
:
379 iCurSel
= SendMessage(hList
,
383 if (iCurSel
== CB_ERR
)
386 NewLcid
= SendMessage(hList
,
390 if (NewLcid
== (LCID
)CB_ERR
)
393 SetupApplet(GetParent(hwndDlg
), NewLcid
);
401 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
403 if (lpnm
->code
== (UINT
)PSN_APPLY
)
410 PropSheet_UnChanged(GetParent(hwndDlg
), hwndDlg
);
412 /* Acquire new value */
413 iCurSel
= SendMessage(hList
,
417 if (iCurSel
== CB_ERR
)
420 NewLcid
= SendMessage(hList
,
424 if (NewLcid
== (LCID
)CB_ERR
)
427 iCurSel
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
431 if (iCurSel
== CB_ERR
)
434 NewGeoID
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
438 if (NewGeoID
== (GEOID
)CB_ERR
)
442 SetNewLocale(NewLcid
);
443 AddNewKbLayoutsByLcid(NewLcid
);
444 SetUserGeoID(NewGeoID
);
445 SetNonUnicodeLang(hwndDlg
, NewLcid
);