From 2fdfdda14b5703240f08a0b4e278185807681e1d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 26 Jul 2017 21:16:34 +0300 Subject: TabSMM: wrongly removed functionality returned back (color chooser in SRMM dialog) --- plugins/TabSRMM/src/msgdialog.cpp | 37 +++++++++++++++++++++++++++++++++++++ plugins/TabSRMM/src/msgdlgutils.cpp | 20 ++++++++------------ plugins/TabSRMM/src/msgs.h | 1 + 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 6d7abf92cd..3af970f9d9 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -581,6 +581,7 @@ CSrmmWindow::CSrmmWindow() m_btnOk.OnClick = Callback(this, &CSrmmWindow::onClick_Ok); m_btnAdd.OnClick = Callback(this, &CSrmmWindow::onClick_Add); m_btnQuote.OnClick = Callback(this, &CSrmmWindow::onClick_Quote); + m_btnColor.OnClick = Callback(this, &CSrmmWindow::onClick_Color); m_btnCancelAdd.OnClick = Callback(this, &CSrmmWindow::onClick_CancelAdd); m_message.OnChange = Callback(this, &CSrmmWindow::onChange_Message); @@ -1187,6 +1188,42 @@ void CSrmmWindow::onClick_Add(CCtrlButton*) } } +void CSrmmWindow::onClick_Color(CCtrlButton *pButton) +{ + CHARFORMAT2 cf; + ZeroMemory(&cf, sizeof(CHARFORMAT2)); + cf.cbSize = sizeof(CHARFORMAT2); + cf.dwMask = CFM_COLOR; + cf.dwEffects = 0; + + RECT rc; + GetWindowRect(pButton->GetHwnd(), &rc); + int iSelection = TrackPopupMenu(GetSubMenu(PluginConfig.g_hMenuContext, 7), TPM_RETURNCMD, rc.left, rc.bottom, 0, m_hwnd, NULL); + if (iSelection == ID_FONT_CLEARALLFORMATTING) { + cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT; + cf.crTextColor = M.GetDword(FONTMODULE, "Font16Col", 0); + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + return; + } + + if (iSelection == ID_FONT_DEFAULTCOLOR) { + cf.crTextColor = M.GetDword(FONTMODULE, "Font16Col", 0); + for (int i = 0; i < Utils::rtf_ctable_size; i++) + if (Utils::rtf_ctable[i].clr == cf.crTextColor) + cf.crTextColor = RGB(GetRValue(cf.crTextColor), GetGValue(cf.crTextColor), GetBValue(cf.crTextColor) == 0 ? GetBValue(cf.crTextColor) + 1 : GetBValue(cf.crTextColor) - 1); + + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + return; + } + + for (int i = 0; i < RTF_CTABLE_DEFSIZE; i++) { + if (Utils::rtf_ctable[i].menuid == iSelection) { + cf.crTextColor = Utils::rtf_ctable[i].clr; + m_message.SendMsg(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf); + } + } +} + void CSrmmWindow::onClick_Quote(CCtrlButton*) { CHARRANGE sel; diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index a3f47459f5..9800e43e42 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -823,15 +823,6 @@ static void CreateColorMap(CMStringW &Text, int iCount, COLORREF *pSrc, int *pDs } } -static int GetRtfIndex(int iCol, int iCount, int *pIndex) -{ - for (int i = 0; i < iCount; i++) - if (pIndex[i] == iCol) - return i; - - return -1; -} - ///////////////////////////////////////////////////////////////////////////////////////// // convert rich edit code to bbcode (if wanted). Otherwise, strip all RTF formatting // tags and return plain text @@ -876,12 +867,17 @@ BOOL CTabBaseDlg::DoRtfToTags(CMStringW &pszText, int iNumColors, COLORREF *pCol if (!wcsncmp(p, L"\\cf", 3)) { // foreground color int iCol = _wtoi(p + 3); - int iInd = GetRtfIndex(iCol, iNumColors, pIndex); + int iInd = -1; + for (int i = 0; i < iNumColors; i++) + if (pIndex[i] == iCol) { + iInd = i; + break; + } if (iCol && !isChat()) - res.AppendFormat((iInd > 0) ? (bInsideColor ? L"[/color][color=%s]" : L"[color=%s]") : (bInsideColor ? L"[/color]" : L""), Utils::rtf_ctable[iInd - 1].szName); + res.AppendFormat((iInd >= 0) ? (bInsideColor ? L"[/color][color=%s]" : L"[color=%s]") : (bInsideColor ? L"[/color]" : L""), Utils::rtf_ctable[iInd].szName); - bInsideColor = iInd > 0; + bInsideColor = iInd >= 0; } else if (!wcsncmp(p, L"\\highlight", 10)) { //background color wchar_t szTemp[20]; diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index def537f926..96950956d3 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -488,6 +488,7 @@ public: void onClick_Ok(CCtrlButton*); void onClick_Add(CCtrlButton*); + void onClick_Color(CCtrlButton*); void onClick_Quote(CCtrlButton*); void onClick_CancelAdd(CCtrlButton*); -- cgit v1.2.3