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: dll/cpl/intl/generalp.c
23 * PURPOSE: General property page
24 * PROGRAMMER: Eric Kohl
31 #define SAMPLE_NUMBER _T("123456789")
35 HWND hLocaleList
, hGeoList
;
39 LocalesEnumProc(LPTSTR lpLocale
)
46 lcid
= _tcstoul(lpLocale
, NULL
, 16);
48 /* Display only languages with installed support */
49 if (!IsValidLocale(lcid
, LCID_INSTALLED
))
52 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
53 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
57 LoadString(hApplet
, IDS_SPAIN
, lang
, 255);
67 GetLocaleInfo(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
)/sizeof(TCHAR
));
72 index
= SendMessage(hList
,
86 /* Update all locale samples */
88 UpdateLocaleSample(HWND hwndDlg
, LCID lcidLocale
)
90 TCHAR OutBuffer
[MAX_SAMPLES_STR_SIZE
];
92 /* Get number format sample */
93 GetNumberFormat(lcidLocale
, NO_FLAG
, SAMPLE_NUMBER
, NULL
, OutBuffer
,
94 MAX_SAMPLES_STR_SIZE
);
95 SendMessage(GetDlgItem(hwndDlg
, IDC_NUMSAMPLE_EDIT
),
96 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
98 /* Get monetary format sample */
99 GetCurrencyFormat(lcidLocale
, LOCALE_USE_CP_ACP
, SAMPLE_NUMBER
, NULL
,
100 OutBuffer
, MAX_SAMPLES_STR_SIZE
);
101 SendMessage(GetDlgItem(hwndDlg
, IDC_MONEYSAMPLE_EDIT
),
102 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
104 /* Get time format sample */
105 GetTimeFormat(lcidLocale
, NO_FLAG
, NULL
, NULL
, OutBuffer
, MAX_SAMPLES_STR_SIZE
);
106 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE_EDIT
),
111 /* Get short date format sample */
112 GetDateFormat(lcidLocale
, DATE_SHORTDATE
, NULL
, NULL
, OutBuffer
,
113 MAX_SAMPLES_STR_SIZE
);
114 SendMessage(GetDlgItem(hwndDlg
, IDC_SHORTTIMESAMPLE_EDIT
), WM_SETTEXT
,
115 0, (LPARAM
)OutBuffer
);
117 /* Get long date sample */
118 GetDateFormat(lcidLocale
, DATE_LONGDATE
, NULL
, NULL
, OutBuffer
,
119 MAX_SAMPLES_STR_SIZE
);
120 SendMessage(GetDlgItem(hwndDlg
, IDC_FULLTIMESAMPLE_EDIT
),
121 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
125 CreateLanguagesList(HWND hwnd
)
131 EnumSystemLocales(LocalesEnumProc
, LCID_SUPPORTED
);
133 /* Select current locale */
134 /* or should it be System and not user? */
135 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
)/sizeof(TCHAR
));
143 /* Sets new locale */
145 SetNewLocale(LCID lcid
)
147 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0)
148 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0)
149 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0)
160 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTCODEPAGE
, OEMPage
, sizeof(OEMPage
)/sizeof(TCHAR
));
163 MessageBox(NULL
, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK
);
167 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, ACPPage
, sizeof(ACPPage
)/sizeof(TCHAR
));
170 MessageBox(NULL
, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK
);
174 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
175 if (ret
!= ERROR_SUCCESS
)
177 // Some serious error
178 MessageBox(NULL
, _T("Problem opening HKCU\\Control Panel\\International key"),
179 _T("Big Problem"), MB_OK
);
183 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
184 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
186 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (LPBYTE
)value
, valuesize
);
187 RegCloseKey(localeKey
);
189 ret
= RegOpenKey(HKEY_USERS
, _T(".DEFAULT\\Control Panel\\International"), &localeKey
);
190 if (ret
!= ERROR_SUCCESS
)
192 // Some serious error
193 MessageBox(NULL
, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"),
194 _T("Big Problem"), MB_OK
);
198 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
199 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
201 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
202 RegCloseKey(localeKey
);
205 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
206 if (ret
!= ERROR_SUCCESS
)
208 MessageBoxW(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"),
209 _T("Big Problem"), MB_OK
);
213 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
214 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
216 RegCloseKey(langKey
);
220 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
221 if (ret
!= ERROR_SUCCESS
)
223 MessageBox(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"),
224 _T("Big Problem"), MB_OK
);
228 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
229 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
231 RegCloseKey(langKey
);
234 /* Location enumerate procedure */
237 LocationsEnumProc(GEOID gId
)
239 TCHAR loc
[MAX_STR_SIZE
];
242 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_STR_SIZE
, LANG_SYSTEM_DEFAULT
);
243 index
= (INT
)SendMessage(hGeoList
,
248 SendMessage(hGeoList
,
256 /* Enumerate all system locations identifiers */
259 CreateLocationsList(HWND hWnd
)
262 TCHAR loc
[MAX_STR_SIZE
];
266 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
268 /* Select current location */
269 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
270 GetGeoInfo(userGeoID
,
274 LANG_SYSTEM_DEFAULT
);
276 SendMessage(hGeoList
,
283 VerifyUnattendLCID(HWND hwndDlg
)
285 LRESULT lCount
, lIndex
, lResult
;
287 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
288 if (lCount
== CB_ERR
)
293 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
295 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
296 if (lResult
== CB_ERR
)
301 if (lResult
== (LRESULT
)UnattendLCID
)
303 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
304 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
313 /* Property page dialog callback */
315 GeneralPageProc(HWND hwndDlg
,
323 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
324 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
325 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
326 if (IsUnattendedSetupEnabled
)
328 if (VerifyUnattendLCID(hwndDlg
))
330 SetNewLocale(UnattendLCID
);
333 DPRINT1("VerifyUnattendLCID failed\n");
339 switch (LOWORD(wParam
))
341 case IDC_LANGUAGELIST
:
342 if (HIWORD(wParam
) == CBN_SELCHANGE
)
347 iCurSel
= SendMessage(hList
,
351 if (iCurSel
== CB_ERR
)
354 NewLcid
= SendMessage(hList
,
358 if (NewLcid
== (LCID
)CB_ERR
)
361 UpdateLocaleSample(hwndDlg
, NewLcid
);
363 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
367 case IDC_LOCATION_COMBO
:
368 if (HIWORD(wParam
) == CBN_SELCHANGE
)
370 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
373 case IDC_SETUP_BUTTON
:
378 iCurSel
= SendMessage(hList
,
382 if (iCurSel
== CB_ERR
)
385 NewLcid
= SendMessage(hList
,
389 if (NewLcid
== (LCID
)CB_ERR
)
392 SetupApplet(GetParent(hwndDlg
), NewLcid
);
400 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
402 if (lpnm
->code
== (UINT
)PSN_APPLY
)
409 PropSheet_UnChanged(GetParent(hwndDlg
), hwndDlg
);
411 /* Acquire new value */
412 iCurSel
= SendMessage(hList
,
416 if (iCurSel
== CB_ERR
)
419 NewLcid
= SendMessage(hList
,
423 if (NewLcid
== (LCID
)CB_ERR
)
426 iCurSel
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
430 if (iCurSel
== CB_ERR
)
433 NewGeoID
= SendMessage(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
),
437 if (NewGeoID
== (GEOID
)CB_ERR
)
441 SetNewLocale(NewLcid
);
442 AddNewKbLayoutsByLcid(NewLcid
);
443 SetUserGeoID(NewGeoID
);
444 SetNonUnicodeLang(hwndDlg
, NewLcid
);