summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-09-05 15:35:12 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-09-05 15:35:12 +0300
commit28c2eb96831f1e6088e4b498f8125b050585dd3b (patch)
tree2bff3cbedb270fdba4288c0eacf2b5381a77b4c9 /plugins/TabSRMM/src
parenta074799eaf3218c979fa07d8a76525aa0ec7b9fd (diff)
SRMM: quoting unification
Diffstat (limited to 'plugins/TabSRMM/src')
-rw-r--r--plugins/TabSRMM/src/msgdialog.cpp55
-rw-r--r--plugins/TabSRMM/src/msgdlgother.cpp4
-rw-r--r--plugins/TabSRMM/src/msgdlgutils.cpp54
-rw-r--r--plugins/TabSRMM/src/msgdlgutils.h1
-rw-r--r--plugins/TabSRMM/src/msglog.cpp3
5 files changed, 26 insertions, 91 deletions
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
@@ -257,60 +257,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);
}
/////////////////////////////////////////////////////////////////////////////////////////