3 * Copyright (C) 2004 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 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.
20 * PROJECT: ReactOS International Control Panel
21 * FILE: dll/cpl/intl/time.c
22 * PURPOSE: Time property page
23 * PROGRAMMER: Eric Kohl
28 static HWND hwndEnum
= NULL
;
31 TimeFormatEnumProc(PWSTR lpTimeFormatString
)
33 SendMessageW(hwndEnum
,
36 (LPARAM
)lpTimeFormatString
);
42 UpdateTimeSample(HWND hWnd
, PGLOBALDATA pGlobalData
)
44 WCHAR szBuffer
[MAX_SAMPLES_STR_SIZE
];
46 GetTimeFormatW(pGlobalData
->UserLCID
, 0, NULL
,
47 pGlobalData
->szTimeFormat
, szBuffer
,
48 MAX_SAMPLES_STR_SIZE
);
49 SendDlgItemMessageW(hWnd
, IDC_TIMESAMPLE
, WM_SETTEXT
, 0, (LPARAM
)szBuffer
);
54 GetSelectedComboEntry(HWND hwndDlg
, DWORD dwIdc
, WCHAR
*Buffer
, UINT uSize
)
59 /* Get handle to time format control */
60 hChildWnd
= GetDlgItem(hwndDlg
, dwIdc
);
61 /* Get index to selected time format */
62 nIndex
= SendMessageW(hChildWnd
, CB_GETCURSEL
, 0, 0);
64 /* No selection? Get content of the edit control */
65 SendMessageW(hChildWnd
, WM_GETTEXT
, uSize
, (LPARAM
)Buffer
);
70 /* Get requested size, including the null terminator;
71 * it shouldn't be required because the previous CB_LIMITTEXT,
72 * but it would be better to check it anyways */
73 uReqSize
= SendMessageW(hChildWnd
, CB_GETLBTEXTLEN
, (WPARAM
)nIndex
, 0) + 1;
74 /* Allocate enough space to be more safe */
75 tmp
= (PWSTR
)_alloca(uReqSize
*sizeof(WCHAR
));
76 /* Get selected time format text */
77 SendMessageW(hChildWnd
, CB_GETLBTEXT
, (WPARAM
)nIndex
, (LPARAM
)tmp
);
78 /* Finally, copy the result into the output */
79 wcsncpy(Buffer
, tmp
, uSize
);
88 PGLOBALDATA pGlobalData
)
90 /* Get the time format */
91 SendDlgItemMessageW(hwndDlg
, IDC_TIMEFORMAT
,
92 CB_LIMITTEXT
, MAX_TIMEFORMAT
, 0);
94 /* Add available time formats to the list */
95 hwndEnum
= GetDlgItem(hwndDlg
, IDC_TIMEFORMAT
);
96 EnumTimeFormatsW(TimeFormatEnumProc
, pGlobalData
->UserLCID
, 0);
98 SendDlgItemMessageW(hwndDlg
, IDC_TIMEFORMAT
,
101 (LPARAM
)pGlobalData
->szTimeFormat
);
108 PGLOBALDATA pGlobalData
)
110 SendDlgItemMessageW(hwndDlg
, IDC_TIMESEPARATOR
,
111 CB_LIMITTEXT
, MAX_TIMESEPARATOR
, 0);
113 SendDlgItemMessageW(hwndDlg
, IDC_TIMESEPARATOR
,
116 (LPARAM
)pGlobalData
->szTimeSep
);
118 SendDlgItemMessageW(hwndDlg
, IDC_TIMESEPARATOR
,
129 PGLOBALDATA pGlobalData
)
133 SendDlgItemMessageW(hwndDlg
, IDC_TIMEAMSYMBOL
,
134 CB_LIMITTEXT
, MAX_TIMEAMSYMBOL
, 0);
136 nLen
= wcslen(pGlobalData
->szTimeAM
);
138 SendDlgItemMessageW(hwndDlg
, IDC_TIMEAMSYMBOL
,
141 (LPARAM
)pGlobalData
->szTimeAM
);
144 SendDlgItemMessageW(hwndDlg
, IDC_TIMEAMSYMBOL
,
150 SendDlgItemMessageW(hwndDlg
, IDC_TIMEAMSYMBOL
,
161 PGLOBALDATA pGlobalData
)
165 SendDlgItemMessageW(hwndDlg
, IDC_TIMEPMSYMBOL
,
166 CB_LIMITTEXT
, MAX_TIMEPMSYMBOL
, 0);
168 nLen
= wcslen(pGlobalData
->szTimeAM
);
170 SendDlgItemMessageW(hwndDlg
, IDC_TIMEPMSYMBOL
,
173 (LPARAM
)pGlobalData
->szTimePM
);
176 SendDlgItemMessageW(hwndDlg
, IDC_TIMEPMSYMBOL
,
181 SendDlgItemMessageW(hwndDlg
, IDC_TIMEPMSYMBOL
,
188 /* Property page dialog callback */
190 TimePageProc(HWND hwndDlg
,
195 PGLOBALDATA pGlobalData
;
197 pGlobalData
= (PGLOBALDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
202 pGlobalData
= (PGLOBALDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
203 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
205 /* Get the time format */
206 InitTimeFormatCB(hwndDlg
, pGlobalData
);
208 /* Get the time separator */
209 InitTimeSeparatorCB(hwndDlg
, pGlobalData
);
211 /* Get the AM symbol */
212 InitAmSymbol(hwndDlg
, pGlobalData
);
214 /* Get the PM symbol */
215 InitPmSymbol(hwndDlg
, pGlobalData
);
217 /* Update the time format sample */
218 UpdateTimeSample(hwndDlg
, pGlobalData
);
222 switch (LOWORD(wParam
))
225 case IDC_TIMESEPARATOR
:
226 case IDC_TIMEAMSYMBOL
:
227 case IDC_TIMEPMSYMBOL
:
228 if (HIWORD(wParam
) == CBN_SELCHANGE
||
229 HIWORD(wParam
) == CBN_EDITCHANGE
)
231 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
238 if (((LPNMHDR
)lParam
)->code
== (UINT
)PSN_APPLY
)
240 /* Get selected/typed time format text */
241 GetSelectedComboEntry(hwndDlg
, IDC_TIMEFORMAT
,
242 pGlobalData
->szTimeFormat
,
245 /* Get selected/typed time separator text */
246 GetSelectedComboEntry(hwndDlg
, IDC_TIMESEPARATOR
,
247 pGlobalData
->szTimeSep
,
250 /* Get selected/typed AM symbol text */
251 GetSelectedComboEntry(hwndDlg
, IDC_TIMEAMSYMBOL
,
252 pGlobalData
->szTimeAM
,
255 /* Get selected/typed PM symbol text */
256 GetSelectedComboEntry(hwndDlg
, IDC_TIMEPMSYMBOL
,
257 pGlobalData
->szTimePM
,
260 pGlobalData
->fUserLocaleChanged
= TRUE
;
262 /* Update the time format sample */
263 UpdateTimeSample(hwndDlg
, pGlobalData
);