tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sw / inc / ToxLinkProcessor.hxx
blob967e658d49700e2ee125d1834a1fa12f82a276a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 #pragma once
11 #include "fmtinfmt.hxx"
12 #include <rtl/ustring.hxx>
14 #include <memory>
15 #include <optional>
16 #include <utility>
17 #include <vector>
19 class SwTextNode;
21 class ToxLinkProcessorTest;
23 namespace sw {
25 /** A helper class for ToxTextGenerator.
26 * It collects information about encountered link tokens and allows access in a processed form.
28 class ToxLinkProcessor {
29 public:
30 ToxLinkProcessor() {}
31 virtual ~ToxLinkProcessor() {}
33 void
34 StartNewLink(sal_Int32 startPosition, const OUString& characterStyle);
36 /** Close a link which has been found during processing.
38 * @internal
39 * If you close more links than were opened, then the method will behave
40 * as if a start link was opened at position 0 with the character style
41 * STR_POOLCHR_TOXJUMP.
43 void
44 CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative);
46 /** Insert the found links as attributes to a text node */
47 void
48 InsertLinkAttributes(SwTextNode& node);
50 private:
51 /** Obtain the pool id which belongs to a character style.
53 * @internal
54 * This method is overridden in the unittests. You should not override it yourself.
56 virtual sal_uInt16
57 ObtainPoolId(const OUString& characterStyle) const;
59 /** Information about a started link */
60 struct StartedLink {
61 StartedLink(sal_Int32 startPosition, OUString characterStyle) :
62 mStartPosition(startPosition), mCharacterStyle(std::move(characterStyle)) {
64 sal_Int32 mStartPosition;
65 OUString mCharacterStyle;
68 /** A link that has been encountered while parsing a tox.
69 * A link is closed if it has both a start and an end token.
71 struct ClosedLink {
72 ClosedLink(const OUString& url, sal_Int32 startPosition, sal_Int32 endPosition)
73 : mINetFormat(url, OUString())
74 , mStartTextPos(startPosition)
75 , mEndTextPos(endPosition)
78 SwFormatINetFormat mINetFormat;
79 sal_Int32 mStartTextPos;
80 sal_Int32 mEndTextPos;
83 std::vector<std::unique_ptr<ClosedLink>> m_ClosedLinks;
85 std::optional<StartedLink> m_oStartedLink;
87 friend class ::ToxLinkProcessorTest;
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */