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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: timedate.c,v 1.2 2004/11/07 16:03:51 ekohl Exp $
21 * PROJECT: ReactOS Timedate Control Panel
22 * FILE: lib/cpl/timedate/timedate.c
23 * PURPOSE: ReactOS Timedate Control Panel
24 * PROGRAMMER: Eric Kohl
35 typedef struct _TZ_INFO
40 SYSTEMTIME StandardDate
;
41 SYSTEMTIME DaylightDate
;
44 typedef struct _TIMEZONE_ENTRY
46 struct _TIMEZONE_ENTRY
*Prev
;
47 struct _TIMEZONE_ENTRY
*Next
;
48 WCHAR Description
[64]; /* 'Display' */
49 WCHAR StandardName
[32]; /* 'Std' */
50 WCHAR DaylightName
[32]; /* 'Dlt' */
51 TZ_INFO TimezoneInfo
; /* 'TZI' */
52 ULONG Index
; /* 'Index ' */
53 } TIMEZONE_ENTRY
, *PTIMEZONE_ENTRY
;
56 #define NUM_APPLETS (1)
59 Applet(HWND hwnd
, UINT uMsg
, LONG wParam
, LONG lParam
);
62 HINSTANCE hApplet
= 0;
64 PTIMEZONE_ENTRY TimeZoneListHead
= NULL
;
65 PTIMEZONE_ENTRY TimeZoneListTail
= NULL
;
69 APPLET Applets
[NUM_APPLETS
] =
71 {IDC_CPLICON
, IDS_CPLNAME
, IDS_CPLDESCRIPTION
, Applet
}
75 /* Property page dialog callback */
77 DateTimePageProc(HWND hwndDlg
,
86 TIME_ZONE_INFORMATION TimeZoneInfo
;
88 GetTimeZoneInformation(&TimeZoneInfo
);
90 SendDlgItemMessageW(hwndDlg
, IDC_TIMEZONE
, WM_SETTEXT
, 0, (LPARAM
)TimeZoneInfo
.StandardName
);
99 static PTIMEZONE_ENTRY
100 GetLargerTimeZoneEntry(DWORD Index
)
102 PTIMEZONE_ENTRY Entry
;
104 Entry
= TimeZoneListHead
;
105 while (Entry
!= NULL
)
107 if (Entry
->Index
>= Index
)
118 CreateTimeZoneList(VOID
)
120 WCHAR szKeyName
[256];
128 PTIMEZONE_ENTRY Entry
;
129 PTIMEZONE_ENTRY Current
;
131 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
132 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
142 lError
= RegEnumKeyExW(hZonesKey
,
150 if (lError
!= ERROR_SUCCESS
&& lError
!= ERROR_MORE_DATA
)
153 if (RegOpenKeyExW(hZonesKey
,
160 Entry
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TIMEZONE_ENTRY
));
163 RegCloseKey(hZoneKey
);
167 dwValueSize
= 64 * sizeof(WCHAR
);
168 if (RegQueryValueExW(hZoneKey
,
172 (LPBYTE
)&Entry
->Description
,
175 RegCloseKey(hZoneKey
);
179 dwValueSize
= 32 * sizeof(WCHAR
);
180 if (RegQueryValueExW(hZoneKey
,
184 (LPBYTE
)&Entry
->StandardName
,
187 RegCloseKey(hZoneKey
);
191 dwValueSize
= 32 * sizeof(WCHAR
);
192 if (RegQueryValueExW(hZoneKey
,
196 (LPBYTE
)&Entry
->DaylightName
,
199 RegCloseKey(hZoneKey
);
203 dwValueSize
= sizeof(DWORD
);
204 if (RegQueryValueExW(hZoneKey
,
208 (LPBYTE
)&Entry
->Index
,
211 RegCloseKey(hZoneKey
);
215 dwValueSize
= sizeof(TZ_INFO
);
216 if (RegQueryValueExW(hZoneKey
,
220 (LPBYTE
)&Entry
->TimezoneInfo
,
223 RegCloseKey(hZoneKey
);
227 RegCloseKey(hZoneKey
);
229 if (TimeZoneListHead
== NULL
&&
230 TimeZoneListTail
== NULL
)
234 TimeZoneListHead
= Entry
;
235 TimeZoneListTail
= Entry
;
239 Current
= GetLargerTimeZoneEntry(Entry
->Index
);
242 if (Current
== TimeZoneListHead
)
244 /* Prepend to head */
246 Entry
->Next
= TimeZoneListHead
;
247 TimeZoneListHead
->Prev
= Entry
;
248 TimeZoneListHead
= Entry
;
252 /* Insert before current */
253 Entry
->Prev
= Current
->Prev
;
254 Entry
->Next
= Current
;
255 Current
->Prev
->Next
= Entry
;
256 Current
->Prev
= Entry
;
262 Entry
->Prev
= TimeZoneListTail
;
264 TimeZoneListTail
->Next
= Entry
;
265 TimeZoneListTail
= Entry
;
272 RegCloseKey(hZonesKey
);
277 DestroyTimeZoneList(VOID
)
279 PTIMEZONE_ENTRY Entry
;
281 while (TimeZoneListHead
!= NULL
)
283 Entry
= TimeZoneListHead
;
285 TimeZoneListHead
= Entry
->Next
;
286 if (TimeZoneListHead
!= NULL
)
288 TimeZoneListHead
->Prev
= NULL
;
291 HeapFree(GetProcessHeap(), 0, Entry
);
294 TimeZoneListTail
= NULL
;
299 ShowTimeZoneList(HWND hwnd
)
301 PTIMEZONE_ENTRY Entry
;
303 Entry
= TimeZoneListHead
;
304 while (Entry
!= NULL
)
309 (LPARAM
)Entry
->Description
);
322 /* Property page dialog callback */
324 TimeZonePageProc(HWND hwndDlg
,
332 CreateTimeZoneList();
333 ShowTimeZoneList(GetDlgItem(hwndDlg
, IDC_TIMEZONELIST
));
337 if ((LOWORD(wParam
) == IDC_TIMEZONELIST
&& HIWORD(wParam
) == CBN_SELCHANGE
) ||
338 (LOWORD(wParam
) == IDC_AUTOADJUST
&& HIWORD(wParam
) == BN_CLICKED
))
340 /* Enable the 'Apply' button */
341 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
346 DestroyTimeZoneList();
355 InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
)
357 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
358 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
359 psp
->dwFlags
= PSP_DEFAULT
;
360 psp
->hInstance
= hApplet
;
361 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
362 psp
->pfnDlgProc
= DlgProc
;
367 Applet(HWND hwnd
, UINT uMsg
, LONG wParam
, LONG lParam
)
370 PROPSHEETPAGE psp
[3];
373 LoadString(hApplet
, IDS_CPLNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
375 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
376 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
377 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
;
378 psh
.hwndParent
= NULL
;
379 psh
.hInstance
= hApplet
;
380 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDC_CPLICON
));
381 psh
.pszCaption
= Caption
;
382 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
386 InitPropSheetPage(&psp
[0], IDD_DATETIMEPAGE
, DateTimePageProc
);
387 InitPropSheetPage(&psp
[1], IDD_TIMEZONEPAGE
, TimeZonePageProc
);
389 return (LONG
)(PropertySheet(&psh
) != -1);
393 /* Control Panel Callback */
395 CPlApplet(HWND hwndCpl
,
400 int i
= (int)lParam1
;
412 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
414 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
415 CPlInfo
->idName
= Applets
[i
].idName
;
416 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
422 Applets
[i
].AppletProc(hwndCpl
, uMsg
, lParam1
, lParam2
);
431 DllMain(HINSTANCE hinstDLL
,
437 case DLL_PROCESS_ATTACH
:
439 INITCOMMONCONTROLSEX InitControls
;
441 InitControls
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
442 InitControls
.dwICC
= ICC_DATE_CLASSES
| ICC_PROGRESS_CLASS
| ICC_UPDOWN_CLASS
;
443 InitCommonControlsEx(&InitControls
);