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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS International Control Panel
22 * FILE: lib/cpl/intl/generalp.c
23 * PURPOSE: General property page
24 * PROGRAMMER: Eric Kohl
38 #define SAMPLE_NUMBER _T("123456789")
42 HWND hLocaleList
, hGeoList
;
46 LocalesEnumProc(LPTSTR lpLocale
)
53 lcid
= _tcstoul(lpLocale
, NULL
, 16);
55 if (lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH
), SORT_DEFAULT
) ||
56 lcid
== MAKELCID(MAKELANGID(LANG_SPANISH
, SUBLANG_SPANISH_MODERN
), SORT_DEFAULT
))
60 LoadString(hApplet
, IDS_SPAIN
, lang
, 255);
70 GetLocaleInfo(lcid
, LOCALE_SLANGUAGE
, lang
, sizeof(lang
));
75 index
= SendMessage(hList
,
89 /* Update all locale samples */
91 UpdateLocaleSample(HWND hwndDlg
, LCID lcidLocale
)
93 TCHAR OutBuffer
[MAX_FMT_SIZE
];
95 /* Get number format sample */
96 GetNumberFormat(lcidLocale
, NO_FLAG
, SAMPLE_NUMBER
, NULL
, OutBuffer
,
98 SendMessage(GetDlgItem(hwndDlg
, IDC_NUMSAMPLE_EDIT
),
99 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
101 /* Get monetary format sample */
102 GetCurrencyFormat(lcidLocale
, LOCALE_USE_CP_ACP
, SAMPLE_NUMBER
, NULL
,
103 OutBuffer
, MAX_FMT_SIZE
);
104 SendMessage(GetDlgItem(hwndDlg
, IDC_MONEYSAMPLE_EDIT
),
105 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
107 /* Get time format sample */
108 GetTimeFormat(lcidLocale
, NO_FLAG
, NULL
, NULL
, OutBuffer
, MAX_FMT_SIZE
);
109 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE_EDIT
),
114 /* Get short date format sample */
115 GetDateFormat(lcidLocale
, DATE_SHORTDATE
, NULL
, NULL
, OutBuffer
,
117 SendMessage(GetDlgItem(hwndDlg
, IDC_SHORTTIMESAMPLE_EDIT
), WM_SETTEXT
,
118 0, (LPARAM
)OutBuffer
);
120 /* Get long date sample */
121 GetDateFormat(lcidLocale
, DATE_LONGDATE
, NULL
, NULL
, OutBuffer
,
123 SendMessage(GetDlgItem(hwndDlg
, IDC_FULLTIMESAMPLE_EDIT
),
124 WM_SETTEXT
, 0, (LPARAM
)OutBuffer
);
128 CreateLanguagesList(HWND hwnd
)
134 EnumSystemLocales(LocalesEnumProc
, LCID_SUPPORTED
);
136 /* Select current locale */
137 /* or should it be System and not user? */
138 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE
, langSel
, sizeof(langSel
));
146 /* Sets new locale */
148 SetNewLocale(LCID lcid
)
150 // HKCU\\Control Panel\\International\\Locale = 0409 (type=0)
151 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","Default",0x00000000,"0409" (type=0)
152 // HKLM,"SYSTEM\CurrentControlSet\Control\NLS\Language","InstallLanguage",0x00000000,"0409" (type=0)
163 ret
= GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTCODEPAGE
, (WORD
*)OEMPage
, sizeof(OEMPage
));
166 MessageBox(NULL
, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK
);
170 GetLocaleInfo(MAKELCID(lcid
, SORT_DEFAULT
), LOCALE_IDEFAULTANSICODEPAGE
, (WORD
*)ACPPage
, sizeof(ACPPage
));
173 MessageBox(NULL
, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK
);
177 ret
= RegOpenKey(HKEY_CURRENT_USER
, _T("Control Panel\\International"), &localeKey
);
178 if (ret
!= ERROR_SUCCESS
)
180 // some serious error
181 MessageBox(NULL
, _T("Problem opening HKCU\\Control Panel\\International key"),
182 _T("Big Problem"), MB_OK
);
186 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
187 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
189 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (LPBYTE
)value
, valuesize
);
190 RegCloseKey(localeKey
);
192 ret
= RegOpenKey(HKEY_USERS
, _T(".DEFAULT\\Control Panel\\International"), &localeKey
);
193 if (ret
!= ERROR_SUCCESS
)
195 // some serious error
196 MessageBox(NULL
, _T("Problem opening HKU\\.DEFAULT\\Control Panel\\International key"),
197 _T("Big Problem"), MB_OK
);
201 wsprintf(value
, _T("%04X"), (DWORD
)lcid
);
202 valuesize
= (_tcslen(value
) + 1) * sizeof(TCHAR
);
204 RegSetValueEx(localeKey
, _T("Locale"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
205 RegCloseKey(localeKey
);
208 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"), &langKey
);
209 if (ret
!= ERROR_SUCCESS
)
211 MessageBoxW(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language key"),
212 _T("Big Problem"), MB_OK
);
216 RegSetValueEx(langKey
, _T("Default"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
217 RegSetValueEx(langKey
, _T("InstallLanguage"), 0, REG_SZ
, (BYTE
*)value
, valuesize
);
219 RegCloseKey(langKey
);
223 ret
= RegOpenKey(HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"), &langKey
);
224 if (ret
!= ERROR_SUCCESS
)
226 MessageBox(NULL
, _T("Problem opening HKLM\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage key"),
227 _T("Big Problem"), MB_OK
);
231 RegSetValueExW(langKey
, _T("OEMCP"), 0, REG_SZ
, (BYTE
*)OEMPage
, (_tcslen(OEMPage
) +1 ) * sizeof(TCHAR
));
232 RegSetValueExW(langKey
, _T("ACP"), 0, REG_SZ
, (BYTE
*)ACPPage
, (_tcslen(ACPPage
) +1 ) * sizeof(TCHAR
));
234 RegCloseKey(langKey
);
237 /* Location enumerate procedure */
240 LocationsEnumProc(GEOID gId
)
242 TCHAR loc
[MAX_STR_SIZE
];
245 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_FMT_SIZE
, LANG_SYSTEM_DEFAULT
);
246 index
= (INT
)SendMessage(hGeoList
,
251 SendMessage(hGeoList
,
259 /* Enumerate all system locations identifiers */
262 CreateLocationsList(HWND hWnd
)
265 TCHAR loc
[MAX_STR_SIZE
];
269 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
271 /* Select current location */
272 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
273 GetGeoInfo(userGeoID
,
277 LANG_SYSTEM_DEFAULT
);
279 SendMessage(hGeoList
,
286 VerifyUnattendLCID(HWND hwndDlg
)
288 LRESULT lCount
, lIndex
, lResult
;
290 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
291 if (lCount
== CB_ERR
)
296 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
298 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
299 if (lResult
== CB_ERR
)
304 if (lResult
== (LCID
)UnattendLCID
)
306 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
307 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
316 /* Property page dialog callback */
318 GeneralPageProc(HWND hwndDlg
,
326 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
327 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
328 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
329 if (IsUnattendedSetupEnabled
)
331 if (VerifyUnattendLCID(hwndDlg
))
333 SetNewLocale(UnattendLCID
);
341 switch (LOWORD(wParam
))
343 case IDC_LANGUAGELIST
:
344 if (HIWORD(wParam
) == CBN_SELCHANGE
)
349 iCurSel
= SendMessage(hList
,
353 if (iCurSel
== CB_ERR
)
356 NewLcid
= SendMessage(hList
,
360 if (NewLcid
== (LCID
)CB_ERR
)
363 UpdateLocaleSample(hwndDlg
, NewLcid
);
365 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
369 case IDC_SETUP_BUTTON
:
374 iCurSel
= SendMessage(hList
,
378 if (iCurSel
== CB_ERR
)
381 NewLcid
= SendMessage(hList
,
385 if (NewLcid
== (LCID
)CB_ERR
)
388 SetupApplet(NewLcid
);
396 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
398 if (lpnm
->code
== (UINT
)PSN_APPLY
)
404 /* Acquire new value */
405 iCurSel
= SendMessage(hList
,
409 if (iCurSel
== CB_ERR
)
412 NewLcid
= SendMessage(hList
,
416 if (NewLcid
== (LCID
)CB_ERR
)
420 SetNewLocale(NewLcid
);