From 28c2eb96831f1e6088e4b498f8125b050585dd3b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 5 Sep 2023 15:35:12 +0300 Subject: SRMM: quoting unification --- plugins/Scriver/src/msgdialog.cpp | 45 ++++-------------------------- plugins/Scriver/src/msglog.cpp | 3 -- plugins/TabSRMM/src/msgdialog.cpp | 55 ++++++++++++++++++------------------- plugins/TabSRMM/src/msgdlgother.cpp | 4 --- plugins/TabSRMM/src/msgdlgutils.cpp | 54 ------------------------------------ plugins/TabSRMM/src/msgdlgutils.h | 1 - plugins/TabSRMM/src/msglog.cpp | 3 -- 7 files changed, 31 insertions(+), 134 deletions(-) (limited to 'plugins') diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 1e2f63cbb6..22bd7c8a08 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -25,42 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ///////////////////////////////////////////////////////////////////////////////////////// -static CMStringW GetQuotedTextW(wchar_t *text) -{ - CMStringW res; - bool newLine = true; - bool wasCR = false; - for (; *text; text++) { - if (*text == '\r') { - wasCR = newLine = true; - res.AppendChar('\r'); - if (text[1] != '\n') - res.AppendChar('\n'); - } - else if (*text == '\n') { - newLine = true; - if (!wasCR) - res.AppendChar('\r'); - - res.AppendChar('\n'); - wasCR = false; - } - else { - if (newLine) { - res.AppendChar('>'); - res.AppendChar(' '); - } - wasCR = newLine = false; - res.AppendChar(*text); - } - } - res.AppendChar('\r'); - res.AppendChar('\n'); - return res; -} - -///////////////////////////////////////////////////////////////////////////////////////// - static INT_PTR CALLBACK ConfirmSendAllDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) { switch (msg) { @@ -412,7 +376,8 @@ void CMsgDialog::onClick_UserMenu(CCtrlButton *pButton) void CMsgDialog::onClick_Quote(CCtrlButton*) { - if (m_hDbEventLast == 0) + MEVENT hDbEventLast = db_event_last(m_hContact); + if (!hDbEventLast) return; SETTEXTEX st; @@ -421,19 +386,19 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) wchar_t *buffer = m_pLog->GetSelection(); if (buffer != nullptr) { - CMStringW quotedBuffer(GetQuotedTextW(buffer)); + CMStringW quotedBuffer(Srmm_Quote(buffer)); m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&st, (LPARAM)quotedBuffer.c_str()); mir_free(buffer); } else { - DB::EventInfo dbei(m_hDbEventLast); + DB::EventInfo dbei(hDbEventLast); if (!dbei) return; if (DbEventIsMessageOrCustom(dbei)) { buffer = DbEvent_GetTextW(&dbei, CP_ACP); if (buffer != nullptr) { - CMStringW quotedBuffer(GetQuotedTextW(buffer)); + CMStringW quotedBuffer(Srmm_Quote(buffer)); m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&st, (LPARAM)quotedBuffer.c_str()); mir_free(buffer); } diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index c653e4f93a..d747909527 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -580,7 +580,6 @@ public: RtfLogStreamData streamData = {}; streamData.hContact = m_pDlg.m_hContact; streamData.hDbEvent = hDbEventFirst; - streamData.hDbEventLast = m_pDlg.m_hDbEventLast; streamData.pLog = this; streamData.eventsToInsert = count; streamData.isFirst = bAppend ? m_rtf.GetRichTextLength() == 0 : 1; @@ -656,8 +655,6 @@ public: ScrollToBottom(); RedrawWindow(m_rtf.GetHwnd(), nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); } - - m_pDlg.m_hDbEventLast = streamData.hDbEventLast; } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index c89031d2bd..a5f22c0b82 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -908,43 +908,40 @@ void CMsgDialog::onClick_Add(CCtrlButton*) void CMsgDialog::onClick_Quote(CCtrlButton*) { - SETTEXTEX stx = { ST_SELECTION, 1200 }; + CMStringW szQuoted; + int iOutputWidth = M.GetDword("quoteLineLength", 64); wchar_t *selected = m_pLog->GetSelection(); - if (selected != nullptr) { - ptrW szQuoted(QuoteText(selected)); - m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)szQuoted); - return; - } + if (selected != nullptr) + szQuoted = Srmm_Quote(selected, iOutputWidth); + else { + MEVENT hDBEvent = db_event_last(m_hContact); + if (hDBEvent == 0) + return; - MEVENT hDBEvent = db_event_last(m_hContact); - if (hDBEvent == 0) - return; + if (m_iLogMode == WANT_BUILTIN_LOG) { + CHARRANGE sel; + LOG()->WndProc(EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin != sel.cpMax) { + ptrA szFromStream(LOG()->GetRichTextRtf(true, true)); + ptrW converted(mir_utf8decodeW(szFromStream)); + Utils::FilterEventMarkers(converted); + szQuoted = Srmm_Quote(converted, iOutputWidth); + } + } - bool bUseSelection = false; - if (m_iLogMode == WANT_BUILTIN_LOG) { - CHARRANGE sel; - LOG()->WndProc(EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin != sel.cpMax) { - ptrA szFromStream(LOG()->GetRichTextRtf(true, true)); - ptrW converted(mir_utf8decodeW(szFromStream)); - Utils::FilterEventMarkers(converted); - m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, ptrW(QuoteText(converted))); - bUseSelection = true; + if (szQuoted.IsEmpty()) { + DB::EventInfo dbei(hDBEvent); + if (dbei) + szQuoted = Srmm_Quote(ptrW(DbEvent_GetTextW(&dbei, CP_ACP)), iOutputWidth); } } - if (!bUseSelection) { - DB::EventInfo dbei(hDBEvent); - - ptrW szConverted(DbEvent_GetTextW(&dbei, CP_ACP)); - if (szConverted != nullptr) - m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, ptrW(QuoteText(szConverted))); - - mir_free(szConverted); + if (!szQuoted.IsEmpty()) { + SETTEXTEX stx = { ST_SELECTION, 1200 }; + m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)szQuoted.c_str()); + SetFocus(m_message.GetHwnd()); } - - SetFocus(m_message.GetHwnd()); } void CMsgDialog::onClick_CancelAdd(CCtrlButton*) diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index badc8c911f..d2deeab39b 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -2376,10 +2376,6 @@ void CMsgDialog::StreamEvents(MEVENT hDbEventFirst, int count, bool bAppend) m_pLog->LogEvents(hDbEventFirst, count, bAppend); DM_ScrollToBottom(0, 0); - if (bAppend && hDbEventFirst) - m_hDbEventLast = hDbEventFirst; - else - m_hDbEventLast = db_event_last(m_hContact); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index f3ed376965..452090771b 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -256,60 +256,6 @@ void TSAPI ProcessAvatarChange(HWND hwnd, LPARAM lParam) } } -///////////////////////////////////////////////////////////////////////////////////////// -// return value MUST be mir_free()'d by caller. - -wchar_t* TSAPI QuoteText(const wchar_t *text) -{ - int outChar, lineChar; - int iCharsPerLine = M.GetDword("quoteLineLength", 64); - - size_t bufSize = mir_wstrlen(text) + 23; - wchar_t *strout = (wchar_t*)mir_alloc(bufSize * sizeof(wchar_t)); - int inChar = 0; - int justDoneLineBreak = 1; - for (outChar = 0, lineChar = 0; text[inChar];) { - if (outChar >= (int)bufSize - 8) { - bufSize += 20; - strout = (wchar_t*)mir_realloc(strout, bufSize * sizeof(wchar_t)); - } - if (justDoneLineBreak && text[inChar] != '\r' && text[inChar] != '\n') { - strout[outChar++] = '>'; - strout[outChar++] = ' '; - lineChar = 2; - } - if (lineChar == iCharsPerLine && text[inChar] != '\r' && text[inChar] != '\n') { - int decreasedBy; - for (decreasedBy = 0; lineChar > 10; lineChar--, inChar--, outChar--, decreasedBy++) - if (strout[outChar] == ' ' || strout[outChar] == '\t' || strout[outChar] == '-') break; - if (lineChar <= 10) { - lineChar += decreasedBy; - inChar += decreasedBy; - outChar += decreasedBy; - } - else inChar++; - strout[outChar++] = '\r'; - strout[outChar++] = '\n'; - justDoneLineBreak = 1; - continue; - } - strout[outChar++] = text[inChar]; - lineChar++; - if (text[inChar] == '\n' || text[inChar] == '\r') { - if (text[inChar] == '\r' && text[inChar + 1] != '\n') - strout[outChar++] = '\n'; - justDoneLineBreak = 1; - lineChar = 0; - } - else justDoneLineBreak = 0; - inChar++; - } - strout[outChar++] = '\r'; - strout[outChar++] = '\n'; - strout[outChar] = 0; - return strout; -} - ///////////////////////////////////////////////////////////////////////////////////////// bool IsStringValidLink(wchar_t *pszText) diff --git a/plugins/TabSRMM/src/msgdlgutils.h b/plugins/TabSRMM/src/msgdlgutils.h index b9cd0fd792..bab14bf6a7 100644 --- a/plugins/TabSRMM/src/msgdlgutils.h +++ b/plugins/TabSRMM/src/msgdlgutils.h @@ -34,7 +34,6 @@ void TSAPI AddUnreadContact(MCONTACT hContact); void TSAPI ProcessAvatarChange(HWND hwnd, LPARAM lParam); BOOL TSAPI CheckCustomLink(HWND hwndRich, POINT *ptClient, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bUrlNeeded); -wchar_t* TSAPI QuoteText(const wchar_t *text); void TSAPI CutContactName(const wchar_t *szold, wchar_t *sznew, size_t size); void TSAPI RearrangeTab(HWND hwndDlg, const CMsgDialog *dat, int iMode, BOOL bSavePos); bool TSAPI IsStatusEvent(int eventType); diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index dca3a53599..ffbb75e694 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -1191,8 +1191,6 @@ void CLogWindow::LogEvents(MEVENT hDbEventFirst, int count, bool fAppend, DB::Ev m_rtf.SetDraw(false); StreamRtfEvents(&streamData, true); - m_pDlg.m_hDbEventLast = streamData.hDbEventLast; - if (m_pDlg.m_bRtlText) m_rtf.SendMsg(EM_SETBKGNDCOLOR, 0, (LOWORD(m_pDlg.m_iLastEventType) & DBEF_SENT) ? (fAppend ? m_pDlg.m_pContainer->m_theme.outbg : m_pDlg.m_pContainer->m_theme.oldoutbg) @@ -1231,7 +1229,6 @@ void CLogWindow::LogEvents(MEVENT hDbEventFirst, int count, bool fAppend, DB::Ev m_rtf.SetDraw(true); InvalidateRect(m_rtf.GetHwnd(), nullptr, FALSE); - EnableWindow(GetDlgItem(m_pDlg.m_hwnd, IDC_QUOTE), m_pDlg.m_hDbEventLast != 0); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3