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/.
11 #ifndef TOXTABSTOPTOKENHANDLER_HXX_
12 #define TOXTABSTOPTOKENHANDLER_HXX_
14 #include <rtl/ustring.hxx>
16 #include <editeng/tstpitem.hxx>
25 /** This class handles tab stop tokens in the pattern for tox entries.
28 * This is an interface class. It allows to mock the class in unit tests
30 class ToxTabStopTokenHandler
33 virtual ~ToxTabStopTokenHandler() {}
35 /** Return value of HandleTabStopToken */
36 struct HandledTabStopToken
{
41 /** Handle a tab stop token.
43 * @returns A HandledTabStopToken. Make sure to append the text field to the text of the target node
44 * and to provide the returned SvxTabStop to the attributes of the node.
46 virtual HandledTabStopToken
47 HandleTabStopToken(const SwFormToken
& aToken
, const SwTextNode
& targetNode
,
48 const SwRootFrame
*currentLayout
) const = 0;
51 /** The default implementation of ToxTabStopTokenHandler */
52 class DefaultToxTabStopTokenHandler final
: public ToxTabStopTokenHandler
56 enum TabStopReferencePolicy
{TABSTOPS_RELATIVE_TO_INDENT
, TABSTOPS_RELATIVE_TO_PAGE
};
59 * @param indexOfSectionNode
60 * The index of the section node. It is needed to determine whether a page description was given by a node
61 * before the tox section.
63 * @param defaultPageDescription
64 * Which page description shall be used if we do not find one or the found page description was provided by
65 * a node before the tox section
67 * @param tabPositionIsRelativeToParagraphIndent
68 * Whether the tab position is relative to the paragraph indent. (toxForm.IsRelTabPos() is true or false.)
70 * @param tabstopReferencePolicy
71 * How tab stops are positioned. (#i21237) The default behavior is to place tab stops relative to the page.
73 DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode
, const SwPageDesc
& defaultPageDescription
,
74 bool tabPositionIsRelativeToParagraphIndent
,
75 TabStopReferencePolicy referencePolicy
);
77 /** Handle a tab stop token.
79 * If the token contains tab alignment information, that is used to create the SvxTabStop.
80 * Else, the information about the tab stop is taken from a page description.
81 * Depending on the TabStopReferencePolicy provided in the constructor, the
82 * method behaves differently when deriving the tab stop position.
84 ToxTabStopTokenHandler::HandledTabStopToken
85 HandleTabStopToken(const SwFormToken
& aToken
, const SwTextNode
& targetNode
,
86 const SwRootFrame
*currentLayout
) const override
;
89 /** Test whether the page layout can be obtained by a layout rectangle.
91 * Is used to determine how to find tab stop position.
94 CanUseLayoutRectangle(const SwTextNode
& targetNode
, const SwRootFrame
*currentLayout
);
96 /** Calculate the page margin from the page description.
98 * This is the fallback method to determine the position of a tab stop.
101 CalculatePageMarginFromPageDescription(const SwTextNode
& targetNode
) const;
103 sal_uInt32 mIndexOfSectionNode
;
104 const SwPageDesc
& mDefaultPageDescription
;
105 bool mTabPositionIsRelativeToParagraphIndent
;
106 TabStopReferencePolicy mTabStopReferencePolicy
;
111 #endif /* TOXTABSTOPTOKENHANDLER_HXX_ */
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */