ReactOS  0.4.15-dev-1070-ge1a01de
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 #include <tzlib.h>
14 
15 typedef struct _TIMEZONE_ENTRY
16 {
19  WCHAR Description[128]; /* 'Display' */
20  WCHAR StandardName[33]; /* 'Std' */
21  WCHAR DaylightName[33]; /* 'Dlt' */
24 
25 
26 static HBITMAP hBitmap = NULL;
27 static int cxSource, cySource;
28 
31 
32 static
35  LONG Bias,
36  LPWSTR lpDescription)
37 {
39 
41  while (Entry != NULL)
42  {
43  if (Entry->TimezoneInfo.Bias < Bias)
44  return Entry;
45 
46  if (Entry->TimezoneInfo.Bias == Bias)
47  {
48  if (_wcsicmp(Entry->Description, lpDescription) > 0)
49  return Entry;
50  }
51 
52  Entry = Entry->Next;
53  }
54 
55  return NULL;
56 }
57 
58 static LONG
60  IN HKEY hZoneKey,
62 {
63  LONG lError;
65  PTIMEZONE_ENTRY Current;
66  ULONG DescriptionSize;
67  ULONG StandardNameSize;
68  ULONG DaylightNameSize;
69 
71  if (Entry == NULL)
72  {
74  }
75 
76  DescriptionSize = sizeof(Entry->Description);
77  StandardNameSize = sizeof(Entry->StandardName);
78  DaylightNameSize = sizeof(Entry->DaylightName);
79 
80  lError = QueryTimeZoneData(hZoneKey,
81  NULL,
82  &Entry->TimezoneInfo,
83  Entry->Description,
84  &DescriptionSize,
85  Entry->StandardName,
86  &StandardNameSize,
87  Entry->DaylightName,
88  &DaylightNameSize);
89  if (lError != ERROR_SUCCESS)
90  {
92  return lError;
93  }
94 
95  if (TimeZoneListHead == NULL &&
97  {
98  Entry->Prev = NULL;
99  Entry->Next = NULL;
102  }
103  else
104  {
105  Current = GetLargerTimeZoneEntry(Entry->TimezoneInfo.Bias, Entry->Description);
106  if (Current != NULL)
107  {
108  if (Current == TimeZoneListHead)
109  {
110  /* Prepend to head */
111  Entry->Prev = NULL;
112  Entry->Next = TimeZoneListHead;
115  }
116  else
117  {
118  /* Insert before current */
119  Entry->Prev = Current->Prev;
120  Entry->Next = Current;
121  Current->Prev->Next = Entry;
122  Current->Prev = Entry;
123  }
124  }
125  else
126  {
127  /* Append to tail */
128  Entry->Prev = TimeZoneListTail;
129  Entry->Next = NULL;
132  }
133  }
134 
135  return ERROR_SUCCESS;
136 }
137 
138 static VOID
140 {
142 }
143 
144 static VOID
146 {
148 
149  while (TimeZoneListHead != NULL)
150  {
152 
153  TimeZoneListHead = Entry->Next;
154  if (TimeZoneListHead != NULL)
155  {
157  }
158 
160  }
161 
163 }
164 
165 
166 static VOID
168 {
169  TIME_ZONE_INFORMATION TimeZoneInfo;
171  BOOL bDoAdvancedTest;
172  DWORD dwIndex;
173  DWORD i;
174 
175  GetTimeZoneInformation(&TimeZoneInfo);
176  bDoAdvancedTest = (!*TimeZoneInfo.StandardName);
177 
178  dwIndex = 0;
179  i = 0;
181  while (Entry != NULL)
182  {
184  CB_ADDSTRING,
185  0,
186  (LPARAM)Entry->Description);
187 
188  if ( (!bDoAdvancedTest && *Entry->StandardName &&
189  wcscmp(Entry->StandardName, TimeZoneInfo.StandardName) == 0) ||
190  ( (Entry->TimezoneInfo.Bias == TimeZoneInfo.Bias) &&
191  (Entry->TimezoneInfo.StandardBias == TimeZoneInfo.StandardBias) &&
192  (Entry->TimezoneInfo.DaylightBias == TimeZoneInfo.DaylightBias) &&
193  (memcmp(&Entry->TimezoneInfo.StandardDate, &TimeZoneInfo.StandardDate, sizeof(SYSTEMTIME)) == 0) &&
194  (memcmp(&Entry->TimezoneInfo.DaylightDate, &TimeZoneInfo.DaylightDate, sizeof(SYSTEMTIME)) == 0) ) )
195  {
196  dwIndex = i;
197  }
198 
199  i++;
200  Entry = Entry->Next;
201  }
202 
204  CB_SETCURSEL,
205  (WPARAM)dwIndex,
206  0);
207 }
208 
209 
210 static VOID
212 {
213  TIME_ZONE_INFORMATION TimeZoneInformation;
215  DWORD dwIndex;
216  DWORD i;
217 
218  dwIndex = (DWORD)SendMessageW(hwnd,
219  CB_GETCURSEL,
220  0,
221  0);
222 
223  i = 0;
225  while (i < dwIndex)
226  {
227  if (Entry == NULL)
228  return;
229 
230  i++;
231  Entry = Entry->Next;
232  }
233 
234  wcscpy(TimeZoneInformation.StandardName,
235  Entry->StandardName);
236  wcscpy(TimeZoneInformation.DaylightName,
237  Entry->DaylightName);
238 
239  TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias;
240  TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias;
241  TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias;
242 
243  memcpy(&TimeZoneInformation.StandardDate,
244  &Entry->TimezoneInfo.StandardDate,
245  sizeof(SYSTEMTIME));
246  memcpy(&TimeZoneInformation.DaylightDate,
247  &Entry->TimezoneInfo.DaylightDate,
248  sizeof(SYSTEMTIME));
249 
250  /* Set time zone information */
251  SetTimeZoneInformation(&TimeZoneInformation);
252 }
253 
254 
255 /* Property page dialog callback */
258  UINT uMsg,
259  WPARAM wParam,
260  LPARAM lParam)
261 {
262  BITMAP bitmap;
263 
264  switch (uMsg)
265  {
266  case WM_INITDIALOG:
267  {
270 
273 
275  if (hBitmap != NULL)
276  {
277  GetObjectW(hBitmap, sizeof(bitmap), &bitmap);
278 
279  cxSource = bitmap.bmWidth;
280  cySource = bitmap.bmHeight;
281  }
282  break;
283  }
284 
285  case WM_DRAWITEM:
286  {
287  LPDRAWITEMSTRUCT lpDrawItem;
288  lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
289  if(lpDrawItem->CtlID == IDC_WORLD_BACKGROUND)
290  {
291  HDC hdcMem;
292  hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
293  if (hdcMem != NULL)
294  {
296  StretchBlt(lpDrawItem->hDC, lpDrawItem->rcItem.left, lpDrawItem->rcItem.top,
297  lpDrawItem->rcItem.right - lpDrawItem->rcItem.left,
298  lpDrawItem->rcItem.bottom - lpDrawItem->rcItem.top,
299  hdcMem, 0, 0, cxSource, cySource, SRCCOPY);
300  DeleteDC(hdcMem);
301  }
302  }
303  }
304  break;
305 
306  case WM_COMMAND:
309  {
310  /* Enable the 'Apply' button */
311  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
312  }
313  break;
314 
315  case WM_DESTROY:
318  break;
319 
320  case WM_NOTIFY:
321  {
322  LPNMHDR lpnm = (LPNMHDR)lParam;
323 
324  switch (lpnm->code)
325  {
326  case PSN_APPLY:
327  {
329  BM_GETCHECK, 0, 0) != BST_UNCHECKED);
332  return TRUE;
333  }
334 
335  default:
336  break;
337  }
338  }
339  break;
340  }
341 
342  return FALSE;
343 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define IN
Definition: typedefs.h:39
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
REG_TZI_FORMAT TimezoneInfo
Definition: timezone.c:22
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _Entry Entry
Definition: kefuncs.h:627
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
PTIMEZONE_ENTRY TimeZoneListHead
Definition: timezone.c:29
#define TRUE
Definition: types.h:120
#define IDC_TIMEZONELIST
Definition: resource.h:16
Definition: timezone.c:15
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:35
LONG top
Definition: windef.h:307
static LONG RetrieveTimeZone(IN HKEY hZoneKey, IN PVOID Context)
Definition: timezone.c:59
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
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 SendDlgItemMessage
Definition: winuser.h:5817
#define PSN_APPLY
Definition: prsht.h:117
LONG left
Definition: windef.h:306
struct _TIMEZONE_ENTRY * PTIMEZONE_ENTRY
int32_t INT_PTR
Definition: typedefs.h:64
LONG right
Definition: windef.h:308
#define DWORD
Definition: nt_native.h:44
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1925
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
UINT code
Definition: winuser.h:3134
#define IDC_AUTODAYLIGHT
Definition: resource.h:17
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:167
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
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:34
VOID EnumerateTimeZoneList(IN PENUM_TIMEZONE_CALLBACK Callback, IN PVOID Context OPTIONAL)
Definition: tzlib.c:223
#define CB_ADDSTRING
Definition: winuser.h:1918
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
PTIMEZONE_ENTRY TimeZoneListTail
Definition: timezone.c:30
#define BM_GETCHECK
Definition: winuser.h:1900
WCHAR DaylightName[33]
Definition: timezone.c:21
#define WM_DESTROY
Definition: winuser.h:1591
VOID SetAutoDaylight(IN BOOL EnableAutoDaylightTime)
Definition: tzlib.c:323
static int cxSource
Definition: timezone.c:27
Definition: uimain.c:88
#define BM_SETCHECK
Definition: winuser.h:1903
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
INT_PTR CALLBACK TimeZonePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: timezone.c:257
#define BN_CLICKED
Definition: winuser.h:1907
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
#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)
struct _TIMEZONE_ENTRY * Prev
Definition: timezone.c:17
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:1174
#define CB_SETCURSEL
Definition: winuser.h:1943
#define WM_COMMAND
Definition: winuser.h:1722
#define BST_UNCHECKED
Definition: winuser.h:199
static VOID DestroyTimeZoneList(VOID)
Definition: timezone.c:145
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:139
static int cySource
Definition: timezone.c:27
struct _TIMEZONE_ENTRY * Next
Definition: timezone.c:18
WCHAR DaylightName[32]
Definition: winbase.h:1176
WCHAR StandardName[33]
Definition: timezone.c:20
BOOL WINAPI DeleteDC(_In_ HDC)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
Definition: bl.h:1331
WCHAR Description[128]
Definition: timezone.c:19
unsigned int UINT
Definition: ndis.h:50
#define IMAGE_BITMAP
Definition: winuser.h:211
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define CBN_SELCHANGE
Definition: winuser.h:1961
#define BST_CHECKED
Definition: winuser.h:197
static VOID SetLocalTimeZone(HWND hwnd)
Definition: timezone.c:211
#define WM_DRAWITEM
Definition: winuser.h:1627
BOOL GetAutoDaylight(VOID)
Definition: tzlib.c:283
#define HIWORD(l)
Definition: typedefs.h:247
unsigned int ULONG
Definition: retypes.h:1
LONG bottom
Definition: windef.h:309
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
#define WM_INITDIALOG
Definition: winuser.h:1721
static HBITMAP hBitmap
Definition: timezone.c:26
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:483
WCHAR StandardName[32]
Definition: winbase.h:1173
#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:1177
LONG QueryTimeZoneData(IN HKEY hZoneKey, OUT PULONG Index OPTIONAL, OUT PREG_TZI_FORMAT TimeZoneInfo, OUT PWCHAR Description OPTIONAL, IN OUT PULONG DescriptionSize OPTIONAL, OUT PWCHAR StandardName OPTIONAL, IN OUT PULONG StandardNameSize OPTIONAL, OUT PWCHAR DaylightName OPTIONAL, IN OUT PULONG DaylightNameSize OPTIONAL)
Definition: tzlib.c:141