diff options
author | George Hazan <ghazan@miranda.im> | 2022-07-30 15:08:07 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-07-30 15:08:07 +0300 |
commit | e743df09941ad6cf44c81b2bcfbc3396f0fc349c (patch) | |
tree | cf73fa49ad828f1e2f5ef6f62fdd79959948da0b /plugins | |
parent | 6462995d9bef854b9a04cc3e794fefcbf2fa2096 (diff) |
WWI:
- options moved to UI classes;
- global variables -> CMOption<>;
- code cleaning;
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/WhenWasIt/WhenWasIt.vcxproj | 1 | ||||
-rw-r--r-- | plugins/WhenWasIt/WhenWasIt.vcxproj.filters | 3 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/WhenWasIt.cpp | 24 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/dlg_handlers.cpp | 362 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/dlg_handlers.h | 3 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/hooked_events.cpp | 25 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/notifiers.cpp | 16 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/options.cpp | 270 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/services.cpp | 39 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/stdafx.h | 31 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/utils.cpp | 19 | ||||
-rw-r--r-- | plugins/WhenWasIt/src/utils.h | 6 |
12 files changed, 357 insertions, 442 deletions
diff --git a/plugins/WhenWasIt/WhenWasIt.vcxproj b/plugins/WhenWasIt/WhenWasIt.vcxproj index 141573b85a..ddab7f13e5 100644 --- a/plugins/WhenWasIt/WhenWasIt.vcxproj +++ b/plugins/WhenWasIt/WhenWasIt.vcxproj @@ -33,6 +33,7 @@ <ClCompile Include="src\hooked_events.cpp" />
<ClCompile Include="src\icons.cpp" />
<ClCompile Include="src\notifiers.cpp" />
+ <ClCompile Include="src\options.cpp" />
<ClCompile Include="src\services.cpp" />
<ClCompile Include="src\stdafx.cxx">
<PrecompiledHeader>Create</PrecompiledHeader>
diff --git a/plugins/WhenWasIt/WhenWasIt.vcxproj.filters b/plugins/WhenWasIt/WhenWasIt.vcxproj.filters index 216635701a..432ff774d0 100644 --- a/plugins/WhenWasIt/WhenWasIt.vcxproj.filters +++ b/plugins/WhenWasIt/WhenWasIt.vcxproj.filters @@ -35,6 +35,9 @@ <ClCompile Include="src\WhenWasIt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\options.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\birthdays.h">
diff --git a/plugins/WhenWasIt/src/WhenWasIt.cpp b/plugins/WhenWasIt/src/WhenWasIt.cpp index fe56baa9f4..5f5d718ea5 100644 --- a/plugins/WhenWasIt/src/WhenWasIt.cpp +++ b/plugins/WhenWasIt/src/WhenWasIt.cpp @@ -26,8 +26,6 @@ MWindowList hAddBirthdayWndsList = nullptr; CMPlugin g_plugin;
-CommonData commonData = { 0 };
-
/////////////////////////////////////////////////////////////////////////////////////////
PLUGININFOEX pluginInfoEx = {
@@ -44,7 +42,27 @@ PLUGININFOEX pluginInfoEx = { };
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
+ PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
+ foreground(MODULENAME, "Foreground", FOREGROUND_COLOR),
+ background(MODULENAME, "Background", BACKGROUND_COLOR),
+ checkInterval(MODULENAME, "CheckInterval", CHECK_INTERVAL),
+ daysInAdvance(MODULENAME, "DaysInAdvance", DAYS_TO_NOTIFY),
+ daysAfter(MODULENAME, "DaysAfter", DAYS_TO_NOTIFY_AFTER),
+ popupTimeout(MODULENAME, "PopupTimeout", POPUP_TIMEOUT),
+ popupTimeoutToday(MODULENAME, "PopupTimeoutToday", POPUP_TIMEOUT),
+ bUsePopups(MODULENAME, "UsePopups", true),
+ bUseDialog(MODULENAME, "UseDialog", true),
+ bIgnoreSubcontacts(MODULENAME, "IgnoreSubcontacts", false),
+ cShowAgeMode(MODULENAME, "ShowCurrentAge", false),
+ bNoBirthdaysPopup(MODULENAME, "NoBirthdaysPopup", false),
+ bOpenInBackground(MODULENAME, "OpenInBackground", false),
+ cSoundNearDays(MODULENAME, "SoundNearDays", BIRTHDAY_NEAR_DEFAULT_DAYS),
+ cDefaultModule(MODULENAME, "DefaultModule", 0),
+ lPopupClick(MODULENAME, "PopupLeftClick", 2),
+ rPopupClick(MODULENAME, "PopupRightClick", 1),
+ bOncePerDay(MODULENAME, "OncePerDay", false),
+ cDlgTimeout(MODULENAME, "DlgTimeout", POPUP_TIMEOUT),
+ notifyFor(MODULENAME, "NotifyFor", 0)
{}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/WhenWasIt/src/dlg_handlers.cpp b/plugins/WhenWasIt/src/dlg_handlers.cpp index d78eb66ec4..e57619675d 100644 --- a/plugins/WhenWasIt/src/dlg_handlers.cpp +++ b/plugins/WhenWasIt/src/dlg_handlers.cpp @@ -29,356 +29,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define UPCOMING_TIMER_ID 1002
-const wchar_t *szShowAgeMode[] = { LPGENW("Upcoming age"), LPGENW("Current age") };
-
-const wchar_t *szSaveModule[] = { LPGENW("UserInfo module"), LPGENW("Protocol module") };
-
-const wchar_t *szPopupClick[] = { LPGENW("Nothing"), LPGENW("Dismiss"), LPGENW("Message window") };
-
-const wchar_t *szNotifyFor[] = { LPGENW("All contacts"), LPGENW("All contacts except hidden ones"), LPGENW("All contacts except ignored ones"), LPGENW("All contacts except hidden and ignored ones") };
-
#define MIN_BIRTHDAYS_WIDTH 200
#define MIN_BIRTHDAYS_HEIGHT 200
-#include "commctrl.h"
-void CreateToolTip(HWND target, wchar_t* tooltip, LPARAM width)
-{
- HWND hwndToolTip = CreateWindow(TOOLTIPS_CLASS, nullptr, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT, target, nullptr, nullptr, nullptr);
- if (hwndToolTip) {
- TOOLINFO ti = { 0 };
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS;
- ti.hwnd = target;
- ti.uId = 0;
- ti.hinst = nullptr;
- ti.lpszText = tooltip;
- GetClientRect(target, &ti.rect);
- SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
- SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, width);
- SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 20000);
- }
-}
-
-int EnablePopupsGroup(HWND hWnd, int enable)
-{
- EnableWindow(GetDlgItem(hWnd, IDC_POPUPS_STATIC), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_POPUP_TIMEOUT), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_FOREGROUND), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_BACKGROUND), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_NOBIRTHDAYS_POPUP), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_IGNORE_SUBCONTACTS), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_PREVIEW), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_LEFT_CLICK), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_RIGHT_CLICK), enable);
-
- return enable;
-}
-
-int EnableClistGroup(HWND hWnd, int enable)
-{
- EnableWindow(GetDlgItem(hWnd, IDC_CLIST_STATIC), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_ADVANCED_ICON), enable);
- return enable;
-}
-
-int EnableDialogGroup(HWND hWnd, int enable)
-{
- EnableWindow(GetDlgItem(hWnd, IDC_DLG_TIMEOUT), enable);
- EnableWindow(GetDlgItem(hWnd, IDC_OPENINBACKGROUND), enable);
-
- return enable;
-}
-
-int AddInfoToComboBoxes(HWND hWnd)
-{
- int i;
-
- for (i = 0; i < _countof(szShowAgeMode); i++)
- SendDlgItemMessage(hWnd, IDC_AGE_COMBOBOX, CB_ADDSTRING, 0, (LPARAM)TranslateW(szShowAgeMode[i]));
-
- for (i = 0; i < _countof(szSaveModule); i++)
- SendDlgItemMessage(hWnd, IDC_DEFAULT_MODULE, CB_ADDSTRING, 0, (LPARAM)TranslateW(szSaveModule[i]));
-
- for (i = 0; i < _countof(szPopupClick); i++) {
- SendDlgItemMessage(hWnd, IDC_LEFT_CLICK, CB_ADDSTRING, 0, (LPARAM)TranslateW(szPopupClick[i]));
- SendDlgItemMessage(hWnd, IDC_RIGHT_CLICK, CB_ADDSTRING, 0, (LPARAM)TranslateW(szPopupClick[i]));
- }
-
- for (i = 0; i < _countof(szNotifyFor); i++)
- SendDlgItemMessage(hWnd, IDC_NOTIFYFOR, CB_ADDSTRING, 0, (LPARAM)TranslateW(szNotifyFor[i]));
-
- return i;
-}
-
-SIZE GetControlTextSize(HWND hCtrl)
-{
- HDC hDC = GetDC(hCtrl);
- HFONT font = (HFONT)SendMessage(hCtrl, WM_GETFONT, 0, 0);
- HFONT oldFont = (HFONT)SelectObject(hDC, font);
- const size_t maxSize = 2048;
- wchar_t buffer[maxSize];
- SIZE size;
- GetWindowText(hCtrl, buffer, _countof(buffer));
- GetTextExtentPoint32(hDC, buffer, (int)mir_wstrlen(buffer), &size);
- SelectObject(hDC, oldFont);
- ReleaseDC(hCtrl, hDC);
- return size;
-}
-
-int EnlargeControl(HWND hCtrl, HWND, SIZE oldSize)
-{
- SIZE size = GetControlTextSize(hCtrl);
- RECT rect;
- GetWindowRect(hCtrl, &rect);
- int offset = (rect.right - rect.left) - oldSize.cx;
- SetWindowPos(hCtrl, HWND_TOP, 0, 0, size.cx + offset, oldSize.cy, SWP_NOMOVE);
- SetWindowPos(hCtrl, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- return 0;
-}
-
-wchar_t *strtrim(wchar_t *str)
-{
- size_t i = 0;
- size_t len = mir_wstrlen(str);
- while ((i < len) && (str[i] == ' ')) { i++; }
- if (i) {
- memmove(str, str + i, len - i + 1);
- len -= i;
- }
-
- while ((len > 0) && (str[--len] == ' '))
- str[len] = 0;
-
- return str;
-}
-
-INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static int bInitializing = 0;
- switch (msg) {
- case WM_INITDIALOG:
- {
- bInitializing = 1;
-
- SIZE oldPopupsSize = GetControlTextSize(GetDlgItem(hWnd, IDC_USE_POPUPS));
- SIZE oldClistIconSize = GetControlTextSize(GetDlgItem(hWnd, IDC_USE_CLISTICON));
- SIZE oldDialogSize = GetControlTextSize(GetDlgItem(hWnd, IDC_USE_DIALOG));
-
- TranslateDialogDefault(hWnd);
-
- EnlargeControl(GetDlgItem(hWnd, IDC_USE_POPUPS), GetDlgItem(hWnd, IDC_POPUPS_STATIC), oldPopupsSize);
- EnlargeControl(GetDlgItem(hWnd, IDC_USE_CLISTICON), GetDlgItem(hWnd, IDC_CLIST_STATIC), oldClistIconSize);
- EnlargeControl(GetDlgItem(hWnd, IDC_USE_DIALOG), GetDlgItem(hWnd, IDC_DIALOG_STATIC), oldDialogSize);
-
- AddInfoToComboBoxes(hWnd);
-
- SendDlgItemMessage(hWnd, IDC_FOREGROUND, CPM_SETDEFAULTCOLOUR, 0, FOREGROUND_COLOR);
- SendDlgItemMessage(hWnd, IDC_BACKGROUND, CPM_SETDEFAULTCOLOUR, 0, BACKGROUND_COLOR);
-
- SendDlgItemMessage(hWnd, IDC_FOREGROUND, CPM_SETCOLOUR, 0, commonData.foreground);
- SendDlgItemMessage(hWnd, IDC_BACKGROUND, CPM_SETCOLOUR, 0, commonData.background);
-
- SendDlgItemMessage(hWnd, IDC_DEFAULT_MODULE, CB_SETCURSEL, commonData.cDefaultModule, 0);
- SendDlgItemMessage(hWnd, IDC_LEFT_CLICK, CB_SETCURSEL, commonData.lPopupClick, 0);
- SendDlgItemMessage(hWnd, IDC_RIGHT_CLICK, CB_SETCURSEL, commonData.rPopupClick, 0);
- SendDlgItemMessage(hWnd, IDC_NOTIFYFOR, CB_SETCURSEL, commonData.notifyFor, 0);
-
- CreateToolTip(GetDlgItem(hWnd, IDC_POPUP_TIMEOUT), TranslateT("Set popup delay when notifying of upcoming birthdays.\nFormat: default delay [ | delay for birthdays occurring today]"), 400);
-
- wchar_t buffer[1024];
- _itow(commonData.daysInAdvance, buffer, 10);
- SetDlgItemText(hWnd, IDC_DAYS_IN_ADVANCE, buffer);
- _itow(commonData.checkInterval, buffer, 10);
- SetDlgItemText(hWnd, IDC_CHECK_INTERVAL, buffer);
- mir_snwprintf(buffer, L"%d|%d", commonData.popupTimeout, commonData.popupTimeoutToday);
- SetDlgItemText(hWnd, IDC_POPUP_TIMEOUT, buffer);
- _itow(commonData.cSoundNearDays, buffer, 10);
- SetDlgItemText(hWnd, IDC_SOUND_NEAR_DAYS_EDIT, buffer);
- _itow(commonData.cDlgTimeout, buffer, 10);
- SetDlgItemText(hWnd, IDC_DLG_TIMEOUT, buffer);
- _itow(commonData.daysAfter, buffer, 10);
- SetDlgItemText(hWnd, IDC_DAYS_AFTER, buffer);
-
- CheckDlgButton(hWnd, IDC_OPENINBACKGROUND, (commonData.bOpenInBackground) ? BST_CHECKED : BST_UNCHECKED);
-
- CheckDlgButton(hWnd, IDC_NOBIRTHDAYS_POPUP, (commonData.bNoBirthdaysPopup) ? BST_CHECKED : BST_UNCHECKED);
- SendDlgItemMessage(hWnd, IDC_AGE_COMBOBOX, CB_SETCURSEL, commonData.cShowAgeMode, 0);
-
- CheckDlgButton(hWnd, IDC_IGNORE_SUBCONTACTS, (commonData.bIgnoreSubcontacts) ? BST_CHECKED : BST_UNCHECKED);
-
- CheckDlgButton(hWnd, IDC_ONCE_PER_DAY, (commonData.bOncePerDay) ? BST_CHECKED : BST_UNCHECKED);
- EnableWindow(GetDlgItem(hWnd, IDC_CHECK_INTERVAL), !commonData.bOncePerDay);
-
- CheckDlgButton(hWnd, IDC_USE_DIALOG, (commonData.bUseDialog) ? BST_CHECKED : BST_UNCHECKED);
- EnableDialogGroup(hWnd, commonData.bUseDialog);
-
- CheckDlgButton(hWnd, IDC_USE_POPUPS, commonData.bUsePopups ? BST_CHECKED : BST_UNCHECKED);
- EnablePopupsGroup(hWnd, commonData.bUsePopups);
-
- CheckDlgButton(hWnd, IDC_USE_CLISTICON, BST_CHECKED);
- EnableWindow(GetDlgItem(hWnd, IDC_USE_CLISTICON), FALSE);
- EnableClistGroup(hWnd, FALSE);
- }
- bInitializing = 0;
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_CHECK_INTERVAL:
- case IDC_POPUP_TIMEOUT:
- case IDC_DAYS_IN_ADVANCE:
- case IDC_DLG_TIMEOUT:
- case IDC_SOUND_NEAR_DAYS_EDIT:
- case IDC_DAYS_AFTER:
- if ((HIWORD(wParam) == EN_CHANGE) && (!bInitializing))// || (HIWORD(wParam) == CBN_SELENDOK))
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_USE_POPUPS:
- case IDC_USE_CLISTICON:
- case IDC_USE_DIALOG:
- EnablePopupsGroup(hWnd, IsDlgButtonChecked(hWnd, IDC_USE_POPUPS));
- EnableClistGroup(hWnd, IsDlgButtonChecked(hWnd, IDC_USE_CLISTICON));
- EnableDialogGroup(hWnd, IsDlgButtonChecked(hWnd, IDC_USE_DIALOG));
- RedrawWindow(GetDlgItem(hWnd, IDC_USE_POPUPS), nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE);
- RedrawWindow(GetDlgItem(hWnd, IDC_USE_CLISTICON), nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE);
- RedrawWindow(GetDlgItem(hWnd, IDC_USE_DIALOG), nullptr, nullptr, RDW_ERASE | RDW_INVALIDATE);
- //fallthrough
-
- case IDC_FOREGROUND:
- case IDC_BACKGROUND:
- case IDC_ADVANCED_ICON:
- case IDC_IGNORE_SUBCONTACTS:
- case IDC_AGE_COMBOBOX:
- case IDC_NOBIRTHDAYS_POPUP:
- case IDC_DEFAULT_MODULE:
- case IDC_LEFT_CLICK:
- case IDC_RIGHT_CLICK:
- case IDC_ONCE_PER_DAY:
- case IDC_NOTIFYFOR:
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- EnableWindow(GetDlgItem(hWnd, IDC_CHECK_INTERVAL), BST_UNCHECKED == IsDlgButtonChecked(hWnd, IDC_ONCE_PER_DAY));
- break;
-
- case IDC_PREVIEW:
- {
- MCONTACT hContact = db_find_first();
- int dtb = rand() % 11; //0..10
- int age = rand() % 50 + 1; //1..50
- PopupNotifyBirthday(hContact, dtb, age);
- break;
- }
- }
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- commonData.foreground = SendDlgItemMessage(hWnd, IDC_FOREGROUND, CPM_GETCOLOUR, 0, 0);
- commonData.background = SendDlgItemMessage(hWnd, IDC_BACKGROUND, CPM_GETCOLOUR, 0, 0);
- commonData.popupTimeout = POPUP_TIMEOUT;
- commonData.popupTimeoutToday = POPUP_TIMEOUT;
- commonData.bUsePopups = IsDlgButtonChecked(hWnd, IDC_USE_POPUPS);
- commonData.bUseDialog = IsDlgButtonChecked(hWnd, IDC_USE_DIALOG);
- commonData.bIgnoreSubcontacts = IsDlgButtonChecked(hWnd, IDC_IGNORE_SUBCONTACTS);
- commonData.bNoBirthdaysPopup = IsDlgButtonChecked(hWnd, IDC_NOBIRTHDAYS_POPUP);
- commonData.cShowAgeMode = SendDlgItemMessage(hWnd, IDC_AGE_COMBOBOX, CB_GETCURSEL, 0, 0);
- commonData.cDefaultModule = SendDlgItemMessage(hWnd, IDC_DEFAULT_MODULE, CB_GETCURSEL, 0, 0);
- commonData.lPopupClick = SendDlgItemMessage(hWnd, IDC_LEFT_CLICK, CB_GETCURSEL, 0, 0);
- commonData.rPopupClick = SendDlgItemMessage(hWnd, IDC_RIGHT_CLICK, CB_GETCURSEL, 0, 0);
- commonData.bOncePerDay = IsDlgButtonChecked(hWnd, IDC_ONCE_PER_DAY);
- commonData.notifyFor = SendDlgItemMessage(hWnd, IDC_NOTIFYFOR, CB_GETCURSEL, 0, 0);
- commonData.bOpenInBackground = IsDlgButtonChecked(hWnd, IDC_OPENINBACKGROUND);
- {
- const int maxSize = 1024;
- wchar_t buffer[maxSize];
-
- GetDlgItemText(hWnd, IDC_DAYS_IN_ADVANCE, buffer, _countof(buffer));
- wchar_t *stop = nullptr;
- commonData.daysInAdvance = wcstol(buffer, &stop, 10);
-
- if (*stop) { commonData.daysInAdvance = DAYS_TO_NOTIFY; }
-
- GetDlgItemText(hWnd, IDC_DAYS_AFTER, buffer, _countof(buffer));
- commonData.daysAfter = wcstol(buffer, &stop, 10);
-
- if (*stop) { commonData.daysAfter = DAYS_TO_NOTIFY_AFTER; }
-
- GetDlgItemText(hWnd, IDC_CHECK_INTERVAL, buffer, _countof(buffer));
- commonData.checkInterval = _wtol(buffer);
- if (!commonData.checkInterval) { commonData.checkInterval = CHECK_INTERVAL; }
-
- GetDlgItemText(hWnd, IDC_POPUP_TIMEOUT, buffer, _countof(buffer));
- wchar_t *pos;
- pos = wcschr(buffer, '|');
- if (pos) {
- wchar_t tmp[128];
- *pos = 0;
- mir_wstrcpy(tmp, buffer);
- strtrim(tmp);
- commonData.popupTimeout = _wtol(tmp);
-
- mir_wstrcpy(tmp, pos + 1);
- strtrim(tmp);
- commonData.popupTimeoutToday = _wtol(tmp);
-
- }
- else commonData.popupTimeout = commonData.popupTimeoutToday = _wtol(buffer);
-
- GetDlgItemText(hWnd, IDC_SOUND_NEAR_DAYS_EDIT, buffer, _countof(buffer));
- //cSoundNearDays = _wtol(buffer);
- commonData.cSoundNearDays = wcstol(buffer, &stop, 10);
- if (*stop) { commonData.cSoundNearDays = BIRTHDAY_NEAR_DEFAULT_DAYS; }
-
- GetDlgItemText(hWnd, IDC_DLG_TIMEOUT, buffer, _countof(buffer));
- commonData.cDlgTimeout = wcstol(buffer, &stop, 10);
- if (*stop) { commonData.cDlgTimeout = POPUP_TIMEOUT; }
-
- g_plugin.setByte("IgnoreSubcontacts", commonData.bIgnoreSubcontacts);
- g_plugin.setByte("UsePopups", commonData.bUsePopups);
- g_plugin.setByte("UseDialog", commonData.bUseDialog);
- g_plugin.setWord("CheckInterval", commonData.checkInterval);
- g_plugin.setWord("DaysInAdvance", commonData.daysInAdvance);
- g_plugin.setWord("DaysAfter", commonData.daysAfter);
- g_plugin.setWord("PopupTimeout", commonData.popupTimeout);
- g_plugin.setWord("PopupTimeoutToday", commonData.popupTimeoutToday);
-
- g_plugin.setByte("ShowCurrentAge", commonData.cShowAgeMode);
- g_plugin.setByte("NoBirthdaysPopup", commonData.bNoBirthdaysPopup);
-
- g_plugin.setByte("OpenInBackground", commonData.bOpenInBackground);
-
- g_plugin.setByte("SoundNearDays", commonData.cSoundNearDays);
-
- g_plugin.setByte("DefaultModule", commonData.cDefaultModule);
-
- g_plugin.setByte("PopupLeftClick", commonData.lPopupClick);
- g_plugin.setByte("PopupRightClick", commonData.rPopupClick);
-
- g_plugin.setDword("Foreground", commonData.foreground);
- g_plugin.setDword("Background", commonData.background);
-
- g_plugin.setByte("OncePerDay", commonData.bOncePerDay);
-
- g_plugin.setWord("DlgTimeout", commonData.cDlgTimeout);
-
- g_plugin.setByte("NotifyFor", commonData.notifyFor);
-
- RefreshAllContactListIcons();
-
- UpdateTimers(); //interval might get changed
- }
- bInitializing = 0;
- }
- break;
- }
- break;
- }
- return 0;
-}
+extern const wchar_t* szSaveModule[2];
INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -397,7 +51,7 @@ INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l for (int i = 0; i < _countof(szSaveModule); i++)
SendDlgItemMessage(hWnd, IDC_COMPATIBILITY, CB_ADDSTRING, 0, (LPARAM)TranslateW(szSaveModule[i]));
- SendDlgItemMessage(hWnd, IDC_COMPATIBILITY, CB_SETCURSEL, commonData.cDefaultModule, 0);
+ SendDlgItemMessage(hWnd, IDC_COMPATIBILITY, CB_SETCURSEL, g_plugin.cDefaultModule, 0);
break;
case WM_SHOWWINDOW:
@@ -689,7 +343,7 @@ int LoadBirthdays(HWND hWnd, int bShowAll) int count = 0;
for (auto &hContact : Contacts())
- count = UpdateBirthdayEntry(hList, hContact, count, bShowAll, commonData.cShowAgeMode, 1);
+ count = UpdateBirthdayEntry(hList, hContact, count, bShowAll, g_plugin.cShowAgeMode, 1);
SetBirthdaysCount(hWnd);
return 0;
@@ -755,9 +409,9 @@ INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa fi.lParam = (LPARAM)hContact;
int idx = ListView_FindItem(hList, -1, &fi);
if (-1 == idx)
- UpdateBirthdayEntry(hList, hContact, ListView_GetItemCount(hList), IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), commonData.cShowAgeMode, 1);
+ UpdateBirthdayEntry(hList, hContact, ListView_GetItemCount(hList), IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 1);
else
- UpdateBirthdayEntry(hList, hContact, idx, IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), commonData.cShowAgeMode, 0);
+ UpdateBirthdayEntry(hList, hContact, idx, IsDlgButtonChecked(hWnd, IDC_SHOW_ALL), g_plugin.cShowAgeMode, 0);
SetBirthdaysCount(hWnd);
}
break;
@@ -834,7 +488,7 @@ INT_PTR CALLBACK DlgProcUpcoming(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar TranslateDialogDefault(hWnd);
Window_SetIcon_IcoLib(hWnd, hListMenu);
{
- timeout = commonData.cDlgTimeout;
+ timeout = g_plugin.cDlgTimeout;
HWND hList = GetDlgItem(hWnd, IDC_UPCOMING_LIST);
mir_subclassWindow(hList, BirthdaysListSubclassProc);
@@ -976,13 +630,13 @@ LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_COMMAND:
switch (HIWORD(wParam)) {
case STN_CLICKED:
- HandlePopupClick(hWnd, commonData.lPopupClick);
+ HandlePopupClick(hWnd, g_plugin.lPopupClick);
break;
}
break;
case WM_CONTEXTMENU:
- HandlePopupClick(hWnd, commonData.rPopupClick);
+ HandlePopupClick(hWnd, g_plugin.rPopupClick);
break;
}
diff --git a/plugins/WhenWasIt/src/dlg_handlers.h b/plugins/WhenWasIt/src/dlg_handlers.h index 7a77e5e33a..8c8d41f08d 100644 --- a/plugins/WhenWasIt/src/dlg_handlers.h +++ b/plugins/WhenWasIt/src/dlg_handlers.h @@ -36,7 +36,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define WWIM_UPDATE_BIRTHDAY (WM_USER + 101)
#define WWIM_ADD_UPCOMING_BIRTHDAY (WM_USER + 102)
-INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+int OnOptionsInitialise(WPARAM wParam, LPARAM);
+
INT_PTR CALLBACK DlgProcBirthdays(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcAddBirthday(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcUpcoming(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/plugins/WhenWasIt/src/hooked_events.cpp b/plugins/WhenWasIt/src/hooked_events.cpp index 9fc1ac1aaf..71d19ec82f 100644 --- a/plugins/WhenWasIt/src/hooked_events.cpp +++ b/plugins/WhenWasIt/src/hooked_events.cpp @@ -40,19 +40,6 @@ static int OnTopToolBarModuleLoaded(WPARAM, LPARAM) return 0;
}
-static int OnOptionsInitialise(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = {};
- odp.position = 100000000;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_WWI);
- odp.szTitle.w = LPGENW("Birthdays");
- odp.szGroup.w = LPGENW("Contacts");
- odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
- odp.pfnDlgProc = DlgProcOptions;
- g_plugin.addOptions(wParam, &odp);
- return 0;
-}
-
static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam)
{
DBCONTACTWRITESETTING *dw = (DBCONTACTWRITESETTING *)lParam;
@@ -95,22 +82,22 @@ int RefreshContactListIcons(MCONTACT hContact) int ignored = db_get_dw(hContact, "Ignore", "Mask1", 0);
ignored = ((ignored & 0x3f) != 0) ? 1 : 0;
int ok = 1;
- if (commonData.notifyFor & EXCLUDE_HIDDEN)
+ if (g_plugin.notifyFor & EXCLUDE_HIDDEN)
ok &= (hidden == 0);
- if (commonData.notifyFor & EXCLUDE_IGNORED)
+ if (g_plugin.notifyFor & EXCLUDE_IGNORED)
ok &= (ignored == 0);
time_t today = Today();
- int dtb = NotifyContactBirthday(hContact, today, commonData.daysInAdvance);
- int dab = NotifyMissedContactBirthday(hContact, today, commonData.daysAfter);
+ int dtb = NotifyContactBirthday(hContact, today, g_plugin.daysInAdvance);
+ int dab = NotifyMissedContactBirthday(hContact, today, g_plugin.daysAfter);
if (ok && (dtb >= 0 || dab > 0)) {
int age = GetContactAge(hContact);
db_set_b(hContact, "UserInfo", "Age", age);
- if ((bShouldCheckBirthdays) && (commonData.bUsePopups))
+ if ((bShouldCheckBirthdays) && (g_plugin.bUsePopups))
{
if (dtb >= 0) {
bBirthdayFound = 1; //only set it if we're called from our CheckBirthdays service
@@ -124,7 +111,7 @@ int RefreshContactListIcons(MCONTACT hContact) if (dtb >= 0)
SoundNotifyBirthday(dtb);
- if ((bShouldCheckBirthdays) && (commonData.bUseDialog)) {
+ if ((bShouldCheckBirthdays) && (g_plugin.bUseDialog)) {
if (dtb >= 0)
DialogNotifyBirthday(hContact, dtb, age);
else if (dab > 0)
diff --git a/plugins/WhenWasIt/src/notifiers.cpp b/plugins/WhenWasIt/src/notifiers.cpp index 2f0f78c8ee..f72530dd9b 100644 --- a/plugins/WhenWasIt/src/notifiers.cpp +++ b/plugins/WhenWasIt/src/notifiers.cpp @@ -22,10 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void FillPopupData(POPUPDATAW &ppd, int dtb)
{
- int popupTimeout = (dtb == 0) ? commonData.popupTimeoutToday : commonData.popupTimeout;
+ int popupTimeout = (dtb == 0) ? g_plugin.popupTimeoutToday : g_plugin.popupTimeout;
- ppd.colorBack = commonData.background;
- ppd.colorText = commonData.foreground;
+ ppd.colorBack = g_plugin.background;
+ ppd.colorText = g_plugin.foreground;
ppd.iSeconds = popupTimeout;
}
@@ -66,7 +66,7 @@ wchar_t *BuildDABText(int dab, wchar_t *name, wchar_t *text, int size) int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age)
{
- if (commonData.bIgnoreSubcontacts && db_mc_isSub(hContact))
+ if (g_plugin.bIgnoreSubcontacts && db_mc_isSub(hContact))
return 0;
wchar_t *name = Clist_GetContactDisplayName(hContact);
@@ -110,7 +110,7 @@ int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age) int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
- if (commonData.bIgnoreSubcontacts && db_mc_isSub(hContact))
+ if (g_plugin.bIgnoreSubcontacts && db_mc_isSub(hContact))
return 0;
wchar_t *name = Clist_GetContactDisplayName(hContact);
@@ -155,7 +155,7 @@ int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age) BuildDTBText(dtb, name, text, _countof(text));
if (!hUpcomingDlg) {
hUpcomingDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_UPCOMING), nullptr, DlgProcUpcoming);
- ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
+ ShowWindow(hUpcomingDlg, g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
TUpcomingBirthday data = { 0 };
@@ -177,7 +177,7 @@ int DialogNotifyMissedBirthday(MCONTACT hContact, int dab, int age) BuildDABText(dab, name, text, _countof(text));
if (!hUpcomingDlg) {
hUpcomingDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_UPCOMING), nullptr, DlgProcUpcoming);
- ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
+ ShowWindow(hUpcomingDlg, g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
TUpcomingBirthday data = { 0 };
@@ -195,7 +195,7 @@ int SoundNotifyBirthday(int dtb) {
if (dtb == 0)
Skin_PlaySound(BIRTHDAY_TODAY_SOUND);
- else if (dtb <= commonData.cSoundNearDays)
+ else if (dtb <= g_plugin.cSoundNearDays)
Skin_PlaySound(BIRTHDAY_NEAR_SOUND);
return 0;
diff --git a/plugins/WhenWasIt/src/options.cpp b/plugins/WhenWasIt/src/options.cpp new file mode 100644 index 0000000000..ca7c2e5759 --- /dev/null +++ b/plugins/WhenWasIt/src/options.cpp @@ -0,0 +1,270 @@ +/* +WhenWasIt (birthday reminder) plugin for Miranda IM + +Copyright © 2006 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +const wchar_t* szShowAgeMode[] = { LPGENW("Upcoming age"), LPGENW("Current age") }; + +const wchar_t* szSaveModule[] = { LPGENW("UserInfo module"), LPGENW("Protocol module") }; + +const wchar_t* szPopupClick[] = { LPGENW("Nothing"), LPGENW("Dismiss"), LPGENW("Message window") }; + +const wchar_t* szNotifyFor[] = { LPGENW("All contacts"), LPGENW("All contacts except hidden ones"), LPGENW("All contacts except ignored ones"), LPGENW("All contacts except hidden and ignored ones") }; + +static SIZE GetControlTextSize(HWND hCtrl) +{ + HDC hDC = GetDC(hCtrl); + HFONT font = (HFONT)SendMessage(hCtrl, WM_GETFONT, 0, 0); + HFONT oldFont = (HFONT)SelectObject(hDC, font); + const size_t maxSize = 2048; + wchar_t buffer[maxSize]; + SIZE size; + GetWindowText(hCtrl, buffer, _countof(buffer)); + GetTextExtentPoint32(hDC, buffer, (int)mir_wstrlen(buffer), &size); + SelectObject(hDC, oldFont); + ReleaseDC(hCtrl, hDC); + return size; +} + +static int EnlargeControl(HWND hCtrl, HWND, SIZE oldSize) +{ + SIZE size = GetControlTextSize(hCtrl); + RECT rect; + GetWindowRect(hCtrl, &rect); + int offset = (rect.right - rect.left) - oldSize.cx; + SetWindowPos(hCtrl, HWND_TOP, 0, 0, size.cx + offset, oldSize.cy, SWP_NOMOVE); + SetWindowPos(hCtrl, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + return 0; +} + +static wchar_t* strtrim(wchar_t *str) +{ + size_t i = 0; + size_t len = mir_wstrlen(str); + while ((i < len) && (str[i] == ' ')) { i++; } + if (i) { + memmove(str, str + i, len - i + 1); + len -= i; + } + + while ((len > 0) && (str[--len] == ' ')) + str[len] = 0; + + return str; +} + +class COptionsDlg : public CDlgBase +{ + CCtrlButton btnPreview; + CCtrlCheck chkPopups, chkClistIcon, chkDialog, chkOncePerDay; + CCtrlCombo cmbModule, cmbAge, cmbLClick, cmbRClick, cmbNotify; + CCtrlColor clrFore, clrBack; + +public: + COptionsDlg() : + CDlgBase(g_plugin, IDD_OPT_WWI), + btnPreview(this, IDC_PREVIEW), + clrFore(this, IDC_FOREGROUND), + clrBack(this, IDC_BACKGROUND), + cmbAge(this, IDC_AGE_COMBOBOX), + cmbModule(this, IDC_DEFAULT_MODULE), + cmbNotify(this, IDC_NOTIFYFOR), + cmbLClick(this, IDC_LEFT_CLICK), + cmbRClick(this, IDC_RIGHT_CLICK), + chkPopups(this, IDC_USE_POPUPS), + chkDialog(this, IDC_USE_DIALOG), + chkClistIcon(this, IDC_USE_CLISTICON), + chkOncePerDay(this, IDC_ONCE_PER_DAY) + { + CreateLink(clrFore, g_plugin.foreground); + CreateLink(clrBack, g_plugin.background); + + btnPreview.OnClick = Callback(this, &COptionsDlg::onClick_Preview); + + chkPopups.OnChange = Callback(this, &COptionsDlg::onChange_Popups); + chkDialog.OnChange = Callback(this, &COptionsDlg::onChange_Dialog); + chkClistIcon.OnChange = Callback(this, &COptionsDlg::onChange_ClistIcon); + chkOncePerDay.OnChange = Callback(this, &COptionsDlg::onChange_OncePerDay); + } + + bool OnInitDialog() override + { + SIZE oldPopupsSize = GetControlTextSize(chkPopups.GetHwnd()); + SIZE oldClistIconSize = GetControlTextSize(chkClistIcon.GetHwnd()); + SIZE oldDialogSize = GetControlTextSize(GetDlgItem(m_hwnd, IDC_USE_DIALOG)); + + EnlargeControl(chkPopups.GetHwnd(), GetDlgItem(m_hwnd, IDC_POPUPS_STATIC), oldPopupsSize); + EnlargeControl(chkClistIcon.GetHwnd(), GetDlgItem(m_hwnd, IDC_CLIST_STATIC), oldClistIconSize); + EnlargeControl(GetDlgItem(m_hwnd, IDC_USE_DIALOG), GetDlgItem(m_hwnd, IDC_DIALOG_STATIC), oldDialogSize); + + for (auto &it : szShowAgeMode) + cmbAge.AddString(TranslateW(it)); + + for (auto &it : szSaveModule) + cmbModule.AddString(TranslateW(it)); + + for (auto &it : szPopupClick) { + cmbLClick.AddString(TranslateW(it)); + cmbRClick.AddString(TranslateW(it)); + } + + for (auto &it : szNotifyFor) + cmbNotify.AddString(TranslateW(it)); + + cmbModule.SetCurSel(g_plugin.cDefaultModule); + cmbLClick.SetCurSel(g_plugin.lPopupClick); + cmbRClick.SetCurSel(g_plugin.rPopupClick); + cmbNotify.SetCurSel(g_plugin.notifyFor); + + CreateToolTip(GetDlgItem(m_hwnd, IDC_POPUP_TIMEOUT), TranslateT("Set popup delay when notifying of upcoming birthdays.\nFormat: default delay [ | delay for birthdays occurring today]"), 400); + + wchar_t buffer[1024]; + _itow(g_plugin.daysInAdvance, buffer, 10); + SetDlgItemText(m_hwnd, IDC_DAYS_IN_ADVANCE, buffer); + _itow(g_plugin.checkInterval, buffer, 10); + SetDlgItemText(m_hwnd, IDC_CHECK_INTERVAL, buffer); + mir_snwprintf(buffer, L"%d|%d", (int)g_plugin.popupTimeout, (int)g_plugin.popupTimeoutToday); + SetDlgItemText(m_hwnd, IDC_POPUP_TIMEOUT, buffer); + _itow(g_plugin.cSoundNearDays, buffer, 10); + SetDlgItemText(m_hwnd, IDC_SOUND_NEAR_DAYS_EDIT, buffer); + _itow(g_plugin.cDlgTimeout, buffer, 10); + SetDlgItemText(m_hwnd, IDC_DLG_TIMEOUT, buffer); + _itow(g_plugin.daysAfter, buffer, 10); + SetDlgItemText(m_hwnd, IDC_DAYS_AFTER, buffer); + + CheckDlgButton(m_hwnd, IDC_OPENINBACKGROUND, (g_plugin.bOpenInBackground) ? BST_CHECKED : BST_UNCHECKED); + + CheckDlgButton(m_hwnd, IDC_NOBIRTHDAYS_POPUP, (g_plugin.bNoBirthdaysPopup) ? BST_CHECKED : BST_UNCHECKED); + cmbAge.SetCurSel(g_plugin.cShowAgeMode); + + CheckDlgButton(m_hwnd, IDC_IGNORE_SUBCONTACTS, (g_plugin.bIgnoreSubcontacts) ? BST_CHECKED : BST_UNCHECKED); + + chkOncePerDay.SetState(g_plugin.bOncePerDay); + EnableWindow(GetDlgItem(m_hwnd, IDC_CHECK_INTERVAL), !g_plugin.bOncePerDay); + + CheckDlgButton(m_hwnd, IDC_USE_DIALOG, (g_plugin.bUseDialog) ? BST_CHECKED : BST_UNCHECKED); + + chkPopups.SetState(g_plugin.bUsePopups); + + chkClistIcon.SetState(true); + chkClistIcon.Disable(); + return true; + } + + bool OnApply() override + { + g_plugin.popupTimeout = POPUP_TIMEOUT; + g_plugin.popupTimeoutToday = POPUP_TIMEOUT; + g_plugin.bUsePopups = chkPopups.GetState(); + g_plugin.bUseDialog = IsDlgButtonChecked(m_hwnd, IDC_USE_DIALOG); + g_plugin.bIgnoreSubcontacts = IsDlgButtonChecked(m_hwnd, IDC_IGNORE_SUBCONTACTS); + g_plugin.bNoBirthdaysPopup = IsDlgButtonChecked(m_hwnd, IDC_NOBIRTHDAYS_POPUP); + g_plugin.cDefaultModule = cmbModule.GetCurSel(); + g_plugin.cShowAgeMode = cmbAge.GetCurSel(); + g_plugin.lPopupClick = cmbLClick.GetCurSel(); + g_plugin.rPopupClick = cmbRClick.GetCurSel(); + g_plugin.notifyFor = cmbNotify.GetCurSel(); + g_plugin.bOncePerDay = chkOncePerDay.GetState(); + g_plugin.bOpenInBackground = IsDlgButtonChecked(m_hwnd, IDC_OPENINBACKGROUND); + + g_plugin.daysInAdvance = GetDlgItemInt(m_hwnd, IDC_DAYS_IN_ADVANCE, 0, 0); + g_plugin.daysAfter = GetDlgItemInt(m_hwnd, IDC_DAYS_AFTER, 0, 0); + g_plugin.checkInterval = GetDlgItemInt(m_hwnd, IDC_CHECK_INTERVAL, 0, 0); + g_plugin.cSoundNearDays = GetDlgItemInt(m_hwnd, IDC_SOUND_NEAR_DAYS_EDIT, 0, 0); + g_plugin.cDlgTimeout = GetDlgItemInt(m_hwnd, IDC_DLG_TIMEOUT, 0, 0); + + const int maxSize = 1024; + wchar_t buffer[maxSize]; + GetDlgItemText(m_hwnd, IDC_POPUP_TIMEOUT, buffer, _countof(buffer)); + wchar_t *pos = wcschr(buffer, '|'); + if (pos) { + wchar_t tmp[128]; + *pos = 0; + mir_wstrcpy(tmp, buffer); + strtrim(tmp); + g_plugin.popupTimeout = _wtol(tmp); + + mir_wstrcpy(tmp, pos + 1); + strtrim(tmp); + g_plugin.popupTimeoutToday = _wtol(tmp); + + } + else g_plugin.popupTimeout = g_plugin.popupTimeoutToday = _wtol(buffer); + + RefreshAllContactListIcons(); + + UpdateTimers(); //interval might get changed + return true; + } + + void onChange_Popups(CCtrlCheck *pCheck) + { + bool bEnable = pCheck->GetState(); + EnableWindow(GetDlgItem(m_hwnd, IDC_POPUPS_STATIC), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_POPUP_TIMEOUT), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_NOBIRTHDAYS_POPUP), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_IGNORE_SUBCONTACTS), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_PREVIEW), bEnable); + clrFore.Enable(bEnable); + clrBack.Enable(bEnable); + cmbLClick.Enable(bEnable); + cmbRClick.Enable(bEnable); + } + + void onChange_ClistIcon(CCtrlCheck *pCheck) + { + bool bEnable = pCheck->GetState(); + EnableWindow(GetDlgItem(m_hwnd, IDC_CLIST_STATIC), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_ADVANCED_ICON), bEnable); + } + + void onChange_Dialog(CCtrlCheck *pCheck) + { + bool bEnable = pCheck->GetState(); + EnableWindow(GetDlgItem(m_hwnd, IDC_DLG_TIMEOUT), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_OPENINBACKGROUND), bEnable); + } + + void onChange_OncePerDay(CCtrlCheck *pCheck) + { + bool bEnable = pCheck->GetState(); + EnableWindow(GetDlgItem(m_hwnd, IDC_CHECK_INTERVAL), !bEnable); + } + + void onClick_Preview(CCtrlButton *) + { + MCONTACT hContact = db_find_first(); + int dtb = rand() % 11; //0..10 + int age = rand() % 50 + 1; //1..50 + PopupNotifyBirthday(hContact, dtb, age); + } +}; + +int OnOptionsInitialise(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = {}; + odp.flags = ODPF_BOLDGROUPS; + odp.position = 100000000; + odp.pDialog = new COptionsDlg(); + odp.szTitle.a = LPGEN("Birthdays"); + odp.szGroup.a = LPGEN("Contacts"); + g_plugin.addOptions(wParam, &odp); + return 0; +} diff --git a/plugins/WhenWasIt/src/services.cpp b/plugins/WhenWasIt/src/services.cpp index b2b622dc00..0e30a3b1c2 100644 --- a/plugins/WhenWasIt/src/services.cpp +++ b/plugins/WhenWasIt/src/services.cpp @@ -29,27 +29,6 @@ int InitServices() {
Log("%s", "Entering function " __FUNCTION__);
- commonData.foreground = g_plugin.getDword("Foreground", FOREGROUND_COLOR);
- commonData.background = g_plugin.getDword("Background", BACKGROUND_COLOR);
- commonData.checkInterval = g_plugin.getWord("CheckInterval", CHECK_INTERVAL);
- commonData.daysInAdvance = g_plugin.getWord("DaysInAdvance", DAYS_TO_NOTIFY);
- commonData.daysAfter = g_plugin.getWord("DaysAfter", DAYS_TO_NOTIFY_AFTER);
- commonData.popupTimeout = g_plugin.getWord("PopupTimeout", POPUP_TIMEOUT);
- commonData.popupTimeoutToday = g_plugin.getWord("PopupTimeoutToday", commonData.popupTimeout);
- commonData.bUsePopups = g_plugin.getByte("UsePopups", TRUE);
- commonData.bUseDialog = g_plugin.getByte("UseDialog", TRUE);
- commonData.bIgnoreSubcontacts = g_plugin.getByte("IgnoreSubcontacts", FALSE);
- commonData.cShowAgeMode = g_plugin.getByte("ShowCurrentAge", FALSE);
- commonData.bNoBirthdaysPopup = g_plugin.getByte("NoBirthdaysPopup", FALSE);
- commonData.bOpenInBackground = g_plugin.getByte("OpenInBackground", FALSE);
- commonData.cSoundNearDays = g_plugin.getByte("SoundNearDays", BIRTHDAY_NEAR_DEFAULT_DAYS);
- commonData.cDefaultModule = g_plugin.getByte("DefaultModule", 0);
- commonData.lPopupClick = g_plugin.getByte("PopupLeftClick", 2);
- commonData.rPopupClick = g_plugin.getByte("PopupRightClick", 1);
- commonData.bOncePerDay = g_plugin.getByte("OncePerDay", 0);
- commonData.cDlgTimeout = g_plugin.getWord("DlgTimeout", POPUP_TIMEOUT);
- commonData.notifyFor = g_plugin.getByte("NotifyFor", 0);
-
CreateServiceFunction(MS_WWI_CHECK_BIRTHDAYS, CheckBirthdaysService);
CreateServiceFunction(MS_WWI_LIST_SHOW, ShowListService);
CreateServiceFunction(MS_WWI_ADD_BIRTHDAY, AddBirthdayService);
@@ -112,23 +91,23 @@ INT_PTR CheckBirthdaysService(WPARAM, LPARAM lParam) int daysAfter = DaysAfterBirthday(Today(), lcYear, lcMonth, lcDay); //get difference between last checked date and today
int savedDaysAfter = 0;
- savedDaysAfter = commonData.daysAfter; //save value
+ savedDaysAfter = g_plugin.daysAfter; //save value
- if ((daysAfter > commonData.daysAfter) && (commonData.daysAfter > 0))//check for passed birthdays
- commonData.daysAfter = daysAfter; //bigger values of the two
+ if ((daysAfter > g_plugin.daysAfter) && (g_plugin.daysAfter > 0))//check for passed birthdays
+ g_plugin.daysAfter = daysAfter; //bigger values of the two
- if ((lParam) && (commonData.bOncePerDay)) //if force check then we don't take OncePerDay into account
+ if ((lParam) && (g_plugin.bOncePerDay)) //if force check then we don't take OncePerDay into account
if (lcDay == today.wDay && lcMonth == today.wMonth && lcYear == today.wYear)
return 0; //already checked today
bShouldCheckBirthdays = 1;
RefreshAllContactListIcons();
- if ((!bBirthdayFound) && (commonData.bNoBirthdaysPopup))
+ if ((!bBirthdayFound) && (g_plugin.bNoBirthdaysPopup))
PopupNotifyNoBirthdays();
bShouldCheckBirthdays = 0;
- commonData.daysAfter = savedDaysAfter; //restore previous value
+ g_plugin.daysAfter = savedDaysAfter; //restore previous value
if (lParam) //if not forced - i.e. timer check
g_plugin.setDword("LastChecked", MAKELONG(MAKEWORD(today.wDay, today.wMonth), today.wYear)); //write the value in DB so we don't check again today
@@ -160,8 +139,8 @@ void ShowPopupMessage(const wchar_t *title, const wchar_t *message, HANDLE icon) ppd.lchIcon = IcoLib_GetIconByHandle(icon);
wcsncpy_s(ppd.lpwzContactName, title, _TRUNCATE);
wcsncpy_s(ppd.lpwzText, message, _TRUNCATE);
- ppd.colorText = commonData.foreground;
- ppd.colorBack = commonData.background;
+ ppd.colorText = g_plugin.foreground;
+ ppd.colorBack = g_plugin.background;
PUAddPopupW(&ppd);
}
@@ -249,7 +228,7 @@ int DoImport(wchar_t *fileName) return 1;
}
- int mode = commonData.cDefaultModule;
+ int mode = g_plugin.cDefaultModule;
while (!feof(fin)) {
wchar_t buffer[4096];
diff --git a/plugins/WhenWasIt/src/stdafx.h b/plugins/WhenWasIt/src/stdafx.h index d9a47dc38f..2feb189db1 100644 --- a/plugins/WhenWasIt/src/stdafx.h +++ b/plugins/WhenWasIt/src/stdafx.h @@ -64,6 +64,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct CMPlugin : public PLUGIN<CMPlugin>
{
+ CMOption<uint32_t> foreground, background;
+ CMOption<bool> bUsePopups, bUseDialog, bIgnoreSubcontacts, bNoBirthdaysPopup, bOncePerDay, bOpenInBackground;
+ CMOption<uint16_t> checkInterval, daysInAdvance, popupTimeout, popupTimeoutToday, cDlgTimeout, daysAfter;
+ CMOption<uint8_t> cShowAgeMode, cSoundNearDays, cDefaultModule;
+ CMOption<uint8_t> lPopupClick, rPopupClick, notifyFor;
+
CMPlugin();
int Load() override;
@@ -74,29 +80,4 @@ extern HWND hBirthdaysDlg; extern HWND hUpcomingDlg;
extern MWindowList hAddBirthdayWndsList;
-struct CommonData{
- uint32_t foreground;
- uint32_t background;
- int checkInterval;
- int daysInAdvance;
- int popupTimeout;
- int popupTimeoutToday;
- int bUsePopups;
- int bUseDialog;
- int bIgnoreSubcontacts;
- int cShowAgeMode;
- int bNoBirthdaysPopup;
- int cSoundNearDays;
- int cDefaultModule;
- int lPopupClick;
- int rPopupClick;
- int bOncePerDay;
- int cDlgTimeout;
- int notifyFor;
- int daysAfter;
- int bOpenInBackground;
-};
-
-extern CommonData commonData;
-
#endif //M_WWI_COMMONHEADERS_H
\ No newline at end of file diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp index 247d226d7e..027d7ee3da 100644 --- a/plugins/WhenWasIt/src/utils.cpp +++ b/plugins/WhenWasIt/src/utils.cpp @@ -235,3 +235,22 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, return rChild;
}
+
+void CreateToolTip(HWND target, wchar_t* tooltip, LPARAM width)
+{
+ HWND hwndToolTip = CreateWindow(TOOLTIPS_CLASS, nullptr, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT, target, nullptr, nullptr, nullptr);
+ if (hwndToolTip) {
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS;
+ ti.hwnd = target;
+ ti.uId = 0;
+ ti.hinst = nullptr;
+ ti.lpszText = tooltip;
+ GetClientRect(target, &ti.rect);
+ SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
+ SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, width);
+ SendMessage(hwndToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 20000);
+ }
+}
diff --git a/plugins/WhenWasIt/src/utils.h b/plugins/WhenWasIt/src/utils.h index 9a5c65a1d9..f5afc2c1c0 100644 --- a/plugins/WhenWasIt/src/utils.h +++ b/plugins/WhenWasIt/src/utils.h @@ -44,9 +44,11 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, int size);
-wchar_t* GetContactID(MCONTACT hContact);
-wchar_t* GetContactID(MCONTACT hContact, char *szProto);
+wchar_t* GetContactID(MCONTACT hContact);
+wchar_t* GetContactID(MCONTACT hContact, char *szProto);
MCONTACT GetContactFromID(wchar_t *szID, char *szProto);
MCONTACT GetContactFromID(wchar_t *szID, wchar_t *szProto);
+void CreateToolTip(HWND target, wchar_t *tooltip, LPARAM width);
+
#endif
\ No newline at end of file |