diff options
author | George Hazan <ghazan@miranda.im> | 2021-03-07 19:51:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-03-07 19:51:59 +0300 |
commit | 9852392895d7c94c84ff3b4ff8966676a493f87c (patch) | |
tree | 7b6216e6bf0f51792b4971bd30521b42d5ccd874 /plugins/TabSRMM | |
parent | a64964a329edfeb8c6fafb1265163015d4a579ce (diff) |
common chats sound & icon processing code moved to the core
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/chat.h | 11 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat_tools.cpp | 319 | ||||
-rw-r--r-- | plugins/TabSRMM/src/hotkeyhandler.cpp | 18 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 1 |
4 files changed, 115 insertions, 234 deletions
diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h index 1917ace7e7..2c9e762908 100644 --- a/plugins/TabSRMM/src/chat.h +++ b/plugins/TabSRMM/src/chat.h @@ -80,16 +80,6 @@ struct TMUCSettings : public GlobalLogSettingsBase CMUCHighlight *Highlight;
};
-struct FLASH_PARAMS : public MZeroedObject
-{
- MCONTACT hContact;
- const char* sound;
- int iEvent;
- HICON hNotifyIcon;
- bool bActiveTab, bInactive, bMustFlash, bMustAutoswitch;
- HWND hWnd;
-};
-
extern TMUCSettings g_Settings;
#pragma comment(lib,"comctl32.lib")
@@ -127,7 +117,6 @@ wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2); bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText);
char GetIndicator(SESSION_INFO *si, LPCTSTR ptszNick, int *iNickIndex);
void Chat_SetFilters(SESSION_INFO *si);
-void DoFlashAndSoundWorker(FLASH_PARAMS* p);
BOOL DoPopup(SESSION_INFO *si, GCEVENT* gce);
int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, wchar_t* pszRoomName, COLORREF crBkg, const wchar_t* fmt, ...);
diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index a759a085ea..56c23a72c5 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -202,115 +202,32 @@ passed: return TRUE;
}
-void DoFlashAndSoundWorker(FLASH_PARAMS *p)
-{
- SESSION_INFO *si = SM_FindSessionByHCONTACT(p->hContact);
- if (si == nullptr)
- return;
-
- CMsgDialog *dat = nullptr;
- if (si->pDlg) {
- dat = si->pDlg;
- if (dat) {
- p->bInactive = dat->m_pContainer->m_hwnd != GetForegroundWindow();
- p->bActiveTab = (dat->m_pContainer->m_hwndActive == si->pDlg->GetHwnd());
- if (p->sound && dat->MustPlaySound())
- Skin_PlaySound(p->sound);
- }
- }
- else if (p->sound)
- Skin_PlaySound(p->sound);
-
- if (dat) {
- BOOL bForcedIcon = (p->hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT] || p->hNotifyIcon == g_chatApi.hIcons[ICON_MESSAGE]);
-
- if ((p->iEvent & si->iLogTrayFlags) || bForcedIcon) {
- if (!p->bActiveTab) {
- if (p->hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT])
- dat->m_iFlashIcon = p->hNotifyIcon;
- else {
- if (dat->m_iFlashIcon != g_chatApi.hIcons[ICON_HIGHLIGHT] && dat->m_iFlashIcon != g_chatApi.hIcons[ICON_MESSAGE])
- dat->m_iFlashIcon = p->hNotifyIcon;
- }
- dat->m_bCanFlashTab = TRUE;
- si->pDlg->timerFlash.Start(TIMEOUT_FLASHWND);
- }
- }
- if (dat->m_pWnd) {
- dat->m_pWnd->updateIcon(p->hNotifyIcon);
- dat->m_pWnd->setOverlayIcon(p->hNotifyIcon, true);
- }
-
- // autoswitch tab..
- if (p->bMustAutoswitch) {
- if ((IsIconic(dat->m_pContainer->m_hwnd)) && !IsZoomed(dat->m_pContainer->m_hwnd) && PluginConfig.m_bAutoSwitchTabs && dat->m_pContainer->m_hwndActive != si->pDlg->GetHwnd()) {
- int iItem = GetTabIndexFromHWND(dat->m_pContainer->m_hwndTabs, si->pDlg->GetHwnd());
- if (iItem >= 0) {
- TabCtrl_SetCurSel(dat->m_pContainer->m_hwndTabs, iItem);
- ShowWindow(dat->m_pContainer->m_hwndActive, SW_HIDE);
- dat->m_pContainer->m_hwndActive = si->pDlg->GetHwnd();
- dat->m_pContainer->UpdateTitle(dat->m_hContact);
- dat->m_pContainer->m_flags.m_bDeferredTabSelect = true;
- }
- }
- }
-
- // flash window if it is not focused
- if (p->bMustFlash && p->bInactive)
- if (!dat->m_pContainer->m_flags.m_bNoFlash)
- dat->m_pContainer->FlashContainer(1, 0);
-
- if (p->hNotifyIcon && p->bInactive && ((p->iEvent & si->iLogTrayFlags) || bForcedIcon)) {
- if (p->bMustFlash)
- dat->m_hTabIcon = p->hNotifyIcon;
- else if (dat->m_iFlashIcon) {
- dat->m_hTabIcon = dat->m_iFlashIcon;
-
- TCITEM item = {};
- item.mask = TCIF_IMAGE;
- item.iImage = 0;
- TabCtrl_SetItem(GetParent(si->pDlg->GetHwnd()), dat->m_iTabID, &item);
- }
-
- HICON hIcon = (HICON)SendMessage(dat->m_pContainer->m_hwnd, WM_GETICON, ICON_BIG, 0);
- if (p->hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT] || (hIcon != g_chatApi.hIcons[ICON_MESSAGE] && hIcon != g_chatApi.hIcons[ICON_HIGHLIGHT])) {
- dat->m_pContainer->SetIcon(dat, p->hNotifyIcon);
- dat->m_pContainer->m_flags.m_bNeedsUpdateTitle = true;
- }
- }
-
- if (p->bMustFlash && p->bInactive)
- AddUnreadContact(dat->m_hContact);
- }
-
- delete p;
-}
-
BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix)
{
if (gce == nullptr || si == nullptr || gce->bIsMe || si->iType == GCW_SERVER)
return FALSE;
- CMsgDialog *dat = nullptr;
- auto *params = new FLASH_PARAMS();
- params->hContact = si->hContact;
- params->bInactive = true;
- if (si->pDlg) {
- dat = si->pDlg;
- if ((si->pDlg->GetHwnd() == si->pDlg->m_pContainer->m_hwndActive) && GetForegroundWindow() == si->pDlg->m_pContainer->m_hwnd)
- params->bInactive = false;
+ CMsgDialog *dat = si->pDlg;
+
+ MCONTACT hContact = si->hContact;
+ bool bInactive = true;
+ if (dat) {
+ if ((dat->GetHwnd() == dat->m_pContainer->m_hwndActive) && GetForegroundWindow() == dat->m_pContainer->m_hwnd)
+ bInactive = false;
}
- params->bActiveTab = params->bMustFlash = params->bMustAutoswitch = false;
- params->iEvent = gce->iType;
+ bool bActiveTab = false;
+ bool bMustFlash = false;
+ bool bMustAutoswitch = false;
+ int iEvent = gce->iType;
+ HWND hWnd = nullptr;
WPARAM wParamForHighLight = 0;
bool bFlagUnread = false;
if (bHighlight) {
gce->iType |= GC_EVENT_HIGHLIGHT;
- params->sound = "ChatHighlight";
if (Contact_IsHidden(si->hContact) != 0)
Contact_Hide(si->hContact, false);
- if (params->bInactive) {
+ if (bInactive) {
bFlagUnread = true;
DoTrayIcon(si, gce);
}
@@ -318,23 +235,22 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (g_Settings.bCreateWindowOnHighlight && dat == nullptr)
wParamForHighLight = 1;
- if (dat && g_Settings.bAnnoyingHighlight && params->bInactive && dat->m_pContainer->m_hwnd != GetForegroundWindow()) {
+ if (dat && g_Settings.bAnnoyingHighlight && bInactive && dat->m_pContainer->m_hwnd != GetForegroundWindow()) {
wParamForHighLight = 2;
- params->hWnd = dat->GetHwnd();
+ hWnd = dat->GetHwnd();
}
if (dat || !nen_options.iMUCDisable)
DoPopup(si, gce);
- if (g_Settings.bFlashWindowHighlight && params->bInactive)
- params->bMustFlash = true;
- params->bMustAutoswitch = true;
- params->hNotifyIcon = g_chatApi.hIcons[ICON_HIGHLIGHT];
+ if (g_Settings.bFlashWindowHighlight && bInactive)
+ bMustFlash = true;
+ bMustAutoswitch = true;
}
else {
// do blinking icons in tray
- if (params->bInactive || !g_Settings.bTrayIconInactiveOnly) {
+ if (bInactive || !g_Settings.bTrayIconInactiveOnly) {
DoTrayIcon(si, gce);
- if (params->iEvent == GC_EVENT_MESSAGE)
+ if (iEvent == GC_EVENT_MESSAGE)
bFlagUnread = true;
}
// stupid thing to not create multiple popups for a QUIT event for instance
@@ -344,120 +260,115 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight DoPopup(si, gce);
// do sounds and flashing
- switch (params->iEvent) {
- case GC_EVENT_JOIN:
- params->sound = "ChatJoin";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_JOIN];
- break;
- case GC_EVENT_PART:
- params->sound = "ChatPart";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_PART];
- break;
- case GC_EVENT_QUIT:
- params->sound = "ChatQuit";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_QUIT];
- break;
- case GC_EVENT_ADDSTATUS:
- case GC_EVENT_REMOVESTATUS:
- params->sound = "ChatMode";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[params->iEvent == GC_EVENT_ADDSTATUS ? ICON_ADDSTATUS : ICON_REMSTATUS];
- break;
- case GC_EVENT_KICK:
- params->sound = "ChatKick";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_KICK];
- break;
- case GC_EVENT_MESSAGE:
- if (params->bInactive)
- params->sound = "RecvMsgInactive";
- else
- params->sound = "RecvMsgActive";
-
- if (params->bInactive && !(si->wState & STATE_TALK)) {
+ if (iEvent == GC_EVENT_MESSAGE) {
+ if (bInactive && !(si->wState & STATE_TALK)) {
si->wState |= STATE_TALK;
db_set_w(si->hContact, si->pszModule, "ApparentMode", ID_STATUS_OFFLINE);
}
- break;
- case GC_EVENT_ACTION:
- params->sound = "ChatAction";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_ACTION];
- break;
- case GC_EVENT_NICK:
- params->sound = "ChatNick";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_NICK];
- break;
- case GC_EVENT_NOTICE:
- params->sound = "ChatNotice";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_NOTICE];
- break;
- case GC_EVENT_TOPIC:
- params->sound = "ChatTopic";
- if (params->bInactive)
- params->hNotifyIcon = g_chatApi.hIcons[ICON_TOPIC];
- break;
- }
-
- if (!(db_get_dw(0, CHAT_MODULE, "SoundFlags", GC_EVENT_HIGHLIGHT) & params->iEvent))
- params->sound = nullptr;
- else if (CHATMODE_MUTE == db_get_b(si->hContact, "SRMM", "MuteMode", CHATMODE_NORMAL))
- params->sound = nullptr;
- }
- else {
- switch (params->iEvent) {
- case GC_EVENT_JOIN:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_JOIN];
- break;
- case GC_EVENT_PART:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_PART];
- break;
- case GC_EVENT_QUIT:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_QUIT];
- break;
- case GC_EVENT_KICK:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_KICK];
- break;
- case GC_EVENT_ACTION:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_ACTION];
- break;
- case GC_EVENT_NICK:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_NICK];
- break;
- case GC_EVENT_NOTICE:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_NOTICE];
- break;
- case GC_EVENT_TOPIC:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_TOPIC];
- break;
- case GC_EVENT_ADDSTATUS:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_ADDSTATUS];
- break;
- case GC_EVENT_REMOVESTATUS:
- params->hNotifyIcon = g_chatApi.hIcons[ICON_REMSTATUS];
- break;
}
}
- if (params->iEvent == GC_EVENT_MESSAGE) {
- params->bMustAutoswitch = true;
+ if (iEvent == GC_EVENT_MESSAGE) {
+ bMustAutoswitch = true;
if (g_Settings.bFlashWindow)
- params->bMustFlash = true;
- params->hNotifyIcon = g_chatApi.hIcons[ICON_MESSAGE];
+ bMustFlash = true;
}
}
+
if (dat && bFlagUnread) {
dat->m_dwUnread++;
if (dat->m_pWnd)
dat->m_pWnd->Invalidate();
}
- PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_MUCFLASHWORKER, wParamForHighLight, (LPARAM)params);
- return TRUE;
+
+ if (1 == wParamForHighLight) {
+ Clist_ContactDoubleClicked(hContact);
+ bActiveTab = true;
+ bInactive = bMustAutoswitch = bMustFlash = false;
+ }
+
+ if (2 == wParamForHighLight) {
+ bActiveTab = true;
+ bInactive = bMustAutoswitch = bMustFlash = false;
+ SendMessage(hWnd, DM_ACTIVATEME, 0, 0);
+ }
+
+ auto sound = si->getSoundName(iEvent);
+ if (dat) {
+ bInactive = dat->m_pContainer->m_hwnd != GetForegroundWindow();
+ bActiveTab = (dat->m_pContainer->m_hwndActive == dat->GetHwnd());
+ if (sound && dat->MustPlaySound())
+ Skin_PlaySound(sound);
+ }
+ else if (sound)
+ Skin_PlaySound(sound);
+
+ // dialog event processing
+ if (dat == nullptr)
+ return true;
+
+ HICON hNotifyIcon = (bManyFix && !bInactive) ? 0 : g_chatApi.getIcon(iEvent);
+ BOOL bForcedIcon = (hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT] || hNotifyIcon == g_chatApi.hIcons[ICON_MESSAGE]);
+
+ if ((iEvent & si->iLogTrayFlags) || bForcedIcon) {
+ if (!bActiveTab) {
+ if (hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT])
+ dat->m_iFlashIcon = hNotifyIcon;
+ else {
+ if (dat->m_iFlashIcon != g_chatApi.hIcons[ICON_HIGHLIGHT] && dat->m_iFlashIcon != g_chatApi.hIcons[ICON_MESSAGE])
+ dat->m_iFlashIcon = hNotifyIcon;
+ }
+ dat->m_bCanFlashTab = TRUE;
+ dat->timerFlash.Start(TIMEOUT_FLASHWND);
+ }
+ }
+ if (dat->m_pWnd) {
+ dat->m_pWnd->updateIcon(hNotifyIcon);
+ dat->m_pWnd->setOverlayIcon(hNotifyIcon, true);
+ }
+
+ // autoswitch tab..
+ if (bMustAutoswitch) {
+ if ((IsIconic(dat->m_pContainer->m_hwnd)) && !IsZoomed(dat->m_pContainer->m_hwnd) && PluginConfig.m_bAutoSwitchTabs && dat->m_pContainer->m_hwndActive != dat->GetHwnd()) {
+ int iItem = GetTabIndexFromHWND(dat->m_pContainer->m_hwndTabs, dat->GetHwnd());
+ if (iItem >= 0) {
+ TabCtrl_SetCurSel(dat->m_pContainer->m_hwndTabs, iItem);
+ ShowWindow(dat->m_pContainer->m_hwndActive, SW_HIDE);
+ dat->m_pContainer->m_hwndActive = dat->GetHwnd();
+ dat->m_pContainer->UpdateTitle(dat->m_hContact);
+ dat->m_pContainer->m_flags.m_bDeferredTabSelect = true;
+ }
+ }
+ }
+
+ // flash window if it is not focused
+ if (bMustFlash && bInactive)
+ if (!dat->m_pContainer->m_flags.m_bNoFlash)
+ dat->m_pContainer->FlashContainer(1, 0);
+
+ if (hNotifyIcon && bInactive && ((iEvent & si->iLogTrayFlags) || bForcedIcon)) {
+ if (bMustFlash)
+ dat->m_hTabIcon = hNotifyIcon;
+ else if (dat->m_iFlashIcon) {
+ dat->m_hTabIcon = dat->m_iFlashIcon;
+
+ TCITEM item = {};
+ item.mask = TCIF_IMAGE;
+ item.iImage = 0;
+ TabCtrl_SetItem(GetParent(dat->GetHwnd()), dat->m_iTabID, &item);
+ }
+
+ HICON hIcon = (HICON)SendMessage(dat->m_pContainer->m_hwnd, WM_GETICON, ICON_BIG, 0);
+ if (hNotifyIcon == g_chatApi.hIcons[ICON_HIGHLIGHT] || (hIcon != g_chatApi.hIcons[ICON_MESSAGE] && hIcon != g_chatApi.hIcons[ICON_HIGHLIGHT])) {
+ dat->m_pContainer->SetIcon(dat, hNotifyIcon);
+ dat->m_pContainer->m_flags.m_bNeedsUpdateTitle = true;
+ }
+ }
+
+ if (bMustFlash && bInactive)
+ AddUnreadContact(dat->m_hContact);
+
+ return true;
}
wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2)
diff --git a/plugins/TabSRMM/src/hotkeyhandler.cpp b/plugins/TabSRMM/src/hotkeyhandler.cpp index a2358b2b03..36c712279d 100644 --- a/plugins/TabSRMM/src/hotkeyhandler.cpp +++ b/plugins/TabSRMM/src/hotkeyhandler.cpp @@ -346,24 +346,6 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP CGlobals::logStatusChange(wParam, reinterpret_cast<CContactCache *>(lParam));
return 0;
- case DM_MUCFLASHWORKER:
- {
- FLASH_PARAMS *p = reinterpret_cast<FLASH_PARAMS*>(lParam);
- if (1 == wParam) {
- Clist_ContactDoubleClicked(p->hContact);
- p->bActiveTab = true;
- p->bInactive = p->bMustAutoswitch = p->bMustFlash = false;
- }
-
- if (2 == wParam) {
- p->bActiveTab = true;
- p->bInactive = p->bMustAutoswitch = p->bMustFlash = false;
- SendMessage(p->hWnd, DM_ACTIVATEME, 0, 0);
- }
- DoFlashAndSoundWorker(p);
- }
- return 0;
-
case WM_POWERBROADCAST:
case WM_DISPLAYCHANGE:
for (TContainerData *pCont = pFirstContainer; pCont; pCont = pCont->pNext)
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index c1388281cb..a67ae4935d 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -722,7 +722,6 @@ struct TIconDescW #define DM_CREATECONTAINER (TM_USER+26)
#define DM_QUERYLASTUNREAD (TM_USER+28)
#define DM_UPDATEPICLAYOUT (TM_USER+30)
-#define DM_MUCFLASHWORKER (TM_USER+32)
#define DM_APPENDMCEVENT (TM_USER+34)
#define DM_CHECKINFOTIP (TM_USER+35)
#define DM_SAVESIZE (TM_USER+36)
|