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: lib/cpl/intl/time.c
22 * PURPOSE: Time property page
23 * PROGRAMMER: Eric Kohl
35 static HWND hwndEnum
= NULL
;
38 TimeFormatEnumProc(LPTSTR lpTimeFormatString
)
43 (LPARAM
)lpTimeFormatString
);
49 UpdateTimeSample(HWND hWnd
, LCID lcid
)
53 GetTimeFormat(lcid
, 0, NULL
, NULL
, szBuffer
, 80);
54 SendMessage(hWnd
, WM_SETTEXT
, 0, (LPARAM
)szBuffer
);
59 GetSelectedComboEntry(HWND hwndDlg
, DWORD dwIdc
, TCHAR
*Buffer
, UINT uSize
)
64 /* get handle to time format control */
65 hChildWnd
= GetDlgItem(hwndDlg
, dwIdc
);
66 /* Get index to selected time format */
67 nIndex
= SendMessage(hChildWnd
, CB_GETCURSEL
, 0, 0);
69 /* no selection? get content of the edit control */
70 SendMessage(hChildWnd
, WM_GETTEXT
, uSize
, (LPARAM
)Buffer
);
75 /* get requested size, including the null terminator;
76 * it shouldn't be required because the previous CB_LIMITTEXT,
77 * but it would be better to check it anyways */
78 uReqSize
= SendMessage(hChildWnd
, CB_GETLBTEXTLEN
, (WPARAM
)nIndex
, 0) + 1;
79 /* allocate enough space to be more safe */
80 tmp
= (LPTSTR
)_alloca(uReqSize
*sizeof(TCHAR
));
81 /* get selected time format text */
82 SendMessage(hChildWnd
, CB_GETLBTEXT
, (WPARAM
)nIndex
, (LPARAM
)tmp
);
83 /* finally, copy the result into the output */
84 _tcsncpy(Buffer
, tmp
, uSize
);
88 /* Property page dialog callback */
90 TimePageProc(HWND hwndDlg
,
95 PGLOBALDATA pGlobalData
;
97 pGlobalData
= (PGLOBALDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
106 pGlobalData
= (PGLOBALDATA
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
107 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
109 /* Update the time format sample */
110 UpdateTimeSample(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE
), pGlobalData
->lcid
);
112 /* Get the time format */
113 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEFORMAT
),
114 CB_LIMITTEXT
, MAX_TIMEFORMAT
, 0);
116 /* Add available time formats to the list */
117 hwndEnum
= GetDlgItem(hwndDlg
, IDC_TIMEFORMAT
);
118 EnumTimeFormats(TimeFormatEnumProc
, pGlobalData
->lcid
, 0);
120 GetLocaleInfo(pGlobalData
->lcid
, LOCALE_STIMEFORMAT
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
121 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEFORMAT
),
126 /* Get the time separator */
127 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESEPARATOR
),
128 CB_LIMITTEXT
, MAX_TIMESEPARATOR
, 0);
129 GetLocaleInfo(pGlobalData
->lcid
, LOCALE_STIME
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
130 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESEPARATOR
),
134 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMESEPARATOR
),
139 /* Get the AM symbol */
140 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEAMSYMBOL
),
141 CB_LIMITTEXT
, MAX_TIMEAMSYMBOL
, 0);
142 nLen
= GetLocaleInfo(pGlobalData
->lcid
, LOCALE_S1159
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
143 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEAMSYMBOL
),
149 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEAMSYMBOL
),
154 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEAMSYMBOL
),
159 /* Get the PM symbol */
160 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEPMSYMBOL
),
161 CB_LIMITTEXT
, MAX_TIMEPMSYMBOL
, 0);
162 nLen
= GetLocaleInfo(pGlobalData
->lcid
, LOCALE_S2359
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
163 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEPMSYMBOL
),
169 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEPMSYMBOL
),
174 SendMessage(GetDlgItem(hwndDlg
, IDC_TIMEPMSYMBOL
),
182 switch (LOWORD(wParam
))
185 case IDC_TIMESEPARATOR
:
186 case IDC_TIMEAMSYMBOL
:
187 case IDC_TIMEPMSYMBOL
:
188 if (HIWORD(wParam
) == CBN_SELCHANGE
||
189 HIWORD(wParam
) == CBN_EDITCHANGE
)
191 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
199 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
201 if (lpnm
->code
== (UINT
)PSN_APPLY
)
205 /* get selected/typed time format text */
206 GetSelectedComboEntry(hwndDlg
, IDC_TIMEFORMAT
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
208 /* Set time format */
209 SetLocaleInfo(pGlobalData
->lcid
, LOCALE_STIMEFORMAT
, Buffer
);
211 /* get selected/typed time separator text */
212 GetSelectedComboEntry(hwndDlg
, IDC_TIMESEPARATOR
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
214 /* Set time separator */
215 SetLocaleInfo(pGlobalData
->lcid
, LOCALE_STIME
, Buffer
);
217 /* get selected/typed AM symbol text */
218 GetSelectedComboEntry(hwndDlg
, IDC_TIMEAMSYMBOL
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
220 /* Set the AM symbol */
221 SetLocaleInfo(pGlobalData
->lcid
, LOCALE_S1159
, Buffer
);
223 /* get selected/typed PM symbol text */
224 GetSelectedComboEntry(hwndDlg
, IDC_TIMEPMSYMBOL
, Buffer
, sizeof(Buffer
)/sizeof(TCHAR
));
226 /* Set the PM symbol */
227 SetLocaleInfo(pGlobalData
->lcid
, LOCALE_S2359
, Buffer
);
229 /* Update the time format sample */
230 UpdateTimeSample(GetDlgItem(hwndDlg
, IDC_TIMESAMPLE
), pGlobalData
->lcid
);