summaryrefslogtreecommitdiff
path: root/sw/source/core/tox/ToxLinkProcessor.cxx
blob: cbb7275ca42f52bfcf2ca1008e79bf5e356f3c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "ToxLinkProcessor.hxx"

#include "SwStyleNameMapper.hxx"
#include "ndtxt.hxx"
#include <poolfmt.hrc>

#include <stdexcept>

namespace sw {

void
ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
{
    m_StartedLinks.push_back(std::unique_ptr<StartedLink>(
                new StartedLink(startPosition, characterStyle)));
}

void
ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url)
{
    StartedLink const startedLink( (m_StartedLinks.empty())
        ? StartedLink(0, SW_RES(STR_POOLCHR_TOXJUMP))
        : *m_StartedLinks.back() );
    if (!m_StartedLinks.empty())
    {
        m_StartedLinks.pop_back();
    }

    if (url.isEmpty()) {
        return;
    }

    std::unique_ptr<ClosedLink> pClosedLink(
            new ClosedLink(url, startedLink.mStartPosition, endPosition));

    const OUString& characterStyle = startedLink.mCharacterStyle;
    sal_uInt16 poolId = ObtainPoolId(characterStyle);
    pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId);
    pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId);

    m_ClosedLinks.push_back(std::move(pClosedLink));
}

sal_uInt16
ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
{
    if (characterStyle.isEmpty()) {
        return USHRT_MAX;
    }
    else {
        return SwStyleNameMapper::GetPoolIdFromUIName(characterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
    }
}


void
ToxLinkProcessor::InsertLinkAttributes(SwTextNode& node)
{
    for (auto const& clink : m_ClosedLinks)
    {
        node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos);
    }
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */