1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <rtl/ustring.hxx>
14 #include <editeng/tstpitem.hxx>
15 #include "nodeoffset.hxx"
24 /** This class handles tab stop tokens in the pattern for tox entries.
27 * This is an interface class. It allows to mock the class in unit tests
29 class ToxTabStopTokenHandler
32 virtual ~ToxTabStopTokenHandler() {}
34 /** Return value of HandleTabStopToken */
35 struct HandledTabStopToken
{
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
)
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
58 enum TabStopReferencePolicy
{TABSTOPS_RELATIVE_TO_INDENT
, TABSTOPS_RELATIVE_TO_PAGE
};
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
)
90 auto CalcEndStop(SwTextNode
const& rNode
,
91 SwRootFrame
const* pLayout
) const -> tools::Long override
;
94 /** Test whether the page layout can be obtained by a layout rectangle.
96 * Is used to determine how to find tab stop position.
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.
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: */