LCOV - code coverage report
Current view: top level - sw/inc - ToxTabStopTokenHandler.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 4 4 100.0 %
Date: 2014-11-03 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      10             : 
      11             : #ifndef TOXTABSTOPTOKENHANDLER_HXX_
      12             : #define TOXTABSTOPTOKENHANDLER_HXX_
      13             : 
      14             : #include "swdllapi.h"
      15             : #include "rtl/ustring.hxx"
      16             : 
      17             : #include "editeng/tstpitem.hxx"
      18             : 
      19             : struct SwFormToken;
      20             : class SwPageDesc;
      21             : class SwRootFrm;
      22             : class SwTxtNode;
      23             : 
      24             : namespace sw {
      25             : 
      26             : /** This class handles tab stop tokens in the pattern for tox entries.
      27             :  *
      28             :  * @internal
      29             :  * This is an interface class. It allows to mock the class in unit tests
      30             :  */
      31          12 : class SW_DLLPUBLIC ToxTabStopTokenHandler
      32             : {
      33             : public:
      34          12 :     virtual ~ToxTabStopTokenHandler() {}
      35             : 
      36             :     /** Return value of HandleTabStopToken */
      37          16 :     struct HandledTabStopToken {
      38             :         OUString text;
      39             :         SvxTabStop tabStop;
      40             :     };
      41             : 
      42             :     /** Handle a tab stop token.
      43             :      *
      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.
      46             :      */
      47             :     virtual HandledTabStopToken
      48             :     HandleTabStopToken(const SwFormToken& aToken, const SwTxtNode& targetNode,
      49             :             const SwRootFrm *currentLayout) const = 0;
      50             : };
      51             : 
      52             : /** The default implementation of ToxTabStopTokenHandler */
      53           8 : class SW_DLLPUBLIC DefaultToxTabStopTokenHandler : public ToxTabStopTokenHandler
      54             : {
      55             : public:
      56             : 
      57             :     enum TabStopReferencePolicy {TABSTOPS_RELATIVE_TO_INDENT, TABSTOPS_RELATIVE_TO_PAGE};
      58             : 
      59             :    /**
      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.
      63             :     *
      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
      67             :     *
      68             :     * @param tabPositionIsRelativeToParagraphIndent
      69             :     * Whether the tab position is relative to the paragraph indent. (toxForm.IsRelTabPos() is true or false.)
      70             :     *
      71             :     * @param tabstopReferencePolicy
      72             :     * How tab stops are positioned. (#i21237) The default behavior is to place tab stops relative to the page.
      73             :     */
      74             :     DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode, const SwPageDesc& defaultPageDescription,
      75             :             bool tabPositionIsRelativeToParagraphIndent,
      76             :             TabStopReferencePolicy referencePolicy = TABSTOPS_RELATIVE_TO_PAGE);
      77             : 
      78             :     /** Handle a tab stop token.
      79             :      *
      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.
      84             :      */
      85             :     ToxTabStopTokenHandler::HandledTabStopToken
      86             :     HandleTabStopToken(const SwFormToken& aToken, const SwTxtNode& targetNode,
      87             :             const SwRootFrm *currentLayout) const SAL_OVERRIDE;
      88             : 
      89             : private:
      90             :     /** Test whether the page layout can be obtained by a layout rectangle.
      91             :      *
      92             :      * Is used to determine how to find tab stop position.
      93             :      */
      94             :     static bool
      95             :     CanUseLayoutRectangle(const SwTxtNode& targetNode, const SwRootFrm *currentLayout);
      96             : 
      97             :     /** Calculate the page margin from the page description.
      98             :      *
      99             :      * This is the fallback method to determine the position of a tab stop.
     100             :      */
     101             :     long
     102             :     CalculatePageMarginFromPageDescription(const SwTxtNode& targetNode) const;
     103             : 
     104             :     sal_uInt32 mIndexOfSectionNode;
     105             :     const SwPageDesc& mDefaultPageDescription;
     106             :     bool mTabPositionIsRelativeToParagraphIndent;
     107             :     TabStopReferencePolicy mTabStopReferencePolicy;
     108             : };
     109             : 
     110             : }
     111             : 
     112             : #endif /* TOXTABSTOPTOKENHANDLER_HXX_ */
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10