LCOV - code coverage report
Current view: top level - sw/source/core/tox - ToxTabStopTokenHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 50 62.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.0 %
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             : #include "ToxTabStopTokenHandler.hxx"
      11             : 
      12             : #include "editeng/tstpitem.hxx"
      13             : #include "editeng/lrspitem.hxx"
      14             : 
      15             : #include "cntfrm.hxx"
      16             : #include "fmtfsize.hxx"
      17             : #include "fmtpdsc.hxx"
      18             : #include "frmfmt.hxx"
      19             : #include "ndtxt.hxx"
      20             : #include "pagedesc.hxx"
      21             : #include "pagefrm.hxx"
      22             : #include "swrect.hxx"
      23             : #include "tox.hxx"
      24             : 
      25             : namespace sw {
      26             : 
      27           4 : DefaultToxTabStopTokenHandler::DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode,
      28             :         const SwPageDesc& defaultPageDescription,
      29             :         bool tabPositionIsRelativeToParagraphIndent,
      30             :         TabStopReferencePolicy referencePolicy)
      31             : : mIndexOfSectionNode(indexOfSectionNode),
      32             :   mDefaultPageDescription(defaultPageDescription),
      33             :   mTabPositionIsRelativeToParagraphIndent(tabPositionIsRelativeToParagraphIndent),
      34           4 :   mTabStopReferencePolicy(referencePolicy)
      35             : {
      36           4 : }
      37             : 
      38             : 
      39             : ToxTabStopTokenHandler::HandledTabStopToken
      40           4 : DefaultToxTabStopTokenHandler::HandleTabStopToken(
      41             :         const SwFormToken& aToken, const SwTextNode& targetNode, const SwRootFrm *currentLayout) const
      42             : {
      43           4 :     HandledTabStopToken result;
      44             : 
      45           4 :     if (aToken.bWithTab) { // #i21237#
      46           4 :         result.text = "\t";
      47             :     }
      48             : 
      49             :     // check whether a tab adjustment has been specified.
      50           4 :     if (SVX_TAB_ADJUST_END > aToken.eTabAlign) {
      51           0 :         const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( targetNode.SwContentNode::GetAttr(RES_LR_SPACE, true) );
      52             : 
      53           0 :         long nTabPosition = aToken.nTabStopPosition;
      54           0 :         if (!mTabPositionIsRelativeToParagraphIndent && rLR.GetTextLeft()) {
      55           0 :             nTabPosition -= rLR.GetTextLeft();
      56             :         }
      57           0 :         result.tabStop = SvxTabStop(nTabPosition, aToken.eTabAlign, cDfltDecimalChar, aToken.cTabFillChar);
      58           0 :         return result;
      59             :     }
      60             : 
      61           4 :     SwRect aNdRect;
      62           4 :     if (CanUseLayoutRectangle(targetNode, currentLayout)) {
      63           0 :         aNdRect = targetNode.FindLayoutRect(true);
      64             :     }
      65             :     long nRightMargin;
      66           4 :     if (aNdRect.IsEmpty()) {
      67           4 :         nRightMargin = CalculatePageMarginFromPageDescription(targetNode);
      68             :     } else {
      69           0 :         nRightMargin = aNdRect.Width();
      70             :     }
      71             :     //#i24363# tab stops relative to indent
      72           4 :     if (mTabStopReferencePolicy == TABSTOPS_RELATIVE_TO_INDENT) {
      73             :         // left margin of paragraph style
      74           4 :         const SvxLRSpaceItem& rLRSpace = targetNode.GetTextColl()->GetLRSpace();
      75           4 :         nRightMargin -= rLRSpace.GetLeft();
      76           4 :         nRightMargin -= rLRSpace.GetTextFirstLineOfst();
      77             :     }
      78             : 
      79           4 :     result.tabStop = SvxTabStop(nRightMargin, SVX_TAB_ADJUST_RIGHT, cDfltDecimalChar, aToken.cTabFillChar);
      80           4 :     return result;
      81             : }
      82             : 
      83             : long
      84           4 : DefaultToxTabStopTokenHandler::CalculatePageMarginFromPageDescription(const SwTextNode& targetNode) const
      85             : {
      86           4 :     size_t nPgDescNdIdx = targetNode.GetIndex() + 1;
      87           4 :     const SwPageDesc *pPageDesc = targetNode.FindPageDesc(false, &nPgDescNdIdx);
      88           4 :     if (!pPageDesc || nPgDescNdIdx < mIndexOfSectionNode) {
      89             :         // Use default page description, if none is found or the found one is given by a Node before the
      90             :         // table-of-content section.
      91           0 :         pPageDesc = &mDefaultPageDescription;
      92             :     }
      93           4 :     const SwFrameFormat& rPgDscFormat = pPageDesc->GetMaster();
      94           4 :     long result = rPgDscFormat.GetFrmSize().GetWidth() - rPgDscFormat.GetLRSpace().GetLeft()
      95           4 :             - rPgDscFormat.GetLRSpace().GetRight();
      96           4 :     return result;
      97             : }
      98             : 
      99             : 
     100             : /*static*/ bool
     101           4 : DefaultToxTabStopTokenHandler::CanUseLayoutRectangle(const SwTextNode& targetNode, const SwRootFrm *currentLayout)
     102             : {
     103             :     const SwPageDesc* pageDescription =
     104           4 :             static_cast<const SwFormatPageDesc&>( targetNode.SwContentNode::GetAttr(RES_PAGEDESC)).GetPageDesc();
     105             : 
     106           4 :     if (!pageDescription) {
     107           4 :         return false;
     108             :     }
     109           0 :     const SwFrm* pFrm = targetNode.getLayoutFrm(currentLayout, 0, 0, true);
     110           0 :     if (!pFrm) {
     111           0 :         return false;
     112             :     }
     113           0 :     pFrm = pFrm->FindPageFrm();
     114           0 :     if (!pFrm) {
     115           0 :         return false;
     116             :     }
     117           0 :     const SwPageFrm* pageFrm = static_cast<const SwPageFrm*>(pFrm);
     118           0 :     if (pageDescription != pageFrm->GetPageDesc()) {
     119           0 :         return false;
     120             :     }
     121           0 :     return true;
     122             : }
     123             : 
     124         177 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11