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
30 #define SAMPLE_NUMBER _T("123456789")
34 HWND hLocaleList
, hGeoList
;
38 LocalesEnumProc(LPTSTR lpLocale
)
45 lcid
= _tcstoul(lpLocale
, NULL
, 16);
47 /* Display only languages with installed support */
48 if (!IsValidLocale(lcid
, LCID_INSTALLED
))
51 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
52 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
56 LoadString(hApplet
, IDS_SPAIN
, lang
, 255);
66 GetLocaleInfo(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
)/sizeof(TCHAR
));
71 index
= SendMessage(hList
,
85 /* Update all locale samples */
87 UpdateLocaleSample(HWND hwndDlg
, LCID lcidLocale
)
89 TCHAR OutBuffer
[MAX_SAMPLES_STR_SIZE
];
91 /* Get number format sample */
92 GetNumberFormat(lcidLocale
, NO_FLAG
, SAMPLE_NUMBER
, NULL
, OutBuffer
,
93 MAX_SAMPLES_STR_SIZE
);
94 SendMessage(GetDlgItem(hwndDlg
, IDC_NUMSAMPLE_EDIT
),
95 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
97 /* Get monetary format sample */
98 GetCurrencyFormat(lcidLocale
, LOCALE_USE_CP_ACP
, SAMPLE_NUMBER
, NULL
,
99 OutBuffer
, MAX_SAMPLES_STR_SIZE
);
100 SendMessage(GetDlgItem(hwndDlg
, IDC_MONEYSAMPLE_EDIT
),
101 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
103 /* Get time format sample */
104 GetTimeFormat(lcidLocale
, NO_FLAG
, NULL
, NULL
, OutBuffer
, MAX_SAMPLES_STR_SIZE
);
105 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE_EDIT
),
110 /* Get short date format sample */
111 GetDateFormat(lcidLocale
, DATE_SHORTDATE
, NULL
, NULL
, OutBuffer
,
112 MAX_SAMPLES_STR_SIZE
);
113 SendMessage(GetDlgItem(hwndDlg
, IDC_SHORTTIMESAMPLE_EDIT
), WM_SETTEXT
,
114 0, (LPARAM
)OutBuffer
);
116 /* Get long date sample */
117 GetDateFormat(lcidLocale
, DATE_LONGDATE
, NULL
, NULL
, OutBuffer
,
118 MAX_SAMPLES_STR_SIZE
);
119 SendMessage(GetDlgItem(hwndDlg
, IDC_FULLTIMESAMPLE_EDIT
),
120 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
124 CreateLanguagesList(HWND hwnd
)
130 EnumSystemLocales(LocalesEnumProc
, LCID_SUPPORTED
);
132 /* Select current locale */
133 /* or should it be System and not user? */
134 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
)/sizeof(TCHAR
));
142 /* Sets new locale */
144 SetNewLocale(LCID lcid
)
146 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0)
147 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0)
148 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0)
159 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTCODEPAGE
, OEMPage
, sizeof(OEMPage
)/sizeof(TCHAR
));
162 MessageBox(NULL
, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK
);
166 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, ACPPage
, sizeof(ACPPage
)/sizeof(TCHAR
));
169 MessageBox(NULL
, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK
);
173 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
174 if (ret
!= ERROR_SUCCESS
)
176 // Some serious error
177 MessageBox(NULL
, _T("Problem opening HKCU\\Control Panel\\International key"),
178 _T("Big Problem"), MB_OK
);
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 // Some serious error
192 MessageBox(NULL
, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"),
193 _T("Big Problem"), MB_OK
);
197 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
198 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
200 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
201 RegCloseKey(localeKey
);
204 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
205 if (ret
!= ERROR_SUCCESS
)
207 MessageBoxW(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"),
208 _T("Big Problem"), MB_OK
);
212 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
213 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
215 RegCloseKey(langKey
);
219 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
220 if (ret
!= ERROR_SUCCESS
)
222 MessageBox(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"),
223 _T("Big Problem"), MB_OK
);
227 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
228 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
230 RegCloseKey(langKey
);
233 /* Location enumerate procedure */
236 LocationsEnumProc(GEOID gId
)
238 TCHAR loc
[MAX_STR_SIZE
];
241 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_STR_SIZE
, LANG_SYSTEM_DEFAULT
);
242 index
= (INT
)SendMessage(hGeoList
,
247 SendMessage(hGeoList
,
255 /* Enumerate all system locations identifiers */
258 CreateLocationsList(HWND hWnd
)
261 TCHAR loc
[MAX_STR_SIZE
];
265 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
267 /* Select current location */
268 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
269 GetGeoInfo(userGeoID
,
273 LANG_SYSTEM_DEFAULT
);
275 SendMessage(hGeoList
,
282 VerifyUnattendLCID(HWND hwndDlg
)
284 LRESULT lCount
, lIndex
, lResult
;
286 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
287 if (lCount
== CB_ERR
)
292 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
294 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
295 if (lResult
== CB_ERR
)
300 if (lResult
== (LRESULT
)UnattendLCID
)
302 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
303 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
312 /* Property page dialog callback */
314 GeneralPageProc(HWND hwndDlg
,
322 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
323 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
324 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
325 if (IsUnattendedSetupEnabled
)
327 if (VerifyUnattendLCID(hwndDlg
))
329 SetNewLocale(UnattendLCID
);
332 DPRINT1("VerifyUnattendLCID failed\n");
338 switch (LOWORD(wParam
))
340 case IDC_LANGUAGELIST
:
341 if (HIWORD(wParam
) == CBN_SELCHANGE
)
346 iCurSel
= SendMessage(hList
,
350 if (iCurSel
== CB_ERR
)
353 NewLcid
= SendMessage(hList
,
357 if (NewLcid
== (LCID
)CB_ERR
)
360 UpdateLocaleSample(hwndDlg
, NewLcid
);
362 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
366 case IDC_LOCATION_COMBO
:
367 if (HIWORD(wParam
) == CBN_SELCHANGE
)
369 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
372 case IDC_SETUP_BUTTON
:
377 iCurSel
= SendMessage(hList
,
381 if (iCurSel
== CB_ERR
)
384 NewLcid
= SendMessage(hList
,
388 if (NewLcid
== (LCID
)CB_ERR
)
391 SetupApplet(GetParent(hwndDlg
), NewLcid
);
399 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
401 if (lpnm
->code
== (UINT
)PSN_APPLY
)
408 PropSheet_UnChanged(GetParent(hwndDlg
), hwndDlg
);
410 /* Acquire new value */
411 iCurSel
= SendMessage(hList
,
415 if (iCurSel
== CB_ERR
)
418 NewLcid
= SendMessage(hList
,
422 if (NewLcid
== (LCID
)CB_ERR
)
425 iCurSel
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
429 if (iCurSel
== CB_ERR
)
432 NewGeoID
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
436 if (NewGeoID
== (GEOID
)CB_ERR
)
440 SetNewLocale(NewLcid
);
441 AddNewKbLayoutsByLcid(NewLcid
);
442 SetUserGeoID(NewGeoID
);
443 SetNonUnicodeLang(hwndDlg
, NewLcid
);