summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_chat.h1
-rw-r--r--include/m_chat_int.h25
-rw-r--r--plugins/Scriver/src/chat_main.cpp51
-rw-r--r--src/core/stdmsg/src/chat_manager.cpp23
-rw-r--r--src/mir_app/src/chat_manager.cpp121
-rw-r--r--src/mir_app/src/chat_svc.cpp1
6 files changed, 104 insertions, 118 deletions
diff --git a/include/m_chat.h b/include/m_chat.h
index c241b7675c..6fe8aad0ca 100644
--- a/include/m_chat.h
+++ b/include/m_chat.h
@@ -133,7 +133,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define GC_ACKMSG 0x0020 // the protocol must acknowlege messages sent
#define GC_TYPNOTIF 0x0040 // enable typing notifications.
#define GC_CHANMGR 0x0080 // enable the 'channel settings' button
-#define GC_FONTSIZE 0x0200 // enable font size selection
// Error messages
#define GC_ERROR 1 // An internal error occurred.
diff --git a/include/m_chat_int.h b/include/m_chat_int.h
index 4871a636bd..c57491af82 100644
--- a/include/m_chat_int.h
+++ b/include/m_chat_int.h
@@ -81,21 +81,17 @@ class CChatRoomDlg;
struct GCModuleInfoBase
{
- char* pszModule;
- wchar_t* ptszModDispName;
- char* pszHeader;
- bool bBold;
- bool bUnderline;
- bool bItalics;
- bool bColor;
- bool bBkgColor;
- bool bChanMgr;
- bool bAckMsg;
- bool bFontSize;
- int nColorCount;
- COLORREF* crColors;
+ char *pszModule;
+ wchar_t *ptszModDispName;
+ char *pszHeader;
+
+ bool bBold, bItalics, bUnderline;
+ bool bColor, bBkgColor;
+ bool bChanMgr, bAckMsg;
+
int iMaxText;
- MODULEINFO* next;
+ int nColorCount;
+ COLORREF *crColors;
};
struct COMMANDINFO
@@ -339,6 +335,7 @@ struct CHAT_MANAGER
// user-defined custom callbacks
void (*OnCreateModule)(MODULEINFO*);
+ void (*OnDestroyModule)(MODULEINFO*);
void (*OnCreateSession)(SESSION_INFO*, MODULEINFO*);
void (*OnOfflineSession)(SESSION_INFO*);
diff --git a/plugins/Scriver/src/chat_main.cpp b/plugins/Scriver/src/chat_main.cpp
index 2c845d7a0a..9840936d74 100644
--- a/plugins/Scriver/src/chat_main.cpp
+++ b/plugins/Scriver/src/chat_main.cpp
@@ -29,32 +29,6 @@ pfnDoPopup oldDoPopup;
GlobalLogSettings g_Settings;
-void LoadModuleIcons(MODULEINFO *mi)
-{
- HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0);
-
- int overlayIcon = ImageList_AddIcon(hList, GetCachedIcon("chat_overlay"));
- ImageList_SetOverlayImage(hList, overlayIcon, 1);
-
- int index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE));
-
- if (mi->hOnlineIcon) DestroyIcon(mi->hOnlineIcon);
- mi->hOnlineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT);
-
- if (mi->hOnlineTalkIcon) DestroyIcon(mi->hOnlineTalkIcon);
- mi->hOnlineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
-
- index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE));
-
- if (mi->hOfflineIcon) DestroyIcon(mi->hOfflineIcon);
- mi->hOfflineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT);
-
- if (mi->hOfflineTalkIcon) DestroyIcon(mi->hOfflineTalkIcon);
- mi->hOfflineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
-
- ImageList_Destroy(hList);
-}
-
static void OnReplaceSession(SESSION_INFO *si)
{
if (si->pDlg)
@@ -100,9 +74,31 @@ static void OnFlashWindow(SESSION_INFO *si, int bInactive)
SendMessage(hwndParent, CM_STARTFLASHING, 0, 0);
}
+static void OnDestroyModule(MODULEINFO *mi)
+{
+ if (mi->hOnlineIcon) DestroyIcon(mi->hOnlineIcon);
+ if (mi->hOnlineTalkIcon) DestroyIcon(mi->hOnlineTalkIcon);
+ if (mi->hOfflineIcon) DestroyIcon(mi->hOfflineIcon);
+ if (mi->hOfflineTalkIcon) DestroyIcon(mi->hOfflineTalkIcon);
+}
+
static void OnCreateModule(MODULEINFO *mi)
{
- LoadModuleIcons(mi);
+ HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0);
+
+ int overlayIcon = ImageList_AddIcon(hList, GetCachedIcon("chat_overlay"));
+ ImageList_SetOverlayImage(hList, overlayIcon, 1);
+
+ int index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE));
+ mi->hOnlineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT);
+ mi->hOnlineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
+
+ index = ImageList_AddIcon(hList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE));
+ mi->hOfflineIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT);
+ mi->hOfflineTalkIcon = ImageList_GetIcon(hList, index, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
+
+ ImageList_Destroy(hList);
+
mi->hOnlineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE, true);
mi->hOfflineIconBig = Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE, true);
}
@@ -137,6 +133,7 @@ int Chat_Load()
pci = Chat_GetInterface(&data);
pci->OnCreateModule = OnCreateModule;
+ pci->OnDestroyModule = OnDestroyModule;
pci->OnLoadSettings = OnLoadSettings;
pci->OnSetStatus = OnSetStatus;
diff --git a/src/core/stdmsg/src/chat_manager.cpp b/src/core/stdmsg/src/chat_manager.cpp
index fe7a0c3db7..6d6eedf8bf 100644
--- a/src/core/stdmsg/src/chat_manager.cpp
+++ b/src/core/stdmsg/src/chat_manager.cpp
@@ -66,24 +66,26 @@ HIMAGELIST hIconsList;
GlobalLogSettings g_Settings;
+static void OnDestroyModule(MODULEINFO *mi)
+{
+ if (mi->hOnlineIcon) DestroyIcon(mi->hOnlineIcon);
+ if (mi->hOnlineTalkIcon) DestroyIcon(mi->hOnlineTalkIcon);
+ if (mi->hOfflineIcon) DestroyIcon(mi->hOfflineIcon);
+ if (mi->hOfflineTalkIcon) DestroyIcon(mi->hOfflineTalkIcon);
+}
+
static void OnCreateModule(MODULEINFO *mi)
{
- mi->OnlineIconIndex = ImageList_AddIcon(hIconsList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE));
- mi->OfflineIconIndex = ImageList_AddIcon(hIconsList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE));
+ OnDestroyModule(mi);
- if (mi->hOnlineIcon) DestroyIcon(mi->hOnlineIcon);
+ mi->OnlineIconIndex = ImageList_AddIcon(hIconsList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_ONLINE));
mi->hOnlineIcon = ImageList_GetIcon(hIconsList, mi->OnlineIconIndex, ILD_TRANSPARENT);
-
- if (mi->hOnlineTalkIcon) DestroyIcon(mi->hOnlineTalkIcon);
mi->hOnlineTalkIcon = ImageList_GetIcon(hIconsList, mi->OnlineIconIndex, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
+ ImageList_AddIcon(hIconsList, mi->hOnlineTalkIcon);
- if (mi->hOfflineIcon) DestroyIcon(mi->hOfflineIcon);
+ mi->OfflineIconIndex = ImageList_AddIcon(hIconsList, Skin_LoadProtoIcon(mi->pszModule, ID_STATUS_OFFLINE));
mi->hOfflineIcon = ImageList_GetIcon(hIconsList, mi->OfflineIconIndex, ILD_TRANSPARENT);
-
- if (mi->hOfflineTalkIcon) DestroyIcon(mi->hOfflineTalkIcon);
mi->hOfflineTalkIcon = ImageList_GetIcon(hIconsList, mi->OfflineIconIndex, ILD_TRANSPARENT | INDEXTOOVERLAYMASK(1));
-
- ImageList_AddIcon(hIconsList, mi->hOnlineTalkIcon);
ImageList_AddIcon(hIconsList, mi->hOfflineTalkIcon);
}
@@ -244,6 +246,7 @@ void Load_ChatModule()
pci = Chat_GetInterface(&data);
pci->OnCreateModule = OnCreateModule;
+ pci->OnDestroyModule = OnDestroyModule;
pci->OnReplaceSession = OnReplaceSession;
pci->OnLoadSettings = OnLoadSettings;
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp
index 6909f66690..f2b6fa00cb 100644
--- a/src/mir_app/src/chat_manager.cpp
+++ b/src/mir_app/src/chat_manager.cpp
@@ -34,13 +34,24 @@ static int compareSessions(const SESSION_INFO *p1, const SESSION_INFO *p2)
LIST<SESSION_INFO> g_arSessions(10, compareSessions);
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int compareModules(const MODULEINFO *p1, const MODULEINFO *p2)
+{
+ return mir_strcmp(p1->pszModule, p2->pszModule);
+}
+
+LIST<MODULEINFO> g_arModules(5, compareModules);
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
CHAT_MANAGER::CHAT_MANAGER() :
arSessions(g_arSessions)
{}
CHAT_MANAGER chatApi;
-MODULEINFO *m_ModList = 0;
+/////////////////////////////////////////////////////////////////////////////////////////
static void SetActiveSession(SESSION_INFO *si)
{
@@ -59,11 +70,9 @@ static SESSION_INFO* GetActiveSession(void)
return g_arSessions[0];
}
-//---------------------------------------------------
-// Session Manager functions
-//
-// Keeps track of all sessions and its windows
-//---------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// Session Manager functions
+// Keeps track of all sessions and its windows
static void SM_FreeSession(SESSION_INFO *si, bool bRemoveContact = false)
{
@@ -509,12 +518,9 @@ static void SM_InvalidateLogDirectories()
}
}
-//---------------------------------------------------
-// Module Manager functions
-//
-// Necessary to keep track of all modules
-// that has registered with the plugin
-//---------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module Manager functions
+// Necessary to keep track of all modules that has registered with the plugin
static MODULEINFO* MM_AddModule(const char *pszModule)
{
@@ -529,14 +535,7 @@ static MODULEINFO* MM_AddModule(const char *pszModule)
if (chatApi.OnCreateModule)
chatApi.OnCreateModule(node);
- if (m_ModList == nullptr) { // list is empty
- m_ModList = node;
- node->next = nullptr;
- }
- else {
- node->next = m_ModList;
- m_ModList = node;
- }
+ g_arModules.insert(node);
return node;
}
@@ -544,15 +543,19 @@ static void MM_IconsChanged()
{
LoadChatIcons();
- for (MODULEINFO *mi = m_ModList; mi != nullptr; mi = mi->next)
+ for (int i = 0; i < g_arModules.getCount(); i++) {
+ MODULEINFO *mi = g_arModules[i];
if (chatApi.OnCreateModule) // recreate icons
chatApi.OnCreateModule(mi);
+ }
}
static void MM_FontsChanged()
{
- for (MODULEINFO *mi = m_ModList; mi != nullptr; mi = mi->next)
+ for (int i = 0; i < g_arModules.getCount(); i++) {
+ MODULEINFO *mi = g_arModules[i];
mi->pszHeader = chatApi.Log_CreateRtfHeader(mi);
+ }
}
static MODULEINFO* MM_FindModule(const char *pszModule)
@@ -560,41 +563,37 @@ static MODULEINFO* MM_FindModule(const char *pszModule)
if (!pszModule)
return nullptr;
- for (MODULEINFO *mi = m_ModList; mi != nullptr; mi = mi->next)
- if (mir_strcmpi(mi->pszModule, pszModule) == 0)
- return mi;
-
- return nullptr;
+ return g_arModules.find((MODULEINFO*)&pszModule);
}
// stupid thing..
static void MM_FixColors()
{
- for (MODULEINFO *mi = m_ModList; mi != nullptr; mi = mi->next)
+ for (int i = 0; i < g_arModules.getCount(); i++) {
+ MODULEINFO *mi = g_arModules[i];
CheckColorsInModule(mi->pszModule);
+ }
}
static BOOL MM_RemoveAll(void)
{
- while (m_ModList != nullptr) {
- MODULEINFO *pLast = m_ModList->next;
- mir_free(m_ModList->pszModule);
- mir_free(m_ModList->ptszModDispName);
- mir_free(m_ModList->pszHeader);
- mir_free(m_ModList->crColors);
- mir_free(m_ModList);
- m_ModList = pLast;
+ for (int i = 0; i < g_arModules.getCount(); i++) {
+ MODULEINFO *mi = g_arModules[i];
+ if (chatApi.OnDestroyModule)
+ chatApi.OnDestroyModule(mi);
+
+ mir_free(mi->pszModule);
+ mir_free(mi->ptszModDispName);
+ mir_free(mi->pszHeader);
+ mir_free(mi->crColors);
+ mir_free(mi);
}
- m_ModList = nullptr;
return TRUE;
}
-//---------------------------------------------------
-// Status manager functions
-//
-// Necessary to keep track of what user statuses
-// per window nicklist that is available
-//---------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// Status manager functions
+// Necessary to keep track of what user statuses per window nicklist that is available
static STATUSINFO* TM_AddStatus(STATUSINFO **ppStatusList, const wchar_t *pszStatus, int *iCount)
{
@@ -684,12 +683,9 @@ static BOOL TM_RemoveAll(STATUSINFO **ppStatusList)
return TRUE;
}
-//---------------------------------------------------
-// User manager functions
-//
-// Necessary to keep track of the users
-// in a window nicklist
-//---------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// User manager functions
+// Necessary to keep track of the users in a window nicklist
static int UM_CompareItem(USERINFO *u1, const wchar_t *pszNick, WORD wStatus)
{
@@ -922,12 +918,9 @@ static BOOL UM_RemoveAll(USERINFO **ppUserList)
return TRUE;
}
-//---------------------------------------------------
-// Log manager functions
-//
-// Necessary to keep track of events
-// in a window log
-//---------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// Log manager functions
+// Necessary to keep track of events in a window log
static LOGINFO* LM_AddEvent(LOGINFO **ppLogListStart, LOGINFO** ppLogListEnd)
{
@@ -1011,20 +1004,18 @@ MIR_APP_DLL(CHAT_MANAGER*) Chat_GetInterface(CHAT_MANAGER_INITDATA *pInit, int _
}
if (g_cbModuleInfo) { // reallocate old modules
mir_cslock lck(csChat);
- MODULEINFO *pPrev = nullptr;
- for (MODULEINFO *p = m_ModList; p; p = p->next) {
- MODULEINFO *p1 = (MODULEINFO*)mir_realloc(p, pInit->cbModuleInfo);
+
+ for (int i = 0; i < g_arModules.getCount(); i++) {
+ MODULEINFO *mi = g_arModules[i];
+ MODULEINFO *p1 = (MODULEINFO*)mir_realloc(mi, pInit->cbModuleInfo);
memset(PBYTE(p1) + sizeof(GCModuleInfoBase), 0, pInit->cbModuleInfo - sizeof(GCModuleInfoBase));
- if (p1 != p) { // realloc could change a pointer, reinsert a structure
- if (m_ModList == p)
- m_ModList = p1;
- if (pPrev != nullptr)
- pPrev->next = p1;
- p = p1;
+ if (p1 != mi) { // realloc could change a pointer, reinsert a structure
+ g_arModules.remove(i);
+ g_arModules.insert(p1, i);
}
- pPrev = p;
}
}
+
g_Settings = pInit->pSettings;
g_szFontGroup = pInit->szFontGroup;
g_cbSession = pInit->cbSession;
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp
index 990eeb5169..da3deabc4a 100644
--- a/src/mir_app/src/chat_svc.cpp
+++ b/src/mir_app/src/chat_svc.cpp
@@ -173,7 +173,6 @@ MIR_APP_DLL(int) Chat_Register(const GCREGISTER *gcr)
mi->bBkgColor = (gcr->dwFlags & GC_BKGCOLOR) != 0;
mi->bAckMsg = (gcr->dwFlags & GC_ACKMSG) != 0;
mi->bChanMgr = (gcr->dwFlags & GC_CHANMGR) != 0;
- mi->bFontSize = (gcr->dwFlags & GC_FONTSIZE) != 0;
mi->iMaxText = gcr->iMaxText;
mi->nColorCount = gcr->nColors;
if (gcr->nColors > 0) {