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_
15 #include "rtl/ustring.hxx"
17 #include "editeng/tstpitem.hxx"
26 /** This class handles tab stop tokens in the pattern for tox entries.
29 * This is an interface class. It allows to mock the class in unit tests
31 class ToxTabStopTokenHandler
34 virtual ~ToxTabStopTokenHandler() {}
36 /** Return value of HandleTabStopToken */
37 struct HandledTabStopToken
{
42 /** Handle a tab stop token.
44 * @returns A HandledTabStopToken. Make sure to append the text field to the text of the target node
45 * and to provide the returned SvxTabStop to the attributes of the node.
47 virtual HandledTabStopToken
48 HandleTabStopToken(const SwFormToken
& aToken
, const SwTextNode
& targetNode
,
49 const SwRootFrm
*currentLayout
) const = 0;
52 /** The default implementation of ToxTabStopTokenHandler */
53 class DefaultToxTabStopTokenHandler
: public ToxTabStopTokenHandler
57 enum TabStopReferencePolicy
{TABSTOPS_RELATIVE_TO_INDENT
, TABSTOPS_RELATIVE_TO_PAGE
};
60 * @param indexOfSectionNode
61 * The index of the section node. It is needed to determine whether a page description was given by a node
62 * before the tox section.
64 * @param defaultPageDescription
65 * Which page description shall be used if we do not find one or the found page description was provided by
66 * a node before the tox section
68 * @param tabPositionIsRelativeToParagraphIndent
69 * Whether the tab position is relative to the paragraph indent. (toxForm.IsRelTabPos() is true or false.)
71 * @param tabstopReferencePolicy
72 * How tab stops are positioned. (#i21237) The default behavior is to place tab stops relative to the page.
74 DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode
, const SwPageDesc
& defaultPageDescription
,
75 bool tabPositionIsRelativeToParagraphIndent
,
76 TabStopReferencePolicy referencePolicy
= TABSTOPS_RELATIVE_TO_PAGE
);
78 /** Handle a tab stop token.
80 * If the token contains tab alignment information, that is used to create the SvxTabStop.
81 * Else, the information about the tab stop is taken from a page description.
82 * Depending on the TabStopReferencePolicy provided in the constructor, the
83 * method behaves differently when deriving the tab stop position.
85 ToxTabStopTokenHandler::HandledTabStopToken
86 HandleTabStopToken(const SwFormToken
& aToken
, const SwTextNode
& targetNode
,
87 const SwRootFrm
*currentLayout
) const SAL_OVERRIDE
;
90 /** Test whether the page layout can be obtained by a layout rectangle.
92 * Is used to determine how to find tab stop position.
95 CanUseLayoutRectangle(const SwTextNode
& targetNode
, const SwRootFrm
*currentLayout
);
97 /** Calculate the page margin from the page description.
99 * This is the fallback method to determine the position of a tab stop.
102 CalculatePageMarginFromPageDescription(const SwTextNode
& targetNode
) const;
104 sal_uInt32 mIndexOfSectionNode
;
105 const SwPageDesc
& mDefaultPageDescription
;
106 bool mTabPositionIsRelativeToParagraphIndent
;
107 TabStopReferencePolicy mTabStopReferencePolicy
;
112 #endif /* TOXTABSTOPTOKENHANDLER_HXX_ */
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */