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.
21 * PROJECT: ReactOS International Control Panel
22 * FILE: lib/cpl/intl/generalp.c
23 * PURPOSE: General property page
24 * PROGRAMMER: Eric Kohl
37 #define SAMPLE_NUMBER _T("123456789")
41 HWND hLocaleList
, hGeoList
;
45 LocalesEnumProc(LPTSTR lpLocale
)
52 lcid
= _tcstoul(lpLocale
, NULL
, 16);
54 /* Display only languages with installed support */
56 if (!IsValidLocale(lcid, LCID_INSTALLED))
60 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
61 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
65 LoadString(hApplet
, IDS_SPAIN
, lang
, 255);
75 GetLocaleInfo(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
)/sizeof(TCHAR
));
80 index
= SendMessage(hList
,
94 /* Update all locale samples */
96 UpdateLocaleSample(HWND hwndDlg
, LCID lcidLocale
)
98 TCHAR OutBuffer
[MAX_SAMPLES_STR_SIZE
];
100 /* Get number format sample */
101 GetNumberFormat(lcidLocale
, NO_FLAG
, SAMPLE_NUMBER
, NULL
, OutBuffer
,
102 MAX_SAMPLES_STR_SIZE
);
103 SendMessage(GetDlgItem(hwndDlg
, IDC_NUMSAMPLE_EDIT
),
104 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
106 /* Get monetary format sample */
107 GetCurrencyFormat(lcidLocale
, LOCALE_USE_CP_ACP
, SAMPLE_NUMBER
, NULL
,
108 OutBuffer
, MAX_SAMPLES_STR_SIZE
);
109 SendMessage(GetDlgItem(hwndDlg
, IDC_MONEYSAMPLE_EDIT
),
110 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
112 /* Get time format sample */
113 GetTimeFormat(lcidLocale
, NO_FLAG
, NULL
, NULL
, OutBuffer
, MAX_SAMPLES_STR_SIZE
);
114 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE_EDIT
),
119 /* Get short date format sample */
120 GetDateFormat(lcidLocale
, DATE_SHORTDATE
, NULL
, NULL
, OutBuffer
,
121 MAX_SAMPLES_STR_SIZE
);
122 SendMessage(GetDlgItem(hwndDlg
, IDC_SHORTTIMESAMPLE_EDIT
), WM_SETTEXT
,
123 0, (LPARAM
)OutBuffer
);
125 /* Get long date sample */
126 GetDateFormat(lcidLocale
, DATE_LONGDATE
, NULL
, NULL
, OutBuffer
,
127 MAX_SAMPLES_STR_SIZE
);
128 SendMessage(GetDlgItem(hwndDlg
, IDC_FULLTIMESAMPLE_EDIT
),
129 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
133 CreateLanguagesList(HWND hwnd
)
139 EnumSystemLocales(LocalesEnumProc
, LCID_SUPPORTED
);
141 /* Select current locale */
142 /* or should it be System and not user? */
143 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
)/sizeof(TCHAR
));
151 /* Sets new locale */
153 SetNewLocale(LCID lcid
)
155 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0)
156 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0)
157 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0)
168 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTCODEPAGE
, OEMPage
, sizeof(OEMPage
)/sizeof(TCHAR
));
171 MessageBox(NULL
, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK
);
175 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, ACPPage
, sizeof(ACPPage
)/sizeof(TCHAR
));
178 MessageBox(NULL
, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK
);
182 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
183 if (ret
!= ERROR_SUCCESS
)
185 // some serious error
186 MessageBox(NULL
, _T("Problem opening HKCU\\Control Panel\\International key"),
187 _T("Big Problem"), MB_OK
);
191 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
192 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
194 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (LPBYTE
)value
, valuesize
);
195 RegCloseKey(localeKey
);
197 ret
= RegOpenKey(HKEY_USERS
, _T(".DEFAULT\\Control Panel\\International"), &localeKey
);
198 if (ret
!= ERROR_SUCCESS
)
200 // some serious error
201 MessageBox(NULL
, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"),
202 _T("Big Problem"), MB_OK
);
206 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
207 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
209 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
210 RegCloseKey(localeKey
);
213 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
214 if (ret
!= ERROR_SUCCESS
)
216 MessageBoxW(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"),
217 _T("Big Problem"), MB_OK
);
221 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
222 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
224 RegCloseKey(langKey
);
228 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
229 if (ret
!= ERROR_SUCCESS
)
231 MessageBox(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"),
232 _T("Big Problem"), MB_OK
);
236 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
237 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
239 RegCloseKey(langKey
);
242 /* Location enumerate procedure */
245 LocationsEnumProc(GEOID gId
)
247 TCHAR loc
[MAX_STR_SIZE
];
250 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_STR_SIZE
, LANG_SYSTEM_DEFAULT
);
251 index
= (INT
)SendMessage(hGeoList
,
256 SendMessage(hGeoList
,
264 /* Enumerate all system locations identifiers */
267 CreateLocationsList(HWND hWnd
)
270 TCHAR loc
[MAX_STR_SIZE
];
274 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
276 /* Select current location */
277 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
278 GetGeoInfo(userGeoID
,
282 LANG_SYSTEM_DEFAULT
);
284 SendMessage(hGeoList
,
291 VerifyUnattendLCID(HWND hwndDlg
)
293 LRESULT lCount
, lIndex
, lResult
;
295 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
296 if (lCount
== CB_ERR
)
301 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
303 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
304 if (lResult
== CB_ERR
)
309 if (lResult
== (LRESULT
)UnattendLCID
)
311 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
312 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
321 /* Property page dialog callback */
323 GeneralPageProc(HWND hwndDlg
,
331 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
332 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
333 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
334 if (IsUnattendedSetupEnabled
)
336 if (VerifyUnattendLCID(hwndDlg
))
338 SetNewLocale(UnattendLCID
);
346 switch (LOWORD(wParam
))
348 case IDC_LANGUAGELIST
:
349 if (HIWORD(wParam
) == CBN_SELCHANGE
)
354 iCurSel
= SendMessage(hList
,
358 if (iCurSel
== CB_ERR
)
361 NewLcid
= SendMessage(hList
,
365 if (NewLcid
== (LCID
)CB_ERR
)
368 UpdateLocaleSample(hwndDlg
, NewLcid
);
370 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
374 case IDC_LOCATION_COMBO
:
375 if (HIWORD(wParam
) == CBN_SELCHANGE
)
377 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
380 case IDC_SETUP_BUTTON
:
385 iCurSel
= SendMessage(hList
,
389 if (iCurSel
== CB_ERR
)
392 NewLcid
= SendMessage(hList
,
396 if (NewLcid
== (LCID
)CB_ERR
)
399 SetupApplet(GetParent(hwndDlg
), NewLcid
);
407 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
409 if (lpnm
->code
== (UINT
)PSN_APPLY
)
416 PropSheet_UnChanged(GetParent(hwndDlg
), hwndDlg
);
418 /* Acquire new value */
419 iCurSel
= SendMessage(hList
,
423 if (iCurSel
== CB_ERR
)
426 NewLcid
= SendMessage(hList
,
430 if (NewLcid
== (LCID
)CB_ERR
)
433 iCurSel
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
437 if (iCurSel
== CB_ERR
)
440 NewGeoID
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
444 if (NewGeoID
== (GEOID
)CB_ERR
)
448 SetNewLocale(NewLcid
);
449 AddNewKbLayoutsByLcid(NewLcid
);
450 SetUserGeoID(NewGeoID
);
451 SetNonUnicodeLang(hwndDlg
, NewLcid
);