LibreOffice Module sw (master)  1
ToxTabStopTokenHandler.cxx
Go to the documentation of this file.
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 
11 
12 #include <editeng/tstpitem.hxx>
13 #include <editeng/lrspitem.hxx>
14 #include <editeng/boxitem.hxx>
15 
16 #include <cntfrm.hxx>
17 #include <fmtfsize.hxx>
18 #include <fmtpdsc.hxx>
19 #include <frmfmt.hxx>
20 #include <frmatr.hxx>
21 #include <ndtxt.hxx>
22 #include <pagedesc.hxx>
23 #include <pagefrm.hxx>
24 #include <swrect.hxx>
25 #include <tox.hxx>
26 
27 namespace sw {
28 
30  const SwPageDesc& defaultPageDescription,
31  bool tabPositionIsRelativeToParagraphIndent,
32  TabStopReferencePolicy referencePolicy)
33 : mIndexOfSectionNode(indexOfSectionNode),
34  mDefaultPageDescription(defaultPageDescription),
35  mTabPositionIsRelativeToParagraphIndent(tabPositionIsRelativeToParagraphIndent),
36  mTabStopReferencePolicy(referencePolicy)
37 {
38 }
39 
40 
43  const SwFormToken& aToken, const SwTextNode& targetNode, const SwRootFrame *currentLayout) const
44 {
46 
47  if (aToken.bWithTab) { // #i21237#
48  result.text = "\t";
49  }
50 
51  // check whether a tab adjustment has been specified.
52  if (SvxTabAdjust::End > aToken.eTabAlign) {
53  const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( targetNode.SwContentNode::GetAttr(RES_LR_SPACE) );
54 
55  long nTabPosition = aToken.nTabStopPosition;
57  nTabPosition -= rLR.GetTextLeft();
58  }
59  result.tabStop = SvxTabStop(nTabPosition, aToken.eTabAlign, cDfltDecimalChar, aToken.cTabFillChar);
60  return result;
61  }
62 
63  SwRect aNdRect;
64  if (CanUseLayoutRectangle(targetNode, currentLayout)) {
65  aNdRect = targetNode.FindLayoutRect(true);
66  }
67  long nRightMargin;
68  if (aNdRect.IsEmpty()) {
69  nRightMargin = CalculatePageMarginFromPageDescription(targetNode);
70  } else {
71  nRightMargin = aNdRect.Width();
72  }
73  //#i24363# tab stops relative to indent
75  // left margin of paragraph style
76  const SvxLRSpaceItem& rLRSpace = targetNode.GetTextColl()->GetLRSpace();
77  nRightMargin -= rLRSpace.GetLeft();
78  nRightMargin -= rLRSpace.GetTextFirstLineOfst();
79  }
80 
81  result.tabStop = SvxTabStop(nRightMargin, SvxTabAdjust::Right, cDfltDecimalChar, aToken.cTabFillChar);
82  return result;
83 }
84 
85 long
87 {
88  size_t nPgDescNdIdx = targetNode.GetIndex() + 1;
89  const SwPageDesc *pPageDesc = targetNode.FindPageDesc(&nPgDescNdIdx);
90  if (!pPageDesc || nPgDescNdIdx < mIndexOfSectionNode) {
91  // Use default page description, if none is found or the found one is given by a Node before the
92  // table-of-content section.
93  pPageDesc = &mDefaultPageDescription;
94  }
95  const SwFrameFormat& rPgDscFormat = pPageDesc->GetMaster();
96  long result = rPgDscFormat.GetFrameSize().GetWidth() - rPgDscFormat.GetLRSpace().GetLeft()
97  - rPgDscFormat.GetLRSpace().GetRight();
98  // Also consider borders
99  const SvxBoxItem& rBox = rPgDscFormat.GetBox();
100  result -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) + rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
101  return result;
102 }
103 
104 
105 /*static*/ bool
107 {
108  const SwPageDesc* pageDescription =
109  static_cast<const SwFormatPageDesc&>( targetNode.SwContentNode::GetAttr(RES_PAGEDESC)).GetPageDesc();
110 
111  if (!pageDescription) {
112  return false;
113  }
114  const SwFrame* pFrame = targetNode.getLayoutFrame(currentLayout);
115  if (!pFrame) {
116  return false;
117  }
118  pFrame = pFrame->FindPageFrame();
119  if (!pFrame) {
120  return false;
121  }
122  const SwPageFrame* pageFrame = static_cast<const SwPageFrame*>(pFrame);
123  return pageDescription == pageFrame->GetPageDesc();
124 }
125 
126 }
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetLeft() const
Base class of the Writer layout elements.
Definition: frame.hxx:295
sal_uLong GetIndex() const
Definition: node.hxx:282
ToxTabStopTokenHandler::HandledTabStopToken HandleTabStopToken(const SwFormToken &aToken, const SwTextNode &targetNode, const SwRootFrame *currentLayout) const override
Handle a tab stop token.
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
SwRect FindLayoutRect(const bool bPrtArea=false, const Point *pPoint=nullptr) const
Definition: node.cxx:1158
short GetTextFirstLineOfst() const
long GetWidth() const
const SwPageDesc * FindPageDesc(size_t *pPgDescNdIdx=nullptr) const
Search PageDesc with which this node is formatted.
Definition: node.cxx:466
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1150
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
bool bWithTab
Definition: tox.hxx:218
sal_Unicode cTabFillChar
Definition: tox.hxx:217
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:84
DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode, const SwPageDesc &defaultPageDescription, bool tabPositionIsRelativeToParagraphIndent, TabStopReferencePolicy referencePolicy)
static bool CanUseLayoutRectangle(const SwTextNode &targetNode, const SwRootFrame *currentLayout)
Test whether the page layout can be obtained by a layout rectangle.
bool IsEmpty() const
Definition: swrect.hxx:294
Style of a layout element.
Definition: frmfmt.hxx:57
TabStopReferencePolicy const mTabStopReferencePolicy
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
long CalculatePageMarginFromPageDescription(const SwTextNode &targetNode) const
Calculate the page margin from the page description.
MetadataImporterPluginType * result
#define cDfltDecimalChar
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:129
A page of the document layout.
Definition: pagefrm.hxx:40
#define RES_LR_SPACE
Definition: hintids.hxx:196
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:216
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
SwTwips nTabStopPosition
Definition: tox.hxx:210
void Width(long nNew)
Definition: swrect.hxx:185
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
long GetRight() const
sal_uInt16 CalcLineSpace(SvxBoxItemLine nLine, bool bEvenIfNoLine=false) const
SvxTabAdjust eTabAlign
Definition: tox.hxx:213
long const nRightMargin
#define RES_PAGEDESC
Definition: hintids.hxx:198
long GetTextLeft() const
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:74
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:837