From 75caaec79fb0072f65a830b48f85d763b386a22f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 18 Mar 2019 21:33:18 +0300 Subject: Notes & Reminders: - options dialog rewritten using UI classes; - GUI logic changed, now all Reminders dialogs carry have attached structures; - fixes #1660 ([Sticky Notes and Reminders] Slight change in behaviour of plugin settings) --- plugins/NotesAndReminders/src/options.cpp | 335 ++++++++++++---------------- plugins/NotesAndReminders/src/reminders.cpp | 285 +++++++++++------------ plugins/NotesAndReminders/src/stdafx.h | 3 - 3 files changed, 277 insertions(+), 346 deletions(-) (limited to 'plugins/NotesAndReminders/src') diff --git a/plugins/NotesAndReminders/src/options.cpp b/plugins/NotesAndReminders/src/options.cpp index 97d6dd6905..3c6805cabe 100644 --- a/plugins/NotesAndReminders/src/options.cpp +++ b/plugins/NotesAndReminders/src/options.cpp @@ -117,14 +117,12 @@ static void InitFonts() hCaptionFont = CreateFontIndirectW(&lfCaption); } - static int FS_FontsChanged(WPARAM, LPARAM) { InitFonts(); SaveNotes(); - LoadNotes(FALSE); - + LoadNotes(false); return 0; } @@ -136,8 +134,7 @@ static int FS_ColorChanged(WPARAM, LPARAM) BodyColor = g_plugin.getDword(colourOptionsList[0].szSettingName, colourOptionsList[0].defColour); SaveNotes(); - LoadNotes(FALSE); - + LoadNotes(false); return 0; } @@ -160,16 +157,14 @@ void RegisterFontServiceFonts() mir_snprintf(szTemp, "Font%d", i); strncpy_s(fontid.setting, szTemp, _countof(fontid.setting)); wcsncpy_s(fontid.name, fontOptionsList[i].szDescr, _TRUNCATE); - fontid.deffontsettings.colour = fontOptionsList[i].defColour; + fontid.deffontsettings.colour = fontOptionsList[i].defColour; fontid.deffontsettings.size = (char)-MulDiv(fontOptionsList[i].defSize, nFontScale, 72); - //fontid.deffontsettings.size = fontOptionsList[i].defSize; - fontid.deffontsettings.style = fontOptionsList[i].defStyle; fontid.deffontsettings.charset = DEFAULT_CHARSET; + wcsncpy_s(fontid.deffontsettings.szFace, fontOptionsList[i].szDefFace, _TRUNCATE); wcsncpy_s(fontid.backgroundName, fontOptionsList[i].szBkgName, _TRUNCATE); - g_plugin.addFont(&fontid); } @@ -197,198 +192,168 @@ void LoadNRFont(int i, LOGFONT *lf, COLORREF *colour) *colour = col; } -static void FillValues(HWND hdlg) +///////////////////////////////////////////////////////////////////////////////////////// + +class CNROptionsDlg : public CDlgBase { - CheckDlgButton(hdlg, IDC_CHECK_HIDENOTES, g_plugin.bShowNotesAtStart ? BST_UNCHECKED : BST_CHECKED); // reversed - CheckDlgButton(hdlg, IDC_CHECK_MENUS, g_plugin.bAddContListMI ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_BUTTONS, g_plugin.bShowNoteButtons ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_SCROLLBARS, g_plugin.bShowScrollbar ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_CLOSE, g_plugin.bCloseAfterAddReminder ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_MSI, g_plugin.bUseMSI ? BST_CHECKED : BST_UNCHECKED); + void FillValues() + { + chkHide.SetState(!g_plugin.bShowNotesAtStart); // reversed - SetDlgItemInt(hdlg, IDC_EDIT_WIDTH, g_NoteWidth, FALSE); - SetDlgItemInt(hdlg, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE); + SetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, g_NoteWidth, FALSE); + SetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE); - SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_SETCURSEL, (WPARAM)(g_NoteTitleDate ? g_NoteTitleDate - 1 : SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_GETCOUNT, 0, 0) - 1), 0); - SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_SETCURSEL, (WPARAM)(g_NoteTitleTime ? g_NoteTitleTime - 1 : SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_GETCOUNT, 0, 0) - 1), 0); + cmbDate.SetCurSel(g_NoteTitleDate ? g_NoteTitleDate - 1 : cmbDate.GetCount()-1); + cmbTime.SetCurSel(g_NoteTitleTime ? g_NoteTitleTime - 1 : cmbTime.GetCount()-1); - SendDlgItemMessage(hdlg, IDC_SLIDER_TRANSPARENCY, TBM_SETPOS, TRUE, 255 - g_Transparency); -} + SendDlgItemMessage(m_hwnd, IDC_SLIDER_TRANSPARENCY, TBM_SETPOS, TRUE, 255 - g_Transparency); + } -static INT_PTR CALLBACK DlgProcOptions(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - SendDlgItemMessage(hdlg, IDC_SLIDER_TRANSPARENCY, TBM_SETRANGE, TRUE, MAKELONG(0, 255 - MIN_ALPHA)); + CCtrlEdit edtBrowser, edtEmail; + CCtrlCombo cmbDate, cmbTime; + CCtrlCheck chkHide, chkMenus, chkButtons, chkScroll, chkClose, chkMSI; + CCtrlButton btnBrowse, btnReset; + +public: + CNROptionsDlg() : + CDlgBase(g_plugin, IDD_STNOTEOPTIONS), + edtEmail(this, IDC_EDIT_EMAILSMS), + edtBrowser(this, IDC_EDIT_ALTBROWSER), + cmbDate(this, IDC_COMBODATE), + cmbTime(this, IDC_COMBOTIME), + chkMSI(this, IDC_CHECK_MSI), + chkHide(this, IDC_CHECK_HIDENOTES), + chkClose(this, IDC_CHECK_CLOSE), + chkMenus(this, IDC_CHECK_MENUS), + chkScroll(this, IDC_CHECK_SCROLLBARS), + chkButtons(this, IDC_CHECK_BUTTONS), + btnReset(this, IDC_BUTTON_RESET), + btnBrowse(this, IDC_BTN_BROWSEBROWSER) + { + btnReset.OnClick = Callback(this, &CNROptionsDlg::onClick_Reset); + btnBrowse.OnClick = Callback(this, &CNROptionsDlg::onClick_Browse); + + CreateLink(chkMSI, g_plugin.bUseMSI); + CreateLink(chkClose, g_plugin.bCloseAfterAddReminder); + CreateLink(chkMenus, g_plugin.bAddContListMI); + CreateLink(chkScroll, g_plugin.bShowScrollbar); + CreateLink(chkButtons, g_plugin.bShowNoteButtons); + } + + bool OnInitDialog() override + { + SendDlgItemMessage(m_hwnd, IDC_SLIDER_TRANSPARENCY, TBM_SETRANGE, TRUE, MAKELONG(0, 255 - MIN_ALPHA)); - SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_RESETCONTENT, 0, 0); + cmbDate.ResetContent(); for (auto &it : dateFormats) - SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_ADDSTRING, 0, (LPARAM)it.lpszUI); + cmbDate.AddString(it.lpszUI); + cmbDate.AddString(TranslateT("None")); + + cmbTime.ResetContent(); for (auto &it : timeFormats) - SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_ADDSTRING, 0, (LPARAM)it.lpszUI); - SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_ADDSTRING, 0, (LPARAM)TranslateT("None")); - SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_ADDSTRING, 0, (LPARAM)TranslateT("None")); + cmbTime.AddString(it.lpszUI); + cmbTime.AddString(TranslateT("None")); - FillValues(hdlg); + FillValues(); if (g_RemindSMS) - SetDlgItemTextA(hdlg, IDC_EDIT_EMAILSMS, g_RemindSMS); + edtEmail.SetTextA(g_RemindSMS); else - SetDlgItemTextA(hdlg, IDC_EDIT_EMAILSMS, ""); - - SetDlgItemTextA(hdlg, IDC_EDIT_ALTBROWSER, g_lpszAltBrowser ? g_lpszAltBrowser : ""); - return TRUE; - - case WM_HSCROLL: - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - return TRUE; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - g_plugin.bShowNotesAtStart = IsDlgButtonChecked(hdlg, IDC_CHECK_HIDENOTES) == 0; // reversed - g_plugin.bShowNoteButtons = IsDlgButtonChecked(hdlg, IDC_CHECK_BUTTONS) != 0; - g_plugin.bShowScrollbar = IsDlgButtonChecked(hdlg, IDC_CHECK_SCROLLBARS) != 0; - g_plugin.bAddContListMI = IsDlgButtonChecked(hdlg, IDC_CHECK_MENUS) != 0; - - BOOL LB; - g_NoteWidth = GetDlgItemInt(hdlg, IDC_EDIT_WIDTH, &LB, FALSE); - g_NoteHeight = GetDlgItemInt(hdlg, IDC_EDIT_HEIGHT, &LB, FALSE); - g_Transparency = 255 - SendDlgItemMessage(hdlg, IDC_SLIDER_TRANSPARENCY, TBM_GETPOS, 0, 0); - - g_plugin.bCloseAfterAddReminder = IsDlgButtonChecked(hdlg, IDC_CHECK_CLOSE) != 0; - g_plugin.bUseMSI = IsDlgButtonChecked(hdlg, IDC_CHECK_MSI) != 0; - - g_NoteTitleDate = (SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_GETCURSEL, 0, 0) + 1) % SendDlgItemMessage(hdlg, IDC_COMBODATE, CB_GETCOUNT, 0, 0); - g_NoteTitleTime = (SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_GETCURSEL, 0, 0) + 1) % SendDlgItemMessage(hdlg, IDC_COMBOTIME, CB_GETCOUNT, 0, 0); - if (g_NoteWidth < 179) { - g_NoteWidth = 179; - SetDlgItemInt(hdlg, IDC_EDIT_WIDTH, g_NoteWidth, FALSE); - } - if (g_NoteHeight < 35) { - g_NoteHeight = 35; - SetDlgItemInt(hdlg, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE); - } - WORD SzT = (WORD)SendDlgItemMessage(hdlg, IDC_EDIT_EMAILSMS, WM_GETTEXTLENGTH, 0, 0); - if (SzT != 0) { - g_RemindSMS = (char*)realloc(g_RemindSMS, SzT + 1); - GetDlgItemTextA(hdlg, IDC_EDIT_EMAILSMS, g_RemindSMS, SzT + 1); - } - char *P = g_RemindSMS; - db_set_blob(0, MODULENAME, "RemindEmail", P, SzT); - - SzT = (WORD)SendDlgItemMessage(hdlg, IDC_EDIT_ALTBROWSER, WM_GETTEXTLENGTH, 0, 0); - if (SzT != 0) { - g_lpszAltBrowser = (char*)mir_realloc(g_lpszAltBrowser, SzT + 1); - GetDlgItemTextA(hdlg, IDC_EDIT_ALTBROWSER, g_lpszAltBrowser, SzT + 1); - rtrim(g_lpszAltBrowser); - if (!*g_lpszAltBrowser) { - mir_free(g_lpszAltBrowser); - g_lpszAltBrowser = nullptr; - } - } - else if (g_lpszAltBrowser) { - mir_free(g_lpszAltBrowser); - g_lpszAltBrowser = nullptr; - } - SetDlgItemTextA(hdlg, IDC_EDIT_ALTBROWSER, g_lpszAltBrowser ? g_lpszAltBrowser : ""); - if (g_lpszAltBrowser) - g_plugin.setString("AltBrowser", g_lpszAltBrowser); - else - g_plugin.delSetting("AltBrowser"); - - g_plugin.setDword("NoteWidth", g_NoteWidth); - g_plugin.setDword("NoteHeight", g_NoteHeight); - g_plugin.setDword("Transparency", g_Transparency); - g_plugin.setDword("NoteTitleDate", g_NoteTitleDate); - g_plugin.setDword("NoteTitleTime", g_NoteTitleTime); - - SaveNotes(); - LoadNotes(FALSE); - return TRUE; - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_BTN_BROWSEBROWSER: - { - wchar_t s[MAX_PATH]; - GetDlgItemText(hdlg, IDC_EDIT_ALTBROWSER, s, _countof(s)); - - OPENFILENAME ofn = {0}; - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hdlg; - ofn.lpstrFilter = TranslateT("Executable Files\0*.exe\0All Files\0*.*\0\0"); - ofn.lpstrFile = s; - ofn.nMaxFile = _countof(s); - ofn.lpstrTitle = TranslateT("Select Executable"); - ofn.lpstrInitialDir = L"."; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_ENABLESIZING | OFN_DONTADDTORECENT; - - if (GetOpenFileName(&ofn)) { - SetDlgItemText(hdlg, IDC_EDIT_ALTBROWSER, s); - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - } - } - break; - - case IDC_BUTTON_RESET: - SAFE_FREE((void**)&g_RemindSMS); - SetDlgItemTextA(hdlg, IDC_EDIT_EMAILSMS, ""); - SetDlgItemTextA(hdlg, IDC_EDIT_ALTBROWSER, ""); - - replaceStr(g_lpszAltBrowser, nullptr); - - g_plugin.bShowNotesAtStart = g_plugin.bAddContListMI = g_plugin.bShowScrollbar = g_plugin.bShowNoteButtons = true; - g_plugin.bCloseAfterAddReminder = g_plugin.bUseMSI = true; - - g_NoteTitleDate = 1; - g_NoteTitleTime = 1; + edtEmail.SetTextA(""); + + edtBrowser.SetTextA(g_lpszAltBrowser ? g_lpszAltBrowser : ""); + return true; + } + + bool OnApply() override + { + g_plugin.bShowNotesAtStart = !chkHide.GetState(); // reversed + + BOOL LB; + g_NoteWidth = GetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, &LB, FALSE); + g_NoteHeight = GetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, &LB, FALSE); + g_Transparency = 255 - SendDlgItemMessage(m_hwnd, IDC_SLIDER_TRANSPARENCY, TBM_GETPOS, 0, 0); + + g_NoteTitleDate = (cmbDate.GetCurSel()+1) % cmbDate.GetCount(); + g_NoteTitleTime = (cmbTime.GetCurSel()+1) % cmbTime.GetCount(); + if (g_NoteWidth < 179) { g_NoteWidth = 179; + SetDlgItemInt(m_hwnd, IDC_EDIT_WIDTH, g_NoteWidth, FALSE); + } + + if (g_NoteHeight < 35) { g_NoteHeight = 35; - g_Transparency = 255; - FillValues(hdlg); - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); // JK optim - return TRUE; - - case IDC_EDIT_ALTBROWSER: - case IDC_EDIT_EMAILSMS: - case IDC_EDIT_WIDTH: - case IDC_EDIT_HEIGHT: - if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; - - case IDC_COMBODATE: - case IDC_COMBOTIME: - if (HIWORD(wParam) == CBN_SELCHANGE) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; - - case IDC_CHECK_SCROLLBARS: - case IDC_CHECK_BUTTONS: - case IDC_CHECK_HIDENOTES: - case IDC_CHECK_MENUS: - case IDC_CHECK_CLOSE: - case IDC_CHECK_MSI: - if (HIWORD(wParam) == BN_CLICKED) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; + SetDlgItemInt(m_hwnd, IDC_EDIT_HEIGHT, g_NoteHeight, FALSE); + } + + mir_free(g_RemindSMS); + g_RemindSMS = edtEmail.GetTextA(); + g_plugin.setString("RemindEmail", g_RemindSMS); + + mir_free(g_lpszAltBrowser); + g_lpszAltBrowser = edtBrowser.GetTextA(); + g_plugin.setString("AltBrowser", g_lpszAltBrowser); + + g_plugin.setDword("NoteWidth", g_NoteWidth); + g_plugin.setDword("NoteHeight", g_NoteHeight); + g_plugin.setDword("Transparency", g_Transparency); + g_plugin.setDword("NoteTitleDate", g_NoteTitleDate); + g_plugin.setDword("NoteTitleTime", g_NoteTitleTime); + + SaveNotes(); + LoadNotes(false); + return true; + } + + void onClick_Browse(CCtrlButton*) + { + wchar_t s[MAX_PATH]; + GetDlgItemText(m_hwnd, IDC_EDIT_ALTBROWSER, s, _countof(s)); + + OPENFILENAME ofn = {0}; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = m_hwnd; + ofn.lpstrFilter = TranslateT("Executable Files\0*.exe\0All Files\0*.*\0\0"); + ofn.lpstrFile = s; + ofn.nMaxFile = _countof(s); + ofn.lpstrTitle = TranslateT("Select Executable"); + ofn.lpstrInitialDir = L"."; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_ENABLESIZING | OFN_DONTADDTORECENT; + + if (GetOpenFileNameW(&ofn)) { + SetDlgItemText(m_hwnd, IDC_EDIT_ALTBROWSER, s); + NotifyChange(); } } - return FALSE; -} + + void onClick_Reset(CCtrlButton*) + { + edtEmail.SetTextA(""); + edtBrowser.SetTextA(""); + + replaceStr(g_RemindSMS, nullptr); + replaceStr(g_lpszAltBrowser, nullptr); + + g_plugin.bShowNotesAtStart = g_plugin.bAddContListMI = g_plugin.bShowScrollbar = g_plugin.bShowNoteButtons = true; + g_plugin.bCloseAfterAddReminder = g_plugin.bUseMSI = true; + + g_NoteTitleDate = 1; + g_NoteTitleTime = 1; + g_NoteWidth = 179; + g_NoteHeight = 35; + g_Transparency = 255; + FillValues(); + NotifyChange(); + } +}; int OnOptInitialise(WPARAM w, LPARAM) { OPTIONSDIALOGPAGE odp = {}; odp.position = 900002000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_STNOTEOPTIONS); odp.szTitle.a = SECTIONNAME; odp.szGroup.a = LPGEN("Plugins"); - odp.pfnDlgProc = DlgProcOptions; + odp.pDialog = new CNROptionsDlg(); g_plugin.addOptions(w, &odp); return 0; } @@ -397,19 +362,7 @@ int OnOptInitialise(WPARAM w, LPARAM) void InitSettings(void) { - void *P = nullptr; - short Sz1 = MAX_PATH; - - ReadSettingBlob(0, MODULENAME, "RemindEmail", (WORD*)&Sz1, &P); - if (!(Sz1 && P)) - g_RemindSMS = nullptr; - else { - g_RemindSMS = (char*)malloc(Sz1 + 1); - memcpy(g_RemindSMS, P, Sz1); - g_RemindSMS[Sz1] = 0; - FreeSettingBlob(Sz1, P); - } - + g_RemindSMS = g_plugin.getStringA("RemindEmail"); g_lpszAltBrowser = g_plugin.getStringA("AltBrowser"); g_NoteWidth = g_plugin.getDword("NoteWidth", 179); diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp index f98a4c235f..747dbc0277 100644 --- a/plugins/NotesAndReminders/src/reminders.cpp +++ b/plugins/NotesAndReminders/src/reminders.cpp @@ -36,7 +36,7 @@ #define IDM_DELETEALLREMINDERS 40003 #define WM_RELOAD (WM_USER + 100) -#define NOTIFY_LIST() if (ListReminderVisible) PostMessage(LV,WM_RELOAD,0,0) +#define NOTIFY_LIST() if (bListReminderVisible) PostMessage(LV,WM_RELOAD,0,0) ///////////////////////////////////////////////////////////////////////////////////////// @@ -47,13 +47,20 @@ struct REMINDERDATA HWND handle; DWORD uid; char* Reminder; - ULARGE_INTEGER When; // FILETIME in UTC + ULARGE_INTEGER Orig, When; // FILETIME in UTC UINT RepeatSound; UINT RepeatSoundTTL; int SoundSel; // -1 if sound disabled bool RemVisible; bool SystemEventQueued; + REMINDERDATA() + { + SYSTEMTIME tm; + GetSystemTime(&tm); + SystemTimeToFileTime(&tm, (FILETIME*)&Orig); + } + ~REMINDERDATA() { // remove pending system event @@ -72,10 +79,9 @@ static int ReminderSortCb(const REMINDERDATA *v1, const REMINDERDATA *v2) static LIST arReminders(1, ReminderSortCb); +static bool bNewReminderVisible = false; +static bool bListReminderVisible = false; static UINT QueuedReminderCount = 0; -static bool ListReminderVisible = false; -static int NewReminderVisible = 0; -static REMINDERDATA *pEditReminder = nullptr; static HWND LV; int WS_Send(SOCKET s, char *data, int datalen); @@ -110,15 +116,6 @@ static REMINDERDATA* FindReminder(DWORD uid) return nullptr; } -static REMINDERDATA* FindReminder(HWND hwndDlg) -{ - for (auto pReminder : arReminders) - if (pReminder->handle == hwndDlg) - return pReminder; - - return nullptr; -} - static DWORD CreateUid() { if (!arReminders.getCount()) @@ -292,19 +289,16 @@ void LoadReminders(void) } else { // old format (for DB backward compatibility) - if (!DelPos) continue; DelPos[0] = 0; // convert time_t to (local) FILETIME { - SYSTEMTIME tm; - struct tm *stm; - time_t tt; + time_t tt = (time_t)strtoul(Value, nullptr, 10); + struct tm *stm = localtime(&tt); - tt = (time_t)strtoul(Value, nullptr, 10); - stm = localtime(&tt); + SYSTEMTIME tm; tm.wDayOfWeek = 0; tm.wSecond = 0; tm.wMilliseconds = 0; @@ -315,6 +309,8 @@ void LoadReminders(void) tm.wMonth = stm->tm_mon + 1; tm.wDay = stm->tm_mday; SystemTimeToFileTime(&tm, (FILETIME*)&rem.When); + + rem.Orig = rem.When; } TVal = DelPos + 1; rem.Reminder = _strdup(TVal); @@ -350,14 +346,6 @@ static void DeleteReminder(REMINDERDATA *p) } } -void CloseReminderList() -{ - if (ListReminderVisible) { - DestroyWindow(LV); - ListReminderVisible = false; - } -} - static void PurgeReminderTree() { for (auto &pt : arReminders) // empty whole tree @@ -746,13 +734,14 @@ static void PopulateTimeCombo(HWND hwndDlg, UINT nIDTime, BOOL bRelative, const // NOTE: may seem like a bit excessive time converstion and handling, but this is done in order // to gracefully handle crossing daylight saving boundaries + SendDlgItemMessage(hwndDlg, nIDTime, CB_RESETCONTENT, 0, 0); + SYSTEMTIME tm2; ULARGE_INTEGER li; wchar_t s[64]; const ULONGLONG MinutesToFileTime = (ULONGLONG)60 * FILETIME_TICKS_PER_SEC; if (!bRelative) { - SendDlgItemMessage(hwndDlg, nIDTime, CB_RESETCONTENT, 0, 0); // ensure that we start on midnight local time SystemTimeToTzSpecificLocalTime(nullptr, (SYSTEMTIME*)tmUtc, &tm2); @@ -780,14 +769,10 @@ static void PopulateTimeCombo(HWND hwndDlg, UINT nIDTime, BOOL bRelative, const if (tm2.wHour == 23 && tm2.wMinute >= 30) break; } - - return; } //////////////////////////////////////////////////////////////////////////////////////// - SendDlgItemMessage(hwndDlg, nIDTime, CB_RESETCONTENT, 0, 0); - SystemTimeToFileTime(tmUtc, (FILETIME*)&li); ULONGLONG ref = li.QuadPart; @@ -1202,18 +1187,20 @@ static void OnDateChanged(HWND hwndDlg, UINT nDateID, UINT nTimeID, UINT nRefTim ReformatTimeInput(hwndDlg, nTimeID, nRefTimeID, h, m, &Date); } - static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam) { + REMINDERDATA *pReminder = (REMINDERDATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (Message) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - SYSTEMTIME tm; - ULARGE_INTEGER li; - GetSystemTime(&tm); - SystemTimeToFileTime(&tm, (FILETIME*)&li); + pReminder = (REMINDERDATA*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - TranslateDialogDefault(hwndDlg); + SYSTEMTIME tm; + ULARGE_INTEGER li = pReminder->Orig; + FileTimeToSystemTime((FILETIME*)&li, &tm); // save reference time in hidden control, is needed when adding reminder to properly detect if speicifed // time wrapped around to tomorrow or not (dialog could in theory be open for a longer period of time @@ -1247,6 +1234,8 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM SendDlgItemMessage(hwndDlg, IDC_TIMEAGAIN, CB_SETCURSEL, 0, 0); + if (pReminder->Reminder) + SetDlgItemTextA(hwndDlg, IDC_REMDATA, pReminder->Reminder); return TRUE; } case WM_NCDESTROY: @@ -1266,11 +1255,8 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM break; case WM_CLOSE: - if (auto *pReminder = FindReminder(hwndDlg)) { - DeleteReminder(pReminder); - JustSaveReminders(); - } - + DeleteReminder(pReminder); + JustSaveReminders(); NOTIFY_LIST(); DestroyWindow(hwndDlg); return TRUE; @@ -1340,83 +1326,80 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM return TRUE; case IDC_DISMISS: - if (auto *pReminder = FindReminder(hwndDlg)) { - DeleteReminder(pReminder); - JustSaveReminders(); - } - + DeleteReminder(pReminder); + JustSaveReminders(); NOTIFY_LIST(); DestroyWindow(hwndDlg); return TRUE; case IDC_REMINDAGAIN: - if (auto *pReminder = FindReminder(hwndDlg)) { - if (IsDlgButtonChecked(hwndDlg, IDC_AFTER) == BST_CHECKED) { - // delta time - ULONGLONG TT; - SYSTEMTIME tm; - ULARGE_INTEGER li; - - GetSystemTime(&tm); - SystemTimeToFileTime(&tm, (FILETIME*)&li); - - int n = SendDlgItemMessage(hwndDlg, IDC_REMINDAGAININ, CB_GETCURSEL, 0, 0); - if (n != CB_ERR) { - TT = SendDlgItemMessage(hwndDlg, IDC_REMINDAGAININ, CB_GETITEMDATA, n, 0) * 60; - if (TT >= 24 * 3600) { - // selection is 1 day or more, take daylight saving boundaries into consideration - // (ie. 24 hour might actually be 23 or 25, in order for reminder to pop up at the - // same time tomorrow) - SYSTEMTIME tm2, tm3; - ULARGE_INTEGER li2 = li; - FileTimeToTzLocalST((FILETIME*)&li2, &tm2); - li2.QuadPart += (TT * FILETIME_TICKS_PER_SEC); - FileTimeToTzLocalST((FILETIME*)&li2, &tm3); - if (tm2.wHour != tm3.wHour || tm2.wMinute != tm3.wMinute) { - // boundary crossed - - // do a quick and dirty sanity check that times not more than 2 hours apart - if (abs((int)(tm3.wHour * 60 + tm3.wMinute) - (int)(tm2.wHour * 60 + tm2.wMinute)) <= 120) { - // adjust TT so that same HH:MM is set - tm3.wHour = tm2.wHour; - tm3.wMinute = tm2.wMinute; - TzLocalSTToFileTime(&tm3, (FILETIME*)&li2); - TT = (li2.QuadPart - li.QuadPart) / FILETIME_TICKS_PER_SEC; - } + if (IsDlgButtonChecked(hwndDlg, IDC_AFTER) == BST_CHECKED) { + // delta time + ULONGLONG TT; + SYSTEMTIME tm; + ULARGE_INTEGER li; + + GetSystemTime(&tm); + SystemTimeToFileTime(&tm, (FILETIME*)&li); + + int n = SendDlgItemMessage(hwndDlg, IDC_REMINDAGAININ, CB_GETCURSEL, 0, 0); + if (n != CB_ERR) { + TT = SendDlgItemMessage(hwndDlg, IDC_REMINDAGAININ, CB_GETITEMDATA, n, 0) * 60; + if (TT >= 24 * 3600) { + // selection is 1 day or more, take daylight saving boundaries into consideration + // (ie. 24 hour might actually be 23 or 25, in order for reminder to pop up at the + // same time tomorrow) + SYSTEMTIME tm2, tm3; + ULARGE_INTEGER li2 = li; + FileTimeToTzLocalST((FILETIME*)&li2, &tm2); + li2.QuadPart += (TT * FILETIME_TICKS_PER_SEC); + FileTimeToTzLocalST((FILETIME*)&li2, &tm3); + if (tm2.wHour != tm3.wHour || tm2.wMinute != tm3.wMinute) { + // boundary crossed + + // do a quick and dirty sanity check that times not more than 2 hours apart + if (abs((int)(tm3.wHour * 60 + tm3.wMinute) - (int)(tm2.wHour * 60 + tm2.wMinute)) <= 120) { + // adjust TT so that same HH:MM is set + tm3.wHour = tm2.wHour; + tm3.wMinute = tm2.wMinute; + TzLocalSTToFileTime(&tm3, (FILETIME*)&li2); + TT = (li2.QuadPart - li.QuadPart) / FILETIME_TICKS_PER_SEC; } } } - else { - // parse user input - wchar_t s[32]; - GetDlgItemText(hwndDlg, IDC_REMINDAGAININ, s, _countof(s)); - - int h = 0, m = 0; - ParseTime(s, &h, &m, TRUE, TRUE); - m += h * 60; - if (!m) { - MessageBox(hwndDlg, TranslateT("The specified time offset is invalid."), _A2W(SECTIONNAME), MB_OK | MB_ICONWARNING); - return TRUE; - } - - TT = m * 60; + } + else { + // parse user input + wchar_t s[32]; + GetDlgItemText(hwndDlg, IDC_REMINDAGAININ, s, _countof(s)); + + int h = 0, m = 0; + ParseTime(s, &h, &m, TRUE, TRUE); + m += h * 60; + if (!m) { + MessageBox(hwndDlg, TranslateT("The specified time offset is invalid."), _A2W(SECTIONNAME), MB_OK | MB_ICONWARNING); + return TRUE; } - pReminder->When = li; - pReminder->When.QuadPart += (TT * FILETIME_TICKS_PER_SEC); + TT = m * 60; } - else if (IsDlgButtonChecked(hwndDlg, IDC_ONDATE) == BST_CHECKED) { - SYSTEMTIME Date; - SendDlgItemMessage(hwndDlg, IDC_DATEAGAIN, DTM_GETSYSTEMTIME, 0, (LPARAM)&Date); + pReminder->When = li; + pReminder->When.QuadPart += (TT * FILETIME_TICKS_PER_SEC); + } + else if (IsDlgButtonChecked(hwndDlg, IDC_ONDATE) == BST_CHECKED) { + SYSTEMTIME Date; - if (!GetTriggerTime(hwndDlg, IDC_TIMEAGAIN, IDC_REFTIME, &Date)) - break; + SendDlgItemMessage(hwndDlg, IDC_DATEAGAIN, DTM_GETSYSTEMTIME, 0, (LPARAM)&Date); - SystemTimeToFileTime(&Date, (FILETIME*)&pReminder->When); - } + if (!GetTriggerTime(hwndDlg, IDC_TIMEAGAIN, IDC_REFTIME, &Date)) + break; + + SystemTimeToFileTime(&Date, (FILETIME*)&pReminder->When); + } - // update reminder text + // update reminder text + { char *ReminderText = nullptr; int SzT = SendDlgItemMessage(hwndDlg, IDC_REMDATA, WM_GETTEXTLENGTH, 0, 0); if (SzT) { @@ -1428,15 +1411,15 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM if (pReminder->Reminder) free(pReminder->Reminder); pReminder->Reminder = ReminderText; + } - pReminder->RemVisible = FALSE; - pReminder->handle = nullptr; + pReminder->RemVisible = FALSE; + pReminder->handle = nullptr; - // re-insert tree item sorted - arReminders.remove(pReminder); - arReminders.insert(pReminder); - JustSaveReminders(); - } + // re-insert tree item sorted + arReminders.remove(pReminder); + arReminders.insert(pReminder); + JustSaveReminders(); NOTIFY_LIST(); DestroyWindow(hwndDlg); @@ -1444,8 +1427,7 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM case IDC_NONE: // create note from remainder - if (auto *pReminder = FindReminder(hwndDlg)) { - // get up-to-date reminder text + { char *ReminderText = nullptr; int SzT = SendDlgItemMessage(hwndDlg, IDC_REMDATA, WM_GETTEXTLENGTH, 0, 0); if (SzT) { @@ -1465,14 +1447,19 @@ static INT_PTR CALLBACK DlgProcNotifyReminder(HWND hwndDlg, UINT Message, WPARAM static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam) { HICON hIcon = nullptr; + REMINDERDATA *pEditReminder = (REMINDERDATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (Message) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); ULARGE_INTEGER li; SYSTEMTIME tm; + + pEditReminder = (REMINDERDATA*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - if (NewReminderVisible == 2) { + if (pEditReminder) { // opening the edit reminder dialog (uses same dialog resource as add reminder) SetWindowText(hwndDlg, TranslateT("Reminder")); SetDlgItemText(hwndDlg, IDC_ADDREMINDER, TranslateT("&Update Reminder")); @@ -1493,7 +1480,7 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP mir_snwprintf(s, L"%I64x", li.QuadPart); SetDlgItemText(hwndDlg, IDC_REFTIME, s); - PopulateTimeCombo(hwndDlg, IDC_TIME, NewReminderVisible != 2, &tm); + PopulateTimeCombo(hwndDlg, IDC_TIME, pEditReminder == nullptr, &tm); FileTimeToTzLocalST((FILETIME*)&li, &tm); @@ -1503,7 +1490,7 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP SendDlgItemMessage(hwndDlg, IDC_REMINDER, EM_LIMITTEXT, MAX_REMINDER_LEN, 0); - if (NewReminderVisible == 2) { + if (pEditReminder) { mir_snwprintf(s, L"%02d:%02d", tm.wHour, tm.wMinute); // search for preset first @@ -1550,7 +1537,7 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP n = SendDlgItemMessage(hwndDlg, IDC_COMBO_REPEATSND, CB_ADDSTRING, 0, (LPARAM)s); SendDlgItemMessage(hwndDlg, IDC_COMBO_REPEATSND, CB_SETITEMDATA, n, (LPARAM)60); - if (NewReminderVisible == 2 && pEditReminder->RepeatSound) { + if (pEditReminder && pEditReminder->RepeatSound) { mir_snwprintf(s, L"%s %d %s", lpszEvery, pEditReminder->RepeatSound, lpszSeconds); SetDlgItemText(hwndDlg, IDC_COMBO_REPEATSND, s); SendDlgItemMessage(hwndDlg, IDC_COMBO_REPEATSND, CB_SETCURSEL, SendDlgItemMessage(hwndDlg, IDC_COMBO_REPEATSND, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)s), 0); @@ -1567,7 +1554,7 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP n = SendDlgItemMessage(hwndDlg, IDC_COMBO_SOUND, CB_ADDSTRING, 0, (LPARAM)TranslateT("None")); SendDlgItemMessage(hwndDlg, IDC_COMBO_SOUND, CB_SETITEMDATA, n, (LPARAM)-1); - if (NewReminderVisible == 2 && pEditReminder->SoundSel) { + if (pEditReminder && pEditReminder->SoundSel) { const UINT n2 = pEditReminder->SoundSel < 0 ? 3 : pEditReminder->SoundSel; SendDlgItemMessage(hwndDlg, IDC_COMBO_SOUND, CB_SETCURSEL, n2, 0); } @@ -1576,12 +1563,12 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP hIcon = IcoLib_GetIconByHandle(iconList[12].hIcolib); SendDlgItemMessage(hwndDlg, IDC_BTN_PLAYSOUND, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon); - if (NewReminderVisible == 2 && pEditReminder->SoundSel) { + if (pEditReminder && pEditReminder->SoundSel) { EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PLAYSOUND), pEditReminder->SoundSel >= 0); EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_REPEATSND), pEditReminder->SoundSel >= 0); } - if (NewReminderVisible == 2) + if (pEditReminder) SetFocus(GetDlgItem(hwndDlg, IDC_ADDREMINDER)); else SetFocus(GetDlgItem(hwndDlg, IDC_REMINDER)); @@ -1593,12 +1580,10 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP return TRUE; case WM_CLOSE: - if (NewReminderVisible == 2) + if (pEditReminder) pEditReminder->RemVisible = FALSE; DestroyWindow(hwndDlg); - NewReminderVisible = FALSE; - pEditReminder = nullptr; return TRUE; case WM_NOTIFY: @@ -1661,12 +1646,10 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP return TRUE; case IDC_CLOSE: - if (NewReminderVisible == 2) + if (pEditReminder) pEditReminder->RemVisible = FALSE; DestroyWindow(hwndDlg); - NewReminderVisible = FALSE; - pEditReminder = nullptr; return TRUE; case IDC_VIEWREMINDERS: @@ -1691,9 +1674,9 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP GetDlgItemTextA(hwndDlg, IDC_REMINDER, ReminderText, SzT + 1); } - if (NewReminderVisible != 2) { + if (!pEditReminder) { // new reminder - REMINDERDATA *TempRem = (REMINDERDATA*)malloc(sizeof(REMINDERDATA)); + REMINDERDATA *TempRem = new REMINDERDATA(); TempRem->uid = CreateUid(); SystemTimeToFileTime(&Date, (FILETIME*)&TempRem->When); TempRem->Reminder = ReminderText; @@ -1723,11 +1706,8 @@ static INT_PTR CALLBACK DlgProcNewReminder(HWND hwndDlg, UINT Message, WPARAM wP JustSaveReminders(); NOTIFY_LIST(); - if (g_plugin.bCloseAfterAddReminder || NewReminderVisible == 2) { + if (g_plugin.bCloseAfterAddReminder || pEditReminder) DestroyWindow(hwndDlg); - NewReminderVisible = false; - pEditReminder = nullptr; - } } } break; @@ -1759,15 +1739,12 @@ INT_PTR OpenTriggeredReminder(WPARAM, LPARAM l) pReminder->RemVisible = TRUE; - HWND H = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_NOTIFYREMINDER), nullptr, DlgProcNotifyReminder); + HWND H = CreateDialogParamW(g_plugin.getInst(), MAKEINTRESOURCE(IDD_NOTIFYREMINDER), nullptr, DlgProcNotifyReminder, (LPARAM)pReminder); pReminder->handle = H; mir_snwprintf(S2, L"%s! - %s", TranslateT("Reminder"), S1); SetWindowText(H, S2); - if (pReminder->Reminder) - SetDlgItemTextA(H, IDC_REMDATA, pReminder->Reminder); - BringWindowToTop(H); return 0; } @@ -1777,16 +1754,12 @@ void EditReminder(REMINDERDATA *p) if (!p) return; - if (!NewReminderVisible && !p->SystemEventQueued) { + if (!bNewReminderVisible && !p->SystemEventQueued) { if (!p->RemVisible) { - p->RemVisible = TRUE; - NewReminderVisible = 2; - pEditReminder = p; - CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); - } - else { - BringWindowToTop(p->handle); + p->RemVisible = true; + CreateDialogParamW(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder, (LPARAM)p); } + else BringWindowToTop(p->handle); } } @@ -1993,7 +1966,7 @@ static INT_PTR CALLBACK DlgProcViewReminders(HWND hwndDlg, UINT Message, WPARAM case WM_CLOSE: DestroyWindow(hwndDlg); - ListReminderVisible = FALSE; + bListReminderVisible = FALSE; return TRUE; case WM_NOTIFY: @@ -2035,7 +2008,7 @@ static INT_PTR CALLBACK DlgProcViewReminders(HWND hwndDlg, UINT Message, WPARAM case IDC_CLOSE: DestroyWindow(hwndDlg); - ListReminderVisible = false; + bListReminderVisible = false; return TRUE; case IDM_NEWREMINDER: @@ -2074,10 +2047,18 @@ static INT_PTR CALLBACK DlgProcViewReminders(HWND hwndDlg, UINT Message, WPARAM ///////////////////////////////////////////////////////////////////////////////////////// +void CloseReminderList() +{ + if (bListReminderVisible) { + DestroyWindow(LV); + bListReminderVisible = false; + } +} + INT_PTR PluginMenuCommandNewReminder(WPARAM, LPARAM) { - if (!NewReminderVisible) { - NewReminderVisible = true; + if (!bNewReminderVisible) { + bNewReminderVisible = true; CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ADDREMINDER), nullptr, DlgProcNewReminder); } return 0; @@ -2085,9 +2066,9 @@ INT_PTR PluginMenuCommandNewReminder(WPARAM, LPARAM) INT_PTR PluginMenuCommandViewReminders(WPARAM, LPARAM) { - if (!ListReminderVisible) { + if (!bListReminderVisible) { CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_LISTREMINDERS), nullptr, DlgProcViewReminders); - ListReminderVisible = true; + bListReminderVisible = true; } else BringWindowToTop(LV); return 0; diff --git a/plugins/NotesAndReminders/src/stdafx.h b/plugins/NotesAndReminders/src/stdafx.h index 207896706d..74456c5bad 100644 --- a/plugins/NotesAndReminders/src/stdafx.h +++ b/plugins/NotesAndReminders/src/stdafx.h @@ -84,13 +84,10 @@ extern long BodyColor; extern COLORREF CaptionFontColor, BodyFontColor; extern int g_NoteTitleDate, g_NoteTitleTime; - extern int g_NoteWidth, g_NoteHeight; - extern int g_Transparency; extern char *g_RemindSMS; - extern char *g_lpszAltBrowser; extern int g_reminderListGeom[4]; -- cgit v1.2.3