LCOV - code coverage report
Current view: top level - sw/source/core/tox - ToxTabStopTokenHandler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 31 50 62.0 %
Date: 2014-11-03 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           8 : 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           8 :   mTabStopReferencePolicy(referencePolicy)
      35             : {
      36           8 : }
      37             : 
      38             : 
      39             : ToxTabStopTokenHandler::HandledTabStopToken
      40           8 : DefaultToxTabStopTokenHandler::HandleTabStopToken(
      41             :         const SwFormToken& aToken, const SwTxtNode& targetNode, const SwRootFrm *currentLayout) const
      42             : {
      43           8 :     HandledTabStopToken result;
      44             : 
      45           8 :     if (aToken.bWithTab) { // #i21237#
      46           8 :         result.text = "\t";
      47             :     }
      48             : 
      49             :     // check whether a tab adjustment has been specified.
      50           8 :     if (SVX_TAB_ADJUST_END > aToken.eTabAlign) {
      51           0 :         const SvxLRSpaceItem& rLR = (SvxLRSpaceItem&) targetNode.SwCntntNode::GetAttr(RES_LR_SPACE, true);
      52             : 
      53           0 :         long nTabPosition = aToken.nTabStopPosition;
      54           0 :         if (!mTabPositionIsRelativeToParagraphIndent && rLR.GetTxtLeft()) {
      55           0 :             nTabPosition -= rLR.GetTxtLeft();
      56             :         }
      57           0 :         result.tabStop = SvxTabStop(nTabPosition, aToken.eTabAlign, cDfltDecimalChar, aToken.cTabFillChar);
      58           0 :         return result;
      59             :     }
      60             : 
      61           8 :     SwRect aNdRect;
      62           8 :     if (CanUseLayoutRectangle(targetNode, currentLayout)) {
      63           0 :         aNdRect = targetNode.FindLayoutRect(true);
      64             :     }
      65             :     long nRightMargin;
      66           8 :     if (aNdRect.IsEmpty()) {
      67           8 :         nRightMargin = CalculatePageMarginFromPageDescription(targetNode);
      68             :     } else {
      69           0 :         nRightMargin = aNdRect.Width();
      70             :     }
      71             :     //#i24363# tab stops relative to indent
      72           8 :     if (mTabStopReferencePolicy == TABSTOPS_RELATIVE_TO_INDENT) {
      73             :         // left margin of paragraph style
      74           8 :         const SvxLRSpaceItem& rLRSpace = targetNode.GetTxtColl()->GetLRSpace();
      75           8 :         nRightMargin -= rLRSpace.GetLeft();
      76           8 :         nRightMargin -= rLRSpace.GetTxtFirstLineOfst();
      77             :     }
      78             : 
      79           8 :     result.tabStop = SvxTabStop(nRightMargin, SVX_TAB_ADJUST_RIGHT, cDfltDecimalChar, aToken.cTabFillChar);
      80           8 :     return result;
      81             : }
      82             : 
      83             : long
      84           8 : DefaultToxTabStopTokenHandler::CalculatePageMarginFromPageDescription(const SwTxtNode& targetNode) const
      85             : {
      86           8 :     sal_uInt32 nPgDescNdIdx = targetNode.GetIndex() + 1;
      87           8 :     const SwPageDesc *pPageDesc = targetNode.FindPageDesc(false, &nPgDescNdIdx);
      88           8 :     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           8 :     const SwFrmFmt& rPgDscFmt = pPageDesc->GetMaster();
      94           8 :     long result = rPgDscFmt.GetFrmSize().GetWidth() - rPgDscFmt.GetLRSpace().GetLeft()
      95           8 :             - rPgDscFmt.GetLRSpace().GetRight();
      96           8 :     return result;
      97             : }
      98             : 
      99             : 
     100             : /*static*/ bool
     101           8 : DefaultToxTabStopTokenHandler::CanUseLayoutRectangle(const SwTxtNode& targetNode, const SwRootFrm *currentLayout)
     102             : {
     103             :     const SwPageDesc* pageDescription =
     104           8 :             ((SwFmtPageDesc&) targetNode.SwCntntNode::GetAttr(RES_PAGEDESC)).GetPageDesc();
     105             : 
     106           8 :     if (!pageDescription) {
     107           8 :         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         270 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10