LibreOffice Module sw (master)  1
ToxLinkProcessor.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <memory>
11 #include <ToxLinkProcessor.hxx>
12 
13 #include <SwStyleNameMapper.hxx>
14 #include <ndtxt.hxx>
15 #include <sal/log.hxx>
16 
17 #include <stdexcept>
18 
19 namespace sw {
20 
21 void
22 ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
23 {
24  SAL_INFO_IF(m_pStartedLink, "sw.core", "ToxLinkProcessor: LS without LE");
25  m_pStartedLink = std::make_unique<StartedLink>(
26  startPosition, characterStyle);
27 }
28 
29 void
30 ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url)
31 {
32  if (m_pStartedLink == nullptr)
33  {
34  SAL_INFO("sw.core", "ToxLinkProcessor: LE without LS");
35  return;
36  }
37 
38  if (url.isEmpty()) {
39  return;
40  }
41 
42  std::unique_ptr<ClosedLink> pClosedLink(
43  new ClosedLink(url, m_pStartedLink->mStartPosition, endPosition));
44 
45  const OUString& characterStyle = m_pStartedLink->mCharacterStyle;
46  sal_uInt16 poolId = ObtainPoolId(characterStyle);
47  pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId);
48  pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId);
49 
50  m_ClosedLinks.push_back(std::move(pClosedLink));
51  m_pStartedLink.reset();
52 }
53 
54 sal_uInt16
55 ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
56 {
57  if (characterStyle.isEmpty()) {
58  return USHRT_MAX;
59  }
60  else {
62  }
63 }
64 
65 
66 void
68 {
69  for (auto const& clink : m_ClosedLinks)
70  {
71  node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos);
72  }
73 }
74 
75 }
76 
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_INFO_IF(condition, area, stream)
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
SwTextAttr * InsertItem(SfxPoolItem &rAttr, const sal_Int32 nStart, const sal_Int32 nEnd, const SetAttrMode nMode=SetAttrMode::DEFAULT)
create new text attribute from rAttr and insert it
Definition: thints.cxx:1224
virtual sal_uInt16 ObtainPoolId(const OUString &characterStyle) const
Obtain the pool id which belongs to a character style.
void CloseLink(sal_Int32 endPosition, const OUString &url)
Close a link which has been found during processing.
std::vector< std::unique_ptr< ClosedLink > > m_ClosedLinks
std::unique_ptr< StartedLink > m_pStartedLink
void InsertLinkAttributes(SwTextNode &node)
Insert the found links as attributes to a text node.
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
#define SAL_INFO(area, stream)
void StartNewLink(sal_Int32 startPosition, const OUString &characterStyle)