ReactOS  0.4.13-dev-482-ge57f103
timezone.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Timedate Control Panel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: dll/cpl/timedate/timezone.c
5  * PURPOSE: Time Zone property page
6  * COPYRIGHT: Copyright 2004-2005 Eric Kohl
7  * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
8  * Copyright 2006 Christoph v. Wittich <Christoph@ActiveVB.de>
9  *
10  */
11 
12 #include "timedate.h"
13 
14 // See also sdk/include/reactos/libs/syssetup/syssetup.h
15 typedef struct _TZ_INFO
16 {
22 } TZ_INFO, *PTZ_INFO;
23 
24 typedef struct _TIMEZONE_ENTRY
25 {
28  WCHAR Description[128]; /* 'Display' */
29  WCHAR StandardName[33]; /* 'Std' */
30  WCHAR DaylightName[33]; /* 'Dlt' */
31  TZ_INFO TimezoneInfo; /* 'TZI' */
33 
34 
35 static HBITMAP hBitmap = NULL;
36 static int cxSource, cySource;
37 
40 
41 static
44  LONG Bias,
45  LPWSTR lpDescription)
46 {
48 
50  while (Entry != NULL)
51  {
52  if (Entry->TimezoneInfo.Bias < Bias)
53  return Entry;
54 
55  if (Entry->TimezoneInfo.Bias == Bias)
56  {
57  if (_wcsicmp(Entry->Description, lpDescription) > 0)
58  return Entry;
59  }
60 
61  Entry = Entry->Next;
62  }
63 
64  return NULL;
65 }
66 
67 
68 static
69 LONG
71  HKEY hZoneKey,
73 {
74  DWORD dwValueSize;
75  LONG lError;
76 
77  dwValueSize = sizeof(Entry->Description);
78  lError = RegQueryValueExW(hZoneKey,
79  L"Display",
80  NULL,
81  NULL,
82  (LPBYTE)&Entry->Description,
83  &dwValueSize);
84  if (lError != ERROR_SUCCESS)
85  return lError;
86 
87  dwValueSize = sizeof(Entry->StandardName);
88  lError = RegQueryValueExW(hZoneKey,
89  L"Std",
90  NULL,
91  NULL,
92  (LPBYTE)&Entry->StandardName,
93  &dwValueSize);
94  if (lError != ERROR_SUCCESS)
95  return lError;
96 
97  dwValueSize = sizeof(Entry->DaylightName);
98  lError = RegQueryValueExW(hZoneKey,
99  L"Dlt",
100  NULL,
101  NULL,
102  (LPBYTE)&Entry->DaylightName,
103  &dwValueSize);
104  if (lError != ERROR_SUCCESS)
105  return lError;
106 
107  dwValueSize = sizeof(Entry->TimezoneInfo);
108  lError = RegQueryValueExW(hZoneKey,
109  L"TZI",
110  NULL,
111  NULL,
112  (LPBYTE)&Entry->TimezoneInfo,
113  &dwValueSize);
114  return lError;
115 }
116 
117 
118 static VOID
120 {
121  WCHAR szKeyName[256];
122  DWORD dwIndex;
123  DWORD dwNameSize;
124  LONG lError;
125  HKEY hZonesKey;
126  HKEY hZoneKey;
128  PTIMEZONE_ENTRY Current;
129 
131  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
132  0,
134  &hZonesKey))
135  return;
136 
137  for (dwIndex = 0; ; dwIndex++)
138  {
139  dwNameSize = sizeof(szKeyName);
140  lError = RegEnumKeyExW(hZonesKey,
141  dwIndex,
142  szKeyName,
143  &dwNameSize,
144  NULL,
145  NULL,
146  NULL,
147  NULL);
148  if (lError == ERROR_NO_MORE_ITEMS)
149  break;
150 
151  if (RegOpenKeyEx (hZonesKey,
152  szKeyName,
153  0,
155  &hZoneKey))
156  break;
157 
159  if (Entry == NULL)
160  {
161  RegCloseKey(hZoneKey);
162  break;
163  }
164 
165  lError = QueryTimezoneData(hZoneKey,
166  Entry);
167 
168  RegCloseKey(hZoneKey);
169 
170  if (lError != ERROR_SUCCESS)
171  {
173  break;
174  }
175 
176  if (TimeZoneListHead == NULL &&
178  {
179  Entry->Prev = NULL;
180  Entry->Next = NULL;
183  }
184  else
185  {
186  Current = GetLargerTimeZoneEntry(Entry->TimezoneInfo.Bias, Entry->Description);
187  if (Current != NULL)
188  {
189  if (Current == TimeZoneListHead)
190  {
191  /* Prepend to head */
192  Entry->Prev = NULL;
193  Entry->Next = TimeZoneListHead;
196  }
197  else
198  {
199  /* Insert before current */
200  Entry->Prev = Current->Prev;
201  Entry->Next = Current;
202  Current->Prev->Next = Entry;
203  Current->Prev = Entry;
204  }
205  }
206  else
207  {
208  /* Append to tail */
209  Entry->Prev = TimeZoneListTail;
210  Entry->Next = NULL;
213  }
214  }
215  }
216 
217  RegCloseKey(hZonesKey);
218 }
219 
220 
221 static VOID
223 {
225 
226  while (TimeZoneListHead != NULL)
227  {
229 
230  TimeZoneListHead = Entry->Next;
231  if (TimeZoneListHead != NULL)
232  {
234  }
235 
237  }
238 
240 }
241 
242 
243 static VOID
245 {
246  TIME_ZONE_INFORMATION TimeZoneInfo;
248  DWORD dwIndex;
249  DWORD i;
250 
251  GetTimeZoneInformation(&TimeZoneInfo);
252 
253  dwIndex = 0;
254  i = 0;
256  while (Entry != NULL)
257  {
259  CB_ADDSTRING,
260  0,
261  (LPARAM)Entry->Description);
262 
263  if (!wcscmp(Entry->StandardName, TimeZoneInfo.StandardName))
264  dwIndex = i;
265 
266  i++;
267  Entry = Entry->Next;
268  }
269 
271  CB_SETCURSEL,
272  (WPARAM)dwIndex,
273  0);
274 }
275 
276 
277 static VOID
279 {
280  TIME_ZONE_INFORMATION TimeZoneInformation;
282  DWORD dwIndex;
283  DWORD i;
284 
285  dwIndex = (DWORD)SendMessageW(hwnd,
286  CB_GETCURSEL,
287  0,
288  0);
289 
290  i = 0;
292  while (i < dwIndex)
293  {
294  if (Entry == NULL)
295  return;
296 
297  i++;
298  Entry = Entry->Next;
299  }
300 
301  wcscpy(TimeZoneInformation.StandardName,
302  Entry->StandardName);
303  wcscpy(TimeZoneInformation.DaylightName,
304  Entry->DaylightName);
305 
306  TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias;
307  TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias;
308  TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias;
309 
310  memcpy(&TimeZoneInformation.StandardDate,
311  &Entry->TimezoneInfo.StandardDate,
312  sizeof(SYSTEMTIME));
313  memcpy(&TimeZoneInformation.DaylightDate,
314  &Entry->TimezoneInfo.DaylightDate,
315  sizeof(SYSTEMTIME));
316 
317  /* Set time zone information */
318  SetTimeZoneInformation(&TimeZoneInformation);
319 }
320 
321 
322 static VOID
324 {
325  HKEY hKey;
326 
328  L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
329  0,
331  &hKey))
332  return;
333 
334  /* If the call fails (non zero), the reg value isn't available,
335  * which means it shouldn't be disabled, so we should check the button.
336  */
337  if (RegQueryValueExW(hKey,
338  L"DisableAutoDaylightTimeSet",
339  NULL,
340  NULL,
341  NULL,
342  NULL))
343  {
345  }
346  else
347  {
349  }
350 
351  RegCloseKey(hKey);
352 }
353 
354 
355 static VOID
357 {
358  HKEY hKey;
359  DWORD dwValue = 1;
360 
362  L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
363  0,
365  &hKey))
366  return;
367 
369  {
370  RegSetValueExW(hKey,
371  L"DisableAutoDaylightTimeSet",
372  0,
373  REG_DWORD,
374  (LPBYTE)&dwValue,
375  sizeof(dwValue));
376  }
377  else
378  {
379  RegDeleteValueW(hKey,
380  L"DisableAutoDaylightTimeSet");
381  }
382 
383  RegCloseKey(hKey);
384 }
385 
386 
387 /* Property page dialog callback */
390  UINT uMsg,
391  WPARAM wParam,
392  LPARAM lParam)
393 {
394  BITMAP bitmap;
395 
396  switch (uMsg)
397  {
398  case WM_INITDIALOG:
403  if (hBitmap != NULL)
404  {
405  GetObjectW(hBitmap, sizeof(bitmap), &bitmap);
406 
407  cxSource = bitmap.bmWidth;
408  cySource = bitmap.bmHeight;
409  }
410  break;
411 
412  case WM_DRAWITEM:
413  {
414  LPDRAWITEMSTRUCT lpDrawItem;
415  lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
416  if(lpDrawItem->CtlID == IDC_WORLD_BACKGROUND)
417  {
418  HDC hdcMem;
419  hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
420  if (hdcMem != NULL)
421  {
423  StretchBlt(lpDrawItem->hDC, lpDrawItem->rcItem.left, lpDrawItem->rcItem.top,
424  lpDrawItem->rcItem.right - lpDrawItem->rcItem.left,
425  lpDrawItem->rcItem.bottom - lpDrawItem->rcItem.top,
426  hdcMem, 0, 0, cxSource, cySource, SRCCOPY);
427  DeleteDC(hdcMem);
428  }
429  }
430  }
431  break;
432 
433  case WM_COMMAND:
436  {
437  /* Enable the 'Apply' button */
438  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
439  }
440  break;
441 
442  case WM_DESTROY:
445  break;
446 
447  case WM_NOTIFY:
448  {
449  LPNMHDR lpnm = (LPNMHDR)lParam;
450 
451  switch (lpnm->code)
452  {
453  case PSN_APPLY:
454  {
458  return TRUE;
459  }
460 
461  default:
462  break;
463  }
464  }
465  break;
466  }
467 
468  return FALSE;
469 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _Entry Entry
Definition: kefuncs.h:640
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
PTIMEZONE_ENTRY TimeZoneListHead
Definition: timezone.c:38
#define IDC_TIMEZONELIST
Definition: resource.h:16
Definition: timezone.c:24
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
LONG top
Definition: windef.h:292
SYSTEMTIME DaylightDate
Definition: timezone.c:21
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HINSTANCE hApplet
Definition: access.c:17
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WPARAM
Definition: windef.h:207
#define PSN_APPLY
Definition: prsht.h:117
LONG left
Definition: windef.h:291
struct _TIMEZONE_ENTRY * PTIMEZONE_ENTRY
int32_t INT_PTR
Definition: typedefs.h:62
LONG right
Definition: windef.h:293
#define DWORD
Definition: nt_native.h:44
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1904
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
WPARAM wParam
Definition: combotst.c:138
#define DWLP_MSGRESULT
Definition: winuser.h:864
struct tagNMHDR * LPNMHDR
static VOID SetAutoDaylightInfo(HWND hwnd)
Definition: timezone.c:356
UINT code
Definition: winuser.h:3112
#define IDC_AUTODAYLIGHT
Definition: resource.h:17
TZ_INFO TimezoneInfo
Definition: timezone.c:31
SYSTEMTIME StandardDate
Definition: timezone.c:20
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static VOID ShowTimeZoneList(HWND hwnd)
Definition: timezone.c:244
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
long LONG
Definition: pedump.c:60
struct _TIMEZONE_ENTRY TIMEZONE_ENTRY
static PTIMEZONE_ENTRY GetLargerTimeZoneEntry(LONG Bias, LPWSTR lpDescription)
Definition: timezone.c:43
#define CB_ADDSTRING
Definition: winuser.h:1897
smooth NULL
Definition: ftsmooth.c:416
static LONG QueryTimezoneData(HKEY hZoneKey, PTIMEZONE_ENTRY Entry)
Definition: timezone.c:70
LONG_PTR LPARAM
Definition: windef.h:208
PTIMEZONE_ENTRY TimeZoneListTail
Definition: timezone.c:39
#define BM_GETCHECK
Definition: winuser.h:1879
WCHAR DaylightName[33]
Definition: timezone.c:30
#define WM_DESTROY
Definition: winuser.h:1591
static int cxSource
Definition: timezone.c:36
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
Definition: uimain.c:88
#define BM_SETCHECK
Definition: winuser.h:1882
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
INT_PTR CALLBACK TimeZonePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: timezone.c:389
#define BN_CLICKED
Definition: winuser.h:1886
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
#define IDC_WORLD_BACKGROUND
Definition: resource.h:18
LONG StandardBias
Definition: timezone.c:18
#define IDC_WORLD
Definition: resource.h:19
#define PSNRET_NOERROR
Definition: prsht.h:129
_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
struct _TIMEZONE_ENTRY * Prev
Definition: timezone.c:26
BOOL WINAPI SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
Definition: timezone.c:316
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
SYSTEMTIME StandardDate
Definition: winbase.h:1161
#define CB_SETCURSEL
Definition: winuser.h:1922
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
static VOID DestroyTimeZoneList(VOID)
Definition: timezone.c:222
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HWND WINAPI GetParent(_In_ HWND)
static VOID CreateTimeZoneList(VOID)
Definition: timezone.c:119
static int cySource
Definition: timezone.c:36
#define RegOpenKeyEx
Definition: winreg.h:520
struct _TIMEZONE_ENTRY * Next
Definition: timezone.c:27
WCHAR DaylightName[32]
Definition: winbase.h:1163
WCHAR StandardName[33]
Definition: timezone.c:29
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2355
BOOL WINAPI DeleteDC(_In_ HDC)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
Definition: bl.h:1331
WCHAR Description[128]
Definition: timezone.c:28
unsigned int UINT
Definition: ndis.h:50
#define IMAGE_BITMAP
Definition: winuser.h:211
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define CBN_SELCHANGE
Definition: winuser.h:1940
#define BST_CHECKED
Definition: winuser.h:197
static VOID SetLocalTimeZone(HWND hwnd)
Definition: timezone.c:278
#define WM_DRAWITEM
Definition: winuser.h:1627
static VOID GetAutoDaylightInfo(HWND hwnd)
Definition: timezone.c:323
#define HIWORD(l)
Definition: typedefs.h:246
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG Bias
Definition: timezone.c:17
LONG bottom
Definition: windef.h:294
static HBITMAP bitmap
Definition: clipboard.c:1344
struct _TZ_INFO TZ_INFO
static HBITMAP
Definition: button.c:44
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _TZ_INFO * PTZ_INFO
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
#define REG_DWORD
Definition: sdbapi.c:596
#define WM_INITDIALOG
Definition: winuser.h:1715
static HBITMAP hBitmap
Definition: timezone.c:35
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
WCHAR StandardName[32]
Definition: winbase.h:1160
#define SRCCOPY
Definition: wingdi.h:332
base of all file and directory entries
Definition: entries.h:82
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HDC hdcMem
Definition: welcome.c:104
#define WM_NOTIFY
Definition: richedit.h:61
SYSTEMTIME DaylightDate
Definition: winbase.h:1164
LONG DaylightBias
Definition: timezone.c:19
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019