diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-13 16:55:17 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-13 16:55:17 +0000 |
commit | cbe3cb21f5bca61a03bbd4ae811ee906e09b3f4f (patch) | |
tree | 4854fb66f4d59940efa3c1590237915851074dbf /src/modules/chat | |
parent | 351bcbec48ed77af5f8efcc4d5198707922c5d86 (diff) |
- miranda32.exe now does nothing bug extends PATH to %miranda_root%\libs and loads mir_app.dll;
- everything that was in miranda32.exe (including resources) moved to mir_app.dll;
- exports from mir_app.dll now available for using directly, without perversions;
- src/stdplug.h deleted;
git-svn-id: http://svn.miranda-ng.org/main/trunk@14143 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/chat')
-rw-r--r-- | src/modules/chat/chat.h | 110 | ||||
-rw-r--r-- | src/modules/chat/chat_opts.cpp | 351 | ||||
-rw-r--r-- | src/modules/chat/chat_rtf.cpp | 204 | ||||
-rw-r--r-- | src/modules/chat/chat_svc.cpp | 631 | ||||
-rw-r--r-- | src/modules/chat/clist.cpp | 250 | ||||
-rw-r--r-- | src/modules/chat/colorchooser.cpp | 284 | ||||
-rw-r--r-- | src/modules/chat/log.cpp | 542 | ||||
-rw-r--r-- | src/modules/chat/manager.cpp | 1331 | ||||
-rw-r--r-- | src/modules/chat/tools.cpp | 768 |
9 files changed, 0 insertions, 4471 deletions
diff --git a/src/modules/chat/chat.h b/src/modules/chat/chat.h deleted file mode 100644 index a84ed5cf54..0000000000 --- a/src/modules/chat/chat.h +++ /dev/null @@ -1,110 +0,0 @@ -/*
-
-Chat module plugin for Miranda IM
-
-Copyright (C) 2003 Jörgen Persson
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include <m_smileyadd.h>
-#include <m_popup.h>
-#include <m_fontservice.h>
-
-struct MODULEINFO : public GCModuleInfoBase {};
-struct SESSION_INFO : public GCSessionInfoBase {};
-struct LOGSTREAMDATA : public GCLogStreamDataBase {};
-
-// special service for tweaking performance
-#define MS_GC_GETEVENTPTR "GChat/GetNewEventPtr"
-typedef INT_PTR(*GETEVENTFUNC)(WPARAM wParam, LPARAM lParam);
-struct GCPTRS
-{
- GETEVENTFUNC pfnAddEvent;
-};
-
-extern HGENMENU hJoinMenuItem, hLeaveMenuItem;
-extern GlobalLogSettingsBase *g_Settings;
-extern int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang;
-extern TCHAR *g_szFontGroup;
-extern mir_cs cs;
-
-extern char* pLogIconBmpBits[14];
-extern size_t logIconBmpSize[14];
-
-// log.c
-void LoadMsgLogBitmaps(void);
-void FreeMsgLogBitmaps(void);
-void ValidateFilename (TCHAR *filename);
-TCHAR* MakeTimeStamp(TCHAR *pszStamp, time_t time);
-TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime);
-char* Log_CreateRtfHeader(MODULEINFO *mi);
-char* Log_CreateRTF(LOGSTREAMDATA *streamData);
-char* Log_SetStyle(int style);
-
-// clist.c
-BOOL AddEvent(MCONTACT hContact, HICON hIcon, MEVENT hEvent, int type, TCHAR* fmt, ...);
-MCONTACT AddRoom(const char *pszModule, const TCHAR *pszRoom, const TCHAR *pszDisplayName, int iType);
-MCONTACT FindRoom(const char *pszModule, const TCHAR *pszRoom);
-BOOL SetAllOffline(BOOL bHide, const char *pszModule);
-BOOL SetOffline(MCONTACT hContact, BOOL bHide);
-
-int RoomDoubleclicked(WPARAM wParam,LPARAM lParam);
-INT_PTR EventDoubleclicked(WPARAM wParam,LPARAM lParam);
-INT_PTR JoinChat(WPARAM wParam, LPARAM lParam);
-INT_PTR LeaveChat(WPARAM wParam, LPARAM lParam);
-int PrebuildContactMenu(WPARAM wParam, LPARAM lParam);
-INT_PTR PrebuildContactMenuSvc(WPARAM wParam, LPARAM lParam);
-
-// colorchooser.c
-void ColorChooser(SESSION_INFO *si, BOOL bFG, HWND hwndDlg, HWND hwndTarget, HWND hwndChooser);
-
-// options.c
-int OptionsInit(void);
-int OptionsUnInit(void);
-void LoadMsgDlgFont(int i, LOGFONT * lf, COLORREF * colour);
-void LoadGlobalSettings(void);
-HICON LoadIconEx(char* pszIcoLibName, BOOL big);
-void LoadLogFonts(void);
-void SetIndentSize(void);
-void RegisterFonts(void);
-
-// services.c
-void LoadChatIcons(void);
-int LoadChatModule(void);
-void UnloadChatModule(void);
-
-// tools.c
-int DoRtfToTags(CMString &pszText, int iNumColors, COLORREF *pColors); -int GetTextPixelSize(TCHAR* pszText, HFONT hFont, BOOL bWidth);
-TCHAR *RemoveFormatting(const TCHAR* pszText);
-BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix);
-int GetColorIndex(const char *pszModule, COLORREF cr);
-void CheckColorsInModule(const char *pszModule);
-int GetRichTextLength(HWND hwnd);
-BOOL IsHighlighted(SESSION_INFO *si, GCEVENT *pszText);
-UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, TCHAR* pszUID, TCHAR* pszWordText);
-void DestroyGCMenu(HMENU *hMenu, int iIndex);
-BOOL DoEventHookAsync(HWND hwnd, const TCHAR *pszID, const char *pszModule, int iType, const TCHAR* pszUID, const TCHAR* pszText, INT_PTR dwItem);
-BOOL DoEventHook(const TCHAR *pszID, const char *pszModule, int iType, const TCHAR *pszUID, const TCHAR* pszText, INT_PTR dwItem);
-BOOL IsEventSupported(int eventType);
-BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce);
-BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce);
-BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce);
-int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, TCHAR* pszRoomName, COLORREF crBkg, const TCHAR* fmt, ...);
-
-const TCHAR* my_strstri(const TCHAR* s1, const TCHAR* s2);
-
-#pragma comment(lib,"comctl32.lib")
diff --git a/src/modules/chat/chat_opts.cpp b/src/modules/chat/chat_opts.cpp deleted file mode 100644 index dd889280c2..0000000000 --- a/src/modules/chat/chat_opts.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright (C) 2003 Jörgen Persson
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-#include <m_fontservice.h>
-
-extern SESSION_INFO g_TabSession;
-
-GlobalLogSettingsBase *g_Settings;
-int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang;
-TCHAR *g_szFontGroup;
-
-#define FONTF_BOLD 1
-#define FONTF_ITALIC 2
-struct FontOptionsList
-{
- LPCTSTR szDescr;
- COLORREF defColour;
- LPCTSTR szDefFace;
- BYTE defCharset, defStyle;
- char defSize;
-};
-
-//remeber to put these in the Translate( ) template file too
-
-static LOGFONT lfDefault;
-
-static FontOptionsList fontOptionsList[] =
-{
- { LPGENT("Timestamp"), RGB(50, 50, 240), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Others nicknames"), RGB(0, 0, 192), lfDefault.lfFaceName, DEFAULT_CHARSET, FONTF_BOLD, -12 },
- { LPGENT("Your nickname"), RGB(0, 0, 192), lfDefault.lfFaceName, DEFAULT_CHARSET, FONTF_BOLD, -12 },
- { LPGENT("User has joined"), RGB(90, 160, 90), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User has left"), RGB(160, 160, 90), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User has disconnected"), RGB(160, 90, 90), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User kicked ..."), RGB(100, 100, 100), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User is now known as ..."), RGB(90, 90, 160), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Notice from user"), RGB(160, 130, 60), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Incoming message"), RGB(90, 90, 90), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Outgoing message"), RGB(90, 90, 90), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("The topic is ..."), RGB(70, 70, 160), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Information messages"), RGB(130, 130, 195), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User enables status for ..."), RGB(70, 150, 70), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("User disables status for ..."), RGB(150, 70, 70), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Action message"), RGB(160, 90, 160), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Highlighted message"), RGB(180, 150, 80), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { _T(""), 0, lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Nick list members (online)"), RGB(0, 0, 0), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { LPGENT("Nick list members (away)"), RGB(170, 170, 170), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 }
-};
-
-static void LoadColors()
-{
- g_Settings->crUserListBGColor = db_get_dw(NULL, CHAT_MODULE, "ColorNicklistBG", GetSysColor(COLOR_WINDOW));
- g_Settings->crUserListSelectedBGColor = db_get_dw(NULL, CHAT_MODULE, "ColorNicklistSelectedBG", GetSysColor(COLOR_HIGHLIGHT));
-}
-
-void LoadLogFonts(void)
-{
- for (int i=0; i < OPTIONS_FONTCOUNT; i++)
- LoadMsgDlgFont(i, &ci.aFonts[i].lf, &ci.aFonts[i].color);
- LoadColors();
-
- if (ci.hListBkgBrush != NULL)
- DeleteObject(ci.hListBkgBrush);
- ci.hListBkgBrush = CreateSolidBrush(g_Settings->crUserListBGColor);
-
- if (ci.hListSelectedBkgBrush != NULL)
- DeleteObject(ci.hListSelectedBkgBrush);
- ci.hListSelectedBkgBrush = CreateSolidBrush(g_Settings->crUserListSelectedBGColor);
-}
-
-void LoadMsgDlgFont(int i, LOGFONT *lf, COLORREF *colour)
-{
- char str[32];
- int style;
- FontOptionsList &FO = fontOptionsList[i];
-
- if (colour) {
- mir_snprintf(str, "Font%dCol", i);
- *colour = db_get_dw(NULL, CHATFONT_MODULE, str, FO.defColour);
- }
- if (lf) {
- mir_snprintf(str, "Font%dSize", i);
- lf->lfHeight = (char)db_get_b(NULL, CHATFONT_MODULE, str, FO.defSize);
- lf->lfWidth = 0;
- lf->lfEscapement = 0;
- lf->lfOrientation = 0;
- mir_snprintf(str, "Font%dSty", i);
- style = db_get_b(NULL, CHATFONT_MODULE, str, FO.defStyle);
- lf->lfWeight = style & FONTF_BOLD ? FW_BOLD : FW_NORMAL;
- lf->lfItalic = style & FONTF_ITALIC ? 1 : 0;
- lf->lfUnderline = 0;
- lf->lfStrikeOut = 0;
- mir_snprintf(str, "Font%dSet", i);
- lf->lfCharSet = db_get_b(NULL, CHATFONT_MODULE, str, FO.defCharset);
- lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
- lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
- lf->lfQuality = DEFAULT_QUALITY;
- lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
- mir_snprintf(str, "Font%d", i);
-
- ptrT tszFace(db_get_tsa(NULL, CHATFONT_MODULE, str));
- if (tszFace == NULL)
- mir_tstrcpy(lf->lfFaceName, FO.szDefFace);
- else
- _tcsncpy_s(lf->lfFaceName, tszFace, _TRUNCATE);
- }
-}
-
-void RegisterFonts(void)
-{
- int index = 0;
-
- SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfDefault), &lfDefault, FALSE);
-
- FontIDT fontid = { sizeof(fontid) };
- fontid.flags = FIDF_ALLOWREREGISTER | FIDF_DEFAULTVALID | FIDF_NEEDRESTART;
- _tcsncpy_s(fontid.backgroundGroup, g_szFontGroup, _TRUNCATE);
- _tcsncpy_s(fontid.group, g_szFontGroup, _TRUNCATE);
-
- for (int i = 0; i < SIZEOF(fontOptionsList); i++, index++) {
- FontOptionsList &FO = fontOptionsList[i];
- strncpy_s(fontid.dbSettingsGroup, CHATFONT_MODULE, _TRUNCATE);
- _tcsncpy_s(fontid.name, FO.szDescr, _TRUNCATE);
-
- mir_snprintf(fontid.prefix, SIZEOF(fontid.prefix), "Font%d", index);
- fontid.order = index;
-
- switch (i) {
- case 18:
- case 19:
- _tcsncpy_s(fontid.backgroundName, LPGENT("Nick list background"), _TRUNCATE);
- break;
- case 17:
- if (g_iFontMode == FONTMODE_SKIP)
- continue;
- if (g_iFontMode == FONTMODE_USE) {
- _tcsncpy_s(fontid.name, LPGENT("Message typing area"), _TRUNCATE);
- _tcsncpy_s(fontid.backgroundName, LPGENT("Message background"), _TRUNCATE);
- FO.defColour = RGB(0, 0, 40);
- break;
- }
-
- _tcsncpy_s(fontid.name, LPGENT("Chat log symbols (Webdings)"), _TRUNCATE);
- FO.szDefFace = _T("Webdings");
- FO.defColour = RGB(170, 170, 170);
- FO.defCharset = SYMBOL_CHARSET;
- // fall through
- default:
- _tcsncpy_s(fontid.backgroundName, LPGENT("Group chat log background"), _TRUNCATE);
- break;
- }
- _tcsncpy_s(fontid.deffontsettings.szFace, FO.szDefFace, _TRUNCATE);
- fontid.deffontsettings.charset = FO.defCharset;
- fontid.deffontsettings.colour = FO.defColour;
- fontid.deffontsettings.size = FO.defSize;
- fontid.deffontsettings.style = FO.defStyle;
- CallService("Font/RegisterW", (WPARAM)&fontid, g_iChatLang);
- }
-}
-
-// load icons from the skinning module if available
-
-HICON LoadIconEx(char* pszIcoLibName, BOOL big)
-{
- char szTemp[256];
- mir_snprintf(szTemp, "chat_%s", pszIcoLibName);
- return Skin_GetIcon(szTemp, big);
-}
-
-static void InitSetting(TCHAR** ppPointer, char* pszSetting, TCHAR* pszDefault)
-{
- DBVARIANT dbv;
- if (!db_get_ts(NULL, CHAT_MODULE, pszSetting, &dbv)) {
- replaceStrT(*ppPointer, dbv.ptszVal);
- db_free(&dbv);
- }
- else replaceStrT(*ppPointer, pszDefault);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-void LoadGlobalSettings(void)
-{
- g_Settings->LogIconSize = 10;
- g_Settings->bLogLimitNames = db_get_b(NULL, CHAT_MODULE, "LogLimitNames", 1) != 0;
- g_Settings->bShowTime = db_get_b(NULL, CHAT_MODULE, "ShowTimeStamp", 1) != 0;
- g_Settings->bSoundsFocus = db_get_b(NULL, CHAT_MODULE, "SoundsFocus", 0) != 0;
- g_Settings->bShowTimeIfChanged = (BOOL)db_get_b(NULL, CHAT_MODULE, "ShowTimeStampIfChanged", 0) != 0;
- g_Settings->bTimeStampEventColour = (BOOL)db_get_b(NULL, CHAT_MODULE, "TimeStampEventColour", 0) != 0;
- g_Settings->iEventLimit = db_get_w(NULL, CHAT_MODULE, "LogLimit", 100);
- g_Settings->dwIconFlags = db_get_dw(NULL, CHAT_MODULE, "IconFlags", 0x0000);
- g_Settings->dwTrayIconFlags = db_get_dw(NULL, CHAT_MODULE, "TrayIconFlags", 0x1000);
- g_Settings->dwPopupFlags = db_get_dw(NULL, CHAT_MODULE, "PopupFlags", 0x0000);
- g_Settings->LoggingLimit = db_get_w(NULL, CHAT_MODULE, "LoggingLimit", 100);
- g_Settings->bLoggingEnabled = (BOOL)db_get_b(NULL, CHAT_MODULE, "LoggingEnabled", 0) != 0;
- g_Settings->bFlashWindow = (BOOL)db_get_b(NULL, CHAT_MODULE, "FlashWindow", 0) != 0;
- g_Settings->bFlashWindowHighlight = (BOOL)db_get_b(NULL, CHAT_MODULE, "FlashWindowHighlight", false) != 0;
- g_Settings->bHighlightEnabled = (BOOL)db_get_b(NULL, CHAT_MODULE, "HighlightEnabled", 1) != 0;
- g_Settings->crLogBackground = db_get_dw(NULL, CHAT_MODULE, "ColorLogBG", GetSysColor(COLOR_WINDOW));
- g_Settings->crUserListColor = db_get_dw(NULL, CHATFONT_MODULE, "Font18Col", RGB(0, 0, 0));
- g_Settings->crUserListHeadingsColor = db_get_dw(NULL, CHATFONT_MODULE, "Font19Col", RGB(170, 170, 170));
- g_Settings->bStripFormat = (BOOL)db_get_b(NULL, CHAT_MODULE, "StripFormatting", 0) != 0;
- g_Settings->bTrayIconInactiveOnly = (BOOL)db_get_b(NULL, CHAT_MODULE, "TrayIconInactiveOnly", 1) != 0;
- g_Settings->bPopupInactiveOnly = (BOOL)db_get_b(NULL, CHAT_MODULE, "PopupInactiveOnly", 1) != 0;
- g_Settings->bAddColonToAutoComplete = (BOOL)db_get_b(NULL, CHAT_MODULE, "AddColonToAutoComplete", 1) != 0;
- g_Settings->iPopupStyle = db_get_b(NULL, CHAT_MODULE, "PopupStyle", 1);
- g_Settings->iPopupTimeout = db_get_w(NULL, CHAT_MODULE, "PopupTimeout", 3);
- g_Settings->crPUBkgColour = db_get_dw(NULL, CHAT_MODULE, "PopupColorBG", GetSysColor(COLOR_WINDOW));
- g_Settings->crPUTextColour = db_get_dw(NULL, CHAT_MODULE, "PopupColorText", 0);
- g_Settings->bShowContactStatus = db_get_b(NULL, CHAT_MODULE, "ShowContactStatus", 0) != 0;
- g_Settings->bContactStatusFirst = db_get_b(NULL, CHAT_MODULE, "ContactStatusFirst", 0) != 0;
-
- LoadColors();
-
- if (ci.OnLoadSettings)
- ci.OnLoadSettings();
-
- InitSetting(&g_Settings->pszTimeStamp, "HeaderTime", _T("[%H:%M]"));
- InitSetting(&g_Settings->pszTimeStampLog, "LogTimestamp", _T("[%d %b %y %H:%M]"));
- InitSetting(&g_Settings->pszIncomingNick, "HeaderIncoming", _T("%n:"));
- InitSetting(&g_Settings->pszOutgoingNick, "HeaderOutgoing", _T("%n:"));
- InitSetting(&g_Settings->pszHighlightWords, "HighlightWords", _T("%m"));
-
- InitSetting(&g_Settings->pszLogDir, "LogDirectory", _T("%miranda_logpath%\\%proto%\\%userid%.log"));
- g_Settings->bLogIndentEnabled = db_get_b(NULL, CHAT_MODULE, "LogIndentEnabled", 1) != 0;
-
- LOGFONT lf;
- if (g_Settings->UserListFont)
- DeleteObject(g_Settings->UserListFont);
- LoadMsgDlgFont(18, &lf, NULL);
- g_Settings->UserListFont = CreateFontIndirect(&lf);
-
- if (g_Settings->UserListHeadingsFont)
- DeleteObject(g_Settings->UserListHeadingsFont);
- LoadMsgDlgFont(19, &lf, NULL);
- g_Settings->UserListHeadingsFont = CreateFontIndirect(&lf);
-
- SetIndentSize();
-}
-
-static void FreeGlobalSettings(void)
-{
- if (g_Settings == NULL)
- return;
-
- mir_free(g_Settings->pszTimeStamp);
- mir_free(g_Settings->pszTimeStampLog);
- mir_free(g_Settings->pszIncomingNick);
- mir_free(g_Settings->pszOutgoingNick);
- mir_free(g_Settings->pszHighlightWords);
- mir_free(g_Settings->pszLogDir);
- if (g_Settings->UserListFont)
- DeleteObject(g_Settings->UserListFont);
- if (g_Settings->UserListHeadingsFont)
- DeleteObject(g_Settings->UserListHeadingsFont);
- if (g_Settings->NameFont)
- DeleteObject(g_Settings->NameFont);
-}
-
-void SetIndentSize()
-{
- if (g_Settings->bShowTime) {
- LOGFONT lf;
- LoadMsgDlgFont(0, &lf, NULL);
- HFONT hFont = CreateFontIndirect(&lf);
- int iText = GetTextPixelSize(MakeTimeStamp(g_Settings->pszTimeStamp, time(NULL)), hFont, TRUE);
- DeleteObject(hFont);
- g_Settings->LogTextIndent = iText * 12 / 10;
- }
- else g_Settings->LogTextIndent = 0;
-}
-
-int GetTextPixelSize(TCHAR* pszText, HFONT hFont, BOOL bWidth)
-{
- if (!pszText || !hFont)
- return 0;
-
- HDC hdc = GetDC(NULL);
- HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
-
- RECT rc = { 0 };
- int i = DrawText(hdc, pszText, -1, &rc, DT_CALCRECT);
- SelectObject(hdc, hOldFont);
- ReleaseDC(NULL, hdc);
- return bWidth ? rc.right - rc.left : rc.bottom - rc.top;
-}
-
-int OptionsInit(void)
-{
- LoadLogFonts();
-
- LOGFONT lf;
- LoadMsgDlgFont(18, &lf, NULL);
- mir_tstrcpy(lf.lfFaceName, _T("MS Shell Dlg"));
- lf.lfUnderline = lf.lfItalic = lf.lfStrikeOut = 0;
- lf.lfHeight = -17;
- lf.lfWeight = FW_BOLD;
- g_Settings->NameFont = CreateFontIndirect(&lf);
- g_Settings->UserListFont = NULL;
- g_Settings->UserListHeadingsFont = NULL;
- g_Settings->iWidth = db_get_dw(NULL, CHAT_MODULE, "roomwidth", -1);
- g_Settings->iHeight = db_get_dw(NULL, CHAT_MODULE, "roomheight", -1);
-
- g_Settings->iSplitterX = db_get_w(NULL, CHAT_MODULE, "SplitterX", 105);
- if (g_Settings->iSplitterX <= 50)
- g_Settings->iSplitterX = 105;
- g_Settings->iSplitterY = db_get_w(NULL, CHAT_MODULE, "SplitterY", 90);
- if (g_Settings->iSplitterY <= 65)
- g_Settings->iSplitterY = 90;
-
- SkinAddNewSoundEx("ChatMessage", LPGEN("Group chats"), LPGEN("Incoming message"));
- SkinAddNewSoundEx("ChatHighlight", LPGEN("Group chats"), LPGEN("Message is highlighted"));
- SkinAddNewSoundEx("ChatAction", LPGEN("Group chats"), LPGEN("User has performed an action"));
- SkinAddNewSoundEx("ChatJoin", LPGEN("Group chats"), LPGEN("User has joined"));
- SkinAddNewSoundEx("ChatPart", LPGEN("Group chats"), LPGEN("User has left"));
- SkinAddNewSoundEx("ChatKick", LPGEN("Group chats"), LPGEN("User has kicked some other user"));
- SkinAddNewSoundEx("ChatMode", LPGEN("Group chats"), LPGEN("User's status was changed"));
- SkinAddNewSoundEx("ChatNick", LPGEN("Group chats"), LPGEN("User has changed name"));
- SkinAddNewSoundEx("ChatNotice", LPGEN("Group chats"), LPGEN("User has sent a notice"));
- SkinAddNewSoundEx("ChatQuit", LPGEN("Group chats"), LPGEN("User has disconnected"));
- SkinAddNewSoundEx("ChatTopic", LPGEN("Group chats"), LPGEN("The topic has been changed"));
- return 0;
-}
-
-int OptionsUnInit(void)
-{
- FreeGlobalSettings();
- return 0;
-}
diff --git a/src/modules/chat/chat_rtf.cpp b/src/modules/chat/chat_rtf.cpp deleted file mode 100644 index 255a051ef9..0000000000 --- a/src/modules/chat/chat_rtf.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright 2000-12 Miranda IM, 2012-15 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "..\..\core\commonheaders.h" - -#include "chat.h" - -///////////////////////////////////////////////////////////////////////////////////////// -// convert rich edit code to bbcode (if wanted). Otherwise, strip all RTF formatting -// tags and return plain text - -static TCHAR tszRtfBreaks[] = _T(" \\\n\r"); - -static void CreateColorMap(CMString &Text, int iCount, COLORREF *pSrc, int *pDst) -{ - const TCHAR *pszText = Text; - int iIndex = 1, i = 0; - - static const TCHAR *lpszFmt = _T("\\red%[^ \x5b\\]\\green%[^ \x5b\\]\\blue%[^ \x5b;];"); - TCHAR szRed[10], szGreen[10], szBlue[10]; - - const TCHAR *p1 = _tcsstr(pszText, _T("\\colortbl")); - if (!p1) - return; - - const TCHAR *pEnd = _tcschr(p1, '}'); - - const TCHAR *p2 = _tcsstr(p1, _T("\\red")); - - for (i = 0; i < iCount; i++) - pDst[i] = -1; - - while (p2 && p2 < pEnd) { - if (_stscanf(p2, lpszFmt, &szRed, &szGreen, &szBlue) > 0) { - for (int i = 0; i < iCount; i++) { - if (pSrc[i] == RGB(_ttoi(szRed), _ttoi(szGreen), _ttoi(szBlue))) - pDst[i] = iIndex; - } - } - iIndex++; - p1 = p2; - p1++; - - p2 = _tcsstr(p1, _T("\\red")); - } -} - -static int GetRtfIndex(int iCol, int iCount, int *pIndex) -{ - for (int i = 0; i < iCount; i++) - if (pIndex[i] == iCol) - return i; - - return -1; -} - -int DoRtfToTags(CMString &pszText, int iNumColors, COLORREF *pColors) -{ - if (pszText.IsEmpty()) - return FALSE; - - // create an index of colors in the module and map them to - // corresponding colors in the RTF color table - int *pIndex = (int*)_alloca(iNumColors * sizeof(int)); - CreateColorMap(pszText, iNumColors, pColors, pIndex); - - // scan the file for rtf commands and remove or parse them - int idx = pszText.Find(_T("\\pard")); - if (idx == -1) { - if ((idx = pszText.Find(_T("\\ltrpar"))) == -1) - return FALSE; - idx += 7; - } - else idx += 5; - - bool bInsideColor = false, bInsideUl = false; - CMString res; - - // iterate through all characters, if rtf control character found then take action - for (const TCHAR *p = pszText.GetString() + idx; *p;) { - switch (*p) { - case '\\': - if (p[1] == '\\' || p[1] == '{' || p[1] == '}') { // escaped characters - res.AppendChar(p[1]); - p += 2; break; - } - if (p[1] == '~') { // non-breaking space - res.AppendChar(0xA0); - p += 2; break; - } - - if (!_tcsncmp(p, _T("\\cf"), 3)) { // foreground color - int iCol = _ttoi(p + 3); - int iInd = GetRtfIndex(iCol, iNumColors, pIndex); - bInsideColor = iInd > 0; - } - else if (!_tcsncmp(p, _T("\\highlight"), 10)) { //background color - TCHAR szTemp[20]; - int iCol = _ttoi(p + 10); - mir_sntprintf(szTemp, _T("%d"), iCol); - } - else if (!_tcsncmp(p, _T("\\line"), 5)) { // soft line break; - res.AppendChar('\n'); - } - else if (!_tcsncmp(p, _T("\\endash"), 7)) { - res.AppendChar(0x2013); - } - else if (!_tcsncmp(p, _T("\\emdash"), 7)) { - res.AppendChar(0x2014); - } - else if (!_tcsncmp(p, _T("\\bullet"), 7)) { - res.AppendChar(0x2022); - } - else if (!_tcsncmp(p, _T("\\ldblquote"), 10)) { - res.AppendChar(0x201C); - } - else if (!_tcsncmp(p, _T("\\rdblquote"), 10)) { - res.AppendChar(0x201D); - } - else if (!_tcsncmp(p, _T("\\lquote"), 7)) { - res.AppendChar(0x2018); - } - else if (!_tcsncmp(p, _T("\\rquote"), 7)) { - res.AppendChar(0x2019); - } - else if (!_tcsncmp(p, _T("\\b"), 2)) { //bold - res.Append((p[2] != '0') ? _T("[b]") : _T("[/b]")); - } - else if (!_tcsncmp(p, _T("\\i"), 2)) { // italics - res.Append((p[2] != '0') ? _T("[i]") : _T("[/i]")); - } - else if (!_tcsncmp(p, _T("\\strike"), 7)) { // strike-out - res.Append((p[7] != '0') ? _T("[s]") : _T("[/s]")); - } - else if (!_tcsncmp(p, _T("\\ul"), 3)) { // underlined - if (p[3] == 0 || _tcschr(tszRtfBreaks, p[3])) { - res.Append(_T("[u]")); - bInsideUl = true; - } - else if (!_tcsnccmp(p + 3, _T("none"), 4)) { - if (bInsideUl) - res.Append(_T("[/u]")); - bInsideUl = false; - } - } - else if (!_tcsncmp(p, _T("\\tab"), 4)) { // tab - res.AppendChar('\t'); - } - else if (p[1] == '\'') { // special character - if (p[2] != ' ' && p[2] != '\\') { - TCHAR tmp[10], *t = tmp; - *t++ = p[2]; - if (p[3] != ' ' && p[3] != '\\') - *t++ = p[3]; - *t = 0; - - // convert string containing char in hex format to int. - TCHAR *stoppedHere; - res.AppendChar(_tcstol(tmp, &stoppedHere, 16)); - } - } - - p++; // skip initial slash - p += _tcscspn(p, tszRtfBreaks); - if (*p == ' ') - p++; - break; - - case '{': // other RTF control characters - case '}': - p++; - break; - - default: // other text that should not be touched - res.AppendChar(*p++); - break; - } - } - - if (bInsideUl) - res.Append(_T("[/u]")); - - pszText = res; - return TRUE; -} diff --git a/src/modules/chat/chat_svc.cpp b/src/modules/chat/chat_svc.cpp deleted file mode 100644 index 31b0fc9080..0000000000 --- a/src/modules/chat/chat_svc.cpp +++ /dev/null @@ -1,631 +0,0 @@ -/* -Chat module plugin for Miranda IM - -Copyright 2000-12 Miranda IM, 2012-15 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "..\..\core\commonheaders.h" - -INT_PTR SvcGetChatManager(WPARAM, LPARAM); - -#include "chat.h" - -HGENMENU hJoinMenuItem, hLeaveMenuItem; -mir_cs cs; - -static HANDLE - hServiceRegister = NULL, - hServiceNewChat = NULL, - hServiceAddEvent = NULL, - hServiceGetAddEventPtr = NULL, - hServiceGetInfo = NULL, - hServiceGetCount = NULL, - hEventPrebuildMenu = NULL, - hEventDoubleclicked = NULL, - hEventJoinChat = NULL, - hEventLeaveChat = NULL, - hHookEvent = NULL; - -///////////////////////////////////////////////////////////////////////////////////////// -// Post-load event hooks - -void LoadChatIcons(void) -{ - ci.hIcons[ICON_ACTION] = LoadIconEx("log_action", FALSE); - ci.hIcons[ICON_ADDSTATUS] = LoadIconEx("log_addstatus", FALSE); - ci.hIcons[ICON_HIGHLIGHT] = LoadIconEx("log_highlight", FALSE); - ci.hIcons[ICON_INFO] = LoadIconEx("log_info", FALSE); - ci.hIcons[ICON_JOIN] = LoadIconEx("log_join", FALSE); - ci.hIcons[ICON_KICK] = LoadIconEx("log_kick", FALSE); - ci.hIcons[ICON_MESSAGE] = LoadIconEx("log_message_in", FALSE); - ci.hIcons[ICON_MESSAGEOUT] = LoadIconEx("log_message_out", FALSE); - ci.hIcons[ICON_NICK] = LoadIconEx("log_nick", FALSE); - ci.hIcons[ICON_NOTICE] = LoadIconEx("log_notice", FALSE); - ci.hIcons[ICON_PART] = LoadIconEx("log_part", FALSE); - ci.hIcons[ICON_QUIT] = LoadIconEx("log_quit", FALSE); - ci.hIcons[ICON_REMSTATUS] = LoadIconEx("log_removestatus", FALSE); - ci.hIcons[ICON_TOPIC] = LoadIconEx("log_topic", FALSE); - ci.hIcons[ICON_STATUS0] = LoadIconEx("status0", FALSE); - ci.hIcons[ICON_STATUS1] = LoadIconEx("status1", FALSE); - ci.hIcons[ICON_STATUS2] = LoadIconEx("status2", FALSE); - ci.hIcons[ICON_STATUS3] = LoadIconEx("status3", FALSE); - ci.hIcons[ICON_STATUS4] = LoadIconEx("status4", FALSE); - ci.hIcons[ICON_STATUS5] = LoadIconEx("status5", FALSE); - - FreeMsgLogBitmaps(); - LoadMsgLogBitmaps(); -} - -static int FontsChanged(WPARAM, LPARAM) -{ - LoadGlobalSettings(); - LoadLogFonts(); - - FreeMsgLogBitmaps(); - LoadMsgLogBitmaps(); - - SetIndentSize(); - g_Settings->bLogIndentEnabled = (db_get_b(NULL, CHAT_MODULE, "LogIndentEnabled", 1) != 0) ? TRUE : FALSE; - - ci.MM_FontsChanged(); - ci.MM_FixColors(); - ci.SM_BroadcastMessage(NULL, GC_SETWNDPROPS, 0, 0, TRUE); - return 0; -} - -static int IconsChanged(WPARAM, LPARAM) -{ - FreeMsgLogBitmaps(); - LoadMsgLogBitmaps(); - - ci.MM_IconsChanged(); - ci.SM_BroadcastMessage(NULL, GC_SETWNDPROPS, 0, 0, FALSE); - return 0; -} - -static int PreShutdown(WPARAM, LPARAM) -{ - if (g_Settings != NULL) { - ci.SM_BroadcastMessage(NULL, GC_CLOSEWINDOW, 0, 1, FALSE); - - ci.SM_RemoveAll(); - ci.MM_RemoveAll(); - - DeleteObject(ci.hListBkgBrush); - DeleteObject(ci.hListSelectedBkgBrush); - } - return 0; -} - -static int SmileyOptionsChanged(WPARAM, LPARAM) -{ - ci.SM_BroadcastMessage(NULL, GC_REDRAWLOG, 0, 1, FALSE); - return 0; -} - -static INT_PTR Service_GetCount(WPARAM, LPARAM lParam) -{ - if (!lParam) - return -1; - - mir_cslock lck(cs); - return ci.SM_GetCount((char *)lParam); -} - -static INT_PTR Service_GetInfo(WPARAM, LPARAM lParam) -{ - GC_INFO *gci = (GC_INFO *)lParam; - if (!gci || !gci->pszModule) - return 1; - - mir_cslock lck(cs); - - SESSION_INFO *si; - if (gci->Flags & GCF_BYINDEX) - si = ci.SM_FindSessionByIndex(gci->pszModule, gci->iItem); - else - si = ci.SM_FindSession(gci->pszID, gci->pszModule); - if (si == NULL) - return 1; - - if (gci->Flags & GCF_DATA) gci->dwItemData = si->dwItemData; - if (gci->Flags & GCF_HCONTACT) gci->hContact = si->hContact; - if (gci->Flags & GCF_TYPE) gci->iType = si->iType; - if (gci->Flags & GCF_COUNT) gci->iCount = si->nUsersInNicklist; - if (gci->Flags & GCF_USERS) gci->pszUsers = ci.SM_GetUsers(si); - if (gci->Flags & GCF_ID) gci->pszID = si->ptszID; - if (gci->Flags & GCF_NAME) gci->pszName = si->ptszName; - return 0; -} - -static INT_PTR Service_Register(WPARAM, LPARAM lParam) -{ - GCREGISTER *gcr = (GCREGISTER *)lParam; - if (gcr == NULL) - return GC_REGISTER_ERROR; - - if (gcr->cbSize != sizeof(GCREGISTER)) - return GC_REGISTER_WRONGVER; - - mir_cslock lck(cs); - MODULEINFO *mi = ci.MM_AddModule(gcr->pszModule); - if (mi == NULL) - return GC_REGISTER_ERROR; - - mi->ptszModDispName = mir_tstrdup(gcr->ptszDispName); - mi->bBold = (gcr->dwFlags & GC_BOLD) != 0; - mi->bUnderline = (gcr->dwFlags & GC_UNDERLINE) != 0; - mi->bItalics = (gcr->dwFlags & GC_ITALICS) != 0; - mi->bColor = (gcr->dwFlags & GC_COLOR) != 0; - mi->bBkgColor = (gcr->dwFlags & GC_BKGCOLOR) != 0; - mi->bAckMsg = (gcr->dwFlags & GC_ACKMSG) != 0; - mi->bChanMgr = (gcr->dwFlags & GC_CHANMGR) != 0; - mi->bSingleFormat = (gcr->dwFlags & GC_SINGLEFORMAT) != 0; - mi->bFontSize = (gcr->dwFlags & GC_FONTSIZE) != 0; - mi->iMaxText = gcr->iMaxText; - mi->nColorCount = gcr->nColors; - if (gcr->nColors > 0) { - mi->crColors = (COLORREF *)mir_alloc(sizeof(COLORREF)* gcr->nColors); - memcpy(mi->crColors, gcr->pColors, sizeof(COLORREF)* gcr->nColors); - } - - mi->pszHeader = ci.Log_CreateRtfHeader(mi); - - CheckColorsInModule((char*)gcr->pszModule); - ci.SetAllOffline(TRUE, gcr->pszModule); - return 0; -} - -static INT_PTR Service_NewChat(WPARAM, LPARAM lParam) -{ - GCSESSION *gcw = (GCSESSION *)lParam; - if (gcw == NULL) - return GC_NEWSESSION_ERROR; - - if (gcw->cbSize != sizeof(GCSESSION)) - return GC_NEWSESSION_WRONGVER; - - mir_cslock lck(cs); - MODULEINFO *mi = ci.MM_FindModule(gcw->pszModule); - if (mi == NULL) - return GC_NEWSESSION_ERROR; - - // create a new session and set the defaults - SESSION_INFO *si = ci.SM_AddSession(gcw->ptszID, gcw->pszModule); - if (si != NULL) { - si->dwItemData = gcw->dwItemData; - if (gcw->iType != GCW_SERVER) - si->wStatus = ID_STATUS_ONLINE; - si->iType = gcw->iType; - si->dwFlags = gcw->dwFlags; - si->ptszName = mir_tstrdup(gcw->ptszName); - si->ptszStatusbarText = mir_tstrdup(gcw->ptszStatusbarText); - si->iSplitterX = g_Settings->iSplitterX; - si->iSplitterY = g_Settings->iSplitterY; - si->iLogFilterFlags = db_get_dw(NULL, CHAT_MODULE, "FilterFlags", 0x03E0); - si->bFilterEnabled = db_get_b(NULL, CHAT_MODULE, "FilterEnabled", 0); - si->bNicklistEnabled = db_get_b(NULL, CHAT_MODULE, "ShowNicklist", 1); - - if (mi->bColor) { - si->iFG = 4; - si->bFGSet = TRUE; - } - if (mi->bBkgColor) { - si->iBG = 2; - si->bBGSet = TRUE; - } - - TCHAR szTemp[256]; - if (si->iType == GCW_SERVER) - mir_sntprintf(szTemp, _T("Server: %s"), si->ptszName); - else - _tcsncpy_s(szTemp, si->ptszName, _TRUNCATE); - si->hContact = ci.AddRoom(gcw->pszModule, gcw->ptszID, szTemp, si->iType); - db_set_s(si->hContact, si->pszModule, "Topic", ""); - db_unset(si->hContact, "CList", "StatusMsg"); - if (si->ptszStatusbarText) - db_set_ts(si->hContact, si->pszModule, "StatusBar", si->ptszStatusbarText); - else - db_set_s(si->hContact, si->pszModule, "StatusBar", ""); - - if (ci.OnCreateSession) - ci.OnCreateSession(si, mi); - } - else if (si = ci.SM_FindSession(gcw->ptszID, gcw->pszModule)) { - ci.UM_RemoveAll(&si->pUsers); - ci.TM_RemoveAll(&si->pStatuses); - - si->iStatusCount = 0; - si->nUsersInNicklist = 0; - - if (ci.OnReplaceSession) - ci.OnReplaceSession(si); - } - - return 0; -} - -static void SetInitDone(SESSION_INFO *si) -{ - if (si->bInitDone) - return; - - si->bInitDone = true; - for (STATUSINFO *p = si->pStatuses; p; p = p->next) - if ((UINT_PTR)p->hIcon < STATUSICONCOUNT) - p->hIcon = HICON(si->iStatusCount - (int)p->hIcon - 1); -} - -static int DoControl(GCEVENT *gce, WPARAM wp) -{ - SESSION_INFO *si; - - if (gce->pDest->iType == GC_EVENT_CONTROL) { - switch (wp) { - case WINDOW_HIDDEN: - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - SetInitDone(si); - ci.SetActiveSession(si->ptszID, si->pszModule); - if (si->hWnd) - ci.ShowRoom(si, wp, FALSE); - } - return 0; - - case WINDOW_MINIMIZE: - case WINDOW_MAXIMIZE: - case WINDOW_VISIBLE: - case SESSION_INITDONE: - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - SetInitDone(si); - if (wp != SESSION_INITDONE || db_get_b(NULL, CHAT_MODULE, "PopupOnJoin", 0) == 0) - ci.ShowRoom(si, wp, TRUE); - return 0; - } - break; - - case SESSION_OFFLINE: - ci.SM_SetOffline(gce->pDest->ptszID, gce->pDest->pszModule); - // fall through - - case SESSION_ONLINE: - ci.SM_SetStatus(gce->pDest->ptszID, gce->pDest->pszModule, wp == SESSION_ONLINE ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); - break; - - case WINDOW_CLEARLOG: - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - ci.LM_RemoveAll(&si->pLog, &si->pLogEnd); - if (ci.OnClearLog) - ci.OnClearLog(si); - si->iEventCount = 0; - si->LastTime = 0; - } - break; - - case SESSION_TERMINATE: - return ci.SM_RemoveSession(gce->pDest->ptszID, gce->pDest->pszModule, (gce->dwFlags & GCEF_REMOVECONTACT) != 0); - } - ci.SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_EVENT_CONTROL + WM_USER + 500, wp, 0); - } - - else if (gce->pDest->iType == GC_EVENT_CHUID && gce->ptszText) { - ci.SM_ChangeUID(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszNick, gce->ptszText); - } - - else if (gce->pDest->iType == GC_EVENT_CHANGESESSIONAME && gce->ptszText) { - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - replaceStrT(si->ptszName, gce->ptszText); - if (si->hWnd) - SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0); - if (ci.OnRenameSession) - ci.OnRenameSession(si); - } - } - - else if (gce->pDest->iType == GC_EVENT_SETITEMDATA) { - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) - si->dwItemData = gce->dwItemData; - } - - else if (gce->pDest->iType == GC_EVENT_GETITEMDATA) { - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - gce->dwItemData = si->dwItemData; - return si->dwItemData; - } - return 0; - } - else if (gce->pDest->iType == GC_EVENT_SETSBTEXT) { - if (si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) { - replaceStrT(si->ptszStatusbarText, gce->ptszText); - if (si->ptszStatusbarText) - db_set_ts(si->hContact, si->pszModule, "StatusBar", si->ptszStatusbarText); - else - db_set_s(si->hContact, si->pszModule, "StatusBar", ""); - - if (ci.OnSetStatusBar) - ci.OnSetStatusBar(si); - } - } - else if (gce->pDest->iType == GC_EVENT_ACK) { - ci.SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_ACKMESSAGE, 0, 0); - } - else if (gce->pDest->iType == GC_EVENT_SENDMESSAGE && gce->ptszText) { - ci.SM_SendUserMessage(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText); - } - else if (gce->pDest->iType == GC_EVENT_SETSTATUSEX) { - ci.SM_SetStatusEx(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText, gce->dwItemData); - } - else return 1; - - return 0; -} - -static void AddUser(GCEVENT *gce) -{ - SESSION_INFO *si = ci.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule); - if (si == NULL) return; - - WORD status = ci.TM_StringToWord(si->pStatuses, gce->ptszStatus); - USERINFO *ui = ci.SM_AddUser(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszUID, gce->ptszNick, status); - if (ui == NULL) return; - - ui->pszNick = mir_tstrdup(gce->ptszNick); - if (gce->bIsMe) - si->pMe = ui; - ui->Status = status; - ui->Status |= si->pStatuses->Status; - - if (ci.OnNewUser) - ci.OnNewUser(si, ui); -} - -static INT_PTR Service_AddEvent(WPARAM wParam, LPARAM lParam) -{ - GCEVENT *gce = (GCEVENT*)lParam; - BOOL bIsHighlighted = FALSE; - BOOL bRemoveFlag = FALSE; - - if (gce == NULL) - return GC_EVENT_ERROR; - - GCDEST *gcd = gce->pDest; - if (gcd == NULL) - return GC_EVENT_ERROR; - - if (gce->cbSize != sizeof(GCEVENT)) - return GC_EVENT_WRONGVER; - - if (!IsEventSupported(gcd->iType)) - return GC_EVENT_ERROR; - - NotifyEventHooks(hHookEvent, wParam, lParam); - - SESSION_INFO *si; - mir_cslock lck(cs); - - // Do different things according to type of event - switch (gcd->iType) { - case GC_EVENT_ADDGROUP: - { - STATUSINFO *si = ci.SM_AddStatus(gcd->ptszID, gcd->pszModule, gce->ptszStatus); - if (si && gce->dwItemData) - si->hIcon = CopyIcon((HICON)gce->dwItemData); - } - return 0; - - case GC_EVENT_CHUID: - case GC_EVENT_CHANGESESSIONAME: - case GC_EVENT_SETITEMDATA: - case GC_EVENT_GETITEMDATA: - case GC_EVENT_CONTROL: - case GC_EVENT_SETSBTEXT: - case GC_EVENT_ACK: - case GC_EVENT_SENDMESSAGE: - case GC_EVENT_SETSTATUSEX: - return DoControl(gce, wParam); - - case GC_EVENT_SETCONTACTSTATUS: - return ci.SM_SetContactStatus(gcd->ptszID, gcd->pszModule, gce->ptszUID, (WORD)gce->dwItemData); - - case GC_EVENT_TOPIC: - if (si = ci.SM_FindSession(gcd->ptszID, gcd->pszModule)) { - if (gce->ptszText) { - replaceStrT(si->ptszTopic, RemoveFormatting(gce->ptszText)); - db_set_ts(si->hContact, si->pszModule, "Topic", si->ptszTopic); - if (ci.OnSetTopic) - ci.OnSetTopic(si); - if (db_get_b(NULL, CHAT_MODULE, "TopicOnClist", 0)) - db_set_ts(si->hContact, "CList", "StatusMsg", si->ptszTopic); - } - } - break; - - case GC_EVENT_ADDSTATUS: - ci.SM_GiveStatus(gcd->ptszID, gcd->pszModule, gce->ptszUID, gce->ptszStatus); - bIsHighlighted = ci.IsHighlighted(NULL, gce); - break; - - case GC_EVENT_REMOVESTATUS: - ci.SM_TakeStatus(gcd->ptszID, gcd->pszModule, gce->ptszUID, gce->ptszStatus); - bIsHighlighted = ci.IsHighlighted(NULL, gce); - break; - - case GC_EVENT_MESSAGE: - case GC_EVENT_ACTION: - if (!gce->bIsMe && gcd->ptszID && gce->ptszText) { - si = ci.SM_FindSession(gcd->ptszID, gcd->pszModule); - bIsHighlighted = ci.IsHighlighted(si, gce); - } - break; - - case GC_EVENT_NICK: - ci.SM_ChangeNick(gcd->ptszID, gcd->pszModule, gce); - bIsHighlighted = ci.IsHighlighted(NULL, gce); - break; - - case GC_EVENT_JOIN: - AddUser(gce); - bIsHighlighted = ci.IsHighlighted(NULL, gce); - break; - - case GC_EVENT_PART: - case GC_EVENT_QUIT: - case GC_EVENT_KICK: - bRemoveFlag = TRUE; - bIsHighlighted = ci.IsHighlighted(NULL, gce); - break; - } - - // Decide which window (log) should have the event - LPCTSTR pWnd = NULL; - LPCSTR pMod = NULL; - if (gcd->ptszID) { - pWnd = gcd->ptszID; - pMod = gcd->pszModule; - } - else if (gcd->iType == GC_EVENT_NOTICE || gcd->iType == GC_EVENT_INFORMATION) { - si = ci.GetActiveSession(); - if (si && !mir_strcmp(si->pszModule, gcd->pszModule)) { - pWnd = si->ptszID; - pMod = si->pszModule; - } - else return 0; - } - else { - // Send the event to all windows with a user pszUID. Used for broadcasting QUIT etc - ci.SM_AddEventToAllMatchingUID(gce); - if (!bRemoveFlag) - return 0; - } - - // add to log - if (pWnd) { - si = ci.SM_FindSession(pWnd, pMod); - - // fix for IRC's old stuyle mode notifications. Should not affect any other protocol - if ((gcd->iType == GC_EVENT_ADDSTATUS || gcd->iType == GC_EVENT_REMOVESTATUS) && !(gce->dwFlags & GCEF_ADDTOLOG)) - return 0; - - if (gcd->iType == GC_EVENT_JOIN && gce->time == 0) - return 0; - - if (si && (si->bInitDone || gcd->iType == GC_EVENT_TOPIC || (gcd->iType == GC_EVENT_JOIN && gce->bIsMe))) { - int isOk = ci.SM_AddEvent(pWnd, pMod, gce, bIsHighlighted); - if (ci.OnAddLog) - ci.OnAddLog(si, isOk); - if (!(gce->dwFlags & GCEF_NOTNOTIFY)) - ci.DoSoundsFlashPopupTrayStuff(si, gce, bIsHighlighted, 0); - if ((gce->dwFlags & GCEF_ADDTOLOG) && g_Settings->bLoggingEnabled) - ci.LogToFile(si, gce); - } - - if (!bRemoveFlag) - return 0; - } - - if (bRemoveFlag) - return ci.SM_RemoveUser(gcd->ptszID, gcd->pszModule, gce->ptszUID) == 0; - - return GC_EVENT_ERROR; -} - -static INT_PTR Service_GetAddEventPtr(WPARAM, LPARAM lParam) -{ - GCPTRS *gp = (GCPTRS *)lParam; - - mir_cslock lck(cs); - gp->pfnAddEvent = Service_AddEvent; - return 0; -} - -static int ModulesLoaded(WPARAM, LPARAM) -{ - LoadChatIcons(); - - HookEvent(ME_SMILEYADD_OPTIONSCHANGED, SmileyOptionsChanged); - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu); - - CLISTMENUITEM mi = { sizeof(mi) }; - mi.position = -2000090001; - mi.flags = CMIF_DEFAULT; - mi.icolibItem = LoadSkinnedIconHandle(SKINICON_CHAT_JOIN); - mi.pszName = LPGEN("&Join chat"); - mi.pszService = "GChat/JoinChat"; - hJoinMenuItem = Menu_AddContactMenuItem(&mi); - - mi.position = -2000090000; - mi.icolibItem = LoadSkinnedIconHandle(SKINICON_CHAT_LEAVE); - mi.flags = CMIF_NOTOFFLINE; - mi.pszName = LPGEN("&Leave chat"); - mi.pszService = "GChat/LeaveChat"; - hLeaveMenuItem = Menu_AddContactMenuItem(&mi); - - ci.SetAllOffline(TRUE, NULL); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Service creation - -static bool bInited = false; - -int LoadChatModule(void) -{ - HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); - HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); - HookEvent(ME_SKIN_ICONSCHANGED, IconsChanged); - - CreateServiceFunction(MS_GC_REGISTER, Service_Register); - CreateServiceFunction(MS_GC_NEWSESSION, Service_NewChat); - CreateServiceFunction(MS_GC_EVENT, Service_AddEvent); - CreateServiceFunction(MS_GC_GETEVENTPTR, Service_GetAddEventPtr); - CreateServiceFunction(MS_GC_GETINFO, Service_GetInfo); - CreateServiceFunction(MS_GC_GETSESSIONCOUNT, Service_GetCount); - - CreateServiceFunction("GChat/DblClickEvent", EventDoubleclicked); - CreateServiceFunction("GChat/PrebuildMenuEvent", PrebuildContactMenuSvc); - CreateServiceFunction("GChat/JoinChat", JoinChat); - CreateServiceFunction("GChat/LeaveChat", LeaveChat); - CreateServiceFunction("GChat/GetInterface", SvcGetChatManager); - - ci.hSendEvent = CreateHookableEvent(ME_GC_EVENT); - ci.hBuildMenuEvent = CreateHookableEvent(ME_GC_BUILDMENU); - hHookEvent = CreateHookableEvent(ME_GC_HOOK_EVENT); - - HookEvent(ME_FONT_RELOAD, FontsChanged); - HookEvent(ME_SKIN2_ICONSCHANGED, IconsChanged); - - bInited = true; - return 0; -} - -void UnloadChatModule(void) -{ - if (!bInited) - return; - - mir_free(ci.szActiveWndID); - mir_free(ci.szActiveWndModule); - - FreeMsgLogBitmaps(); - OptionsUnInit(); - - DestroyHookableEvent(ci.hSendEvent); - DestroyHookableEvent(ci.hBuildMenuEvent); - DestroyHookableEvent(hHookEvent); -} diff --git a/src/modules/chat/clist.cpp b/src/modules/chat/clist.cpp deleted file mode 100644 index 4306806568..0000000000 --- a/src/modules/chat/clist.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright (C) 2003 Jörgen Persson
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-MCONTACT AddRoom(const char *pszModule, const TCHAR *pszRoom, const TCHAR *pszDisplayName, int iType)
-{
- TCHAR pszGroup[50]; *pszGroup = '\0';
- ptrT groupName(db_get_tsa(NULL, CHAT_MODULE, "AddToGroup"));
- if (groupName)
- _tcsncpy_s(pszGroup, groupName, _TRUNCATE);
- else
- mir_tstrcpy(pszGroup, _T("Chat rooms"));
-
- if (pszGroup[0]) {
- HANDLE hGroup = Clist_GroupExists(pszGroup);
- if (hGroup == 0) {
- hGroup = Clist_CreateGroup(0, pszGroup);
- if (hGroup) {
- CallService(MS_CLUI_GROUPADDED, (WPARAM)hGroup, 0);
- CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)hGroup, 1);
- }
- }
- }
-
- MCONTACT hContact = ci.FindRoom(pszModule, pszRoom);
- if (hContact) { //contact exist, make sure it is in the right group
- if (pszGroup[0]) {
- ptrT grpName(db_get_tsa(hContact, "CList", "Group"));
- if (!mir_tstrcmp(pszGroup, grpName))
- db_set_ts(hContact, "CList", "Group", pszGroup);
- }
-
- db_set_w(hContact, pszModule, "Status", ID_STATUS_OFFLINE);
- db_set_ts(hContact, pszModule, "Nick", pszDisplayName);
- return hContact;
- }
-
- // here we create a new one since no one is to be found
- if ((hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0)) == NULL)
- return NULL;
-
- CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)pszModule);
- if (pszGroup[0])
- db_set_ts(hContact, "CList", "Group", pszGroup);
- else
- db_unset(hContact, "CList", "Group");
- db_set_ts(hContact, pszModule, "Nick", pszDisplayName);
- db_set_ts(hContact, pszModule, "ChatRoomID", pszRoom);
- db_set_b(hContact, pszModule, "ChatRoom", (BYTE)iType);
- db_set_w(hContact, pszModule, "Status", ID_STATUS_OFFLINE);
- return hContact;
-}
-
-BOOL SetOffline(MCONTACT hContact, BOOL bHide)
-{
- if (hContact) {
- char *szProto = GetContactProto(hContact);
- db_set_w(hContact, szProto, "ApparentMode", 0);
- db_set_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
- return TRUE;
- }
-
- return FALSE;
-}
-
-BOOL SetAllOffline(BOOL bHide, const char *pszModule)
-{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- char *szProto = GetContactProto(hContact);
- if (!ci.MM_FindModule(szProto))
- continue;
- if (pszModule && mir_strcmp(pszModule, szProto))
- continue;
- int i = db_get_b(hContact, szProto, "ChatRoom", 0);
- if (i != 0) {
- db_set_w(hContact, szProto, "ApparentMode", 0);
- db_set_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
- }
- }
-
- return TRUE;
-}
-
-int RoomDoubleclicked(WPARAM hContact, LPARAM lParam)
-{
- if (!hContact)
- return 0;
-
- char *szProto = GetContactProto(hContact);
- if (ci.MM_FindModule(szProto) == NULL)
- return 0;
- if (db_get_b(hContact, szProto, "ChatRoom", 0) == 0)
- return 0;
-
- ptrT roomid(db_get_tsa(hContact, szProto, "ChatRoomID"));
- if (roomid == NULL)
- return 0;
-
- SESSION_INFO *si = ci.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 &&
- !CallService(MS_CLIST_GETEVENT, hContact, 0) &&
- IsWindowVisible(si->hWnd) && !IsIconic(si->hWnd))
- {
- if (ci.OnDblClickSession)
- ci.OnDblClickSession(si);
- return 1;
- }
- ci.ShowRoom(si, WINDOW_VISIBLE, TRUE);
- }
- return 1;
-}
-
-INT_PTR EventDoubleclicked(WPARAM wParam,LPARAM lParam)
-{
- return RoomDoubleclicked((WPARAM)((CLISTEVENT*)lParam)->hContact, 0);
-}
-
-INT_PTR JoinChat(WPARAM hContact, LPARAM lParam)
-{
- if (hContact) {
- char *szProto = GetContactProto(hContact);
- if (szProto) {
- if (db_get_w(hContact, szProto, "Status", 0) == ID_STATUS_OFFLINE)
- CallProtoService(szProto, PS_JOINCHAT, hContact, lParam);
- else
- RoomDoubleclicked(hContact, 0);
- }
- }
-
- return 0;
-}
-
-INT_PTR LeaveChat(WPARAM hContact, LPARAM lParam)
-{
- if (hContact) {
- char *szProto = GetContactProto(hContact);
- if (szProto)
- CallProtoService(szProto, PS_LEAVECHAT, hContact, lParam);
- }
- return 0;
-}
-
-int PrebuildContactMenu(WPARAM hContact, LPARAM)
-{
- if (hContact == 0)
- return 0;
-
- bool bEnabledJoin = false, bEnabledLeave = false;
- char *szProto = GetContactProto(hContact);
- if (szProto) {
- // display this menu item only for chats
- if (db_get_b(hContact, szProto, "ChatRoom", 0)) {
- // still hide it for offline protos
- if (CallProtoService(szProto, PS_GETSTATUS, 0, 0) != ID_STATUS_OFFLINE) {
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.flags = CMIM_NAME;
- if (db_get_w(hContact, szProto, "Status", 0) == ID_STATUS_OFFLINE) {
- if (ProtoServiceExists(szProto, PS_JOINCHAT)) {
- bEnabledJoin = true;
- mi.pszName = LPGEN("&Join chat");
- }
- }
- else {
- bEnabledJoin = true;
- mi.pszName = LPGEN("&Open chat window");
- }
- Menu_ModifyItem(hJoinMenuItem, &mi);
- }
- bEnabledLeave = ProtoServiceExists(szProto, PS_LEAVECHAT) != 0;
- }
- }
-
- Menu_ShowItem(hJoinMenuItem, bEnabledJoin);
- Menu_ShowItem(hLeaveMenuItem, bEnabledLeave);
- return 0;
-}
-
-INT_PTR PrebuildContactMenuSvc(WPARAM wParam, LPARAM lParam)
-{
- return PrebuildContactMenu(wParam, lParam);
-}
-
-BOOL AddEvent(MCONTACT hContact, HICON hIcon, MEVENT hEvent, int type, TCHAR* fmt, ...)
-{
- TCHAR szBuf[4096];
-
- if (!fmt || !fmt[0] || mir_tstrlen(fmt) > 2000)
- return FALSE;
-
- va_list marker;
- va_start(marker, fmt);
- mir_vsntprintf(szBuf, SIZEOF(szBuf), fmt, marker);
- va_end(marker);
-
- CLISTEVENT cle = { 0 };
- cle.cbSize = sizeof(cle);
- cle.hContact = hContact;
- cle.hDbEvent = hEvent;
- cle.flags = type | CLEF_TCHAR;
- cle.hIcon = hIcon;
- cle.pszService = "GChat/DblClickEvent" ;
- cle.ptszTooltip = TranslateTS(szBuf);
- if (type) {
- if (!CallService(MS_CLIST_GETEVENT, hContact, 0))
- CallService(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle);
- }
- else {
- if (CallService(MS_CLIST_GETEVENT, hContact, 0))
- CallService(MS_CLIST_REMOVEEVENT, hContact, (LPARAM)GC_FAKE_EVENT);
- CallService(MS_CLIST_ADDEVENT, hContact, (LPARAM)&cle);
- }
- return TRUE;
-}
-
-MCONTACT FindRoom(const char *pszModule, const TCHAR *pszRoom)
-{
- for (MCONTACT hContact = db_find_first(pszModule); hContact; hContact = db_find_next(hContact, pszModule)) {
- if (!db_get_b(hContact, pszModule, "ChatRoom", 0))
- continue;
-
- ptrT roomid(db_get_tsa(hContact, pszModule, "ChatRoomID"));
- if (roomid != NULL && !mir_tstrcmpi(roomid, pszRoom))
- return hContact;
- }
-
- return 0;
-}
diff --git a/src/modules/chat/colorchooser.cpp b/src/modules/chat/colorchooser.cpp deleted file mode 100644 index f81012b527..0000000000 --- a/src/modules/chat/colorchooser.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright 2000-12 Miranda IM, 2012-15 Miranda NG project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-struct COLORCHOOSER
-{
- MODULEINFO *pModule;
- int xPosition, yPosition;
- HWND hWndTarget, hWndChooser;
- BOOL bForeground;
- GCSessionInfoBase *si;
-};
-
-static int CalculateCoordinatesToButton(COLORCHOOSER * pCC, POINT pt)
-{
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
- int nCols = iSquareRoot * iSquareRoot < pCC->pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
-
- int col = pt.x / 25;
- int row = (pt.y - 20) / 20;
- int pos = nCols * row + col;
-
- if (pt.y < 20 && pos >= pCC->pModule->nColorCount)
- pos = -1;
-
- return pos;
-}
-
-static RECT CalculateButtonToCoordinates(COLORCHOOSER * pCC, int buttonPosition)
-{
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
- int nCols = iSquareRoot * iSquareRoot < pCC->pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
-
- int row = buttonPosition / nCols;
- int col = buttonPosition % nCols;
-
- RECT pt;
- pt.left = col * 25 + 1;
- pt.top = row * 20 + 20;
- pt.right = pt.left + 25 - 1;
- pt.bottom = pt.top + 20;
-
- return pt;
-}
-
-static INT_PTR CALLBACK DlgProcColorToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static COLORCHOOSER* pCC = NULL;
- static int iCurrentHotTrack;
- static BOOL bChoosing;
- static int iRows;
- static int iColumns;
- static HWND hPreviousActiveWindow;
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- pCC = (COLORCHOOSER*) lParam;
-
- iCurrentHotTrack = -2;
- bChoosing = FALSE;
-
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
-
- iColumns = iSquareRoot * iSquareRoot == pCC->pModule->nColorCount ? iSquareRoot : iSquareRoot + 1;
- iRows = iSquareRoot;
-
- RECT rc;
- rc.top = rc.left = 100;
- rc.right = 100 + iColumns * 25 + 1;
- rc.bottom = iRows * 20 + 100 + 20;
-
- AdjustWindowRectEx(&rc, GetWindowLongPtr(hwndDlg, GWL_STYLE), FALSE, GetWindowLongPtr(hwndDlg, GWL_EXSTYLE));
-
- int width = rc.right - rc.left;
- int height = rc.bottom - rc.top;
-
- pCC->yPosition -= height;
-
- SetDlgItemText(hwndDlg, IDC_COLORTEXT, pCC->bForeground ? TranslateT("Text color") : TranslateT("Background color"));
- SetWindowPos(GetDlgItem(hwndDlg, IDC_COLORTEXT), NULL, 0, 0, width, 20, 0);
- SetWindowPos(hwndDlg, NULL, pCC->xPosition, pCC->yPosition, width, height, SWP_SHOWWINDOW);
- }
- break;
-
- case WM_CTLCOLOREDIT:
- case WM_CTLCOLORSTATIC:
- if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_COLORTEXT)) {
- SetTextColor((HDC)wParam, RGB(60, 60, 150));
- SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
- return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- if (iCurrentHotTrack >= 0)
- PostMessage(hwndDlg, WM_LBUTTONUP, 0, 0);
- break;
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
- }
- break;
-
- case WM_LBUTTONUP:
- if (iCurrentHotTrack >= 0 && iCurrentHotTrack < pCC->pModule->nColorCount && pCC->hWndTarget != NULL) {
- CHARFORMAT2 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- cf.dwMask = 0;
- cf.dwEffects = 0;
-
- HWND hWindow = GetParent(pCC->hWndTarget);
- int ctrlId = GetDlgCtrlID(pCC->hWndChooser);
-
- if (pCC->bForeground) {
- pCC->si->bFGSet = TRUE;
- pCC->si->iFG = iCurrentHotTrack;
- if (IsDlgButtonChecked(hWindow, ctrlId)) {
- cf.dwMask = CFM_COLOR;
- cf.crTextColor = pCC->pModule->crColors[iCurrentHotTrack];
- SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- }
- }
- else {
- pCC->si->bBGSet = TRUE;
- pCC->si->iBG = iCurrentHotTrack;
- if (IsDlgButtonChecked(hWindow, ctrlId)) {
- cf.dwMask = CFM_BACKCOLOR;
- cf.crBackColor = pCC->pModule->crColors[iCurrentHotTrack];
- SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
- }
- }
- }
- PostMessage(hwndDlg, WM_CLOSE, 0, 0);
- break;
-
- case WM_ACTIVATE:
- if (wParam == WA_INACTIVE)
- PostMessage(hwndDlg, WM_CLOSE, 0, 0);
- else if ((wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE))
- hPreviousActiveWindow = (HWND)lParam;
- break;
-
- case WM_MOUSEMOVE:
- {
- HDC hdc = GetDC(hwndDlg);
- POINT pt;
- RECT rect;
- int but;
-
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
-
- if (iCurrentHotTrack == -2)
- return 0; // prevent focussing when not drawn yet!
-
- but = CalculateCoordinatesToButton(pCC, pt);
-
- // weird stuff
- if (but != iCurrentHotTrack) {
- if (iCurrentHotTrack >= 0) {
- rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
- DrawFocusRect(hdc, &rect);
- iCurrentHotTrack = -1;
- }
- iCurrentHotTrack = but;
-
- if (iCurrentHotTrack >= 0) {
- rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
- DrawFocusRect(hdc, &rect);
- }
- }
- ReleaseDC(hwndDlg, hdc);
- }
- break;
-
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- int iThisRow = 1;
- int iThisColumn = 0;
-
- RECT rc;
- GetClientRect(hwndDlg, &rc);
- rc.top += 20;
-
- HDC hdc = BeginPaint(hwndDlg, &ps);
-
- // fill background
- FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
-
- for (int i=0; i < pCC->pModule->nColorCount; i++) {
- // decide place to draw the color block in the window
- iThisColumn ++;
- if (iThisColumn > iColumns) {
- iThisColumn = 1;
- iThisRow++;
- }
-
- if (pCC->bForeground && pCC->si->bFGSet && pCC->si->iFG == i || !pCC->bForeground && pCC->si->bBGSet && pCC->si->iBG == i) {
- rc.top = (iThisRow - 1) * 20 + 1 + 20 ;
- rc.left = (iThisColumn - 1) * 25 + 1 + 1 ;
- rc.bottom = iThisRow * 20 - 1 + 20 ;
- rc.right = iThisColumn * 25 - 1 ;
-
- DrawEdge(hdc, &rc, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_BOTTOM);
- }
-
- rc.top = (iThisRow - 1) * 20 + 3 + 20 ;
- rc.left = (iThisColumn - 1) * 25 + 3 + 1 ;
- rc.bottom = iThisRow * 20 - 3 + 20 ;
- rc.right = iThisColumn * 25 - 3 ;
-
- FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
-
- HBRUSH hbr = CreateSolidBrush(pCC->pModule->crColors[i]);
-
- rc.top = (iThisRow - 1) * 20 + 4 + 20;
- rc.left = (iThisColumn - 1) * 25 + 4 + 1;
- rc.bottom = iThisRow * 20 - 4 + 20;
- rc.right = iThisColumn * 25 - 4;
-
- FillRect(hdc, &rc, hbr);
- DeleteObject(hbr);
- }
-
- EndPaint(hwndDlg, &ps);
- iCurrentHotTrack = -1;
- }
- break;
-
- case WM_CLOSE:
- SetFocus(pCC->hWndTarget);
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- mir_free(pCC);
- return TRUE;
- }
-
- return FALSE;
-}
-
-void ColorChooser(SESSION_INFO *si, BOOL bFG, HWND hwndDlg, HWND hwndTarget, HWND hwndChooser)
-{
- RECT rc;
- GetWindowRect(hwndChooser, &rc);
-
- COLORCHOOSER *pCC = (COLORCHOOSER *)mir_alloc(sizeof(COLORCHOOSER));
- pCC->hWndTarget = hwndTarget;
- pCC->pModule = ci.MM_FindModule(si->pszModule);
- pCC->xPosition = rc.left + 3;
- pCC->yPosition = IsWindowVisible(hwndChooser) ? rc.top - 1 : rc.top + 20;
- pCC->bForeground = bFG;
- pCC->hWndChooser = hwndChooser;
- pCC->si = si;
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_COLORCHOOSER), hwndDlg, DlgProcColorToolWindow, (LPARAM)pCC);
-}
diff --git a/src/modules/chat/log.cpp b/src/modules/chat/log.cpp deleted file mode 100644 index 4ad98b44eb..0000000000 --- a/src/modules/chat/log.cpp +++ /dev/null @@ -1,542 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright (C) 2003 Jörgen Persson
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-// The code for streaming the text is to a large extent copied from
-// the srmm module and then modified to fit the chat module.
-
-char* pLogIconBmpBits[14];
-size_t logIconBmpSize[ SIZEOF(pLogIconBmpBits) ];
-
-#define RTFCACHELINESIZE 128
-static char CHAT_rtfFontsGlobal[OPTIONS_FONTCOUNT][RTFCACHELINESIZE];
-
-static int EventToIndex(LOGINFO *lin)
-{
- switch (lin->iType) {
- case GC_EVENT_MESSAGE:
- if (lin->bIsMe)
- return 10;
- else
- return 9;
-
- case GC_EVENT_JOIN: return 3;
- case GC_EVENT_PART: return 4;
- case GC_EVENT_QUIT: return 5;
- case GC_EVENT_NICK: return 7;
- case GC_EVENT_KICK: return 6;
- case GC_EVENT_NOTICE: return 8;
- case GC_EVENT_TOPIC: return 11;
- case GC_EVENT_INFORMATION:return 12;
- case GC_EVENT_ADDSTATUS: return 13;
- case GC_EVENT_REMOVESTATUS: return 14;
- case GC_EVENT_ACTION: return 15;
- }
- return 0;
-}
-
-static int EventToIcon(LOGINFO *lin)
-{
- switch (lin->iType) {
- case GC_EVENT_MESSAGE:
- if (lin->bIsMe)
- return ICON_MESSAGEOUT;
- else
- return ICON_MESSAGE;
-
- case GC_EVENT_JOIN: return ICON_JOIN;
- case GC_EVENT_PART: return ICON_PART;
- case GC_EVENT_QUIT: return ICON_QUIT;
- case GC_EVENT_NICK: return ICON_NICK;
- case GC_EVENT_KICK: return ICON_KICK;
- case GC_EVENT_NOTICE: return ICON_NOTICE;
- case GC_EVENT_TOPIC: return ICON_TOPIC;
- case GC_EVENT_INFORMATION:return ICON_INFO;
- case GC_EVENT_ADDSTATUS: return ICON_ADDSTATUS;
- case GC_EVENT_REMOVESTATUS: return ICON_REMSTATUS;
- case GC_EVENT_ACTION: return ICON_ACTION;
- }
- return 0;
-}
-
-char* Log_SetStyle(int style)
-{
- if (style < OPTIONS_FONTCOUNT)
- return CHAT_rtfFontsGlobal[style];
-
- return "";
-}
-
-static void Log_Append(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...)
-{
- va_list va;
- int charsDone = 0;
-
- va_start(va, fmt);
- for (;;) {
- charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va);
- if (charsDone >= 0)
- break;
- cbBufferAlloced += 4096;
- buffer = (char*)mir_realloc(buffer, cbBufferAlloced);
- }
- va_end(va);
- cbBufferEnd += charsDone;
-}
-
-static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *fmt, ...)
-{
- va_list va;
- int lineLen, textCharsCount = 0;
- TCHAR* line = (TCHAR*)alloca(8001 * sizeof(TCHAR));
-
- va_start(va, fmt);
- lineLen = mir_vsntprintf(line, 8000, fmt, va);
- if (lineLen < 0) lineLen = 8000;
- line[lineLen] = 0;
- va_end(va);
-
- lineLen = lineLen * 20 + 8;
- if (cbBufferEnd + lineLen > cbBufferAlloced) {
- cbBufferAlloced += (lineLen + 1024 - lineLen % 1024);
- buffer = (char *)mir_realloc(buffer, cbBufferAlloced);
- }
-
- char *d = buffer + cbBufferEnd;
-
- for (; *line; line++, textCharsCount++) {
- if (*line == '\r' && line[1] == '\n') {
- memcpy(d, "\\par ", 5);
- line++;
- d += 5;
- }
- else if (*line == '\n') {
- memcpy(d, "\\line ", 6);
- d += 6;
- }
- else if (*line == '%' && !simpleMode) {
- char szTemp[200];
-
- szTemp[0] = '\0';
- switch (*++line) {
- case '\0':
- case '%':
- *d++ = '%';
- break;
-
- case 'c':
- case 'f':
- if (g_Settings->bStripFormat || streamData->bStripFormat)
- line += 2;
-
- else if (line[1] != '\0' && line[2] != '\0') {
- TCHAR szTemp3[3], c = *line;
- int col;
- szTemp3[0] = line[1];
- szTemp3[1] = line[2];
- szTemp3[2] = '\0';
- line += 2;
-
- col = _ttoi(szTemp3);
- col += (OPTIONS_FONTCOUNT + 1);
- mir_snprintf(szTemp, (c == 'c') ? "\\cf%u " : "\\highlight%u ", col);
- }
- break;
- case 'C':
- case 'F':
- if (!g_Settings->bStripFormat && !streamData->bStripFormat) {
- int j = streamData->lin->bIsHighlighted ? 16 : EventToIndex(streamData->lin);
- if (*line == 'C')
- mir_snprintf(szTemp, "\\cf%u ", j + 1);
- else
- mir_snprintf(szTemp, "\\highlight0 ");
- }
- break;
- case 'b':
- case 'u':
- case 'i':
- if (!streamData->bStripFormat)
- mir_snprintf(szTemp, (*line == 'u') ? "\\%cl " : "\\%c ", *line);
- break;
-
- case 'B':
- case 'U':
- case 'I':
- if (!streamData->bStripFormat) {
- mir_snprintf(szTemp, (*line == 'U') ? "\\%cl0 " : "\\%c0 ", *line);
- CharLowerA(szTemp);
- }
- break;
-
- case 'r':
- if (!streamData->bStripFormat) {
- int index = EventToIndex(streamData->lin);
- mir_snprintf(szTemp, "%s ", Log_SetStyle(index));
- }
- break;
- }
-
- if (szTemp[0]) {
- size_t iLen = mir_strlen(szTemp);
- memcpy(d, szTemp, iLen);
- d += iLen;
- }
- }
- else if (*line == '\t' && !streamData->bStripFormat) {
- memcpy(d, "\\tab ", 5);
- d += 5;
- }
- else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) {
- *d++ = '\\';
- *d++ = (char)*line;
- }
- else if (*line > 0 && *line < 128) {
- *d++ = (char)*line;
- }
- else d += sprintf(d, "\\u%u ?", (WORD)*line); //!!!!!!!!!!!
- }
-
- cbBufferEnd = (int)(d - buffer);
- return textCharsCount;
-}
-
-static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, LOGSTREAMDATA *streamData)
-{
- TCHAR szTemp[512], szTemp2[512];
- TCHAR* pszNick = NULL;
- if (streamData->lin->ptszNick) {
- if (g_Settings->bLogLimitNames && mir_tstrlen(streamData->lin->ptszNick) > 20) {
- mir_tstrncpy(szTemp2, streamData->lin->ptszNick, 20);
- mir_tstrncpy(szTemp2 + 20, _T("..."), 4);
- }
- else mir_tstrncpy(szTemp2, streamData->lin->ptszNick, 511);
-
- if (streamData->lin->ptszUserInfo)
- mir_sntprintf(szTemp, _T("%s (%s)"), szTemp2, streamData->lin->ptszUserInfo);
- else
- _tcsncpy_s(szTemp, szTemp2, _TRUNCATE);
- pszNick = szTemp;
- }
-
- switch (streamData->lin->iType) {
- case GC_EVENT_MESSAGE:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, _T("%s"), streamData->lin->ptszText);
- break;
- case GC_EVENT_ACTION:
- if (streamData->lin->ptszNick && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s "), streamData->lin->ptszNick);
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, _T("%s"), streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_JOIN:
- if (pszNick) {
- if (!streamData->lin->bIsMe)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has joined"), pszNick);
- else
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, TranslateT("You have joined %s"), streamData->si->ptszName);
- }
- break;
- case GC_EVENT_PART:
- if (pszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has left"), pszNick);
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T(": %s"), streamData->lin->ptszText);
- break;
- case GC_EVENT_QUIT:
- if (pszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has disconnected"), pszNick);
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, _T(": %s"), streamData->lin->ptszText);
- break;
- case GC_EVENT_NICK:
- if (pszNick && streamData->lin->ptszText) {
- if (!streamData->lin->bIsMe)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s is now known as %s"), pszNick, streamData->lin->ptszText);
- else
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("You are now known as %s"), streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_KICK:
- if (streamData->lin->ptszNick && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s kicked %s"), streamData->lin->ptszStatus, streamData->lin->ptszNick);
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, _T(": %s"), streamData->lin->ptszText);
- break;
- case GC_EVENT_NOTICE:
- if (pszNick && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("Notice from %s: "), pszNick);
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, _T("%s"), streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_TOPIC:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, TranslateT("The topic is '%s%s'"), streamData->lin->ptszText, _T("%r"));
- if (streamData->lin->ptszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced,
- streamData->lin->ptszUserInfo ? TranslateT(" (set by %s on %s)") : TranslateT(" (set by %s)"),
- streamData->lin->ptszNick, streamData->lin->ptszUserInfo);
- break;
- case GC_EVENT_INFORMATION:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, (streamData->lin->bIsMe) ? _T("--> %s") : _T("%s"), streamData->lin->ptszText);
- break;
- case GC_EVENT_ADDSTATUS:
- if (streamData->lin->ptszNick && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s enables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
- break;
- case GC_EVENT_REMOVESTATUS:
- if (streamData->lin->ptszNick && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s disables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
- break;
- }
-}
-
-TCHAR* MakeTimeStamp(TCHAR *pszStamp, time_t time)
-{
- static TCHAR szTime[30];
- if (!_tcsftime(szTime, SIZEOF(szTime)-1, pszStamp, localtime(&time)))
- _tcsncpy_s(szTime, TranslateT("<invalid>"), _TRUNCATE);
- return szTime;
-}
-
-char* Log_CreateRTF(LOGSTREAMDATA *streamData)
-{
- MODULEINFO *mi = ci.MM_FindModule(streamData->si->pszModule);
-
- // guesstimate amount of memory for the RTF
- size_t bufferEnd = 0, bufferAlloced = streamData->bRedraw ? 1024 * (streamData->si->iEventCount + 2) : 2048;
- char *buffer = (char *)mir_alloc(bufferAlloced);
- buffer[0] = '\0';
-
- // ### RTF HEADER
- char *header = mi->pszHeader;
- if (header)
- Log_Append(buffer, bufferEnd, bufferAlloced, header);
-
- // ### RTF BODY (one iteration per event that should be streamed in)
- for (LOGINFO *lin = streamData->lin; lin; lin = lin->prev) {
- // filter
- if (streamData->si->iType == GCW_CHATROOM || streamData->si->iType == GCW_PRIVMESS)
- if (streamData->si->bFilterEnabled && (streamData->si->iLogFilterFlags & lin->iType) == 0)
- continue;
-
- // create new line, and set font and color
- if (lin->next != NULL)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\par ");
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
-
- // Insert icon
- if ((lin->iType & g_Settings->dwIconFlags) || lin->bIsHighlighted && (g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT)) {
- int iIndex = (lin->bIsHighlighted && g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT) ? ICON_HIGHLIGHT : EventToIcon(lin);
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14");
- while (bufferAlloced - bufferEnd < logIconBmpSize[0])
- bufferAlloced += 4096;
- buffer = (char *)mir_realloc(buffer, bufferAlloced);
- memcpy(buffer + bufferEnd, pLogIconBmpBits[iIndex], logIconBmpSize[iIndex]);
- bufferEnd += logIconBmpSize[iIndex];
- }
-
- if (g_Settings->bTimeStampEventColour) {
- LOGFONT &lf = ci.aFonts[0].lf;
-
- // colored timestamps
- static char szStyle[256];
- if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
- int iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1);
- mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
- }
- else {
- int iii = lin->bIsHighlighted ? 16 : EventToIndex(lin);
- mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
- }
- }
- else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
-
- if (g_Settings->dwIconFlags)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
-
- //insert timestamp
- if (g_Settings->bShowTime) {
- TCHAR szTimeStamp[30], szOldTimeStamp[30];
-
- mir_tstrncpy(szTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, lin->time), 30);
- mir_tstrncpy(szOldTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, streamData->si->LastTime), 30);
- if (!g_Settings->bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) {
- streamData->si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s"), szTimeStamp);
- }
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
- }
-
- // Insert the nick
- if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
- TCHAR pszTemp[300], *p1;
-
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
- mir_tstrncpy(pszTemp, lin->bIsMe ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick, 299);
- p1 = _tcsstr(pszTemp, _T("%n"));
- if (p1)
- p1[1] = 's';
-
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick);
- Log_Append(buffer, bufferEnd, bufferAlloced, " ");
- }
-
- // Insert the message
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
- streamData->lin = lin;
- AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData);
- }
-
- // ### RTF END
- if (streamData->bRedraw)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}");
- else
- Log_Append(buffer, bufferEnd, bufferAlloced, "}");
- return buffer;
-}
-
-char* Log_CreateRtfHeader(MODULEINFO *mi)
-{
- int i;
-
- // guesstimate amount of memory for the RTF header
- size_t bufferEnd = 0, bufferAlloced = 4096;
- char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced);
- buffer[0] = '\0';
-
- // get the number of pixels per logical inch
- HDC hdc = GetDC(NULL);
- ci.logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY);
- ci.logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX);
- ReleaseDC(NULL, hdc);
-
- // ### RTF HEADER
-
- // font table
- Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
- for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, ci.aFonts[i].lf.lfCharSet, ci.aFonts[i].lf.lfFaceName);
-
- // colour table
- Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;");
-
- for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(ci.aFonts[i].color), GetGValue(ci.aFonts[i].color), GetBValue(ci.aFonts[i].color));
-
- for (i = 0; i < mi->nColorCount; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
-
- // new paragraph
- Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard");
-
- // set tabs and indents
- int iIndent = 0;
-
- if (g_Settings->dwIconFlags) {
- iIndent += (14 * 1440) / ci.logPixelSX;
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent);
- }
- if (g_Settings->bShowTime) {
- int iSize = (g_Settings->LogTextIndent * 1440) / ci.logPixelSX;
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize);
- if (g_Settings->bLogIndentEnabled)
- iIndent += iSize;
- }
-
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
- return buffer;
-}
-
-#define RTFPICTHEADERMAXSIZE 78
-
-void LoadMsgLogBitmaps(void)
-{
- HBRUSH hBkgBrush = CreateSolidBrush(g_Settings->crLogBackground);
-
- BITMAPINFOHEADER bih = { 0 };
- bih.biSize = sizeof(bih);
- bih.biBitCount = 24;
- bih.biCompression = BI_RGB;
- bih.biHeight = bih.biWidth = g_Settings->LogIconSize;
- bih.biPlanes = 1;
- int widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4;
-
- RECT rc;
- rc.top = rc.left = 0;
- rc.right = bih.biWidth;
- rc.bottom = bih.biHeight;
-
- HDC hdc = GetDC(NULL);
- HBITMAP hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight);
- HDC hdcMem = CreateCompatibleDC(hdc);
- PBYTE pBmpBits = (PBYTE)mir_alloc(widthBytes * bih.biHeight);
- for (int i = 0; i < SIZEOF(pLogIconBmpBits); i++) {
- size_t size = RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2;
- pLogIconBmpBits[i] = (char*)mir_alloc(size);
- size_t rtfHeaderSize = mir_snprintf((char *)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);
-
- HICON hIcon = ci.hIcons[i];
- HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
- FillRect(hdcMem, &rc, hBkgBrush);
- DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
- SelectObject(hdcMem, hoBmp);
- GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS);
-
- char *szDest = pLogIconBmpBits[i] + rtfHeaderSize;
- bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
- bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
- mir_strcpy(szDest, "}");
-
- logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
- }
- mir_free(pBmpBits);
- DeleteDC(hdcMem);
- DeleteObject(hBmp);
- ReleaseDC(NULL, hdc);
- DeleteObject(hBkgBrush);
-
- if (ci.logPixelSY == 0) {
- HDC hdc;
- hdc = GetDC(NULL);
- ci.logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY);
- ci.logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX);
- ReleaseDC(NULL, hdc);
- }
-
- for (int i = 0; i < OPTIONS_FONTCOUNT; i++) {
- LOGFONT &F = ci.aFonts[i].lf;
- mir_snprintf(CHAT_rtfFontsGlobal[i], RTFCACHELINESIZE,
- "\\f%u\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", i, i + 1,
- F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic, F.lfUnderline, 2 * abs(F.lfHeight) * 74 / ci.logPixelSY);
- }
-}
-
-void FreeMsgLogBitmaps(void)
-{
- for (int i = 0; i < SIZEOF(pLogIconBmpBits); i++)
- mir_free(pLogIconBmpBits[i]);
-}
diff --git a/src/modules/chat/manager.cpp b/src/modules/chat/manager.cpp deleted file mode 100644 index bbc846c89f..0000000000 --- a/src/modules/chat/manager.cpp +++ /dev/null @@ -1,1331 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright 2000-12 Miranda IM, 2012-15 Miranda NG project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-#define WINDOWS_COMMANDS_MAX 30
-
-CHAT_MANAGER ci;
-
-MODULEINFO *m_ModList = 0;
-
-static void SetActiveSessionEx(SESSION_INFO *si)
-{
- if (si) {
- replaceStrT(ci.szActiveWndID, si->ptszID);
- replaceStr(ci.szActiveWndModule, si->pszModule);
- }
-}
-
-static void SetActiveSession(const TCHAR *pszID, const char *pszModule)
-{
- SESSION_INFO *si = ci.SM_FindSession(pszID, pszModule);
- if (si)
- SetActiveSessionEx(si);
-}
-
-static SESSION_INFO* GetActiveSession(void)
-{
- SESSION_INFO *si = ci.SM_FindSession(ci.szActiveWndID, ci.szActiveWndModule);
- if (si)
- return si;
-
- return ci.wndList;
-}
-
-//---------------------------------------------------
-// Session Manager functions
-//
-// Keeps track of all sessions and its windows
-//---------------------------------------------------
-
-static SESSION_INFO* SM_AddSession(const TCHAR *pszID, const char *pszModule)
-{
- if (!pszID || !pszModule)
- return NULL;
-
- if (ci.SM_FindSession(pszID, pszModule))
- return NULL;
-
- SESSION_INFO *node = (SESSION_INFO*)mir_calloc(g_cbSession);
- node->ptszID = mir_tstrdup(pszID);
- node->pszModule = mir_strdup(pszModule);
-
- if (ci.wndList == NULL) { // list is empty
- ci.wndList = node;
- node->next = NULL;
- }
- else {
- node->next = ci.wndList;
- ci.wndList = node;
- }
- return node;
-}
-
-static void SM_FreeSession(SESSION_INFO *si)
-{
- // 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
- if (si->hContact && db_get_b(si->hContact, si->pszModule, "ChatRoom", 0) != 0) {
- ci.SetOffline(si->hContact, (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS) ? TRUE : FALSE);
- db_set_s(si->hContact, si->pszModule, "Topic", "");
- db_set_s(si->hContact, si->pszModule, "StatusBar", "");
- db_unset(si->hContact, "CList", "StatusMsg");
- }
-
- ci.UM_RemoveAll(&si->pUsers);
- ci.TM_RemoveAll(&si->pStatuses);
- ci.LM_RemoveAll(&si->pLog, &si->pLogEnd);
-
- si->iStatusCount = 0;
- si->nUsersInNicklist = 0;
-
- mir_free(si->pszModule);
- mir_free(si->ptszID);
- mir_free(si->ptszName);
- mir_free(si->ptszStatusbarText);
- mir_free(si->ptszTopic);
-
- while (si->lpCommands != NULL) {
- COMMANDINFO *pNext = si->lpCommands->next;
- mir_free(si->lpCommands->lpCommand);
- mir_free(si->lpCommands);
- si->lpCommands = pNext;
- }
-
- mir_free(si);
-}
-
-static int SM_RemoveSession(const TCHAR *pszID, const char *pszModule, BOOL removeContact)
-{
- if (!pszModule)
- return FALSE;
-
- SESSION_INFO *pTemp = ci.wndList, *pLast = NULL;
- while (pTemp != NULL) {
- // match
- if ((!pszID && pTemp->iType != GCW_SERVER || !mir_tstrcmpi(pTemp->ptszID, pszID)) && !mir_strcmpi(pTemp->pszModule, pszModule)) {
- DWORD dw = pTemp->dwItemData;
-
- if (ci.OnRemoveSession)
- ci.OnRemoveSession(pTemp);
- DoEventHook(pTemp->ptszID, pTemp->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)pTemp->dwItemData);
-
- if (pLast == NULL)
- ci.wndList = pTemp->next;
- else
- pLast->next = pTemp->next;
-
- // 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
- if (pTemp->hContact && removeContact)
- CallService(MS_DB_CONTACT_DELETE, (WPARAM)pTemp->hContact, 0);
-
- SM_FreeSession(pTemp);
-
- if (pszID)
- return (int)dw;
- if (pLast)
- pTemp = pLast->next;
- else
- pTemp = ci.wndList;
- }
- else {
- pLast = pTemp;
- pTemp = pTemp->next;
- }
- }
- return FALSE;
-}
-
-static SESSION_INFO* SM_FindSession(const TCHAR *pszID, const char *pszModule)
-{
- if (!pszID || !pszModule)
- return NULL;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next)
- if (!mir_tstrcmpi(si->ptszID, pszID) && !mir_strcmpi(si->pszModule, pszModule))
- return si;
-
- return NULL;
-}
-
-static BOOL SM_SetOffline(const TCHAR *pszID, const char *pszModule)
-{
- if (!pszModule)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- ci.UM_RemoveAll(&si->pUsers);
- si->nUsersInNicklist = 0;
- if (si->iType != GCW_SERVER)
- si->bInitDone = FALSE;
- if (ci.OnOfflineSession)
- ci.OnOfflineSession(si);
- if (pszID)
- return TRUE;
- }
- return TRUE;
-}
-
-static BOOL SM_SetStatusEx(const TCHAR *pszID, const char *pszModule, const TCHAR* pszText, int flags)
-{
- if (!pszModule)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- ci.UM_SetStatusEx(si->pUsers, pszText, flags);
- if (si->hWnd)
- RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), NULL, NULL, RDW_INVALIDATE);
- if (pszID)
- return TRUE;
- }
- return TRUE;
-}
-
-static HICON SM_GetStatusIcon(SESSION_INFO *si, USERINFO * ui)
-{
- if (!ui || !si)
- return NULL;
-
- STATUSINFO *ti = ci.TM_FindStatus(si->pStatuses, ci.TM_WordToString(si->pStatuses, ui->Status));
- if (ti != NULL) {
- if ((UINT_PTR)ti->hIcon >= STATUSICONCOUNT)
- return ti->hIcon;
-
- return ci.hIcons[ICON_STATUS0 + (int)ti->hIcon];
- }
- return ci.hIcons[ICON_STATUS0];
-}
-
-static BOOL SM_AddEventToAllMatchingUID(GCEVENT *gce)
-{
- int bManyFix = 0;
-
- for (SESSION_INFO *p = ci.wndList; p != NULL; p = p->next) {
- if (!p->bInitDone || mir_strcmpi(p->pszModule, gce->pDest->pszModule))
- continue;
-
- if (!ci.UM_FindUser(p->pUsers, gce->ptszUID))
- continue;
-
- if (ci.OnEventBroadcast)
- ci.OnEventBroadcast(p, gce);
-
- if (!(gce->dwFlags & GCEF_NOTNOTIFY))
- ci.DoSoundsFlashPopupTrayStuff(p, gce, FALSE, bManyFix);
-
- bManyFix++;
- if ((gce->dwFlags & GCEF_ADDTOLOG) && g_Settings->bLoggingEnabled)
- ci.LogToFile(p, gce);
- }
-
- return 0;
-}
-
-static BOOL SM_AddEvent(const TCHAR *pszID, const char *pszModule, GCEVENT *gce, BOOL bIsHighlighted)
-{
- SESSION_INFO *p = SM_FindSession(pszID, pszModule);
- if (p == NULL)
- return TRUE;
-
- LOGINFO *li = ci.LM_AddEvent(&p->pLog, &p->pLogEnd);
- p->iEventCount += 1;
-
- li->iType = gce->pDest->iType;
- li->ptszNick = mir_tstrdup(gce->ptszNick);
- li->ptszText = mir_tstrdup(gce->ptszText);
- li->ptszStatus = mir_tstrdup(gce->ptszStatus);
- li->ptszUserInfo = mir_tstrdup(gce->ptszUserInfo);
-
- li->bIsMe = gce->bIsMe;
- li->time = gce->time;
- li->bIsHighlighted = bIsHighlighted;
-
- if (g_Settings->iEventLimit > 0 && p->iEventCount > g_Settings->iEventLimit + 20) {
- ci.LM_TrimLog(&p->pLog, &p->pLogEnd, p->iEventCount - g_Settings->iEventLimit);
- p->bTrimmed = true;
- p->iEventCount = g_Settings->iEventLimit;
- return FALSE;
- }
- return TRUE;
-}
-
-static USERINFO* SM_AddUser(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID, const TCHAR *pszNick, WORD wStatus)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return NULL;
-
- USERINFO *p = ci.UM_AddUser(si->pStatuses, &si->pUsers, pszUID, pszNick, wStatus);
- si->nUsersInNicklist++;
- if (ci.OnAddUser)
- ci.OnAddUser(si, p);
- return p;
-}
-
-static BOOL SM_MoveUser(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID)
-{
- if (!pszUID)
- return FALSE;
-
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- ci.UM_SortUser(&si->pUsers, pszUID);
- return TRUE;
-}
-
-static BOOL SM_RemoveUser(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID)
-{
- if (!pszModule || !pszUID)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- USERINFO *ui = ci.UM_FindUser(si->pUsers, pszUID);
- if (ui) {
- si->nUsersInNicklist--;
- if (ci.OnRemoveUser)
- ci.OnRemoveUser(si, ui);
-
- ci.UM_RemoveUser(&si->pUsers, pszUID);
-
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
-
- if (pszID)
- return TRUE;
- }
- }
-
- return 0;
-}
-
-static USERINFO* SM_GetUserFromIndex(const TCHAR *pszID, const char *pszModule, int index)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- return (si == NULL) ? NULL : ci.UM_FindUserFromIndex(si->pUsers, index);
-}
-
-STATUSINFO* SM_AddStatus(const TCHAR *pszID, const char *pszModule, const TCHAR *pszStatus)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return NULL;
-
- STATUSINFO *ti = ci.TM_AddStatus(&si->pStatuses, pszStatus, &si->iStatusCount);
- if (ti)
- si->iStatusCount++;
- if (ci.OnAddStatus)
- ci.OnAddStatus(si, ti);
- return ti;
-}
-
-static BOOL SM_GiveStatus(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID, const TCHAR *pszStatus)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- USERINFO *ui = ci.UM_GiveStatus(si->pUsers, pszUID, ci.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);
- }
- return TRUE;
-}
-
-static BOOL SM_SetContactStatus(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID, WORD wStatus)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- USERINFO *ui = ci.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);
- }
- return TRUE;
-}
-
-static BOOL SM_TakeStatus(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID, const TCHAR *pszStatus)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- USERINFO *ui = ci.UM_TakeStatus(si->pUsers, pszUID, ci.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);
- }
- return TRUE;
-}
-
-static LRESULT SM_SendMessage(const TCHAR *pszID, const char *pszModule, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (pszModule == NULL)
- return 0;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- if (si->hWnd) {
- LRESULT i = SendMessage(si->hWnd, msg, wParam, lParam);
- if (pszID)
- return i;
- }
- if (pszID)
- return 0;
- }
- return 0;
-}
-
-static BOOL SM_PostMessage(const TCHAR *pszID, const char *pszModule, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- if (si->hWnd)
- return PostMessage(si->hWnd, msg, wParam, lParam);
- return FALSE;
-}
-
-static BOOL SM_BroadcastMessage(const char *pszModule, UINT msg, WPARAM wParam, LPARAM lParam, BOOL bAsync)
-{
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if (pszModule && _strcmpi(si->pszModule, pszModule))
- continue;
-
- if (si->hWnd) {
- if (bAsync)
- PostMessage(si->hWnd, msg, wParam, lParam);
- else
- SendMessage(si->hWnd, msg, wParam, lParam);
- }
- }
- return TRUE;
-}
-
-static BOOL SM_SetStatus(const TCHAR *pszID, const char *pszModule, int wStatus)
-{
- if (!pszModule)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- si->wStatus = wStatus;
- if (si->hContact) {
- if (si->iType != GCW_SERVER && wStatus != ID_STATUS_OFFLINE)
- db_unset(si->hContact, "CList", "Hidden");
-
- db_set_w(si->hContact, si->pszModule, "Status", (WORD)wStatus);
- }
-
- if (ci.OnSetStatus)
- ci.OnSetStatus(si, wStatus);
-
- if (pszID)
- return TRUE;
- }
- return TRUE;
-}
-
-static BOOL SM_SendUserMessage(const TCHAR *pszID, const char *pszModule, const TCHAR* pszText)
-{
- if (!pszModule || !pszText)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- if (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS)
- DoEventHook(si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, pszText, 0);
- if (pszID)
- return TRUE;
- }
- return TRUE;
-}
-
-static BOOL SM_ChangeUID(const TCHAR *pszID, const char *pszModule, const TCHAR *pszUID, const TCHAR* pszNewUID)
-{
- if (!pszModule)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((pszID && mir_tstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
- continue;
-
- USERINFO* ui = ci.UM_FindUser(si->pUsers, pszUID);
- if (ui)
- replaceStrT(ui->pszUID, pszNewUID);
- if (pszID)
- return TRUE;
- }
- return TRUE;
-}
-
-static BOOL SM_ChangeNick(const TCHAR *pszID, const char *pszModule, GCEVENT *gce)
-{
- if (!pszModule)
- return FALSE;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if ((!pszID || !mir_tstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) {
- USERINFO *ui = ci.UM_FindUser(si->pUsers, gce->ptszUID);
- if (ui) {
- replaceStrT(ui->pszNick, gce->ptszText);
- SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
- if (ci.OnChangeNick)
- ci.OnChangeNick(si);
- }
-
- if (pszID)
- return TRUE;
- }
- }
- return TRUE;
-}
-
-static BOOL SM_SetTabbedWindowHwnd(SESSION_INFO *si, HWND hwnd)
-{
- for (SESSION_INFO *p = ci.wndList; p != NULL; p = p->next) {
- if (si && si == p)
- p->hWnd = hwnd;
- else
- p->hWnd = NULL;
- }
- return TRUE;
-}
-
-static BOOL SM_RemoveAll(void)
-{
- while (ci.wndList) {
- SESSION_INFO *pLast = ci.wndList->next;
-
- if (ci.wndList->hWnd)
- SendMessage(ci.wndList->hWnd, GC_EVENT_CONTROL + WM_USER + 500, SESSION_TERMINATE, 0);
- DoEventHook(ci.wndList->ptszID, ci.wndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)ci.wndList->dwItemData);
-
- SM_FreeSession(ci.wndList);
- ci.wndList = pLast;
- }
- ci.wndList = NULL;
- return TRUE;
-}
-
-static void SM_AddCommand(const TCHAR *pszID, const char *pszModule, const char* lpNewCommand)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return;
-
- COMMANDINFO *node = (COMMANDINFO *)mir_alloc(sizeof(COMMANDINFO));
- node->lpCommand = mir_strdup(lpNewCommand);
- node->last = NULL; // always added at beginning!
-
- // new commands are added at start
- if (si->lpCommands == NULL) {
- node->next = NULL;
- si->lpCommands = node;
- }
- else {
- node->next = si->lpCommands;
- si->lpCommands->last = node; // hmm, weird
- si->lpCommands = node;
- }
- si->lpCurrentCommand = NULL; // current command
- si->wCommandsNum++;
-
- if (si->wCommandsNum > WINDOWS_COMMANDS_MAX) {
- COMMANDINFO *pCurComm = si->lpCommands;
- while (pCurComm->next != NULL) { pCurComm = pCurComm->next; }
- COMMANDINFO *pLast = pCurComm->last;
- mir_free(pCurComm->lpCommand);
- mir_free(pCurComm);
- pLast->next = NULL;
- // done
- si->wCommandsNum--;
- }
-}
-
-static char* SM_GetPrevCommand(const TCHAR *pszID, const char *pszModule) // get previous command. returns NULL if previous command does not exist. current command remains as it was.
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return NULL;
-
- COMMANDINFO *pPrevCmd = NULL;
- if (si->lpCurrentCommand != NULL) {
- if (si->lpCurrentCommand->next != NULL) // not NULL
- pPrevCmd = si->lpCurrentCommand->next; // next command (newest at beginning)
- else
- pPrevCmd = si->lpCurrentCommand;
- }
- else pPrevCmd = si->lpCommands;
-
- si->lpCurrentCommand = pPrevCmd; // make it the new command
- return (pPrevCmd) ? pPrevCmd->lpCommand : NULL;
-}
-
-static char* SM_GetNextCommand(const TCHAR *pszID, const char *pszModule) // get next command. returns NULL if next command does not exist. current command becomes NULL (a prev command after this one will get you the last command)
-{
- SESSION_INFO *si = SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return NULL;
-
- COMMANDINFO *pNextCmd = NULL;
- if (si->lpCurrentCommand != NULL)
- pNextCmd = si->lpCurrentCommand->last; // last command (newest at beginning)
-
- si->lpCurrentCommand = pNextCmd; // make it the new command
- return (pNextCmd) ? pNextCmd->lpCommand : NULL;
-}
-
-static int SM_GetCount(const char *pszModule)
-{
- int count = 0;
-
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next)
- if (!mir_strcmpi(pszModule, si->pszModule))
- count++;
-
- return count;
-}
-
-static SESSION_INFO* SM_FindSessionByIndex(const char *pszModule, int iItem)
-{
- int count = 0;
- for (SESSION_INFO *si = ci.wndList; si != NULL; si = si->next) {
- if (!mir_strcmpi(pszModule, si->pszModule)) {
- if (iItem == count)
- return si;
-
- count++;
- }
- }
- return NULL;
-
-}
-
-static char* SM_GetUsers(SESSION_INFO *si)
-{
- if (si == NULL)
- return NULL;
-
- USERINFO *utemp = NULL;
- for (SESSION_INFO *p = ci.wndList; p != NULL; p = p->next) {
- if (si == p) {
- if ((utemp = p->pUsers) == NULL)
- return NULL;
-
- break;
- }
- }
- if (utemp == NULL)
- return NULL;
-
- char* p = NULL;
- size_t alloced = 0;
- do {
- size_t pLen = mir_strlen(p), nameLen = mir_tstrlen(utemp->pszUID);
- if (pLen + nameLen + 2 > alloced)
- p = (char*)mir_realloc(p, alloced += 4096);
-
- WideCharToMultiByte(CP_ACP, 0, utemp->pszUID, -1, p + pLen, (int)nameLen + 1, 0, 0);
- mir_strcpy(p + pLen + nameLen, " ");
- utemp = utemp->next;
- }
- while (utemp != NULL);
- return p;
-}
-
-static void SM_InvalidateLogDirectories()
-{
- for (SESSION_INFO *si = ci.wndList; si; si = si->next)
- si->pszLogFileName[0] = si->pszLogFileName[1] = 0;
-}
-
-//---------------------------------------------------
-// Module Manager functions
-//
-// Necessary to keep track of all modules
-// that has registered with the plugin
-//---------------------------------------------------
-
-static MODULEINFO* MM_AddModule(const char *pszModule)
-{
- if (pszModule == NULL)
- return NULL;
-
- if (ci.MM_FindModule(pszModule))
- return NULL;
-
- MODULEINFO *node = (MODULEINFO*)mir_calloc(g_cbModuleInfo);
- replaceStr(node->pszModule, pszModule);
- if (ci.OnCreateModule)
- ci.OnCreateModule(node);
-
- if (m_ModList == NULL) { // list is empty
- m_ModList = node;
- node->next = NULL;
- }
- else {
- node->next = m_ModList;
- m_ModList = node;
- }
- return node;
-}
-
-static void MM_IconsChanged()
-{
- LoadChatIcons();
-
- for (MODULEINFO *mi = m_ModList; mi != NULL; mi = mi->next) {
- Safe_DestroyIcon(mi->hOnlineIcon);
- Safe_DestroyIcon(mi->hOfflineIcon);
- Safe_DestroyIcon(mi->hOnlineTalkIcon);
- Safe_DestroyIcon(mi->hOfflineTalkIcon);
-
- if (ci.OnCreateModule) // recreate icons
- ci.OnCreateModule(mi);
- }
-}
-
-static void MM_FontsChanged()
-{
- for (MODULEINFO *mi = m_ModList; mi != NULL; mi = mi->next)
- mi->pszHeader = ci.Log_CreateRtfHeader(mi);
-}
-
-static MODULEINFO* MM_FindModule(const char *pszModule)
-{
- if (!pszModule)
- return NULL;
-
- for (MODULEINFO *mi = m_ModList; mi != NULL; mi = mi->next)
- if (mir_strcmpi(mi->pszModule, pszModule) == 0)
- return mi;
-
- return NULL;
-}
-
-// stupid thing..
-static void MM_FixColors()
-{
- for (MODULEINFO *mi = m_ModList; mi != NULL; mi = mi->next)
- CheckColorsInModule(mi->pszModule);
-}
-
-static BOOL MM_RemoveAll(void)
-{
- while (m_ModList != NULL) {
- 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);
-
- Safe_DestroyIcon(m_ModList->hOnlineIcon);
- Safe_DestroyIcon(m_ModList->hOfflineIcon);
- Safe_DestroyIcon(m_ModList->hOnlineTalkIcon);
- Safe_DestroyIcon(m_ModList->hOfflineTalkIcon);
-
- mir_free(m_ModList);
- m_ModList = pLast;
- }
- m_ModList = NULL;
- return TRUE;
-}
-
-//---------------------------------------------------
-// Status manager functions
-//
-// Necessary to keep track of what user statuses
-// per window nicklist that is available
-//---------------------------------------------------
-
-static STATUSINFO* TM_AddStatus(STATUSINFO **ppStatusList, const TCHAR *pszStatus, int *iCount)
-{
- if (!ppStatusList || !pszStatus)
- return NULL;
-
- if (!ci.TM_FindStatus(*ppStatusList, pszStatus)) {
- STATUSINFO *node = (STATUSINFO*)mir_alloc(sizeof(STATUSINFO));
- memset(node, 0, sizeof(STATUSINFO));
- replaceStrT(node->pszGroup, pszStatus);
- node->hIcon = (HICON)(*iCount);
- while ((int)node->hIcon > STATUSICONCOUNT - 1)
- node->hIcon--;
-
- if (*ppStatusList == NULL) { // list is empty
- node->Status = 1;
- *ppStatusList = node;
- node->next = NULL;
- }
- else {
- node->Status = ppStatusList[0]->Status * 2;
- node->next = *ppStatusList;
- *ppStatusList = node;
- }
- return node;
-
- }
- return FALSE;
-}
-
-static STATUSINFO* TM_FindStatus(STATUSINFO *pStatusList, const TCHAR *pszStatus)
-{
- if (!pStatusList || !pszStatus)
- return NULL;
-
- for (STATUSINFO *pTemp = pStatusList; pTemp != NULL; pTemp = pTemp->next)
- if (mir_tstrcmpi(pTemp->pszGroup, pszStatus) == 0)
- return pTemp;
-
- return 0;
-}
-
-static WORD TM_StringToWord(STATUSINFO *pStatusList, const TCHAR *pszStatus)
-{
- if (!pStatusList || !pszStatus)
- return 0;
-
- for (STATUSINFO *pTemp = pStatusList; pTemp != NULL; pTemp = pTemp->next) {
- if (mir_tstrcmpi(pTemp->pszGroup, pszStatus) == 0)
- return pTemp->Status;
-
- if (pTemp->next == NULL)
- return pStatusList->Status;
- }
- return 0;
-}
-
-static TCHAR* TM_WordToString(STATUSINFO *pStatusList, WORD Status)
-{
- if (!pStatusList)
- return NULL;
-
- for (STATUSINFO *pTemp = pStatusList; pTemp != NULL; pTemp = pTemp->next) {
- if (pTemp->Status & Status) {
- Status -= pTemp->Status;
- if (Status == 0)
- return pTemp->pszGroup;
- }
- }
- return 0;
-}
-
-static BOOL TM_RemoveAll(STATUSINFO **ppStatusList)
-{
- if (!ppStatusList)
- return FALSE;
-
- while (*ppStatusList != NULL) {
- STATUSINFO *pLast = ppStatusList[0]->next;
- mir_free(ppStatusList[0]->pszGroup);
- if ((int)ppStatusList[0]->hIcon > 10)
- DestroyIcon(ppStatusList[0]->hIcon);
- mir_free(*ppStatusList);
- *ppStatusList = pLast;
- }
- *ppStatusList = NULL;
- return TRUE;
-}
-
-//---------------------------------------------------
-// User manager functions
-//
-// Necessary to keep track of the users
-// in a window nicklist
-//---------------------------------------------------
-
-static int UM_CompareItem(USERINFO *u1, const TCHAR *pszNick, WORD wStatus)
-{
- WORD dw1 = u1->Status;
- WORD dw2 = wStatus;
-
- for (int i = 0; i < 8; i++) {
- if ((dw1 & 1) && !(dw2 & 1))
- return -1;
- if ((dw2 & 1) && !(dw1 & 1))
- return 1;
- if ((dw1 & 1) && (dw2 & 1))
- return mir_tstrcmpi(u1->pszNick, pszNick);
-
- dw1 = dw1 >> 1;
- dw2 = dw2 >> 1;
- }
- return mir_tstrcmpi(u1->pszNick, pszNick);
-}
-
-static USERINFO* UM_SortUser(USERINFO **ppUserList, const TCHAR *pszUID)
-{
- USERINFO *ui = *ppUserList, *pLast = NULL;
- if (!ui || !pszUID)
- return NULL;
-
- while (ui && mir_tstrcmpi(ui->pszUID, pszUID)) {
- pLast = ui;
- ui = ui->next;
- }
-
- if (ui == NULL)
- return NULL;
-
- USERINFO *node = ui;
- if (pLast)
- pLast->next = ui->next;
- else
- *ppUserList = ui->next;
- ui = *ppUserList;
-
- pLast = NULL;
-
- while (ui && ci.UM_CompareItem(ui, node->pszNick, node->Status) <= 0) {
- pLast = ui;
- ui = ui->next;
- }
-
- if (*ppUserList == NULL) { // list is empty
- *ppUserList = node;
- node->next = NULL;
- }
- else {
- if (pLast) {
- node->next = ui;
- pLast->next = node;
- }
- else {
- node->next = *ppUserList;
- *ppUserList = node;
- }
- }
-
- return node;
-}
-
-USERINFO* UM_AddUser(STATUSINFO *pStatusList, USERINFO **ppUserList, const TCHAR *pszUID, const TCHAR *pszNick, WORD wStatus)
-{
- if (pStatusList == NULL || ppUserList == NULL || pszNick == NULL)
- return NULL;
-
- USERINFO *ui = *ppUserList, *pLast = NULL;
- while (ui && ci.UM_CompareItem(ui, pszNick, wStatus) <= 0) {
- pLast = ui;
- ui = ui->next;
- }
-
- // if (!UM_FindUser(*ppUserList, pszUI, wStatus)
- USERINFO *node = (USERINFO*)mir_calloc(sizeof(USERINFO));
- replaceStrT(node->pszUID, pszUID);
-
- if (*ppUserList == NULL) { // list is empty
- *ppUserList = node;
- node->next = NULL;
- }
- else {
- if (pLast) {
- node->next = ui;
- pLast->next = node;
- }
- else {
- node->next = *ppUserList;
- *ppUserList = node;
- }
- }
-
- return node;
-}
-
-static USERINFO* UM_FindUser(USERINFO *pUserList, const TCHAR *pszUID)
-{
- if (!pUserList || !pszUID)
- return NULL;
-
- for (USERINFO *ui = pUserList; ui != NULL; ui = ui->next)
- if (!mir_tstrcmpi(ui->pszUID, pszUID))
- return ui;
-
- return NULL;
-}
-
-static USERINFO* UM_FindUserFromIndex(USERINFO *pUserList, int index)
-{
- if (!pUserList)
- return NULL;
-
- int i = 0;
- for (USERINFO *ui = pUserList; ui != NULL; ui = ui->next) {
- if (i == index)
- return ui;
- i++;
- }
- return NULL;
-}
-
-static USERINFO* UM_GiveStatus(USERINFO *pUserList, const TCHAR *pszUID, WORD status)
-{
- USERINFO *ui = UM_FindUser(pUserList, pszUID);
- if (ui == NULL)
- return NULL;
-
- ui->Status |= status;
- return ui;
-}
-
-static USERINFO* UM_SetContactStatus(USERINFO *pUserList, const TCHAR *pszUID, WORD status)
-{
- USERINFO *ui = UM_FindUser(pUserList, pszUID);
- if (ui == NULL)
- return NULL;
-
- ui->ContactStatus = status;
- return ui;
-}
-
-static BOOL UM_SetStatusEx(USERINFO *pUserList, const TCHAR* pszText, int flags)
-{
- int bOnlyMe = (flags & GC_SSE_ONLYLISTED) != 0, bSetStatus = (flags & GC_SSE_ONLINE) != 0;
- char cDelimiter = (flags & GC_SSE_TABDELIMITED) ? '\t' : ' ';
-
- for (USERINFO *ui = pUserList; ui != NULL; ui = ui->next) {
- if (!bOnlyMe)
- ui->iStatusEx = 0;
-
- if (pszText != NULL) {
- TCHAR *s = (TCHAR *)_tcsstr(pszText, ui->pszUID);
- if (s) {
- ui->iStatusEx = 0;
- if (s == pszText || s[-1] == cDelimiter) {
- size_t len = mir_tstrlen(ui->pszUID);
- if (s[len] == cDelimiter || s[len] == '\0')
- ui->iStatusEx = (!bOnlyMe || bSetStatus) ? 1 : 0;
- }
- }
- }
- }
- return TRUE;
-}
-
-static USERINFO* UM_TakeStatus(USERINFO *pUserList, const TCHAR *pszUID, WORD status)
-{
- USERINFO *ui = UM_FindUser(pUserList, pszUID);
- if (ui == NULL)
- return NULL;
-
- ui->Status &= ~status;
- return ui;
-}
-
-static TCHAR* UM_FindUserAutoComplete(USERINFO *pUserList, const TCHAR* pszOriginal, const TCHAR* pszCurrent)
-{
- if (!pUserList || !pszOriginal || !pszCurrent)
- return NULL;
-
- TCHAR *pszName = NULL;
- for (USERINFO *ui = pUserList; ui != NULL; ui = ui->next)
- if (ui->pszNick && my_strstri(ui->pszNick, pszOriginal) == ui->pszNick)
- if (mir_tstrcmpi(ui->pszNick, pszCurrent) > 0 && (!pszName || mir_tstrcmpi(ui->pszNick, pszName) < 0))
- pszName = ui->pszNick;
-
- return pszName;
-}
-
-static BOOL UM_RemoveUser(USERINFO **ppUserList, const TCHAR *pszUID)
-{
- if (!ppUserList || !pszUID)
- return FALSE;
-
- USERINFO *ui = *ppUserList, *pLast = NULL;
- while (ui != NULL) {
- if (!mir_tstrcmpi(ui->pszUID, pszUID)) {
- if (pLast == NULL)
- *ppUserList = ui->next;
- else
- pLast->next = ui->next;
- mir_free(ui->pszNick);
- mir_free(ui->pszUID);
- mir_free(ui);
- return TRUE;
- }
- pLast = ui;
- ui = ui->next;
- }
- return FALSE;
-}
-
-static BOOL UM_RemoveAll(USERINFO **ppUserList)
-{
- if (!ppUserList)
- return FALSE;
-
- while (*ppUserList != NULL) {
- USERINFO *pLast = ppUserList[0]->next;
- mir_free(ppUserList[0]->pszUID);
- mir_free(ppUserList[0]->pszNick);
- mir_free(*ppUserList);
- *ppUserList = pLast;
- }
- *ppUserList = NULL;
- return TRUE;
-}
-
-//---------------------------------------------------
-// Log manager functions
-//
-// Necessary to keep track of events
-// in a window log
-//---------------------------------------------------
-
-static LOGINFO* LM_AddEvent(LOGINFO **ppLogListStart, LOGINFO** ppLogListEnd)
-{
- if (!ppLogListStart || !ppLogListEnd)
- return NULL;
-
- LOGINFO *node = (LOGINFO*)mir_calloc(sizeof(LOGINFO));
- if (*ppLogListStart == NULL) { // list is empty
- *ppLogListStart = node;
- *ppLogListEnd = node;
- node->next = NULL;
- node->prev = NULL;
- }
- else {
- ppLogListStart[0]->prev = node;
- node->next = *ppLogListStart;
- *ppLogListStart = node;
- ppLogListStart[0]->prev = NULL;
- }
-
- return node;
-}
-
-static BOOL LM_TrimLog(LOGINFO **ppLogListStart, LOGINFO **ppLogListEnd, int iCount)
-{
- LOGINFO *pTemp = *ppLogListEnd;
- while (pTemp != NULL && iCount > 0) {
- *ppLogListEnd = pTemp->prev;
- if (*ppLogListEnd == NULL)
- *ppLogListStart = NULL;
-
- mir_free(pTemp->ptszNick);
- mir_free(pTemp->ptszUserInfo);
- mir_free(pTemp->ptszText);
- mir_free(pTemp->ptszStatus);
- mir_free(pTemp);
- pTemp = *ppLogListEnd;
- iCount--;
- }
- ppLogListEnd[0]->next = NULL;
-
- return TRUE;
-}
-
-static BOOL LM_RemoveAll(LOGINFO **ppLogListStart, LOGINFO **ppLogListEnd)
-{
- while (*ppLogListStart != NULL) {
- LOGINFO *pLast = ppLogListStart[0]->next;
- mir_free(ppLogListStart[0]->ptszText);
- mir_free(ppLogListStart[0]->ptszNick);
- mir_free(ppLogListStart[0]->ptszStatus);
- mir_free(ppLogListStart[0]->ptszUserInfo);
- mir_free(*ppLogListStart);
- *ppLogListStart = pLast;
- }
- *ppLogListStart = NULL;
- *ppLogListEnd = NULL;
- return TRUE;
-}
-
-INT_PTR SvcGetChatManager(WPARAM wParam, LPARAM lParam)
-{
- if (lParam == NULL)
- return (INT_PTR)&ci;
-
- // wipe out old junk
- memset(PBYTE(&ci) + offsetof(CHAT_MANAGER, OnCreateModule), 0, sizeof(CHAT_MANAGER)-offsetof(CHAT_MANAGER, OnCreateModule));
-
- CHAT_MANAGER_INITDATA *pInit = (CHAT_MANAGER_INITDATA*)lParam;
- if (g_cbSession) { // reallocate old sessions
- mir_cslock lck(cs);
- SESSION_INFO *pPrev = NULL;
- for (SESSION_INFO *p = ci.wndList; p; p = p->next) {
- 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 (ci.wndList == p)
- ci.wndList = p1;
- if (pPrev != NULL)
- pPrev->next = p1;
- p = p1;
- }
- pPrev = p;
- }
- }
- if (g_cbModuleInfo) { // reallocate old modules
- mir_cslock lck(cs);
- MODULEINFO *pPrev = NULL;
- for (MODULEINFO *p = m_ModList; p; p = p->next) {
- MODULEINFO *p1 = (MODULEINFO*)mir_realloc(p, 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 != NULL)
- pPrev->next = p1;
- p = p1;
- }
- pPrev = p;
- }
- }
- g_Settings = pInit->pSettings;
- g_szFontGroup = pInit->szFontGroup;
- g_cbSession = pInit->cbSession;
- g_cbModuleInfo = pInit->cbModuleInfo;
- g_iFontMode = pInit->iFontMode;
- g_iChatLang = (int)wParam;
-
- ci.SetActiveSession = SetActiveSession;
- ci.SetActiveSessionEx = SetActiveSessionEx;
- ci.GetActiveSession = GetActiveSession;
- ci.SM_AddSession = SM_AddSession;
- ci.SM_RemoveSession = SM_RemoveSession;
- ci.SM_FindSession = SM_FindSession;
- ci.SM_AddUser = SM_AddUser;
- ci.SM_ChangeUID = SM_ChangeUID;
- ci.SM_ChangeNick = SM_ChangeNick;
- ci.SM_RemoveUser = SM_RemoveUser;
- ci.SM_SetOffline = SM_SetOffline;
- ci.SM_SetTabbedWindowHwnd = SM_SetTabbedWindowHwnd;
- ci.SM_GetStatusIcon = SM_GetStatusIcon;
- ci.SM_SetStatus = SM_SetStatus;
- ci.SM_SetStatusEx = SM_SetStatusEx;
- ci.SM_SendUserMessage = SM_SendUserMessage;
- ci.SM_AddStatus = SM_AddStatus;
- ci.SM_AddEventToAllMatchingUID = SM_AddEventToAllMatchingUID;
- ci.SM_AddEvent = SM_AddEvent;
- ci.SM_SendMessage = SM_SendMessage;
- ci.SM_PostMessage = SM_PostMessage;
- ci.SM_BroadcastMessage = SM_BroadcastMessage;
- ci.SM_RemoveAll = SM_RemoveAll;
- ci.SM_GiveStatus = SM_GiveStatus;
- ci.SM_SetContactStatus = SM_SetContactStatus;
- ci.SM_TakeStatus = SM_TakeStatus;
- ci.SM_MoveUser = SM_MoveUser;
- ci.SM_AddCommand = SM_AddCommand;
- ci.SM_GetPrevCommand = SM_GetPrevCommand;
- ci.SM_GetNextCommand = SM_GetNextCommand;
- ci.SM_GetCount = SM_GetCount;
- ci.SM_FindSessionByIndex = SM_FindSessionByIndex;
- ci.SM_GetUsers = SM_GetUsers;
- ci.SM_GetUserFromIndex = SM_GetUserFromIndex;
- ci.SM_InvalidateLogDirectories = SM_InvalidateLogDirectories;
-
- ci.MM_AddModule = MM_AddModule;
- ci.MM_FindModule = MM_FindModule;
- ci.MM_FixColors = MM_FixColors;
- ci.MM_FontsChanged = MM_FontsChanged;
- ci.MM_IconsChanged = MM_IconsChanged;
- ci.MM_RemoveAll = MM_RemoveAll;
-
- ci.TM_AddStatus = TM_AddStatus;
- ci.TM_FindStatus = TM_FindStatus;
- ci.TM_StringToWord = TM_StringToWord;
- ci.TM_WordToString = TM_WordToString;
- ci.TM_RemoveAll = TM_RemoveAll;
-
- ci.UM_SetStatusEx = UM_SetStatusEx;
- ci.UM_AddUser = UM_AddUser;
- ci.UM_SortUser = UM_SortUser;
- ci.UM_FindUser = UM_FindUser;
- ci.UM_FindUserFromIndex = UM_FindUserFromIndex;
- ci.UM_GiveStatus = UM_GiveStatus;
- ci.UM_SetContactStatus = UM_SetContactStatus;
- ci.UM_TakeStatus = UM_TakeStatus;
- ci.UM_FindUserAutoComplete = UM_FindUserAutoComplete;
- ci.UM_RemoveUser = UM_RemoveUser;
- ci.UM_RemoveAll = UM_RemoveAll;
- ci.UM_CompareItem = UM_CompareItem;
-
- ci.LM_AddEvent = LM_AddEvent;
- ci.LM_TrimLog = LM_TrimLog;
- ci.LM_RemoveAll = LM_RemoveAll;
-
- ci.AddRoom = AddRoom;
- ci.SetOffline = SetOffline;
- ci.SetAllOffline = SetAllOffline;
- ci.AddEvent = AddEvent;
- ci.FindRoom = FindRoom;
- ci.DoRtfToTags = DoRtfToTags;
-
- ci.Log_CreateRTF = Log_CreateRTF;
- ci.Log_CreateRtfHeader = Log_CreateRtfHeader;
- ci.LoadMsgDlgFont = LoadMsgDlgFont;
- ci.MakeTimeStamp = MakeTimeStamp;
-
- ci.DoEventHook = DoEventHook;
- ci.DoEventHookAsync = DoEventHookAsync;
-
- ci.DoSoundsFlashPopupTrayStuff = DoSoundsFlashPopupTrayStuff;
- ci.DoTrayIcon = DoTrayIcon;
- ci.DoPopup = DoPopup;
- ci.ShowPopup = ShowPopup;
- ci.LogToFile = LogToFile;
- ci.GetChatLogsFilename = GetChatLogsFilename;
- ci.GetColorIndex = GetColorIndex;
- ci.Log_SetStyle = Log_SetStyle;
-
- ci.IsHighlighted = IsHighlighted;
- ci.RemoveFormatting = RemoveFormatting;
- ci.ReloadSettings = LoadGlobalSettings;
- ci.ColorChooser = ColorChooser;
-
- ci.pLogIconBmpBits = pLogIconBmpBits;
- ci.logIconBmpSize = logIconBmpSize;
-
- RegisterFonts();
- OptionsInit();
- return (INT_PTR)&ci;
-}
diff --git a/src/modules/chat/tools.cpp b/src/modules/chat/tools.cpp deleted file mode 100644 index b91686d538..0000000000 --- a/src/modules/chat/tools.cpp +++ /dev/null @@ -1,768 +0,0 @@ -/*
-Chat module plugin for Miranda IM
-
-Copyright 2000-12 Miranda IM, 2012-15 Miranda NG project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "chat.h"
-
-int GetRichTextLength(HWND hwnd)
-{
- GETTEXTLENGTHEX gtl;
- gtl.flags = GTL_PRECISE;
- gtl.codepage = CP_ACP;
- return (int)SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static TCHAR szTemp[10000];
-
-TCHAR* RemoveFormatting(const TCHAR *pszWord)
-{
- if (pszWord == NULL)
- return NULL;
-
- TCHAR *d = szTemp;
- size_t cbLen = mir_tstrlen(pszWord);
- if (cbLen > SIZEOF(szTemp))
- cbLen = SIZEOF(szTemp)-1;
-
- for (size_t i = 0; i < cbLen;) {
- if (pszWord[i] == '%') {
- switch (pszWord[i+1]) {
- case '%':
- *d++ = '%';
-
- case 'b':
- case 'u':
- case 'i':
- case 'B':
- case 'U':
- case 'I':
- case 'r':
- case 'C':
- case 'F':
- i += 2;
- continue;
-
- case 'c':
- case 'f':
- i += 4;
- continue;
- }
- }
-
- *d++ = pszWord[i++];
- }
- *d = 0;
-
- return szTemp;
-}
-
-BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce)
-{
- switch (gce->pDest->iType) {
- case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT:
- case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT:
- ci.AddEvent(si->hContact, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE), GC_FAKE_EVENT, 0, TranslateT("%s wants your attention in %s"), gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_MESSAGE:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_MESSAGE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_ACTION:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_ACTION], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_JOIN:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_JOIN], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has joined %s"), gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_PART:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_PART], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has left %s"), gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_QUIT:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_QUIT], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s has disconnected"), gce->ptszNick);
- break;
- case GC_EVENT_NICK:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_NICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText);
- break;
- case GC_EVENT_KICK:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_KICK], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s kicked %s from %s"), gce->ptszStatus, gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_NOTICE:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_NOTICE], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Notice from %s"), gce->ptszNick);
- break;
- case GC_EVENT_TOPIC:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_TOPIC], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Topic change in %s"), si->ptszName);
- break;
- case GC_EVENT_INFORMATION:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_INFO], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("Information in %s"), si->ptszName);
- break;
- case GC_EVENT_ADDSTATUS:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_ADDSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s enables '%s' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName);
- break;
- case GC_EVENT_REMOVESTATUS:
- ci.AddEvent(si->hContact, ci.hIcons[ICON_REMSTATUS], GC_FAKE_EVENT, CLEF_ONLYAFEW, TranslateT("%s disables '%s' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName);
- break;
- }
-
- return TRUE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static void __stdcall ShowRoomFromPopup(void *pi)
-{
- SESSION_INFO *si = (SESSION_INFO*)pi;
- ci.ShowRoom(si, WINDOW_VISIBLE, TRUE);
-}
-
-static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message) {
- case WM_COMMAND:
- if (HIWORD(wParam) == STN_CLICKED) {
- SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd);
- CallFunctionAsync(ShowRoomFromPopup, si);
-
- PUDeletePopup(hWnd);
- return TRUE;
- }
- break;
- case WM_CONTEXTMENU:
- SESSION_INFO *si = (SESSION_INFO*)PUGetPluginData(hWnd);
- if (si->hContact)
- if (CallService(MS_CLIST_GETEVENT, (WPARAM)si->hContact, 0))
- CallService(MS_CLIST_REMOVEEVENT, (WPARAM)si->hContact, (LPARAM)GC_FAKE_EVENT);
-
- if (si->hWnd && KillTimer(si->hWnd, TIMERID_FLASHWND))
- FlashWindow(si->hWnd, FALSE);
-
- PUDeletePopup(hWnd);
- break;
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
-}
-
-int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, TCHAR* pszRoomName, COLORREF crBkg, const TCHAR* fmt, ...)
-{
- static TCHAR szBuf[4 * 1024];
-
- if (!fmt || fmt[0] == 0 || mir_tstrlen(fmt) > 2000)
- return 0;
-
- va_list marker;
- va_start(marker, fmt);
- mir_vsntprintf(szBuf, 4096, fmt, marker);
- va_end(marker);
-
- POPUPDATAT pd = { 0 };
- pd.lchContact = hContact;
-
- if (hIcon)
- pd.lchIcon = hIcon;
- else
- pd.lchIcon = LoadIconEx("window", FALSE);
-
- PROTOACCOUNT *pa = ProtoGetAccount(pszProtoName);
- mir_sntprintf(pd.lptzContactName, SIZEOF(pd.lptzContactName), _T("%s - %s"),
- (pa == NULL) ? _A2T(pszProtoName) : pa->tszAccountName,
- cli.pfnGetContactDisplayName(hContact, 0));
-
- mir_tstrncpy(pd.lptzText, TranslateTS(szBuf), SIZEOF(pd.lptzText));
- pd.iSeconds = g_Settings->iPopupTimeout;
-
- if (g_Settings->iPopupStyle == 2) {
- pd.colorBack = 0;
- pd.colorText = 0;
- }
- else if (g_Settings->iPopupStyle == 3) {
- pd.colorBack = g_Settings->crPUBkgColour;
- pd.colorText = g_Settings->crPUTextColour;
- }
- else {
- pd.colorBack = g_Settings->crLogBackground;
- pd.colorText = crBkg;
- }
-
- pd.PluginWindowProc = PopupDlgProc;
- pd.PluginData = si;
- return PUAddPopupT(&pd);
-}
-
-BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce)
-{
- switch (gce->pDest->iType) {
- case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT:
- ci.ShowPopup(si->hContact, si, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, ci.aFonts[16].color, TranslateT("%s says: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT:
- ci.ShowPopup(si->hContact, si, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, ci.aFonts[16].color, _T("%s %s"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_MESSAGE:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, ci.aFonts[9].color, TranslateT("%s says: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_ACTION:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_ACTION], si->pszModule, si->ptszName, ci.aFonts[15].color, _T("%s %s"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_JOIN:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_JOIN], si->pszModule, si->ptszName, ci.aFonts[3].color, TranslateT("%s has joined"), gce->ptszNick);
- break;
- case GC_EVENT_PART:
- if (!gce->ptszText)
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_PART], si->pszModule, si->ptszName, ci.aFonts[4].color, TranslateT("%s has left"), gce->ptszNick);
- else
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_PART], si->pszModule, si->ptszName, ci.aFonts[4].color, TranslateT("%s has left (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_QUIT:
- if (!gce->ptszText)
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_QUIT], si->pszModule, si->ptszName, ci.aFonts[5].color, TranslateT("%s has disconnected"), gce->ptszNick);
- else
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_QUIT], si->pszModule, si->ptszName, ci.aFonts[5].color, TranslateT("%s has disconnected (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_NICK:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_NICK], si->pszModule, si->ptszName, ci.aFonts[7].color, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText);
- break;
- case GC_EVENT_KICK:
- if (!gce->ptszText)
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_KICK], si->pszModule, si->ptszName, ci.aFonts[6].color, TranslateT("%s kicked %s"), (char *)gce->ptszStatus, gce->ptszNick);
- else
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_KICK], si->pszModule, si->ptszName, ci.aFonts[6].color, TranslateT("%s kicked %s (%s)"), (char *)gce->ptszStatus, gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_NOTICE:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_NOTICE], si->pszModule, si->ptszName, ci.aFonts[8].color, TranslateT("Notice from %s: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_TOPIC:
- if (!gce->ptszNick)
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, ci.aFonts[11].color, TranslateT("The topic is '%s'"), RemoveFormatting(gce->ptszText));
- else
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, ci.aFonts[11].color, TranslateT("The topic is '%s' (set by %s)"), RemoveFormatting(gce->ptszText), gce->ptszNick);
- break;
- case GC_EVENT_INFORMATION:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_INFO], si->pszModule, si->ptszName, ci.aFonts[12].color, _T("%s"), RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_ADDSTATUS:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_ADDSTATUS], si->pszModule, si->ptszName, ci.aFonts[13].color, TranslateT("%s enables '%s' status for %s"), gce->ptszText, (char *)gce->ptszStatus, gce->ptszNick);
- break;
- case GC_EVENT_REMOVESTATUS:
- ci.ShowPopup(si->hContact, si, ci.hIcons[ICON_REMSTATUS], si->pszModule, si->ptszName, ci.aFonts[14].color, TranslateT("%s disables '%s' status for %s"), gce->ptszText, (char *)gce->ptszStatus, gce->ptszNick);
- break;
- }
-
- return TRUE;
-}
-
-BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix)
-{
- if (!gce || !si || gce->bIsMe || si->iType == GCW_SERVER)
- return FALSE;
-
- BOOL bInactive = si->hWnd == NULL || GetForegroundWindow() != si->hWnd;
-
- int iEvent = gce->pDest->iType;
-
- if (bHighlight) {
- gce->pDest->iType |= GC_EVENT_HIGHLIGHT;
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatHighlight");
- if (db_get_b(si->hContact, "CList", "Hidden", 0) != 0)
- db_unset(si->hContact, "CList", "Hidden");
- if (bInactive)
- ci.DoTrayIcon(si, gce);
- if (bInactive || !g_Settings->bPopupInactiveOnly)
- ci.DoPopup(si, gce);
- if (ci.OnFlashHighlight)
- ci.OnFlashHighlight(si, bInactive);
- return TRUE;
- }
-
- // do blinking icons in tray
- if (bInactive || !g_Settings->bTrayIconInactiveOnly)
- ci.DoTrayIcon(si, gce);
-
- // stupid thing to not create multiple popups for a QUIT event for instance
- if (bManyFix == 0) {
- // do popups
- if (bInactive || !g_Settings->bPopupInactiveOnly)
- ci.DoPopup(si, gce);
-
- // do sounds and flashing
- switch (iEvent) {
- case GC_EVENT_JOIN:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatJoin");
- break;
- case GC_EVENT_PART:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatPart");
- break;
- case GC_EVENT_QUIT:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatQuit");
- break;
- case GC_EVENT_ADDSTATUS:
- case GC_EVENT_REMOVESTATUS:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatMode");
- break;
- case GC_EVENT_KICK:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatKick");
- break;
- case GC_EVENT_MESSAGE:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatMessage");
-
- if (bInactive && !(si->wState & STATE_TALK)) {
- si->wState |= STATE_TALK;
- db_set_w(si->hContact, si->pszModule, "ApparentMode", ID_STATUS_OFFLINE);
- }
- if (ci.OnFlashWindow)
- ci.OnFlashWindow(si, bInactive);
- break;
- case GC_EVENT_ACTION:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatAction");
- break;
- case GC_EVENT_NICK:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatNick");
- break;
- case GC_EVENT_NOTICE:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatNotice");
- break;
- case GC_EVENT_TOPIC:
- if (bInactive || !g_Settings->bSoundsFocus)
- SkinPlaySound("ChatTopic");
- break;
- }
- }
-
- return TRUE;
-}
-
-int GetColorIndex(const char *pszModule, COLORREF cr)
-{
- MODULEINFO *pMod = ci.MM_FindModule(pszModule);
- int i = 0;
-
- if (!pMod || pMod->nColorCount == 0)
- return -1;
-
- for (i = 0; i < pMod->nColorCount; i++)
- if (pMod->crColors[i] == cr)
- return i;
-
- return -1;
-}
-
-// obscure function that is used to make sure that any of the colors
-// passed by the protocol is used as fore- or background color
-// in the messagebox. THis is to vvercome limitations in the richedit
-// that I do not know currently how to fix
-
-void CheckColorsInModule(const char *pszModule)
-{
- MODULEINFO *pMod = ci.MM_FindModule(pszModule);
- int i = 0;
- COLORREF crFG;
- COLORREF crBG = (COLORREF)db_get_dw(NULL, CHAT_MODULE, "ColorMessageBG", GetSysColor(COLOR_WINDOW));
-
- LoadMsgDlgFont(17, NULL, &crFG);
-
- if (!pMod)
- return;
-
- for (i = 0; i < pMod->nColorCount; i++) {
- if (pMod->crColors[i] == crFG || pMod->crColors[i] == crBG) {
- if (pMod->crColors[i] == RGB(255, 255, 255))
- pMod->crColors[i]--;
- else
- pMod->crColors[i]++;
- }
- }
-}
-
-const TCHAR* my_strstri(const TCHAR* s1, const TCHAR* s2)
-{
- int i, j, k;
- for (i = 0; s1[i]; i++)
- for (j = i, k = 0; _totlower(s1[j]) == _totlower(s2[k]); j++, k++)
- if (!s2[k + 1])
- return s1 + i;
-
- return NULL;
-}
-
-static TCHAR szTrimString[] = _T(":,.!?;\'>)");
-
-BOOL IsHighlighted(SESSION_INFO *si, GCEVENT *gce)
-{
- if (!g_Settings->bHighlightEnabled || !g_Settings->pszHighlightWords || !gce || !si || !si->pMe)
- return FALSE;
-
- if (gce->ptszText == NULL)
- return FALSE;
-
- TCHAR *buf = RemoveFormatting(NEWTSTR_ALLOCA(gce->ptszText));
-
- int iStart = 0;
- CMString tszHighlightWords(g_Settings->pszHighlightWords);
-
- while (true) {
- CMString tszToken = tszHighlightWords.Tokenize(_T("\t "), iStart);
- if (iStart == -1)
- break;
-
- // replace %m with the users nickname
- if (tszToken == _T("%m"))
- tszToken = si->pMe->pszNick;
-
- if (tszToken.Find('*') == -1)
- tszToken = '*' + tszToken + '*';
-
- // time to get the next/first word in the incoming text string
- for (const TCHAR *p = buf; *p != '\0'; p += _tcscspn(p, _T(" "))) {
- p += _tcsspn(p, _T(" "));
-
- // compare the words, using wildcards
- if (wildcmpit(RemoveFormatting(p), tszToken))
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce)
-{
- TCHAR szBuffer[4096];
- TCHAR szLine[4096];
- TCHAR p = '\0';
- szBuffer[0] = '\0';
-
- GetChatLogsFilename(si, gce->time);
- BOOL bFileJustCreated = !PathFileExists(si->pszLogFileName);
-
- TCHAR tszFolder[MAX_PATH];
- _tcsncpy_s(tszFolder, si->pszLogFileName, _TRUNCATE);
- PathRemoveFileSpec(tszFolder);
- if (!PathIsDirectory(tszFolder))
- CreateDirectoryTreeT(tszFolder);
-
- TCHAR szTime[100];
- mir_tstrncpy(szTime, ci.MakeTimeStamp(g_Settings->pszTimeStampLog, gce->time), 99);
-
- FILE *hFile = _tfopen(si->pszLogFileName, _T("ab+"));
- if (hFile == NULL)
- return FALSE;
-
- TCHAR szTemp[512], szTemp2[512];
- TCHAR* pszNick = NULL;
- if (bFileJustCreated)
- fputws((const wchar_t*)"\377\376", hFile); //UTF-16 LE BOM == FF FE
- if (gce->ptszNick) {
- if (g_Settings->bLogLimitNames && mir_tstrlen(gce->ptszNick) > 20) {
- mir_tstrncpy(szTemp2, gce->ptszNick, 20);
- mir_tstrncpy(szTemp2 + 20, _T("..."), 4);
- }
- else mir_tstrncpy(szTemp2, gce->ptszNick, 511);
-
- if (gce->ptszUserInfo)
- mir_sntprintf(szTemp, _T("%s (%s)"), szTemp2, gce->ptszUserInfo);
- else
- _tcsncpy_s(szTemp, szTemp2, _TRUNCATE);
- pszNick = szTemp;
- }
-
- switch (gce->pDest->iType) {
- case GC_EVENT_MESSAGE:
- case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT:
- p = '*';
- mir_sntprintf(szBuffer, _T("%s: %s"), gce->ptszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_ACTION:
- case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT:
- p = '*';
- mir_sntprintf(szBuffer, _T("%s %s"), gce->ptszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_JOIN:
- p = '>';
- mir_sntprintf(szBuffer, TranslateT("%s has joined"), pszNick);
- break;
- case GC_EVENT_PART:
- p = '<';
- if (!gce->ptszText)
- mir_sntprintf(szBuffer, TranslateT("%s has left"), pszNick);
- else
- mir_sntprintf(szBuffer, TranslateT("%s has left (%s)"), pszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_QUIT:
- p = '<';
- if (!gce->ptszText)
- mir_sntprintf(szBuffer, TranslateT("%s has disconnected"), pszNick);
- else
- mir_sntprintf(szBuffer, TranslateT("%s has disconnected (%s)"), pszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_NICK:
- p = '^';
- mir_sntprintf(szBuffer, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText);
- break;
- case GC_EVENT_KICK:
- p = '~';
- if (!gce->ptszText)
- mir_sntprintf(szBuffer, TranslateT("%s kicked %s"), gce->ptszStatus, gce->ptszNick);
- else
- mir_sntprintf(szBuffer, TranslateT("%s kicked %s (%s)"), gce->ptszStatus, gce->ptszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_NOTICE:
- p = 'o';
- mir_sntprintf(szBuffer, TranslateT("Notice from %s: %s"), gce->ptszNick, ci.RemoveFormatting(gce->ptszText));
- break;
- case GC_EVENT_TOPIC:
- p = '#';
- if (!gce->ptszNick)
- mir_sntprintf(szBuffer, TranslateT("The topic is '%s'"), ci.RemoveFormatting(gce->ptszText));
- else
- mir_sntprintf(szBuffer, TranslateT("The topic is '%s' (set by %s)"), ci.RemoveFormatting(gce->ptszText), gce->ptszNick);
- break;
- case GC_EVENT_INFORMATION:
- p = '!';
- _tcsncpy_s(szBuffer, ci.RemoveFormatting(gce->ptszText), _TRUNCATE);
- break;
- case GC_EVENT_ADDSTATUS:
- p = '+';
- mir_sntprintf(szBuffer, TranslateT("%s enables '%s' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick);
- break;
- case GC_EVENT_REMOVESTATUS:
- p = '-';
- mir_sntprintf(szBuffer, TranslateT("%s disables '%s' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick);
- break;
- }
-
- // formatting strings don't need to be translatable - changing them via language pack would
- // only screw up the log format.
- if (p)
- mir_sntprintf(szLine, SIZEOF(szLine), _T("%s %c %s\r\n"), szTime, p, szBuffer);
- else
- mir_sntprintf(szLine, SIZEOF(szLine), _T("%s %s\r\n"), szTime, szBuffer);
-
- if (szLine[0]) {
- _fputts(szLine, hFile);
-
- if (g_Settings->LoggingLimit > 0) {
- fseek(hFile, 0, SEEK_END);
- long dwSize = ftell(hFile);
- rewind(hFile);
-
- long trimlimit = g_Settings->LoggingLimit * 1024;
- if (dwSize > trimlimit) {
- time_t now = time(0);
-
- TCHAR tszTimestamp[20];
- _tcsftime(tszTimestamp, 20, _T("%Y%m%d-%H%M%S"), _localtime32((__time32_t *)&now));
- tszTimestamp[19] = 0;
-
- // max size reached, rotate the log
- // move old logs to /archived sub folder just inside the log root folder.
- // add a time stamp to the file name.
- TCHAR tszDrive[_MAX_DRIVE], tszDir[_MAX_DIR], tszName[_MAX_FNAME], tszExt[_MAX_EXT];
- _tsplitpath(si->pszLogFileName, tszDrive, tszDir, tszName, tszExt);
-
- TCHAR tszNewPath[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20];
- mir_sntprintf(tszNewPath, SIZEOF(tszNewPath), _T("%s%sarchived\\"), tszDrive, tszDir);
- CreateDirectoryTreeT(tszNewPath);
-
- TCHAR tszNewName[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20];
- mir_sntprintf(tszNewName, SIZEOF(tszNewName), _T("%s%s-%s%s"), tszNewPath, tszName, tszTimestamp, tszExt);
- fclose(hFile);
- hFile = 0;
- if (!PathFileExists(tszNewName))
- CopyFile(si->pszLogFileName, tszNewName, TRUE);
- DeleteFile(si->pszLogFileName);
- }
- }
- }
-
- if (hFile)
- fclose(hFile);
- return TRUE;
-}
-
-BOOL DoEventHookAsync(HWND hwnd, const TCHAR *pszID, const char *pszModule, int iType, const TCHAR* pszUID, const TCHAR* pszText, INT_PTR dwItem)
-{
- SESSION_INFO *si = ci.SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- GCDEST *gcd = (GCDEST*)mir_calloc(sizeof(GCDEST));
- gcd->pszModule = mir_strdup(pszModule);
- gcd->ptszID = mir_tstrdup(pszID);
- gcd->iType = iType;
-
- GCHOOK *gch = (GCHOOK*)mir_calloc(sizeof(GCHOOK));
- gch->ptszUID = mir_tstrdup(pszUID);
- gch->ptszText = mir_tstrdup(pszText);
- gch->dwData = dwItem;
- gch->pDest = gcd;
- PostMessage(hwnd, GC_FIREHOOK, 0, (LPARAM)gch);
- return TRUE;
-}
-
-BOOL DoEventHook(const TCHAR *pszID, const char *pszModule, int iType, const TCHAR *pszUID, const TCHAR* pszText, INT_PTR dwItem)
-{
- SESSION_INFO *si = ci.SM_FindSession(pszID, pszModule);
- if (si == NULL)
- return FALSE;
-
- GCDEST gcd = { (char*)pszModule, pszID, iType };
- GCHOOK gch = { 0 };
- gch.ptszUID = (LPTSTR)pszUID;
- gch.ptszText = (LPTSTR)pszText;
- gch.dwData = dwItem;
- gch.pDest = &gcd;
- NotifyEventHooks(ci.hSendEvent, 0, (WPARAM)&gch);
- return TRUE;
-}
-
-BOOL IsEventSupported(int eventType)
-{
- // Supported events
- switch (eventType) {
- case GC_EVENT_JOIN:
- case GC_EVENT_PART:
- case GC_EVENT_QUIT:
- case GC_EVENT_KICK:
- case GC_EVENT_NICK:
- case GC_EVENT_NOTICE:
- case GC_EVENT_MESSAGE:
- case GC_EVENT_TOPIC:
- case GC_EVENT_INFORMATION:
- case GC_EVENT_ACTION:
- case GC_EVENT_ADDSTATUS:
- case GC_EVENT_REMOVESTATUS:
- case GC_EVENT_CHUID:
- case GC_EVENT_CHANGESESSIONAME:
- case GC_EVENT_ADDGROUP:
- case GC_EVENT_SETITEMDATA:
- case GC_EVENT_GETITEMDATA:
- case GC_EVENT_SETSBTEXT:
- case GC_EVENT_ACK:
- case GC_EVENT_SENDMESSAGE:
- case GC_EVENT_SETSTATUSEX:
- case GC_EVENT_CONTROL:
- case GC_EVENT_SETCONTACTSTATUS:
- return TRUE;
- }
-
- // Other events
- return FALSE;
-}
-
-void ValidateFilename(TCHAR *filename)
-{
- TCHAR *p1 = filename;
- TCHAR szForbidden[] = _T("\\/:*?\"<>|");
- while (*p1 != '\0') {
- if (_tcschr(szForbidden, *p1))
- *p1 = '_';
- p1 += 1;
- }
-}
-
-static TCHAR tszOldTimeStamp[30];
-
-TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime)
-{
- if (!tTime)
- time(&tTime);
-
- // check whether relevant parts of the timestamp have changed and
- // we have to reparse the filename
- TCHAR *tszNow = ci.MakeTimeStamp(_T("%a%d%m%Y"), tTime); // once a day
- if (mir_tstrcmp(tszOldTimeStamp, tszNow)) {
- _tcsncpy_s(tszOldTimeStamp, tszNow, _TRUNCATE);
- *si->pszLogFileName = 0;
- }
-
- if (si->pszLogFileName[0] == 0) {
- REPLACEVARSARRAY rva[11];
- rva[0].lptzKey = _T("d");
- rva[0].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%#d"), tTime));
- // day 01-31
- rva[1].lptzKey = _T("dd");
- rva[1].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%d"), tTime));
- // month 1-12
- rva[2].lptzKey = _T("m");
- rva[2].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%#m"), tTime));
- // month 01-12
- rva[3].lptzKey = _T("mm");
- rva[3].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%m"), tTime));
- // month text short
- rva[4].lptzKey = _T("mon");
- rva[4].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%b"), tTime));
- // month text
- rva[5].lptzKey = _T("month");
- rva[5].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%B"), tTime));
- // year 01-99
- rva[6].lptzKey = _T("yy");
- rva[6].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%y"), tTime));
- // year 1901-9999
- rva[7].lptzKey = _T("yyyy");
- rva[7].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%Y"), tTime));
- // weekday short
- rva[8].lptzKey = _T("wday");
- rva[8].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%a"), tTime));
- // weekday
- rva[9].lptzKey = _T("weekday");
- rva[9].lptzValue = mir_tstrdup(ci.MakeTimeStamp(_T("%A"), tTime));
- // end of array
- rva[10].lptzKey = NULL;
- rva[10].lptzValue = NULL;
-
- TCHAR tszTemp[MAX_PATH], *ptszVarPath;
- if (g_Settings->pszLogDir[mir_tstrlen(g_Settings->pszLogDir) - 1] == '\\') {
- mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%s%s"), g_Settings->pszLogDir, _T("%userid%.log"));
- ptszVarPath = tszTemp;
- }
- else ptszVarPath = g_Settings->pszLogDir;
-
- REPLACEVARSDATA dat = { sizeof(dat) };
- dat.dwFlags = RVF_TCHAR;
- dat.hContact = si->hContact;
- dat.variables = rva;
- TCHAR *tszParsedName = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)ptszVarPath, (LPARAM)&dat);
- if (ci.OnGetLogName)
- ci.OnGetLogName(si, tszParsedName);
- else
- PathToAbsoluteT(tszParsedName, si->pszLogFileName);
- mir_free(tszParsedName);
-
- for (int i = 0; i < SIZEOF(rva); i++)
- mir_free(rva[i].lptzValue);
-
- for (TCHAR *p = si->pszLogFileName + 2; *p; ++p)
- if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|')
- *p = _T('_');
- }
-
- return si->pszLogFileName;
-}
|