LibreOffice Module sw (master) 1
ToxTextGenerator.hxx
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef SW_TOXTEXTGENERATOR_HXX_
21#define SW_TOXTEXTGENERATOR_HXX_
22
23#include <rtl/ustring.hxx>
24#include <sal/types.h>
25
26#include "fmtautofmt.hxx"
27
28#include <memory>
29#include <vector>
30#include <unordered_map>
31
32class SfxItemSet;
33class SwAttrPool;
35class SwChapterField;
37class SwContentFrame;
38class SwRootFrame;
39class SwContentNode;
40class SwDoc;
41class SwForm;
42struct SwFormToken;
43class SwTextAttr;
44class SwTextNode;
45struct SwTOXSortTabBase;
46class ToxTextGeneratorTest;
47
48namespace sw {
49
50class ToxLinkProcessor;
51class ToxTabStopTokenHandler;
52class ToxWhitespaceStripper;
53
59{
60public:
61 ToxTextGenerator(const SwForm& toxForm, std::shared_ptr<ToxTabStopTokenHandler> tabStopHandler);
62
63 virtual ~ToxTextGenerator();
64
70 void
72 std::unordered_map<OUString, int> & rMarkURLs,
73 const std::vector<std::unique_ptr<SwTOXSortTabBase>>& entries,
74 sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
75 SwRootFrame const* pLayout);
76
77private:
79 std::shared_ptr<ToxLinkProcessor> mLinkProcessor;
80 std::shared_ptr<ToxTabStopTokenHandler> mTabStopTokenHandler;
81
86 OUString text;
87 std::vector<std::unique_ptr<SwFormatAutoFormat>> autoFormats;
88 std::vector<sal_Int32> startPositions;
89 std::vector<sal_Int32> endPositions;
90 };
91
92 static void GetAttributesForNode(
93 HandledTextToken & rResult,
94 sal_Int32 & rOffset,
95 SwTextNode const& rNode,
96 ToxWhitespaceStripper const& rStripper,
97 SwAttrPool & rPool,
98 SwRootFrame const*const pLayout);
99
105 static HandledTextToken
106 HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool,
107 SwRootFrame const*const pLayout);
108
110 static void
111 ApplyHandledTextToken(const HandledTextToken& htt, SwTextNode& targetNode);
112
123 static OUString
124 ConstructPageNumberPlaceholder(size_t numberOfToxSources);
125
133 static std::shared_ptr<SfxItemSet>
135
144 static OUString
145 GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
146 sal_uInt8 nLevel, SwRootFrame const* pLayout, bool bAddSpace = true);
147
150 OUString
151 HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
152 SwRootFrame const* pLayout) const;
153
156 OUString
157 GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
158 const SwContentNode *contentNode, SwRootFrame const* pLayout) const;
159
164 virtual SwChapterField
165 ObtainChapterField(SwChapterFieldType* chapterFieldType, const SwFormToken* chapterToken,
166 const SwContentFrame* contentFrame, const SwContentNode *contentNode) const;
167
168 friend class ::ToxTextGeneratorTest;
169};
170
171}
172
173#endif /* SW_TOXTEXTGENERATOR_HXX_ */
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
Definition: doc.hxx:197
Definition: tox.hxx:314
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
This class generates text for the entries of a table of x.
void GenerateText(SwDoc *doc, std::unordered_map< OUString, int > &rMarkURLs, const std::vector< std::unique_ptr< SwTOXSortTabBase > > &entries, sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess, SwRootFrame const *pLayout)
Generate the text for an entry of a table of X (X is, e.g., content).
std::shared_ptr< ToxTabStopTokenHandler > mTabStopTokenHandler
static void ApplyHandledTextToken(const HandledTextToken &htt, SwTextNode &targetNode)
Applies the result of a handled text token to a target node.
static HandledTextToken HandleTextToken(const SwTOXSortTabBase &source, SwAttrPool &attrPool, SwRootFrame const *const pLayout)
Append text (and selected attributes) to a target node.
ToxTextGenerator(const SwForm &toxForm, std::shared_ptr< ToxTabStopTokenHandler > tabStopHandler)
std::shared_ptr< ToxLinkProcessor > mLinkProcessor
static OUString ConstructPageNumberPlaceholder(size_t numberOfToxSources)
Handle a page number token.
OUString HandleChapterToken(const SwTOXSortTabBase &rBase, const SwFormToken &aToken, SwRootFrame const *pLayout) const
Handle a chapter token.
virtual SwChapterField ObtainChapterField(SwChapterFieldType *chapterFieldType, const SwFormToken *chapterToken, const SwContentFrame *contentFrame, const SwContentNode *contentNode) const
Obtain a ChapterField to use for the text generation.
static OUString GetNumStringOfFirstNode(const SwTOXSortTabBase &rBase, bool bUsePrefix, sal_uInt8 nLevel, SwRootFrame const *pLayout, bool bAddSpace=true)
This method will call GetNumStringOfFirstNode() of the first node in the provided SwTOXSortTabBase.
OUString GenerateTextForChapterToken(const SwFormToken &chapterToken, const SwContentFrame *contentFrame, const SwContentNode *contentNode, SwRootFrame const *pLayout) const
Generate the text for a chapter token.
static void GetAttributesForNode(HandledTextToken &rResult, sal_Int32 &rOffset, SwTextNode const &rNode, ToxWhitespaceStripper const &rStripper, SwAttrPool &rPool, SwRootFrame const *const pLayout)
static std::shared_ptr< SfxItemSet > CollectAttributesForTox(const SwTextAttr &hint, SwAttrPool &pool)
Collect the attributes of a hint that shall be copied over to the TOX.
This class helps to remove unwanted whitespaces from a string to use in a Tox.
Dialog to specify the properties of date form field.
Class for sorting directories.
Definition: txmsrt.hxx:124
std::vector< std::unique_ptr< SwFormatAutoFormat > > autoFormats
unsigned char sal_uInt8