From 3ffb500915c8b5a9e02d2b0136c20e9519d4f983 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 28 Jan 2016 11:20:28 +0000 Subject: port of tabsrmm's solution for events to StdMsg & Scriver git-svn-id: http://svn.miranda-ng.org/main/trunk@16177 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Scriver/src/msgs.cpp | 82 ++++++++++++++++++++++++++--------------- plugins/TabSRMM/src/globals.cpp | 1 + src/core/stdmsg/src/msgs.cpp | 59 ++++++++++++++++++++--------- 3 files changed, 94 insertions(+), 48 deletions(-) diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index ecc63cbc13..a7e3db3628 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -131,7 +131,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) cle.pszService = "SRMsg/ReadMessage"; mir_sntprintf(toolTip, TranslateT("Message from %s"), contactName); cle.ptszTooltip = toolTip; - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); + pcli->pfnAddEvent(&cle); } return 0; } @@ -220,15 +220,17 @@ static int TypingMessage(WPARAM hContact, LPARAM lParam) CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&tn); } else { - CLISTEVENT cle = { sizeof(cle) }; + pcli->pfnRemoveEvent(hContact, 1); + + CLISTEVENT cle = {}; + cle.cbSize = sizeof(cle); cle.hContact = hContact; cle.hDbEvent = 1; cle.flags = CLEF_ONLYAFEW | CLEF_TCHAR; cle.hIcon = GetCachedIcon("scriver_TYPING"); cle.pszService = "SRMsg/TypingMessage"; cle.ptszTooltip = szTip; - CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); - CallServiceSync(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle); + pcli->pfnAddEvent(&cle); } } return 0; @@ -251,43 +253,63 @@ static int ContactDeleted(WPARAM wParam, LPARAM) return 0; } -static void RestoreUnreadMessageAlerts(void) +///////////////////////////////////////////////////////////////////////////////////////// + +struct MSavedEvent { - TCHAR toolTip[256]; + MSavedEvent(MCONTACT _hContact, MEVENT _hEvent) : + hContact(_hContact), + hEvent(_hEvent) + { + } - DBEVENTINFO dbei = { sizeof(dbei) }; + MEVENT hEvent; + MCONTACT hContact; +}; - CLISTEVENT cle = { sizeof(cle) }; - cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); - cle.pszService = "SRMsg/ReadMessage"; - cle.flags = CLEF_TCHAR; - cle.ptszTooltip = toolTip; +static void RestoreUnreadMessageAlerts(void) +{ + OBJLIST arEvents(10, NumericKeySortT); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { + DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = 0; db_event_get(hDbEvent, &dbei); - if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && DbEventIsMessageOrCustom(&dbei)) { - int windowAlreadyExists = WindowList_Find(g_dat.hMessageWindowList, hContact) != NULL; - if (windowAlreadyExists) - continue; - - if (IsAutoPopup(hContact) && !windowAlreadyExists) { - NewMessageWindowLParam newData = { 0 }; - newData.hContact = hContact; - newData.flags = NMWLP_INCOMING; - HWND hParent = GetParentWindow(newData.hContact, FALSE); - CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)&newData); - } - else { - cle.hContact = hContact; - cle.hDbEvent = hDbEvent; - mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); - } + if ((dbei.flags & (DBEF_SENT | DBEF_READ)) || !DbEventIsMessageOrCustom(&dbei)) + continue; + + int windowAlreadyExists = WindowList_Find(g_dat.hMessageWindowList, hContact) != NULL; + if (windowAlreadyExists) + continue; + + if (IsAutoPopup(hContact) && !windowAlreadyExists) { + NewMessageWindowLParam newData = { 0 }; + newData.hContact = hContact; + newData.flags = NMWLP_INCOMING; + HWND hParent = GetParentWindow(newData.hContact, FALSE); + CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)&newData); } + else arEvents.insert(new MSavedEvent(hContact, hDbEvent)); } } + + TCHAR toolTip[256]; + + CLISTEVENT cle = {}; + cle.cbSize = sizeof(cle); + cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); + cle.pszService = "SRMsg/ReadMessage"; + cle.flags = CLEF_TCHAR; + cle.ptszTooltip = toolTip; + + for (int i = 0; i < arEvents.getCount(); i++) { + MSavedEvent &e = arEvents[i]; + mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(e.hContact, 0)); + cle.hContact = e.hContact; + cle.hDbEvent = e.hEvent; + pcli->pfnAddEvent(&cle); + } } static INT_PTR GetWindowAPI(WPARAM, LPARAM) diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index a3dbf0e364..2c0e32a1e5 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -557,6 +557,7 @@ void CGlobals::RestoreUnreadMessageAlerts(void) } } } + TCHAR toolTip[256]; CLISTEVENT cle = {}; diff --git a/src/core/stdmsg/src/msgs.cpp b/src/core/stdmsg/src/msgs.cpp index 573846ae4e..3172bdb661 100644 --- a/src/core/stdmsg/src/msgs.cpp +++ b/src/core/stdmsg/src/msgs.cpp @@ -97,7 +97,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) TCHAR toolTip[256]; mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); cle.ptszTooltip = toolTip; - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); + pcli->pfnAddEvent(&cle); return 0; } @@ -178,15 +178,18 @@ static int TypingMessage(WPARAM hContact, LPARAM lParam) CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)& tn); } else { - CLISTEVENT cle = { sizeof(cle) }; + pcli->pfnRemoveEvent(hContact, 1); + + CLISTEVENT cle = {}; + cle.cbSize = sizeof(cle); cle.hContact = hContact; cle.hDbEvent = 1; cle.flags = CLEF_ONLYAFEW | CLEF_TCHAR; cle.hIcon = Skin_LoadIcon(SKINICON_OTHER_TYPING); cle.pszService = "SRMsg/ReadMessage"; cle.ptszTooltip = szTip; - CallServiceSync(MS_CLIST_REMOVEEVENT, hContact, 1); - CallServiceSync(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle); + pcli->pfnAddEvent(&cle); + IcoLib_ReleaseIcon(cle.hIcon); } } @@ -223,21 +226,29 @@ static int ContactDeleted(WPARAM wParam, LPARAM) return 0; } -static void RestoreUnreadMessageAlerts(void) +///////////////////////////////////////////////////////////////////////////////////////// + +struct MSavedEvent { - TCHAR toolTip[256]; + MSavedEvent(MCONTACT _hContact, MEVENT _hEvent) : + hContact(_hContact), + hEvent(_hEvent) + { + } - CLISTEVENT cle = { sizeof(cle) }; - cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); - cle.pszService = "SRMsg/ReadMessage"; - cle.flags = CLEF_TCHAR; - cle.ptszTooltip = toolTip; + MEVENT hEvent; + MCONTACT hContact; +}; - DBEVENTINFO dbei = { sizeof(dbei) }; +static void RestoreUnreadMessageAlerts(void) +{ + OBJLIST arEvents(10, NumericKeySortT); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { bool autoPopup = false; + + DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = 0; db_event_get(hDbEvent, &dbei); if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { @@ -255,15 +266,27 @@ static void RestoreUnreadMessageAlerts(void) newData.noActivate = db_get_b(NULL, SRMMMOD, SRMSGSET_DONOTSTEALFOCUS, SRMSGDEFSET_DONOTSTEALFOCUS); CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), NULL, DlgProcMessage, (LPARAM)& newData); } - else { - cle.hContact = hContact; - cle.hDbEvent = hDbEvent; - mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); - } + else arEvents.insert(new MSavedEvent(hContact, hDbEvent)); } } } + + TCHAR toolTip[256]; + + CLISTEVENT cle = {}; + cle.cbSize = sizeof(cle); + cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); + cle.pszService = "SRMsg/ReadMessage"; + cle.flags = CLEF_TCHAR; + cle.ptszTooltip = toolTip; + + for (int i = 0; i < arEvents.getCount(); i++) { + MSavedEvent &e = arEvents[i]; + mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(e.hContact, 0)); + cle.hContact = e.hContact; + cle.hDbEvent = e.hEvent; + pcli->pfnAddEvent(&cle); + } } void RegisterSRMMFonts(void); -- cgit v1.2.3