diff options
author | George Hazan <ghazan@miranda.im> | 2017-04-05 20:18:35 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-04-05 20:18:35 +0300 |
commit | 6b3d56dbdccc4b608d258a4a7705514e46947e28 (patch) | |
tree | da2167bc274694a25cdd204370062360ad3048a9 /src | |
parent | c1ceb16e6e5957c94232a0ff43fbeca0ff19bf93 (diff) |
SRMM* plugins switched to CCtrlRichEdit
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/chat_util.cpp | 133 | ||||
-rw-r--r-- | src/core/stdmsg/src/chat_window.cpp | 114 | ||||
-rw-r--r-- | src/core/stdmsg/src/stdafx.h | 1 |
3 files changed, 106 insertions, 142 deletions
diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp deleted file mode 100644 index 4e2c25b689..0000000000 --- a/src/core/stdmsg/src/chat_util.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - -Copyright 2000-12 Miranda IM, 2012-17 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" - -void CChatRoomDlg::StreamInEvents(LOGINFO *lin, bool bRedraw) -{ - if (m_hwnd == nullptr || lin == nullptr || m_si == nullptr) - return; - - if (!bRedraw && m_si->iType == GCW_CHATROOM && m_bFilterEnabled && (m_iLogFilterFlags & lin->iType) == 0) - return; - - LOGSTREAMDATA streamData; - memset(&streamData, 0, sizeof(streamData)); - streamData.hwnd = m_log.GetHwnd(); - streamData.si = m_si; - streamData.lin = lin; - streamData.bStripFormat = FALSE; - - BOOL bFlag = FALSE; - - EDITSTREAM stream = {}; - stream.pfnCallback = Srmm_LogStreamCallback; - stream.dwCookie = (DWORD_PTR)& streamData; - - SCROLLINFO scroll; - scroll.cbSize = sizeof(SCROLLINFO); - scroll.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; - GetScrollInfo(m_log.GetHwnd(), SB_VERT, &scroll); - - POINT point = {}; - m_log.SendMsg(EM_GETSCROLLPOS, 0, (LPARAM)&point); - - // do not scroll to bottom if there is a selection - CHARRANGE oldsel, sel; - m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&oldsel); - if (oldsel.cpMax != oldsel.cpMin) - m_log.SendMsg(WM_SETREDRAW, FALSE, 0); - - //set the insertion point at the bottom - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd()); - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); - - // fix for the indent... must be a M$ bug - if (sel.cpMax == 0) - bRedraw = TRUE; - - // should the event(s) be appended to the current log - WPARAM wp = bRedraw ? SF_RTF : SFF_SELECTION | SF_RTF; - - //get the number of pixels per logical inch - if (bRedraw) { - HDC hdc = GetDC(nullptr); - pci->logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); - pci->logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX); - ReleaseDC(nullptr, hdc); - m_log.SendMsg(WM_SETREDRAW, FALSE, 0); - bFlag = TRUE; - } - - // stream in the event(s) - streamData.lin = lin; - streamData.bRedraw = bRedraw; - m_log.SendMsg(EM_STREAMIN, wp, (LPARAM)&stream); - - // do smileys - if (SmileyAddInstalled && (bRedraw || (lin->ptszText && lin->iType != GC_EVENT_JOIN && lin->iType != GC_EVENT_NICK && lin->iType != GC_EVENT_ADDSTATUS && lin->iType != GC_EVENT_REMOVESTATUS))) { - CHARRANGE newsel; - newsel.cpMax = -1; - newsel.cpMin = sel.cpMin; - if (newsel.cpMin < 0) - newsel.cpMin = 0; - - SMADD_RICHEDIT3 sm = {}; - sm.cbSize = sizeof(sm); - sm.hwndRichEditControl = m_log.GetHwnd(); - sm.Protocolname = m_si->pszModule; - sm.rangeToReplace = bRedraw ? nullptr : &newsel; - sm.disableRedraw = TRUE; - sm.hContact = m_si->hContact; - CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&sm); - } - - // scroll log to bottom if the log was previously scrolled to bottom, else restore old position - if (bRedraw || (UINT)scroll.nPos >= (UINT)scroll.nMax - scroll.nPage - 5 || scroll.nMax - scroll.nMin - scroll.nPage < 50) - ScrollToBottom(); - else - m_log.SendMsg(EM_SETSCROLLPOS, 0, (LPARAM)&point); - - // do we need to restore the selection - if (oldsel.cpMax != oldsel.cpMin) { - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldsel); - m_log.SendMsg(WM_SETREDRAW, TRUE, 0); - InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); - } - - // need to invalidate the window - if (bFlag) { - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd()); - m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); - m_log.SendMsg(WM_SETREDRAW, TRUE, 0); - InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int GetRichTextLength(HWND hwnd) -{ - GETTEXTLENGTHEX gtl; - gtl.flags = GTL_PRECISE; - gtl.codepage = CP_ACP; - return (int)SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); -} diff --git a/src/core/stdmsg/src/chat_window.cpp b/src/core/stdmsg/src/chat_window.cpp index 8432929f09..ce6928a20d 100644 --- a/src/core/stdmsg/src/chat_window.cpp +++ b/src/core/stdmsg/src/chat_window.cpp @@ -121,12 +121,7 @@ void CChatRoomDlg::onClick_Ok(CCtrlButton *pButton) if (!pButton->Enabled()) return; - ptrA pszRtf; - EDITSTREAM stream; - memset(&stream, 0, sizeof(stream)); - stream.pfnCallback = Srmm_MessageStreamCallback; - stream.dwCookie = (DWORD_PTR)&pszRtf; // pass pointer to pointer - m_message.SendMsg(EM_STREAMOUT, SF_RTFNOOBJS | SFF_PLAINRTF | SF_USECODEPAGE | (CP_UTF8 << 16), (LPARAM)&stream); + ptrA pszRtf(m_message.GetRichTextRtf()); if (pszRtf == nullptr) return; @@ -250,7 +245,7 @@ void CChatRoomDlg::ScrollToBottom() scroll.nPos = scroll.nMax - scroll.nPage + 1; SetScrollInfo(m_log.GetHwnd(), SB_VERT, &scroll, TRUE); - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd()); + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); PostMessage(m_log.GetHwnd(), WM_VSCROLL, MAKEWPARAM(SB_BOTTOM, 0), 0); } @@ -382,6 +377,109 @@ void CChatRoomDlg::UpdateTitle() ///////////////////////////////////////////////////////////////////////////////////////// +void CChatRoomDlg::StreamInEvents(LOGINFO *lin, bool bRedraw) +{ + if (m_hwnd == nullptr || lin == nullptr || m_si == nullptr) + return; + + if (!bRedraw && m_si->iType == GCW_CHATROOM && m_bFilterEnabled && (m_iLogFilterFlags & lin->iType) == 0) + return; + + LOGSTREAMDATA streamData; + memset(&streamData, 0, sizeof(streamData)); + streamData.hwnd = m_log.GetHwnd(); + streamData.si = m_si; + streamData.lin = lin; + streamData.bStripFormat = FALSE; + + bool bFlag = false; + + EDITSTREAM stream = {}; + stream.pfnCallback = Srmm_LogStreamCallback; + stream.dwCookie = (DWORD_PTR)& streamData; + + SCROLLINFO scroll; + scroll.cbSize = sizeof(SCROLLINFO); + scroll.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; + GetScrollInfo(m_log.GetHwnd(), SB_VERT, &scroll); + + POINT point = {}; + m_log.SendMsg(EM_GETSCROLLPOS, 0, (LPARAM)&point); + + // do not scroll to bottom if there is a selection + CHARRANGE oldsel, sel; + m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&oldsel); + if (oldsel.cpMax != oldsel.cpMin) + m_log.SendMsg(WM_SETREDRAW, FALSE, 0); + + //set the insertion point at the bottom + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + + // fix for the indent... must be a M$ bug + if (sel.cpMax == 0) + bRedraw = TRUE; + + // should the event(s) be appended to the current log + WPARAM wp = bRedraw ? SF_RTF : SFF_SELECTION | SF_RTF; + + //get the number of pixels per logical inch + if (bRedraw) { + HDC hdc = GetDC(nullptr); + pci->logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); + pci->logPixelSX = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(nullptr, hdc); + m_log.SendMsg(WM_SETREDRAW, FALSE, 0); + bFlag = true; + } + + // stream in the event(s) + streamData.lin = lin; + streamData.bRedraw = bRedraw; + m_log.SendMsg(EM_STREAMIN, wp, (LPARAM)&stream); + + // do smileys + if (SmileyAddInstalled && (bRedraw || (lin->ptszText && lin->iType != GC_EVENT_JOIN && lin->iType != GC_EVENT_NICK && lin->iType != GC_EVENT_ADDSTATUS && lin->iType != GC_EVENT_REMOVESTATUS))) { + CHARRANGE newsel; + newsel.cpMax = -1; + newsel.cpMin = sel.cpMin; + if (newsel.cpMin < 0) + newsel.cpMin = 0; + + SMADD_RICHEDIT3 sm = {}; + sm.cbSize = sizeof(sm); + sm.hwndRichEditControl = m_log.GetHwnd(); + sm.Protocolname = m_si->pszModule; + sm.rangeToReplace = bRedraw ? nullptr : &newsel; + sm.disableRedraw = TRUE; + sm.hContact = m_si->hContact; + CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&sm); + } + + // scroll log to bottom if the log was previously scrolled to bottom, else restore old position + if (bRedraw || (UINT)scroll.nPos >= (UINT)scroll.nMax - scroll.nPage - 5 || scroll.nMax - scroll.nMin - scroll.nPage < 50) + ScrollToBottom(); + else + m_log.SendMsg(EM_SETSCROLLPOS, 0, (LPARAM)&point); + + // do we need to restore the selection + if (oldsel.cpMax != oldsel.cpMin) { + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&oldsel); + m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); + } + + // need to invalidate the window + if (bFlag) { + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); + m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); + m_log.SendMsg(WM_SETREDRAW, TRUE, 0); + InvalidateRect(m_log.GetHwnd(), nullptr, TRUE); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + int CChatRoomDlg::Resizer(UTILRESIZECONTROL *urc) { bool bControl = db_get_b(0, CHAT_MODULE, "ShowTopButtons", 1) != 0; @@ -1081,7 +1179,7 @@ INT_PTR CChatRoomDlg::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_SRMM_MESSAGE: - EnableWindow(m_btnOk.GetHwnd(), GetRichTextLength(m_message.GetHwnd()) != 0); + EnableWindow(m_btnOk.GetHwnd(), m_message.GetRichTextLength() != 0); break; } break; diff --git a/src/core/stdmsg/src/stdafx.h b/src/core/stdmsg/src/stdafx.h index 29d888b6a1..d199fd10d3 100644 --- a/src/core/stdmsg/src/stdafx.h +++ b/src/core/stdmsg/src/stdafx.h @@ -135,7 +135,6 @@ HICON LoadIconEx(const char *pszIcoLibName, bool big); HANDLE GetIconHandle(const char *pszIcolibName);
// tools.cpp
-int GetRichTextLength(HWND hwnd);
void SetButtonsPos(HWND hwndDlg, bool bIsChat);
/////////////////////////////////////////////////////////////////////////////////////////
|