From 12a21d5cdf92fcefe8283af5392d4c5358f900e7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Sep 2024 20:38:14 +0300 Subject: two atavisms with old chat engine formatting removed --- include/m_chat_int.h | 1 - plugins/NewStory/src/history_array.cpp | 2 +- plugins/TabSRMM/src/chat_tools.cpp | 2 +- plugins/TabSRMM/src/muchighlight.cpp | 3 +- src/mir_app/src/chat.h | 1 - src/mir_app/src/chat_loginfo.cpp | 11 +++---- src/mir_app/src/chat_manager.cpp | 1 - src/mir_app/src/chat_svc.cpp | 33 ++++++++++----------- src/mir_app/src/chat_tools.cpp | 53 ++-------------------------------- 9 files changed, 27 insertions(+), 80 deletions(-) diff --git a/include/m_chat_int.h b/include/m_chat_int.h index c5f0d163f2..599218c258 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -305,7 +305,6 @@ struct CHAT_MANAGER char* (*Log_SetStyle)(int style); bool (*IsHighlighted)(SESSION_INFO *si, GCEVENT *pszText); - wchar_t* (*RemoveFormatting)(const wchar_t *pszText); void (*ReloadSettings)(void); void (*CreateNick)(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &dest); diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index dff781605f..d4e2cf5634 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -520,7 +520,7 @@ void HistoryArray::addChatEvent(NewstoryListData *pOwner, SESSION_INFO *si, cons if (!bTextUsed && lin->ptszText) { if (!wszText.IsEmpty()) wszText.AppendChar(' '); - wszText.Append(g_chatApi.RemoveFormatting(lin->ptszText)); + wszText.Append(lin->ptszText); } p.wtext = wszText.Detach(); diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index e09c6ff4a0..31682a5f0e 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -184,7 +184,7 @@ passed: if (iNewEvent == GC_EVENT_MESSAGE) { ShowPopup(si->hContact, si, g_chatApi.getIcon(GC_EVENT_MESSAGE), si->pszModule, si->ptszName, clr ? clr : g_chatApi.aFonts[9].color, - L"%s%s:%s %s", bbStart, gce->pszNick.w, bbEnd, g_chatApi.RemoveFormatting(gce->pszText.w)); + L"%s%s:%s %s", bbStart, gce->pszNick.w, bbEnd, gce->pszText.w); } else oldDoPopup(si, gce); diff --git a/plugins/TabSRMM/src/muchighlight.cpp b/plugins/TabSRMM/src/muchighlight.cpp index 0e34837673..7f35c72039 100644 --- a/plugins/TabSRMM/src/muchighlight.cpp +++ b/plugins/TabSRMM/src/muchighlight.cpp @@ -117,8 +117,7 @@ bool CMUCHighlight::match(const GCEVENT *pgce, const SESSION_INFO *psi, uint32_t return false; if ((m_iMode & MATCH_TEXT) && (dwFlags & MATCH_TEXT) && (m_fHighlightMe || m_iTextPatterns > 0) && psi != nullptr) { - wchar_t *p = g_chatApi.RemoveFormatting(pgce->pszText.w); - p = NEWWSTR_ALLOCA(p); + wchar_t *p = NEWWSTR_ALLOCA(pgce->pszText.w); if (p == nullptr) return false; CharLower(p); diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 430c694e8c..9b2564bad0 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -120,7 +120,6 @@ void UnloadChatModule(void); // tools.c int DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pColors); -wchar_t* RemoveFormatting(const wchar_t* pszText); BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); int GetRichTextLength(HWND hwnd); bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); diff --git a/src/mir_app/src/chat_loginfo.cpp b/src/mir_app/src/chat_loginfo.cpp index fff834d8d0..2a72a77e32 100644 --- a/src/mir_app/src/chat_loginfo.cpp +++ b/src/mir_app/src/chat_loginfo.cpp @@ -96,13 +96,9 @@ void LOGINFO::write(RtfChatLogStreamData *streamData, bool simpleMode, CMStringA else if (*line == '\n') { buf.Append("\\line "); } + /* else if (*line == '%' && !simpleMode) { switch (*++line) { - case '\0': - case '%': - buf.AppendChar('%'); - break; - case 'c': case 'f': if (g_Settings->bStripFormat || streamData->bStripFormat) @@ -149,8 +145,13 @@ void LOGINFO::write(RtfChatLogStreamData *streamData, bool simpleMode, CMStringA if (!streamData->bStripFormat) buf.AppendFormat("%s ", Log_SetStyle(getIndex())); break; + + default: + buf.AppendChar('%'); + break; } } + */ else if (*line == '\t' && !streamData->bStripFormat) { buf.Append("\\tab "); } diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 07e53b5969..cf3dcfba39 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -787,7 +787,6 @@ static void ResetApi() g_chatApi.CreateNick = ::CreateNick; g_chatApi.IsHighlighted = ::IsHighlighted; - g_chatApi.RemoveFormatting = ::RemoveFormatting; g_chatApi.ReloadSettings = ::LoadGlobalSettings; } diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index 2bf0745e90..ec7b44be06 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -462,27 +462,24 @@ static BOOL HandleChatEvent(GCEVENT &gce, int bManyFix) return SM_SetContactStatus(si, gce.pszUID.w, (uint16_t)gce.dwItemData); case GC_EVENT_TOPIC: - { - wchar_t *pwszNew = RemoveFormatting(gce.pszText.w); - if (!mir_wstrcmp(si->ptszTopic, pwszNew)) // nothing changed? exiting - return 0; + if (!mir_wstrcmp(si->ptszTopic, gce.pszText.w)) // nothing changed? exiting + return 0; - si->bIsDirty = true; - replaceStrW(si->ptszTopic, pwszNew); - if (pwszNew != nullptr) - db_set_ws(si->hContact, si->pszModule, "Topic", si->ptszTopic); - else - db_unset(si->hContact, si->pszModule, "Topic"); + si->bIsDirty = true; + replaceStrW(si->ptszTopic, gce.pszText.w); + if (gce.pszText.w != nullptr) + db_set_ws(si->hContact, si->pszModule, "Topic", si->ptszTopic); + else + db_unset(si->hContact, si->pszModule, "Topic"); - if (g_chatApi.OnSetTopic) - g_chatApi.OnSetTopic(si); + if (g_chatApi.OnSetTopic) + g_chatApi.OnSetTopic(si); - if (Chat::bTopicOnClist) { - if (pwszNew != nullptr) - db_set_ws(si->hContact, "CList", "StatusMsg", si->ptszTopic); - else - db_unset(si->hContact, "CList", "StatusMsg"); - } + if (Chat::bTopicOnClist) { + if (gce.pszText.w != nullptr) + db_set_ws(si->hContact, "CList", "StatusMsg", si->ptszTopic); + else + db_unset(si->hContact, "CList", "StatusMsg"); } break; diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index dd0c7d9895..2c4ba34ddc 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -38,53 +38,6 @@ int GetRichTextLength(HWND hwnd) ///////////////////////////////////////////////////////////////////////////////////////// -wchar_t* RemoveFormatting(const wchar_t *pszWord) -{ - static wchar_t szTemp[10000]; - - if (pszWord == nullptr) - return nullptr; - - wchar_t *d = szTemp; - size_t cbLen = mir_wstrlen(pszWord); - if (cbLen > _countof(szTemp)) - cbLen = _countof(szTemp)-1; - - for (size_t i = 0; i < cbLen;) { - if (pszWord[i] == '%') { - switch (pszWord[i+1]) { - case '%': - *d++ = '%'; - __fallthrough; - - 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; -} - -///////////////////////////////////////////////////////////////////////////////////////// - HICON CHAT_MANAGER::getIcon(int iEventType) const { if (iEventType & GC_EVENT_HIGHLIGHT) @@ -343,7 +296,7 @@ BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce) if (!bTextUsed && lin.ptszText) { if (!wszText.IsEmpty()) wszText.AppendChar(' '); - wszText.Append(RemoveFormatting(gce->pszText.w)); + wszText.Append(gce->pszText.w); } g_chatApi.ShowPopup(si->hContact, si, g_chatApi.getIcon(gce->iType), si->pszModule, si->ptszName, dwColor, L"%s", wszText.c_str()); @@ -422,7 +375,7 @@ bool IsHighlighted(SESSION_INFO *si, GCEVENT *gce) if (pMe == nullptr) return FALSE; - wchar_t *buf = RemoveFormatting(NEWWSTR_ALLOCA(gce->pszText.w)); + wchar_t *buf = NEWWSTR_ALLOCA(gce->pszText.w); int iStart = 0; CMStringW tszHighlightWords(g_Settings->pszHighlightWords); @@ -543,7 +496,7 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) if (!bTextUsed && lin.ptszText) { if (!buf.IsEmpty()) buf.AppendChar(' '); - buf.Append(RemoveFormatting(gce->pszText.w)); + buf.Append(gce->pszText.w); } // formatting strings don't need to be translatable - changing them via language pack would -- cgit v1.2.3