summaryrefslogtreecommitdiff
path: root/sw/source/uibase/uiview/view2.cxx
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-01-28 19:59:35 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2021-02-02 18:16:43 +0100
commit7685c0746cf0db6f51c6a7a488f4a960f8eab3c9 (patch)
tree9e68984782579ae58f685354b7f816a60f4807e9 /sw/source/uibase/uiview/view2.cxx
parenta2e533767bed88f293d2129aca9dfd9c4c60226b (diff)
tdf#121842 sw: add hyperlinks to toxmarks in ToC/User-Defined Index
The toxmark is identified by the type of index, the name of the index type (only for user-defined; there is only one ToC type), the text (either text:string-value or text content of the toxmark), and a counter to distinguish marks with the same text. Both text and type name can contain arbitrary characters so use U+0019 control character as separator. Links look like: #1%19text%19Utypename|toxmark Change-Id: I5aeec727e2cd3a02d676cf3ea4c302bf7c77d319 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110091 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw/source/uibase/uiview/view2.cxx')
-rw-r--r--sw/source/uibase/uiview/view2.cxx81
1 files changed, 81 insertions, 0 deletions
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 8b7e4667aae3..e76fc2f30e41 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -2022,6 +2022,83 @@ void SwView::EditLinkDlg()
pDlg->Execute();
}
+static auto JumpToTOXMark(SwWrtShell & rSh, OUString const& rName) -> bool
+{
+ sal_Int32 const first(rName.indexOf(toxMarkSeparator));
+ if (first == -1)
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: missing separator");
+ return false;
+ }
+ sal_Int32 const counter(rName.copy(0, first).toInt32());
+ if (counter <= 0)
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: invalid counter");
+ return false;
+ }
+ sal_Int32 const second(rName.indexOf(toxMarkSeparator, first + 1));
+ if (second == -1)
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: missing separator");
+ return false;
+ }
+ OUString const entry(rName.copy(first + 1, second - (first + 1)));
+ if (rName.getLength() < second + 2)
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: invalid tox");
+ return false;
+ }
+ sal_uInt16 const indexType(rName[second + 1]);
+ OUString const indexName(rName.copy(second + 2));
+ SwTOXType const* pType(nullptr);
+ switch (indexType)
+ {
+ case 'A':
+ pType = rSh.GetTOXType(TOX_INDEX, 0);
+ assert(pType);
+ break;
+ case 'C':
+ pType = rSh.GetTOXType(TOX_CONTENT, 0);
+ assert(pType);
+ break;
+ case 'U':
+ for (auto i = rSh.GetTOXTypeCount(TOX_USER); 0 < i; )
+ {
+ --i;
+ auto const pTmp(rSh.GetTOXType(TOX_USER, i));
+ if (pTmp->GetTypeName() == indexName)
+ {
+ pType = pTmp;
+ break;
+ }
+ }
+ break;
+ }
+ if (!pType)
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: tox doesn't exist");
+ return false;
+ }
+ // type and alt text are the search keys
+ SwTOXMark tmp(pType);
+ tmp.SetAlternativeText(entry);
+ SwTOXMark const* pMark(&tmp);
+ // hack: check first if one exists
+ if (&tmp != &rSh.GetDoc()->GotoTOXMark(tmp, TOX_SAME_NXT, rSh.IsReadOnlyAvailable()))
+ {
+ for (sal_Int32 i = 0; i < counter; ++i)
+ {
+ pMark = &rSh.GotoTOXMark(*pMark, TOX_SAME_NXT);
+ }
+ return true;
+ }
+ else
+ {
+ SAL_WARN("sw.ui", "JumpToTOXMark: tox mark doesn't exist");
+ return false;
+ }
+}
+
bool SwView::JumpToSwMark( const OUString& rMark )
{
bool bRet = false;
@@ -2092,6 +2169,10 @@ bool SwView::JumpToSwMark( const OUString& rMark )
bRet = m_pWrtShell->GotoRefMark(sName, REF_SEQUENCEFLD, nSeqNo);
}
}
+ else if (sCmp == "toxmark")
+ {
+ bRet = JumpToTOXMark(*m_pWrtShell, sName);
+ }
else if( sCmp == "text" )
{
// normal text search