ReactOS  0.4.15-dev-1397-g19779b3
time.c
Go to the documentation of this file.
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 
30 
31 static BOOL CALLBACK
32 TimeFormatEnumProc(PWSTR lpTimeFormatString)
33 {
36  0,
37  (LPARAM)lpTimeFormatString);
38 
39  return TRUE;
40 }
41 
42 static VOID
44 {
45  WCHAR szBuffer[MAX_SAMPLES_STR_SIZE];
46 
47  GetTimeFormatW(pGlobalData->UserLCID, 0, NULL,
48  pGlobalData->szTimeFormat, szBuffer,
51 }
52 
53 
54 static
55 VOID
57  HWND hwndDlg,
58  PGLOBALDATA pGlobalData)
59 {
60  /* Get the time format */
63 
64  /* Add available time formats to the list */
67 
70  -1,
71  (LPARAM)pGlobalData->szTimeFormat);
72 }
73 
74 static
75 VOID
77  HWND hwndDlg,
78  PGLOBALDATA pGlobalData)
79 {
82 
85  0,
86  (LPARAM)pGlobalData->szTimeSep);
87 
90  0, /* Index */
91  0);
92 }
93 
94 
95 static
96 VOID
98  HWND hwndDlg,
99  PGLOBALDATA pGlobalData)
100 {
101  int nLen;
102 
105 
106  nLen = wcslen(pGlobalData->szTimeAM);
107 
109  CB_ADDSTRING,
110  0,
111  (LPARAM)pGlobalData->szTimeAM);
112  if (nLen != 0)
113  {
115  CB_ADDSTRING,
116  0,
117  (LPARAM)L"");
118  }
119 
121  CB_SETCURSEL,
122  0, /* Index */
123  0);
124 }
125 
126 
127 static
128 VOID
130  HWND hwndDlg,
131  PGLOBALDATA pGlobalData)
132 {
133  int nLen;
134 
137 
138  nLen = wcslen(pGlobalData->szTimeAM);
139 
141  CB_ADDSTRING,
142  0,
143  (LPARAM)pGlobalData->szTimePM);
144  if (nLen != 0)
145  {
147  CB_ADDSTRING,
148  0,
149  (LPARAM)L"");
150  }
152  CB_SETCURSEL,
153  0, /* Index */
154  0);
155 }
156 
157 
158 static
159 BOOL
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,
172  szTimeFormat,
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,
186  szTimeSep,
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,
200  szTimeAM,
202 
203  /* PM symbol */
204  GetSelectedComboBoxText(hwndDlg,
206  szTimePM,
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 */
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 ||
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 */
struct _GLOBALDATA * PGLOBALDATA
VOID GetSelectedComboBoxText(HWND hwndDlg, INT nIdDlgItem, PWSTR Buffer, UINT uSize)
Definition: misc.c:176
BOOL WINAPI EnumTimeFormatsW(TIMEFMT_ENUMPROCW proc, LCID lcid, DWORD flags)
Definition: lcformat.c:2143
static BOOL GetTimeSetting(HWND hwndDlg, PGLOBALDATA pGlobalData)
Definition: time.c:160
#define TRUE
Definition: types.h:120
#define IDC_TIMEAMSYMBOL
Definition: resource.h:48
uint16_t * PWSTR
Definition: typedefs.h:56
#define CALLBACK
Definition: compat.h:35
HWND hWnd
Definition: settings.c:17
static HWND hwndTimeEnum
Definition: time.c:29
WCHAR szTimeFormat[MAX_TIMEFORMAT]
Definition: intl.h:90
#define IDC_TIMEFORMAT
Definition: resource.h:46
UINT_PTR WPARAM
Definition: windef.h:207
static VOID InitPmSymbol(HWND hwndDlg, PGLOBALDATA pGlobalData)
Definition: time.c:129
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:64
WCHAR szTimeAM[MAX_TIMEAMSYMBOL]
Definition: intl.h:92
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
WCHAR szTimeSep[MAX_TIMESEPARATOR]
Definition: intl.h:91
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDC_TIMEPMSYMBOL
Definition: resource.h:49
#define CB_ADDSTRING
Definition: winuser.h:1918
static BOOL CALLBACK TimeFormatEnumProc(PWSTR lpTimeFormatString)
Definition: time.c:32
#define MAX_TIMESEPARATOR
Definition: intl.h:39
#define LPPROPSHEETPAGE
Definition: prsht.h:390
static VOID InitAmSymbol(HWND hwndDlg, PGLOBALDATA pGlobalData)
Definition: time.c:97
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_LIMITTEXT
Definition: winuser.h:1940
#define MAX_TIMEFORMAT
Definition: intl.h:38
#define WM_SETTEXT
Definition: winuser.h:1599
#define MAX_SAMPLES_STR_SIZE
Definition: intl.h:24
#define CBN_EDITCHANGE
Definition: winuser.h:1957
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_TIMESAMPLE
Definition: resource.h:45
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define DWLP_USER
Definition: winuser.h:866
#define CB_SELECTSTRING
Definition: winuser.h:1942
#define CB_SETCURSEL
Definition: winuser.h:1943
#define WM_COMMAND
Definition: winuser.h:1722
Definition: inflate.c:139
#define MAX_TIMEPMSYMBOL
Definition: intl.h:41
HWND WINAPI GetParent(_In_ HWND)
static VOID UpdateTimeSample(HWND hWnd, PGLOBALDATA pGlobalData)
Definition: time.c:43
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_TIMESEPARATOR
Definition: resource.h:47
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define CBN_SELCHANGE
Definition: winuser.h:1961
static VOID InitTimeSeparatorCB(HWND hwndDlg, PGLOBALDATA pGlobalData)
Definition: time.c:76
#define HIWORD(l)
Definition: typedefs.h:247
#define MAX_TIMEAMSYMBOL
Definition: intl.h:40
INT_PTR CALLBACK TimePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: time.c:220
#define GetWindowLongPtr
Definition: treelist.c:73
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1079
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
static VOID InitTimeFormatCB(HWND hwndDlg, PGLOBALDATA pGlobalData)
Definition: time.c:56
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define WM_NOTIFY
Definition: richedit.h:61
WCHAR szTimePM[MAX_TIMEPMSYMBOL]
Definition: intl.h:93
LCID UserLCID
Definition: intl.h:113