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 PrintErrorMsgBox(IDS_ERROR_OEM_CODE_PAGE
);
168 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, ACPPage
, sizeof(ACPPage
)/sizeof(TCHAR
));
171 PrintErrorMsgBox(IDS_ERROR_ANSI_CODE_PAGE
);
175 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
176 if (ret
!= ERROR_SUCCESS
)
178 PrintErrorMsgBox(IDS_ERROR_INT_KEY_REG
);
182 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
183 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
185 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (LPBYTE
)value
, valuesize
);
186 RegCloseKey(localeKey
);
188 ret
= RegOpenKey(HKEY_USERS
, _T(".DEFAULT\\Control Panel\\International"), &localeKey
);
189 if (ret
!= ERROR_SUCCESS
)
191 PrintErrorMsgBox(IDS_ERROR_DEF_INT_KEY_REG
);
195 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
196 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
198 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
199 RegCloseKey(localeKey
);
202 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
203 if (ret
!= ERROR_SUCCESS
)
205 PrintErrorMsgBox(IDS_ERROR_NLS_KEY_REG
);
209 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
210 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
212 RegCloseKey(langKey
);
216 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
217 if (ret
!= ERROR_SUCCESS
)
219 PrintErrorMsgBox(IDS_ERROR_NLS_CODE_REG
);
223 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
224 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
226 RegCloseKey(langKey
);
229 /* Location enumerate procedure */
232 LocationsEnumProc(GEOID gId
)
234 TCHAR loc
[MAX_STR_SIZE
];
237 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_STR_SIZE
, LANG_SYSTEM_DEFAULT
);
238 index
= (INT
)SendMessage(hGeoList
,
243 SendMessage(hGeoList
,
251 /* Enumerate all system locations identifiers */
254 CreateLocationsList(HWND hWnd
)
257 TCHAR loc
[MAX_STR_SIZE
];
261 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
263 /* Select current location */
264 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
265 GetGeoInfo(userGeoID
,
269 LANG_SYSTEM_DEFAULT
);
271 SendMessage(hGeoList
,
278 VerifyUnattendLCID(HWND hwndDlg
)
280 LRESULT lCount
, lIndex
, lResult
;
282 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
283 if (lCount
== CB_ERR
)
288 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
290 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
291 if (lResult
== CB_ERR
)
296 if (lResult
== (LRESULT
)UnattendLCID
)
298 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
299 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
308 /* Property page dialog callback */
310 GeneralPageProc(HWND hwndDlg
,
318 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
319 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
320 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
321 if (IsUnattendedSetupEnabled
)
323 if (VerifyUnattendLCID(hwndDlg
))
325 SetNewLocale(UnattendLCID
);
328 DPRINT1("VerifyUnattendLCID failed\n");
334 switch (LOWORD(wParam
))
336 case IDC_LANGUAGELIST
:
337 if (HIWORD(wParam
) == CBN_SELCHANGE
)
342 iCurSel
= SendMessage(hList
,
346 if (iCurSel
== CB_ERR
)
349 NewLcid
= SendMessage(hList
,
353 if (NewLcid
== (LCID
)CB_ERR
)
356 UpdateLocaleSample(hwndDlg
, NewLcid
);
358 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
362 case IDC_LOCATION_COMBO
:
363 if (HIWORD(wParam
) == CBN_SELCHANGE
)
365 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
368 case IDC_SETUP_BUTTON
:
373 iCurSel
= SendMessage(hList
,
377 if (iCurSel
== CB_ERR
)
380 NewLcid
= SendMessage(hList
,
384 if (NewLcid
== (LCID
)CB_ERR
)
387 SetupApplet(GetParent(hwndDlg
), NewLcid
);
395 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
397 if (lpnm
->code
== (UINT
)PSN_APPLY
)
404 PropSheet_UnChanged(GetParent(hwndDlg
), hwndDlg
);
406 /* Acquire new value */
407 iCurSel
= SendMessage(hList
,
411 if (iCurSel
== CB_ERR
)
414 NewLcid
= SendMessage(hList
,
418 if (NewLcid
== (LCID
)CB_ERR
)
421 iCurSel
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
425 if (iCurSel
== CB_ERR
)
428 NewGeoID
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
432 if (NewGeoID
== (GEOID
)CB_ERR
)
436 SetNewLocale(NewLcid
);
437 AddNewKbLayoutsByLcid(NewLcid
);
438 SetUserGeoID(NewGeoID
);
439 SetNonUnicodeLang(hwndDlg
, NewLcid
);