diff options
author | George Hazan <george.hazan@gmail.com> | 2023-12-20 16:43:14 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-12-20 16:43:14 +0300 |
commit | d80970d9b26b5e9b7868ec61349490da5e24dc64 (patch) | |
tree | 4f77d2094176eeaecfb99c9d7ad902124752503c | |
parent | 633f26707366cca4bd876d8f874f3ed116560e0d (diff) |
libTextControl: contact settings extracted to MTextSetProto
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.h | 15 | ||||
-rw-r--r-- | libs/mTextControl/src/services.cpp | 32 | ||||
-rw-r--r-- | libs/mTextControl/src/stdafx.h | 1 | ||||
-rw-r--r-- | libs/mTextControl/src/textcontrol.cpp | 17 | ||||
-rw-r--r-- | plugins/ExternalAPI/m_text.h | 9 | ||||
-rw-r--r-- | plugins/Popup/src/popup_wnd2.cpp | 5 |
6 files changed, 52 insertions, 27 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; diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h index d6e948b673..4190a56dc5 100644 --- a/plugins/ExternalAPI/m_text.h +++ b/plugins/ExternalAPI/m_text.h @@ -61,7 +61,7 @@ enum MTEXTCONTROL_DLL(HANDLE) MTextRegister(const char *userTitle, uint32_t options);
// allocate text object (unicode)
-MTEXTCONTROL_DLL(HText) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text);
+MTEXTCONTROL_DLL(HText) MTextCreateW(HANDLE userHandle, const wchar_t *text);
// allocate text object (advanced)
MTEXTCONTROL_DLL(HText) MTextCreateEx(HANDLE userHandle, const void *text, uint32_t flags);
@@ -81,11 +81,14 @@ MTEXTCONTROL_DLL(int) MTextActivate(HText text, bool bActivate = true); // wrapped text size is stored in sz, text
MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HText text);
-// display text object
+// displays text object
// result = 1 (success), 0 (failure)
MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HText text);
-// set parent window for text object (this is required for mouse handling, etc)
+// sets a contact & protocol (optionally, for hContact == 0) for text object (required for valid stickers' processing)
+MTEXTCONTROL_DLL(int) MTextSetProto(HText text, MCONTACT hContact, const char *szProto = nullptr);
+
+// sets parent window for text object (this is required for mouse handling, etc)
MTEXTCONTROL_DLL(int) MTextSetParent(HText text, HWND hwnd);
// send message to an object
diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp index b6de298843..8a4c95ce08 100644 --- a/plugins/Popup/src/popup_wnd2.cpp +++ b/plugins/Popup/src/popup_wnd2.cpp @@ -740,10 +740,9 @@ void PopupWnd2::buildMText() m_mtText = m_mtTitle = nullptr;
if (m_lptzText && m_lptzTitle) {
- auto *szProto = Proto_GetBaseAccountName(m_hContact);
m_textType = TT_MTEXT;
- m_mtText = MTextCreateW(htuText, szProto, m_lptzText);
- m_mtTitle = MTextCreateW(htuTitle, szProto, m_lptzTitle);
+ m_mtText = MTextCreateW(htuText, m_lptzText); MTextSetProto(m_mtText, m_hContact);
+ m_mtTitle = MTextCreateW(htuTitle, m_lptzTitle); MTextSetProto(m_mtTitle, m_hContact);
}
}
|