[WINHTTP] Sync with Wine Staging 3.9. CORE-14656
[reactos.git] / 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 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.
18 */
19 /*
20 * PROJECT: ReactOS International Control Panel
21 * FILE: dll/cpl/intl/time.c
22 * PURPOSE: Time property page
23 * PROGRAMMERS: Eric Kohl
24 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
25 */
26
27 #include "intl.h"
28
29 static HWND hwndTimeEnum = NULL;
30
31 static BOOL CALLBACK
32 TimeFormatEnumProc(PWSTR lpTimeFormatString)
33 {
34 SendMessageW(hwndTimeEnum,
35 CB_ADDSTRING,
36 0,
37 (LPARAM)lpTimeFormatString);
38
39 return TRUE;
40 }
41
42 static VOID
43 UpdateTimeSample(HWND hWnd, PGLOBALDATA pGlobalData)
44 {
45 WCHAR szBuffer[MAX_SAMPLES_STR_SIZE];
46
47 GetTimeFormatW(pGlobalData->UserLCID, 0, NULL,
48 pGlobalData->szTimeFormat, szBuffer,
49 MAX_SAMPLES_STR_SIZE);
50 SendDlgItemMessageW(hWnd, IDC_TIMESAMPLE, WM_SETTEXT, 0, (LPARAM)szBuffer);
51 }
52
53
54 static
55 VOID
56 InitTimeFormatCB(
57 HWND hwndDlg,
58 PGLOBALDATA pGlobalData)
59 {
60 /* Get the time format */
61 SendDlgItemMessageW(hwndDlg, IDC_TIMEFORMAT,
62 CB_LIMITTEXT, MAX_TIMEFORMAT, 0);
63
64 /* Add available time formats to the list */
65 hwndTimeEnum = GetDlgItem(hwndDlg, IDC_TIMEFORMAT);
66 EnumTimeFormatsW(TimeFormatEnumProc, pGlobalData->UserLCID, 0);
67
68 SendDlgItemMessageW(hwndDlg, IDC_TIMEFORMAT,
69 CB_SELECTSTRING,
70 -1,
71 (LPARAM)pGlobalData->szTimeFormat);
72 }
73
74 static
75 VOID
76 InitTimeSeparatorCB(
77 HWND hwndDlg,
78 PGLOBALDATA pGlobalData)
79 {
80 SendDlgItemMessageW(hwndDlg, IDC_TIMESEPARATOR,
81 CB_LIMITTEXT, MAX_TIMESEPARATOR, 0);
82
83 SendDlgItemMessageW(hwndDlg, IDC_TIMESEPARATOR,
84 CB_ADDSTRING,
85 0,
86 (LPARAM)pGlobalData->szTimeSep);
87
88 SendDlgItemMessageW(hwndDlg, IDC_TIMESEPARATOR,
89 CB_SETCURSEL,
90 0, /* Index */
91 0);
92 }
93
94
95 static
96 VOID
97 InitAmSymbol(
98 HWND hwndDlg,
99 PGLOBALDATA pGlobalData)
100 {
101 int nLen;
102
103 SendDlgItemMessageW(hwndDlg, IDC_TIMEAMSYMBOL,
104 CB_LIMITTEXT, MAX_TIMEAMSYMBOL, 0);
105
106 nLen = wcslen(pGlobalData->szTimeAM);
107
108 SendDlgItemMessageW(hwndDlg, IDC_TIMEAMSYMBOL,
109 CB_ADDSTRING,
110 0,
111 (LPARAM)pGlobalData->szTimeAM);
112 if (nLen != 0)
113 {
114 SendDlgItemMessageW(hwndDlg, IDC_TIMEAMSYMBOL,
115 CB_ADDSTRING,
116 0,
117 (LPARAM)L"");
118 }
119
120 SendDlgItemMessageW(hwndDlg, IDC_TIMEAMSYMBOL,
121 CB_SETCURSEL,
122 0, /* Index */
123 0);
124 }
125
126
127 static
128 VOID
129 InitPmSymbol(
130 HWND hwndDlg,
131 PGLOBALDATA pGlobalData)
132 {
133 int nLen;
134
135 SendDlgItemMessageW(hwndDlg, IDC_TIMEPMSYMBOL,
136 CB_LIMITTEXT, MAX_TIMEPMSYMBOL, 0);
137
138 nLen = wcslen(pGlobalData->szTimeAM);
139
140 SendDlgItemMessageW(hwndDlg, IDC_TIMEPMSYMBOL,
141 CB_ADDSTRING,
142 0,
143 (LPARAM)pGlobalData->szTimePM);
144 if (nLen != 0)
145 {
146 SendDlgItemMessageW(hwndDlg, IDC_TIMEPMSYMBOL,
147 CB_ADDSTRING,
148 0,
149 (LPARAM)L"");
150 }
151 SendDlgItemMessageW(hwndDlg, IDC_TIMEPMSYMBOL,
152 CB_SETCURSEL,
153 0, /* Index */
154 0);
155 }
156
157
158 static
159 BOOL
160 GetTimeSetting(
161 HWND hwndDlg,
162 PGLOBALDATA pGlobalData)
163 {
164 WCHAR szTimeFormat[MAX_TIMEFORMAT];
165 WCHAR szTimeSep[MAX_TIMESEPARATOR];
166 WCHAR szTimeAM[MAX_TIMEAMSYMBOL];
167 WCHAR szTimePM[MAX_TIMEPMSYMBOL];
168
169 /* Time format */
170 GetSelectedComboBoxText(hwndDlg,
171 IDC_TIMEFORMAT,
172 szTimeFormat,
173 MAX_TIMEFORMAT);
174
175 /* Check the time format */
176 if (szTimeFormat[0] == L'\0')
177 {
178 /* TODO: Show error message */
179
180 return FALSE;
181 }
182
183 /* Time separator */
184 GetSelectedComboBoxText(hwndDlg,
185 IDC_TIMESEPARATOR,
186 szTimeSep,
187 MAX_TIMESEPARATOR);
188
189 /* Check the time separator */
190 if (szTimeSep[0] == L'\0')
191 {
192 /* TODO: Show error message */
193
194 return FALSE;
195 }
196
197 /* AM symbol */
198 GetSelectedComboBoxText(hwndDlg,
199 IDC_TIMEAMSYMBOL,
200 szTimeAM,
201 MAX_TIMEAMSYMBOL);
202
203 /* PM symbol */
204 GetSelectedComboBoxText(hwndDlg,
205 IDC_TIMEPMSYMBOL,
206 szTimePM,
207 MAX_TIMEPMSYMBOL);
208
209 /* Store settings in global data */
210 wcscpy(pGlobalData->szTimeFormat, szTimeFormat);
211 wcscpy(pGlobalData->szTimeSep, szTimeSep);
212 wcscpy(pGlobalData->szTimeAM, szTimeAM);
213 wcscpy(pGlobalData->szTimePM, szTimePM);
214
215 return TRUE;
216 }
217
218 /* Property page dialog callback */
219 INT_PTR CALLBACK
220 TimePageProc(HWND hwndDlg,
221 UINT uMsg,
222 WPARAM wParam,
223 LPARAM lParam)
224 {
225 PGLOBALDATA pGlobalData;
226
227 pGlobalData = (PGLOBALDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
228
229 switch (uMsg)
230 {
231 case WM_INITDIALOG:
232 pGlobalData = (PGLOBALDATA)((LPPROPSHEETPAGE)lParam)->lParam;
233 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
234
235 /* Get the time format */
236 InitTimeFormatCB(hwndDlg, pGlobalData);
237
238 /* Get the time separator */
239 InitTimeSeparatorCB(hwndDlg, pGlobalData);
240
241 /* Get the AM symbol */
242 InitAmSymbol(hwndDlg, pGlobalData);
243
244 /* Get the PM symbol */
245 InitPmSymbol(hwndDlg, pGlobalData);
246
247 /* Update the time format sample */
248 UpdateTimeSample(hwndDlg, pGlobalData);
249 break;
250
251 case WM_COMMAND:
252 switch (LOWORD(wParam))
253 {
254 case IDC_TIMEFORMAT:
255 case IDC_TIMESEPARATOR:
256 case IDC_TIMEAMSYMBOL:
257 case IDC_TIMEPMSYMBOL:
258 if (HIWORD(wParam) == CBN_SELCHANGE ||
259 HIWORD(wParam) == CBN_EDITCHANGE)
260 {
261 /* Enable the Apply button */
262 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
263 }
264 break;
265 }
266 break;
267
268 case WM_NOTIFY:
269 if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
270 {
271 if (GetTimeSetting(hwndDlg, pGlobalData))
272 {
273 pGlobalData->bUserLocaleChanged = TRUE;
274 UpdateTimeSample(hwndDlg, pGlobalData);
275 }
276 }
277 break;
278 }
279
280 return FALSE;
281 }
282
283 /* EOF */