diff options
author | George Hazan <george.hazan@gmail.com> | 2023-10-19 18:15:45 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-10-19 18:15:45 +0300 |
commit | ec9b7581909991cacbcd291becdf17ccbf6194b8 (patch) | |
tree | 9a017a6f8f60b80b8a573a3706da4ddb0a96de1a /plugins | |
parent | b6f4df821380405c6bfa4a53f9db3874173e4b32 (diff) |
mTextControl: RTF code redesign
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ExternalAPI/m_text.h | 7 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 10 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 24 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.h | 14 |
4 files changed, 43 insertions, 12 deletions
diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h index 1c231c2fd2..bc3fc25237 100644 --- a/plugins/ExternalAPI/m_text.h +++ b/plugins/ExternalAPI/m_text.h @@ -46,6 +46,13 @@ enum MTEXT_FLG_RTF = 0x00000004,
};
+struct MRtfProvider
+{
+ virtual CMStringA CreateRtfHeader() = 0;
+ virtual CMStringA CreateRtfBody() = 0;
+ virtual CMStringA CreateRtfFooter() = 0;
+};
+
// subscribe to MText services
MTEXTCONTROL_DLL(HANDLE) MTextRegister(const char *userTitle, uint32_t options);
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index efd3fe9267..72d2b2e4ea 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -372,10 +372,12 @@ void ItemData::load(bool bFullLoad) void ItemData::setText() { - if (m_bRtf) - data = MTextCreateEx(htuLog, (void*)TplFormatRtf(getTemplate(), hContact, this).c_str(), MTEXT_FLG_RTF); - else - data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), TplFormatString(getTemplate(), hContact, this)); + if (m_bRtf) { + NSRtfProvider prov(this); + data = MTextCreateEx(htuLog, &prov, MTEXT_FLG_RTF); + } + else data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), TplFormatString(getTemplate(), hContact, this)); + savedHeight = -1; } diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index cab175563a..7010ff1e85 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -121,27 +121,37 @@ static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p) buf.AppendChar('}'); } -CMStringA TplFormatRtf(int tpl, MCONTACT hContact, ItemData *item) +CMStringA NSRtfProvider::CreateRtfHeader() { - CMStringW wszText = TplFormatString(tpl, hContact, item); - CMStringA buf; buf.Append("{\\rtf1\\ansi\\deff0"); - auto &F = g_fontTable[(item->dbe.flags & DBEF_SENT) ? FONT_OUTMSG : FONT_INMSG]; + auto &F = g_fontTable[(m_pItem->dbe.flags & DBEF_SENT) ? FONT_OUTMSG : FONT_INMSG]; buf.AppendFormat("{\\fonttbl{\\f0\\fnil\\fcharset1 %s;}}", F.lf.lfFaceName); COLORREF cr = GetSysColor(COLOR_WINDOWTEXT); buf.AppendFormat("{\\colortbl \\red%u\\green%u\\blue%u;", GetRValue(cr), GetGValue(cr), GetBValue(cr)); - cr = g_colorTable[(item->dbe.flags & DBEF_SENT) ? COLOR_OUTNICK : COLOR_INNICK].cl; + cr = g_colorTable[(m_pItem->dbe.flags & DBEF_SENT) ? COLOR_OUTNICK : COLOR_INNICK].cl; buf.AppendFormat("\\red%u\\green%u\\blue%u;}", GetRValue(cr), GetGValue(cr), GetBValue(cr)); + return buf; +} + +CMStringA NSRtfProvider::CreateRtfBody() +{ + auto &F = g_fontTable[(m_pItem->dbe.flags & DBEF_SENT) ? FONT_OUTMSG : FONT_INMSG]; + CMStringW wszText = TplFormatString(m_pItem->getTemplate(), m_pItem->hContact, m_pItem); - buf.AppendFormat("\\par\\ltrpar \\f0\\cf0\\b0\\i0\\fs%d ", -F.lf.lfHeight); + CMStringA buf; + // buf.AppendFormat("\\f0\\cf0\\b0\\i0\\fs%d ", -F.lf.lfHeight); AppendUnicodeToBuffer(buf, wszText); - buf.AppendChar('}'); return buf; } +CMStringA NSRtfProvider::CreateRtfFooter() +{ + return "}"; +} + /////////////////////////////////////////////////////////////////////////////// // Template formatting for copying text diff --git a/plugins/NewStory/src/templates.h b/plugins/NewStory/src/templates.h index 932f9dc437..1ad2deed48 100644 --- a/plugins/NewStory/src/templates.h +++ b/plugins/NewStory/src/templates.h @@ -71,9 +71,21 @@ extern TemplateInfo templates[TPL_COUNT]; void LoadTemplates(); void SaveTemplates(); -CMStringA TplFormatRtf(int tpl, MCONTACT hContact, ItemData *args); CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item); CMStringW TplFormatStringEx(int tpl, wchar_t *sztpl, ItemData *args); +class NSRtfProvider : public MRtfProvider +{ + ItemData *m_pItem; + +public: + NSRtfProvider(ItemData *pItem) : + m_pItem(pItem) + {} + + CMStringA CreateRtfHeader() override; + CMStringA CreateRtfBody() override; + CMStringA CreateRtfFooter() override; +}; #endif // __templates_h__
\ No newline at end of file |