Update git submodules
[LibreOffice.git] / sw / inc / ToxTabStopTokenHandler.hxx
blob23a7d720682c10da213fa05bf87377ba2def62f3
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 */
10 #pragma once
12 #include <rtl/ustring.hxx>
14 #include <editeng/tstpitem.hxx>
15 #include "nodeoffset.hxx"
17 struct SwFormToken;
18 class SwPageDesc;
19 class SwRootFrame;
20 class SwTextNode;
22 namespace sw {
24 /** This class handles tab stop tokens in the pattern for tox entries.
26 * @internal
27 * This is an interface class. It allows to mock the class in unit tests
29 class ToxTabStopTokenHandler
31 public:
32 virtual ~ToxTabStopTokenHandler() {}
34 /** Return value of HandleTabStopToken */
35 struct HandledTabStopToken {
36 OUString text;
37 SvxTabStop tabStop;
40 /** Handle a tab stop token.
42 * @returns A HandledTabStopToken. Make sure to append the text field to the text of the target node
43 * and to provide the returned SvxTabStop to the attributes of the node.
45 virtual HandledTabStopToken
46 HandleTabStopToken(const SwFormToken& aToken, const SwTextNode& targetNode)
47 const = 0;
49 virtual auto CalcEndStop(SwTextNode const& rNode,
50 SwRootFrame const* pLayout) const -> tools::Long = 0;
53 /** The default implementation of ToxTabStopTokenHandler */
54 class DefaultToxTabStopTokenHandler final : public ToxTabStopTokenHandler
56 public:
58 enum TabStopReferencePolicy {TABSTOPS_RELATIVE_TO_INDENT, TABSTOPS_RELATIVE_TO_PAGE};
60 /**
61 * @param indexOfSectionNode
62 * The index of the section node. It is needed to determine whether a page description was given by a node
63 * before the tox section.
65 * @param defaultPageDescription
66 * Which page description shall be used if we do not find one or the found page description was provided by
67 * a node before the tox section
69 * @param tabPositionIsRelativeToParagraphIndent
70 * Whether the tab position is relative to the paragraph indent. (toxForm.IsRelTabPos() is true or false.)
72 * @param tabstopReferencePolicy
73 * How tab stops are positioned. (#i21237) The default behavior is to place tab stops relative to the page.
75 DefaultToxTabStopTokenHandler(SwNodeOffset indexOfSectionNode, const SwPageDesc& defaultPageDescription,
76 bool tabPositionIsRelativeToParagraphIndent,
77 TabStopReferencePolicy referencePolicy);
79 /** Handle a tab stop token.
81 * If the token contains tab alignment information, that is used to create the SvxTabStop.
82 * Else, the information about the tab stop is taken from a page description.
83 * Depending on the TabStopReferencePolicy provided in the constructor, the
84 * method behaves differently when deriving the tab stop position.
86 ToxTabStopTokenHandler::HandledTabStopToken
87 HandleTabStopToken(const SwFormToken& aToken, const SwTextNode& targetNode)
88 const override;
90 auto CalcEndStop(SwTextNode const& rNode,
91 SwRootFrame const* pLayout) const -> tools::Long override;
93 private:
94 /** Test whether the page layout can be obtained by a layout rectangle.
96 * Is used to determine how to find tab stop position.
98 static bool
99 CanUseLayoutRectangle(const SwTextNode& targetNode, const SwRootFrame *currentLayout);
101 /** Calculate the page margin from the page description.
103 * This is the fallback method to determine the position of a tab stop.
105 tools::Long
106 CalculatePageMarginFromPageDescription(const SwTextNode& targetNode) const;
108 SwNodeOffset mIndexOfSectionNode;
109 const SwPageDesc& mDefaultPageDescription;
110 bool mTabPositionIsRelativeToParagraphIndent;
111 TabStopReferencePolicy mTabStopReferencePolicy;
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */