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 */
241 LocationsEnumProc(GEOID gId
)
243 TCHAR loc
[MAX_STR_SIZE
];
246 GetGeoInfo(gId
, GEO_FRIENDLYNAME
, loc
, MAX_FMT_SIZE
, LANG_SYSTEM_DEFAULT
);
247 index
= (INT
)SendMessage(hGeoList
,
252 SendMessage(hGeoList
,
261 /* Enumerate all system locations identifiers */
264 CreateLocationsList(HWND hWnd
)
268 TCHAR loc
[MAX_STR_SIZE
];
272 EnumSystemGeoID(GEOCLASS_NATION
, 0, LocationsEnumProc
);
274 /* Select current location */
275 userGeoID
= GetUserGeoID(GEOCLASS_NATION
);
276 GetGeoInfo(userGeoID
,
280 LANG_SYSTEM_DEFAULT
);
282 SendMessage(hGeoList
,
290 VerifyUnattendLCID(HWND hwndDlg
)
292 LRESULT lCount
, lIndex
, lResult
;
294 lCount
= SendMessage(hList
, CB_GETCOUNT
, (WPARAM
)0, (LPARAM
)0);
295 if (lCount
== CB_ERR
)
300 for (lIndex
= 0; lIndex
< lCount
; lIndex
++)
302 lResult
= SendMessage(hList
, CB_GETITEMDATA
, (WPARAM
)lIndex
, (LPARAM
)0);
303 if (lResult
== CB_ERR
)
308 if (lResult
== (LCID
)UnattendLCID
)
310 SendMessage(hList
, CB_SETCURSEL
, (WPARAM
)lIndex
, (LPARAM
)0);
311 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
320 /* Property page dialog callback */
322 GeneralPageProc(HWND hwndDlg
,
330 CreateLanguagesList(GetDlgItem(hwndDlg
, IDC_LANGUAGELIST
));
331 UpdateLocaleSample(hwndDlg
, LOCALE_USER_DEFAULT
);
332 CreateLocationsList(GetDlgItem(hwndDlg
, IDC_LOCATION_COMBO
));
333 if (IsUnattendedSetupEnabled
)
335 if (VerifyUnattendLCID(hwndDlg
))
337 SetNewLocale(UnattendLCID
);
345 switch (LOWORD(wParam
))
347 case IDC_LANGUAGELIST
:
348 if (HIWORD(wParam
) == CBN_SELCHANGE
)
353 iCurSel
= SendMessage(hList
,
357 if (iCurSel
== CB_ERR
)
360 NewLcid
= SendMessage(hList
,
364 if (NewLcid
== (LCID
)CB_ERR
)
367 UpdateLocaleSample(hwndDlg
, NewLcid
);
369 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(NewLcid
);
400 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
402 if (lpnm
->code
== (UINT
)PSN_APPLY
)
408 /* Acquire new value */
409 iCurSel
= SendMessage(hList
,
413 if (iCurSel
== CB_ERR
)
416 NewLcid
= SendMessage(hList
,
420 if (NewLcid
== (LCID
)CB_ERR
)
424 SetNewLocale(NewLcid
);