diff options
author | George Hazan <george.hazan@gmail.com> | 2023-10-30 15:22:28 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-10-30 15:22:28 +0300 |
commit | ee2337c6bc391d0ab1d58123899920c6df0d2ef0 (patch) | |
tree | 976d43891e839e11702387f121c505792f284aea /plugins | |
parent | 16143e784b1697c4b5349bc888c97f7160cf4534 (diff) |
fixes #3616 (NewStory: не работают настройки цвета своего имени и имени собеседника)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/NewStory/src/fonts.cpp | 8 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 10 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.h | 9 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 4 | ||||
-rw-r--r-- | plugins/NewStory/src/options.cpp | 2 | ||||
-rw-r--r-- | plugins/NewStory/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 108 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.h | 19 | ||||
-rw-r--r-- | plugins/NewStory/src/version.h | 4 |
9 files changed, 71 insertions, 94 deletions
diff --git a/plugins/NewStory/src/fonts.cpp b/plugins/NewStory/src/fonts.cpp index f7e32c1ef9..8cdd428859 100644 --- a/plugins/NewStory/src/fonts.cpp +++ b/plugins/NewStory/src/fonts.cpp @@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. MyColourID g_colorTable[COLOR_COUNT] = { - { LPGEN("Incoming name"), "ColorNickIn", RGB(0xc8, 0x3f, 0x6b) }, - { LPGEN("Outgoing name"), "ColorNickOut", RGB(0x08, 0x60, 0xbd) }, + { LPGEN("Incoming name"), "ColorNickIn", RGB(0x00, 0x00, 0x00) }, + { LPGEN("Outgoing name"), "ColorNickOut", RGB(0x00, 0x00, 0x00) }, { LPGEN("Incoming messages"), "ColorMsgIn", RGB(0xd6, 0xf5, 0xc0) }, { LPGEN("Outgoing messages"), "ColorMsgOut", RGB(0xf5, 0xe7, 0xd8) }, @@ -38,7 +38,7 @@ MyColourID g_colorTable[COLOR_COUNT] = { LPGEN("Selected item's background"), "ColorSel", GetSysColor(COLOR_HIGHLIGHT) }, { LPGEN("Selected item's frame"), "ColorSelFrm", GetSysColor(COLOR_HIGHLIGHTTEXT) }, - { LPGEN("Highlighted messages"), "ColorHighlight", RGB(0xf0, 0xf0, 0xf0) }, + { LPGEN("Highlighted messages"), "ColorHighlight", RGB(0xf0, 0xf0, 0xf0) }, { LPGEN("Grid background"), "Background", RGB(0xff, 0xff, 0xff) }, { LPGEN("Separator"), "Separator", RGB(0x60, 0x60, 0x60) }, }; @@ -52,7 +52,7 @@ MyFontID g_fontTable[FONT_COUNT] = { LPGEN("Outgoing files"), "FontFileOut" }, { LPGEN("Status changes"), "FontStatus" }, - { LPGEN("Highlighted messages"), "FontHighlight", DBFONTF_BOLD, RGB(0x7f, 0, 0) }, + { LPGEN("Highlighted messages"), "FontHighlight", DBFONTF_BOLD, RGB(0x7f, 0, 0) }, { LPGEN("Other incoming events"), "FontIn" }, { LPGEN("Other outgoing events"), "FontOut" }, diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 67505d91d1..db00f46f98 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -306,9 +306,6 @@ void ItemData::load(bool bFullLoad) db_event_markRead(hContact, hEvent); Clist_RemoveEvent(-1, hEvent); } - - // uncomment this to use RTF engine - // m_bRtf = true; __fallthrough; case EVENTTYPE_STATUSCHANGE: @@ -372,12 +369,7 @@ void ItemData::load(bool bFullLoad) void ItemData::setText() { - if (m_bRtf) { - NSRtfProvider prov(this); - data = MTextCreateEx(htuLog, &prov, MTEXT_FLG_RTF); - } - else data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), TplFormatString(getTemplate(), hContact, this)); - + data = MTextCreateEx(htuLog, formatRtf().GetBuffer(), MTEXT_FLG_RTF); savedHeight = -1; } diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index cfefca9612..151ff568ca 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -8,12 +8,13 @@ enum GROUPING_ITEM = 2, }; +CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item); + struct ItemData { MCONTACT hContact; MEVENT hEvent; - bool m_bRtf; bool m_bSelected, m_bHighlighted; bool m_bLoaded, m_bIsResult; bool m_bOfflineFile, m_bOfflineDownloaded; @@ -25,7 +26,7 @@ struct ItemData wchar_t *wtext; wchar_t *wszNick; - HANDLE data; + HText data; ItemData(); ~ItemData(); @@ -43,6 +44,10 @@ struct ItemData int getCopyTemplate() const; void getFontColor(int &fontId, int &colorId) const; + CMStringA formatRtf(); + CMStringW formatString() { return TplFormatString(getTemplate(), hContact, this); } + CMStringW formatStringEx(int tpl, wchar_t *sztpl); + inline wchar_t *getWBuf() { load(true); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 365ad3e8aa..d7102b980a 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -290,7 +290,7 @@ void NewstoryListData::Copy(bool bTextOnly) res.Append(L"\r\n"); } else { // copy text only - CMStringW wszText(TplFormatString(p->getCopyTemplate(), p->hContact, p)); + CMStringW wszText(p->formatString()); RemoveBbcodes(wszText); res.Append(wszText); } @@ -497,7 +497,7 @@ int NewstoryListData::GetItemHeight(int index) int width = rc.right - rc.left; SIZE sz = { width - 6, 0 }; - MTextMeasure(hdc, &sz, (HANDLE)item->data); + MTextMeasure(hdc, &sz, item->data); SelectObject(hdc, hOldFont); ReleaseDC(m_hwnd, hdc); diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp index 2d5f355e1b..ee84cd1b79 100644 --- a/plugins/NewStory/src/options.cpp +++ b/plugins/NewStory/src/options.cpp @@ -83,7 +83,7 @@ class CTemplateOptsDlg : public CBaseOptsDlg item.hEvent = m_hDbEVent; item.load(true); - CMStringW wszText(TplFormatStringEx(int(m_curr - templates), m_curr->tmpValue, &item)); + CMStringW wszText(item.formatStringEx(int(m_curr - templates), m_curr->tmpValue)); preview.SetText(wszText); gpreview.SetText(wszText); } diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h index 70039c4c3f..fc0c78dd22 100644 --- a/plugins/NewStory/src/stdafx.h +++ b/plugins/NewStory/src/stdafx.h @@ -45,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_langpack.h> #include <m_message.h> #include <m_metacontacts.h> +#include <m_netlib.h> #include <m_options.h> #include <m_protocols.h> #include <m_protosvc.h> diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 7e6f82a0a7..8d2e1bd242 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -27,46 +27,17 @@ wchar_t *months[12] = }; /////////////////////////////////////////////////////////////////////////////// -// Template formatting for options dialog - -CMStringW TplFormatStringEx(int tpl, wchar_t *sztpl, ItemData *item) -{ - if (tpl < 0 || tpl >= TPL_COUNT || !sztpl) - return mir_wstrdup(L""); - - TemplateVars vars; - - auto &T = templates[tpl]; - for (auto &it : T.vf) - if (it) - it(&vars, item->hContact, item); - - CMStringW buf; - for (wchar_t *p = sztpl; *p; p++) { - if (*p == '%') { - wchar_t *var = vars.GetVar((p[1] & 0xff)); - if (var) - buf.Append(var); - p++; - } - else buf.AppendChar(*p); - } - - return buf; -} - -/////////////////////////////////////////////////////////////////////////////// -// Template formatting for the control +// RTF generator static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p) { for (; *p; p++) { if (*p == '\r' && p[1] == '\n') { - buf.Append("\\p "); + buf.Append("\\par "); p++; } else if (*p == '\n') { - buf.Append("\\p "); + buf.Append("\\par "); } else if (*p == '\t') { buf.Append("\\tab "); @@ -118,39 +89,35 @@ static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p) } } -CMStringA NSRtfProvider::CreateRtfHeader() +CMStringA ItemData::formatRtf() { CMStringA buf; buf.Append("{\\rtf1\\ansi\\deff0"); - auto &F = g_fontTable[(m_pItem->dbe.flags & DBEF_SENT) ? FONT_OUTMSG : FONT_INMSG]; + int fontID, colorID; + getFontColor(fontID, colorID); + auto &F = g_fontTable[fontID]; buf.AppendFormat("{\\fonttbl{\\f0\\fnil\\fcharset0 %s;}}", F.lf.lfFaceName); - COLORREF cr = GetSysColor(COLOR_WINDOWTEXT); + COLORREF cr = F.cl; buf.AppendFormat("{\\colortbl \\red%u\\green%u\\blue%u;", GetRValue(cr), GetGValue(cr), GetBValue(cr)); - cr = g_colorTable[(m_pItem->dbe.flags & DBEF_SENT) ? COLOR_OUTNICK : COLOR_INNICK].cl; + cr = g_colorTable[(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); + HDC hdc = GetDC(nullptr); + int logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(nullptr, hdc); - CMStringA buf; - buf.AppendFormat("\\viewkind4\\uc1\\pard \\f0\\b0\\i0\\fs%d ", F.lf.lfHeight); - AppendUnicodeToBuffer(buf, wszText); - return buf; -} + buf.AppendFormat("\\uc1\\pard \\cf0\\f0\\b0\\i0\\fs%d ", 2 * abs(F.lf.lfHeight) * 74 / logPixelSY); + AppendUnicodeToBuffer(buf, formatString()); -CMStringA NSRtfProvider::CreateRtfFooter() -{ - return " \\par }"; + buf.Append("}"); + Netlib_Logf(0, buf); + return buf; } /////////////////////////////////////////////////////////////////////////////// -// Template formatting for copying text +// Template formatting for the control CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item) { @@ -184,6 +151,35 @@ CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item) } /////////////////////////////////////////////////////////////////////////////// +// Template formatting for options dialog + +CMStringW ItemData::formatStringEx(int tpl, wchar_t *sztpl) +{ + CMStringW buf; + if (tpl < 0 || tpl >= TPL_COUNT || !sztpl) + return buf; + + TemplateVars vars; + + auto &T = templates[tpl]; + for (auto &it : T.vf) + if (it) + it(&vars, hContact, this); + + for (wchar_t *p = sztpl; *p; p++) { + if (*p == '%') { + wchar_t *var = vars.GetVar((p[1] & 0xff)); + if (var) + buf.Append(var); + p++; + } + else buf.AppendChar(*p); + } + + return buf; +} + +/////////////////////////////////////////////////////////////////////////////// // TemplateVars members TemplateVars::TemplateVars() @@ -246,13 +242,13 @@ void vfEvent(TemplateVars *vars, MCONTACT, ItemData *item) if (!item->wszNick) { char *proto = Proto_GetBaseAccountName(item->hContact); ptrW nick(Contact::GetInfo(CNF_DISPLAY, 0, proto)); - vars->SetNick(nick, false); + vars->SetNick(nick); } - else vars->SetNick(item->wszNick, false); + else vars->SetNick(item->wszNick); } else { wchar_t *nick = (item->wszNick) ? item->wszNick : Clist_GetContactDisplayName(item->hContact, 0); - vars->SetNick(nick, true); + vars->SetNick(nick); } // %I: Icon @@ -392,9 +388,9 @@ void vfOther(TemplateVars *vars, MCONTACT, ItemData *item) ///////////////////////////////////////////////////////////////////////////////////////// -void TemplateVars::SetNick(wchar_t *v, bool bIncoming) +void TemplateVars::SetNick(wchar_t *v) { - CMStringW wszNick(FORMAT, L"[color=%d]%s[/color]", g_colorTable[(bIncoming) ? COLOR_INNICK : COLOR_OUTNICK].cl, v); + CMStringW wszNick(FORMAT, L"[c1]%s[c0]", v); auto &V = vars['N']; if (V.del) diff --git a/plugins/NewStory/src/templates.h b/plugins/NewStory/src/templates.h index 1ad2deed48..bfb7e123e7 100644 --- a/plugins/NewStory/src/templates.h +++ b/plugins/NewStory/src/templates.h @@ -16,7 +16,7 @@ struct TemplateVars return vars[id].val; } - void SetNick(wchar_t *v, bool bIncoming); + void SetNick(wchar_t *v); void SetVar(uint8_t id, wchar_t *v, bool d); }; @@ -71,21 +71,4 @@ extern TemplateInfo templates[TPL_COUNT]; void LoadTemplates(); void SaveTemplates(); -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 diff --git a/plugins/NewStory/src/version.h b/plugins/NewStory/src/version.h index b23dcd2b60..23bd96a08b 100644 --- a/plugins/NewStory/src/version.h +++ b/plugins/NewStory/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 1
+#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 4
+#define __BUILD_NUM 1
#include <stdver.h>
|