diff options
author | George Hazan <ghazan@miranda.im> | 2017-04-05 20:14:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-04-05 20:14:14 +0300 |
commit | 4164d60646b408abf62bc8170165aedcc574d088 (patch) | |
tree | 531de09ce40e5b9c9dc527c9e2548407b72e3255 /src | |
parent | a81a0f3e536ebcd46b1bacf3539cd8d8fe0e0ccd (diff) |
more methods for CCtrlRichEdit: GetRichTextRtf, GetRichTextUtf, GetRichText, SetRichText, SetRichTextRtf
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_core/src/CCtrlRichEdit.cpp | 91 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 6 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 6 | ||||
-rw-r--r-- | src/mir_core/src/stdafx.h | 1 |
4 files changed, 99 insertions, 5 deletions
diff --git a/src/mir_core/src/CCtrlRichEdit.cpp b/src/mir_core/src/CCtrlRichEdit.cpp index 42bc243603..136bbf116a 100644 --- a/src/mir_core/src/CCtrlRichEdit.cpp +++ b/src/mir_core/src/CCtrlRichEdit.cpp @@ -29,10 +29,95 @@ CCtrlRichEdit::CCtrlRichEdit(CDlgBase *dlg, int ctrlId) : CCtrlEdit(dlg, ctrlId) {} -int CCtrlRichEdit::GetRichTextLength() const +int CCtrlRichEdit::GetRichTextLength(int iCodePage) const { GETTEXTLENGTHEX gtl; - gtl.flags = GTL_PRECISE; - gtl.codepage = CP_ACP; + gtl.codepage = iCodePage; + gtl.flags = GTL_PRECISE | GTL_USECRLF; + if (iCodePage == CP_ACP) + gtl.flags |= GTL_NUMBYTES; + else + gtl.flags |= GTL_NUMCHARS; + return (int)SendMessage(m_hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); } + +char* CCtrlRichEdit::GetRichTextUtf() const +{ + int textBufferSize = GetRichTextLength(CP_UTF8); + if (textBufferSize == 0) + return nullptr; + + textBufferSize++; + char *textBuffer = (char*)mir_alloc(textBufferSize+1); + + GETTEXTEX gt = {}; + gt.cb = textBufferSize; + gt.flags = GT_USECRLF; + gt.codepage = CP_UTF8; + SendMessage(m_hwnd, EM_GETTEXTEX, (WPARAM)>, (LPARAM)textBuffer); + return textBuffer; +} + +int CCtrlRichEdit::SetRichText(const wchar_t *text) +{ + SETTEXTEX st; + st.flags = ST_DEFAULT; + st.codepage = 1200; + SendMessage(m_hwnd, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)text); + + return GetRichTextLength(1200); +} + +int CCtrlRichEdit::SetRichTextRtf(const char *text) +{ + SETTEXTEX st; + st.flags = ST_DEFAULT; + st.codepage = CP_UTF8; + SendMessage(m_hwnd, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)text); + + return GetRichTextLength(1200); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static DWORD CALLBACK 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; +} + +char* CCtrlRichEdit::GetRichTextRtf(bool bText, bool bSelection) const +{ + char *pszText = nullptr; + DWORD dwFlags = SF_USECODEPAGE | (CP_UTF8 << 16); + if (bText) + dwFlags |= SF_TEXT; + else + dwFlags |= SF_RTFNOOBJS | SFF_PLAINRTF; + if (bSelection) + dwFlags |= SFF_SELECTION; + + EDITSTREAM stream = { 0 }; + stream.pfnCallback = MessageStreamCallback; + stream.dwCookie = (DWORD_PTR)&pszText; // pass pointer to pointer + SendMessage(m_hwnd, EM_STREAMOUT, dwFlags, (LPARAM)&stream); + return pszText; // pszText contains the text +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 2a45d39427..ee3c8ca055 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1042,4 +1042,8 @@ CallFunctionSync @1170 ??0CCtrlRichEdit@@QAE@PAVCDlgBase@@H@Z @1229 NONAME
??1CCtrlRichEdit@@UAE@XZ @1230 NONAME
??_7CCtrlRichEdit@@6B@ @1231 NONAME
-?GetRichTextLength@CCtrlRichEdit@@QBEHXZ @1232 NONAME
+?GetRichTextLength@CCtrlRichEdit@@QBEHH@Z @1232 NONAME
+?SetRichText@CCtrlRichEdit@@QAEHPB_W@Z @1233 NONAME
+?SetRichTextRtf@CCtrlRichEdit@@QAEHPBD@Z @1234 NONAME
+?GetRichTextUtf@CCtrlRichEdit@@QBEPADXZ @1235 NONAME
+?GetRichTextRtf@CCtrlRichEdit@@QBEPAD_N0@Z @1236 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index a1865697b3..215d63fec8 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1042,4 +1042,8 @@ CallFunctionSync @1170 ??0CCtrlRichEdit@@QEAA@PEAVCDlgBase@@H@Z @1229 NONAME
??1CCtrlRichEdit@@UEAA@XZ @1230 NONAME
??_7CCtrlRichEdit@@6B@ @1231 NONAME
-?GetRichTextLength@CCtrlRichEdit@@QEBAHXZ @1232 NONAME
+?GetRichTextLength@CCtrlRichEdit@@QEBAHH@Z @1232 NONAME
+?SetRichText@CCtrlRichEdit@@QEAAHPEB_W@Z @1233 NONAME
+?SetRichTextRtf@CCtrlRichEdit@@QEAAHPEBD@Z @1234 NONAME
+?GetRichTextUtf@CCtrlRichEdit@@QEBAPEADXZ @1235 NONAME
+?GetRichTextRtf@CCtrlRichEdit@@QEBAPEAD_N0@Z @1236 NONAME
diff --git a/src/mir_core/src/stdafx.h b/src/mir_core/src/stdafx.h index c66328f039..47b504c123 100644 --- a/src/mir_core/src/stdafx.h +++ b/src/mir_core/src/stdafx.h @@ -61,6 +61,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_protocols.h>
#include <m_button.h>
#include <m_gui.h>
+#include <m_chat_int.h>
#include "miranda.h"
|