From ca9e2e3b6d8a378c244eba40a85937a12306247d Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 11 Nov 2004 12:24:56 +0000 Subject: [PATCH] Enable automatic adjustment of daylight savings changes. svn path=/trunk/; revision=11616 --- reactos/lib/cpl/timedate/De.rc | 2 +- reactos/lib/cpl/timedate/En.rc | 2 +- reactos/lib/cpl/timedate/resource.h | 2 +- reactos/lib/cpl/timedate/timedate.c | 142 +++++++++++++++++++++++++++- reactos/lib/syssetup/resource.h | 2 +- reactos/lib/syssetup/syssetup_Cz.rc | 2 +- reactos/lib/syssetup/syssetup_De.rc | 2 +- reactos/lib/syssetup/syssetup_En.rc | 2 +- reactos/lib/syssetup/syssetup_Fr.rc | 2 +- reactos/lib/syssetup/wizard.c | 57 +++++++++-- 10 files changed, 199 insertions(+), 16 deletions(-) diff --git a/reactos/lib/cpl/timedate/De.rc b/reactos/lib/cpl/timedate/De.rc index 92fe37c9c26..715f3b68227 100644 --- a/reactos/lib/cpl/timedate/De.rc +++ b/reactos/lib/cpl/timedate/De.rc @@ -29,7 +29,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 5, 4, 241, 136, CBS_DROPDOWNLIST | WS_VSCROLL | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "&Uhr automatisch auf Sommer-/Winterzeit umstellen", - IDC_AUTOADJUST, 5, 136, 241, 10, WS_VISIBLE | WS_GROUP | WS_TABSTOP + IDC_AUTODAYLIGHT, 5, 136, 241, 10, WS_VISIBLE | WS_GROUP | WS_TABSTOP END diff --git a/reactos/lib/cpl/timedate/En.rc b/reactos/lib/cpl/timedate/En.rc index 8ae7000827d..01a2e4dac67 100644 --- a/reactos/lib/cpl/timedate/En.rc +++ b/reactos/lib/cpl/timedate/En.rc @@ -28,7 +28,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 5, 4, 241, 136, CBS_DROPDOWNLIST | WS_VSCROLL | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "Automatically adjust clock for &daylight saving changes", - IDC_AUTOADJUST, 5, 136, 241, 10, WS_VISIBLE | WS_GROUP | WS_TABSTOP + IDC_AUTODAYLIGHT, 5, 136, 241, 10, WS_VISIBLE | WS_GROUP | WS_TABSTOP END diff --git a/reactos/lib/cpl/timedate/resource.h b/reactos/lib/cpl/timedate/resource.h index e6c5c63f733..6a399911816 100644 --- a/reactos/lib/cpl/timedate/resource.h +++ b/reactos/lib/cpl/timedate/resource.h @@ -12,7 +12,7 @@ #define IDD_TIMEZONEPAGE 110 #define IDC_TIMEZONELIST 111 -#define IDC_AUTOADJUST 113 +#define IDC_AUTODAYLIGHT 113 #define IDS_CPLNAME 1001 #define IDS_CPLDESCRIPTION 2001 diff --git a/reactos/lib/cpl/timedate/timedate.c b/reactos/lib/cpl/timedate/timedate.c index 74fa262ad7c..eed20cf578a 100644 --- a/reactos/lib/cpl/timedate/timedate.c +++ b/reactos/lib/cpl/timedate/timedate.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: timedate.c,v 1.3 2004/11/08 10:33:08 ekohl Exp $ +/* $Id: timedate.c,v 1.4 2004/11/11 12:24:56 ekohl Exp $ * * PROJECT: ReactOS Timedate Control Panel * FILE: lib/cpl/timedate/timedate.c @@ -103,6 +103,17 @@ DateTimePageProc(HWND hwndDlg, PropSheet_Changed(GetParent(hwndDlg), hwndDlg); break; + case PSN_SETACTIVE: + /* FIXME: Update the time zone name */ + return 0; + + case PSN_APPLY: + + /* FIXME: Set date and time */ + + SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); + return TRUE; + default: break; } @@ -348,6 +359,113 @@ ShowTimeZoneList(HWND hwnd) } +static VOID +SetLocalTimeZone(HWND hwnd) +{ + TIME_ZONE_INFORMATION TimeZoneInformation; + PTIMEZONE_ENTRY Entry; + DWORD dwIndex; + DWORD i; + + dwIndex = SendMessage(hwnd, + CB_GETCURSEL, + 0, + 0); + + i = 0; + Entry = TimeZoneListHead; + while (i < dwIndex) + { + if (Entry == NULL) + return; + + i++; + Entry = Entry->Next; + } + + wcscpy(TimeZoneInformation.StandardName, + Entry->StandardName); + wcscpy(TimeZoneInformation.DaylightName, + Entry->DaylightName); + + TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias; + TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias; + TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias; + + memcpy(&TimeZoneInformation.StandardDate, + &Entry->TimezoneInfo.StandardDate, + sizeof(SYSTEMTIME)); + memcpy(&TimeZoneInformation.DaylightDate, + &Entry->TimezoneInfo.DaylightDate, + sizeof(SYSTEMTIME)); + + /* Set time zone information */ + SetTimeZoneInformation(&TimeZoneInformation); +} + + +static VOID +GetAutoDaylightInfo(HWND hwnd) +{ + HKEY hKey; + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", + 0, + KEY_SET_VALUE, + &hKey)) + return; + + if (RegQueryValueExW(hKey, + L"DisableAutoDaylightTimeSet", + NULL, + NULL, + NULL, + NULL)) + { + SendMessage(hwnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); + } + else + { + SendMessage(hwnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0); + } + + RegCloseKey(hKey); +} + + +static VOID +SetAutoDaylightInfo(HWND hwnd) +{ + HKEY hKey; + DWORD dwValue = 1; + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", + 0, + KEY_SET_VALUE, + &hKey)) + return; + + if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED) + { + RegSetValueExW(hKey, + L"DisableAutoDaylightTimeSet", + 0, + REG_DWORD, + (LPBYTE)&dwValue, + sizeof(DWORD)); + } + else + { + RegDeleteKeyW(hKey, + L"DisableAutoDaylightTimeSet"); + } + + RegCloseKey(hKey); +} + + /* Property page dialog callback */ INT_PTR CALLBACK TimeZonePageProc(HWND hwndDlg, @@ -360,11 +478,12 @@ TimeZonePageProc(HWND hwndDlg, case WM_INITDIALOG: CreateTimeZoneList(); ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST)); + GetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT)); break; case WM_COMMAND: if ((LOWORD(wParam) == IDC_TIMEZONELIST && HIWORD(wParam) == CBN_SELCHANGE) || - (LOWORD(wParam) == IDC_AUTOADJUST && HIWORD(wParam) == BN_CLICKED)) + (LOWORD(wParam) == IDC_AUTODAYLIGHT && HIWORD(wParam) == BN_CLICKED)) { /* Enable the 'Apply' button */ PropSheet_Changed(GetParent(hwndDlg), hwndDlg); @@ -374,6 +493,25 @@ TimeZonePageProc(HWND hwndDlg, case WM_DESTROY: DestroyTimeZoneList(); break; + + case WM_NOTIFY: + { + LPNMHDR lpnm = (LPNMHDR)lParam; + + switch (lpnm->code) + { + case PSN_APPLY: + SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT)); + SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST)); + SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); + return TRUE; + + default: + break; + } + + } + break; } return FALSE; diff --git a/reactos/lib/syssetup/resource.h b/reactos/lib/syssetup/resource.h index 4a61b953aaf..8931c36d8f3 100644 --- a/reactos/lib/syssetup/resource.h +++ b/reactos/lib/syssetup/resource.h @@ -46,7 +46,7 @@ #define IDC_DATEPICKER 1015 #define IDC_TIMEPICKER 1016 #define IDC_TIMEZONELIST 1017 -#define IDC_DAYLIGHTSAVINGS 1018 +#define IDC_AUTODAYLIGHT 1018 #define IDD_PROCESSPAGE 1020 #define IDC_PROCESSPROGRESS 1021 diff --git a/reactos/lib/syssetup/syssetup_Cz.rc b/reactos/lib/syssetup/syssetup_Cz.rc index 777ff0c28a4..686ed2a5633 100644 --- a/reactos/lib/syssetup/syssetup_Cz.rc +++ b/reactos/lib/syssetup/syssetup_Cz.rc @@ -102,7 +102,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 53, 96, 201, 42, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "Automatically adjust clock for &daylight saving changes", - IDC_DAYLIGHTSAVINGS, 53, 124, 201, 10 + IDC_AUTODAYLIGHT, 53, 124, 201, 10 END diff --git a/reactos/lib/syssetup/syssetup_De.rc b/reactos/lib/syssetup/syssetup_De.rc index 826df9a3474..bddfdea8443 100644 --- a/reactos/lib/syssetup/syssetup_De.rc +++ b/reactos/lib/syssetup/syssetup_De.rc @@ -104,7 +104,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 53, 96, 201, 42, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "&Uhr automatisch auf Sommer-/Winterzeit umstellen", - IDC_DAYLIGHTSAVINGS, 53, 124, 201, 10 + IDC_AUTODAYLIGHT, 53, 124, 201, 10 END diff --git a/reactos/lib/syssetup/syssetup_En.rc b/reactos/lib/syssetup/syssetup_En.rc index ef3074b2d9d..eb5f4bbb62b 100644 --- a/reactos/lib/syssetup/syssetup_En.rc +++ b/reactos/lib/syssetup/syssetup_En.rc @@ -104,7 +104,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 53, 96, 201, 42, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "Automatically adjust clock for &daylight saving changes", - IDC_DAYLIGHTSAVINGS, 53, 124, 201, 10 + IDC_AUTODAYLIGHT, 53, 124, 201, 10 END diff --git a/reactos/lib/syssetup/syssetup_Fr.rc b/reactos/lib/syssetup/syssetup_Fr.rc index c660afc08ea..a47ab99c134 100644 --- a/reactos/lib/syssetup/syssetup_Fr.rc +++ b/reactos/lib/syssetup/syssetup_Fr.rc @@ -105,7 +105,7 @@ BEGIN COMBOBOX IDC_TIMEZONELIST, 53, 96, 201, 42, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP AUTOCHECKBOX "Automatically adjust clock for &daylight saving changes", - IDC_DAYLIGHTSAVINGS, 53, 124, 201, 10 + IDC_AUTODAYLIGHT, 53, 124, 201, 10 END diff --git a/reactos/lib/syssetup/wizard.c b/reactos/lib/syssetup/wizard.c index 8cfd7e575fa..d5ee644e2eb 100644 --- a/reactos/lib/syssetup/wizard.c +++ b/reactos/lib/syssetup/wizard.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: wizard.c,v 1.11 2004/11/05 11:48:45 ekohl Exp $ +/* $Id: wizard.c,v 1.12 2004/11/11 12:23:43 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -537,7 +537,6 @@ static VOID CreateTimeZoneList(PSETUPDATA SetupData) { WCHAR szKeyName[256]; -// WCHAR szValue[256]; DWORD dwIndex; DWORD dwNameSize; DWORD dwValueSize; @@ -693,13 +692,26 @@ CreateTimeZoneList(PSETUPDATA SetupData) } -#if 0 static VOID DestroyTimeZoneList(PSETUPDATA SetupData) { + PTIMEZONE_ENTRY Entry; + while (SetupData->TimeZoneListHead != NULL) + { + Entry = SetupData->TimeZoneListHead; + + SetupData->TimeZoneListHead = Entry->Next; + if (SetupData->TimeZoneListHead != NULL) + { + SetupData->TimeZoneListHead->Prev = NULL; + } + + HeapFree(GetProcessHeap(), 0, Entry); + } + + SetupData->TimeZoneListTail = NULL; } -#endif static VOID @@ -800,6 +812,32 @@ GetLocalSystemTime(HWND hwnd, PSETUPDATA SetupData) } +static VOID +SetAutoDaylightInfo(HWND hwnd) +{ + HKEY hKey; + DWORD dwValue = 1; + + if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED) + { + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", + 0, + KEY_SET_VALUE, + &hKey)) + return; + + RegSetValueExW(hKey, + L"DisableAutoDaylightTimeSet", + 0, + REG_DWORD, + (LPBYTE)&dwValue, + sizeof(DWORD)); + RegCloseKey(hKey); + } +} + + INT_PTR CALLBACK DateTimePageDlgProc(HWND hwndDlg, UINT uMsg, @@ -822,7 +860,9 @@ DateTimePageDlgProc(HWND hwndDlg, CreateTimeZoneList(SetupData); ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST), - SetupData); + SetupData); + + SendDlgItemMessage(hwndDlg, IDC_AUTODAYLIGHT, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); } break; @@ -842,7 +882,8 @@ DateTimePageDlgProc(HWND hwndDlg, { GetLocalSystemTime(hwndDlg, SetupData); SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST), - SetupData); + SetupData); + SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT)); SetLocalTime(&SetupData->SystemTime); } break; @@ -853,6 +894,10 @@ DateTimePageDlgProc(HWND hwndDlg, } break; + case WM_DESTROY: + DestroyTimeZoneList(SetupData); + break; + default: break; }