Merge 14551:14980 from trunk
[reactos.git] / reactos / lib / cpl / intl / locale.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004, 2005 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS International Control Panel
22 * FILE: lib/cpl/intl/locale.c
23 * PURPOSE: Locale property page
24 * PROGRAMMER: Eric Kohl
25 * Klemens Friedl
26 * Aleksey Bragin
27 */
28
29 #define WINVER 0x0501
30
31 #include <windows.h>
32 #include <commctrl.h>
33 #include <cpl.h>
34
35 #include <stdio.h>
36
37 #include "intl.h"
38 #include "resource.h"
39
40 HWND hList;
41
42 BOOL CALLBACK LocalesEnumProc(
43 LPTSTR lpLocale // locale id
44 )
45 {
46 LCID lcid;
47 TCHAR lang[255];
48 int index;
49
50 //swscanf(lpLocale, L"%lx", &lcid); // maybe use wcstoul?
51 lcid = wcstoul(lpLocale, NULL, 16);
52
53 GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang));
54
55 index = SendMessageW(hList,
56 CB_ADDSTRING,
57 0,
58 (LPARAM)lang);
59
60 SendMessageW(hList,
61 CB_SETITEMDATA,
62 index,
63 (LPARAM)lcid);
64
65 return TRUE;
66 }
67
68
69 static VOID
70 CreateLanguagesList(HWND hwnd)
71 {
72 TCHAR langSel[255];
73
74 hList = hwnd;
75 EnumSystemLocalesW(LocalesEnumProc, LCID_SUPPORTED);
76
77 // Select current locale
78 GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)); // or should it be System and not user?
79
80 SendMessageW(hList,
81 CB_SELECTSTRING,
82 -1,
83 (LPARAM)langSel);
84 }
85
86 /*
87 static VOID
88 ShowLanguagesList(HWND hwnd)
89 {
90 TIME_ZONE_INFORMATION TimeZoneInfo;
91 PTIMEZONE_ENTRY Entry;
92 DWORD dwIndex;
93 DWORD i;
94
95 GetTimeZoneInformation(&TimeZoneInfo);
96
97 dwIndex = 0;
98 i = 0;
99 Entry = TimeZoneListHead;
100 while (Entry != NULL)
101 {
102 SendMessageW(hwnd,
103 CB_ADDSTRING,
104 0,
105 (LPARAM)Entry->Description);
106
107 if (!wcscmp(Entry->StandardName, TimeZoneInfo.StandardName))
108 dwIndex = i;
109
110 i++;
111 Entry = Entry->Next;
112 }
113
114 SendMessageW(hwnd,
115 CB_SETCURSEL,
116 (WPARAM)dwIndex,
117 0);
118 }
119 */
120
121 /* Property page dialog callback */
122 INT_PTR CALLBACK
123 LocalePageProc(HWND hwndDlg,
124 UINT uMsg,
125 WPARAM wParam,
126 LPARAM lParam)
127 {
128 switch(uMsg)
129 {
130 case WM_INITDIALOG:
131 CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST));
132 break;
133 case WM_COMMAND:
134 switch (LOWORD(wParam))
135 {
136 case IDC_LANGUAGELIST:
137 if (HIWORD(wParam) == CBN_SELCHANGE)
138 {
139 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
140 }
141 break;
142 }
143 break;
144
145 case WM_NOTIFY:
146 {
147 LPNMHDR lpnm = (LPNMHDR)lParam;
148 if (lpnm->code == PSN_APPLY)
149 {
150 // Apply changes
151 LCID NewLcid;
152 int iCurSel;
153 char tmp[100];
154
155 // Acquire new value
156 iCurSel = SendMessageW(hList,
157 CB_GETCURSEL,
158 0,
159 0);
160 if (iCurSel == CB_ERR)
161 break;
162
163 NewLcid = SendMessageW(hList,
164 CB_GETITEMDATA,
165 iCurSel,
166 0);
167
168 if (NewLcid == CB_ERR)
169 break;
170
171
172 //TOOD: Actually set new locale
173
174 sprintf(tmp, "%lx, cursel=%d", NewLcid, iCurSel);
175 MessageBoxA(hwndDlg, tmp, "debug", MB_OK);
176 }
177 }
178 break;
179 }
180 return FALSE;
181 }
182
183
184 /* EOF */