lok: Hide file linking in section
[LibreOffice.git] / sw / inc / ToxTextGenerator.hxx
blob6758355732664b6d44e2a6bba4f4c8cac1075db3
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SW_TOXTEXTGENERATOR_HXX_
21 #define SW_TOXTEXTGENERATOR_HXX_
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
26 #include "fmtautofmt.hxx"
28 #include <memory>
29 #include <vector>
31 class SfxItemSet;
32 class SwAttrPool;
33 class SwFormatAutoFormat;
34 class SwChapterField;
35 class SwChapterFieldType;
36 class SwContentFrame;
37 class SwRootFrame;
38 class SwContentNode;
39 class SwDoc;
40 class SwForm;
41 struct SwFormToken;
42 class SwTextAttr;
43 class SwTextNode;
44 struct SwTOXSortTabBase;
45 class ToxTextGeneratorTest;
47 namespace sw {
49 class ToxLinkProcessor;
50 class ToxTabStopTokenHandler;
51 class ToxWhitespaceStripper;
53 /** This class generates text for the entries of a table of x.
55 * You can control its behavior by calling @link SetTabstopPolicy() and specifying the desired behavior.
57 class ToxTextGenerator
59 public:
60 ToxTextGenerator(const SwForm& toxForm, std::shared_ptr<ToxTabStopTokenHandler> const & tabStopHandler);
62 virtual ~ToxTextGenerator();
64 /** Generate the text for an entry of a table of X (X is, e.g., content).
66 * This method will process the entries in @p entries, starting at @p indexOfEntryToProcess and
67 * process @p numberOfEntriesToProcess entries.
69 void
70 GenerateText(SwDoc *doc, const std::vector<std::unique_ptr<SwTOXSortTabBase>>& entries,
71 sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
72 SwRootFrame const* pLayout);
74 private:
75 const SwForm& mToxForm;
76 std::shared_ptr<ToxLinkProcessor> mLinkProcessor;
77 std::shared_ptr<ToxTabStopTokenHandler> mTabStopTokenHandler;
79 /** A handled text token.
80 * It contains the information which should be added to the target text node.
82 struct HandledTextToken {
83 OUString text;
84 std::vector<std::unique_ptr<SwFormatAutoFormat>> autoFormats;
85 std::vector<sal_Int32> startPositions;
86 std::vector<sal_Int32> endPositions;
89 static void GetAttributesForNode(
90 HandledTextToken & rResult,
91 sal_Int32 & rOffset,
92 SwTextNode const& rNode,
93 ToxWhitespaceStripper const& rStripper,
94 SwAttrPool & rPool,
95 SwRootFrame const*const pLayout);
97 /** Append text (and selected attributes) to a target node.
99 * Will take the text of @p source, and return the text and the attributes which should be added to the
100 * target text node. @see CollectAttributesForTox() for the criteria of the attributes which are taken.
102 static HandledTextToken
103 HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool,
104 SwRootFrame const*const pLayout);
106 /** Applies the result of a handled text token to a target node. */
107 static void
108 ApplyHandledTextToken(const HandledTextToken& htt, SwTextNode& targetNode);
110 /** Handle a page number token.
112 * Will return a string of @p numberOfToxSources concatenated '@' signs, separated by commas, and
113 * finished by a '~'.
114 * (The '@' sign is the magic character C_NUM_REPL, the '~' sign is the magic character C_END_PAGE_NUM.
116 * @internal
117 * The count of similar entries, i.e., nodes in aTOXSources of SwTOXSortTabBase gives the PagerNumber
118 * pattern.
120 static OUString
121 ConstructPageNumberPlaceholder(size_t numberOfToxSources);
123 /** Collect the attributes of a hint that shall be copied over to the TOX.
125 * Some text attributes are used in the TOX entries. This method defines which attributes are used.
127 * @param hint The hint from which the attributes are taken
128 * @param pool The attribute pool for the new items
130 static std::shared_ptr<SfxItemSet>
131 CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& pool);
133 /** This method will call GetNumStringOfFirstNode() of the first node in the provided SwTOXSortTabBase.
135 * The parameters @p bUsePrefix and @p nLevel are passed to SwTextNode::GetNumString()
137 * @internal
138 * The method is only called if several preconditions for @p rBase are true. Check the implementation
139 * for details.
141 static OUString
142 GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
143 sal_uInt8 nLevel, SwRootFrame const* pLayout);
145 /** Handle a chapter token.
147 OUString
148 HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
149 SwRootFrame const* pLayout) const;
151 /** Generate the text for a chapter token.
153 OUString
154 GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
155 const SwContentNode *contentNode, SwRootFrame const* pLayout) const;
157 /** Obtain a ChapterField to use for the text generation.
158 * @internal
159 * This method is overridden in the unittests. Do not override it yourself.
161 virtual SwChapterField
162 ObtainChapterField(SwChapterFieldType* chapterFieldType, const SwFormToken* chapterToken,
163 const SwContentFrame* contentFrame, const SwContentNode *contentNode) const;
165 friend class ::ToxTextGeneratorTest;
170 #endif /* SW_TOXTEXTGENERATOR_HXX_ */
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */