diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-09 15:13:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-09 15:13:13 +0300 |
commit | 017f8e72ac56a88ecaea40dd1c52b1da0ae46986 (patch) | |
tree | 63f9429a30caa5a96dc18431c225b8d8aa57d83c /src | |
parent | 6bf18e4265c8a0938d12e98eef1562b1ee4bc97b (diff) |
common rtf management code moved to the core
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/chat_util.cpp | 60 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/srmm_util.cpp | 74 |
4 files changed, 80 insertions, 58 deletions
diff --git a/src/core/stdmsg/src/chat_util.cpp b/src/core/stdmsg/src/chat_util.cpp index 00dfb9a49a..26d8f37f12 100644 --- a/src/core/stdmsg/src/chat_util.cpp +++ b/src/core/stdmsg/src/chat_util.cpp @@ -21,36 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" - -// The code for streaming the text is to a large extent copied from -// the srmm module and then modified to fit the chat module. - -static DWORD CALLBACK Log_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) -{ - LOGSTREAMDATA *lstrdat = (LOGSTREAMDATA*)dwCookie; - if (lstrdat) { - // create the RTF - if (lstrdat->buffer == NULL) { - lstrdat->bufferOffset = 0; - lstrdat->buffer = pci->Log_CreateRTF(lstrdat); - lstrdat->bufferLen = (int)mir_strlen(lstrdat->buffer); - } - - // give the RTF to the RE control - *pcb = min(cb, lstrdat->bufferLen - lstrdat->bufferOffset); - memcpy(pbBuff, lstrdat->buffer + lstrdat->bufferOffset, *pcb); - lstrdat->bufferOffset += *pcb; - - // free stuff if the streaming operation is complete - if (lstrdat->bufferOffset == lstrdat->bufferLen) { - mir_free(lstrdat->buffer); - lstrdat->buffer = NULL; - } - } - - return 0; -} - void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, BOOL bRedraw) { if (hwndDlg == 0 || lin == 0 || si == 0) @@ -71,7 +41,7 @@ void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, BOOL bRedra BOOL bFlag = FALSE; EDITSTREAM stream = {}; - stream.pfnCallback = Log_StreamCallback; + stream.pfnCallback = Srmm_LogStreamCallback; stream.dwCookie = (DWORD_PTR)& streamData; SCROLLINFO scroll; @@ -156,32 +126,6 @@ void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, BOOL bRedra ///////////////////////////////////////////////////////////////////////////////////////// -static DWORD CALLBACK Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) -{ - static DWORD dwRead; - char **ppText = (char **)dwCookie; - - if (*ppText == NULL) { - *ppText = (char *)mir_alloc(cb + 1); - memcpy(*ppText, pbBuff, cb); - (*ppText)[cb] = 0; - *pcb = cb; - dwRead = cb; - } - else { - char *p = (char *)mir_alloc(dwRead + cb + 1); - memcpy(p, *ppText, dwRead); - memcpy(p + dwRead, pbBuff, cb); - p[dwRead + cb] = 0; - mir_free(*ppText); - *ppText = p; - *pcb = cb; - dwRead += cb; - } - - return 0; -} - char* Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si) { if (hwndDlg == 0 || si == 0) @@ -190,7 +134,7 @@ char* Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si) char* pszText = NULL; EDITSTREAM stream; memset(&stream, 0, sizeof(stream)); - stream.pfnCallback = Message_StreamCallback; + stream.pfnCallback = Srmm_MessageStreamCallback; stream.dwCookie = (DWORD_PTR)&pszText; // pass pointer to pointer DWORD dwFlags = SF_RTFNOOBJS | SFF_PLAINRTF | SF_USECODEPAGE | (CP_UTF8 << 16); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 58a81567f4..e725d21d0f 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -408,3 +408,5 @@ ProtoGetAvatarMimeType @401 ??2CSrmmBaseDialog@@SAPAXI@Z @409 NONAME
??3CSrmmBaseDialog@@SAXPAX@Z @410 NONAME
?isChat@CSrmmBaseDialog@@QBE_NXZ @411 NONAME
+Srmm_LogStreamCallback @412
+Srmm_MessageStreamCallback @413
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 4616073840..b23014f010 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -408,3 +408,5 @@ ProtoGetAvatarMimeType @401 ??2CSrmmBaseDialog@@SAPEAX_K@Z @409 NONAME
??3CSrmmBaseDialog@@SAXPEAX@Z @410 NONAME
?isChat@CSrmmBaseDialog@@QEBA_NXZ @411 NONAME
+Srmm_LogStreamCallback @412
+Srmm_MessageStreamCallback @413
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp new file mode 100644 index 0000000000..78ed59e436 --- /dev/null +++ b/src/mir_app/src/srmm_util.cpp @@ -0,0 +1,74 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 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" +#include "chat.h" + +MIR_APP_DLL(DWORD) CALLBACK Srmm_LogStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) +{ + LOGSTREAMDATA *lstrdat = (LOGSTREAMDATA*)dwCookie; + if (lstrdat) { + // create the RTF + if (lstrdat->buffer == nullptr) { + lstrdat->bufferOffset = 0; + lstrdat->buffer = chatApi.Log_CreateRTF(lstrdat); + lstrdat->bufferLen = (int)mir_strlen(lstrdat->buffer); + } + + // give the RTF to the RE control + *pcb = min(cb, LONG(lstrdat->bufferLen - lstrdat->bufferOffset)); + memcpy(pbBuff, lstrdat->buffer + lstrdat->bufferOffset, *pcb); + lstrdat->bufferOffset += *pcb; + + // free stuff if the streaming operation is complete + if (lstrdat->bufferOffset == lstrdat->bufferLen) { + mir_free(lstrdat->buffer); + lstrdat->buffer = nullptr; + } + } + + return 0; +} + +MIR_APP_DLL(DWORD) CALLBACK Srmm_MessageStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) +{ + static DWORD dwRead; + char **ppText = (char **)dwCookie; + + if (*ppText == nullptr) { + *ppText = (char *)mir_alloc(cb + 2); + memcpy(*ppText, pbBuff, cb); + *pcb = cb; + dwRead = cb; + *(*ppText + cb) = '\0'; + } + else { + char *p = (char *)mir_realloc(*ppText, dwRead + cb + 2); + memcpy(p + dwRead, pbBuff, cb); + *ppText = p; + *pcb = cb; + dwRead += cb; + *(*ppText + dwRead) = '\0'; + } + return 0; +} |