diff options
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/msgdlgother.cpp | 192 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 3 |
2 files changed, 10 insertions, 185 deletions
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index e94ca1a89d..1317a38f3c 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -186,189 +186,6 @@ void CMsgDialog::DetermineMinHeight() }
/////////////////////////////////////////////////////////////////////////////////////////
-// convert rich edit code to bbcode (if wanted). Otherwise, strip all RTF formatting
-// tags and return plain text
-
-static wchar_t tszRtfBreaks[] = L" \\\n\r";
-
-static void CreateColorMap(const wchar_t *pszText, std::vector<COLORREF> &res)
-{
- const wchar_t *p1 = wcsstr(pszText, L"\\colortbl");
- if (!p1)
- return;
-
- const wchar_t *pEnd = wcschr(p1, '}');
-
- for (const wchar_t *p2 = wcsstr(p1, L"\\red"); p2 && p2 < pEnd; p2 = wcsstr(p1, L"\\red")) {
- int iRed, iGreen, iBlue;
- if (swscanf(p2, L"\\red%d\\green%d\\blue%d;", &iRed, &iGreen, &iBlue) > 0)
- res.push_back(RGB(iRed, iGreen, iBlue));
-
- p1 = p2 + 1;
- }
-}
-
-BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
-{
- if (pszText.IsEmpty())
- return FALSE;
-
- // used to filter out attributes which are already set for the default message input area font
- auto &lf = m_pContainer->m_theme.logFonts[MSGFONTID_MESSAGEAREA];
-
- // create an index of colors in the module and map them to
- // corresponding colors in the RTF color table
- std::vector<COLORREF> colorTable;
- CreateColorMap(pszText, colorTable);
-
- // scan the file for rtf commands and remove or parse them
- int idx = pszText.Find(L"\\pard");
- if (idx == -1) {
- if ((idx = pszText.Find(L"\\ltrpar")) == -1)
- return FALSE;
- idx += 7;
- }
- else idx += 5;
-
- bool bInsideUl = false, bStart = true;
- CMStringW res;
-
- // iterate through all characters, if rtf control character found then take action
- for (const wchar_t *p = pszText.GetString() + idx; *p;) {
- switch (*p) {
- case '\\':
- if (p[1] == '\\' || p[1] == '{' || p[1] == '}') { // escaped characters
- res.AppendChar(p[1]);
- bStart = false;
- p += 2; break;
- }
- if (p[1] == '~') { // non-breaking space
- res.AppendChar(0xA0);
- bStart = false;
- p += 2; break;
- }
-
- if (!wcsncmp(p, L"\\cf", 3)) { // foreground color
- COLORREF cr = colorTable[_wtoi(p + 3) - 1];
- if (cr != m_pContainer->m_theme.fontColors[MSGFONTID_MESSAGEAREA])
- res.AppendFormat(L"[color=%08X]", cr);
- else if (!bStart)
- res.Append(L"[/color]");
- }
- else if (!wcsncmp(p, L"\\highlight", 10)) { // background color
- COLORREF cr = colorTable[_wtoi(p + 10) - 1];
- if (cr != m_pContainer->m_theme.inputbg)
- res.AppendFormat(L"[bkcolor=%08X]", cr);
- else if (!bStart)
- res.AppendFormat(L"[/bkcolor]");
- }
- else if (!wcsncmp(p, L"\\line", 5)) { // soft line break;
- res.AppendChar('\n');
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\endash", 7)) {
- res.AppendChar(0x2013);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\emdash", 7)) {
- res.AppendChar(0x2014);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\bullet", 7)) {
- res.AppendChar(0x2022);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\ldblquote", 10)) {
- res.AppendChar(0x201C);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\rdblquote", 10)) {
- res.AppendChar(0x201D);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\lquote", 7)) {
- res.AppendChar(0x2018);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\rquote", 7)) {
- res.AppendChar(0x2019);
- bStart = false;
- }
- else if (!wcsncmp(p, L"\\b", 2)) { //bold
- // only allow bold if the font itself isn't a bold one, otherwise just strip it..
- if (lf.lfWeight != FW_BOLD && m_bSendFormat)
- res.Append((p[2] != '0') ? L"[b]" : L"[/b]");
- }
- else if (!wcsncmp(p, L"\\i", 2)) { // italics
- if (!lf.lfItalic && m_bSendFormat)
- res.Append((p[2] != '0') ? L"[i]" : L"[/i]");
- }
- else if (!wcsncmp(p, L"\\strike", 7)) { // strike-out
- if (!lf.lfStrikeOut && m_bSendFormat)
- res.Append((p[7] != '0') ? L"[s]" : L"[/s]");
- }
- else if (!wcsncmp(p, L"\\ul", 3)) { // underlined
- if (!lf.lfUnderline && m_bSendFormat) {
- if (p[3] == 0 || wcschr(tszRtfBreaks, p[3])) {
- res.Append(L"[u]");
- bInsideUl = true;
- }
- else if (!wcsncmp(p + 3, L"none", 4)) {
- if (bInsideUl)
- res.Append(L"[/u]");
- bInsideUl = false;
- }
- }
- }
- else if (!wcsncmp(p, L"\\tab", 4)) { // tab
- res.AppendChar('\t');
- }
- else if (p[1] == '\'') { // special character
- if (p[2] != ' ' && p[2] != '\\') {
- wchar_t tmp[10];
-
- if (p[3] != ' ' && p[3] != '\\') {
- wcsncpy(tmp, p + 2, 3);
- tmp[3] = 0;
- }
- else {
- wcsncpy(tmp, p + 2, 2);
- tmp[2] = 0;
- }
-
- // convert string containing char in hex format to int.
- wchar_t *stoppedHere;
- res.AppendChar(wcstol(tmp, &stoppedHere, 16));
- bStart = false;
- }
- }
-
- p++; // skip initial slash
- p += wcscspn(p, tszRtfBreaks);
- if (*p == ' ')
- p++;
- break;
-
- case '{': // other RTF control characters
- case '}':
- p++;
- break;
-
- default: // other text that should not be touched
- res.AppendChar(*p++);
- bStart = false;
- break;
- }
- }
-
- if (bInsideUl)
- res.Append(L"[/u]");
-
- pszText = res;
- return TRUE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
void CMsgDialog::DrawNickList(USERINFO *ui, DRAWITEMSTRUCT *dis)
{
@@ -639,6 +456,15 @@ bool CMsgDialog::GetFirstEvent() }
/////////////////////////////////////////////////////////////////////////////////////////
+
+void CMsgDialog::GetInputFont(LOGFONTW &lf, COLORREF &bg, COLORREF &fg) const
+{
+ lf = m_pContainer->m_theme.logFonts[MSGFONTID_MESSAGEAREA];
+ fg = m_pContainer->m_theme.fontColors[MSGFONTID_MESSAGEAREA];
+ bg = m_pContainer->m_theme.inputbg;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// returns != 0 when one of the installed keyboard layouts belongs to an rtl language
// used to find out whether we need to configure the message input box for bidirectional mode
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 5e6aefbe58..106ae689b6 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -413,7 +413,6 @@ class CMsgDialog : public CSrmmBaseDialog void AdjustBottomAvatarDisplay(void);
bool CalcDynamicAvatarSize(BITMAP *bminfo);
void DetermineMinHeight(void);
- BOOL DoRtfToTags(CMStringW &pszText) const;
int FindRTLLocale(void);
void FlashOnClist(MEVENT hEvent, const DB::EventInfo &dbei);
void FlashTab(bool bInvertMode);
@@ -465,7 +464,6 @@ class CMsgDialog : public CSrmmBaseDialog bool m_bInsertMode, m_bInitMode = true;
bool m_bDeferredScroll;
bool m_bWasBackgroundCreate;
- bool m_bSendFormat;
int m_iRealAvatarHeight;
int m_iButtonBarReallyNeeds;
@@ -591,6 +589,7 @@ public: void DrawNickList(USERINFO *ui, DRAWITEMSTRUCT *dis) override;
void EventAdded(MEVENT, const DB::EventInfo &dbei) override;
bool GetFirstEvent() override;
+ void GetInputFont(LOGFONTW &lf, COLORREF &bg, COLORREF &fg) const override;
bool IsActive() const override;
void LoadSettings() override;
void OnOptionsApplied() override;
|