summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-22 14:00:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-22 14:00:43 +0300
commit79742b2d021b99425d4c9ceac871deb6b8967cee (patch)
tree5359f8d0b4aa64a1e54ebc6436e9a367b4470e31
parent11bd2b97b306e9df877f8adbc3fac971137c2bce (diff)
fixes #1660 completely
-rw-r--r--plugins/NotesAndReminders/src/miscutils.cpp4
-rw-r--r--plugins/NotesAndReminders/src/notes.cpp86
-rw-r--r--plugins/NotesAndReminders/src/reminders.cpp122
-rw-r--r--plugins/NotesAndReminders/src/stdafx.h3
-rw-r--r--plugins/NotesAndReminders/src/version.h2
5 files changed, 83 insertions, 134 deletions
diff --git a/plugins/NotesAndReminders/src/miscutils.cpp b/plugins/NotesAndReminders/src/miscutils.cpp
index 676bfbbed9..8e2197ff55 100644
--- a/plugins/NotesAndReminders/src/miscutils.cpp
+++ b/plugins/NotesAndReminders/src/miscutils.cpp
@@ -38,7 +38,7 @@ void WS_CleanUp()
WSACleanup();
}
-int WS_Send(SOCKET s, char *data, int datalen)
+int WS_Send(SOCKET s, const char *data, int datalen)
{
int rlen;
if ((rlen = send(s, data, datalen, 0)) == SOCKET_ERROR) return FALSE;
@@ -68,7 +68,7 @@ unsigned long WS_ResolveName(char *name, WORD *port, int defaultPort)
return ret;
}
-void Send(char *user, char *host, char *Msg, char *server)
+void Send(char *user, char *host, const char *Msg, char *server)
{
SOCKADDR_IN sockaddr;
WORD port;
diff --git a/plugins/NotesAndReminders/src/notes.cpp b/plugins/NotesAndReminders/src/notes.cpp
index 4ff5c393c9..24e13506a6 100644
--- a/plugins/NotesAndReminders/src/notes.cpp
+++ b/plugins/NotesAndReminders/src/notes.cpp
@@ -88,7 +88,7 @@ struct STICKYNOTE : public MZeroedObject
{
HWND SNHwnd, REHwnd;
BOOL bVisible, bOnTop;
- char *data;
+ CMStringA szText;
ULARGE_INTEGER ID; // FILETIME in UTC
wchar_t *title;
BOOL CustomTitle;
@@ -101,7 +101,6 @@ struct STICKYNOTE : public MZeroedObject
if (SNHwnd)
DestroyWindow(SNHwnd);
SAFE_FREE((void**)&title);
- SAFE_FREE((void**)&data);
if (pCustomFont) {
DeleteObject(pCustomFont->hFont);
free(pCustomFont);
@@ -263,8 +262,8 @@ void BringAllNotesToFront(STICKYNOTE *pActive)
}
}
-// pModified optionally points to the modified note that invoked the JustSaveNotesEx call
-static void JustSaveNotesEx(STICKYNOTE *pModified = nullptr)
+// pModified optionally points to the modified note that invoked the JustSaveNotes call
+static void JustSaveNotes(STICKYNOTE *pModified = nullptr)
{
int i = 0, NotesCount = g_arStickies.getCount();
char ValueName[32];
@@ -274,7 +273,6 @@ static void JustSaveNotesEx(STICKYNOTE *pModified = nullptr)
g_plugin.setDword("NotesData", NotesCount);
for (auto &pNote : g_arStickies) {
- BOOL bDeleteTData = TRUE;
int scrollV = 0;
char *tData = nullptr;
@@ -302,13 +300,9 @@ static void JustSaveNotesEx(STICKYNOTE *pModified = nullptr)
GetWindowTextA(pNote->REHwnd, tData, SzT + 1);
}
- if (pNote == pModified) {
- // update the data of the modified note
- if (pNote->data)
- free(pNote->data);
- pNote->data = tData ? tData : _strdup("");
- bDeleteTData = FALSE;
- }
+ // update the data of the modified note
+ if (pNote == pModified)
+ pNote->szText = tData ? tData : "";
if (!tData) // empty note
SzT = 0;
@@ -348,8 +342,7 @@ static void JustSaveNotesEx(STICKYNOTE *pModified = nullptr)
mir_snprintf(ValueName, "NotesData%d", i++); // we do not reverse notes in DB
db_set_blob(0, MODULENAME, ValueName, szValue.GetBuffer(), szValue.GetLength() + 1);
- if (bDeleteTData)
- SAFE_FREE((void**)&tData);
+ SAFE_FREE((void**)&tData);
// make no save is queued for the note
if (pNote->SNHwnd)
@@ -369,7 +362,7 @@ void OnDeleteNote(HWND hdlg, STICKYNOTE *SN)
{
if (MessageBoxW(hdlg, TranslateT("Are you sure you want to delete this note?"), TranslateT(SECTIONNAME), MB_OKCANCEL) == IDOK) {
g_arStickies.remove(SN);
- JustSaveNotesEx();
+ JustSaveNotes();
NOTIFY_LIST();
}
}
@@ -407,12 +400,12 @@ void ShowHideNotes(void)
}
}
- JustSaveNotesEx();
+ JustSaveNotes();
}
void SaveNotes(void)
{
- JustSaveNotesEx();
+ JustSaveNotes();
g_arStickies.destroy();
}
@@ -577,8 +570,7 @@ static void SetNoteTextControl(STICKYNOTE *SN)
CF.crTextColor = SN->FgColor ? (SN->FgColor & 0xffffff) : BodyFontColor;
SendMessage(SN->REHwnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CF);
- if (SN->data) // TODO: use EM_STREAMIN
- SetWindowTextA(SN->REHwnd, SN->data);
+ SetWindowTextA(SN->REHwnd, SN->szText);
}
@@ -615,7 +607,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
case WM_TIMER:
if (wParam == 1025) {
KillTimer(hdlg, 1025);
- JustSaveNotesEx(SN);
+ JustSaveNotes(SN);
}
break;
@@ -866,7 +858,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SN->BgColor = clrPresets[id - IDM_COLORPRESET_BG].color | 0xff000000;
SendMessage(SN->REHwnd, EM_SETBKGNDCOLOR, 0, SN->BgColor & 0xffffff);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
return FALSE;
}
@@ -880,7 +872,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SendMessage(SN->REHwnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CF);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
return FALSE;
}
@@ -904,7 +896,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SN->BgColor = cc.rgbResult | 0xff000000;
SendMessage(SN->REHwnd, EM_SETBKGNDCOLOR, 0, SN->BgColor & 0xffffff);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
}
break;
@@ -930,7 +922,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SendMessage(SN->REHwnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CF);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
}
break;
@@ -973,7 +965,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SendMessage(SN->REHwnd, WM_SETFONT, (WPARAM)(SN->pCustomFont ? SN->pCustomFont->hFont : hBodyFont), FALSE);
SetNoteTextControl(SN);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
break;
@@ -981,7 +973,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SN->BgColor = 0;
SendMessage(SN->REHwnd, EM_SETBKGNDCOLOR, 0, (LPARAM)BodyColor);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
break;
case ID_TEXTCOLOR_RESET:
@@ -994,7 +986,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SendMessage(SN->REHwnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&CF);
}
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
break;
case ID_FONT_RESET:
@@ -1008,7 +1000,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SendMessage(SN->REHwnd, WM_SETFONT, (WPARAM)hBodyFont, FALSE);
SetNoteTextControl(SN);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
break;
@@ -1021,7 +1013,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SN->title = _wcsdup(s);
SN->CustomTitle = TRUE;
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
}
break;
@@ -1034,7 +1026,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
}
InitNoteTitle(SN);
RedrawWindow(SN->SNHwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
break;
@@ -1045,7 +1037,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
case IDM_HIDENOTE:
SN->bVisible = false;
ShowWindow(hdlg, SW_HIDE);
- JustSaveNotesEx();
+ JustSaveNotes();
break;
case IDM_COPY:
@@ -1072,7 +1064,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
SN->bOnTop = !SN->bOnTop;
SetWindowPos(hdlg, SN->bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
RedrawWindow(hdlg, nullptr, nullptr, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
break;
case ID_CONTEXTMENUNOTEPOPUP_VIEWNOTES:
@@ -1099,7 +1091,7 @@ LRESULT CALLBACK StickyNoteWndProc(HWND hdlg, UINT message, WPARAM wParam, LPARA
return FALSE;
}
-STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER *ID, BOOL bVisible, BOOL bOnTop, int scrollV, COLORREF bgClr, COLORREF fgClr, wchar_t *Title, STICKYNOTEFONT *pCustomFont, BOOL bLoading)
+static STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, const char *pszText, ULARGE_INTEGER *ID, BOOL bVisible, BOOL bOnTop, int scrollV, COLORREF bgClr, COLORREF fgClr, wchar_t *Title, STICKYNOTEFONT *pCustomFont, BOOL bLoading)
{
WNDCLASSEX TWC = {0};
WINDOWPLACEMENT TWP;
@@ -1109,8 +1101,6 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
const BOOL bIsStartup = bVisible & 0x10000;
bVisible &= ~0x10000;
- char *TData = Data;
-
if (!GetClassInfoEx(hmiranda, NOTE_WND_CLASS, &TWC)) {
TWC.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE;
TWC.cbClsExtra = 0;
@@ -1126,7 +1116,7 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
if (!RegisterClassEx(&TWC)) return nullptr;
}
- if (!TData || Aw < 0 || Ah < 0) {
+ if (!pszText || Aw < 0 || Ah < 0) {
TWP.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(GetDesktopWindow(), &TWP);
Aw = g_NoteWidth; Ah = g_NoteHeight;
@@ -1147,10 +1137,8 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
g_arStickies.insert(TSN);
- if (!TData)
- TSN->data = _strdup("");
- else
- TSN->data = TData;
+ if (pszText)
+ TSN->szText = pszText;
// init note title (time-stamp)
if (Title) {
@@ -1184,7 +1172,7 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
// ensure that window is not placed off-screen (if previous session had different monitor count or resolution)
// NOTE: SetWindowPlacement should do this, but it's extremly flakey
- if (Data) {
+ if (pszText) {
if (!MonitorFromWindow(TSN->SNHwnd, MONITOR_DEFAULTTONULL)) {
TWP.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(GetDesktopWindow(), &TWP);
@@ -1203,7 +1191,7 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
ShowWindow(TSN->SNHwnd, SW_SHOWNA);
// when loading notes (only at startup), place all non-top notes at the bottom so they don't cover other windows
- if (Data && !bOnTop && bIsStartup)
+ if (pszText && !bOnTop && bIsStartup)
SetWindowPos(TSN->SNHwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
}
@@ -1220,9 +1208,9 @@ STICKYNOTE* NewNoteEx(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER
return TSN;
}
-void NewNote(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER *ID, BOOL bVisible, BOOL bOnTop, int scrollV)
+void NewNote(int Ax, int Ay, int Aw, int Ah, const char *pszText, ULARGE_INTEGER *ID, BOOL bVisible, BOOL bOnTop, int scrollV)
{
- auto *PSN = NewNoteEx(Ax, Ay, Aw, Ah, Data, ID, bVisible, bOnTop, scrollV, 0, 0, nullptr, nullptr, FALSE);
+ auto *PSN = NewNoteEx(Ax, Ay, Aw, Ah, pszText, ID, bVisible, bOnTop, scrollV, 0, 0, nullptr, nullptr, FALSE);
if (PSN)
SetFocus(PSN->REHwnd);
}
@@ -1495,7 +1483,7 @@ static void EditNote(STICKYNOTE *SN)
if (!SN->bVisible) {
SN->bVisible = TRUE;
- JustSaveNotesEx();
+ JustSaveNotes();
}
SetWindowPos(SN->SNHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
@@ -1583,7 +1571,7 @@ static void InitListView(HWND AHLV)
lvTIt.iItem = i;
lvTIt.iSubItem = 3;
- lvTIt.pszText = GetPreviewString(pNote->data);
+ lvTIt.pszText = GetPreviewString(pNote->szText);
ListView_SetItem(AHLV, &lvTIt);
i++;
@@ -1718,7 +1706,7 @@ static INT_PTR CALLBACK DlgProcViewNotes(HWND hwndDlg, UINT Message, WPARAM wPar
LPNMLISTVIEW NM = (LPNMLISTVIEW)lParam;
switch (NM->hdr.code) {
case LVN_ITEMCHANGED:
- SetDlgItemTextA(hwndDlg, IDC_REMINDERDATA, g_arStickies[NM->iItem].data);
+ SetDlgItemTextA(hwndDlg, IDC_REMINDERDATA, g_arStickies[NM->iItem].szText);
break;
case NM_DBLCLK:
@@ -1755,7 +1743,7 @@ static INT_PTR CALLBACK DlgProcViewNotes(HWND hwndDlg, UINT Message, WPARAM wPar
auto &SN = g_arStickies[i];
SN.bVisible = !SN.bVisible;
ShowWindow(SN.SNHwnd, SN.bVisible ? SW_SHOWNA : SW_HIDE);
- JustSaveNotesEx();
+ JustSaveNotes();
}
}
}
@@ -1771,7 +1759,7 @@ static INT_PTR CALLBACK DlgProcViewNotes(HWND hwndDlg, UINT Message, WPARAM wPar
SN.bOnTop = !SN.bOnTop;
SetWindowPos(SN.SNHwnd, SN.bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
RedrawWindow(SN.SNHwnd, nullptr, nullptr, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
- JustSaveNotesEx();
+ JustSaveNotes();
}
}
}
diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp
index e8509dc00b..6a44979af6 100644
--- a/plugins/NotesAndReminders/src/reminders.cpp
+++ b/plugins/NotesAndReminders/src/reminders.cpp
@@ -26,7 +26,7 @@ struct REMINDERDATA : public MZeroedObject
{
HWND handle;
DWORD uid;
- char* Reminder;
+ CMStringA szText;
ULARGE_INTEGER When; // FILETIME in UTC
UINT RepeatSound;
UINT RepeatSoundTTL;
@@ -65,7 +65,7 @@ static HWND LV;
int WS_Send(SOCKET s, char *data, int datalen);
unsigned long WS_ResolveName(char *name, WORD *port, int defaultPort);
-void Send(char *user, char *host, char *Msg, char* server);
+void Send(char *user, char *host, const char *Msg, char* server);
wchar_t* GetPreviewString(const char *lpsz);
// time convertsion routines that take local time-zone specific daylight saving configuration into account
@@ -144,17 +144,10 @@ void JustSaveReminders(void)
int i = 0;
for (auto &pReminder : arReminders) {
- char *tmpReminder;
- if (mir_strlen(pReminder->Reminder))
- tmpReminder = pReminder->Reminder;
- else
- tmpReminder = "";
-
- CMStringA szValue;
-
// data header (save 'When' with 1-second resolution, it's just a waste to have 100-nanosecond resolution
// which results in larger DB strings with no use)
- szValue.AppendFormat("X%u:%I64x", pReminder->uid, pReminder->When.QuadPart / FILETIME_TICKS_PER_SEC);
+ CMStringA szValue;
+ szValue.Format("X%u:%I64x", pReminder->uid, pReminder->When.QuadPart / FILETIME_TICKS_PER_SEC);
// repeat
if (pReminder->bRepeat)
@@ -169,8 +162,8 @@ void JustSaveReminders(void)
szValue.AppendFormat("\033""%u:%d", DATATAG_SNDSEL, pReminder->SoundSel);
// reminder text/note (ALWAYS PUT THIS PARAM LAST)
- if (tmpReminder && *tmpReminder)
- szValue.AppendFormat("\033""%u:%s", DATATAG_TEXT, tmpReminder);
+ if (!pReminder->szText.IsEmpty())
+ szValue.AppendFormat("\033""%u:%s", DATATAG_TEXT, pReminder->szText.c_str());
char ValueName[32];
mir_snprintf(ValueName, "RemindersData%d", i++);
@@ -248,7 +241,7 @@ void LoadReminders(void)
switch (tag) {
case DATATAG_TEXT:
- rem.Reminder = _strdup(TVal);
+ rem.szText = TVal;
break;
case DATATAG_SNDREPEAT:
@@ -268,8 +261,6 @@ void LoadReminders(void)
if (rem.SoundSel < 0)
rem.RepeatSound = 0;
- if (!rem.Reminder)
- rem.Reminder = _strdup("");
}
else {
// old format (for DB backward compatibility)
@@ -295,7 +286,7 @@ void LoadReminders(void)
SystemTimeToFileTime(&tm, (FILETIME*)&rem.When);
TVal = DelPos + 1;
- rem.Reminder = _strdup(TVal);
+ rem.szText = TVal;
}
// queue uid generation if invalid uid is present
@@ -518,7 +509,7 @@ bool CheckRemindersAndStart(void)
strncpy(S1, g_RemindSMS, S2 - g_RemindSMS);
S1[S2 - g_RemindSMS] = 0x0;
S2++;
- Send(S1, S2, pReminder->Reminder ? pReminder->Reminder : "", NULL);
+ Send(S1, S2, pReminder->szText, NULL);
SAFE_FREE((void**)&S1);
DeleteReminder(pReminder);
JustSaveReminders();
@@ -552,19 +543,16 @@ static LRESULT CALLBACK DatePickerWndProc(HWND hWnd, UINT message, WPARAM wParam
return mir_callNextSubclass(hWnd, DatePickerWndProc, message, wParam, lParam);
}
-static void InitDatePicker(HWND hwndDlg, UINT nIDDate)
+static void InitDatePicker(CCtrlDate &pDate)
{
- // subclass date picker to prevent user editing (should only use the dropdown calender to ensure valid dates)
- HWND hCtrl = GetDlgItem(hwndDlg, nIDDate);
-
// tweak style of picker
if (IsWinVerVistaPlus()) {
- DWORD dw = SendDlgItemMessage(hwndDlg, nIDDate, DTM_GETMCSTYLE, 0, 0);
+ DWORD dw = pDate.SendMsg(DTM_GETMCSTYLE, 0, 0);
dw |= MCS_WEEKNUMBERS | MCS_NOSELCHANGEONNAV;
- SendDlgItemMessage(hwndDlg, nIDDate, DTM_SETMCSTYLE, 0, dw);
+ pDate.SendMsg(DTM_SETMCSTYLE, 0, dw);
}
- mir_subclassWindow(hCtrl, DatePickerWndProc);
+ mir_subclassWindow(pDate.GetHwnd(), DatePickerWndProc);
}
static BOOL ParseTime(const wchar_t *s, int *hout, int *mout, BOOL bTimeOffset, BOOL bAllowOffsetOverride)
@@ -706,9 +694,9 @@ static BOOL ParseTime(const wchar_t *s, int *hout, int *mout, BOOL bTimeOffset,
}
// returns TRUE if combo box list displays time offsets ("23:34 (5 Minutes)" etc.)
-__inline static BOOL IsRelativeCombo(CCtrlCombo &pCombo)
+__inline static bool IsRelativeCombo(CCtrlCombo &pCombo)
{
- return (pCombo.GetItemData(0) >= 0);
+ return pCombo.GetItemData(0) < 0x80000000;
}
static void PopulateTimeCombo(CCtrlCombo &pCombo, bool bRelative, const SYSTEMTIME *tmUtc)
@@ -750,6 +738,7 @@ static void PopulateTimeCombo(CCtrlCombo &pCombo, bool bRelative, const SYSTEMTI
if (tm2.wHour == 23 && tm2.wMinute >= 30)
break;
}
+ return;
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -878,21 +867,17 @@ static int ReformatTimeInput(CCtrlCombo &pCombo, CCtrlBase &pRef, int h, int m,
return 0;
}
+ // search for preset first
wchar_t buf[64];
mir_snwprintf(buf, L"%02d:%02d", h, m);
-
- // search for preset first
int n = pCombo.FindString(buf);
if (n != -1) {
pCombo.SetCurSel(n);
return 0;
}
+ // date format is a time offset ("24:43 (5 Minutes)" etc.)
if (IsRelativeCombo(pCombo)) {
- // date format is a time offset ("24:43 (5 Minutes)" etc.)
-
- SYSTEMTIME tmTriggerLocal, tmTriggerLocal2;
-
// get reference time (UTC) from hidden control
pRef.GetText(buf, _countof(buf));
ULONGLONG ref = _wcstoui64(buf, nullptr, 16);
@@ -904,6 +889,7 @@ static int ReformatTimeInput(CCtrlCombo &pCombo, CCtrlBase &pRef, int h, int m,
const UINT nRefT = (UINT)tmRefLocal.wHour * 60 + (UINT)tmRefLocal.wMinute;
const UINT nT = h * 60 + m;
+ SYSTEMTIME tmTriggerLocal, tmTriggerLocal2;
tmTriggerLocal = tmRefLocal;
tmTriggerLocal.wHour = (WORD)h;
tmTriggerLocal.wMinute = (WORD)m;
@@ -1104,7 +1090,7 @@ static void OnDateChanged(CCtrlDate &pDate, CCtrlCombo &pTime, CCtrlBase &refTim
}
/////////////////////////////////////////////////////////////////////////////////////////
-// Reminder notification dialog
+// szText notification dialog
class CReminderNotifyDlg : public CDlgBase
{
@@ -1148,6 +1134,7 @@ class CReminderNotifyDlg : public CDlgBase
CCtrlBase refTime;
CCtrlDate dateAgain;
+ CCtrlEdit edtText;
CCtrlCheck chkAfter, chkOnDate;
CCtrlCombo cmbTimeAgain, cmbRemindAgainIn;
CCtrlButton btnDismiss, btnNone, btnRemindAgain;
@@ -1160,6 +1147,7 @@ public:
btnNone(this, IDC_NONE),
btnDismiss(this, IDC_DISMISS),
btnRemindAgain(this, IDC_REMINDAGAIN),
+ edtText(this, IDC_REMDATA),
chkAfter(this, IDC_AFTER),
chkOnDate(this, IDC_ONDATE),
dateAgain(this, IDC_DATEAGAIN),
@@ -1213,14 +1201,14 @@ public:
cmbRemindAgainIn.SetCurSel(16);
}
- SendDlgItemMessage(m_hwnd, IDC_REMDATA, EM_LIMITTEXT, MAX_REMINDER_LEN, 0);
+ edtText.SendMsg(EM_LIMITTEXT, MAX_REMINDER_LEN, 0);
PopulateTimeCombo(cmbTimeAgain, true, &tm);
// make sure date picker uses reference time
FileTimeToTzLocalST((FILETIME*)&li, &tm);
dateAgain.SetTime(&tm);
- InitDatePicker(m_hwnd, IDC_DATEAGAIN);
+ InitDatePicker(dateAgain);
cmbTimeAgain.SetCurSel(0);
@@ -1229,8 +1217,7 @@ public:
mir_snwprintf(S2, L"%s! - %s", TranslateT("Reminder"), S1);
SetCaption(S2);
- if (m_pReminder->Reminder)
- SetDlgItemTextA(m_hwnd, IDC_REMDATA, m_pReminder->Reminder);
+ edtText.SetTextA(m_pReminder->szText);
return true;
}
@@ -1372,19 +1359,8 @@ public:
}
// update reminder text
- char *ReminderText = nullptr;
- int SzT = SendDlgItemMessage(m_hwnd, IDC_REMDATA, WM_GETTEXTLENGTH, 0, 0);
- if (SzT) {
- if (SzT > MAX_REMINDER_LEN) SzT = MAX_REMINDER_LEN;
- ReminderText = (char*)malloc(SzT + 1);
- GetDlgItemTextA(m_hwnd, IDC_REMDATA, ReminderText, SzT + 1);
- }
-
- if (m_pReminder->Reminder)
- free(m_pReminder->Reminder);
- m_pReminder->Reminder = ReminderText;
-
- m_pReminder->bVisible = FALSE;
+ m_pReminder->szText = ptrA(edtText.GetTextA());
+ m_pReminder->bVisible = false;
m_pReminder->handle = nullptr;
// re-insert tree item sorted
@@ -1396,16 +1372,8 @@ public:
void onClick_None(CCtrlButton*)
{
- // create note from remainder
- char *ReminderText = nullptr;
- int SzT = SendDlgItemMessage(m_hwnd, IDC_REMDATA, WM_GETTEXTLENGTH, 0, 0);
- if (SzT) {
- if (SzT > MAX_REMINDER_LEN) SzT = MAX_REMINDER_LEN;
- ReminderText = (char*)malloc(SzT + 1);
- GetDlgItemTextA(m_hwnd, IDC_REMDATA, ReminderText, SzT + 1);
- }
-
- NewNote(0, 0, -1, -1, ReminderText, nullptr, TRUE, TRUE, 0);
+ // create note from reminder
+ NewNote(0, 0, -1, -1, ptrA(edtText.GetTextA()), nullptr, TRUE, TRUE, 0);
}
};
@@ -1436,6 +1404,7 @@ class CReminderFormDlg : public CDlgBase
CCtrlBase refTime;
CCtrlDate date;
+ CCtrlEdit edtText;
CCtrlCheck chkRepeat;
CCtrlCombo cmbSound, cmbRepeat, cmbTime;
CCtrlButton btnAdd, btnView, btnPlaySound;
@@ -1448,6 +1417,7 @@ public:
btnAdd(this, IDC_ADDREMINDER),
btnView(this, IDC_VIEWREMINDERS),
btnPlaySound(this, IDC_BTN_PLAYSOUND),
+ edtText(this, IDC_REMINDER),
refTime(this, IDC_REFTIME),
chkRepeat(this, IDC_CHECK_REPEAT),
cmbTime(this, IDC_COMBOREMINDERTIME),
@@ -1495,9 +1465,9 @@ public:
// make sure date picker uses reference time
FileTimeToTzLocalST((FILETIME*)&li, &tm);
date.SetTime(&tm);
- InitDatePicker(m_hwnd, IDC_DATE);
+ InitDatePicker(date);
- SendDlgItemMessage(m_hwnd, IDC_REMINDER, EM_LIMITTEXT, MAX_REMINDER_LEN, 0);
+ edtText.SendMsg(EM_LIMITTEXT, MAX_REMINDER_LEN, 0);
if (m_pReminder) {
mir_snwprintf(s, L"%02d:%02d", tm.wHour, tm.wMinute);
@@ -1509,7 +1479,7 @@ public:
else
cmbTime.SetText(s);
- SetDlgItemTextA(m_hwnd, IDC_REMINDER, m_pReminder->Reminder);
+ edtText.SetTextA(m_pReminder->szText);
}
else cmbTime.SetCurSel(0);
@@ -1568,7 +1538,7 @@ public:
if (m_pReminder)
SetFocus(GetDlgItem(m_hwnd, IDC_ADDREMINDER));
else
- SetFocus(GetDlgItem(m_hwnd, IDC_REMINDER));
+ SetFocus(edtText.GetHwnd());
return true;
}
@@ -1593,21 +1563,13 @@ public:
else
RepeatSound = 0;
- int SzT = SendDlgItemMessage(m_hwnd, IDC_REMINDER, WM_GETTEXTLENGTH, 0, 0);
- char *ReminderText = nullptr;
- if (SzT) {
- if (SzT > MAX_REMINDER_LEN) SzT = MAX_REMINDER_LEN;
- ReminderText = (char*)malloc(SzT + 1);
- GetDlgItemTextA(m_hwnd, IDC_REMINDER, ReminderText, SzT + 1);
- }
-
bool bClose = g_plugin.bCloseAfterAddReminder || m_pReminder;
if (!m_pReminder) {
// new reminder
REMINDERDATA *TempRem = new REMINDERDATA();
TempRem->uid = CreateUid();
SystemTimeToFileTime(&Date, (FILETIME*)&TempRem->When);
- TempRem->Reminder = ReminderText;
+ TempRem->szText = edtText.GetTextA();
TempRem->bRepeat = chkRepeat.GetState();
TempRem->SoundSel = cmbSound.GetItemData(cmbSound.GetCurSel());
TempRem->RepeatSound = TempRem->SoundSel < 0 ? 0 : (UINT)RepeatSound;
@@ -1617,10 +1579,7 @@ public:
// update existing reminder
SystemTimeToFileTime(&Date, (FILETIME*)&m_pReminder->When);
- if (m_pReminder->Reminder)
- free(m_pReminder->Reminder);
- m_pReminder->Reminder = ReminderText;
-
+ m_pReminder->szText = ptrA(edtText.GetTextA());
m_pReminder->bRepeat = chkRepeat.GetState();
m_pReminder->SoundSel = cmbSound.GetItemData(cmbSound.GetCurSel());
m_pReminder->RepeatSound = m_pReminder->SoundSel < 0 ? 0 : (UINT)RepeatSound;
@@ -1632,7 +1591,8 @@ public:
m_pReminder->bVisible = false;
m_pReminder = nullptr; // prevent new reminder from being deleted
}
- SetDlgItemTextA(m_hwnd, IDC_REMINDER, "");
+
+ edtText.SetTextA("");
JustSaveReminders();
NOTIFY_LIST();
if (bClose)
@@ -1726,7 +1686,7 @@ static void InitListView(HWND AHLV)
ListView_InsertItem(AHLV, &lvTIt);
lvTIt.mask = LVIF_TEXT;
- wchar_t *S2 = GetPreviewString(pReminder->Reminder);
+ wchar_t *S2 = GetPreviewString(pReminder->szText);
lvTIt.iItem = i;
lvTIt.iSubItem = 1;
lvTIt.pszText = S2;
@@ -1882,7 +1842,7 @@ static INT_PTR CALLBACK DlgProcViewReminders(HWND hwndDlg, UINT Message, WPARAM
LPNMLISTVIEW NM = (LPNMLISTVIEW)lParam;
switch (NM->hdr.code) {
case LVN_ITEMCHANGED:
- SetDlgItemTextA(hwndDlg, IDC_REMINDERDATA, arReminders[NM->iItem]->Reminder);
+ SetDlgItemTextA(hwndDlg, IDC_REMINDERDATA, arReminders[NM->iItem]->szText);
break;
case NM_DBLCLK:
diff --git a/plugins/NotesAndReminders/src/stdafx.h b/plugins/NotesAndReminders/src/stdafx.h
index 504c5da958..58c27892ed 100644
--- a/plugins/NotesAndReminders/src/stdafx.h
+++ b/plugins/NotesAndReminders/src/stdafx.h
@@ -2,6 +2,7 @@
#include <windows.h>
#include <commctrl.h>
+#include <limits.h>
#include <time.h>
#include <richedit.h>
@@ -52,7 +53,7 @@ struct CMPlugin : public PLUGIN<CMPlugin>
extern void CreateMsgWindow(void);
extern void DestroyMsgWindow(void);
-void NewNote(int Ax, int Ay, int Aw, int Ah, char *Data, ULARGE_INTEGER *ID, BOOL Visible, BOOL bOnTop, int scrollV);
+void NewNote(int Ax, int Ay, int Aw, int Ah, const char *pszText, ULARGE_INTEGER *ID, BOOL Visible, BOOL bOnTop, int scrollV);
void LoadNotes(BOOL bIsStartup);
void SaveNotes(void);
void DeleteNotes(void);
diff --git a/plugins/NotesAndReminders/src/version.h b/plugins/NotesAndReminders/src/version.h
index f154f6bd1e..c0b647f551 100644
--- a/plugins/NotesAndReminders/src/version.h
+++ b/plugins/NotesAndReminders/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>