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/Scriver/src/chat/chat.h | 6 +++--- plugins/Scriver/src/chat/main.cpp | 37 +++++++++++++++++++----------------- plugins/Scriver/src/chat/manager.cpp | 28 ++++++++++++--------------- plugins/Scriver/src/chat/window.cpp | 26 ++++++++++++------------- 4 files changed, 48 insertions(+), 49 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/chat/chat.h b/plugins/Scriver/src/chat/chat.h index 02764be9a0..c742adcb6d 100644 --- a/plugins/Scriver/src/chat/chat.h +++ b/plugins/Scriver/src/chat/chat.h @@ -70,9 +70,9 @@ extern GlobalLogSettings g_Settings; void UpgradeCheck(void); // log.c -void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, BOOL bRedraw); -void LoadMsgLogBitmaps(void); -void FreeMsgLogBitmaps(void); +void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, BOOL bRedraw); +void LoadMsgLogBitmaps(void); +void FreeMsgLogBitmaps(void); // window.c int GetTextPixelSize( wchar_t* pszText, HFONT hFont, BOOL bWidth); diff --git a/plugins/Scriver/src/chat/main.cpp b/plugins/Scriver/src/chat/main.cpp index dc416bf42c..4a419ebde8 100644 --- a/plugins/Scriver/src/chat/main.cpp +++ b/plugins/Scriver/src/chat/main.cpp @@ -22,9 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../stdafx.h" // globals -CHAT_MANAGER *pci, saveCI; +CHAT_MANAGER *pci; HMENU g_hMenu = nullptr; +pfnDoTrayIcon oldDoTrayIcon; +pfnDoPopup oldDoPopup; + GlobalLogSettings g_Settings; void LoadModuleIcons(MODULEINFO *mi) @@ -47,39 +50,40 @@ void LoadModuleIcons(MODULEINFO *mi) static void OnReplaceSession(SESSION_INFO *si) { - if (si->hWnd) - RedrawWindow(GetDlgItem(si->hWnd, IDC_CHAT_LIST), nullptr, nullptr, RDW_INVALIDATE); + if (si->pDlg) + RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_CHAT_LIST), nullptr, nullptr, RDW_INVALIDATE); } static void OnNewUser(SESSION_INFO *si, USERINFO*) { - if (si->hWnd) - SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0); + if (si->pDlg) + SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0); } static void OnSetStatus(SESSION_INFO *si, int) { - PostMessage(si->hWnd, GC_FIXTABICONS, 0, 0); + if (si->pDlg) + PostMessage(si->pDlg->GetHwnd(), GC_FIXTABICONS, 0, 0); } static void OnFlashHighlight(SESSION_INFO *si, int bInactive) { - if (!bInactive || !si->hWnd) + if (!bInactive || !si->pDlg) return; if (g_Settings.bFlashWindowHighlight) - SendMessage(GetParent(si->hWnd), CM_STARTFLASHING, 0, 0); - SendMessage(si->hWnd, GC_SETMESSAGEHIGHLIGHT, 0, 0); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_SETMESSAGEHIGHLIGHT, 0, 0); } static void OnFlashWindow(SESSION_INFO *si, int bInactive) { - if (!bInactive || !si->hWnd) + if (!bInactive || !si->pDlg) return; if (g_Settings.bFlashWindow) - SendMessage(GetParent(si->hWnd), CM_STARTFLASHING, 0, 0); - SendMessage(si->hWnd, GC_SETTABHIGHLIGHT, 0, 0); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_STARTFLASHING, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_SETTABHIGHLIGHT, 0, 0); } static void OnCreateModule(MODULEINFO *mi) @@ -92,14 +96,14 @@ static void OnCreateModule(MODULEINFO *mi) static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) { if (gce->pDest->iType & g_Settings.dwTrayIconFlags) - return saveCI.DoTrayIcon(si, gce); + return oldDoTrayIcon(si, gce); return TRUE; } static BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) { if (gce->pDest->iType & g_Settings.dwPopupFlags) - return saveCI.DoPopup(si, gce); + return oldDoPopup(si, gce); return TRUE; } @@ -117,7 +121,6 @@ int Chat_Load() { CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Messaging") L"/" LPGENW("Group chats"), FONTMODE_SKIP }; pci = Chat_GetInterface(&data); - saveCI = *pci; pci->OnCreateModule = OnCreateModule; pci->OnNewUser = OnNewUser; @@ -131,8 +134,8 @@ int Chat_Load() pci->OnFlashHighlight = OnFlashHighlight; pci->ShowRoom = ShowRoom; - pci->DoPopup = DoPopup; - pci->DoTrayIcon = DoTrayIcon; + oldDoPopup = pci->DoPopup; pci->DoPopup = DoPopup; + oldDoTrayIcon = pci->DoTrayIcon; pci->DoTrayIcon = DoTrayIcon; pci->ReloadSettings(); g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU)); diff --git a/plugins/Scriver/src/chat/manager.cpp b/plugins/Scriver/src/chat/manager.cpp index cb8f50589a..307059dfd8 100644 --- a/plugins/Scriver/src/chat/manager.cpp +++ b/plugins/Scriver/src/chat/manager.cpp @@ -23,38 +23,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. HWND SM_FindWindowByContact(MCONTACT hContact) { - SESSION_INFO *pTemp = pci->wndList; - - while (pTemp != nullptr) { - if (pTemp->hContact == hContact) - return pTemp->hWnd; - - pTemp = pTemp->next; + for (int i = 0; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *si = pci->arSessions[i]; + if (si->hContact == hContact) + return (si->pDlg) ? si->pDlg->GetHwnd() : nullptr; } return nullptr; } -SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* currSession, SESSION_INFO* prevSession, const wchar_t* pszOriginal, const wchar_t* pszCurrent) +SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO *currSession, SESSION_INFO *prevSession, const wchar_t *pszOriginal, const wchar_t *pszCurrent) { SESSION_INFO* pResult = nullptr; if (prevSession == nullptr && my_strstri(currSession->ptszName, pszOriginal) == currSession->ptszName) pResult = currSession; else { wchar_t* pszName = nullptr; - SESSION_INFO* pTemp = pci->wndList; if (currSession == prevSession) pszCurrent = pszOriginal; - while (pTemp != nullptr) { - if (pTemp != currSession && !mir_strcmpi(pszModule, pTemp->pszModule)) { - if (my_strstri(pTemp->ptszName, pszOriginal) == pTemp->ptszName) { - if (prevSession != pTemp && mir_wstrcmpi(pTemp->ptszName, pszCurrent) > 0 && (!pszName || mir_wstrcmpi(pTemp->ptszName, pszName) < 0)) { - pResult = pTemp; - pszName = pTemp->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; } } } - pTemp = pTemp->next; } } return pResult; diff --git a/plugins/Scriver/src/chat/window.cpp b/plugins/Scriver/src/chat/window.cpp index c48e0c8ea5..9731065f73 100644 --- a/plugins/Scriver/src/chat/window.cpp +++ b/plugins/Scriver/src/chat/window.cpp @@ -426,9 +426,9 @@ static INT_PTR CALLBACK FilterWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP if (iFlags & GC_EVENT_ADDSTATUS) iFlags |= GC_EVENT_REMOVESTATUS; - 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); PostMessage(hwndDlg, WM_CLOSE, 0, 0); } break; @@ -794,8 +794,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); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -982,7 +982,7 @@ void CChatRoomDlg::OnDestroy() { NotifyLocalWinEvent(m_hContact, m_hwnd, MSG_WINDOW_EVT_CLOSING); - m_si->hWnd = nullptr; + m_si->pDlg = nullptr; SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0); SendMessage(m_hwndParent, CM_REMOVECHILD, 0, (LPARAM)m_hwnd); @@ -1443,7 +1443,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) } SendMessage(m_hwnd, GC_FIXTABICONS, 0, 0); - if (!m_si->hWnd) { + if (!m_si->pDlg) { ShowRoom(m_si); SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); } @@ -1750,7 +1750,7 @@ void ShowRoom(SESSION_INFO *si) return; // Do we need to create a window? - if (si->hWnd == nullptr) { + if (si->pDlg == nullptr) { HWND hParent = GetParentWindow(si->hContact, TRUE); CChatRoomDlg *pDlg = new CChatRoomDlg(si); @@ -1758,11 +1758,11 @@ void ShowRoom(SESSION_INFO *si) pDlg->Show(); pDlg->m_pParent = (ParentWindowData*)GetWindowLongPtr(hParent, GWLP_USERDATA); - si->hWnd = pDlg->GetHwnd(); + si->pDlg = pDlg; } - SendMessage(si->hWnd, DM_UPDATETABCONTROL, -1, (LPARAM)si); - SendMessage(GetParent(si->hWnd), CM_ACTIVATECHILD, 0, (LPARAM)si->hWnd); - SendMessage(GetParent(si->hWnd), CM_POPUPWINDOW, 0, (LPARAM)si->hWnd); - SendMessage(si->hWnd, WM_MOUSEACTIVATE, 0, 0); - SetFocus(GetDlgItem(si->hWnd, IDC_MESSAGE)); + SendMessage(si->pDlg->GetHwnd(), DM_UPDATETABCONTROL, -1, (LPARAM)si); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_ACTIVATECHILD, 0, (LPARAM)si->pDlg->GetHwnd()); + SendMessage(GetParent(si->pDlg->GetHwnd()), CM_POPUPWINDOW, 0, (LPARAM)si->pDlg->GetHwnd()); + SendMessage(si->pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0); + SetFocus(GetDlgItem(si->pDlg->GetHwnd(), IDC_MESSAGE)); } -- cgit v1.2.3