diff options
author | George Hazan <ghazan@miranda.im> | 2023-02-19 17:50:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-02-19 17:50:00 +0300 |
commit | 5a754e4a418e767ea3355521fd04878197cfe7aa (patch) | |
tree | acd2649ba6fec60d626424a28c0ac0b239742eb4 | |
parent | 756cda6094c7e3e24a29323867b070b988dfaf1c (diff) |
fixes #2357 (NewStory: links in log/history should be clickable)
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.cpp | 7 | ||||
-rw-r--r-- | libs/mTextControl/src/FormattedTextDraw.h | 27 | ||||
-rw-r--r-- | libs/mTextControl/src/services.cpp | 58 | ||||
-rw-r--r-- | libs/mTextControl/src/textcontrol.cpp | 2 | ||||
-rw-r--r-- | plugins/ExternalAPI/m_text.h | 19 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 5 |
6 files changed, 71 insertions, 47 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp index de93cef046..c5ca3d4ecc 100644 --- a/libs/mTextControl/src/FormattedTextDraw.cpp +++ b/libs/mTextControl/src/FormattedTextDraw.cpp @@ -241,12 +241,13 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He HDC CFormattedTextDraw::TxGetDC() { - return nullptr; + return GetDC(nullptr); } -INT CFormattedTextDraw::TxReleaseDC(HDC) +INT CFormattedTextDraw::TxReleaseDC(HDC hdc) { - return 1; + ReleaseDC(nullptr, hdc); + return FALSE; } BOOL CFormattedTextDraw::TxShowScrollBar(INT, BOOL) diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h index 49468753b6..58f22a667b 100644 --- a/libs/mTextControl/src/FormattedTextDraw.h +++ b/libs/mTextControl/src/FormattedTextDraw.h @@ -28,24 +28,23 @@ interface IFormattedTextDraw { public: virtual ~IFormattedTextDraw() {}; - virtual HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal) = 0; - virtual HRESULT Create() = 0; - virtual HRESULT Draw(void *hdcDraw, RECT *prc) = 0; - virtual HRESULT putRTFTextA(char *newVal) = 0; - virtual HRESULT putRTFTextW(wchar_t *newVal) = 0; - virtual HRESULT putTextA(char *newVal) = 0; - virtual HRESULT putTextW(wchar_t *newVal) = 0; - - virtual ITextServices *getTextService() = 0; - virtual ITextDocument *getTextDocument() = 0; - virtual void setParentWnd(HWND hwnd, RECT rect) = 0; + virtual HRESULT get_NaturalSize(void *hdcDraw, long *Width, long *pVal) PURE; + virtual HRESULT Create() PURE; + virtual HRESULT Draw(void *hdcDraw, RECT *prc) PURE; + virtual HRESULT putRTFTextA(char *newVal) PURE; + virtual HRESULT putRTFTextW(wchar_t *newVal) PURE; + virtual HRESULT putTextA(char *newVal) PURE; + virtual HRESULT putTextW(wchar_t *newVal) PURE; + + virtual ITextServices *getTextService() PURE; + virtual ITextDocument *getTextDocument() PURE; + virtual void setParentWnd(HWND hwnd, RECT rect) PURE; // COM-like functions - virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; - virtual ULONG STDMETHODCALLTYPE Release(void) = 0; + virtual ULONG STDMETHODCALLTYPE AddRef(void) PURE; + virtual ULONG STDMETHODCALLTYPE Release(void) PURE; }; - ///////////////////////////////////////////////////////////////////////////// // CFormattedTextDraw class CFormattedTextDraw : diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp index ae6524b758..b5529797c2 100644 --- a/libs/mTextControl/src/services.cpp +++ b/libs/mTextControl/src/services.cpp @@ -34,9 +34,8 @@ struct TextObject void MText_InitFormatting0(IFormattedTextDraw *ftd, uint32_t) { - LRESULT lResult; - // urls + LRESULT lResult; ftd->getTextService()->TxSendMessage(EM_AUTOURLDETECT, TRUE, 0, &lResult); } @@ -62,7 +61,7 @@ void MText_InitFormatting1(TextObject *text) ///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (unicode) -MTEXTCONTROL_DLL(HANDLE) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text) +MTEXTCONTROL_DLL(TextObject*) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text) { TextObject *result = new TextObject; result->szProto = szProto; @@ -75,13 +74,13 @@ MTEXTCONTROL_DLL(HANDLE) MTextCreateW(HANDLE userHandle, const char *szProto, co result->ftd->putTextW((wchar_t*)text); MText_InitFormatting1(result); - return (HANDLE)result; + return result; } ///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (advanced) -MTEXTCONTROL_DLL(HANDLE) MTextCreateEx(HANDLE userHandle, void *text, uint32_t flags) +MTEXTCONTROL_DLL(TextObject*) MTextCreateEx(HANDLE userHandle, void *text, uint32_t flags) { TextObject *result = new TextObject; result->options = TextUserGetOptions(userHandle); @@ -103,12 +102,12 @@ MTEXTCONTROL_DLL(HANDLE) MTextCreateEx(HANDLE userHandle, void *text, uint32_t f ///////////////////////////////////////////////////////////////////////////////////////// // measure text object -MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HANDLE text) +MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, TextObject *text) { if (!text) return 0; - + long lWidth = sz->cx, lHeight = sz->cy; - ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight); + text->ftd->get_NaturalSize(dc, &lWidth, &lHeight); sz->cx = lWidth; sz->cy = lHeight; return 0; @@ -117,7 +116,7 @@ MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HANDLE text) ///////////////////////////////////////////////////////////////////////////////////////// // display text object -MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) +MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, TextObject *text) { if (!text) return 0; @@ -128,19 +127,19 @@ MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) cf.cbSize = sizeof(cf); cf.dwMask = CFM_COLOR; cf.crTextColor = cl; - ((TextObject *)text)->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + text->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); SetBkMode(dc, TRANSPARENT); long lWidth = sz.cx, lHeight; - ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight); + text->ftd->get_NaturalSize(dc, &lWidth, &lHeight); RECT rt; rt.left = pos.x; rt.top = pos.y; rt.right = pos.x + lWidth; rt.bottom = pos.y + lHeight; - ((TextObject *)text)->ftd->Draw(dc, &rt); + text->ftd->Draw(dc, &rt); return 0; } @@ -148,13 +147,16 @@ MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) ///////////////////////////////////////////////////////////////////////////////////////// // set parent window for text object (this is required for mouse handling, etc) -MTEXTCONTROL_DLL(int) MTextSetParent(HANDLE text, HWND hwnd) +MTEXTCONTROL_DLL(int) MTextSetParent(TextObject *text, HWND hwnd) { if (text) { RECT rc; GetClientRect(hwnd, &rc); - ((TextObject *)text)->ftd->setParentWnd(hwnd, rc); + text->ftd->setParentWnd(hwnd, rc); + + DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); + SetWindowLong(hwnd, GWL_STYLE, dwStyle | 8); } return 0; } @@ -162,17 +164,16 @@ MTEXTCONTROL_DLL(int) MTextSetParent(HANDLE text, HWND hwnd) ///////////////////////////////////////////////////////////////////////////////////////// // send message to an object -MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam) +MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, TextObject *text, UINT msg, WPARAM wParam, LPARAM lParam) { - if (!text) - return 0; + if (!text) return 0; LRESULT lResult; - ((TextObject *)text)->ftd->getTextService()->TxSendMessage(msg, wParam, lParam, &lResult); + text->ftd->getTextService()->TxSendMessage(msg, wParam, lParam, &lResult); if (hwnd && (msg == WM_MOUSEMOVE)) { HDC hdc = GetDC(hwnd); - ((TextObject *)text)->ftd->getTextService()->OnTxSetCursor(DVASPECT_CONTENT, 0, nullptr, nullptr, hdc, nullptr, nullptr, LOWORD(lParam), HIWORD(lParam)); + text->ftd->getTextService()->OnTxSetCursor(DVASPECT_CONTENT, 0, nullptr, nullptr, hdc, nullptr, nullptr, LOWORD(lParam), HIWORD(lParam)); ReleaseDC(hwnd, hdc); } @@ -180,10 +181,25 @@ MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM } ///////////////////////////////////////////////////////////////////////////////////////// +// activates text object + +MTEXTCONTROL_DLL(int) MTextActivate(TextObject *text, bool bActivate) +{ + if (!text) return 0; + + if (bActivate) + text->ftd->getTextService()->OnTxInPlaceActivate(0); + else + text->ftd->getTextService()->OnTxInPlaceDeactivate(); + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// // destroy text object -MTEXTCONTROL_DLL(int) MTextDestroy(HANDLE text) +MTEXTCONTROL_DLL(int) MTextDestroy(TextObject *text) { - delete (TextObject *)text; + delete text; return 0; } diff --git a/libs/mTextControl/src/textcontrol.cpp b/libs/mTextControl/src/textcontrol.cpp index d58fd0e1c1..30caf61b95 100644 --- a/libs/mTextControl/src/textcontrol.cpp +++ b/libs/mTextControl/src/textcontrol.cpp @@ -27,7 +27,7 @@ struct TextControlData { HANDLE htu; wchar_t *text; - HANDLE mtext; + struct TextObject *mtext; }; void MTextControl_RegisterClass() diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h index 0780b58bd1..2039de8ba1 100644 --- a/plugins/ExternalAPI/m_text.h +++ b/plugins/ExternalAPI/m_text.h @@ -8,8 +8,10 @@ #ifdef MTEXTCONTROL_EXPORTS
#define MTEXTCONTROL_EXPORT __declspec(dllexport)
+ typedef struct TextObject *HText;
#else
#define MTEXTCONTROL_EXPORT __declspec(dllimport)
+ typedef HANDLE HText;
#endif
#define MTEXTCONTROL_DLL(T) MTEXTCONTROL_EXPORT T __stdcall
@@ -47,29 +49,32 @@ enum MTEXTCONTROL_DLL(HANDLE) MTextRegister(const char *userTitle, DWORD options);
// allocate text object (unicode)
-MTEXTCONTROL_DLL(HANDLE) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text);
+MTEXTCONTROL_DLL(HText) MTextCreateW(HANDLE userHandle, const char *szProto, const wchar_t *text);
// allocate text object (advanced)
-MTEXTCONTROL_DLL(HANDLE) MTextCreateEx(HANDLE userHandle, void *text, DWORD flags);
+MTEXTCONTROL_DLL(HText) MTextCreateEx(HANDLE userHandle, void *text, DWORD flags);
// destroys text object
-MTEXTCONTROL_DLL(int) MTextDestroy(HANDLE text);
+MTEXTCONTROL_DLL(int) MTextDestroy(HText text);
+
+// activates text object
+MTEXTCONTROL_DLL(int) MTextActivate(HText text, bool bActivate = true);
// measures text object
// result = 1 (success), 0 (failure)
// sz->cx is interpreted as maximum width allowed.
// wrapped text size is stored in sz, text
-MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HANDLE text);
+MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HText text);
// display text object
// result = 1 (success), 0 (failure)
-MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text);
+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)
-MTEXTCONTROL_DLL(int) MTextSetParent(HANDLE text, HWND hwnd);
+MTEXTCONTROL_DLL(int) MTextSetParent(HText text, HWND hwnd);
// send message to an object
-MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam);
+MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HText text, UINT msg, WPARAM wParam, LPARAM lParam);
#ifdef __cplusplus
}
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 2ce131b9a3..348f955c41 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -823,6 +823,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (data->caret != idx) data->EndEditItem(false); + auto *pItem = data->items[idx]; + MTextActivate(pItem->data, true); + if (wParam & MK_CONTROL) { SendMessage(hwnd, NSM_TOGGLEITEMS, idx, idx); SendMessage(hwnd, NSM_SETCARET, idx, TRUE); @@ -832,7 +835,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SendMessage(hwnd, NSM_SETCARET, idx, TRUE); } else { - auto *pItem = data->items[idx]; pt.y -= pItem->savedTop; if (pItem->isLink(pt)) { Utils_OpenUrlW(pItem->getWBuf()); @@ -847,6 +849,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SendMessage(hwnd, NSM_SELECTITEMS2, idx, idx); SendMessage(hwnd, NSM_SETCARET, idx, TRUE); } + MTextActivate(pItem->data, false); } SetFocus(hwnd); |