From 610f48f080c6ae8c298a032cd92bb2ca9948aded Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:57:13 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@23 4f64403b-2f21-0410-a795-97e2b3489a10 --- worldtime/IcoLib.h | 37 ++ worldtime/WorldTime.cpp | 98 ++++ worldtime/WorldTime.dsp | 208 +++++++++ worldtime/WorldTime.dsw | 29 ++ worldtime/WorldTime.h | 44 ++ worldtime/WorldTime.plg | 81 ++++ worldtime/WorldTime.rc | 217 +++++++++ worldtime/WorldTime.sln | 20 + worldtime/WorldTime.vcproj | 434 +++++++++++++++++ worldtime/common.h | 27 ++ worldtime/day.ico | Bin 0 -> 2550 bytes worldtime/night.ico | Bin 0 -> 2550 bytes worldtime/options.cpp | 543 +++++++++++++++++++++ worldtime/plugwin.cpp | 1118 ++++++++++++++++++++++++++++++++++++++++++++ worldtime/plugwin.h | 113 +++++ worldtime/resource.h | 64 +++ worldtime/sunrise.ico | Bin 0 -> 2550 bytes worldtime/sunset.ico | Bin 0 -> 2550 bytes worldtime/time_convert.cpp | 209 +++++++++ worldtime/time_convert.h | 32 ++ worldtime/timezone.cpp | 70 +++ worldtime/timezone.h | 44 ++ 22 files changed, 3388 insertions(+) create mode 100644 worldtime/IcoLib.h create mode 100644 worldtime/WorldTime.cpp create mode 100644 worldtime/WorldTime.dsp create mode 100644 worldtime/WorldTime.dsw create mode 100644 worldtime/WorldTime.h create mode 100644 worldtime/WorldTime.plg create mode 100644 worldtime/WorldTime.rc create mode 100644 worldtime/WorldTime.sln create mode 100644 worldtime/WorldTime.vcproj create mode 100644 worldtime/common.h create mode 100644 worldtime/day.ico create mode 100644 worldtime/night.ico create mode 100644 worldtime/options.cpp create mode 100644 worldtime/plugwin.cpp create mode 100644 worldtime/plugwin.h create mode 100644 worldtime/resource.h create mode 100644 worldtime/sunrise.ico create mode 100644 worldtime/sunset.ico create mode 100644 worldtime/time_convert.cpp create mode 100644 worldtime/time_convert.h create mode 100644 worldtime/timezone.cpp create mode 100644 worldtime/timezone.h diff --git a/worldtime/IcoLib.h b/worldtime/IcoLib.h new file mode 100644 index 0000000..1817df6 --- /dev/null +++ b/worldtime/IcoLib.h @@ -0,0 +1,37 @@ +typedef struct { + int cbSize; + char *pszSection; //section name used to group icons + char *pszDescription; //description for options dialog + char *pszName; //name to refer to icon when playing and in db + //this name is miranda-wide. so use prefixes of your plugin + //e.g: "isee_connect", "clist_delete", etc + char *pszDefaultFile; //default icon file to use + int iDefaultIndex; +} SKINICONDESC; + +typedef struct { + int cbSize; + char *pszSection; + char *pszDescription; + char *pszName; + char *pszDefaultFile; + int iDefaultIndex; + HICON hDefaultIcon; +} SKINICONDESC2; + +// +// Add a icon into options UI +// +// wParam = (WPARAM)0 +// lParam = (LPARAM)(SKINICONDESC*)sid; +// +#define MS_SKIN2_ADDICON "Skin2/Icons/AddIcon" +// +// Retrieve HICON with name specified in lParam +// Returned HICON SHOULDN'T be destroyed, it managed by IcoLib +// +#define MS_SKIN2_GETICON "Skin2/Icons/GetIcon" +// +// Icons change notification +// +#define ME_SKIN2_ICONSCHANGED "Skin2/IconsChanged" diff --git a/worldtime/WorldTime.cpp b/worldtime/WorldTime.cpp new file mode 100644 index 0000000..63bc7b7 --- /dev/null +++ b/worldtime/WorldTime.cpp @@ -0,0 +1,98 @@ +#include "common.h" +#include "WorldTime.h" + +HINSTANCE hInst; +PLUGINLINK *pluginLink; + +PLUGININFO pluginInfo={ + sizeof(PLUGININFO), + "World Time", + PLUGIN_MAKE_VERSION(0, 2, 6, 7), + "Display world times.", + "Scott Ellis", + "mail@scottellis.com.au", + "© 2004 Scott Ellis", + "http://scottellis.com.au/", + 0, //not transient + 0 //doesn't replace anything built-in +}; + +int winver = 0; + +#define VER_9X 1 +#define VER_NT40 2 +#define VER_2KXP 3 + +void detect_win_version() { + OSVERSIONINFO version; + + version.dwOSVersionInfoSize = sizeof(version); + GetVersionEx(&version); + + winver = (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ? VER_9X + : (version.dwMajorVersion == 4) ? VER_NT40 : VER_2KXP; +} + + +extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + +extern "C" WORLDTIME_API PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +void CreatePluginServices() { +} + +static int OnModulesLoaded(WPARAM wParam, LPARAM lParam) { + + HWND contact_list_hwnd = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); + addmypluginwindow1(contact_list_hwnd); + + return 0; +} + +extern "C" WORLDTIME_API int Load(PLUGINLINK *link) +{ + pluginLink=link; + +/* + detect_win_version(); + if(winver < 2) { + MessageBox(0, "Sorry, this plugin does not work on Win9x (yet).\nPlugin disabled.", "World Time", MB_ICONERROR | MB_OK); + return 0; + } +*/ + + // ensure datetime picker is loaded + INITCOMMONCONTROLSEX ccx = {0}; + ccx.dwSize = sizeof(ccx); + ccx.dwICC = ICC_DATE_CLASSES; + InitCommonControlsEx(&ccx); + + if(build_timezone_list()) { + + DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0 ); + CreatePluginServices(); + + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + + HookEvent( ME_OPT_INITIALISE, WorldTimeOptInit ); + } else { + MessageBox(0, "Unable to read timezone information.\nPlugin disabled.", "World Time", MB_ICONERROR | MB_OK); + } + + return 0; +} + +extern "C" WORLDTIME_API int Unload(void) +{ + CloseHandle( mainThread ); + plugwin_cleanup(); + return 0; +} + diff --git a/worldtime/WorldTime.dsp b/worldtime/WorldTime.dsp new file mode 100644 index 0000000..8e66c7a --- /dev/null +++ b/worldtime/WorldTime.dsp @@ -0,0 +1,208 @@ +# Microsoft Developer Studio Project File - Name="WorldTime" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=WorldTime - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "WorldTime.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "WorldTime.mak" CFG="WorldTime - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "WorldTime - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "WorldTime - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "WorldTime - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /Yu"stdafx.h" /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "NDEBUG" +# ADD RSC /l 0xc09 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x22070000" /dll /machine:I386 /out:"../../bin/release/plugins/WorldTime.dll" + +!ELSEIF "$(CFG)" == "WorldTime - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 2 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0xc09 /d "_DEBUG" +# ADD RSC /l 0xc09 /d "_DEBUG" /d "_AFXDLL" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 user32.lib gdi32.lib shell32.lib advapi32.lib comctl32.lib /nologo /dll /debug /machine:I386 /out:"../../bin/debug/plugins/WorldTime.dll" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "WorldTime - Win32 Release" +# Name "WorldTime - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\options.cpp +# End Source File +# Begin Source File + +SOURCE=.\plugwin.cpp +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"stdafx.h" +# End Source File +# Begin Source File + +SOURCE=.\time_convert.cpp +# End Source File +# Begin Source File + +SOURCE=.\timezone.cpp +# End Source File +# Begin Source File + +SOURCE=.\WorldTime.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\IcoLib.h +# End Source File +# Begin Source File + +SOURCE=.\plugwin.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# Begin Source File + +SOURCE=.\time_convert.h +# End Source File +# Begin Source File + +SOURCE=.\timezone.h +# End Source File +# Begin Source File + +SOURCE=.\WorldTime.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\1_night.ico +# End Source File +# Begin Source File + +SOURCE=.\2_sunrise.ico +# End Source File +# Begin Source File + +SOURCE=.\3_day.ico +# End Source File +# Begin Source File + +SOURCE=.\4_sunset.ico +# End Source File +# Begin Source File + +SOURCE=.\day.ico +# End Source File +# Begin Source File + +SOURCE=.\icon_moon.ico +# End Source File +# Begin Source File + +SOURCE=.\icon_sun.ico +# End Source File +# Begin Source File + +SOURCE=.\icon_sunrise.ico +# End Source File +# Begin Source File + +SOURCE=.\icon_sunset.ico +# End Source File +# Begin Source File + +SOURCE=.\night.ico +# End Source File +# Begin Source File + +SOURCE=.\sunrise.ico +# End Source File +# Begin Source File + +SOURCE=.\sunset.ico +# End Source File +# Begin Source File + +SOURCE=.\WorldTime.rc +# End Source File +# End Group +# Begin Source File + +SOURCE=.\ReadMe.txt +# End Source File +# End Target +# End Project diff --git a/worldtime/WorldTime.dsw b/worldtime/WorldTime.dsw new file mode 100644 index 0000000..4c7c60a --- /dev/null +++ b/worldtime/WorldTime.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "WorldTime"=".\WorldTime.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/worldtime/WorldTime.h b/worldtime/WorldTime.h new file mode 100644 index 0000000..5300f73 --- /dev/null +++ b/worldtime/WorldTime.h @@ -0,0 +1,44 @@ +// © 2004 Scott Ellis +#ifndef _WORLD_TIME_H +#define _WORLD_TIME_H + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the PINGPLUG_VC6_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// PINGPLUG_VC6_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +#ifdef WORLDTIME_EXPORTS +#define WORLDTIME_API __declspec(dllexport) +#else +#define WORLDTIME_API __declspec(dllimport) +#endif + +#include "plugwin.h" +#include "timezone.h" + +//#include "../../include/newpluginapi.h" +#include "../../include/m_clui.h" +#include "../../include/m_system.h" +#include "../../include/m_options.h" +#include "../../include/m_protocols.h" +#include "../../include/m_protomod.h" +#include "../../include/m_protosvc.h" + +#include "../../include/m_updater.h" + +//#include "../../include/m_clist.h" +//#include "../../include/m_skin.h" +//#include "../../include/m_cluiframes.h" +//#include "../../include/m_netlib.h" + + +extern HINSTANCE hInst; +extern PLUGINLINK *pluginLink; +extern PLUGININFO pluginInfo; + +extern "C" WORLDTIME_API PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion); +extern "C" WORLDTIME_API int Load(PLUGINLINK *link); +extern "C" WORLDTIME_API int Unload(void); + +#endif \ No newline at end of file diff --git a/worldtime/WorldTime.plg b/worldtime/WorldTime.plg new file mode 100644 index 0000000..1fd4a90 --- /dev/null +++ b/worldtime/WorldTime.plg @@ -0,0 +1,81 @@ + + +
+

Build Log

+

+--------------------Configuration: WorldTime - Win32 Release-------------------- +

+

Command Lines

+Creating temporary file "C:\DOCUME~1\sje\LOCALS~1\Temp\RSP8E.tmp" with contents +[ +/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /Fp"Release/WorldTime.pch" /Yu"stdafx.h" /Fo"Release/" /Fd"Release/" /FD /c +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\options.cpp" +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\plugwin.cpp" +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\WorldTime.cpp" +] +Creating command line "cl.exe @C:\DOCUME~1\sje\LOCALS~1\Temp\RSP8E.tmp" +Creating temporary file "C:\DOCUME~1\sje\LOCALS~1\Temp\RSP8F.tmp" with contents +[ +comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x22070000" /dll /incremental:no /pdb:"Release/WorldTime.pdb" /machine:I386 /out:"../../bin/release/plugins/WorldTime.dll" /implib:"Release/WorldTime.lib" +".\Release\options.obj" +".\Release\plugwin.obj" +".\Release\StdAfx.obj" +".\Release\time_convert.obj" +".\Release\timezone.obj" +".\Release\WorldTime.obj" +".\Release\WorldTime.res" +] +Creating command line "link.exe @C:\DOCUME~1\sje\LOCALS~1\Temp\RSP8F.tmp" +

Output Window

+Compiling... +options.cpp +plugwin.cpp +WorldTime.cpp +Generating Code... +Linking... + Creating library Release/WorldTime.lib and object Release/WorldTime.exp + + + +

Results

+WorldTime.dll - 0 error(s), 0 warning(s) +

+--------------------Configuration: WorldTime - Win32 Debug-------------------- +

+

Command Lines

+Creating temporary file "C:\DOCUME~1\sje\LOCALS~1\Temp\RSP93.tmp" with contents +[ +/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WORLDTIME_EXPORTS" /D "_WINDLL" /D "_AFXDLL" /Fp"Debug/WorldTime.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\options.cpp" +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\plugwin.cpp" +"C:\Documents and Settings\sje\My Documents\MyProjects\miranda\plugins\WorldTime\WorldTime.cpp" +] +Creating command line "cl.exe @C:\DOCUME~1\sje\LOCALS~1\Temp\RSP93.tmp" +Creating temporary file "C:\DOCUME~1\sje\LOCALS~1\Temp\RSP94.tmp" with contents +[ +user32.lib gdi32.lib shell32.lib advapi32.lib comctl32.lib /nologo /dll /incremental:yes /pdb:"Debug/WorldTime.pdb" /debug /machine:I386 /out:"../../bin/debug/plugins/WorldTime.dll" /implib:"Debug/WorldTime.lib" /pdbtype:sept +".\Debug\options.obj" +".\Debug\plugwin.obj" +".\Debug\StdAfx.obj" +".\Debug\time_convert.obj" +".\Debug\timezone.obj" +".\Debug\WorldTime.obj" +".\Debug\WorldTime.res" +] +Creating command line "link.exe @C:\DOCUME~1\sje\LOCALS~1\Temp\RSP94.tmp" +

Output Window

+Compiling... +WorldTime.cpp +Generating Code... +Skipping... (no relevant changes detected) +options.cpp +plugwin.cpp +Linking... + + + +

Results

+WorldTime.dll - 0 error(s), 0 warning(s) +
+ + diff --git a/worldtime/WorldTime.rc b/worldtime/WorldTime.rc new file mode 100644 index 0000000..eefebde --- /dev/null +++ b/worldtime/WorldTime.rc @@ -0,0 +1,217 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE MOVEABLE PURE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE MOVEABLE PURE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE MOVEABLE PURE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (Australia) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENA) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_DIALOG1 DIALOGEX 0, 0, 327, 255 +STYLE DS_FIXEDSYS | WS_CHILD | WS_VISIBLE | WS_SYSMENU +FONT 8, "MS Shell Dlg" +BEGIN + GROUPBOX "Configuration",IDC_STATIC,7,7,313,241 + GROUPBOX "Interface",IDC_STATIC,28,16,272,75 + CONTROL "Show/hide with contact list (*if set, show/hide menu item has no effect)", + IDC_CHK_MINMAX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,34, + 27,260,10 + GROUPBOX "Times",IDC_STATIC,28,155,272,87 + LISTBOX IDC_LIST_TIMES2,53,169,221,43,LBS_NOINTEGRALHEIGHT | + WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Remove",IDC_BTN_REM,143,219,42,16,WS_DISABLED + CONTROL "Format Date",IDC_CHK_FORMAT,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,34,59,72,10 + EDITTEXT IDC_ED_FORMAT,211,58,78,12,ES_AUTOHSCROLL + CTEXT "and Time",IDC_STATIC,166,60,41,8 + EDITTEXT IDC_ED_DATE_FORMAT,111,58,51,12,ES_AUTOHSCROLL + CONTROL "Show icons",IDC_CHK_ICONS,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,34,75,116,10 + PUSHBUTTON "Edit",IDC_BTN_EDIT,94,219,42,16,WS_DISABLED + PUSHBUTTON "Add",IDC_BTN_ADD,45,219,42,16 + PUSHBUTTON "Up",IDC_BTN_UP,192,219,42,16,WS_DISABLED + PUSHBUTTON "Down",IDC_BTN_DOWN,241,219,42,16,WS_DISABLED + CONTROL "Hide main menu item (requires restart)", + IDC_CHK_HIDEMENU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, + 34,43,170,10 + PUSHBUTTON "Show Window",IDC_BTN_SHOW,211,40,78,13 + GROUPBOX "List",IDC_STATIC,28,94,272,59 + RTEXT "Font size:",IDC_STATICH,36,111,45,8 + EDITTEXT IDC_ED_FSIZE,86,109,32,14,ES_AUTOHSCROLL | ES_NUMBER, + WS_EX_RIGHT + CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT | + UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,118,108, + 12,15 + CONTROL "Custom1",IDC_TEXTCOL,"ColourPicker",WS_TABSTOP,164,117, + 40,9 + CTEXT "Text",IDC_STATICH2,161,105,44,9 + CONTROL "Custom1",IDC_BGCOL,"ColourPicker",WS_TABSTOP,217,117,40, + 9 + CTEXT "Background",IDC_STATIC,212,105,53,9 + LTEXT "Use the Customize/Fonts options to change text size and colour", + IDC_STATFS,39,107,174,31,NOT WS_VISIBLE + RTEXT "Indent:",IDC_STATIC,37,136,42,8 + EDITTEXT IDC_EDIT1,86,133,33,15,ES_AUTOHSCROLL + CONTROL "Spin2",IDC_SP_INDENT,"msctls_updown32",UDS_SETBUDDYINT | + UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,118,133, + 12,15 + RTEXT "Row height:",IDC_STATIC,144,136,60,8 + EDITTEXT IDC_EDIT2,214,133,33,15,ES_AUTOHSCROLL + CONTROL "Spin3",IDC_SP_ROWHEIGHT,"msctls_updown32", + UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | + UDS_ARROWKEYS,247,133,12,15 +END + +IDD_DIALOG2 DIALOG DISCARDABLE 0, 0, 296, 223 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Time Details" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,95,202,50,14,WS_DISABLED + PUSHBUTTON "Cancel",IDCANCEL,150,202,50,14 + LISTBOX IDC_LIST_TIMES,43,39,208,46,LBS_NOINTEGRALHEIGHT | + WS_VSCROLL | WS_TABSTOP + EDITTEXT IDC_ED_DISP,43,92,208,14,ES_AUTOHSCROLL | ES_READONLY + LTEXT "Label:",IDC_STATIC,68,123,20,8 + EDITTEXT IDC_ED_LABEL,94,121,133,14,ES_AUTOHSCROLL | WS_DISABLED + CONTROL "Alphabetical",IDC_RAD_ALPHA,"Button",BS_AUTORADIOBUTTON, + 88,25,55,10 + CONTROL "Geographical",IDC_RAD_GEO,"Button",BS_AUTORADIOBUTTON, + 151,25,58,10 + LTEXT "Sort Order:",IDC_STATIC,44,25,35,8 + CONTROL "DateTimePicker1",IDC_TIME_SUNRISE,"SysDateTimePick32", + DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,119,153, + 90,15 + RTEXT "Sunrise:",IDC_STATIC,49,155,54,8 + CONTROL "DateTimePicker1",IDC_TIME_SUNSET,"SysDateTimePick32", + DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,119,173, + 90,15 + RTEXT "Sunset:",IDC_STATIC,49,176,54,8 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO MOVEABLE PURE +BEGIN + IDD_DIALOG1, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 320 + TOPMARGIN, 7 + BOTTOMMARGIN, 248 + END + + IDD_DIALOG2, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 289 + TOPMARGIN, 7 + BOTTOMMARGIN, 216 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDR_CONTEXT MENU DISCARDABLE +BEGIN + MENUITEM "", 65535 + POPUP "test menu" + BEGIN + MENUITEM "Testing!!!", POPUP_TESTING + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON_SUN ICON DISCARDABLE "day.ico" +IDI_ICON_SUNSET ICON DISCARDABLE "sunset.ico" +IDI_ICON_MOON ICON DISCARDABLE "night.ico" +IDI_ICON_SUNRISE ICON DISCARDABLE "sunrise.ico" +#endif // English (Australia) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/worldtime/WorldTime.sln b/worldtime/WorldTime.sln new file mode 100644 index 0000000..34702e9 --- /dev/null +++ b/worldtime/WorldTime.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WorldTime", "WorldTime.vcproj", "{5F370DEE-3F8E-4BA1-BC2C-2B040691BD18}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5F370DEE-3F8E-4BA1-BC2C-2B040691BD18}.Debug|Win32.ActiveCfg = Debug|Win32 + {5F370DEE-3F8E-4BA1-BC2C-2B040691BD18}.Debug|Win32.Build.0 = Debug|Win32 + {5F370DEE-3F8E-4BA1-BC2C-2B040691BD18}.Release|Win32.ActiveCfg = Release|Win32 + {5F370DEE-3F8E-4BA1-BC2C-2B040691BD18}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/worldtime/WorldTime.vcproj b/worldtime/WorldTime.vcproj new file mode 100644 index 0000000..a8b18c8 --- /dev/null +++ b/worldtime/WorldTime.vcproj @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/worldtime/common.h b/worldtime/common.h new file mode 100644 index 0000000..11d06b6 --- /dev/null +++ b/worldtime/common.h @@ -0,0 +1,27 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__C0DB2B52_6239_4F4B_85C1_830836CC6209__INCLUDED_) +#define AFX_STDAFX_H__C0DB2B52_6239_4F4B_85C1_830836CC6209__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// Insert your headers here +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define _WIN32_WINNT 0x0500 + +#include +#include +#include +#include +#include + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__C0DB2B52_6239_4F4B_85C1_830836CC6209__INCLUDED_) diff --git a/worldtime/day.ico b/worldtime/day.ico new file mode 100644 index 0000000..5658f3a Binary files /dev/null and b/worldtime/day.ico differ diff --git a/worldtime/night.ico b/worldtime/night.ico new file mode 100644 index 0000000..9d3a989 Binary files /dev/null and b/worldtime/night.ico differ diff --git a/worldtime/options.cpp b/worldtime/options.cpp new file mode 100644 index 0000000..7bac536 --- /dev/null +++ b/worldtime/options.cpp @@ -0,0 +1,543 @@ +#include "common.h" +#include "plugwin.h" +//#include "commctrl.h" + +void save_listbox_items() { + DBWriteContactSettingDword(0, "WorldTime", "NumEntries", listbox_items.size()); + int index = 0; + for(ITEMLIST::iterator i = listbox_items.begin(); i != listbox_items.end(); i++, index++) { + std::ostringstream p1, p2, p3, p4; + + p1 << "Label" << index; + p2 << "Index" << index; + p3 << "Sunrise" << index; + p4 << "Sunset" << index; + + DBWriteContactSettingString(0, "WorldTime", p1.str().c_str(), i->pszText); + DBWriteContactSettingDword(0, "WorldTime", p2.str().c_str(), i->timezone_list_index); + DBWriteContactSettingDword(0, "WorldTime", p3.str().c_str(), i->sunrise.wHour * 60 + i->sunrise.wMinute); + DBWriteContactSettingDword(0, "WorldTime", p4.str().c_str(), i->sunset.wHour * 60 + i->sunset.wMinute); + } +} + +void set_minmax(bool mm) { + hook_window_behaviour_to_clist = mm; + if(hook_window_behaviour_to_clist) { + BYTE state = DBGetContactSettingByte(NULL, "CList", "Setting", SETTING_STATE_NORMAL); + + if(pluginwind) { + if(state == SETTING_STATE_NORMAL) + ShowWindow(pluginwind, SW_SHOW); + else + ShowWindow(pluginwind, SW_HIDE); + } + } +} + +void set_set_format(bool sf) { + set_format = sf; +} + +void set_time_format(const char *sf) { + strncpy(format_string, sf, 512); +} + +void set_date_format(const char *sf) { + strncpy(date_format_string, sf, 512); +} + +void set_show_icons(bool si) { + show_icons = si; +} + +void set_hide_menu(bool hm) { + hide_menu = hm; +} + +ITEMLIST temp_listbox_items; + +void fill_timezone_list_control(HWND hwndDlg) { + int index = 0; + + HWND hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + SendMessage(hw, LB_RESETCONTENT, 0, 0); + + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_ALPHA)) { + + for(TimeList::iterator i = timezone_list.begin(); i != timezone_list.end(); i++, index++) { + SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->tcName); + SendMessage(hw, LB_SETITEMDATA, (WPARAM)index, (LPARAM)i->list_index); + } + } else { + for(TimeList::iterator i = geo_timezone_list.begin(); i != geo_timezone_list.end(); i++, index++) { + SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->tcName); + SendMessage(hw, LB_SETITEMDATA, (WPARAM)index, (LPARAM)i->list_index); + } + } +} + + +LISTITEM add_edit_item; + +static BOOL CALLBACK DlgProcOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + HWND hw; + int sel; + char buf[MAX_NAME_LENGTH]; + + switch ( msg ) { + case WM_INITDIALOG: + { + TranslateDialogDefault( hwndDlg ); + + CheckDlgButton(hwndDlg, IDC_RAD_ALPHA, 1); + CheckDlgButton(hwndDlg, IDC_RAD_GEO, 0); + + fill_timezone_list_control(hwndDlg); + + if(add_edit_item.timezone_list_index != -1) { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + SendMessage(hw, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)timezone_list[add_edit_item.timezone_list_index].tcName); + SetDlgItemText(hwndDlg, IDC_ED_LABEL, add_edit_item.pszText); + + hw = GetDlgItem(hwndDlg, IDC_ED_LABEL); + EnableWindow(hw, TRUE); + hw = GetDlgItem(hwndDlg, IDOK); + EnableWindow(hw, TRUE); + + SendDlgItemMessage(hwndDlg, IDC_TIME_SUNRISE, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&add_edit_item.sunrise); + SendDlgItemMessage(hwndDlg, IDC_TIME_SUNSET, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&add_edit_item.sunset); + + hw = GetDlgItem(hwndDlg, IDC_ED_DISP); + SetWindowText(hw, timezone_list[add_edit_item.timezone_list_index].tcDisp); + } else { + SYSTEMTIME systime = {0}; + + GetSystemTime(&systime); + + systime.wHour = 6; + systime.wMinute = 0; + systime.wSecond = 0; + SendDlgItemMessage(hwndDlg, IDC_TIME_SUNRISE, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&systime); + systime.wHour = 18; + SendDlgItemMessage(hwndDlg, IDC_TIME_SUNSET, DTM_SETSYSTEMTIME, (WPARAM)GDT_VALID, (LPARAM)&systime); + + } + } + break; + + case WM_COMMAND: + if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LIST_TIMES) { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + sel = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel != LB_ERR) { + hw = GetDlgItem(hwndDlg, IDC_ED_LABEL); + EnableWindow(hw, sel != -1); + if(sel == -1) + add_edit_item.timezone_list_index = -1; + else { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + add_edit_item.timezone_list_index = (int)SendMessage(hw, LB_GETITEMDATA, sel, 0); + + hw = GetDlgItem(hwndDlg, IDC_ED_DISP); + SetWindowText(hw, timezone_list[add_edit_item.timezone_list_index].tcDisp); + } + } + } + + if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) { + switch( LOWORD( wParam )) { + case IDC_ED_LABEL: + GetDlgItemText(hwndDlg, IDC_ED_LABEL, buf, MAX_NAME_LENGTH); + hw = GetDlgItem(hwndDlg, IDOK); + EnableWindow(hw, (strlen(buf) > 0)); + strncpy(add_edit_item.pszText, buf, MAX_NAME_LENGTH); + } + } + + if ( HIWORD( wParam ) == BN_CLICKED ) { + switch( LOWORD( wParam )) { + case IDC_RAD_ALPHA: + CheckDlgButton(hwndDlg, IDC_RAD_GEO, 0); + fill_timezone_list_control(hwndDlg); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + if(add_edit_item.timezone_list_index != -1) + SendMessage(hw, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)timezone_list[add_edit_item.timezone_list_index].tcName); + break; + case IDC_RAD_GEO: + CheckDlgButton(hwndDlg, IDC_RAD_ALPHA, 0); + fill_timezone_list_control(hwndDlg); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES); + if(add_edit_item.timezone_list_index != -1) + SendMessage(hw, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)timezone_list[add_edit_item.timezone_list_index].tcName); + break; + case IDOK: + if(SendDlgItemMessage(hwndDlg, IDC_TIME_SUNRISE, DTM_GETSYSTEMTIME, 0, (LPARAM)&add_edit_item.sunrise) != GDT_VALID) { + add_edit_item.sunrise.wHour = 6; + add_edit_item.sunrise.wMinute = 0; + add_edit_item.sunrise.wSecond = 0; + } + if(SendDlgItemMessage(hwndDlg, IDC_TIME_SUNSET, DTM_GETSYSTEMTIME, 0, (LPARAM)&add_edit_item.sunset) != GDT_VALID) { + add_edit_item.sunset.wHour = 18; + add_edit_item.sunset.wMinute = 0; + add_edit_item.sunset.wSecond = 0; + } + EndDialog(hwndDlg, IDOK); + break; + case IDCANCEL: + EndDialog(hwndDlg, IDCANCEL); + break; + } + } + break; + } + return FALSE; +} + +static BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + + HWND hw; + int sel, index; + DBVARIANT dbv; + + switch ( msg ) { + case WM_INITDIALOG: { + TranslateDialogDefault( hwndDlg ); + + SendMessage(GetDlgItem(hwndDlg, IDC_SPIN1), UDM_SETRANGE, 0, (LPARAM)MAKELONG(50, 5)); + if(!DBGetContactSetting(NULL,"WorldTime","FontSize",&dbv) + || !DBGetContactSetting(NULL,"CLC","Font0Size",&dbv)) + { + SendMessage(GetDlgItem(hwndDlg, IDC_SPIN1), UDM_SETPOS, 0, dbv.bVal); + } + + SendMessage(GetDlgItem(hwndDlg, IDC_SP_INDENT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(500, 0)); + SendMessage(GetDlgItem(hwndDlg, IDC_SP_INDENT), UDM_SETPOS, 0, DBGetContactSettingWord(NULL, "WorldTime", "Indent", 0)); + SendMessage(GetDlgItem(hwndDlg, IDC_SP_ROWHEIGHT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(500, 6)); + SendMessage(GetDlgItem(hwndDlg, IDC_SP_ROWHEIGHT), UDM_SETPOS, 0, DBGetContactSettingWord(NULL, "WorldTime", "RowHeight", GetSystemMetrics(SM_CYSMICON))); + + temp_listbox_items = listbox_items; + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + + index = 0; + for(ITEMLIST::iterator ili = temp_listbox_items.begin(); ili != temp_listbox_items.end(); ili++, index++) { + sel = SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)&ili->pszText); + } + + if(!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { + bool minmax = (DBGetContactSettingByte(NULL, "WorldTime", "MinMax", DEFAULT_MINMAX ? 1 : 0) == 1); + CheckDlgButton(hwndDlg, IDC_CHK_MINMAX, minmax); + bool hide_menu = (DBGetContactSettingByte(NULL, "WorldTime", "HideMenu", 0) == 1); + CheckDlgButton(hwndDlg, IDC_CHK_HIDEMENU, hide_menu ? 1 : 0); + } else { + CheckDlgButton(hwndDlg, IDC_CHK_HIDEMENU, TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_HIDEMENU), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SHOW), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_MINMAX), FALSE); + } + + bool set_format = (DBGetContactSettingByte(NULL, "WorldTime", "EnableTimeFormat", 0) == 1); + CheckDlgButton(hwndDlg, IDC_CHK_FORMAT, set_format ? 1 : 0); + bool show_icons = (DBGetContactSettingByte(NULL, "WorldTime", "ShowIcons", 1) == 1); + CheckDlgButton(hwndDlg, IDC_CHK_ICONS, show_icons ? 1 : 0); + DBVARIANT dbv; + if(!DBGetContactSetting(NULL, "WorldTime", "TimeFormat", &dbv)) + strcpy(format_string, dbv.pszVal); + DBFreeVariant(&dbv); + SetDlgItemText(hwndDlg, IDC_ED_FORMAT, format_string); + if(!DBGetContactSetting(NULL, "WorldTime", "DateFormat", &dbv)) + strcpy(date_format_string, dbv.pszVal); + DBFreeVariant(&dbv); + SetDlgItemText(hwndDlg, IDC_ED_DATE_FORMAT, date_format_string); + + if(!set_format) { + hw = GetDlgItem(hwndDlg, IDC_ED_FORMAT); + EnableWindow(hw, FALSE); + hw = GetDlgItem(hwndDlg, IDC_ED_DATE_FORMAT); + EnableWindow(hw, FALSE); + } + + SendDlgItemMessage(hwndDlg, IDC_TEXTCOL, CPM_SETCOLOUR, 0, DBGetContactSettingDword(NULL, "WorldTime", "FontCol", GetSysColor(COLOR_WINDOWTEXT))); + SendDlgItemMessage(hwndDlg, IDC_BGCOL, CPM_SETCOLOUR, 0, DBGetContactSettingDword(NULL, "WorldTime", "BgColour", GetSysColor(COLOR_3DFACE))); + + if(ServiceExists(MS_FONT_REGISTER)) { + ShowWindow(GetDlgItem(hwndDlg, IDC_STATICH), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_STATICH2), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_SPIN1), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_ED_FSIZE), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_TEXTCOL), SW_HIDE); + + ShowWindow(GetDlgItem(hwndDlg, IDC_STATFS), SW_SHOW); + + } + + //return TRUE; + return FALSE; + } + case WM_COMMAND: + if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) { + switch( LOWORD( wParam )) { + case IDC_ED_FORMAT: + case IDC_ED_DATE_FORMAT: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + } + + if (HIWORD( wParam ) == LBN_SELCHANGE && LOWORD(wParam) == IDC_LIST_TIMES2) { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + sel = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel != LB_ERR) { + hw = GetDlgItem(hwndDlg, IDC_BTN_REM); + EnableWindow(hw, sel != -1); + hw = GetDlgItem(hwndDlg, IDC_BTN_EDIT); + EnableWindow(hw, sel != -1); + + hw = GetDlgItem(hwndDlg, IDC_BTN_UP); + EnableWindow(hw, (sel > 0)); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int count = SendMessage(hw, LB_GETCOUNT, 0, 0); + hw = GetDlgItem(hwndDlg, IDC_BTN_DOWN); + EnableWindow(hw, (sel < count - 1)); + } + } + + if ( HIWORD( wParam ) == BN_CLICKED ) { + switch( LOWORD( wParam )) { + case IDC_BTN_SHOW: + ShowWindow(pluginwind, SW_SHOW); + break; + case IDC_BTN_EDIT: + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + sel = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel != LB_ERR && sel != -1) { + + add_edit_item = temp_listbox_items[sel]; + if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hwndDlg, DlgProcOpts2) == IDOK) { + temp_listbox_items[sel] = add_edit_item; + + SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, (LPARAM)0); + SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel, (LPARAM)add_edit_item.pszText); + SendMessage(hw, LB_SETCURSEL, (WPARAM)sel, 0); + + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + } + break; + + case IDC_BTN_ADD: + + add_edit_item.pszText[0] = '\0'; + add_edit_item.timezone_list_index = -1; + + if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hwndDlg, DlgProcOpts2) == IDOK) { + temp_listbox_items.push_back(add_edit_item); + + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + sel = SendMessage(hw, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)add_edit_item.pszText); + SendMessage(hw, LB_SETCURSEL, (WPARAM)sel, 0); + + hw = GetDlgItem(hwndDlg, IDC_BTN_REM); + EnableWindow(hw, TRUE); + hw = GetDlgItem(hwndDlg, IDC_BTN_EDIT); + EnableWindow(hw, TRUE); + + sel = temp_listbox_items.size() - 1; + hw = GetDlgItem(hwndDlg, IDC_BTN_UP); + EnableWindow(hw, (sel > 0)); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int count = SendMessage(hw, LB_GETCOUNT, 0, 0); + hw = GetDlgItem(hwndDlg, IDC_BTN_DOWN); + EnableWindow(hw, (sel < count - 1)); + + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + break; + + case IDC_BTN_REM: + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + sel = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel != LB_ERR) { + SendMessage(hw, LB_DELETESTRING, (WPARAM)sel, 0); + + { + ITEMLIST::iterator i = temp_listbox_items.begin(); + for(int j = 0; j < sel; j++) + i++; + temp_listbox_items.erase(i); + } + + hw = GetDlgItem(hwndDlg, IDC_BTN_REM); + EnableWindow(hw, FALSE); + hw = GetDlgItem(hwndDlg, IDC_BTN_EDIT); + EnableWindow(hw, FALSE); + hw = GetDlgItem(hwndDlg, IDC_BTN_UP); + EnableWindow(hw, FALSE); + hw = GetDlgItem(hwndDlg, IDC_BTN_DOWN); + EnableWindow(hw, FALSE); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + break; + case IDC_BTN_DOWN: + { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel2 != LB_ERR) { + add_edit_item = temp_listbox_items[sel2]; + temp_listbox_items[sel2] = temp_listbox_items[sel2 + 1]; + temp_listbox_items[sel2 + 1] = add_edit_item; + + SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0); + SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_listbox_items[sel2].pszText); + SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 + 1), (LPARAM)0); + SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 + 1), (LPARAM)temp_listbox_items[sel2 + 1].pszText); + SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 + 1), 0); + + hw = GetDlgItem(hwndDlg, IDC_BTN_UP); + EnableWindow(hw, (sel2 + 1 > 0)); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int count = SendMessage(hw, LB_GETCOUNT, 0, 0); + hw = GetDlgItem(hwndDlg, IDC_BTN_DOWN); + EnableWindow(hw, (sel2 + 1 < count - 1)); + + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + } + break; + case IDC_BTN_UP: + { + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int sel2 = SendMessage(hw, LB_GETCURSEL, 0, 0); + if(sel2 != LB_ERR) { + add_edit_item = temp_listbox_items[sel2]; + temp_listbox_items[sel2] = temp_listbox_items[sel2 - 1]; + temp_listbox_items[sel2 - 1] = add_edit_item; + + SendMessage(hw, LB_DELETESTRING, (WPARAM)sel2, (LPARAM)0); + SendMessage(hw, LB_INSERTSTRING, (WPARAM)sel2, (LPARAM)temp_listbox_items[sel2].pszText); + SendMessage(hw, LB_DELETESTRING, (WPARAM)(sel2 - 1), (LPARAM)0); + SendMessage(hw, LB_INSERTSTRING, (WPARAM)(sel2 - 1), (LPARAM)temp_listbox_items[sel2 - 1].pszText); + SendMessage(hw, LB_SETCURSEL, (WPARAM)(sel2 - 1), 0); + + hw = GetDlgItem(hwndDlg, IDC_BTN_UP); + EnableWindow(hw, (sel2 - 1 > 0)); + hw = GetDlgItem(hwndDlg, IDC_LIST_TIMES2); + int count = SendMessage(hw, LB_GETCOUNT, 0, 0); + hw = GetDlgItem(hwndDlg, IDC_BTN_DOWN); + EnableWindow(hw, (sel2 - 1 < count - 1)); + + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + } + break; + case IDC_CHK_ICONS: + case IDC_CHK_MINMAX: + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_HIDEMENU: + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_FORMAT: + hw = GetDlgItem(hwndDlg, IDC_ED_FORMAT); + EnableWindow(hw, IsDlgButtonChecked(hwndDlg, IDC_CHK_FORMAT)); + hw = GetDlgItem(hwndDlg, IDC_ED_DATE_FORMAT); + EnableWindow(hw, IsDlgButtonChecked(hwndDlg, IDC_CHK_FORMAT)); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + } + } + if(LOWORD(wParam) == IDC_TEXTCOL || LOWORD(wParam) == IDC_BGCOL + || LOWORD(wParam) == IDC_SPIN1 || LOWORD(wParam) == IDC_SP_INDENT || LOWORD(wParam) == IDC_SP_ROWHEIGHT) + { + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + break; + + case WM_NOTIFY: + if(((LPNMHDR)lParam)->code == UDN_DELTAPOS ) { + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + if(((LPNMHDR)lParam)->code == PSN_APPLY ) { + bool new_minmax = IsDlgButtonChecked(hwndDlg, IDC_CHK_MINMAX) == BST_CHECKED; + DBWriteContactSettingByte(NULL, "WorldTime", "MinMax", new_minmax ? 1 : 0); + set_minmax(new_minmax); + + bool new_set_format = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORMAT) == BST_CHECKED; + DBWriteContactSettingByte(NULL, "WorldTime", "EnableTimeFormat", new_set_format ? 1 : 0); + set_set_format(new_set_format); + + bool new_show_icons = IsDlgButtonChecked(hwndDlg, IDC_CHK_ICONS) == BST_CHECKED; + DBWriteContactSettingByte(NULL, "WorldTime", "ShowIcons", new_show_icons ? 1 : 0); + set_show_icons(new_show_icons); + + bool new_hide_menu = IsDlgButtonChecked(hwndDlg, IDC_CHK_HIDEMENU) == BST_CHECKED; + DBWriteContactSettingByte(NULL, "WorldTime", "HideMenu", new_hide_menu ? 1 : 0); + set_hide_menu(new_hide_menu); + + char buf[512]; + GetDlgItemText(hwndDlg, IDC_ED_FORMAT, buf, 512); + DBWriteContactSettingString(NULL, "WorldTime", "TimeFormat", buf); + set_time_format(buf); + + GetDlgItemText(hwndDlg, IDC_ED_DATE_FORMAT, buf, 512); + DBWriteContactSettingString(NULL, "WorldTime", "DateFormat", buf); + set_date_format(buf); + + listbox_items = temp_listbox_items; + save_listbox_items(); + + if(!ServiceExists(MS_FONT_REGISTER)) { + DBWriteContactSettingDword(NULL, "WorldTime", "FontCol", ContactFontColour = SendDlgItemMessage(hwndDlg, IDC_TEXTCOL, CPM_GETCOLOUR, 0, 0)); + DBWriteContactSettingByte(0, "WorldTime", "FontSize", (BYTE)SendMessage(GetDlgItem(hwndDlg, IDC_SPIN1), UDM_GETPOS, 0, 0) & 255); + } + + DBWriteContactSettingDword(NULL, "WorldTime", "BgColour", SendDlgItemMessage(hwndDlg, IDC_BGCOL, CPM_GETCOLOUR, 0, 0)); + + DBWriteContactSettingWord(0, "WorldTime", "Indent", (WORD)SendMessage(GetDlgItem(hwndDlg, IDC_SP_INDENT), UDM_GETPOS, 0, 0)); + DBWriteContactSettingWord(0, "WorldTime", "RowHeight", (WORD)SendMessage(GetDlgItem(hwndDlg, IDC_SP_ROWHEIGHT), UDM_GETPOS, 0, 0)); + + DeleteObject(ContactFont); + ContactFont = (HFONT)GetFont(); + + if(pluginwind) { + /* + RECT r; + SIZE textSize; + GetWindowRect(pluginwind, &r); + HFONT hOldFont = (HFONT)SelectObject(GetDC(pluginwind), ContactFont); + GetTextExtentPoint32(GetDC(pluginwind),"X",1,&textSize); + SelectObject(GetDC(pluginwind), hOldFont); + SetWindowPos(pluginwind, 0, 0, 0, r.right - r.left, textSize.cy * listbox_items.size(), SWP_NOZORDER | SWP_NOMOVE); + if(Frameid != -1) { + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, (WPARAM)MAKELONG(FO_HEIGHT, Frameid), (LPARAM)DBGetContactSettingByte(0, "WorldTime", "FontSize", 10) * listbox_items.size()); + } + */ + FillList(0, 0); + } + + return TRUE; + } + break; + } + + return FALSE; +} + +int WorldTimeOptInit(WPARAM wParam,LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = { 0 }; +#define OPTIONPAGE_OLD_SIZE2 60 + + //odp.cbSize = sizeof(odp); + odp.cbSize = OPTIONPAGE_OLD_SIZE2; + odp.position = -790000000; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCE(IDD_DIALOG1); + odp.pszTitle = Translate("World Time"); + odp.pszGroup = Translate("Plugins"); + odp.flags = ODPF_BOLDGROUPS; + //odp.nIDBottomSimpleControl = IDC_PPM; + odp.pfnDlgProc = DlgProcOpts; + CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp ); + + return 0; +} + diff --git a/worldtime/plugwin.cpp b/worldtime/plugwin.cpp new file mode 100644 index 0000000..cc7ae56 --- /dev/null +++ b/worldtime/plugwin.cpp @@ -0,0 +1,1118 @@ +#include "common.h" +#include "plugwin.h" +#include "commctrl.h" + +HFONT TitleBarFont; +HFONT ContactFont; +COLORREF ContactFontColour; + +FontID font_id; // for use with FontService plugin + +HANDLE mainThread; + +HBRUSH tbrush = 0; + +HANDLE mainMenuItem, hIconsChangedEvent, hDBChange, hIcoLibIconsChanged; + +HICON upIcon, downIcon, riseIcon, setIcon; + +HMENU hMainMenu; +UINT menuItemId; + +ITEMLIST listbox_items; + +TCHAR format_string[512], date_format_string[512]; + +int Frameid=-1; +HWND label; + +HWND pluginwind = 0, hwnd_clist = 0; + +static CRITICAL_SECTION cs2; + +bool hook_window_behaviour_to_clist = true; +bool set_format = false; +bool show_icons = true; +bool hide_menu = false; + +HANDLE status_update_thread = 0; + +static HMODULE hUserDll; +BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD); +BOOL (WINAPI *MyAnimateWindow)(HWND hWnd,DWORD dwTime,DWORD dwFlags); + +#define TM_AUTOALPHA 1 +static int transparentFocus=1; + +#define WM_WTREFRESH (WM_USER + 10) +#define WMU_INITIALIZE (WM_USER + 11) +#define WMU_SIZELIST (WM_USER + 12) + +static int CLUILoadTitleBarFont() +{ + char facename[]="MS Shell Dlg"; + HFONT hfont; + LOGFONT logfont; + memset(&logfont,0,sizeof(logfont)); + memcpy(logfont.lfFaceName,facename,sizeof(facename)); + logfont.lfWeight=FW_NORMAL; + logfont.lfHeight=-10; + hfont=CreateFontIndirect(&logfont); + return((int)hfont); +} + +HFONT GetCLCFont0() +{ + DBVARIANT dbv; + char idstr[10]; + BYTE style; + LOGFONT log_font; + LOGFONT *lf = &log_font; + int i = 0; + HFONT hFont; + HDC hdc = GetDC(pluginwind); + + SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(LOGFONT),lf,FALSE); + + if(!DBGetContactSetting(NULL,"WorldTime","FontName",&dbv)) { + lstrcpy(lf->lfFaceName,dbv.pszVal); + DBFreeVariant(&dbv); + } else { + wsprintf(idstr,"Font%dName",i); + if(!DBGetContactSetting(NULL,"CLC",idstr,&dbv)) { + lstrcpy(lf->lfFaceName,dbv.pszVal); + DBFreeVariant(&dbv); + } + } + wsprintf(idstr, "Font%dCol", i); + ContactFontColour = (COLORREF)DBGetContactSettingDword(NULL, "CLC", idstr, GetSysColor(COLOR_WINDOWTEXT)); + if(!DBGetContactSetting(NULL,"WorldTime","FontSize",&dbv)) { + lf->lfHeight=(char)dbv.bVal; + } else { + wsprintf(idstr,"Font%dSize",i); + lf->lfHeight=(char)DBGetContactSettingByte(NULL,"CLC",idstr,lf->lfHeight); + if(lf->lfHeight > 0) + lf->lfHeight=-MulDiv(abs(lf->lfHeight), GetDeviceCaps(hdc, LOGPIXELSY), 72); + } + +#define DBFONTF_BOLD 1 +#define DBFONTF_ITALIC 2 +#define DBFONTF_UNDERLINE 4 + + if(!DBGetContactSetting(NULL,"WorldTime","FontSty",&dbv)) { + style=(BYTE)DBGetContactSettingByte(NULL,"WorldTime","FontSty",(lf->lfWeight==FW_NORMAL?0:DBFONTF_BOLD)|(lf->lfItalic?DBFONTF_ITALIC:0)|(lf->lfUnderline?DBFONTF_UNDERLINE:0)); + } else { + wsprintf(idstr,"Font%dSty",i); + style=(BYTE)DBGetContactSettingByte(NULL,"CLC",idstr,(lf->lfWeight==FW_NORMAL?0:DBFONTF_BOLD)|(lf->lfItalic?DBFONTF_ITALIC:0)|(lf->lfUnderline?DBFONTF_UNDERLINE:0)); + } + lf->lfWidth=lf->lfEscapement=lf->lfOrientation=0; + lf->lfWeight=style&DBFONTF_BOLD?FW_BOLD:FW_NORMAL; + lf->lfItalic=(style&DBFONTF_ITALIC)!=0; + lf->lfUnderline=(style&DBFONTF_UNDERLINE)!=0; + lf->lfStrikeOut=0; + + if(!DBGetContactSetting(NULL,"WorldTime","FontSet",&dbv)) { + lf->lfCharSet = dbv.bVal; + } else { + wsprintf(idstr,"Font%dSet",i); + lf->lfCharSet=DBGetContactSettingByte(NULL,"CLC",idstr,lf->lfCharSet); + } + lf->lfOutPrecision=OUT_DEFAULT_PRECIS; + lf->lfClipPrecision=CLIP_DEFAULT_PRECIS; + lf->lfQuality=DEFAULT_QUALITY; + lf->lfPitchAndFamily=DEFAULT_PITCH|FF_DONTCARE; + + hFont=CreateFontIndirect(lf); + ReleaseDC(pluginwind, hdc); + return hFont; +} + +HFONT GetFont() { + if(ServiceExists(MS_FONT_REGISTER)) { + LOGFONT log_font; + ContactFontColour = (COLORREF)CallService(MS_FONT_GET, (WPARAM)&font_id, (LPARAM)&log_font); + return CreateFontIndirect(&log_font); + } else + return (HFONT)GetCLCFont0(); +} + +int ReloadFont(WPARAM wParam, LPARAM lParam) { + DeleteObject(ContactFont); + ContactFont = GetFont(); + if(pluginwind) { + /* + RECT r; + SIZE textSize; + GetWindowRect(pluginwind, &r); + HFONT hOldFont = (HFONT)SelectObject(GetDC(pluginwind), ContactFont); + GetTextExtentPoint32(GetDC(pluginwind),"X",1,&textSize); + SelectObject(GetDC(pluginwind), hOldFont); + SetWindowPos(pluginwind, 0, 0, 0, r.right - r.left, textSize.cy * listbox_items.size(), SWP_NOZORDER | SWP_NOMOVE); + if(Frameid != -1) { + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, (WPARAM)MAKELONG(FO_HEIGHT, Frameid), (LPARAM)DBGetContactSettingByte(0, "WorldTime", "FontSize", 10) * listbox_items.size()); + } + */ + InvalidateRect(label, 0, TRUE); + } + return 0; +} + +/* +void CALLBACK plug1TimerProc( + HWND hwnd, // handle to window + UINT uMsg, // WM_TIMER message + UINT idEvent, // timer identifier + DWORD dwTime // current system time +) +{ + char TBcapt[255]; + SYSTEMTIME systime; + + GetLocalTime(&systime); + + wsprintf(TBcapt,"%s %02d:%02d:%02d",Translate("World Time"), systime.wHour, systime.wMinute, systime.wSecond); + + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_TBNAME,Frameid),(LPARAM)TBcapt); + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_TBTIPNAME,Frameid),(LPARAM)TBcapt); + CallService(MS_CLIST_FRAMES_UPDATEFRAME,Frameid,FU_TBREDRAW); +}; +*/ + +void CALLBACK plug1TimerProc2( + HWND hwnd, // handle to window + UINT uMsg, // WM_TIMER message + UINT idEvent, // timer identifier + DWORD dwTime // current system time +) +{ + if(pluginwind && label) { + //InvalidateRect(pluginwind, 0, TRUE); + //InvalidateRect(label, 0, FALSE); + //ValidateRect(pluginwind, 0); + SendMessage(pluginwind, WM_WTREFRESH, 0, 0); + } +}; + +void CALLBACK plug1TimerProc3( + HWND hwnd, // handle to window + UINT uMsg, // WM_TIMER message + UINT idEvent, // timer identifier + DWORD dwTime // current system time +) +{ + if(pluginwind && hwnd_clist && hook_window_behaviour_to_clist) { + if(IsWindowVisible(pluginwind) != IsWindowVisible(hwnd_clist)) + ShowWindow(pluginwind, IsWindowVisible(hwnd_clist) ? SW_SHOW : SW_HIDE); + } +} + +int minutes_diff(SYSTEMTIME *t1, SYSTEMTIME *t2) { + return (t1->wHour - t2->wHour) * 60 + (t1->wMinute - t2->wMinute); +} + + +bool FrameIsFloating() { + if(Frameid == -1) + return true; // no frames, always floating + + return (CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLOATING, Frameid), 0) != 0); +} + +WNDPROC oldListWindowProc; + +LRESULT CALLBACK SubclassedListWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PAINTSTRUCT ps; + HDC hdc; + RECT r; + + switch(msg) { + case WM_PAINT: + if(SendMessage(hwnd, LB_GETCOUNT, 0, 0) == 0) { + hdc = BeginPaint(hwnd, &ps); + GetClientRect(hwnd, &r); + if(FrameIsFloating()) { + //SkinDrawGlyph(hdc, &r, &r, "Main Window/Backgrnd"); + SkinDrawGlyph(hdc, &r, &r, "World Time/Background"); + } else { + //SkinDrawWindowBack(hwnd, hdc, &r, "Main Window/Backgrnd"); + SkinDrawGlyph(hdc, &r, &r, "World Time/Background"); + } + EndPaint(hwnd, &ps); + return TRUE; + } else + break; + } + + return CallWindowProc(oldListWindowProc, hwnd, msg, wParam, lParam); +} + +LRESULT CALLBACK mypluginwindow1proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + RECT rect; + MEASUREITEMSTRUCT *mis; + LPDRAWITEMSTRUCT dis; + LISTITEM *pItemData; + SIZE textSize; + RECT r; + LPARAM lp; + int sel; + HFONT oldFont; + //PAINTSTRUCT ps; + + switch(msg) + { + + case WM_MEASUREITEM: + { + mis = (MEASUREITEMSTRUCT *)lParam; + mis->itemWidth = 100; + mis->itemHeight = DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON)); + return TRUE; + } + + case WM_DRAWITEM: + dis = (LPDRAWITEMSTRUCT)lParam; + //pItemData = (LISTITEM *)dis->itemData; + if(dis->hwndItem == label) { + HBRUSH ttbrush = 0; + RECT r; + COLORREF tcol; + //GetClientRect(dis->hwndItem, &r); + GetClientRect(hwnd, &r); + if(dis->itemID != -1) { + + oldFont = (HFONT)SelectObject(dis->hDC, ContactFont); + GetTextExtentPoint32(dis->hDC,"X",1,&textSize); + SendMessage(label, LB_SETITEMHEIGHT, 0, (LPARAM)DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON))); + // stop full list erase + //dis->rcItem.bottom = dis->rcItem.top + DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON)); + + if(dis->itemState & ODS_SELECTED && dis->itemState & ODS_FOCUS) { + + if(ServiceExists(MS_SKIN_DRAWGLYPH)) { + if(FrameIsFloating()) { + //SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Selection Background"); + } else { + //SkinDrawWindowBack(label, dis->hDC, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Selection Background"); + } + } else { + tcol = DBGetContactSettingDword(NULL,"CLC","SelBkColour", CLCDEFAULT_SELBKCOLOUR); + SetBkColor(dis->hDC, tcol); + FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol))); + } + + tcol = DBGetContactSettingDword(NULL,"CLC","SelTextColour", CLCDEFAULT_SELTEXTCOLOUR); + SetTextColor(dis->hDC, tcol); + } else { + + if(ServiceExists(MS_SKIN_DRAWGLYPH)) { + + if(FrameIsFloating()) { + //SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background"); + } else { + //SkinDrawWindowBack(label, dis->hDC, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background"); + } + + } else { + //tcol = DBGetContactSettingDword(NULL,"CLC","BkColour", CLCDEFAULT_BKCOLOUR); + tcol = DBGetContactSettingDword(NULL, "WorldTime", "BgColour", GetSysColor(COLOR_3DFACE)); + SetBkColor(dis->hDC, tcol); + FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol))); + } + + //SendMessage(label, LB_GETITEMRECT, (WPARAM)dis->itemID, (LPARAM)&r); + //FillRect(dis->hDC, &r, (ttbrush = CreateSolidBrush(tcol))); + + tcol = ContactFontColour; + SetTextColor(dis->hDC, tcol); + } + + SetBkMode(dis->hDC, TRANSPARENT); + EnterCriticalSection(&cs2); + pItemData = &listbox_items[dis->itemID]; + { + + dis->rcItem.left += DBGetContactSettingWord(NULL, "WorldTime", "Indent", 0); + if(show_icons) { + //DrawIconEx(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-GetSystemMetrics(SM_CYSMICON))>>1, pItemData->icon, GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL); + DrawIconEx(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-16)>>1, pItemData->icon, 0, 0, 0, NULL, DI_NORMAL); + + GetTextExtentPoint32(dis->hDC,pItemData->pszText,lstrlen(pItemData->pszText),&textSize); + TextOut(dis->hDC,dis->rcItem.left + 16 + 4,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszText,lstrlen(pItemData->pszText)); + } else { + GetTextExtentPoint32(dis->hDC,pItemData->pszText,lstrlen(pItemData->pszText),&textSize); + TextOut(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszText,lstrlen(pItemData->pszText)); + } + + GetTextExtentPoint32(dis->hDC,pItemData->pszTimeText,lstrlen(pItemData->pszTimeText),&textSize); + TextOut(dis->hDC,dis->rcItem.right - textSize.cx - 2,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszTimeText,lstrlen(pItemData->pszTimeText)); + + if(set_format) { + int xSave = textSize.cx; + + GetTextExtentPoint32(dis->hDC,pItemData->pszDateText,lstrlen(pItemData->pszDateText),&textSize); + TextOut(dis->hDC,dis->rcItem.right - textSize.cx - xSave - 4,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszDateText,lstrlen(pItemData->pszDateText)); + } + } + + LeaveCriticalSection(&cs2); + SetBkMode(dis->hDC, OPAQUE); + SelectObject(dis->hDC, oldFont); + } else { + if(ServiceExists(MS_SKIN_DRAWGLYPH)) { + if(FrameIsFloating()) { + //SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background"); + } else { + //SkinDrawWindowBack(label, dis->hDC, &dis->rcItem, "Main Window/Backgrnd"); + SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background"); + } + } else { + //tcol = DBGetContactSettingDword(NULL,"CLC","BkColour", CLCDEFAULT_BKCOLOUR); + tcol = DBGetContactSettingDword(NULL, "WorldTime", "BgColour", GetSysColor(COLOR_3DFACE)); + SetBkColor(dis->hDC, tcol); + FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol))); + } + } + + if(ttbrush) DeleteObject(ttbrush); + } + return TRUE; + case WM_WTREFRESH: + { + bool need_repaint = false; + + SYSTEMTIME st, other_st; + HANDLE hIcon; + TCHAR buf[512], buf2[512]; + MyGetSystemTime(&st); + + EnterCriticalSection(&cs2); + for(ITEMLIST::iterator i = listbox_items.begin(); i != listbox_items.end(); i++) { + TIME_ZONE_INFORMATION tzi; + tzi.Bias = timezone_list[i->timezone_list_index].TZI.Bias; + tzi.DaylightBias = timezone_list[i->timezone_list_index].TZI.DaylightBias; + tzi.DaylightDate = timezone_list[i->timezone_list_index].TZI.DaylightDate; + tzi.StandardBias = timezone_list[i->timezone_list_index].TZI.StandardBias; + tzi.StandardDate = timezone_list[i->timezone_list_index].TZI.StandardDate; + + MySystemTimeToTzSpecificLocalTime(&tzi, &st, &other_st); + + if(set_format) { + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &other_st, format_string, buf, 512); + GetDateFormat(LOCALE_USER_DEFAULT, 0, &other_st, date_format_string, buf2, 512); + } else + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &other_st, 0, buf, 512); + + int risediff = minutes_diff(&other_st, &i->sunrise), + setdiff = minutes_diff(&other_st, &i->sunset); + if(risediff >= 0 && setdiff < 0) { + if(risediff < 30) + hIcon = riseIcon; + else + hIcon = upIcon; + } else { + if(setdiff > 0 && setdiff < 30) + hIcon = setIcon; + else + hIcon = downIcon; + } + + if(strcmp(buf, i->pszTimeText) || (set_format && strcmp(buf2, i->pszDateText)) || i->icon != hIcon) { + need_repaint = true; + strcpy(i->pszTimeText, buf); + if(set_format) strcpy(i->pszDateText, buf2); + else i->pszDateText[0] = '\0'; + i->icon = (HICON)hIcon; + } + } + LeaveCriticalSection(&cs2); + if(need_repaint) + InvalidateRect(label, 0, FALSE); + } + return TRUE; + case WM_CTLCOLORLISTBOX: + { + if(ServiceExists(MS_SKIN_DRAWGLYPH)) return 0; + + if(tbrush) DeleteObject(tbrush); + + return (BOOL)(tbrush = CreateSolidBrush((COLORREF)DBGetContactSettingDword(NULL,"WorldTime","BgColour", GetSysColor(COLOR_3DFACE)))); + } + break; + case WM_ERASEBKGND: + /* + { +// HDC hDC = (HDC)wParam; +// HBRUSH tempBrush = CreateSolidBrush((COLORREF)DBGetContactSettingDword(NULL,"CLC","BkColour", CLCDEFAULT_BKCOLOUR)); +// GetClientRect(hwnd, &r); +// FillRect(hDC, &r, tempBrush); +// DeleteObject(tempBrush); + + HDC hdc = GetDC(hwnd); + RECT r; + GetClientRect(hwnd, &r); + SkinDrawWindowBack(hwnd, hdc, &r, "Ping/Background"); + ReleaseDC(hwnd, hdc); + } + */ + //return DefWindowProc(hwnd, msg, wParam, lParam); + { + RECT r; + GetClientRect(hwnd, &r); + if(ServiceExists(MS_SKIN_DRAWGLYPH)) { + if(FrameIsFloating()) { + //SkinDrawGlyph((HDC)wParam, &r, &r, "Main Window/Backgrnd"); + SkinDrawGlyph((HDC)wParam, &r, &r, "World Time/Background"); + } else { + //SkinDrawWindowBack(label, (HDC)wParam, &r, "Main Window/Backgrnd"); + SkinDrawGlyph((HDC)wParam, &r, &r, "World Time/Background"); + } + } else { + FillRect((HDC)wParam, &r, tbrush); + } + } + return TRUE; + + + case WM_SYSCOLORCHANGE: + SendMessage(label,msg,wParam,lParam); + break; + + case WM_CREATE: + label=CreateWindow("LISTBOX", "", (WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_NOTIFY) & ~WS_BORDER, 0, 0, 0, 0, hwnd, NULL, hInst,0); + + oldListWindowProc = (WNDPROC)SetWindowLong(label, GWL_WNDPROC, (LONG)SubclassedListWindowProc); + + if (DBGetContactSettingByte(NULL,"CList","Transparent",0)) + { + if(ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { + + } else { + SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); + if (MySetLayeredWindowAttributes) MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_ALPHA_DEFAULT), LWA_ALPHA); + } + //if (MySetLayeredWindowAttributes) MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), 255, LWA_ALPHA); + } + return FALSE; + + case WMU_INITIALIZE: + { + //CreateWindow("button","button1",WS_VISIBLE|WS_CHILD ,120,4,60,22,hwnd,NULL,hInst,0); + //label=CreateWindow("LISTBOX", "", (WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_NOTIFY) & ~WS_BORDER, 2, 2, 120, 60, hwnd, NULL, hInst,0); + + //SetTimer(hwnd,TIMER_ID, 1000,plug1TimerProc); + SetTimer(hwnd,TIMER_ID2,1000,plug1TimerProc2); + SetTimer(hwnd,TIMER_ID3,1000,plug1TimerProc3); + + + + } + //PostMessage(hwnd, WM_WTREFRESH, 0, 0); + //PostMessage(hwnd, WM_SIZE, 0, 0); + PostMessage(hwnd, WMU_SIZELIST, 0, 0); + return TRUE; + + + case WM_ACTIVATE: + if(wParam==WA_INACTIVE) { + if((HWND)wParam!=hwnd) + if(DBGetContactSettingByte(NULL,"CList","Transparent",SETTING_TRANSPARENT_DEFAULT)) + if(transparentFocus) + SetTimer(hwnd, TM_AUTOALPHA,250,NULL); + } + else { + if(DBGetContactSettingByte(NULL,"CList","Transparent",SETTING_TRANSPARENT_DEFAULT)) { + KillTimer(hwnd,TM_AUTOALPHA); + if (MySetLayeredWindowAttributes) MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_ALPHA_DEFAULT), LWA_ALPHA); + transparentFocus=1; + } + } + break; + + case WM_SETCURSOR: + if(DBGetContactSettingByte(NULL,"CList","Transparent",SETTING_TRANSPARENT_DEFAULT)) { + if (!transparentFocus && GetForegroundWindow()!=hwnd && MySetLayeredWindowAttributes) { + MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_ALPHA_DEFAULT), LWA_ALPHA); + transparentFocus=1; + SetTimer(hwnd, TM_AUTOALPHA,250,NULL); + } + } + break; + + case WM_TIMER: + if ((int)wParam==TM_AUTOALPHA) + { int inwnd; + + if (GetForegroundWindow()==hwnd) { + KillTimer(hwnd,TM_AUTOALPHA); + inwnd=1; + } + else { + POINT pt; + HWND hwndPt; + pt.x=(short)LOWORD(GetMessagePos()); + pt.y=(short)HIWORD(GetMessagePos()); + hwndPt=WindowFromPoint(pt); + inwnd=(hwndPt==hwnd || GetParent(hwndPt)==hwnd); + } + if (inwnd!=transparentFocus && MySetLayeredWindowAttributes) + { //change + transparentFocus=inwnd; + if(transparentFocus) MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_ALPHA_DEFAULT), LWA_ALPHA); + else MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","AutoAlpha",SETTING_AUTOALPHA_DEFAULT), LWA_ALPHA); + } + if(!transparentFocus) KillTimer(hwnd,TM_AUTOALPHA); + } + return TRUE; + + case WM_SHOWWINDOW: + { static int noRecurse=0; + if(lParam) break; + if(noRecurse) break; + if(!DBGetContactSettingByte(NULL,"CLUI","FadeInOut",0) || !IsWinVer2000Plus()) break; + if(GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_LAYERED) { + DWORD thisTick,startTick; + int sourceAlpha,destAlpha; + if(wParam) { + sourceAlpha=0; + destAlpha=(BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_AUTOALPHA_DEFAULT); + MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), 0, LWA_ALPHA); + noRecurse=1; + ShowWindow(hwnd,SW_SHOW); + noRecurse=0; + } + else { + sourceAlpha=(BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_AUTOALPHA_DEFAULT); + destAlpha=0; + } + for(startTick=GetTickCount();;) { + thisTick=GetTickCount(); + if(thisTick>=startTick+200) break; + MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)(sourceAlpha+(destAlpha-sourceAlpha)*(int)(thisTick-startTick)/200), LWA_ALPHA); + } + MySetLayeredWindowAttributes(hwnd, RGB(0,0,0), (BYTE)destAlpha, LWA_ALPHA); + } + else { +// if(wParam) SetForegroundWindow(hwnd); + MyAnimateWindow(hwnd,200,AW_BLEND|(wParam?0:AW_HIDE)); + //SetWindowPos(label,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); + } + //int res = DefWindowProc(hwnd, msg, wParam, lParam); + //return res; + DBWriteContactSettingByte(NULL, "WorldTime", "WindowVisible", wParam ? 1 : 0); + + PostMessage(hwnd, WMU_SIZELIST, 0, 0); + InvalidateRect(hwnd, 0, TRUE); + break; + //return FALSE; //break; + } + + case WM_CONTEXTMENU: + { + OPENOPTIONSDIALOG ood; + ood.cbSize = sizeof(ood); + ood.pszGroup = Translate("Plugins"); + ood.pszPage = Translate("World Time"); + + CallService(MS_OPT_OPENOPTIONS, 0, (LPARAM)&ood); + } + return TRUE; + + case WM_RBUTTONDOWN: + //CallService(MS_CLIST_MENUBUILDFRAMECONTEXT, Frameid, 0); + break; + + + case WM_COMMAND: + if (HIWORD( wParam ) == LBN_DBLCLK) { + sel = SendMessage(label, LB_GETCURSEL, 0, 0); + if(sel != LB_ERR) { + lp = SendMessage(label, LB_GETITEMDATA, sel, 0); + if(lp != LB_ERR) { + pItemData = (LISTITEM *)lp; + + // ?? + } + } + } + break; + case WM_PRINTCLIENT: + { + /* + HDC hdc = (HDC)wParam; + RECT r; + GetClientRect(hwnd, &r); + */ + } + return TRUE; + + case WM_PAINT: + { + RECT r; + if(GetUpdateRect(hwnd, &r, FALSE)) { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hwnd, &ps); + SendMessage(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, (LPARAM)(PRF_CLIENT | PRF_CHILDREN)); + EndPaint(hwnd, &ps); + } + } + return TRUE; + + case WM_MOVE: // needed for docked frames in clist_mw (not needed in clist_modern) + if(FrameIsFloating()) + break; + case WM_SIZE: + //if(IsWindowVisible(hwnd)) + PostMessage(hwnd, WMU_SIZELIST, 0, 0); + break; + case WMU_SIZELIST: + + { + //PostMessage(label, WM_SIZE, wParam, lParam); + + GetClientRect(hwnd,&rect); + + { + //char buff[256]; + //sprintf(buff, "WMU_SIZELIST: width = %d, height = %d", rect.right - rect.left, rect.bottom - rect.top); + //PUShowMessage(buff, SM_NOTIFY); + + } + + int winheight = rect.bottom - rect.top, + itemheight = SendMessage(label, LB_GETITEMHEIGHT, 0, 0), + count = SendMessage(label, LB_GETCOUNT, 0, 0), + height = min(winheight - winheight % itemheight, itemheight * count); + SetWindowPos(label, 0, rect.left, rect.top, rect.right-rect.left, height, SWP_NOZORDER); + InvalidateRect(label, 0, FALSE); + //SetWindowPos(label, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER); + } + if(Frameid != -1) { + //CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)Frameid, (LPARAM)(FU_TBREDRAW | FU_FMREDRAW)); + CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)Frameid, (LPARAM)FU_TBREDRAW); + //CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)Frameid, (LPARAM)(FU_TBREDRAW | FU_FMREDRAW | FU_FMPOS)); + } + + InvalidateRect(hwnd, 0, TRUE); + return TRUE; + + + case WM_DESTROY: + if(tbrush) DeleteObject(tbrush); + + if(!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { + GetWindowRect(hwnd, &r); + + DBWriteContactSettingDword(NULL, "WorldTime", "WindowX", r.left); + DBWriteContactSettingDword(NULL, "WorldTime", "WindowY", r.top); + DBWriteContactSettingDword(NULL, "WorldTime", "WindowWidth", r.right - r.left); + DBWriteContactSettingDword(NULL, "WorldTime", "WindowHeight", r.bottom - r.top); + } + + { + KillTimer(hwnd,TIMER_ID); + KillTimer(hwnd,TIMER_ID2); + } + DestroyWindow(label); + + break; + + case WM_CLOSE: + if(!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { + if(!hook_window_behaviour_to_clist) + ShowWindow(hwnd, SW_HIDE); + return TRUE; + } + break; + + }; + + return DefWindowProc(hwnd, msg, wParam, lParam); +}; + +int FillList(WPARAM wParam, LPARAM lParam) { + + SendMessage(label, LB_RESETCONTENT, 0, 0); + + EnterCriticalSection(&cs2); + + for(ITEMLIST::iterator i = listbox_items.begin(); i != listbox_items.end(); i++) { + SendMessage(label, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)i->pszText); + } + + LeaveCriticalSection(&cs2); + + InvalidateRect(label, 0, TRUE); + return 0; +} + +static int PlugShowWindow(WPARAM wParam, LPARAM lParam) { + if(pluginwind && !hook_window_behaviour_to_clist) { + ShowWindow(pluginwind, IsWindowVisible(pluginwind) ? SW_HIDE : SW_SHOW); + DBWriteContactSettingByte(NULL, "WorldTime", "WindowVisible", IsWindowVisible(pluginwind) ? 1 : 0); + } + return 0; +} + +int InitIcons(WPARAM wParam, LPARAM lParam) { + if(ServiceExists(MS_SKIN2_ADDICON)) { + SKINICONDESC2 sid; + + sid.cbSize = sizeof(SKINICONDESC2); + sid.pszSection = "WorldTime"; + + sid.pszDescription = Translate("Day"); + sid.pszName = "WorldTime_day"; + sid.pszDefaultFile = "WorldTime.dll"; + sid.iDefaultIndex = IDI_ICON_SUN; + sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = Translate("Night"); + sid.pszName = "WorldTime_night"; + sid.pszDefaultFile = "WorldTime.dll"; + sid.iDefaultIndex = IDI_ICON_MOON; + sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = Translate("Sunrise"); + sid.pszName = "WorldTime_sunrise"; + sid.pszDefaultFile = "WorldTime.dll"; + sid.iDefaultIndex = IDI_ICON_SUNRISE; + sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUNRISE), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + sid.pszDescription = Translate("Sunset"); + sid.pszName = "WorldTime_sunset"; + sid.pszDefaultFile = "WorldTime.dll"; + sid.iDefaultIndex = IDI_ICON_SUNSET; + sid.hDefaultIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUNSET), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid); + + upIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_day"); + downIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_night"); + riseIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunrise"); + setIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunset"); + } else { + upIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + downIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + riseIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SUN), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + setIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_MOON), IMAGE_ICON, 16, 16, 0);//LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS ); + } + return 0; +} + +int ReloadIcons(WPARAM wParam, LPARAM lParam) { + upIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_day"); + downIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_night"); + riseIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunrise"); + setIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"WorldTime_sunset"); + return 0; +} + +void load_listbox_items() { + int num = DBGetContactSettingDword(0, "WorldTime", "NumEntries", 0); + for(int i = 0; i < num; i++) { + LISTITEM li = {0}; + std::ostringstream p1, p2, p3, p4; + + p1 << "Label" << i; + p2 << "Index" << i; + p3 << "Sunrise" << i; + p4 << "Sunset" << i; + + DBVARIANT dbv; + DBGetContactSetting(0, "WorldTime", p1.str().c_str(), &dbv); + strncpy(li.pszText, dbv.pszVal, MAX_NAME_LENGTH); + DBFreeVariant(&dbv); + + li.timezone_list_index = (int)DBGetContactSettingDword(0, "WorldTime", p2.str().c_str(), 0); + + GetSystemTime(&li.sunrise); + GetSystemTime(&li.sunset); + + int sunrise_min = (int)DBGetContactSettingDword(0, "WorldTime", p3.str().c_str(), 360), // 60 * 6 (6 am) = 360 + sunset_min = (int)DBGetContactSettingDword(0, "WorldTime", p4.str().c_str(), 1080); // 60 * 18 (6 pm) = 1080 + + li.sunrise.wHour = sunrise_min / 60; + li.sunrise.wMinute = sunrise_min % 60; + li.sunrise.wSecond = 0; + li.sunset.wHour = sunset_min / 60; + li.sunset.wMinute = sunset_min % 60; + li.sunset.wSecond = 0; + + li.pszTimeText[0] = '\0'; + li.pszDateText[0] = '\0'; + li.icon = upIcon; + + listbox_items.push_back(li); + } +} + +static int DBSettingChange(WPARAM wParam, LPARAM lParam) { + if(pluginwind && (HANDLE)wParam == NULL) { + DBCONTACTWRITESETTING *db_write = (DBCONTACTWRITESETTING *)lParam; + if(hook_window_behaviour_to_clist) { + if(!strcmp("CList", db_write->szModule)) { + if(!strcmp("State", db_write->szSetting)) { + // contact list setting change + BYTE state = db_write->value.bVal; + + if(state == SETTING_STATE_NORMAL) + ShowWindow(pluginwind, SW_SHOW); + else + ShowWindow(pluginwind, SW_HIDE); + } else if(!strcmp("Transparent", db_write->szSetting)) { + if(db_write->value.bVal) { + SetWindowLong(pluginwind, GWL_EXSTYLE, GetWindowLong(pluginwind, GWL_EXSTYLE) | WS_EX_LAYERED); + if (MySetLayeredWindowAttributes) MySetLayeredWindowAttributes(pluginwind, RGB(0,0,0), (BYTE)DBGetContactSettingByte(NULL,"CList","Alpha",SETTING_ALPHA_DEFAULT), LWA_ALPHA); + } else { + SetWindowLong(pluginwind, GWL_EXSTYLE, GetWindowLong(pluginwind, GWL_EXSTYLE) & ~WS_EX_LAYERED); + } + } else if(!strcmp("Alpha", db_write->szSetting)) { + ShowWindow(pluginwind, IsWindowVisible(pluginwind) ? SW_SHOW : SW_HIDE); + } else if(!strcmp("AutoAlpha", db_write->szSetting)) { + ShowWindow(pluginwind, IsWindowVisible(pluginwind) ? SW_SHOW : SW_HIDE); + } + } + } + + if(db_write && !strcmp("CLC", db_write->szModule) && !strncmp("Font", db_write->szSetting, 4)) { + DeleteObject(ContactFont); + ContactFont = (HFONT)GetFont(); + InvalidateRect(label, 0, FALSE); + } + } + + return 0; +} + +int RefreshWindow(WPARAM wParam, LPARAM lParam) { + //InvalidateRect(hpwnd, 0, TRUE); + InvalidateRect(label, 0, TRUE); + return 0; +} + +int SkinReload(WPARAM wParam, LPARAM lParam) { + CreateGlyphedObjectDefColor("World Time/Background", DBGetContactSettingDword(NULL, "WorldTime", "BgColour", GetSysColor(COLOR_3DFACE))); + CreateGlyphedObjectDefColor("World Time/Selection Background", DBGetContactSettingDword(NULL, "CLC", "SelBkColour", CLCDEFAULT_SELBKCOLOUR)); + RefreshWindow(0, 0); + return 0; +} + +int addmypluginwindow1(HWND parent) +{ + if(ServiceExists(MS_FONT_REGISTER)) { + font_id.cbSize = sizeof(FontID); + strncpy(font_id.group, "Frames", sizeof(font_id.group)); + strncpy(font_id.name, "World Time", sizeof(font_id.name)); + strncpy(font_id.dbSettingsGroup, "WorldTime", sizeof(font_id.dbSettingsGroup)); + strncpy(font_id.prefix, "Font", sizeof(font_id.prefix)); + font_id.order = 0; + + CallService(MS_FONT_REGISTER, (WPARAM)&font_id, 0); + HookEvent(ME_FONT_RELOAD, ReloadFont); + } + + if(ServiceExists(MS_SKIN_REGISTERDEFOBJECT)) { + SkinReload(0, 0); + HookEvent(ME_SKIN_SERVICESCREATED, SkinReload); + } + + hUserDll = LoadLibrary("user32.dll"); + if (hUserDll) { + MySetLayeredWindowAttributes = (BOOL (WINAPI *)(HWND,COLORREF,BYTE,DWORD))GetProcAddress(hUserDll, "SetLayeredWindowAttributes"); + MyAnimateWindow=(BOOL (WINAPI*)(HWND,DWORD,DWORD))GetProcAddress(hUserDll,"AnimateWindow"); + } + + hwnd_clist = parent; + + InitializeCriticalSection(&cs2); + + hook_window_behaviour_to_clist = (DBGetContactSettingByte(NULL, "WorldTime", "MinMax", DEFAULT_MINMAX ? 1 : 0) == 1); + set_format = (DBGetContactSettingByte(NULL, "WorldTime", "EnableTimeFormat", 0) == 1); + show_icons = (DBGetContactSettingByte(NULL, "WorldTime", "ShowIcons", 1) == 1); + hide_menu = (DBGetContactSettingByte(NULL, "WorldTime", "HideMenu", 0) == 1); + DBVARIANT dbv; + if(!DBGetContactSetting(NULL, "WorldTime", "TimeFormat", &dbv)) { + strncpy(format_string, dbv.pszVal, 512); + } + DBFreeVariant(&dbv); + if(!DBGetContactSetting(NULL, "WorldTime", "DateFormat", &dbv)) { + strncpy(date_format_string, dbv.pszVal, 512); + } + DBFreeVariant(&dbv); + + WNDCLASS wndclass; + int font; + + InitIcons(0, 0); + if(ServiceExists(MS_SKIN2_ADDICON)) { + hIcoLibIconsChanged = HookEvent(ME_SKIN2_ICONSCHANGED, ReloadIcons); + } + + load_listbox_items(); + + //hIconsChangedEvent = HookEvent(ME_SKIN_ICONSCHANGED, LoadIcons); + hDBChange = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChange); + + wndclass.style = 0; + wndclass.lpfnWndProc = mypluginwindow1proc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInst; + wndclass.hIcon = NULL; + wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = PLUG; + RegisterClass(&wndclass); + + if(ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { + pluginwind=CreateWindow(PLUG,Translate("World Time"), + WS_BORDER|WS_CHILD|WS_CLIPCHILDREN, + 0,0,0,0,parent,NULL,hInst,NULL); + + CLISTFrame Frame = {0}; + Frame.name=PLUG; + Frame.cbSize=sizeof(CLISTFrame); + Frame.hWnd=pluginwind; + Frame.align=alBottom; + Frame.Flags=F_VISIBLE|F_SHOWTB|F_SHOWTBTIP; + Frame.height=30; + Frame.TBname = Translate("World Time"); + + Frameid=CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&Frame,0); + + } else { + CreateServiceFunction("WorldTime/ShowWindow", PlugShowWindow); + + int x, y, width, height; + bool visible; + + x = (int)DBGetContactSettingDword(NULL, "WorldTime", "WindowX", DEFAULT_WINDOW_X); + y = (int)DBGetContactSettingDword(NULL, "WorldTime", "WindowY", DEFAULT_WINDOW_Y); + width = (int)DBGetContactSettingDword(NULL, "WorldTime", "WindowWidth", DEFAULT_WINDOW_WIDTH); + height = (int)DBGetContactSettingDword(NULL, "WorldTime", "WindowHeight", DEFAULT_WINDOW_HEIGHT); + + + if(hook_window_behaviour_to_clist) { + visible = (DBGetContactSettingByte(NULL, "CList", "State", SETTING_STATE_NORMAL) == SETTING_STATE_NORMAL); + } else { + visible = ((int)DBGetContactSettingByte(NULL, "WorldTime", "WindowVisible", 1) == 1); + } + + pluginwind=CreateWindowEx(WS_EX_TOOLWINDOW, PLUG,Translate("World Time"), + WS_POPUPWINDOW | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | (visible ? WS_VISIBLE : 0) | WS_CLIPCHILDREN, + x,y,width,height,parent,NULL,hInst,NULL); + + if(!hide_menu) { + CLISTMENUITEM mi; + memset( &mi, 0, sizeof( mi )); + mi.flags = 0; + mi.popupPosition = 0; + mi.pszPopupName = NULL; + mi.cbSize = sizeof( mi ); + mi.position = 2000400000; + mi.hIcon = 0;//LoadIcon( hInst, 0); + mi.pszName = Translate( "*Hide/Show &World Time Window" ); + mi.pszService = "WorldTime/ShowWindow"; + mainMenuItem = (HANDLE)CallService( MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM)&mi ); + } + } + + + font=SendMessage(parent,WM_GETFONT,0,0); + SendMessage(pluginwind,WM_SETFONT,font,0); + + TitleBarFont = (HFONT)CLUILoadTitleBarFont(); + ContactFont = (HFONT)GetFont(); + + SendMessage(label,WM_SETFONT,(WPARAM)TitleBarFont,0); + + FillList(0, 0); + + SendMessage(pluginwind, WMU_INITIALIZE, 0, 0); + + return 0; + +}; + +// popup support + +LRESULT CALLBACK NullWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) +{ + switch( message ) { + case WM_COMMAND: { + PUDeletePopUp( hWnd ); + break; + } + + case WM_CONTEXTMENU: + PUDeletePopUp( hWnd ); + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); +} + +void CALLBACK sttMainThreadCallback( ULONG dwParam ) +{ + POPUPDATAEX* ppd = ( POPUPDATAEX* )dwParam; + + if ( ServiceExists(MS_POPUP_ADDPOPUPEX) ) + CallService( MS_POPUP_ADDPOPUPEX, ( WPARAM )ppd, 0 ); + else + if ( ServiceExists(MS_POPUP_ADDPOPUP) ) + CallService( MS_POPUP_ADDPOPUP, ( WPARAM )ppd, 0 ); + + free( ppd ); +} + +void __stdcall ShowPopup( const char* line1, const char* line2, int flags ) +{ + if ( !ServiceExists( MS_POPUP_ADDPOPUP )) { + MessageBox( NULL, line2, Translate("World Time"), MB_OK | MB_ICONINFORMATION ); + return; + } + + POPUPDATAEX* ppd = ( POPUPDATAEX* )calloc( sizeof( POPUPDATAEX ), 1 ); + + ppd->lchContact = NULL; + ppd->lchIcon = 0; + strcpy( ppd->lpzContactName, line1 ); + strcpy( ppd->lpzText, line2 ); + + ppd->colorBack = GetSysColor( COLOR_BTNFACE ); + ppd->colorText = GetSysColor( COLOR_WINDOWTEXT ); + ppd->iSeconds = 10; + + ppd->PluginWindowProc = ( WNDPROC )NullWindowProc; + ppd->PluginData = NULL; + + QueueUserAPC( sttMainThreadCallback , mainThread, ( ULONG )ppd ); +} + +void plugwin_cleanup() { + UnhookEvent(hIcoLibIconsChanged); + if(hIconsChangedEvent) UnhookEvent(hIconsChangedEvent); + + UnhookEvent(hDBChange); + + //KillTimer(pluginwind, TIMER_ID2); + DestroyWindow(pluginwind); + + DeleteCriticalSection(&cs2); + + DeleteObject(ContactFont); + DestroyIcon((HICON)upIcon); + DestroyIcon((HICON)upIcon); + DestroyIcon((HICON)riseIcon); + DestroyIcon((HICON)setIcon); +} \ No newline at end of file diff --git a/worldtime/plugwin.h b/worldtime/plugwin.h new file mode 100644 index 0000000..0e83d96 --- /dev/null +++ b/worldtime/plugwin.h @@ -0,0 +1,113 @@ +#ifndef _PLUGWIN +#define _PLUGWIN + +#define TIMER_ID 19191 +#define TIMER_ID2 19192 +#define TIMER_ID3 19193 + +#include "timezone.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "../mwclist/m_clist.h" +#include +#include +//#include "../mwclist/m_clc.h" +#include +#include +#include + + +#include "IcoLib.h" + +#include + +#include "resource.h" + +#include "time_convert.h" + +#define PLUG "WorldTime" + +#define DEFAULT_MINMAX false + +#define DEFAULT_WINDOW_X 100 +#define DEFAULT_WINDOW_Y 100 +#define DEFAULT_WINDOW_WIDTH 200 +#define DEFAULT_WINDOW_HEIGHT 100 + +#define MAX_NAME_LENGTH 256 +#define MAX_TIME_LENGTH 256 + +typedef struct tagLISTITEM { + int cbSize; + char pszText[MAX_NAME_LENGTH]; + int timezone_list_index; + SYSTEMTIME sunset; + SYSTEMTIME sunrise; + char pszTimeText[MAX_NAME_LENGTH]; + char pszDateText[MAX_NAME_LENGTH]; + HICON icon; +} LISTITEM; + +#include +typedef std::vector ITEMLIST; + +extern HICON upIcon, downIcon; + +extern ITEMLIST listbox_items; + +extern HANDLE mainThread; + +extern char format_string[]; + +int addmypluginwindow1(HWND parent); +void plugwin_cleanup(); + + +int WorldTimeOptInit(WPARAM wParam,LPARAM lParam); +void __stdcall ShowPopup( const char* line1, const char* line2, int flags ); + +#define WinVerMajor() LOBYTE(LOWORD(GetVersion())) +#define WinVerMinor() HIBYTE(LOWORD(GetVersion())) +#define IsWinVer2000Plus() (WinVerMajor()>=5) + +#define CLCDEFAULT_BKCOLOUR GetSysColor(COLOR_3DFACE) +#define CLCDEFAULT_SELBKCOLOUR GetSysColor(COLOR_HIGHLIGHT) +#define CLCDEFAULT_SELTEXTCOLOUR GetSysColor(COLOR_HIGHLIGHTTEXT) +#define CLCDEFAULT_TEXTCOLOUR GetSysColor(COLOR_WINDOWTEXT) + +int InitIcons(WPARAM wParam, LPARAM lParam); +int LoadIcons(WPARAM wParam, LPARAM lParam); + +extern HINSTANCE hInst; + +extern ITEMLIST listbox_items; + +extern TCHAR format_string[512], date_format_string[512]; + +extern HWND pluginwind, hwnd_clist; + +extern bool hook_window_behaviour_to_clist; +extern bool set_format; +extern bool show_icons; +extern bool hide_menu; + +extern HFONT ContactFont; +extern COLORREF ContactFontColour; + +HFONT GetFont(); + +int FillList(WPARAM wParam, LPARAM lParam); + + + +#endif diff --git a/worldtime/resource.h b/worldtime/resource.h new file mode 100644 index 0000000..e061f35 --- /dev/null +++ b/worldtime/resource.h @@ -0,0 +1,64 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by WorldTime.rc +// +#define IDD_DIALOG1 101 +#define IDI_ICON_SUN 104 +#define IDI_ICON_MOON 105 +#define IDR_CONTEXT 111 +#define IDD_DIALOG2 112 +#define IDI_ICON_SUNSET 117 +#define IDI_ICON_SUNRISE 119 +#define IDC_PPM 1001 +#define IDC_PT 1002 +#define IDC_CHECK1 1005 +#define IDC_CHECKPOPUP 1005 +#define IDC_CHK_FORMAT 1005 +#define IDC_BUTTONEDIT 1006 +#define IDC_CHK_ICONS 1006 +#define IDC_BUTTONRELOAD 1007 +#define IDC_CHK_LOG 1008 +#define IDC_ED_FILENAME 1009 +#define IDC_CHECKPOPUP2 1010 +#define IDC_CHK_MINMAX 1011 +#define IDC_CHK_BLOCK 1012 +#define IDC_LIST_TIMES 1012 +#define IDC_ED_DISP 1013 +#define IDC_ED_LABEL 1014 +#define IDC_BTN_ADD 1015 +#define IDC_LIST_TIMES2 1016 +#define IDC_BTN_REM 1017 +#define IDC_RAD_ALPHA 1018 +#define IDC_BTN_EDIT 1018 +#define IDC_RAD_GEO 1019 +#define IDC_ED_FORMAT 1020 +#define IDC_ED_DATE_FORMAT 1021 +#define IDC_BTN_UP 1022 +#define IDC_BTN_DOWN 1023 +#define IDC_CHK_HIDEMENU 1024 +#define IDC_BTN_SHOW 1025 +#define IDC_ED_FSIZE 1026 +#define IDC_SPIN1 1029 +#define IDC_TEXTCOL 1030 +#define IDC_BGCOL 1031 +#define IDC_STATFS 1032 +#define IDC_STATICH 1033 +#define IDC_STATICH2 1034 +#define IDC_EDIT1 1035 +#define IDC_SP_INDENT 1037 +#define IDC_EDIT2 1038 +#define IDC_SP_ROWHEIGHT 1040 +#define IDC_TIME_SUNRISE 1041 +#define IDC_TIME_SUNSET 1042 +#define POPUP_TESTING 40001 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 121 +#define _APS_NEXT_COMMAND_VALUE 40002 +#define _APS_NEXT_CONTROL_VALUE 1042 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/worldtime/sunrise.ico b/worldtime/sunrise.ico new file mode 100644 index 0000000..2158bc0 Binary files /dev/null and b/worldtime/sunrise.ico differ diff --git a/worldtime/sunset.ico b/worldtime/sunset.ico new file mode 100644 index 0000000..f141da6 Binary files /dev/null and b/worldtime/sunset.ico differ diff --git a/worldtime/time_convert.cpp b/worldtime/time_convert.cpp new file mode 100644 index 0000000..bfd2781 --- /dev/null +++ b/worldtime/time_convert.cpp @@ -0,0 +1,209 @@ +#include "common.h" +#include "time_convert.h" + +void ConvertToAbsolute (const SYSTEMTIME * pstLoc, const SYSTEMTIME * pstDst, SYSTEMTIME * pstDstAbs) +{ + static int iDays [12] = { 31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31 } ; + int iDay ; + + // Set up the aboluste date structure except for wDay, which we must find + + pstDstAbs->wYear = pstLoc->wYear ; // Notice from local date/time + pstDstAbs->wMonth = pstDst->wMonth ; + pstDstAbs->wDayOfWeek = pstDst->wDayOfWeek ; + + pstDstAbs->wHour = pstDst->wHour ; + pstDstAbs->wMinute = pstDst->wMinute ; + pstDstAbs->wSecond = pstDst->wSecond ; + pstDstAbs->wMilliseconds = pstDst->wMilliseconds ; + + // Fix the iDays array for leap years + + if ((pstLoc->wYear % 4 == 0) && ((pstLoc->wYear % 100 != 0) || + (pstLoc->wYear % 400 == 0))) + { + iDays[1] = 29 ; + } + + // Find a day of the month that falls on the same + // day of the week as the transition. + + // Suppose today is the 20th of the month (pstLoc->wDay = 20) + // Suppose today is a Wednesday (pstLoc->wDayOfWeek = 3) + // Suppose the transition occurs on a Friday (pstDst->wDayOfWeek = 5) + // Then iDay = 31, meaning that the 31st falls on a Friday + // (The 7 is this formula avoids negatives.) + + iDay = pstLoc->wDay + pstDst->wDayOfWeek + 7 - pstLoc->wDayOfWeek ; + + // Now shrink iDay to a value between 1 and 7. + + iDay = (iDay - 1) % 7 + 1 ; + + // Now iDay is a day of the month ranging from 1 to 7. + // Recall that the wDay field of the structure can range + // from 1 to 5, 1 meaning "first", 2 meaning "second", + // and 5 meaning "last". + // So, increase iDay so it's the proper day of the month. + + iDay += 7 * (pstDst->wDay - 1) ; + + // Could be that iDay overshot the end of the month, so + // fix it up using the number of days in each month + + if (iDay > iDays[pstDst->wMonth - 1]) + iDay -= 7 ; + + // Assign that day to the structure. + + pstDstAbs->wDay = iDay ; +} + +BOOL LocalGreaterThanTransition (const SYSTEMTIME * pstLoc, const SYSTEMTIME * pstTran) +{ + FILETIME ftLoc, ftTran ; + LARGE_INTEGER liLoc, liTran ; + SYSTEMTIME stTranAbs ; + + // Easy case: Just compare the two months + + if (pstLoc->wMonth != pstTran->wMonth) + return (pstLoc->wMonth > pstTran->wMonth) ; + + // Well, we're in a transition month. That requires a bit more work. + + // Check if pstDst is in absolute or day-in-month format. + // (See documentation of TIME_ZONE_INFORMATION, StandardDate field.) + + if (pstTran->wYear) // absolute format (haven't seen one yet!) + { + stTranAbs = * pstTran ; + } + else // day-in-month format + { + ConvertToAbsolute (pstLoc, pstTran, &stTranAbs) ; + } + + // Now convert both date/time structures to large integers & compare + + SystemTimeToFileTime (pstLoc, &ftLoc) ; + liLoc = * (LARGE_INTEGER *) (void *) &ftLoc ; + + SystemTimeToFileTime (&stTranAbs, &ftTran) ; + liTran = * (LARGE_INTEGER *) (void *) &ftTran ; + + return (liLoc.QuadPart > liTran.QuadPart) ; +} + +BOOL MySystemTimeToTzSpecificLocalTime(const TIME_ZONE_INFORMATION *ptzi, const SYSTEMTIME *pstUtc, SYSTEMTIME *pstLoc) { + // st is UTC + + FILETIME ft ; + LARGE_INTEGER li ; + SYSTEMTIME stDst ; + + // If we're running under NT, just call the real function + + if (!(0x80000000 & GetVersion())) + return SystemTimeToTzSpecificLocalTime ((TIME_ZONE_INFORMATION *) ptzi, (SYSTEMTIME *) pstUtc, pstLoc) ; + + // Convert time to a LARGE_INTEGER and subtract the bias + + SystemTimeToFileTime (pstUtc, &ft) ; + li = * (LARGE_INTEGER *) (void *) &ft; + li.QuadPart -= (LONGLONG) 600000000 * ptzi->Bias ; + + // Convert to a local date/time before application of daylight saving time. + // The local date/time must be used to determine when the conversion occurs. + + ft = * (FILETIME *) (void *) &li ; + FileTimeToSystemTime (&ft, pstLoc) ; + + // Find the time assuming Daylight Saving Time + + li.QuadPart -= (LONGLONG) 600000000 * ptzi->DaylightBias ; + ft = * (FILETIME *) (void *) &li ; + FileTimeToSystemTime (&ft, &stDst) ; + + // Now put li back the way it was + + li.QuadPart += (LONGLONG) 600000000 * ptzi->DaylightBias ; + + if (ptzi->StandardDate.wMonth) // ie, daylight savings time + { + // Northern hemisphere + + if ((ptzi->DaylightDate.wMonth < ptzi->StandardDate.wMonth) && + + (stDst.wMonth >= pstLoc->wMonth) && // avoid the end of year problem + + LocalGreaterThanTransition (pstLoc, &ptzi->DaylightDate) && + !LocalGreaterThanTransition (&stDst, &ptzi->StandardDate)) + { + li.QuadPart -= (LONGLONG) 600000000 * ptzi->DaylightBias ; + } + // Southern hemisphere + + else if ((ptzi->StandardDate.wMonth < ptzi->DaylightDate.wMonth) && + (!LocalGreaterThanTransition (&stDst, &ptzi->StandardDate) || + LocalGreaterThanTransition (pstLoc, &ptzi->DaylightDate))) + { + li.QuadPart -= (LONGLONG) 600000000 * ptzi->DaylightBias ; + } + else + { + li.QuadPart -= (LONGLONG) 600000000 * ptzi->StandardBias ; + } + } + + ft = * (FILETIME *) (void *) &li ; + FileTimeToSystemTime (&ft, pstLoc) ; + return TRUE ; +} + +VOID MyGetSystemTime(LPSYSTEMTIME lpSystemTime) { + //TIME_ZONE_INFORMATION tzi; + //FILETIME ft; + //LARGE_INTEGER li; + + GetSystemTime(lpSystemTime); + //GetTimeZoneInformation(&tzi); + + /* + // the following corrects for the condition that occurs when 'automatically adjust for daylight savings' is off, but + // local timezone info says it is daylight savings time... + // it assumes that the timezone has not been adjusted but the time has instead - resulting in wrong GMT in the system clock + + if(tzi.StandardDate.wMonth != 0 && tzi.DaylightBias == 0 && tzi.StandardBias == 0) { + // Northern hemisphere + if ((tzi.DaylightDate.wMonth < tzi.StandardDate.wMonth) && + + LocalGreaterThanTransition (lpSystemTime, &tzi.DaylightDate) && + !LocalGreaterThanTransition (lpSystemTime, &tzi.StandardDate)) + { + // add one hour to the system time + SystemTimeToFileTime(lpSystemTime, &ft); + li = * (LARGE_INTEGER *) (void *) &ft; + li.QuadPart += (LONGLONG) 600000000 * 60; + ft = * (FILETIME *) (void *) &li ; + FileTimeToSystemTime(&ft, lpSystemTime); + } + // Southern hemisphere + + else if ((tzi.StandardDate.wMonth < tzi.DaylightDate.wMonth) && + (!LocalGreaterThanTransition (lpSystemTime, &tzi.StandardDate) || + LocalGreaterThanTransition (lpSystemTime, &tzi.DaylightDate))) + { + // add one hour to the system time + SystemTimeToFileTime(lpSystemTime, &ft); + li = * (LARGE_INTEGER *) (void *) &ft; + li.QuadPart += (LONGLONG) 600000000 * 60; + ft = * (FILETIME *) (void *) &li ; + FileTimeToSystemTime(&ft, lpSystemTime); + } + + } + */ +} + diff --git a/worldtime/time_convert.h b/worldtime/time_convert.h new file mode 100644 index 0000000..33cd927 --- /dev/null +++ b/worldtime/time_convert.h @@ -0,0 +1,32 @@ +#ifndef _TIME_CONVERT_H +#define _TIME_CONVERT_H + +/* + + from http://cvs.sourceforge.net/viewcvs.py/tortoisecvs/TortoiseCVS/src/Utils/Attic/ClockRackCon.c?view=markup + (GPL) + +---------------------------------------------------------------- + ClockRackCon.c -- Time-zone time conversion for ClockRack 1.1 + (c) Ziff Davis Media, Inc. + All rights reserved. + + First published in PC Magazine, US edition, September 1, 2000. + + Programmed by Charles Petzold. + + The entire function of this module is to implement the + MySystemTimeToTzSpecificLocalTime all because Windows 95 & 98 + do not implement the NT function SystemTimeToTzSpecificLocalTime. + --------------------------------------------------------------------- + + +*/ + +BOOL LocalGreaterThanTransition (const SYSTEMTIME * pstLoc, const SYSTEMTIME * pstTran); + +BOOL MySystemTimeToTzSpecificLocalTime(const TIME_ZONE_INFORMATION *pTZI, const SYSTEMTIME *st, SYSTEMTIME *other_st); + +VOID MyGetSystemTime(LPSYSTEMTIME lpSystemTime); + +#endif \ No newline at end of file diff --git a/worldtime/timezone.cpp b/worldtime/timezone.cpp new file mode 100644 index 0000000..ee4a8ed --- /dev/null +++ b/worldtime/timezone.cpp @@ -0,0 +1,70 @@ +#include "common.h" +#include "timezone.h" + +TimeList timezone_list, geo_timezone_list; + +bool LS_TZREG::operator<(const LS_TZREG &other) { + //return Index < other.Index; + return TZI.Bias < other.TZI.Bias; +} + +bool build_timezone_list() { + HKEY HKlmtz; + HKEY KKtz; + DWORD dwIndex = 0; + CHAR tcName[MAX_SIZE]; + DWORD dwcbName = MAX_SIZE; + DWORD dwcbValue; + DWORD dwcbSTD; + DWORD dwcbDLT; + LS_TZREG Temp; + FILETIME ftLastWrite; + unsigned int list_index = 0; + bool win9x = false; + + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TZREG, 0, KEY_ENUMERATE_SUB_KEYS, &HKlmtz) != ERROR_SUCCESS) { + win9x = true; + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TZREG_9X, 0, KEY_ENUMERATE_SUB_KEYS, &HKlmtz) != ERROR_SUCCESS) + return false; + } + + while(RegEnumKeyEx(HKlmtz, dwIndex++, tcName, &dwcbName, NULL, NULL, NULL, &ftLastWrite) != ERROR_NO_MORE_ITEMS) { + + if(RegOpenKeyEx(HKlmtz, tcName, 0,KEY_QUERY_VALUE, &KKtz) != ERROR_SUCCESS) { + RegCloseKey(HKlmtz); + return false; + } + + strncpy(Temp.tcName, tcName, MAX_SIZE); + dwcbValue = MAX_SIZE; + RegQueryValueEx(KKtz,"Display",NULL,NULL,(BYTE*)Temp.tcDisp,&dwcbValue); + dwcbDLT = MAX_SIZE; + RegQueryValueEx(KKtz,"Dlt",NULL,NULL,(BYTE*)Temp.tcDLT,&dwcbDLT); + dwcbSTD = MAX_SIZE; + RegQueryValueEx(KKtz,"Std",NULL,NULL,(BYTE*)Temp.tcSTD,&dwcbSTD); + dwcbValue = MAX_SIZE; + RegQueryValueEx(KKtz,"MapID",NULL,NULL,(BYTE*)Temp.MapID,&dwcbValue); + if(!win9x) { + dwcbValue = sizeof(DWORD); + RegQueryValueEx(KKtz,"Index",NULL,NULL,(BYTE*)&Temp.Index,&dwcbValue); + } + dwcbValue = sizeof(Temp.TZI); + RegQueryValueEx(KKtz,"TZI",NULL,NULL,(BYTE*)&Temp.TZI,&dwcbValue); + + RegCloseKey(KKtz); + + Temp.list_index = list_index; + timezone_list.push_back(Temp); + + dwcbName = MAX_SIZE; + list_index++; + } + + RegCloseKey(HKlmtz); + + geo_timezone_list = timezone_list; + std::sort(geo_timezone_list.begin(), geo_timezone_list.end()); + + return true; +} + diff --git a/worldtime/timezone.h b/worldtime/timezone.h new file mode 100644 index 0000000..0770976 --- /dev/null +++ b/worldtime/timezone.h @@ -0,0 +1,44 @@ +#ifndef _TIMEZONE_H +#define _TIMEZONE_H + +#define TZREG "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" +#define TZREG_9X "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones" +//#define TZREG2 "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation" +#define MAX_SIZE 512 + +#include +#include + +struct REG_TZI { + long Bias; + long StandardBias; + long DaylightBias; + SYSTEMTIME StandardDate; + SYSTEMTIME DaylightDate; +}; + + +struct LS_TZREG { + TCHAR tcName[MAX_SIZE]; + TCHAR tcDisp[MAX_SIZE]; + TCHAR tcDLT[MAX_SIZE]; + TCHAR tcSTD[MAX_SIZE]; + TCHAR MapID[MAX_SIZE]; + DWORD Index; + DWORD ActiveTimeBias; + //TIME_ZONE_INFORMATION TZI; + REG_TZI TZI; + + unsigned int list_index; + + bool operator<(const LS_TZREG &other); +}; + +typedef std::vector< LS_TZREG > TimeList; + +extern TimeList timezone_list, geo_timezone_list; +bool build_timezone_list(); + +void convert_regdata_to_tzi(int vector_index); + +#endif -- cgit v1.2.3