summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-02-28 17:35:22 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-02-28 17:35:22 +0300
commit1d9308bdb58d0cff1b12bf82575319964bae469e (patch)
tree01221e66231ee1628f231d63e92d48f53ac98245
parent14ad818465dcd095dc8ecf3dbc8cef082c5ceb6b (diff)
fixes #3365 (NewStory: проблемы со ссылками )
-rw-r--r--plugins/NewStory/src/history_array.cpp37
-rw-r--r--plugins/NewStory/src/history_array.h3
-rw-r--r--plugins/NewStory/src/history_control.cpp8
3 files changed, 39 insertions, 9 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index a47a54f5ba..6247e22cab 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -51,18 +51,47 @@ void ItemData::checkCreate(HWND hwnd)
if (data == nullptr) {
data = MTextCreateW(htuLog, Proto_GetBaseAccountName(hContact), ptrW(TplFormatString(getTemplate(), hContact, this)));
MTextSetParent(data, hwnd);
+ MTextActivate(data, true);
}
}
-bool ItemData::isLink(POINT pt) const
+bool ItemData::isLink(POINT pt, CMStringW &url) const
{
int cp = MTextSendMessage(0, data, EM_CHARFROMPOS, 0, LPARAM(&pt));
if (cp == -1)
return false;
- CHARRANGE cr = { cp, cp + 1 };
- MTextSendMessage(0, data, EM_EXSETSEL, 0, LPARAM(&cr));
-
+ if (!isLinkChar(cp))
+ return false;
+
+ CHARRANGE sel = { cp, cp };
+ for (sel.cpMin = cp; sel.cpMin >= 0; sel.cpMin--)
+ if (!isLinkChar(sel.cpMin))
+ break;
+
+ for (sel.cpMax = cp + 1; isLinkChar(sel.cpMax); sel.cpMax++)
+ ;
+
+ if (sel.cpMax > sel.cpMin) {
+ url.Truncate(sel.cpMax - sel.cpMin + 1);
+
+ TEXTRANGE tr = { 0 };
+ tr.chrg = sel;
+ tr.lpstrText = url.GetBuffer();
+ int iRes = MTextSendMessage(0, data, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
+ if (iRes > 0)
+ url.Trim();
+ else
+ url.Empty();
+ }
+ return true;
+}
+
+bool ItemData::isLinkChar(int idx) const
+{
+ CHARRANGE sel = { idx, idx + 1 };
+ MTextSendMessage(0, data, EM_EXSETSEL, 0, LPARAM(&sel));
+
CHARFORMAT2 cf = {};
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_LINK;
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index a6ec9b6503..a57b5f42ca 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -24,7 +24,8 @@ struct ItemData
void load(bool bFullLoad);
bool isGrouped() const;
- bool isLink(POINT pt) const;
+ bool isLink(POINT pt, CMStringW &url) const;
+ bool isLinkChar(int idx) const;
int getTemplate() const;
int getCopyTemplate() const;
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 348f955c41..398c6b24ab 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -824,7 +824,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
data->EndEditItem(false);
auto *pItem = data->items[idx];
- MTextActivate(pItem->data, true);
if (wParam & MK_CONTROL) {
SendMessage(hwnd, NSM_TOGGLEITEMS, idx, idx);
@@ -836,8 +835,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
else {
pt.y -= pItem->savedTop;
- if (pItem->isLink(pt)) {
- Utils_OpenUrlW(pItem->getWBuf());
+
+ CMStringW wszUrl;
+ if (pItem->isLink(pt, wszUrl)) {
+ Utils_OpenUrlW(wszUrl);
return 0;
}
@@ -849,7 +850,6 @@ 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);