From e4f25e2f1f5ecad84a8900b056be90d0c2ccf559 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 15 Mar 2023 12:17:54 +0300 Subject: HM_DBEVENTADDED message replaced with CMsgDialog::EventAdded method --- plugins/TabSRMM/src/functions.h | 5 +- plugins/TabSRMM/src/generic_msghandlers.cpp | 109 ---------------------------- plugins/TabSRMM/src/globals.cpp | 3 - plugins/TabSRMM/src/mim.cpp | 27 +------ plugins/TabSRMM/src/mim.h | 1 - plugins/TabSRMM/src/msgdialog.cpp | 7 -- plugins/TabSRMM/src/msgdlgother.cpp | 108 ++++++++++++++++++++++++++- plugins/TabSRMM/src/msglog.cpp | 4 +- plugins/TabSRMM/src/msgs.h | 5 +- 9 files changed, 115 insertions(+), 154 deletions(-) (limited to 'plugins/TabSRMM/src') diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index dc0bb47c5f..e7311632d2 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -84,9 +84,8 @@ void TSAPI CacheMsgLogIcons(); void TSAPI CacheLogFonts(); void TSAPI LoadIconTheme(); -int DbEventIsForMsgWindow(DBEVENTINFO *dbei); - -int TSAPI DbEventIsShown(DBEVENTINFO *dbei); +bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei); +bool DbEventIsShown(const DBEVENTINFO *dbei); // custom tab control diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 91a8906c30..f69e6de35d 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -1034,115 +1034,6 @@ void CMsgDialog::DM_AddDivider() } ///////////////////////////////////////////////////////////////////////////////////////// -// incoming event handler - -void CMsgDialog::DM_EventAdded(WPARAM, LPARAM lParam) -{ - MEVENT hDbEvent = (MEVENT)lParam; - - DBEVENTINFO dbei = {}; - db_event_get(hDbEvent, &dbei); - if (m_hDbEventFirst == 0) - m_hDbEventFirst = hDbEvent; - - bool bIsStatusChangeEvent = IsStatusEvent(dbei.eventType); - bool bDisableNotify = (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ)); - - if (!DbEventIsShown(&dbei)) - return; - - if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) { - m_lastMessage = dbei.timestamp; - m_wszStatusBar[0] = 0; - if (m_bShowTyping) { - m_nTypeSecs = 0; - DM_Typing(true); - m_bShowTyping = 0; - } - HandleIconFeedback(this, (HICON)-1); - if (m_pContainer->m_hwndStatus) - PostMessage(m_hwnd, DM_UPDATELASTMESSAGE, 0, 0); - } - - // set the message log divider to mark new (maybe unseen) messages, if the container has - // been minimized or in the background. - if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) { - if (g_plugin.bDividersUsePopupConfig && g_plugin.bUseDividers) { - if (!MessageWindowOpened(m_hContact, nullptr)) - DM_AddDivider(); - } - else if (g_plugin.bUseDividers) { - if (!m_pContainer->IsActive()) - DM_AddDivider(); - else if (m_pContainer->m_hwndActive != m_hwnd) - DM_AddDivider(); - } - - if (IsWindowVisible(m_pContainer->m_hwnd)) - m_pContainer->m_bHidden = false; - } - m_cache->updateStats(TSessionStats::UPDATE_WITH_LAST_RCV, 0); - - if (hDbEvent != m_hDbEventFirst) - StreamEvents(hDbEvent, 1, 1); - else - RemakeLog(); - - // handle tab flashing - if (!bDisableNotify && !bIsStatusChangeEvent) - if ((TabCtrl_GetCurSel(m_hwndParent) != m_iTabID) && !(dbei.flags & DBEF_SENT)) { - switch (dbei.eventType) { - case EVENTTYPE_MESSAGE: - m_iFlashIcon = PluginConfig.g_IconMsgEvent; - break; - case EVENTTYPE_FILE: - m_iFlashIcon = PluginConfig.g_IconFileEvent; - break; - default: - m_iFlashIcon = PluginConfig.g_IconMsgEvent; - break; - } - timerFlash.Start(TIMEOUT_FLASHWND); - m_bCanFlashTab = true; - } - - // try to flash the contact list... - if (!bDisableNotify) - FlashOnClist(hDbEvent, &dbei); - - // autoswitch tab if option is set AND container is minimized (otherwise, we never autoswitch) - // never switch for status changes... - if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) { - if (g_plugin.bAutoSwitchTabs && m_pContainer->m_hwndActive != m_hwnd) { - if ((IsIconic(m_pContainer->m_hwnd) && !IsZoomed(m_pContainer->m_hwnd)) || (g_plugin.bHideOnClose && !IsWindowVisible(m_pContainer->m_hwnd))) { - int iItem = GetTabIndexFromHWND(GetParent(m_hwnd), m_hwnd); - if (iItem >= 0) { - TabCtrl_SetCurSel(m_hwndParent, iItem); - ShowWindow(m_pContainer->m_hwndActive, SW_HIDE); - m_pContainer->m_hwndActive = m_hwnd; - m_pContainer->UpdateTitle(m_hContact); - m_pContainer->cfg.flags.m_bDeferredTabSelect = true; - } - } - } - } - - // flash window if it is not focused - if (!bDisableNotify && !bIsStatusChangeEvent) - if (!IsActive() && !(dbei.flags & DBEF_SENT)) { - if (!m_pContainer->cfg.flags.m_bNoFlash && !m_pContainer->IsActive()) - m_pContainer->FlashContainer(1, 0); - m_pContainer->SetIcon(this, Skin_LoadIcon(SKINICON_EVENT_MESSAGE)); - m_pContainer->cfg.flags.m_bNeedsUpdateTitle = true; - } - - // play a sound - if (!bDisableNotify && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) - PlayIncomingSound(); - - if (m_pWnd) - m_pWnd->Invalidate(); -} void CMsgDialog::DM_HandleAutoSizeRequest(REQRESIZE* rr) { diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index a80ff3f2b2..397e829dc1 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -265,10 +265,7 @@ int CGlobals::ModulesLoaded(WPARAM, LPARAM) HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged); HookEvent(ME_DB_CONTACT_DELETED, DBContactDeleted); - HookEvent(ME_DB_EVENT_ADDED, CMimAPI::DispatchNewEvent); HookEvent(ME_DB_EVENT_ADDED, CMimAPI::MessageEventAdded); - - HookEvent(ME_DB_EVENT_EDITED, CMimAPI::DispatchNewEvent); HookEvent(ME_DB_EVENT_EDITED, CMimAPI::MessageEventAdded); HookEvent(ME_FONT_RELOAD, ::FontServiceFontsChanged); diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index 9b776b88ab..7412bd0474 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -360,27 +360,6 @@ int CMimAPI::PrebuildContactMenu(WPARAM hContact, LPARAM) return 0; } -///////////////////////////////////////////////////////////////////////////////////////// -// this handler is called first in the message window chain - it will handle events for which a message window -// is already open. if not, it will do nothing and the 2nd handler(MessageEventAdded) will perform all -// the needed actions. -// -// this handler POSTs the event to the message window procedure - so it is fast and can exit quickly which will -// improve the overall responsiveness when receiving messages. - -int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM hDbEvent) -{ - if (hContact) { - Utils::sendContactMessage(hContact, HM_DBEVENTADDED, hContact, hDbEvent); - - // we're in meta and an event belongs to a sub - MCONTACT hReal = db_event_getContact(hDbEvent); - if (hReal != hContact) - Utils::sendContactMessage(hReal, HM_DBEVENTADDED, hContact, hDbEvent); - } - return 0; -} - ///////////////////////////////////////////////////////////////////////////////////////// // Message event added is called when a new message is added to the database // if no session is open for the contact, this function will determine if and how a new message @@ -390,7 +369,7 @@ int CMimAPI::DispatchNewEvent(WPARAM hContact, LPARAM hDbEvent) int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) { - if (hContact == 0) + if (hContact == 0 || Contact::IsGroupChat(hContact)) return 0; DBEVENTINFO dbei = {}; @@ -401,12 +380,10 @@ int CMimAPI::MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) pDlg = Srmm_FindDialog(db_event_getContact(hDbEvent)); BOOL isCustomEvent = IsCustomEvent(dbei.eventType); - BOOL isShownCustomEvent = DbEventIsForMsgWindow(&dbei); + bool isShownCustomEvent = DbEventIsForMsgWindow(&dbei); if (dbei.markedRead() || (isCustomEvent && !isShownCustomEvent)) return 0; - g_clistApi.pfnRemoveEvent(hContact, 1); - bool bAutoPopup = g_plugin.bAutoPopup; bool bAutoCreate = g_plugin.bAutoTabs; bool bAutoContainer = g_plugin.bAutoContainer; diff --git a/plugins/TabSRMM/src/mim.h b/plugins/TabSRMM/src/mim.h index b9d094868a..4245d0a957 100644 --- a/plugins/TabSRMM/src/mim.h +++ b/plugins/TabSRMM/src/mim.h @@ -173,7 +173,6 @@ public: static int TypingMessage(WPARAM wParam, LPARAM lParam); static int ProtoAck(WPARAM wParam, LPARAM lParam); static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam); - static int DispatchNewEvent(WPARAM wParam, LPARAM lParam); static int MessageEventAdded(WPARAM wParam, LPARAM lParam); public: diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index d6a30b3153..acc2e1bd44 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -2489,13 +2489,6 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) StreamEvents(lParam, 1, 1); return 0; - case HM_DBEVENTADDED: - // this is called whenever a new event has been added to the database. - // this CAN be posted (some sanity checks required). - if (this && !isChat()) - DM_EventAdded(m_hContact, lParam); - return 0; - case WM_TIMER: // timer id for message timeouts is composed like: // for single message sends: basevalue (TIMERID_MSGSEND) + send queue index diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index fb80588a80..ff9dac657e 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -452,6 +452,112 @@ void CMsgDialog::EnableSending(bool bMode) const ///////////////////////////////////////////////////////////////////////////////////////// +void CMsgDialog::EventAdded(MEVENT hDbEvent, const DBEVENTINFO &dbei) +{ + if (m_hDbEventFirst == 0) + m_hDbEventFirst = hDbEvent; + + bool bIsStatusChangeEvent = IsStatusEvent(dbei.eventType); + bool bDisableNotify = (dbei.eventType == EVENTTYPE_MESSAGE && (dbei.flags & DBEF_READ)); + + if (!DbEventIsShown(&dbei)) + return; + + if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) { + m_lastMessage = dbei.timestamp; + m_wszStatusBar[0] = 0; + if (m_bShowTyping) { + m_nTypeSecs = 0; + DM_Typing(true); + m_bShowTyping = 0; + } + HandleIconFeedback(this, (HICON)-1); + if (m_pContainer->m_hwndStatus) + PostMessage(m_hwnd, DM_UPDATELASTMESSAGE, 0, 0); + } + + // set the message log divider to mark new (maybe unseen) messages, if the container has + // been minimized or in the background. + if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) { + if (g_plugin.bDividersUsePopupConfig && g_plugin.bUseDividers) { + if (!MessageWindowOpened(m_hContact, nullptr)) + DM_AddDivider(); + } + else if (g_plugin.bUseDividers) { + if (!m_pContainer->IsActive()) + DM_AddDivider(); + else if (m_pContainer->m_hwndActive != m_hwnd) + DM_AddDivider(); + } + + if (IsWindowVisible(m_pContainer->m_hwnd)) + m_pContainer->m_bHidden = false; + } + m_cache->updateStats(TSessionStats::UPDATE_WITH_LAST_RCV, 0); + + if (hDbEvent != m_hDbEventFirst) + StreamEvents(hDbEvent, 1, 1); + else + RemakeLog(); + + // handle tab flashing + if (!bDisableNotify && !bIsStatusChangeEvent) + if ((TabCtrl_GetCurSel(m_hwndParent) != m_iTabID) && !(dbei.flags & DBEF_SENT)) { + switch (dbei.eventType) { + case EVENTTYPE_MESSAGE: + m_iFlashIcon = PluginConfig.g_IconMsgEvent; + break; + case EVENTTYPE_FILE: + m_iFlashIcon = PluginConfig.g_IconFileEvent; + break; + default: + m_iFlashIcon = PluginConfig.g_IconMsgEvent; + break; + } + timerFlash.Start(TIMEOUT_FLASHWND); + m_bCanFlashTab = true; + } + + // try to flash the contact list... + if (!bDisableNotify) + FlashOnClist(hDbEvent, &dbei); + + // autoswitch tab if option is set AND container is minimized (otherwise, we never autoswitch) + // never switch for status changes... + if (!(dbei.flags & DBEF_SENT) && !bIsStatusChangeEvent) { + if (g_plugin.bAutoSwitchTabs && m_pContainer->m_hwndActive != m_hwnd) { + if ((IsIconic(m_pContainer->m_hwnd) && !IsZoomed(m_pContainer->m_hwnd)) || (g_plugin.bHideOnClose && !IsWindowVisible(m_pContainer->m_hwnd))) { + int iItem = GetTabIndexFromHWND(GetParent(m_hwnd), m_hwnd); + if (iItem >= 0) { + TabCtrl_SetCurSel(m_hwndParent, iItem); + ShowWindow(m_pContainer->m_hwndActive, SW_HIDE); + m_pContainer->m_hwndActive = m_hwnd; + m_pContainer->UpdateTitle(m_hContact); + m_pContainer->cfg.flags.m_bDeferredTabSelect = true; + } + } + } + } + + // flash window if it is not focused + if (!bDisableNotify && !bIsStatusChangeEvent) + if (!IsActive() && !(dbei.flags & DBEF_SENT)) { + if (!m_pContainer->cfg.flags.m_bNoFlash && !m_pContainer->IsActive()) + m_pContainer->FlashContainer(1, 0); + m_pContainer->SetIcon(this, Skin_LoadIcon(SKINICON_EVENT_MESSAGE)); + m_pContainer->cfg.flags.m_bNeedsUpdateTitle = true; + } + + // play a sound + if (!bDisableNotify && dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & (DBEF_SENT))) + PlayIncomingSound(); + + if (m_pWnd) + m_pWnd->Invalidate(); +} + +///////////////////////////////////////////////////////////////////////////////////////// + bool CMsgDialog::GetFirstEvent() { int historyMode = g_plugin.getByte(m_hContact, SRMSGSET_LOADHISTORY, -1); @@ -537,7 +643,7 @@ int CMsgDialog::FindRTLLocale() ///////////////////////////////////////////////////////////////////////////////////////// -void CMsgDialog::FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei) +void CMsgDialog::FlashOnClist(MEVENT hEvent, const DBEVENTINFO *dbei) { m_dwTickLastEvent = GetTickCount(); diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index e12507d8e0..2fb0e7fe9e 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -411,7 +411,7 @@ static char *CreateRTFTail() return mir_strdup("}"); } -int TSAPI DbEventIsShown(DBEVENTINFO *dbei) +bool DbEventIsShown(const DBEVENTINFO *dbei) { if (!IsCustomEvent(dbei->eventType) || DbEventIsForMsgWindow(dbei)) return 1; @@ -419,7 +419,7 @@ int TSAPI DbEventIsShown(DBEVENTINFO *dbei) return IsStatusEvent(dbei->eventType); } -int DbEventIsForMsgWindow(DBEVENTINFO *dbei) +bool DbEventIsForMsgWindow(const DBEVENTINFO *dbei) { DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType); return et && (et->flags & DETF_MSGWINDOW); diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index d0c23f3522..8f0082470a 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -70,7 +70,6 @@ #define EM_REFRESHWITHOUTCLIP (TM_USER+0x106) #define HM_EVENTSENT (TM_USER+10) -#define HM_DBEVENTADDED (TM_USER+12) #define DM_SETINFOPANEL (TM_USER+13) #define DM_OPTIONSAPPLIED (TM_USER+14) #define DM_SPLITSENDACK (TM_USER+19) @@ -437,7 +436,6 @@ class CMsgDialog : public CSrmmBaseDialog HWND DM_CreateClist(void); void DM_DismissTip(const POINT& pt); void DM_ErrorDetected(int type, int flag); - void DM_EventAdded(WPARAM wParam, LPARAM lParam); void DM_FreeTheme(void); bool DM_GenericHotkeysCheck(MSG *message); void DM_HandleAutoSizeRequest(REQRESIZE *rr); @@ -457,7 +455,7 @@ class CMsgDialog : public CSrmmBaseDialog void DetermineMinHeight(void); BOOL DoRtfToTags(CMStringW &pszText) const; int FindRTLLocale(void); - void FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei); + void FlashOnClist(MEVENT hEvent, const DBEVENTINFO *dbei); void FlashTab(bool bInvertMode); LRESULT GetSendButtonState(); void GetSendFormat(void); @@ -633,6 +631,7 @@ public: void AddLog() override; void CloseTab() override; + void EventAdded(MEVENT, const DBEVENTINFO &dbei) override; bool GetFirstEvent() override; bool IsActive() const override; void LoadSettings() override; -- cgit v1.2.3