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 
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;
46 
47 namespace sw {
48 
49 class ToxLinkProcessor;
50 class ToxTabStopTokenHandler;
51 class ToxWhitespaceStripper;
52 
58 {
59 public:
60  ToxTextGenerator(const SwForm& toxForm, std::shared_ptr<ToxTabStopTokenHandler> const & tabStopHandler);
61 
62  virtual ~ToxTextGenerator();
63 
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);
73 
74 private:
75  const SwForm& mToxForm;
76  std::shared_ptr<ToxLinkProcessor> mLinkProcessor;
77  std::shared_ptr<ToxTabStopTokenHandler> mTabStopTokenHandler;
78 
83  OUString text;
84  std::vector<std::unique_ptr<SwFormatAutoFormat>> autoFormats;
85  std::vector<sal_Int32> startPositions;
86  std::vector<sal_Int32> endPositions;
87  };
88 
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);
96 
102  static HandledTextToken
103  HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool,
104  SwRootFrame const*const pLayout);
105 
107  static void
108  ApplyHandledTextToken(const HandledTextToken& htt, SwTextNode& targetNode);
109 
120  static OUString
121  ConstructPageNumberPlaceholder(size_t numberOfToxSources);
122 
130  static std::shared_ptr<SfxItemSet>
131  CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& pool);
132 
141  static OUString
142  GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
143  sal_uInt8 nLevel, SwRootFrame const* pLayout);
144 
147  OUString
148  HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
149  SwRootFrame const* pLayout) const;
150 
153  OUString
154  GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
155  const SwContentNode *contentNode, SwRootFrame const* pLayout) const;
156 
161  virtual SwChapterField
162  ObtainChapterField(SwChapterFieldType* chapterFieldType, const SwFormToken* chapterToken,
163  const SwContentFrame* contentFrame, const SwContentNode *contentNode) const;
164 
165  friend class ::ToxTextGeneratorTest;
166 };
167 
168 }
169 
170 #endif /* SW_TOXTEXTGENERATOR_HXX_ */
171 
172 /* 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:276
Definition: doc.hxx:185
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.
Definition: accfrmobj.cxx:40
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
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...
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.
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void GenerateText(SwDoc *doc, 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).
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.
::cppu::ImplementationEntry const entries[]
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