From 6b3d56dbdccc4b608d258a4a7705514e46947e28 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 5 Apr 2017 20:18:35 +0300 Subject: SRMM* plugins switched to CCtrlRichEdit --- plugins/Scriver/src/chat_log.cpp | 6 +-- plugins/Scriver/src/chat_window.cpp | 23 ++++---- plugins/Scriver/src/input.cpp | 6 +-- plugins/Scriver/src/msgdialog.cpp | 12 ++--- plugins/Scriver/src/msglog.cpp | 8 +-- plugins/Scriver/src/utils.cpp | 82 ----------------------------- plugins/Scriver/src/utils.h | 6 --- plugins/TabSRMM/src/chat.h | 1 - plugins/TabSRMM/src/chat_log.cpp | 4 +- plugins/TabSRMM/src/chat_tools.cpp | 8 --- plugins/TabSRMM/src/chat_window.cpp | 14 ++--- plugins/TabSRMM/src/contactcache.cpp | 38 ++++++------- plugins/TabSRMM/src/contactcache.h | 2 +- plugins/TabSRMM/src/controls.cpp | 11 ++-- plugins/TabSRMM/src/generic_msghandlers.cpp | 6 +-- plugins/TabSRMM/src/msgdialog.cpp | 21 +++----- plugins/TabSRMM/src/msgdlgutils.cpp | 44 ++++++++-------- plugins/TabSRMM/src/msgdlgutils.h | 1 - plugins/TabSRMM/src/msgs.h | 3 ++ plugins/TabSRMM/src/sendqueue.cpp | 4 +- plugins/TabSRMM/src/utils.cpp | 21 -------- plugins/TabSRMM/src/utils.h | 1 - 22 files changed, 97 insertions(+), 225 deletions(-) (limited to 'plugins') diff --git a/plugins/Scriver/src/chat_log.cpp b/plugins/Scriver/src/chat_log.cpp index 3d8ea3eb55..34ca7d665f 100644 --- a/plugins/Scriver/src/chat_log.cpp +++ b/plugins/Scriver/src/chat_log.cpp @@ -39,7 +39,7 @@ void CChatRoomDlg::StreamInEvents(LOGINFO* lin, bool bRedraw) streamData.si = m_si; streamData.lin = lin; streamData.bStripFormat = FALSE; - streamData.isFirst = bRedraw ? 1 : (GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE) == 0); + streamData.isFirst = bRedraw ? 1 : m_log.GetRichTextLength() == 0; EDITSTREAM stream = { 0 }; stream.pfnCallback = Srmm_LogStreamCallback; @@ -60,7 +60,7 @@ void CChatRoomDlg::StreamInEvents(LOGINFO* lin, bool bRedraw) m_log.SendMsg(WM_SETREDRAW, FALSE, 0); // set the insertion point at the bottom - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); m_log.SendMsg(EM_EXGETSEL, 0, (LPARAM)&sel); @@ -115,7 +115,7 @@ void CChatRoomDlg::StreamInEvents(LOGINFO* lin, bool bRedraw) // need to invalidate the window if (bFlag) { - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + 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); diff --git a/plugins/Scriver/src/chat_window.cpp b/plugins/Scriver/src/chat_window.cpp index 4efe867148..40ed6a6db3 100644 --- a/plugins/Scriver/src/chat_window.cpp +++ b/plugins/Scriver/src/chat_window.cpp @@ -27,19 +27,20 @@ void CChatRoomDlg::TabAutoComplete() int start = LOWORD(lResult), end = HIWORD(lResult); m_message.SendMsg(EM_SETSEL, end, end); - GETTEXTEX gt = { 0 }; - gt.codepage = 1200; - int iLen = GetRichTextLength(m_message.GetHwnd(), gt.codepage, TRUE); + int iLen = m_message.GetRichTextLength(1200); if (iLen <= 0) return; bool isTopic = false, isRoom = false; wchar_t *pszName = nullptr; wchar_t* pszText = (wchar_t*)mir_alloc(iLen + 100 * sizeof(wchar_t)); + + GETTEXTEX gt = {}; + gt.codepage = 1200; gt.cb = iLen + 99 * sizeof(wchar_t); gt.flags = GT_DEFAULT; - m_message.SendMsg(EM_GETTEXTEX, (WPARAM)>, (LPARAM)pszText); + if (start > 1 && pszText[start - 1] == ' ' && pszText[start - 2] == ':') start -= 2; @@ -311,14 +312,14 @@ void CChatRoomDlg::onClick_Ok(CCtrlButton *pButton) if (!pButton->Enabled()) return; - char *pszRtf = GetRichTextRTF(m_message.GetHwnd()); - if (pszRtf == nullptr) - return; - MODULEINFO *mi = pci->MM_FindModule(m_si->pszModule); if (mi == nullptr) return; + char *pszRtf = m_message.GetRichTextRtf(); + if (pszRtf == nullptr) + return; + TCmdList *cmdListNew = tcmdlist_last(cmdList); while (cmdListNew != nullptr && cmdListNew->temporary) { cmdList = tcmdlist_remove(cmdList, cmdListNew); @@ -369,10 +370,10 @@ void CChatRoomDlg::onClick_Filter(CCtrlButton *pButton) RedrawLog(); } -void CChatRoomDlg::onChange_Message(CCtrlEdit *pEdit) +void CChatRoomDlg::onChange_Message(CCtrlEdit*) { cmdListCurrent = nullptr; - m_btnOk.Enable(GetRichTextLength(pEdit->GetHwnd(), 1200, FALSE) != 0); + m_btnOk.Enable(m_message.GetRichTextLength() != 0); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -425,7 +426,7 @@ void CChatRoomDlg::ScrollToBottom() SetScrollInfo(m_log.GetHwnd(), SB_VERT, &sci, TRUE); CHARRANGE sel; - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE); + 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); } diff --git a/plugins/Scriver/src/input.cpp b/plugins/Scriver/src/input.cpp index 0698cdf2d9..b2ec93eb56 100644 --- a/plugins/Scriver/src/input.cpp +++ b/plugins/Scriver/src/input.cpp @@ -199,7 +199,7 @@ int CScriverWindow::InputAreaShortcuts(HWND hwnd, UINT msg, WPARAM wParam, LPARA } if ((wParam == VK_UP || wParam == VK_DOWN) && isCtrl && !db_get_b(0, SRMM_MODULE, SRMSGSET_AUTOCLOSE, SRMSGDEFSET_AUTOCLOSE)) { - if (cmdList) { + if (cmdList && hwnd == m_message.GetHwnd()) { TCmdList *cmdListNew = nullptr; if (wParam == VK_UP) { if (cmdListCurrent == nullptr) { @@ -209,7 +209,7 @@ int CScriverWindow::InputAreaShortcuts(HWND hwnd, UINT msg, WPARAM wParam, LPARA cmdListNew = tcmdlist_last(cmdList); } if (cmdListNew != nullptr) { - char *textBuffer = GetRichTextUtf(hwnd); + char *textBuffer = m_message.GetRichTextUtf(); if (textBuffer != nullptr) // takes textBuffer to a queue, no leak here cmdList = tcmdlist_append(cmdList, textBuffer, 20, TRUE); @@ -229,7 +229,7 @@ int CScriverWindow::InputAreaShortcuts(HWND hwnd, UINT msg, WPARAM wParam, LPARA if (cmdListNew != nullptr) { SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); - int iLen = SetRichTextRTF(hwnd, cmdListNew->szCmd); + int iLen = m_message.SetRichTextRtf(cmdListNew->szCmd); SendMessage(hwnd, EM_SCROLLCARET, 0, 0); SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 1dce87450c..80585493ba 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -269,7 +269,7 @@ void CSrmmWindow::OnInitDialog() int len = 0; ptrW ptszSavedMsg(db_get_wsa(m_hContact, "SRMM", "SavedMsg")); if (ptszSavedMsg) - len = SetRichText(m_message.GetHwnd(), ptszSavedMsg); + len = m_message.SetRichText(ptszSavedMsg); PostMessage(m_message.GetHwnd(), EM_SETSEL, len, len); } @@ -412,7 +412,7 @@ void CSrmmWindow::OnDestroy() ReleaseSendQueueItems(m_hwnd); if (g_dat.flags & SMF_SAVEDRAFTS) { - ptrA szText(GetRichTextUtf(m_message.GetHwnd())); + ptrA szText(m_message.GetRichTextUtf()); if (szText) db_set_utf(m_hContact, "SRMM", "SavedMsg", szText); else @@ -455,7 +455,7 @@ void CSrmmWindow::onClick_Ok(CCtrlButton *pButton) pf2.dwMask = PFM_RTLPARA; m_message.SendMsg(EM_GETPARAFORMAT, 0, (LPARAM)&pf2); - int bufSize = GetRichTextLength(m_message.GetHwnd(), 1200, TRUE) + 2; + int bufSize = m_message.GetRichTextLength(1200) + 2; ptrW ptszUnicode((wchar_t*)mir_alloc(bufSize * sizeof(wchar_t))); MessageSendQueueItem msi = { 0 }; @@ -582,7 +582,7 @@ void CSrmmWindow::onClick_History(CCtrlButton*) void CSrmmWindow::onChange_Message(CCtrlEdit*) { - int len = GetRichTextLength(m_message.GetHwnd(), 1200, FALSE); + int len = m_message.GetRichTextLength(); cmdListCurrent = nullptr; UpdateReadChars(); EnableWindow(GetDlgItem(m_hwnd, IDOK), len != 0); @@ -701,7 +701,7 @@ void CSrmmWindow::SetDialogToType() m_splitter.Show(); UpdateReadChars(); - EnableWindow(GetDlgItem(m_hwnd, IDOK), GetRichTextLength(m_message.GetHwnd(), 1200, FALSE) ? TRUE : FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDOK), m_message.GetRichTextLength() != 0); SendMessage(m_hwnd, DM_CLISTSETTINGSCHANGED, 0, 0); SendMessage(m_hwnd, WM_SIZE, 0, 0); } @@ -786,7 +786,7 @@ void CSrmmWindow::UpdateReadChars() { if (m_pParent->hwndActive == m_hwnd) { wchar_t szText[256]; - int len = GetRichTextLength(m_message.GetHwnd(), 1200, FALSE); + int len = m_message.GetRichTextLength(1200); StatusBarData sbd; sbd.iItem = 1; diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 0f984c7e2d..a96257bef1 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -777,7 +777,7 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) streamData.hDbEventLast = m_hDbEventLast; streamData.dlgDat = this; streamData.eventsToInsert = count; - streamData.isFirst = fAppend ? GetRichTextLength(m_log.GetHwnd(), CP_ACP, FALSE) == 0 : 1; + streamData.isFirst = fAppend ? m_log.GetRichTextLength() == 0 : 1; streamData.gdat = &g_dat; EDITSTREAM stream = {}; @@ -791,14 +791,14 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) gtxl.flags = GTL_DEFAULT | GTL_PRECISE | GTL_NUMCHARS; gtxl.codepage = 1200; fi.chrg.cpMin = m_log.SendMsg(EM_GETTEXTLENGTHEX, (WPARAM)>xl, 0); - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd(), 1200, FALSE); + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); } else { m_log.SendMsg(WM_SETREDRAW, FALSE, 0); ClearLog(); sel.cpMin = 0; - sel.cpMax = GetRichTextLength(m_log.GetHwnd(), 1200, FALSE); + sel.cpMax = m_log.GetRichTextLength(); m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); fi.chrg.cpMin = 0; m_isMixed = 0; @@ -829,7 +829,7 @@ void CSrmmWindow::StreamInEvents(MEVENT hDbEventFirst, int count, int fAppend) CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&smre); } - int len = GetRichTextLength(m_log.GetHwnd(), 1200, FALSE); + int len = m_log.GetRichTextLength(); m_log.SendMsg(EM_SETSEL, len - 1, len - 1); if (!fAppend) diff --git a/plugins/Scriver/src/utils.cpp b/plugins/Scriver/src/utils.cpp index ddc542ad38..b1585f00b5 100644 --- a/plugins/Scriver/src/utils.cpp +++ b/plugins/Scriver/src/utils.cpp @@ -50,70 +50,6 @@ void logInfo(const char *fmt, ...) } } -int GetRichTextLength(HWND hwnd, int codepage, BOOL inBytes) -{ - GETTEXTLENGTHEX gtl; - gtl.codepage = codepage; - if (inBytes) { - gtl.flags = GTL_NUMBYTES; - } - else { - gtl.flags = GTL_NUMCHARS; - } - gtl.flags |= GTL_PRECISE | GTL_USECRLF; - return (int)SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); -} - -char* GetRichTextUtf(HWND hwnd) -{ - int textBufferSize = GetRichTextLength(hwnd, CP_UTF8, TRUE); - if (textBufferSize == 0) - return nullptr; - - textBufferSize++; - char *textBuffer = (char*)mir_alloc(textBufferSize); - - GETTEXTEX gt = { 0 }; - gt.cb = textBufferSize; - gt.flags = GT_USECRLF; - gt.codepage = CP_UTF8; - SendMessage(hwnd, EM_GETTEXTEX, (WPARAM)>, (LPARAM)textBuffer); - return textBuffer; -} - -int SetRichText(HWND hwnd, const wchar_t *text) -{ - SETTEXTEX st; - st.flags = ST_DEFAULT; - st.codepage = 1200; - SendMessage(hwnd, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)text); - - return GetRichTextLength(hwnd, 1200, FALSE); -} - -int SetRichTextRTF(HWND hwnd, const char *text) -{ - SETTEXTEX st; - st.flags = ST_DEFAULT; - st.codepage = CP_UTF8; - SendMessage(hwnd, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)text); - - return GetRichTextLength(hwnd, 1200, FALSE); -} - -char* GetRichTextRTF(HWND hwnd) -{ - if (hwnd == 0) - return nullptr; - - char *pszText = nullptr; - EDITSTREAM stream = { 0 }; - stream.pfnCallback = Srmm_MessageStreamCallback; - stream.dwCookie = (DWORD_PTR)&pszText; // pass pointer to pointer - SendMessage(hwnd, EM_STREAMOUT, SF_RTFNOOBJS | SFF_PLAINRTF | SF_USECODEPAGE | (CP_UTF8 << 16), (LPARAM)&stream); - return pszText; // pszText contains the text -} - void rtrimText(wchar_t *text) { static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n"; @@ -198,24 +134,6 @@ wchar_t *GetRichEditSelection(HWND hwnd) return (wchar_t*)msi.sendBuffer; } -void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...) -{ - va_list va; - int charsDone; - - va_start(va, fmt); - for (;;) { - charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va); - if (charsDone >= 0) - break; - cbBufferAlloced += 1024; - buffer = (char*)mir_realloc(buffer, cbBufferAlloced); - } - va_end(va); - cbBufferEnd += charsDone; -} - - int MeasureMenuItem(WPARAM, LPARAM lParam) { LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam; diff --git a/plugins/Scriver/src/utils.h b/plugins/Scriver/src/utils.h index ba88ea469d..dc03c0aba9 100644 --- a/plugins/Scriver/src/utils.h +++ b/plugins/Scriver/src/utils.h @@ -36,15 +36,9 @@ enum SEARCHENGINES { wchar_t *limitText(wchar_t *text, int limit); void logInfo(const char *fmt, ...); -int GetRichTextLength(HWND hwnd, int codepage, BOOL inBytes); wchar_t *GetRichEditSelection(HWND hwnd); -char* GetRichTextRTF(HWND hwnd); -char* GetRichTextUtf(HWND hwnd); wchar_t *GetRichTextWord(HWND hwnd, POINT *pt); -int SetRichText(HWND hwnd, const wchar_t *text); -int SetRichTextRTF(HWND hwnd, const char *text); void SearchWord(wchar_t * word, int engine); -void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...); int MeasureMenuItem(WPARAM wParam, LPARAM lParam); int DrawMenuItem(WPARAM wParam, LPARAM lParam); void SetSearchEngineIcons(HMENU hMenu, HIMAGELIST hImageList); diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h index a18054cc5e..e42674d2d0 100644 --- a/plugins/TabSRMM/src/chat.h +++ b/plugins/TabSRMM/src/chat.h @@ -125,7 +125,6 @@ int UM_CompareItem(USERINFO *u1, const wchar_t* pszNick, WORD wStatus); BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight, int bManyFix); int Chat_GetColorIndex(const char* pszModule, COLORREF cr); wchar_t* my_strstri(const wchar_t* s1, const wchar_t* s2); -int GetRichTextLength(HWND hwnd); bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); char GetIndicator(SESSION_INFO *si, LPCTSTR ptszNick, int *iNickIndex); void Chat_SetFilters(SESSION_INFO *si); diff --git a/plugins/TabSRMM/src/chat_log.cpp b/plugins/TabSRMM/src/chat_log.cpp index 037d457fd7..10e0d74476 100644 --- a/plugins/TabSRMM/src/chat_log.cpp +++ b/plugins/TabSRMM/src/chat_log.cpp @@ -866,7 +866,7 @@ void CChatRoomDlg::StreamInEvents(LOGINFO *lin, bool bRedraw) m_log.SendMsg(WM_SETREDRAW, FALSE, 0); // set the insertion point at the bottom - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd()); + sel.cpMin = sel.cpMax = m_log.GetRichTextLength(); m_log.SendMsg(EM_EXSETSEL, 0, (LPARAM)&sel); // fix for the indent... must be a M$ bug @@ -983,7 +983,7 @@ void CChatRoomDlg::StreamInEvents(LOGINFO *lin, bool bRedraw) // need to invalidate the window if (bFlag) { - sel.cpMin = sel.cpMax = GetRichTextLength(m_log.GetHwnd()); + 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); diff --git a/plugins/TabSRMM/src/chat_tools.cpp b/plugins/TabSRMM/src/chat_tools.cpp index a3fe2d7e42..256648b33c 100644 --- a/plugins/TabSRMM/src/chat_tools.cpp +++ b/plugins/TabSRMM/src/chat_tools.cpp @@ -28,14 +28,6 @@ #include "stdafx.h" -int GetRichTextLength(HWND hwnd) -{ - GETTEXTLENGTHEX gtl; - gtl.flags = GTL_PRECISE; - gtl.codepage = CP_ACP; - return (int)SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); -} - static void __stdcall ShowRoomFromPopup(void *pi) { SESSION_INFO *si = (SESSION_INFO*)pi; diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index 8b24b7526c..4d45b95a44 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -636,7 +636,7 @@ void CChatRoomDlg::onClick_OK(CCtrlButton*) if (mi == nullptr) return; - ptrA pszRtf(Message_GetFromStream(m_message.GetHwnd())); + ptrA pszRtf(m_message.GetRichTextRtf()); pci->SM_AddCommand(m_si->ptszID, m_si->pszModule, pszRtf); CMStringW ptszText(ptrW(mir_utf8decodeW(pszRtf))); @@ -715,8 +715,8 @@ void CChatRoomDlg::onChange_Message(CCtrlEdit*) UpdateReadChars(); m_dwLastActivity = GetTickCount(); m_pContainer->dwLastActivity = m_dwLastActivity; - m_btnOk.SendMsg(BUTTONSETASNORMAL, GetRichTextLength(m_message.GetHwnd()) != 0, 0); - m_btnOk.Enable(GetRichTextLength(m_message.GetHwnd()) != 0); + m_btnOk.SendMsg(BUTTONSETASNORMAL, m_message.GetRichTextLength() != 0, 0); + m_btnOk.Enable(m_message.GetRichTextLength() != 0); // Typing support for GCW_PRIVMESS sessions if (m_si->iType == GCW_PRIVMESS) { @@ -996,7 +996,7 @@ LRESULT CChatRoomDlg::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) return CSkin::DrawRichEditFrame(m_log.GetHwnd(), this, ID_EXTBKHISTORY, msg, wParam, lParam, stubLogProc); case WM_COPY: - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); case WM_SETCURSOR: if (g_Settings.bClickableNicks && (LOWORD(lParam) == HTCLIENT)) { @@ -1041,7 +1041,7 @@ LRESULT CChatRoomDlg::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) return TRUE; } if (wParam == VK_INSERT && GetKeyState(VK_CONTROL) & 0x8000) - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); break; case WM_SYSKEYUP: @@ -1070,7 +1070,7 @@ LRESULT CChatRoomDlg::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) bool isCtrl, isShift, isAlt; KbdState(isShift, isCtrl, isAlt); if (wParam == 0x03 && isCtrl) // Ctrl+C - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); break; } @@ -1333,7 +1333,7 @@ LRESULT CChatRoomDlg::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) if (!m_si->lpCurrentCommand || !m_si->lpCurrentCommand->last) { // Next command is not defined. It means currently entered text is not saved in the history and it // need to be saved in the window context. - char *enteredText = Message_GetFromStream(m_hwnd); + char *enteredText = m_message.GetRichTextRtf(); if (m_enteredText) mir_free(m_enteredText); diff --git a/plugins/TabSRMM/src/contactcache.cpp b/plugins/TabSRMM/src/contactcache.cpp index 12c3361463..b612be884a 100644 --- a/plugins/TabSRMM/src/contactcache.cpp +++ b/plugins/TabSRMM/src/contactcache.cpp @@ -229,24 +229,25 @@ void CContactCache::setWindowData(CSrmmWindow *dat) // saves message to the input history. // it's using streamout in UTF8 format - no unicode "issues" and all RTF formatting is saved to the history. -void CContactCache::saveHistory(WPARAM wParam, LPARAM) +void CContactCache::saveHistory(int iHistorySize) { if (m_dat == nullptr) return; int oldTop = 0; - if (wParam) { + if (iHistorySize) { oldTop = m_iHistoryTop; - m_iHistoryTop = (int)wParam; + m_iHistoryTop = iHistorySize; } - char *szFromStream = ::Message_GetFromStream(GetDlgItem(m_dat->GetHwnd(), IDC_SRMM_MESSAGE), SF_RTFNOOBJS | SFF_PLAINRTF | SF_NCRFORNONASCII); + CCtrlRichEdit &pEntry = m_dat->GetEntry(); + ptrA szFromStream(pEntry.GetRichTextRtf()); if (szFromStream != nullptr) { - size_t iLength = 0, iStreamLength = 0; - iLength = iStreamLength = (mir_strlen(szFromStream) + 1); + size_t iLength, iStreamLength; + iLength = iStreamLength = mir_strlen(szFromStream) + 1; if (iLength > 0 && m_history != nullptr) { // XXX: iLength > 1 ? - if ((m_iHistoryTop == m_iHistorySize) && oldTop == 0) { // shift the stack down... + if (m_iHistoryTop == m_iHistorySize && oldTop == 0) { // shift the stack down... TInputHistory ihTemp = m_history[0]; m_iHistoryTop--; ::memmove((void*)&m_history[0], (void*)&m_history[1], (m_iHistorySize - 1) * sizeof(TInputHistory)); @@ -274,7 +275,6 @@ void CContactCache::saveHistory(WPARAM wParam, LPARAM) } } } - mir_free(szFromStream); } if (oldTop) m_iHistoryTop = oldTop; @@ -290,13 +290,14 @@ void CContactCache::inputHistoryEvent(WPARAM wParam) return; if (m_history != nullptr && m_history[0].szText != nullptr) { // at least one entry needs to be alloced, otherwise we get a nice infinite loop ;) - HWND hwndEdit = ::GetDlgItem(m_dat->GetHwnd(), IDC_SRMM_MESSAGE); + CCtrlRichEdit &pEntry = m_dat->GetEntry(); + SETTEXTEX stx = { ST_DEFAULT, CP_UTF8 }; if (m_dat->m_dwFlags & MWF_NEEDHISTORYSAVE) { m_iHistoryCurrent = m_iHistoryTop; - if (::GetWindowTextLength(hwndEdit) > 0) - saveHistory(m_iHistorySize, 0); + if (::GetWindowTextLength(pEntry.GetHwnd()) > 0) + saveHistory(m_iHistorySize); else m_history[m_iHistorySize].szText[0] = (wchar_t)'\0'; } @@ -312,20 +313,19 @@ void CContactCache::inputHistoryEvent(WPARAM wParam) } if (m_iHistoryCurrent == m_iHistoryTop) { if (m_history[m_iHistorySize].szText != nullptr) { // replace the temp buffer - ::SetWindowText(hwndEdit, L""); - ::SendMessage(hwndEdit, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_history[m_iHistorySize].szText); - ::SendMessage(hwndEdit, EM_SETSEL, -1, -1); + pEntry.SetText(L""); + pEntry.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_history[m_iHistorySize].szText); + pEntry.SendMsg(EM_SETSEL, -1, -1); } } else { + pEntry.SetText(L""); if (m_history[m_iHistoryCurrent].szText != nullptr) { - ::SetWindowText(hwndEdit, L""); - ::SendMessage(hwndEdit, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_history[m_iHistoryCurrent].szText); - ::SendMessage(hwndEdit, EM_SETSEL, -1, -1); + pEntry.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_history[m_iHistoryCurrent].szText); + pEntry.SendMsg(EM_SETSEL, -1, -1); } - else ::SetWindowText(hwndEdit, L""); } - ::SendMessage(m_dat->GetHwnd(), WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(hwndEdit), EN_CHANGE), (LPARAM)hwndEdit); + pEntry.OnChange(&pEntry); m_dat->m_dwFlags &= ~MWF_NEEDHISTORYSAVE; } } diff --git a/plugins/TabSRMM/src/contactcache.h b/plugins/TabSRMM/src/contactcache.h index 8dbe60e8d6..226c6d0a4e 100644 --- a/plugins/TabSRMM/src/contactcache.h +++ b/plugins/TabSRMM/src/contactcache.h @@ -116,7 +116,7 @@ struct CContactCache : public MZeroedObject /* * input history */ - void saveHistory(WPARAM wParam, LPARAM lParam); + void saveHistory(int iHistorySize = 0); void inputHistoryEvent(WPARAM wParam); static CContactCache* getContactCache(MCONTACT hContact); diff --git a/plugins/TabSRMM/src/controls.cpp b/plugins/TabSRMM/src/controls.cpp index b53bd9faf3..b780f28f2e 100644 --- a/plugins/TabSRMM/src/controls.cpp +++ b/plugins/TabSRMM/src/controls.cpp @@ -987,17 +987,12 @@ LONG_PTR CALLBACK CTabBaseDlg::StatusBarSubclassProc(HWND hWnd, UINT msg, WPARAM } SendMessage(hWnd, SB_GETRECT, 1, (LPARAM)&rc); if (PtInRect(&rc, pt)) { - int iLength = 0; - GETTEXTLENGTHEX gtxl = { 0 }; int iQueued = db_get_dw(dat->m_hContact, "SendLater", "count", 0); - gtxl.codepage = CP_UTF8; - gtxl.flags = GTL_DEFAULT | GTL_PRECISE | GTL_NUMBYTES; - iLength = SendDlgItemMessage(dat->GetHwnd(), IDC_SRMM_MESSAGE, EM_GETTEXTLENGTHEX, (WPARAM)>xl, 0); tooltip_active = TRUE; - const wchar_t *szFormat = TranslateT("There are %d pending send jobs. Message length: %d bytes, message length limit: %d bytes\n\n%d messages are queued for later delivery"); - - mir_snwprintf(wBuf, szFormat, dat->m_iOpenJobs, iLength, dat->m_nMax ? dat->m_nMax : 20000, iQueued); + mir_snwprintf(wBuf, + TranslateT("There are %d pending send jobs. Message length: %d bytes, message length limit: %d bytes\n\n%d messages are queued for later delivery"), + dat->m_iOpenJobs, dat->m_message.GetRichTextLength(CP_UTF8), dat->m_nMax ? dat->m_nMax : 20000, iQueued); CallService("mToolTip/ShowTipW", (WPARAM)wBuf, (LPARAM)&ti); } diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 0137a4ce52..7cc4f4c7ee 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -534,7 +534,7 @@ void CTabBaseDlg::DM_InitRichEdit() char *szStreamOut = nullptr; if (!fIsChat && GetWindowTextLength(m_message.GetHwnd()) > 0) - szStreamOut = Message_GetFromStream(m_message.GetHwnd()); + szStreamOut = m_message.GetRichTextRtf(); SetWindowText(m_message.GetHwnd(), L""); m_log.SendMsg(EM_SETBKGNDCOLOR, 0, colour); @@ -1475,7 +1475,7 @@ void CTabBaseDlg::DM_ErrorDetected(int type, int flag) case MSGERROR_CANCEL: case MSGERROR_SENDLATER: if (m_dwFlags & MWF_ERRORSTATE) { - m_cache->saveHistory(0, 0); + m_cache->saveHistory(); if (type == MSGERROR_SENDLATER) sendQueue->doSendLater(m_iCurrentQueueError, this); // to be implemented at a later time m_iOpenJobs--; @@ -1497,7 +1497,7 @@ void CTabBaseDlg::DM_ErrorDetected(int type, int flag) if (m_dwFlags & MWF_ERRORSTATE) { int resent = 0; - m_cache->saveHistory(0, 0); + m_cache->saveHistory(); if (m_iCurrentQueueError >= 0 && m_iCurrentQueueError < SendQueue::NR_SENDJOBS) { SendJob *job = sendQueue->getJobByIndex(m_iCurrentQueueError); if (job->iSendId == 0 && job->hContact == 0) diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index da9531b32f..512d30b786 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -891,7 +891,7 @@ void CSrmmWindow::OnDestroy() Skin_LoadProtoIcon(m_cache->getActiveProto(), m_cache->getActiveStatus()), 1, PluginConfig.g_hMenuRecent); if (m_hContact) { if (!m_bEditNotesActive) { - char *msg = Message_GetFromStream(m_message.GetHwnd(), SF_TEXT); + char *msg = m_message.GetRichTextRtf(true); if (msg) { db_set_utf(m_hContact, SRMSGMOD, "SavedMsg", msg); mir_free(msg); @@ -1095,7 +1095,7 @@ void CSrmmWindow::onClick_Ok(CCtrlButton*) if (GetSendButtonState(m_hwnd) == PBS_DISABLED) return; - ptrA streamOut(Message_GetFromStream(m_message.GetHwnd(), final_sendformat ? 0 : SF_TEXT)); + ptrA streamOut(m_message.GetRichTextRtf(!final_sendformat)); if (streamOut == nullptr) return; @@ -1142,7 +1142,7 @@ void CSrmmWindow::onClick_Ok(CCtrlButton*) if (m_sendMode & SMODE_CONTAINER && m_pContainer->m_hwndActive == m_hwnd && GetForegroundWindow() == m_pContainer->m_hwnd) { int tabCount = TabCtrl_GetItemCount(m_hwndParent); - ptrA szFromStream(Message_GetFromStream(m_message.GetHwnd(), m_SendFormat ? 0 : SF_TEXT)); + ptrA szFromStream(m_message.GetRichTextRtf(!m_SendFormat)); TCITEM tci = {}; tci.mask = TCIF_PARAM; @@ -1264,7 +1264,7 @@ void CSrmmWindow::onClick_Quote(CCtrlButton*) mir_free(szConverted); } else { - ptrA szFromStream(Message_GetFromStream(m_log.GetHwnd(), SF_TEXT | SFF_SELECTION)); + ptrA szFromStream(m_log.GetRichTextRtf(true, true)); ptrW converted(mir_utf8decodeW(szFromStream)); Utils::FilterEventMarkers(converted); ptrW szQuoted(QuoteText(converted)); @@ -1812,15 +1812,10 @@ int CSrmmWindow::OnFilter(MSGFILTER *pFilter) cr.cpMin = cr.cpMax; if (isCtrl) { SETTEXTEX stx = { ST_KEEPUNDO | ST_SELECTION, CP_UTF8 }; - char *streamOut = nullptr; - if (isAlt) - streamOut = Message_GetFromStream(m_log.GetHwnd(), SF_RTFNOOBJS | SFF_PLAINRTF | SFF_SELECTION); - else - streamOut = Message_GetFromStream(m_log.GetHwnd(), SF_TEXT | SFF_SELECTION); + ptrA streamOut(m_log.GetRichTextRtf(!isAlt, true)); if (streamOut) { Utils::FilterEventMarkers(streamOut); m_message.SendMsg(EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)streamOut); - mir_free(streamOut); } SetFocus(m_message.GetHwnd()); } @@ -1870,7 +1865,7 @@ LRESULT CSrmmWindow::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) case WM_CHAR: KbdState(isShift, isCtrl, isAlt); if (wParam == 0x03 && isCtrl) // Ctrl+C - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); if (wParam == 0x11 && isCtrl) // Ctrl+Q m_btnQuote.OnClick(&m_btnQuote); break; @@ -1900,11 +1895,11 @@ LRESULT CSrmmWindow::WndProc_Log(UINT msg, WPARAM wParam, LPARAM lParam) case WM_KEYDOWN: KbdState(isShift, isCtrl, isAlt); if (wParam == VK_INSERT && isCtrl) - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); break; case WM_COPY: - return Utils::WMCopyHandler(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + return WMCopyHandler(msg, wParam, lParam); case WM_NCCALCSIZE: return CSkin::NcCalcRichEditFrame(m_log.GetHwnd(), this, ID_EXTBKHISTORY, msg, wParam, lParam, stubLogProc); diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index a00131b43c..a05ad3a6f1 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -786,29 +786,6 @@ void CTabBaseDlg::FlashOnClist(MEVENT hEvent, DBEVENTINFO *dbei) } ///////////////////////////////////////////////////////////////////////////////////////// -// retrieve contents of the richedit control by streaming.Used to get the -// typed message before sending it. -// caller must mir_free the returned pointer. -// UNICODE version returns UTF-8 encoded string. - -char* TSAPI Message_GetFromStream(HWND hwndRtf, DWORD dwPassedFlags) -{ - if (hwndRtf == 0) - return nullptr; - - DWORD dwFlags = (CP_UTF8 << 16) | SF_USECODEPAGE; - if (dwPassedFlags == 0) - dwFlags |= (SF_RTFNOOBJS | SFF_PLAINRTF); - else - dwFlags |= dwPassedFlags; - - char *pszText = nullptr; - EDITSTREAM stream = { 0 }; - stream.pfnCallback = Srmm_MessageStreamCallback; - stream.dwCookie = (DWORD_PTR)&pszText; // pass pointer to pointer - SendMessage(hwndRtf, EM_STREAMOUT, dwFlags, (LPARAM)&stream); - return pszText; // pszText contains the text -} static wchar_t tszRtfBreaks[] = L" \\\n\r"; @@ -1702,6 +1679,27 @@ void CTabBaseDlg::KbdState(bool &isShift, bool &isControl, bool &isAlt) isAlt = (kstate[VK_MENU] & 0x80) != 0; } +///////////////////////////////////////////////////////////////////////////////////////// +// generic handler for the WM_COPY message in message log/chat history richedit control(s). +// it filters out the invisible event boundary markers from the text copied to the clipboard. +// WINE Fix: overwrite clippboad data from original control data + +LRESULT CTabBaseDlg::WMCopyHandler(UINT msg, WPARAM wParam, LPARAM lParam) +{ + LRESULT result = mir_callNextSubclass(m_log.GetHwnd(), stubLogProc, msg, wParam, lParam); + + ptrA szFromStream(m_log.GetRichTextRtf(true, true)); + if (szFromStream != nullptr) { + ptrW converted(mir_utf8decodeW(szFromStream)); + if (converted != nullptr) { + Utils::FilterEventMarkers(converted); + Utils::CopyToClipBoard(converted, m_log.GetHwnd()); + } + } + + return result; +} + ///////////////////////////////////////////////////////////////////////////////////////// // calculate the minimum required client height for the given message // window layout diff --git a/plugins/TabSRMM/src/msgdlgutils.h b/plugins/TabSRMM/src/msgdlgutils.h index 452dc2502f..cd2362ca59 100644 --- a/plugins/TabSRMM/src/msgdlgutils.h +++ b/plugins/TabSRMM/src/msgdlgutils.h @@ -33,7 +33,6 @@ void TSAPI ProcessAvatarChange(HWND hwnd, LPARAM lParam); int TSAPI CheckValidSmileyPack(const char *szProto, MCONTACT hContact); wchar_t* TSAPI QuoteText(const wchar_t *text); -char* TSAPI Message_GetFromStream(HWND hwndRtf, DWORD dwPassedFlags = 0); UINT TSAPI GetIEViewMode(MCONTACT hContact); void TSAPI LoadOverrideTheme(TContainerData *pContainer); void TSAPI LoadThemeDefaults(TContainerData *pContainer); diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 434f785275..a735db1f04 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -256,6 +256,7 @@ protected: bool IsAutoSplitEnabled() const; void ResizeIeView(); void ShowPopupMenu(const CCtrlBase&, POINT pt); + LRESULT WMCopyHandler(UINT uMsg, WPARAM wParam, LPARAM lParam); public: DWORD m_dwFlags; @@ -370,6 +371,8 @@ public: static LONG_PTR CALLBACK StatusBarSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + __forceinline CCtrlRichEdit& GetEntry() { return m_message; } + HWND DM_CreateClist(); void DM_EventAdded(WPARAM wParam, LPARAM lParam); void DM_InitRichEdit(); diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index 6e54e8d65e..8c7557a11f 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -103,7 +103,7 @@ entry_found: HWND hwndDlg = dat->GetHwnd(); - dat->m_cache->saveHistory(0, 0); + dat->m_cache->saveHistory(); ::SetDlgItemText(hwndDlg, IDC_SRMM_MESSAGE, L""); ::SetFocus(GetDlgItem(hwndDlg, IDC_SRMM_MESSAGE)); @@ -581,7 +581,7 @@ int SendQueue::doSendLater(int iJobIndex, CTabBaseDlg *dat, MCONTACT hContact, b dat->StreamInEvents(0, 1, 1, &dbei); if (dat->m_hDbEventFirst == 0) SendMessage(dat->GetHwnd(), DM_REMAKELOG, 0, 0); - dat->m_cache->saveHistory(0, 0); + dat->m_cache->saveHistory(); dat->EnableSendButton(false); if (dat->m_pContainer->m_hwndActive == dat->GetHwnd()) dat->UpdateReadChars(); diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 1e66c60cc8..fe5302d2fd 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -975,27 +975,6 @@ size_t Utils::CopyToClipBoard(const wchar_t *str, const HWND hwndOwner) return i; } -///////////////////////////////////////////////////////////////////////////////////////// -// generic handler for the WM_COPY message in message log/chat history richedit control(s). -// it filters out the invisible event boundary markers from the text copied to the clipboard. -// WINE Fix: overwrite clippboad data from original control data - -LRESULT Utils::WMCopyHandler(HWND hwnd, WNDPROC oldWndProc, UINT msg, WPARAM wParam, LPARAM lParam) -{ - LRESULT result = mir_callNextSubclass(hwnd, oldWndProc, msg, wParam, lParam); - - ptrA szFromStream(Message_GetFromStream(hwnd, SF_TEXT | SFF_SELECTION)); - if (szFromStream != nullptr) { - ptrW converted(mir_utf8decodeW(szFromStream)); - if (converted != nullptr) { - Utils::FilterEventMarkers(converted); - Utils::CopyToClipBoard(converted, hwnd); - } - } - - return result; -} - ///////////////////////////////////////////////////////////////////////////////////////// // file list handler diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h index 4af0af042a..f35963f505 100644 --- a/plugins/TabSRMM/src/utils.h +++ b/plugins/TabSRMM/src/utils.h @@ -88,7 +88,6 @@ public: static LPTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich); static size_t CopyToClipBoard(const wchar_t *str, const HWND hwndOwner); - static LRESULT WMCopyHandler(HWND hwnd, WNDPROC oldWndProc, UINT uMsg, WPARAM wParam, LPARAM lParam); static void AddToFileList(wchar_t ***pppFiles, int *totalCount, LPCTSTR szFilename); -- cgit v1.2.3