diff options
29 files changed, 335 insertions, 323 deletions
diff --git a/include/m_chat_int.h b/include/m_chat_int.h index 7b2b0c35b1..c8d9c9bc27 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef M_CHAT_INT_H__
#define M_CHAT_INT_H__ 1
+#pragma warning(disable:4512)
+
#include <m_string.h>
#include <m_chat.h>
#include <m_gui.h>
@@ -101,6 +103,8 @@ struct SESSION_INFO; struct MODULEINFO;
struct LOGSTREAMDATA;
+class CChatRoomDlg;
+
struct GCModuleInfoBase
{
char* pszModule;
@@ -172,7 +176,7 @@ struct USERINFO struct GCSessionInfoBase
{
- HWND hWnd;
+ MCONTACT hContact;
bool bFGSet;
bool bBGSet;
@@ -202,11 +206,11 @@ struct GCSessionInfoBase WORD wState;
WORD wCommandsNum;
void* pItemData;
- MCONTACT hContact;
time_t LastTime;
int currentHovered;
+ CChatRoomDlg *pDlg;
COMMANDINFO* lpCommands;
COMMANDINFO* lpCurrentCommand;
LOGINFO* pLog;
@@ -216,7 +220,6 @@ struct GCSessionInfoBase STATUSINFO* pStatuses;
wchar_t pszLogFileName[MAX_PATH];
- SESSION_INFO *next;
};
struct GCLogStreamDataBase
@@ -290,8 +293,13 @@ struct CHAT_MANAGER_INITDATA int iFontMode;
};
+typedef BOOL (*pfnDoTrayIcon)(SESSION_INFO *si, GCEVENT *gce);
+typedef BOOL (*pfnDoPopup)(SESSION_INFO *si, GCEVENT *gce);
+
struct CHAT_MANAGER
{
+ CHAT_MANAGER();
+
void (*SetActiveSession)(const wchar_t *pszID, const char *pszModule);
void (*SetActiveSessionEx)(SESSION_INFO *si);
SESSION_INFO* (*GetActiveSession)(void);
@@ -373,7 +381,7 @@ struct CHAT_MANAGER HBRUSH hListBkgBrush, hListSelectedBkgBrush;
HANDLE hBuildMenuEvent, hSendEvent;
FONTINFO aFonts[OPTIONS_FONTCOUNT];
- SESSION_INFO *wndList;
+ LIST<SESSION_INFO> &arSessions;
char **pLogIconBmpBits;
MWindowList hWindowList;
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));
}
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<char> *szSettings = (LIST<char>*)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;
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 7e6e032d3b..1b31333ae0 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -69,4 +69,4 @@ int StrToStatus(const CMStringW &str); time_t StringToDate(const CMStringW &str); int SerialNext(void); -struct SESSION_INFO : public GCSessionInfoBase {};
\ No newline at end of file +struct SESSION_INFO : public GCSessionInfoBase {}; diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index 794983a869..55bec5bc71 100644 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -108,8 +108,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "jabber_ibb.h"
#include "jabber_db_utils.h"
-struct SESSION_INFO : public GCSessionInfoBase
-{};
+struct SESSION_INFO : public GCSessionInfoBase {};
struct CJabberProto;
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h index 73cb54d892..ad04ab61e1 100644 --- a/protocols/SkypeWeb/src/stdafx.h +++ b/protocols/SkypeWeb/src/stdafx.h @@ -62,8 +62,7 @@ extern char g_szMirVer[]; extern HANDLE g_hCallEvent;
extern FI_INTERFACE *fii;
-struct SESSION_INFO : public GCSessionInfoBase
-{};
+struct SESSION_INFO : public GCSessionInfoBase {};
#define SKYPE_ENDPOINTS_HOST "client-s.gateway.messenger.live.com"
diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp index 0041d3ea6f..c0e881954d 100644 --- a/src/core/stdmsg/src/chat_manager.cpp +++ b/src/core/stdmsg/src/chat_manager.cpp @@ -22,56 +22,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" +pfnDoTrayIcon oldDoTrayIcon; +pfnDoPopup oldDoPopup; + SESSION_INFO* SM_GetPrevWindow(SESSION_INFO *si) { - if (!si) - return NULL; - - BOOL bFound = FALSE; - SESSION_INFO *pTemp = pci->wndList; - while (pTemp != NULL) { - if (si == pTemp) { - if (bFound) - return NULL; - else - bFound = TRUE; - } - else if (bFound == TRUE && pTemp->hWnd) - return pTemp; - pTemp = pTemp->next; - if (pTemp == NULL && bFound) - pTemp = pci->wndList; + int i = pci->arSessions.indexOf(si); + if (i == -1) + return nullptr; + + for (i--; i >= 0; i--) { + SESSION_INFO *p = pci->arSessions[i]; + if (p->pDlg) + return p; } - return NULL; + + return nullptr; } SESSION_INFO* SM_GetNextWindow(SESSION_INFO *si) { - if (!si) - return NULL; - - SESSION_INFO *pTemp = pci->wndList, *pLast = NULL; - while (pTemp != NULL) { - if (si == pTemp) { - if (pLast) { - if (pLast != pTemp) - return pLast; - else - return NULL; - } - } - if (pTemp->hWnd) - pLast = pTemp; - pTemp = pTemp->next; - if (pTemp == NULL) - pTemp = pci->wndList; + int i = pci->arSessions.indexOf(si); + if (i == -1) + return nullptr; + + for (i++; i < pci->arSessions.getCount(); i++) { + SESSION_INFO *p = pci->arSessions[i]; + if (p->pDlg) + return p; } - return NULL; + + return nullptr; } ///////////////////////////////////////////////////////////////////////////////////////// -CHAT_MANAGER *pci, saveCI; +CHAT_MANAGER *pci; HMENU g_hMenu = NULL; @@ -95,14 +81,14 @@ static void OnCreateModule(MODULEINFO *mi) static void OnReplaceSession(SESSION_INFO *si) { - if (si->hWnd) - RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), NULL, NULL, RDW_INVALIDATE); + if (si->pDlg) + RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), NULL, NULL, 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 OnFlashHighlight(SESSION_INFO *si, int bInactive) @@ -110,10 +96,10 @@ static void OnFlashHighlight(SESSION_INFO *si, int bInactive) if (!bInactive) return; - if (!g_Settings.bTabsEnable && si->hWnd && g_Settings.bFlashWindowHighlight) - SetTimer(si->hWnd, TIMERID_FLASHWND, 900, NULL); + if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindowHighlight) + SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, NULL); if (g_Settings.bTabsEnable && si->pDlg) - SendMessage(si->hWnd, GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si->pDlg); + SendMessage(si->pDlg->GetHwnd(), GC_SETMESSAGEHIGHLIGHT, 0, (LPARAM)si->pDlg); } static void OnFlashWindow(SESSION_INFO *si, int bInactive) @@ -121,23 +107,23 @@ static void OnFlashWindow(SESSION_INFO *si, int bInactive) if (!bInactive) return; - if (!g_Settings.bTabsEnable && si->hWnd && g_Settings.bFlashWindow) - SetTimer(si->hWnd, TIMERID_FLASHWND, 900, NULL); + if (!g_Settings.bTabsEnable && si->pDlg && g_Settings.bFlashWindow) + SetTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND, 900, NULL); if (g_Settings.bTabsEnable && si->pDlg) - SendMessage(si->hWnd, GC_SETTABHIGHLIGHT, 0, (LPARAM)si->pDlg); + SendMessage(si->pDlg->GetHwnd(), GC_SETTABHIGHLIGHT, 0, (LPARAM)si->pDlg); } 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; } @@ -212,10 +198,8 @@ void Load_ChatModule() CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Chat module"), FONTMODE_SKIP }; pci = Chat_GetInterface(&data); - saveCI = *pci; pci->OnNewUser = OnNewUser; - pci->OnCreateModule = OnCreateModule; pci->OnReplaceSession = OnReplaceSession; @@ -224,8 +208,8 @@ void Load_ChatModule() 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/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp index 26d8f37f12..b9a44e45f6 100644 --- a/src/core/stdmsg/src/chat_util.cpp +++ b/src/core/stdmsg/src/chat_util.cpp @@ -171,13 +171,12 @@ bool LoadMessageFont(LOGFONT *lf, COLORREF *colour) lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; mir_snprintf(str, "SRMFont%d", i); - DBVARIANT dbv; - if (db_get_ws(NULL, "SRMM", str, &dbv)) + ptrW wszFontFace(db_get_wsa(NULL, "SRMM", str)); + if (wszFontFace == nullptr) mir_wstrcpy(lf->lfFaceName, L"Arial"); - else { - mir_wstrncpy(lf->lfFaceName, dbv.ptszVal, _countof(lf->lfFaceName)); - db_free(&dbv); - } + else + mir_wstrncpy(lf->lfFaceName, wszFontFace, _countof(lf->lfFaceName)); + mir_snprintf(str, "SRMFont%dSet", i); lf->lfCharSet = db_get_b(NULL, "SRMM", str, DEFAULT_CHARSET); } diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index b66912c87d..cf7cf376ac 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -819,8 +819,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); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -881,7 +881,6 @@ CChatRoomDlg::CChatRoomDlg(SESSION_INFO *si) : void CChatRoomDlg::OnInitDialog() { - m_si->hWnd = m_hwnd; m_si->pDlg = this; if (g_Settings.bTabsEnable) @@ -937,8 +936,7 @@ void CChatRoomDlg::OnDestroy() WindowList_Remove(pci->hWindowList, m_hwnd); - m_si->pDlg = NULL; - m_si->hWnd = NULL; + m_si->pDlg = nullptr; m_si->wState &= ~STATE_TALK; DestroyWindow(m_hwndStatus); m_hwndStatus = NULL; @@ -1168,14 +1166,14 @@ void CChatRoomDlg::SetWindowPosition() else SetWindowPos(m_hwnd, 0, (screen.right - screen.left) / 2 - (550) / 2, (screen.bottom - screen.top) / 2 - (400) / 2, (550), (400), SWP_NOZORDER | SWP_HIDEWINDOW | SWP_NOACTIVATE); SESSION_INFO *pActive = pci->GetActiveSession(); - if (pActive && pActive->hWnd && db_get_b(NULL, CHAT_MODULE, "CascadeWindows", 1)) { + if (pActive && pActive->pDlg && db_get_b(NULL, CHAT_MODULE, "CascadeWindows", 1)) { RECT rcThis, rcNew; int dwFlag = SWP_NOZORDER | SWP_NOACTIVATE; if (!IsWindowVisible(m_hwnd)) dwFlag |= SWP_HIDEWINDOW; GetWindowRect(m_hwnd, &rcThis); - GetWindowRect(pActive->hWnd, &rcNew); + GetWindowRect(pActive->pDlg->GetHwnd(), &rcNew); int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME); SetWindowPos(m_hwnd, 0, rcNew.left + offset, rcNew.top + offset, rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, dwFlag); @@ -1491,7 +1489,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: diff --git a/src/core/stdmsg/src/globals.cpp b/src/core/stdmsg/src/globals.cpp index 4a42858cbb..5b2ec570f5 100644 --- a/src/core/stdmsg/src/globals.cpp +++ b/src/core/stdmsg/src/globals.cpp @@ -44,8 +44,11 @@ static int IconsChanged(WPARAM, LPARAM) static int OnShutdown(WPARAM, LPARAM)
{
- for (SESSION_INFO *si = pci->wndList; si; si = si->next)
- SendMessage(si->hWnd, WM_CLOSE, 0, 0);
+ for (int i = 0; i < pci->arSessions.getCount(); i++) {
+ SESSION_INFO *si = pci->arSessions[i];
+ if (si->pDlg)
+ si->pDlg->Close();
+ }
UninitTabs();
ImageList_Destroy(hIconsList);
diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index 076d743dad..f15624007b 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -92,7 +92,6 @@ struct MODULEINFO : public GCModuleInfoBase struct SESSION_INFO : public GCSessionInfoBase
{
int iX, iY;
- class CChatRoomDlg *pDlg;
};
struct LOGSTREAMDATA : public GCLogStreamDataBase {};
@@ -110,7 +109,6 @@ struct GlobalLogSettings : public GlobalLogSettingsBase /////////////////////////////////////////////////////////////////////////////////////////
extern GlobalLogSettings g_Settings;
-extern CHAT_MANAGER saveCI;
extern HMENU g_hMenu;
extern HIMAGELIST hIconsList;
diff --git a/src/core/stdmsg/src/tabs.cpp b/src/core/stdmsg/src/tabs.cpp index 11bc1d1e39..5a4a904096 100644 --- a/src/core/stdmsg/src/tabs.cpp +++ b/src/core/stdmsg/src/tabs.cpp @@ -243,7 +243,7 @@ void CTabbedWindow::TabClicked() } SendMessage(m_hwnd, GC_FIXTABICONS, 0, (LPARAM)pDlg); - if (!s->hWnd) { + if (!s->pDlg) { pci->ShowRoom(s); SendMessage(m_hwnd, WM_MOUSEACTIVATE, 0, 0); } @@ -527,9 +527,9 @@ void ShowRoom(SESSION_INFO *si) return; // Do we need to create a window? - if (si->hWnd == NULL) { + if (si->pDlg == nullptr) { if (g_Settings.bTabsEnable) { - if (pDialog == NULL) { + if (pDialog == nullptr) { pDialog = new CTabbedWindow(); pDialog->Show(); } @@ -541,22 +541,22 @@ void ShowRoom(SESSION_INFO *si) pRoom->Show(); } - PostMessage(si->hWnd, WM_SIZE, 0, 0); + PostMessage(si->pDlg->GetHwnd(), WM_SIZE, 0, 0); if (si->iType != GCW_SERVER) - SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0); else - SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0); - SendMessage(si->hWnd, GC_REDRAWLOG, 0, 0); - SendMessage(si->hWnd, GC_UPDATESTATUSBAR, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_UPDATETITLE, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG, 0, 0); + SendMessage(si->pDlg->GetHwnd(), GC_UPDATESTATUSBAR, 0, 0); } - SetWindowLongPtr(si->hWnd, GWL_EXSTYLE, GetWindowLongPtr(si->hWnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); + SetWindowLongPtr(si->pDlg->GetHwnd(), GWL_EXSTYLE, GetWindowLongPtr(si->pDlg->GetHwnd(), GWL_EXSTYLE) | WS_EX_APPWINDOW); - if (IsIconic(si->hWnd)) - ShowWindow(si->hWnd, SW_NORMAL); - ShowWindow(si->hWnd, SW_SHOW); - SetForegroundWindow(si->hWnd); + if (IsIconic(si->pDlg->GetHwnd())) + ShowWindow(si->pDlg->GetHwnd(), SW_NORMAL); + ShowWindow(si->pDlg->GetHwnd(), SW_SHOW); + SetForegroundWindow(si->pDlg->GetHwnd()); - SendMessage(si->hWnd, WM_MOUSEACTIVATE, 0, 0); - SetFocus(GetDlgItem(si->hWnd, IDC_MESSAGE)); + SendMessage(si->pDlg->GetHwnd(), WM_MOUSEACTIVATE, 0, 0); + SetFocus(GetDlgItem(si->pDlg->GetHwnd(), IDC_MESSAGE)); } diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 66c39fa753..fbfc8872f6 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -27,6 +27,11 @@ struct MODULEINFO : public GCModuleInfoBase {}; struct SESSION_INFO : public GCSessionInfoBase {};
struct LOGSTREAMDATA : public GCLogStreamDataBase {};
+class CChatRoomDlg : public CSrmmBaseDialog
+{
+ CChatRoomDlg(); // just to suppress compiler's warnings, never implemented
+};
+
extern HGENMENU hJoinMenuItem, hLeaveMenuItem;
extern GlobalLogSettingsBase *g_Settings;
extern int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang;
@@ -34,6 +39,7 @@ extern wchar_t *g_szFontGroup; extern mir_cs csChat;
extern char* pLogIconBmpBits[14];
+extern LIST<SESSION_INFO> g_arSessions;
// log.c
void LoadMsgLogBitmaps(void);
@@ -104,7 +110,7 @@ bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText);
void DestroyGCMenu(HMENU *hMenu, int iIndex);
BOOL DoEventHookAsync(HWND hwnd, const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
-BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
+BOOL DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
BOOL IsEventSupported(int eventType);
BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce);
BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce);
diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 93346dd334..70a126dbe8 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -117,8 +117,8 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) SESSION_INFO *si = SM_FindSession(roomid, szProto);
if (si) {
// is the "toggle visibility option set, so we need to close the window?
- if (si->hWnd != NULL && db_get_b(NULL, CHAT_MODULE, "ToggleVisibility", 0) == 1 && !cli.pfnGetEvent(hContact, 0) && IsWindowVisible(si->hWnd) && !IsIconic(si->hWnd)) {
- PostMessage(si->hWnd, GC_CLOSEWINDOW, 0, 0);
+ if (si->pDlg != NULL && db_get_b(NULL, CHAT_MODULE, "ToggleVisibility", 0) == 1 && !cli.pfnGetEvent(hContact, 0) && IsWindowVisible(si->pDlg->GetHwnd()) && !IsIconic(si->pDlg->GetHwnd())) {
+ PostMessage(si->pDlg->GetHwnd(), GC_CLOSEWINDOW, 0, 0);
return 1;
}
chatApi.ShowRoom(si);
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 9c373c376a..1ff2b061e2 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -26,6 +26,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define WINDOWS_COMMANDS_MAX 30
+static int compareSessions(const SESSION_INFO *p1, const SESSION_INFO *p2)
+{
+ int res = mir_strcmp(p1->pszModule, p2->pszModule);
+ return (res != 0) ? res : mir_wstrcmp(p1->ptszID, p2->ptszID);
+}
+
+LIST<SESSION_INFO> g_arSessions(10, compareSessions);
+
+CHAT_MANAGER::CHAT_MANAGER() :
+ arSessions(g_arSessions)
+{}
+
CHAT_MANAGER chatApi;
MODULEINFO *m_ModList = 0;
@@ -51,7 +63,7 @@ static SESSION_INFO* GetActiveSession(void) if (si)
return si;
- return chatApi.wndList;
+ return g_arSessions[0];
}
//---------------------------------------------------
@@ -99,18 +111,13 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon if (!pszModule)
return FALSE;
- SESSION_INFO *si = chatApi.wndList, *pLast = NULL;
- while (si != NULL) {
+ for (int i = g_arSessions.getCount() - 1; i >= 0; i--) {
+ SESSION_INFO *si = g_arSessions[i];
// match
if ((!pszID && si->iType != GCW_SERVER || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) {
- if (si->hWnd)
- SendMessage(si->hWnd, GC_CONTROL_MSG, SESSION_TERMINATE, 0);
- DoEventHook(si->ptszID, si->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
-
- if (pLast == NULL)
- chatApi.wndList = si->next;
- else
- pLast->next = si->next;
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_CONTROL_MSG, SESSION_TERMINATE, 0);
+ DoEventHook(si, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
// contact may have been deleted here already, since function may be called after deleting
// contact so the handle may be invalid, therefore db_get_b shall return 0
@@ -118,18 +125,10 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon db_delete_contact(si->hContact);
SM_FreeSession(si);
+ g_arSessions.remove(i);
if (pszID)
return 1;
-
- if (pLast)
- si = pLast->next;
- else
- si = chatApi.wndList;
- }
- else {
- pLast = si;
- si = si->next;
}
}
return FALSE;
@@ -138,14 +137,14 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon SESSION_INFO* SM_FindSession(const wchar_t *pszID, const char *pszModule)
{
if (!pszID || !pszModule)
- return NULL;
+ return nullptr;
- mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next)
- if (!mir_wstrcmpi(si->ptszID, pszID) && !mir_strcmpi(si->pszModule, pszModule))
- return si;
+ SESSION_INFO tmp;
+ tmp.pszModule = (char*)pszModule;
+ tmp.ptszID = (wchar_t*)pszID;
- return NULL;
+ mir_cslock lck(csChat);
+ return g_arSessions.find(&tmp);
}
BOOL SM_SetOffline(const wchar_t *pszID, const char *pszModule)
@@ -153,7 +152,8 @@ BOOL SM_SetOffline(const wchar_t *pszID, const char *pszModule) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -231,7 +231,8 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p if (!pszModule || !pszUID)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -245,8 +246,8 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p si->pMe = NULL;
chatApi.UM_RemoveUser(&si->pUsers, pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
if (pszID)
return TRUE;
@@ -271,8 +272,8 @@ BOOL SM_GiveStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *p USERINFO *ui = chatApi.UM_GiveStatus(si->pUsers, pszUID, chatApi.TM_StringToWord(si->pStatuses, pszStatus));
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -286,8 +287,8 @@ BOOL SM_SetContactStatus(const wchar_t *pszID, const char *pszModule, const wcha USERINFO *ui = chatApi.UM_SetContactStatus(si->pUsers, pszUID, wStatus);
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -301,8 +302,8 @@ BOOL SM_TakeStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *p USERINFO *ui = chatApi.UM_TakeStatus(si->pUsers, pszUID, chatApi.TM_StringToWord(si->pStatuses, pszStatus));
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -312,12 +313,13 @@ LRESULT SM_SendMessage(const wchar_t *pszID, const char *pszModule, UINT msg, WP if (pszModule == NULL)
return 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
- if (si->hWnd) {
- LRESULT i = SendMessage(si->hWnd, msg, wParam, lParam);
+ if (si->pDlg) {
+ LRESULT i = SendMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
if (pszID)
return i;
}
@@ -329,15 +331,16 @@ LRESULT SM_SendMessage(const wchar_t *pszID, const char *pszModule, UINT msg, WP static BOOL SM_BroadcastMessage(const char *pszModule, UINT msg, WPARAM wParam, LPARAM lParam, BOOL bAsync)
{
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (pszModule && _strcmpi(si->pszModule, pszModule))
continue;
- if (si->hWnd) {
+ if (si->pDlg) {
if (bAsync)
- PostMessage(si->hWnd, msg, wParam, lParam);
+ PostMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
else
- SendMessage(si->hWnd, msg, wParam, lParam);
+ SendMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
}
}
return TRUE;
@@ -348,7 +351,8 @@ BOOL SM_SetStatus(const wchar_t *pszID, const char *pszModule, int wStatus) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -374,14 +378,15 @@ BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((!pszID || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) {
USERINFO *ui = chatApi.UM_FindUser(si->pUsers, gce->ptszUID);
if (ui) {
replaceStrW(ui->pszNick, gce->ptszText);
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
if (chatApi.OnChangeNick)
chatApi.OnChangeNick(si);
}
@@ -395,17 +400,16 @@ BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) void SM_RemoveAll(void)
{
- while (chatApi.wndList) {
- SESSION_INFO *pLast = chatApi.wndList->next;
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
- if (chatApi.wndList->hWnd)
- SendMessage(chatApi.wndList->hWnd, GC_CONTROL_MSG, SESSION_TERMINATE, 0);
- DoEventHook(chatApi.wndList->ptszID, chatApi.wndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)chatApi.wndList->pItemData);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_CONTROL_MSG, SESSION_TERMINATE, 0);
+ DoEventHook(si, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
- SM_FreeSession(chatApi.wndList);
- chatApi.wndList = pLast;
+ SM_FreeSession(si);
}
- chatApi.wndList = NULL;
+ g_arSessions.destroy();
}
static void SM_AddCommand(const wchar_t *pszID, const char *pszModule, const char* lpNewCommand)
@@ -480,9 +484,11 @@ static int SM_GetCount(const char *pszModule) {
int count = 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next)
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (!mir_strcmpi(pszModule, si->pszModule))
count++;
+ }
return count;
}
@@ -490,7 +496,8 @@ static int SM_GetCount(const char *pszModule) static SESSION_INFO* SM_FindSessionByIndex(const char *pszModule, int iItem)
{
int count = 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (!mir_strcmpi(pszModule, si->pszModule)) {
if (iItem == count)
return si;
@@ -508,7 +515,8 @@ char* SM_GetUsers(SESSION_INFO *si) return NULL;
USERINFO *utemp = NULL;
- for (SESSION_INFO *p = chatApi.wndList; p != NULL; p = p->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
if (si == p) {
if ((utemp = p->pUsers) == NULL)
return NULL;
@@ -536,8 +544,10 @@ char* SM_GetUsers(SESSION_INFO *si) static void SM_InvalidateLogDirectories()
{
- for (SESSION_INFO *si = chatApi.wndList; si; si = si->next)
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
si->pszLogFileName[0] = si->pszLogFileName[1] = 0;
+ }
}
//---------------------------------------------------
@@ -1031,6 +1041,12 @@ static BOOL LM_RemoveAll(LOGINFO **ppLogListStart, LOGINFO **ppLogListEnd) return TRUE;
}
+static BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
+{
+ SESSION_INFO *si = chatApi.SM_FindSession(pszID, pszModule);
+ return (si) ? DoEventHook(si, iType, pUser, pszText, dwItem) : FALSE;
+}
+
MIR_APP_DLL(CHAT_MANAGER*) Chat_GetInterface(CHAT_MANAGER_INITDATA *pInit, int _hLangpack)
{
if (pInit == NULL)
@@ -1041,18 +1057,15 @@ MIR_APP_DLL(CHAT_MANAGER*) Chat_GetInterface(CHAT_MANAGER_INITDATA *pInit, int _ if (g_cbSession) { // reallocate old sessions
mir_cslock lck(csChat);
- SESSION_INFO *pPrev = NULL;
- for (SESSION_INFO *p = chatApi.wndList; p; p = p->next) {
+
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
SESSION_INFO *p1 = (SESSION_INFO*)mir_realloc(p, pInit->cbSession);
memset(PBYTE(p1) + sizeof(GCSessionInfoBase), 0, pInit->cbSession - sizeof(GCSessionInfoBase));
if (p1 != p) { // realloc could change a pointer, reinsert a structure
- if (chatApi.wndList == p)
- chatApi.wndList = p1;
- if (pPrev != NULL)
- pPrev->next = p1;
- p = p1;
+ g_arSessions.remove(i);
+ g_arSessions.insert(p1);
}
- pPrev = p;
}
}
if (g_cbModuleInfo) { // reallocate old modules
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index 2d8dc7cb24..a3f8f492d0 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -220,12 +220,7 @@ EXTERN_C MIR_APP_DLL(GCSessionInfoBase*) Chat_NewSession( si->ptszID = mir_wstrdup(ptszID);
si->pszModule = mir_strdup(pszModule);
- if (chatApi.wndList == NULL) // list is empty
- chatApi.wndList = si;
- else {
- si->next = chatApi.wndList;
- chatApi.wndList = si;
- }
+ chatApi.arSessions.insert(si);
lck.unlock();
// set the defaults
@@ -413,7 +408,8 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) {
int bManyFix = 0;
- for (SESSION_INFO *p = chatApi.wndList; p != NULL; p = p->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
if (!p->bInitDone || mir_strcmpi(p->pszModule, gce->pDest->pszModule))
continue;
@@ -423,11 +419,11 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) if (chatApi.OnEventBroadcast)
chatApi.OnEventBroadcast(p, gce);
- if (p->hWnd && p->bInitDone) {
+ if (p->pDlg && p->bInitDone) {
if (SM_AddEvent(p->ptszID, p->pszModule, gce, FALSE))
- SendMessage(p->hWnd, GC_ADDLOG, 0, 0);
+ SendMessage(p->pDlg->GetHwnd(), GC_ADDLOG, 0, 0);
else
- SendMessage(p->hWnd, GC_REDRAWLOG2, 0, 0);
+ SendMessage(p->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0);
}
if (!(gce->dwFlags & GCEF_NOTNOTIFY)) {
@@ -569,11 +565,11 @@ EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT *gce) }
int isOk = SM_AddEvent(pWnd, pMod, gce, bIsHighlighted);
- if (si->hWnd) {
+ if (si->pDlg) {
if (isOk)
- SendMessage(si->hWnd, GC_ADDLOG, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_ADDLOG, 0, 0);
else
- SendMessage(si->hWnd, GC_REDRAWLOG2, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0);
}
if (!(gce->dwFlags & GCEF_NOTNOTIFY)) {
@@ -637,8 +633,8 @@ MIR_APP_DLL(int) Chat_ChangeSessionName(const char *szModule, const wchar_t *wsz replaceStrW(si->ptszName, wszNewName);
db_set_ws(si->hContact, szModule, "Nick", wszNewName);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATETITLE, 0, 0);
}
return 0;
}
@@ -649,7 +645,8 @@ MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszId, c return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
@@ -676,12 +673,13 @@ MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
if (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS)
- DoEventHook(si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, wszText, 0);
+ DoEventHook(si, GC_USER_MESSAGE, NULL, wszText, 0);
if (wszId)
break;
}
@@ -702,8 +700,8 @@ MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszI else
db_set_s(si->hContact, si->pszModule, "StatusBar", "");
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATESTATUSBAR, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATESTATUSBAR, 0, 0);
}
return 0;
}
@@ -714,13 +712,14 @@ MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t *wszId, in return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
chatApi.UM_SetStatusEx(si->pUsers, wszText, flags);
- if (si->hWnd)
- RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), NULL, NULL, RDW_INVALIDATE);
+ if (si->pDlg)
+ RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), NULL, NULL, RDW_INVALIDATE);
if (wszId)
break;
}
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 39ad6f98a4..13f573a2c4 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -154,8 +154,8 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA if (cli.pfnGetEvent(si->hContact, 0))
cli.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);
PUDeletePopup(hWnd);
break;
@@ -273,7 +273,7 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (!gce || !si || gce->bIsMe || si->iType == GCW_SERVER)
return FALSE;
- BOOL bInactive = si->hWnd == NULL || GetForegroundWindow() != si->hWnd;
+ BOOL bInactive = si->pDlg == NULL || GetForegroundWindow() != si->pDlg->GetHwnd();
int iEvent = gce->pDest->iType;
@@ -631,15 +631,14 @@ BOOL DoEventHookAsync(HWND hwnd, const wchar_t *pszID, const char *pszModule, in return TRUE;
}
-BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
+BOOL DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
{
- SESSION_INFO *si = chatApi.SM_FindSession(pszID, pszModule);
- if (si == NULL)
+ if (si == nullptr)
return FALSE;
- GCDEST gcd = { (char*)pszModule, pszID, iType };
+ GCDEST gcd = { si->pszModule, si->ptszID, iType };
GCHOOK gch = { 0 };
- if (pUser != NULL) {
+ if (pUser != nullptr) {
gch.ptszUID = pUser->pszUID;
gch.ptszNick = pUser->pszNick;
}
diff --git a/src/mir_app/src/netlibsock.cpp b/src/mir_app/src/netlibsock.cpp index 57cb023b4b..7bfbd3c7df 100644 --- a/src/mir_app/src/netlibsock.cpp +++ b/src/mir_app/src/netlibsock.cpp @@ -69,7 +69,7 @@ MIR_APP_DLL(int) Netlib_Recv(HNETLIBCONN nlc, char *buf, int len, int flags) recvResult = NetlibHttpGatewayRecv(nlc, buf, len, flags);
else {
if (!nlc->foreBuf.isEmpty()) {
- recvResult = min(len, nlc->foreBuf.length());
+ recvResult = min(len, (int)nlc->foreBuf.length());
memcpy(buf, nlc->foreBuf.data(), recvResult);
nlc->foreBuf.remove(recvResult);
}
|