reshuffling of dlls
[reactos.git] / reactos / dll / cpl / intl / time.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 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 /*
20 * PROJECT: ReactOS International Control Panel
21 * FILE: lib/cpl/intl/time.c
22 * PURPOSE: Time property page
23 * PROGRAMMER: Eric Kohl
24 */
25
26 #include <windows.h>
27 #include <commctrl.h>
28 #include <cpl.h>
29
30 #include "intl.h"
31 #include "resource.h"
32
33 /*
34 * TODO:
35 * - Enumerate available time formats (use EnumTimeformatsW)
36 */
37
38 static VOID
39 UpdateTimeSample(HWND hWnd)
40 {
41 WCHAR InBuffer[80];
42 WCHAR OutBuffer[80];
43
44 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, InBuffer, 80);
45
46 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, InBuffer, OutBuffer, 80);
47
48 SendMessageW(hWnd, WM_SETTEXT, 0, (LPARAM)OutBuffer);
49 }
50
51
52 /* Property page dialog callback */
53 INT_PTR CALLBACK
54 TimePageProc(HWND hwndDlg,
55 UINT uMsg,
56 WPARAM wParam,
57 LPARAM lParam)
58 {
59 switch(uMsg)
60 {
61 case WM_INITDIALOG:
62 {
63 WCHAR Buffer[80];
64 int nLen;
65
66 /* Update the time format sample */
67 UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE));
68
69 /* Get the time format (max. 80 characters) */
70 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
71 CB_LIMITTEXT, 80, 0);
72
73 /* FIXME: add available time formats to the list */
74
75 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, Buffer, 80);
76 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
77 CB_ADDSTRING,
78 0,
79 (LPARAM)Buffer);
80 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
81 CB_SETCURSEL,
82 0, /* index */
83 0);
84
85 /* Get the time separator (max. 4 characters) */
86 SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
87 CB_LIMITTEXT, 4, 0);
88 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STIME, Buffer, 80);
89 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
90 CB_ADDSTRING,
91 0,
92 (LPARAM)Buffer);
93 SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
94 CB_SETCURSEL,
95 0, /* index */
96 0);
97
98 /* Get the AM symbol (max. 9 characters) */
99 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
100 CB_LIMITTEXT, 9, 0);
101 nLen = GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S1159, Buffer, 80);
102 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
103 CB_ADDSTRING,
104 0,
105 (LPARAM)Buffer);
106 if (nLen != 0)
107 {
108 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
109 CB_ADDSTRING,
110 0,
111 (LPARAM)L"");
112 }
113 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
114 CB_SETCURSEL,
115 0, /* index */
116 0);
117
118 /* Get the PM symbol (max. 9 characters) */
119 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
120 CB_LIMITTEXT, 9, 0);
121 nLen = GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S2359, Buffer, 80);
122 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
123 CB_ADDSTRING,
124 0,
125 (LPARAM)Buffer);
126 if (nLen != 0)
127 {
128 SendMessageW(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
129 CB_ADDSTRING,
130 0,
131 (LPARAM)L"");
132 }
133 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
134 CB_SETCURSEL,
135 0, /* index */
136 0);
137 }
138 break;
139
140 case WM_COMMAND:
141 switch (LOWORD(wParam))
142 {
143 case IDC_TIMEFORMAT:
144 case IDC_TIMESEPARATOR:
145 case IDC_TIMEAMSYMBOL:
146 case IDC_TIMEPMSYMBOL:
147 if (HIWORD(wParam) == CBN_SELCHANGE ||
148 HIWORD(wParam) == CBN_EDITCHANGE)
149 {
150 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
151 }
152 break;
153 }
154 break;
155
156 case WM_NOTIFY:
157 {
158 LPNMHDR lpnm = (LPNMHDR)lParam;
159
160 if (lpnm->code == (UINT)PSN_APPLY)
161 {
162 WCHAR Buffer[80];
163 int nIndex;
164
165 /* Set time format */
166 nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
167 CB_GETCURSEL, 0, 0);
168 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
169 CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
170 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, Buffer);
171
172 /* Set time separator */
173 nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
174 CB_GETCURSEL, 0, 0);
175 SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
176 CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
177 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STIME, Buffer);
178
179 /* Set the AM symbol */
180 nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
181 CB_GETCURSEL, 0, 0);
182 if (nIndex != CB_ERR)
183 {
184 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
185 CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
186 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S1159, Buffer);
187 }
188 else
189 {
190 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S1159, L"");
191 }
192
193 /* Set the PM symbol */
194 nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
195 CB_GETCURSEL, 0, 0);
196 if (nIndex != CB_ERR)
197 {
198 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
199 CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
200 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S2359, Buffer);
201 }
202 else
203 {
204 SetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_S2359, L"");
205 }
206
207 /* Update the time format sample */
208 UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE));
209 }
210 }
211 break;
212 }
213
214 return FALSE;
215 }
216
217 /* EOF */