From 7ed2502b7f67d2f349c5fb58703557cf310e7e14 Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Sun, 4 Dec 2022 09:36:54 -0900 Subject: tdf#152029 Bring hyperlinks to attention in document view when mouse pointer is over hyperlink entry in the Navigator content tree Change-Id: I84693426277f2394f2c4b6f7bae5143bd1909285 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143636 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/source/uibase/inc/conttree.hxx | 2 ++ sw/source/uibase/utlui/content.cxx | 59 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx index 77358b9edb30..6d2083f04480 100644 --- a/sw/source/uibase/inc/conttree.hxx +++ b/sw/source/uibase/inc/conttree.hxx @@ -33,6 +33,7 @@ #include #include +#include class SwWrtShell; class SwContentType; @@ -136,6 +137,7 @@ class SwContentTree final : public SfxListener std::unique_ptr m_xOverlayObject; void BringBookmarksToAttention(const std::vector& rNames); + void BringURLFieldsToAttention(const SwGetINetAttrs& rINetAttrsArr); /** * Before any data will be deleted, the last active entry has to be found. diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index cb7f96ec3b23..3e581082c8e8 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -1165,7 +1165,8 @@ IMPL_LINK(SwContentTree, MouseMoveHdl, const MouseEvent&, rMEvt, bool) { SwContent* pCnt = weld::fromId(m_xTreeView->get_id(*xEntry)); const ContentTypeId nType = pCnt->GetParent()->GetType(); - bRemoveOverlayObject = nType != ContentTypeId::BOOKMARK; + bRemoveOverlayObject = nType != ContentTypeId::BOOKMARK && + nType != ContentTypeId::URLFIELD; if (!bRemoveOverlayObject && m_xTreeView->iter_compare(*xEntry, *m_xOverlayCompareEntry) != 0) { @@ -1174,13 +1175,19 @@ IMPL_LINK(SwContentTree, MouseMoveHdl, const MouseEvent&, rMEvt, bool) { BringBookmarksToAttention(std::vector {pCnt->GetName()}); } + else if (nType == ContentTypeId::URLFIELD) + { + BringURLFieldsToAttention(SwGetINetAttrs {SwGetINetAttr(pCnt->GetName(), + *static_cast(pCnt)->GetINetAttr())}); + } } } else // content type entry { const ContentTypeId nType = weld::fromId(m_xTreeView->get_id(*xEntry))->GetType(); - bRemoveOverlayObject = nType != ContentTypeId::BOOKMARK; + bRemoveOverlayObject = nType != ContentTypeId::BOOKMARK && + nType != ContentTypeId::URLFIELD; if (!bRemoveOverlayObject && m_xTreeView->iter_compare(*xEntry, *m_xOverlayCompareEntry) != 0) { @@ -1198,6 +1205,12 @@ IMPL_LINK(SwContentTree, MouseMoveHdl, const MouseEvent&, rMEvt, bool) BringBookmarksToAttention(aNames); } } + else if (nType == ContentTypeId::URLFIELD) + { + SwGetINetAttrs aINetAttrsArr; + m_pActiveShell->GetINetAttrs(aINetAttrsArr, false); + BringURLFieldsToAttention(aINetAttrsArr); + } } } } @@ -5577,4 +5590,46 @@ void SwContentTree::BringBookmarksToAttention(const std::vector& rName m_aOverlayObjectDelayTimer.Start(); } +void SwContentTree::BringURLFieldsToAttention(const SwGetINetAttrs& rINetAttrsArr) +{ + std::vector aRanges; + for (const auto& r : rINetAttrsArr) + { + if (SwTextFrame* pFrame = static_cast( + r.rINetAttr.GetTextNode().getLayoutFrame(m_pActiveShell->GetLayout()))) + { + SwRect aStartCharRect; + SwPosition aStartPos(r.rINetAttr.GetTextNode(), r.rINetAttr.GetStart()); + pFrame->GetCharRect(aStartCharRect, aStartPos); + SwRect aEndCharRect; + SwPosition aEndPos(r.rINetAttr.GetTextNode(), r.rINetAttr.GetAnyEnd()); + pFrame->GetCharRect(aEndCharRect, aEndPos); + if (aStartCharRect.Top() == aEndCharRect.Top()) + { + // single line range + aRanges.emplace_back(aStartCharRect.Left(), aStartCharRect.Top(), + aEndCharRect.Right() + 1, aEndCharRect.Bottom() + 1); + } + else + { + // multi line range + SwRect aFrameRect = pFrame->getFrameArea(); + aRanges.emplace_back(aStartCharRect.Left(), aStartCharRect.Top(), + aFrameRect.Right(), aStartCharRect.Bottom() + 1); + if (aStartCharRect.Bottom() + 1 != aEndCharRect.Top()) + aRanges.emplace_back(aFrameRect.Left(), aStartCharRect.Bottom() + 1, + aFrameRect.Right(), aEndCharRect.Top() + 1); + aRanges.emplace_back(aFrameRect.Left(), aEndCharRect.Top() + 1, + aEndCharRect.Right() + 1, aEndCharRect.Bottom() + 1); + } + } + } + if (m_xOverlayObject && m_xOverlayObject->getOverlayManager()) + m_xOverlayObject->getOverlayManager()->remove(*m_xOverlayObject); + m_xOverlayObject.reset(new sdr::overlay::OverlaySelection(sdr::overlay::OverlayType::Invert, + Color(), std::move(aRanges), + true /*unused for Invert type*/)); + m_aOverlayObjectDelayTimer.Start(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit