summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-24 12:13:13 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-24 12:13:13 +0300
commit0021960123579809c02d4560ae9aee5b26008f52 (patch)
tree1d76582581cb967574167b0d728c42aeb7a59fd4 /src
parented8bdca0a0b72341faab25040b09c6f28110f127 (diff)
similar code reduced
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/chat_log.cpp72
-rw-r--r--src/mir_app/src/chat_manager.cpp48
-rw-r--r--src/mir_app/src/mir_app.def7
-rw-r--r--src/mir_app/src/mir_app64.def7
4 files changed, 74 insertions, 60 deletions
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp
index 60a68c78cf..45e59c666f 100644
--- a/src/mir_app/src/chat_log.cpp
+++ b/src/mir_app/src/chat_log.cpp
@@ -30,54 +30,6 @@ char *pLogIconBmpBits[14];
#define RTFCACHELINESIZE 128
static char CHAT_rtfFontsGlobal[OPTIONS_FONTCOUNT][RTFCACHELINESIZE];
-static int EventToIndex(const 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(const 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)
@@ -129,7 +81,7 @@ static int Log_AppendRTF(RtfChatLogStreamData *streamData, const LOGINFO &lin, b
case 'C':
case 'F':
if (!g_Settings->bStripFormat && !streamData->bStripFormat) {
- int j = lin.bIsHighlighted ? 16 : EventToIndex(lin);
+ int j = lin.bIsHighlighted ? 16 : lin.getIndex();
if (*line == 'C')
mir_snprintf(szTemp, "\\cf%u ", j + 1);
else
@@ -153,10 +105,8 @@ static int Log_AppendRTF(RtfChatLogStreamData *streamData, const LOGINFO &lin, b
break;
case 'r':
- if (!streamData->bStripFormat) {
- int index = EventToIndex(lin);
- mir_snprintf(szTemp, "%s ", Log_SetStyle(index));
- }
+ if (!streamData->bStripFormat)
+ mir_snprintf(szTemp, "%s ", Log_SetStyle(lin.getIndex()));
break;
}
@@ -385,7 +335,7 @@ void CRtfLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const L
// 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);
+ int iIndex = (lin.bIsHighlighted && (g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT)) ? ICON_HIGHLIGHT : lin.getIcon();
buf.Append("\\f0\\fs14");
buf.Append(pLogIconBmpBits[iIndex]);
}
@@ -399,7 +349,7 @@ void CRtfLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const L
buf.AppendFormat("\\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 / g_chatApi.logPixelSY);
}
else {
- int iii = lin.bIsHighlighted ? 16 : EventToIndex(lin);
+ int iii = lin.bIsHighlighted ? 16 : lin.getIndex();
buf.AppendFormat("\\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 / g_chatApi.logPixelSY);
}
}
@@ -432,12 +382,22 @@ void CRtfLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const L
}
// Insert the message
- buf.AppendFormat("%s ", Log_SetStyle(lin.bIsHighlighted ? 16 : EventToIndex(lin)));
+ CreateChatRtfMessage(streamData, lin, buf);
+
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Chat event message
+
+void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const LOGINFO &lin, CMStringA &buf)
+{
+ buf.AppendFormat("%s ", Log_SetStyle(lin.bIsHighlighted ? 16 : lin.getIndex()));
CMStringW wszCaption;
bool bTextUsed = Chat_GetDefaultEventDescr(streamData->si, &lin, wszCaption);
if (!wszCaption.IsEmpty())
Log_AppendRTF(streamData, lin, !bTextUsed, buf, wszCaption);
+
if (!bTextUsed && lin.ptszText) {
if (!wszCaption.IsEmpty())
Log_AppendRTF(streamData, lin, false, buf, L" ");
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp
index eb0de25e12..be8ede8b01 100644
--- a/src/mir_app/src/chat_manager.cpp
+++ b/src/mir_app/src/chat_manager.cpp
@@ -73,6 +73,54 @@ LOGINFO::~LOGINFO()
{
}
+int LOGINFO::getIndex() const
+{
+ switch (iType) {
+ case GC_EVENT_MESSAGE:
+ if (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;
+}
+
+int LOGINFO::getIcon() const
+{
+ switch (iType) {
+ case GC_EVENT_MESSAGE:
+ if (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;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Session Manager functions
// Keeps track of all sessions and its windows
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 4e24c3be80..85a560255c 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -852,11 +852,14 @@ Chat_IsMuted @941 NONAME
?GetDialog@CSrmmLogWindow@@QBEAAVCMsgDialog@@XZ @969 NONAME
?isHistory@EventInfo@DB@@QBE_NXZ @970 NONAME
?isSrmm@EventInfo@DB@@QBE_NXZ @971 NONAME
-?CreateRtfTail@CRtfLogWindow@@UAEXPAURtfLogStreamData@@@Z @972 NONAME
+?CreateRtfTail@CRtfLogWindow@@QAEXPAURtfLogStreamData@@@Z @972 NONAME
?StreamRtfEvents@CRtfLogWindow@@QAEXPAURtfLogStreamData@@_N@Z @973 NONAME
?CreateChatRtfEvent@CRtfLogWindow@@UAEXPAURtfChatLogStreamData@@ABULOGINFO@@@Z @974 NONAME
?CreateChatRtfHeader@CRtfLogWindow@@UAEXPAURtfChatLogStreamData@@@Z @975 NONAME
-?CreateChatRtfTail@CRtfLogWindow@@UAEXPAURtfChatLogStreamData@@@Z @976 NONAME
+?CreateChatRtfTail@CRtfLogWindow@@QAEXPAURtfChatLogStreamData@@@Z @976 NONAME
?StreamChatRtfEvents@CRtfLogWindow@@QAEXPAURtfChatLogStreamData@@_N@Z @977 NONAME
??0LOGINFO@@QAE@PBUGCEVENT@@@Z @978 NONAME
??1LOGINFO@@QAE@XZ @979 NONAME
+?CreateChatRtfMessage@CRtfLogWindow@@QAEXPAURtfChatLogStreamData@@ABULOGINFO@@AAV?$CMStringT@DV?$ChTraitsCRT@D@@@@@Z @980 NONAME
+?getIcon@LOGINFO@@QBEHXZ @981 NONAME
+?getIndex@LOGINFO@@QBEHXZ @982 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 1cb5054e48..8fae93a9fd 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -852,11 +852,14 @@ Chat_IsMuted @941 NONAME
?GetDialog@CSrmmLogWindow@@QEBAAEAVCMsgDialog@@XZ @969 NONAME
?isHistory@EventInfo@DB@@QEBA_NXZ @970 NONAME
?isSrmm@EventInfo@DB@@QEBA_NXZ @971 NONAME
-?CreateRtfTail@CRtfLogWindow@@UEAAXPEAURtfLogStreamData@@@Z @972 NONAME
+?CreateRtfTail@CRtfLogWindow@@QEAAXPEAURtfLogStreamData@@@Z @972 NONAME
?StreamRtfEvents@CRtfLogWindow@@QEAAXPEAURtfLogStreamData@@_N@Z @973 NONAME
?CreateChatRtfEvent@CRtfLogWindow@@UEAAXPEAURtfChatLogStreamData@@AEBULOGINFO@@@Z @974 NONAME
?CreateChatRtfHeader@CRtfLogWindow@@UEAAXPEAURtfChatLogStreamData@@@Z @975 NONAME
-?CreateChatRtfTail@CRtfLogWindow@@UEAAXPEAURtfChatLogStreamData@@@Z @976 NONAME
+?CreateChatRtfTail@CRtfLogWindow@@QEAAXPEAURtfChatLogStreamData@@@Z @976 NONAME
?StreamChatRtfEvents@CRtfLogWindow@@QEAAXPEAURtfChatLogStreamData@@_N@Z @977 NONAME
??0LOGINFO@@QEAA@PEBUGCEVENT@@@Z @978 NONAME
??1LOGINFO@@QEAA@XZ @979 NONAME
+?CreateChatRtfMessage@CRtfLogWindow@@QEAAXPEAURtfChatLogStreamData@@AEBULOGINFO@@AEAV?$CMStringT@DV?$ChTraitsCRT@D@@@@@Z @980 NONAME
+?getIcon@LOGINFO@@QEBAHXZ @981 NONAME
+?getIndex@LOGINFO@@QEBAHXZ @982 NONAME