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 
32 class SfxItemSet;
33 class SwAttrPool;
34 class SwFormatAutoFormat;
35 class SwChapterField;
36 class SwChapterFieldType;
37 class SwContentFrame;
38 class SwRootFrame;
39 class SwContentNode;
40 class SwDoc;
41 class SwForm;
42 struct SwFormToken;
43 class SwTextAttr;
44 class SwTextNode;
45 struct SwTOXSortTabBase;
46 class ToxTextGeneratorTest;
47 
48 namespace sw {
49 
50 class ToxLinkProcessor;
51 class ToxTabStopTokenHandler;
52 class ToxWhitespaceStripper;
53 
59 {
60 public:
61  ToxTextGenerator(const SwForm& toxForm, std::shared_ptr<ToxTabStopTokenHandler> const & tabStopHandler);
62 
63  virtual ~ToxTextGenerator();
64 
70  void
71  GenerateText(SwDoc *doc,
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 
77 private:
78  const SwForm& mToxForm;
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>
134  CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& pool);
135 
144  static OUString
145  GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
146  sal_uInt8 nLevel, SwRootFrame const* pLayout);
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: */
std::shared_ptr< ToxLinkProcessor > mLinkProcessor
OUString HandleChapterToken(const SwTOXSortTabBase &rBase, const SwFormToken &aToken, SwRootFrame const *pLayout) const
Handle a chapter token.
std::vector< std::unique_ptr< SwFormatAutoFormat > > autoFormats
Definition: tox.hxx:315
Definition: doc.hxx:187
This class generates text for the entries of a table of x.
std::shared_ptr< ToxTabStopTokenHandler > mTabStopTokenHandler
This class helps to remove unwanted whitespaces from a string to use in a Tox.
Dialog to specify the properties of date form field.
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
static OUString GetNumStringOfFirstNode(const SwTOXSortTabBase &rBase, bool bUsePrefix, sal_uInt8 nLevel, SwRootFrame const *pLayout)
This method will call GetNumStringOfFirstNode() of the first node in the provided SwTOXSortTabBase...
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
ToxTextGenerator(const SwForm &toxForm, std::shared_ptr< ToxTabStopTokenHandler > const &tabStopHandler)
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 ConstructPageNumberPlaceholder(size_t numberOfToxSources)
Handle a page number token.
OUString GenerateTextForChapterToken(const SwFormToken &chapterToken, const SwContentFrame *contentFrame, const SwContentNode *contentNode, SwRootFrame const *pLayout) const
Generate the text for a chapter token.
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).
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
unsigned char sal_uInt8
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.
static void ApplyHandledTextToken(const HandledTextToken &htt, SwTextNode &targetNode)
Applies the result of a handled text token to a target node.
static void GetAttributesForNode(HandledTextToken &rResult, sal_Int32 &rOffset, SwTextNode const &rNode, ToxWhitespaceStripper const &rStripper, SwAttrPool &rPool, SwRootFrame const *const pLayout)
static HandledTextToken HandleTextToken(const SwTOXSortTabBase &source, SwAttrPool &attrPool, SwRootFrame const *const pLayout)
Append text (and selected attributes) to a target node.
Class for sorting directories.
Definition: txmsrt.hxx:120