diff options
-rw-r--r-- | include/m_gui.h | 12 | ||||
-rw-r--r-- | libs/win32/mir_core.lib | bin | 315250 -> 316556 bytes | |||
-rw-r--r-- | libs/win64/mir_core.lib | bin | 316184 -> 317528 bytes | |||
-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 |
7 files changed, 110 insertions, 6 deletions
diff --git a/include/m_gui.h b/include/m_gui.h index da0d1e49b5..e94d43f3d3 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -800,7 +800,17 @@ class MIR_CORE_EXPORT CCtrlRichEdit : public CCtrlEdit public:
CCtrlRichEdit(CDlgBase *dlg, int ctrlId);
- int GetRichTextLength() const;
+ // returns text length in bytes if a parameter is omitted or in symbols, if not
+ int GetRichTextLength(int iCodePage = CP_ACP) const;
+
+ // returns a buffer that should be freed using mir_free() or ptrA/ptrW
+ char* GetRichTextRtf(bool bText = false, bool bSelection = false) const; // returns text with formatting
+ char* GetRichTextUtf() const; // returns only text in utf8
+ wchar_t* GetRichText() const; // returns only text in ucs2
+
+ // these methods return text length in Unicode chars
+ int SetRichText(const wchar_t *text);
+ int SetRichTextRtf(const char *text);
};
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex ddc24cb04f..8481522342 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 52b819b92b..eec22a1b26 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib 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"
|