From 2d737d50469b965c2787823a94757f4c9f0a7107 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Mar 2017 17:28:47 +0300 Subject: chat API: - SESSION_INFO now addresses an instance of CChatRoomDlg instead of HWND; - linked list of sessions replaced with the usual LIST<>; - saveCI removed everywhere --- plugins/TabSRMM/src/chat.h | 2 -- plugins/TabSRMM/src/chat_main.cpp | 37 ++++++++++++++------------- plugins/TabSRMM/src/chat_manager.cpp | 24 ++++++++++++------ plugins/TabSRMM/src/chat_tools.cpp | 48 +++++++++++++++++------------------ plugins/TabSRMM/src/chat_window.cpp | 24 ++++++++---------- plugins/TabSRMM/src/container.cpp | 2 +- plugins/TabSRMM/src/hotkeyhandler.cpp | 8 +++--- plugins/TabSRMM/src/msgs.cpp | 12 ++++----- plugins/TabSRMM/src/stdafx.h | 3 +++ 9 files changed, 84 insertions(+), 76 deletions(-) (limited to 'plugins/TabSRMM/src') diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h index 0fdd8849c0..25963dae51 100644 --- a/plugins/TabSRMM/src/chat.h +++ b/plugins/TabSRMM/src/chat.h @@ -50,7 +50,6 @@ struct MODULEINFO : public GCModuleInfoBase struct SESSION_INFO : public GCSessionInfoBase { - CChatRoomDlg *dat; int iLogTrayFlags, iLogPopupFlags, iDiskLogFlags; }; @@ -93,7 +92,6 @@ struct FLASH_PARAMS }; extern TMUCSettings g_Settings; -extern CHAT_MANAGER saveCI; #pragma comment(lib,"comctl32.lib") diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp index 31aed38421..bac02dec6b 100644 --- a/plugins/TabSRMM/src/chat_main.cpp +++ b/plugins/TabSRMM/src/chat_main.cpp @@ -31,6 +31,9 @@ HANDLE g_hWindowList; HMENU g_hMenu = nullptr; +pfnDoPopup oldDoPopup, oldLogToFile; +pfnDoTrayIcon oldDoTrayIcon; + CHAT_MANAGER *pci; TMUCSettings g_Settings; @@ -49,31 +52,31 @@ static void OnReplaceSession(SESSION_INFO *si) { if (si->hContact) Chat_SetFilters(si); - if (si->hWnd) - RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), nullptr, nullptr, RDW_INVALIDATE); + if (si->pDlg) + RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), nullptr, nullptr, RDW_INVALIDATE); } static void OnSetTopic(SESSION_INFO *si) { - if (si->hWnd) - si->dat->m_pPanel.Invalidate(true); + if (si->pDlg) + si->pDlg->m_pPanel.Invalidate(true); } static void OnNewUser(SESSION_INFO *si, USERINFO*) { - if (si->hWnd) { - SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0); - if (si->dat) - si->dat->GetMyNick(); + if (si->pDlg) { + SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0); + if (si->pDlg) + si->pDlg->GetMyNick(); } } static void OnChangeNick(SESSION_INFO *si) { - if (si->hWnd) { - if (si->dat) - si->dat->GetMyNick(); - SendMessage(si->hWnd, GC_UPDATESTATUSBAR, 0, 0); + if (si->pDlg) { + if (si->pDlg) + si->pDlg->GetMyNick(); + SendMessage(si->pDlg->GetHwnd(), GC_UPDATESTATUSBAR, 0, 0); } } @@ -158,8 +161,6 @@ void Chat_ModulesLoaded() ///////////////////////////////////////////////////////////////////////////////////////// // load the group chat module -CHAT_MANAGER saveCI; - static int CopyChatSetting(const char *szSetting, LPARAM param) { LIST *szSettings = (LIST*)param; @@ -216,7 +217,7 @@ int Chat_Load() CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Message Sessions") L"/" LPGENW("Group chats"), FONTMODE_ALTER }; pci = Chat_GetInterface(&data); - saveCI = *pci; + pci->OnCreateModule = OnCreateModule; pci->OnNewUser = OnNewUser; @@ -232,9 +233,9 @@ int Chat_Load() // this operation is unsafe, that's why we restore the old pci state on exit pci->DoSoundsFlashPopupTrayStuff = DoSoundsFlashPopupTrayStuff; pci->IsHighlighted = IsHighlighted; - pci->LogToFile = LogToFile; - pci->DoPopup = DoPopup; - pci->ShowPopup = ShowPopup; + oldLogToFile = pci->LogToFile; pci->LogToFile = LogToFile; + oldDoPopup = pci->DoPopup; pci->DoPopup = DoPopup; + oldDoTrayIcon = pci->DoTrayIcon; pci->ShowPopup = ShowPopup; pci->Log_CreateRTF = Log_CreateRTF; pci->Log_CreateRtfHeader = Log_CreateRtfHeader; pci->UM_CompareItem = UM_CompareItem; diff --git a/plugins/TabSRMM/src/chat_manager.cpp b/plugins/TabSRMM/src/chat_manager.cpp index cff97336cf..ab7f447c4b 100644 --- a/plugins/TabSRMM/src/chat_manager.cpp +++ b/plugins/TabSRMM/src/chat_manager.cpp @@ -77,26 +77,30 @@ int UM_CompareItem(USERINFO *u1, const wchar_t* pszNick, WORD wStatus) BOOL SM_ReconfigureFilters() { - for (SESSION_INFO *si = pci->wndList; si; si = si->next) - Chat_SetFilters(si); + for (int i = 0; i < pci->arSessions.getCount(); i++) + Chat_SetFilters(pci->arSessions[i]); return TRUE; } SESSION_INFO* SM_FindSessionByHWND(HWND hWnd) { - for (SESSION_INFO *si = pci->wndList; si; si = si->next) - if (si->hWnd == hWnd) + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; + if (si->pDlg && si->pDlg->GetHwnd() == hWnd) return si; + } return nullptr; } SESSION_INFO* SM_FindSessionByHCONTACT(MCONTACT h) { - for (SESSION_INFO *si = pci->wndList; si; si = si->next) + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; if (si->hContact == h) return si; + } return nullptr; } @@ -111,13 +115,17 @@ SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* cu pszCurrent = pszOriginal; SESSION_INFO *pResult = nullptr; - for (SESSION_INFO *si = pci->wndList; si; si = si->next) - if (si != currSession && !mir_strcmpi(pszModule, si->pszModule)) - if (my_strstri(si->ptszName, pszOriginal) == si->ptszName) + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; + if (si != currSession && !mir_strcmpi(pszModule, si->pszModule)) { + if (my_strstri(si->ptszName, pszOriginal) == si->ptszName) { if (prevSession != si && mir_wstrcmpi(si->ptszName, pszCurrent) > 0 && (!pszName || mir_wstrcmpi(si->ptszName, pszName) < 0)) { pResult = si; pszName = si->ptszName; } + } + } + } return pResult; } diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index 0292d434bc..f0233278df 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -49,8 +49,8 @@ static void __stdcall Chat_DismissPopup(void *pi) if (pcli->pfnGetEvent(si->hContact, 0)) pcli->pfnRemoveEvent(si->hContact, GC_FAKE_EVENT); - if (si->hWnd && KillTimer(si->hWnd, TIMERID_FLASHWND)) - FlashWindow(si->hWnd, FALSE); + if (si->pDlg && KillTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND)) + FlashWindow(si->pDlg->GetHwnd(), FALSE); } static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -88,7 +88,7 @@ BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) { int iEvent = gce->pDest->iType; if (si && (iEvent & si->iLogTrayFlags)) - return saveCI.DoTrayIcon(si, gce); + return oldDoTrayIcon(si, gce); return TRUE; } @@ -141,7 +141,7 @@ BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) if (si == nullptr || !(iEvent & si->iLogPopupFlags)) return true; - CTabBaseDlg *dat = si->dat; + CTabBaseDlg *dat = si->pDlg; TContainerData *pContainer = dat ? dat->m_pContainer : nullptr; wchar_t *bbStart, *bbEnd; @@ -184,7 +184,7 @@ BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) if (pContainer->dwFlags & CNT_DONTREPORTFOCUSED) goto passed; - if (pContainer->hwndActive == si->hWnd) + if (pContainer->hwndActive == si->pDlg->GetHwnd()) return 0; goto passed; @@ -204,32 +204,32 @@ passed: ShowPopup(si->hContact, si, pci->hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, clr ? clr : pci->aFonts[9].color, TranslateT("%s%s says:%s %s"), bbStart, gce->ptszNick, bbEnd, pci->RemoveFormatting(gce->ptszText)); } - else saveCI.DoPopup(si, gce); + else oldDoPopup(si, gce); return TRUE; } -void DoFlashAndSoundWorker(FLASH_PARAMS* p) +void DoFlashAndSoundWorker(FLASH_PARAMS *p) { SESSION_INFO *si = SM_FindSessionByHCONTACT(p->hContact); - if (si == 0) + if (si == nullptr) return; CTabBaseDlg *dat = 0; - if (si->hWnd) { - dat = si->dat; + if (si->pDlg) { + dat = si->pDlg; if (dat) { p->bInactive = dat->m_pContainer->hwnd != GetForegroundWindow(); - p->bActiveTab = (dat->m_pContainer->hwndActive == si->hWnd); + p->bActiveTab = (dat->m_pContainer->hwndActive == si->pDlg->GetHwnd()); } - if (p->sound && Utils::mustPlaySound(si->dat)) + if (p->sound && Utils::mustPlaySound(si->pDlg)) SkinPlaySound(p->sound); } else if (p->sound) SkinPlaySound(p->sound); if (dat) { - HWND hwndTab = GetParent(si->hWnd); + HWND hwndTab = GetParent(si->pDlg->GetHwnd()); BOOL bForcedIcon = (p->hNotifyIcon == pci->hIcons[ICON_HIGHLIGHT] || p->hNotifyIcon == pci->hIcons[ICON_MESSAGE]); if ((p->iEvent & si->iLogTrayFlags) || bForcedIcon) { @@ -241,7 +241,7 @@ void DoFlashAndSoundWorker(FLASH_PARAMS* p) dat->m_iFlashIcon = p->hNotifyIcon; } dat->m_bCanFlashTab = TRUE; - SetTimer(si->hWnd, TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); + SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, TIMEOUT_FLASHWND, nullptr); } } if (dat->m_pWnd) { @@ -251,12 +251,12 @@ void DoFlashAndSoundWorker(FLASH_PARAMS* p) // autoswitch tab.. if (p->bMustAutoswitch) { - if ((IsIconic(dat->m_pContainer->hwnd)) && !IsZoomed(dat->m_pContainer->hwnd) && PluginConfig.haveAutoSwitch() && dat->m_pContainer->hwndActive != si->hWnd) { - int iItem = GetTabIndexFromHWND(hwndTab, si->hWnd); + if ((IsIconic(dat->m_pContainer->hwnd)) && !IsZoomed(dat->m_pContainer->hwnd) && PluginConfig.haveAutoSwitch() && dat->m_pContainer->hwndActive != si->pDlg->GetHwnd()) { + int iItem = GetTabIndexFromHWND(hwndTab, si->pDlg->GetHwnd()); if (iItem >= 0) { TabCtrl_SetCurSel(hwndTab, iItem); ShowWindow(dat->m_pContainer->hwndActive, SW_HIDE); - dat->m_pContainer->hwndActive = si->hWnd; + dat->m_pContainer->hwndActive = si->pDlg->GetHwnd(); SendMessage(dat->m_pContainer->hwnd, DM_UPDATETITLE, dat->m_hContact, 0); dat->m_pContainer->dwFlags |= CNT_DEFERREDTABSELECT; } @@ -277,7 +277,7 @@ void DoFlashAndSoundWorker(FLASH_PARAMS* p) TCITEM item = {}; item.mask = TCIF_IMAGE; item.iImage = 0; - TabCtrl_SetItem(GetParent(si->hWnd), dat->m_iTabID, &item); + TabCtrl_SetItem(GetParent(si->pDlg->GetHwnd()), dat->m_iTabID, &item); } HICON hIcon = (HICON)SendMessage(dat->m_pContainer->hwnd, WM_GETICON, ICON_BIG, 0); @@ -303,9 +303,9 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight FLASH_PARAMS *params = (FLASH_PARAMS*)mir_calloc(sizeof(FLASH_PARAMS)); params->hContact = si->hContact; params->bInactive = TRUE; - if (si->hWnd && si->dat) { - dat = si->dat; - if ((si->hWnd == si->dat->m_pContainer->hwndActive) && GetForegroundWindow() == si->dat->m_pContainer->hwnd) + if (si->pDlg) { + dat = si->pDlg; + if ((si->pDlg->GetHwnd() == si->pDlg->m_pContainer->hwndActive) && GetForegroundWindow() == si->pDlg->m_pContainer->hwnd) params->bInactive = FALSE; } params->bActiveTab = params->bMustFlash = params->bMustAutoswitch = FALSE; @@ -333,8 +333,8 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (dat || !nen_options.iMUCDisable) DoPopup(si, gce); - if (params->bInactive && si && si->hWnd) - SendMessage(si->hWnd, GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si); + if (params->bInactive && si && si->pDlg) + SendMessage(si->pDlg->GetHwnd(), GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si); if (g_Settings.bFlashWindowHighlight && params->bInactive) params->bMustFlash = TRUE; params->bMustAutoswitch = TRUE; @@ -502,7 +502,7 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) if (!(gce->pDest->iType & si->iDiskLogFlags)) return FALSE; - return saveCI.LogToFile(si, gce); // call kernel method + return oldLogToFile(si, gce); // call kernel method } UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText) diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index cb7780da7f..6e10dedfe5 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -1063,9 +1063,9 @@ static INT_PTR CALLBACK FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP db_set_dw(si->hContact, CHAT_MODULE, "TrayIconMask", dwMask); } Chat_SetFilters(si); - SendMessage(si->hWnd, GC_CHANGEFILTERFLAG, 0, iFlags); + SendMessage(si->pDlg->GetHwnd(), GC_CHANGEFILTERFLAG, 0, iFlags); if (si->bFilterEnabled) - SendMessage(si->hWnd, GC_REDRAWLOG, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG, 0, 0); } } DestroyWindow(hwndDlg); @@ -1511,8 +1511,8 @@ static void __cdecl phase2(void * lParam) SESSION_INFO *si = (SESSION_INFO*)lParam; Sleep(30); - if (si && si->hWnd) - PostMessage(si->hWnd, GC_REDRAWLOG2, 0, 0); + if (si && si->pDlg) + PostMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -1581,8 +1581,7 @@ void CChatRoomDlg::OnInitDialog() m_cache->updateNick(); m_cache->updateUIN(); - m_si->hWnd = m_hwnd; - m_si->dat = this; + m_si->pDlg = this; m_bIsAutosizingInput = IsAutoSplitEnabled(); m_fLimitedUpdate = false; m_iInputAreaHeight = -1; @@ -1673,8 +1672,7 @@ void CChatRoomDlg::OnDestroy() if (pcli->pfnGetEvent(m_si->hContact, 0)) pcli->pfnRemoveEvent(m_si->hContact, GC_FAKE_EVENT); m_si->wState &= ~STATE_TALK; - m_si->hWnd = nullptr; - m_si->dat = nullptr; + m_si->pDlg = nullptr; m_si = nullptr; TABSRMM_FireEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSING, 0); @@ -2356,7 +2354,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) switch (wParam) { case SESSION_OFFLINE: SendMessage(m_hwnd, GC_UPDATESTATUSBAR, 0, 0); - SendMessage(m_si->hWnd, GC_UPDATENICKLIST, 0, 0); + SendMessage(m_si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0); return TRUE; case SESSION_ONLINE: @@ -3126,15 +3124,15 @@ void ShowRoom(SESSION_INFO *si) if (si == nullptr) return; - if (si->hWnd != nullptr) { - ActivateExistingTab(si->dat->m_pContainer, si->hWnd); + if (si->pDlg != nullptr) { + ActivateExistingTab(si->pDlg->m_pContainer, si->pDlg->GetHwnd()); return; } wchar_t szName[CONTAINER_NAMELEN + 2]; szName[0] = 0; TContainerData *pContainer = nullptr; - if (si->dat != nullptr) - pContainer = si->dat->m_pContainer; + if (si->pDlg != nullptr) + pContainer = si->pDlg->m_pContainer; if (pContainer == nullptr) { GetContainerNameForContact(si->hContact, szName, CONTAINER_NAMELEN); if (!g_Settings.bOpenInDefault && !mir_wstrcmp(szName, L"default")) diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index 3503354b83..fcbd5be40f 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -1209,7 +1209,7 @@ panel_found: if (hwnd == 0) { SESSION_INFO *si = SM_FindSessionByHCONTACT(wParam); if (si) { - SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_UPDATETITLE, 0, 0); return 0; } } diff --git a/plugins/TabSRMM/src/hotkeyhandler.cpp b/plugins/TabSRMM/src/hotkeyhandler.cpp index 202e6e7423..2291e50711 100644 --- a/plugins/TabSRMM/src/hotkeyhandler.cpp +++ b/plugins/TabSRMM/src/hotkeyhandler.cpp @@ -110,11 +110,11 @@ void TSAPI HandleMenuEntryFromhContact(MCONTACT hContact) SESSION_INFO *si = SM_FindSessionByHCONTACT(hContact); if (si != nullptr) { // session does exist, but no window is open for it - if (si->hWnd) { + if (si->pDlg) { TContainerData *pContainer = 0; - SendMessage(si->hWnd, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); + SendMessage(si->pDlg->GetHwnd(), DM_QUERYCONTAINER, 0, (LPARAM)&pContainer); if (pContainer) { - ActivateExistingTab(pContainer, si->hWnd); + ActivateExistingTab(pContainer, si->pDlg->GetHwnd()); if (GetForegroundWindow() != pContainer->hwnd) SetForegroundWindow(pContainer->hwnd); SetFocus(GetDlgItem(pContainer->hwndActive, IDC_MESSAGE)); @@ -199,7 +199,7 @@ LONG_PTR CALLBACK HotkeyHandlerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP if (hWnd == nullptr) { SESSION_INFO *si = SM_FindSessionByHCONTACT((MCONTACT)dis->itemID); - hWnd = si ? si->hWnd : 0; + hWnd = si ? si->pDlg->GetHwnd() : nullptr; } CSrmmWindow *dat = 0; diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index 1ca98b630c..cd20c73006 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -97,12 +97,12 @@ static INT_PTR GetWindowData(WPARAM wParam, LPARAM lParam) else { SESSION_INFO *si = SM_FindSessionByHCONTACT(mwid->hContact); - if (si != nullptr && si->hWnd != 0) { + if (si != nullptr && si->pDlg != nullptr) { mwd->uFlags = MSG_WINDOW_UFLAG_MSG_BOTH; - mwd->hwndWindow = si->hWnd; - mwd->local = GetParent(GetParent(si->hWnd)); - SendMessage(si->hWnd, DM_GETWINDOWSTATE, 0, 0); - mwd->uState = GetWindowLongPtr(si->hWnd, DWLP_MSGRESULT); + mwd->hwndWindow = si->pDlg->GetHwnd(); + mwd->local = GetParent(GetParent(si->pDlg->GetHwnd())); + SendMessage(si->pDlg->GetHwnd(), DM_GETWINDOWSTATE, 0, 0); + mwd->uState = GetWindowLongPtr(si->pDlg->GetHwnd(), DWLP_MSGRESULT); return 0; } else { @@ -321,7 +321,7 @@ static INT_PTR SetStatusText(WPARAM hContact, LPARAM lParam) if (hwnd = M.FindWindow(hContact)) SetStatusTextWorker((CTabBaseDlg*)GetWindowLongPtr(hwnd, GWLP_USERDATA), (StatusTextData*)lParam); } - else SetStatusTextWorker(si->dat, (StatusTextData*)lParam); + else SetStatusTextWorker(si->pDlg, (StatusTextData*)lParam); return 0; } diff --git a/plugins/TabSRMM/src/stdafx.h b/plugins/TabSRMM/src/stdafx.h index 14d2eb220f..c458b0ab28 100644 --- a/plugins/TabSRMM/src/stdafx.h +++ b/plugins/TabSRMM/src/stdafx.h @@ -237,6 +237,9 @@ extern HMODULE g_hIconDLL; extern HMENU g_hMenu; extern bool g_bShutdown; +extern pfnDoPopup oldDoPopup, oldLogToFile; +extern pfnDoTrayIcon oldDoTrayIcon; + extern CREOleCallback reOleCallback; extern CREOleCallback2 reOleCallback2; -- cgit v1.2.3