summaryrefslogtreecommitdiff
path: root/libs/mTextControl
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-12-20 16:43:14 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-12-20 16:43:14 +0300
commitd80970d9b26b5e9b7868ec61349490da5e24dc64 (patch)
tree4f77d2094176eeaecfb99c9d7ad902124752503c /libs/mTextControl
parent633f26707366cca4bd876d8f874f3ed116560e0d (diff)
libTextControl: contact settings extracted to MTextSetProto
Diffstat (limited to 'libs/mTextControl')
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.h15
-rw-r--r--libs/mTextControl/src/services.cpp32
-rw-r--r--libs/mTextControl/src/stdafx.h1
-rw-r--r--libs/mTextControl/src/textcontrol.cpp17
4 files changed, 44 insertions, 21 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h
index 82993e903a..932ec1a63b 100644
--- a/libs/mTextControl/src/FormattedTextDraw.h
+++ b/libs/mTextControl/src/FormattedTextDraw.h
@@ -111,6 +111,21 @@ public:
HRESULT InitDefaultParaFormat();
};
+struct TextObject
+{
+ uint32_t options = 0;
+ MCONTACT hContact = INVALID_CONTACT_ID;
+ const char *szProto = nullptr;
+ CFormattedTextDraw *ftd = nullptr;
+
+ TextObject() {}
+
+ ~TextObject()
+ {
+ delete ftd;
+ }
+};
+
void bbCodeParse(CFormattedTextDraw *ts);
#endif //__FORMATTEDTEXTDRAW_H_
diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp
index 35efa5f5f7..3dcb82fd19 100644
--- a/libs/mTextControl/src/services.cpp
+++ b/libs/mTextControl/src/services.cpp
@@ -20,20 +20,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "stdafx.h"
#include "FormattedTextDraw.h"
-struct TextObject
-{
- uint32_t options = 0;
- const char *szProto = nullptr;
- CFormattedTextDraw *ftd = nullptr;
-
- TextObject() {}
-
- ~TextObject()
- {
- delete ftd;
- }
-};
-
/////////////////////////////////////////////////////////////////////////////////////////
// Helper functions
@@ -74,10 +60,9 @@ DWORD CALLBACK EditStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb,
return 0;
}
-MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text)
+MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const wchar_t *text)
{
TextObject *result = new TextObject;
- result->szProto = szProto;
result->options = TextUserGetOptions(userHandle);
result->ftd = new CFormattedTextDraw();
InitRichEdit(result->ftd->getTextService());
@@ -209,6 +194,21 @@ MTEXTCONTROL_DLL(int) MTextSetParent(TextObject *text, HWND hwnd)
}
/////////////////////////////////////////////////////////////////////////////////////////
+// sets a contact & protocol (optionally, for hContact == 0) for text object (required for valid stickers' processing)
+
+MTEXTCONTROL_DLL(int) MTextSetProto(TextObject *text, MCONTACT hContact, const char *szProto)
+{
+ if (!text) return 0;
+
+ if (hContact && szProto == nullptr)
+ szProto = Proto_GetBaseAccountName(hContact);
+
+ text->hContact = hContact;
+ text->szProto = szProto;
+ return TRUE;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// send message to an object
MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, TextObject *text, UINT msg, WPARAM wParam, LPARAM lParam)
diff --git a/libs/mTextControl/src/stdafx.h b/libs/mTextControl/src/stdafx.h
index 3866c8849d..ef6c76c921 100644
--- a/libs/mTextControl/src/stdafx.h
+++ b/libs/mTextControl/src/stdafx.h
@@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <m_database.h>
#include <m_langpack.h>
#include <m_netlib.h>
+#include <m_protocols.h>
#include <m_utils.h>
#include <m_text.h>
diff --git a/libs/mTextControl/src/textcontrol.cpp b/libs/mTextControl/src/textcontrol.cpp
index f261094307..abc05f65e2 100644
--- a/libs/mTextControl/src/textcontrol.cpp
+++ b/libs/mTextControl/src/textcontrol.cpp
@@ -18,12 +18,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "stdafx.h"
+#include "FormattedTextDraw.h"
struct TextControlData
{
HANDLE htu;
wchar_t *text;
- struct TextObject *mtext;
+ TextObject *mtext;
COLORREF clBack = -1;
};
@@ -106,15 +107,21 @@ static LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam,
case MTM_UPDATE:
if (data->text) delete[] data->text;
- if (data->mtext) MTextDestroy(data->mtext);
{
+ MCONTACT hContact = INVALID_CONTACT_ID;
+ if (data->mtext) {
+ hContact = data->mtext->hContact;
+ MTextDestroy(data->mtext);
+ }
+
int textLength = GetWindowTextLengthW(hwnd);
data->text = new wchar_t[textLength + 1];
GetWindowTextW(hwnd, data->text, textLength + 1);
- }
- data->mtext = MTextCreateW(data->htu, 0, data->text);
- MTextSetParent(data->mtext, hwnd);
+ data->mtext = MTextCreateW(data->htu, data->text);
+ MTextSetParent(data->mtext, hwnd);
+ MTextSetProto(data->mtext, hContact);
+ }
InvalidateRect(hwnd, nullptr, TRUE);
return TRUE;