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
27namespace 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 = targetNode.SwContentNode::GetAttr(RES_LR_SPACE);
54
55 tools::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 }
68 if (aNdRect.IsEmpty()) {
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();
79 }
80
81 result.tabStop = SvxTabStop(nRightMargin, SvxTabAdjust::Right, cDfltDecimalChar, aToken.cTabFillChar);
82 return result;
83}
84
87{
88 SwNodeOffset 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 tools::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 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: */
sal_Int16 CalcLineSpace(SvxBoxItemLine nLine, bool bEvenIfNoLine=false, bool bAllowNegative=false) const
short GetTextFirstLineOffset() const
tools::Long GetRight() const
tools::Long GetTextLeft() const
tools::Long GetLeft() const
tools::Long GetWidth() const
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1230
SwRect FindLayoutRect(const bool bPrtArea=false, const Point *pPoint=nullptr) const
Definition: node.cxx:1238
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:84
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:74
Style of a layout element.
Definition: frmfmt.hxx:62
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwPageFrame * FindPageFrame()
Definition: frame.hxx:681
SwNodeOffset GetIndex() const
Definition: node.hxx:312
const SwPageDesc * FindPageDesc(SwNodeOffset *pPgDescNdIdx=nullptr) const
Search PageDesc with which this node is formatted.
Definition: node.cxx:496
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:238
A page of the document layout.
Definition: pagefrm.hxx:58
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:143
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
bool IsEmpty() const
Definition: swrect.hxx:304
void Width(tools::Long nNew)
Definition: swrect.hxx:189
The root element of a Writer document layout.
Definition: rootfrm.hxx:83
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:111
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:891
static bool CanUseLayoutRectangle(const SwTextNode &targetNode, const SwRootFrame *currentLayout)
Test whether the page layout can be obtained by a layout rectangle.
DefaultToxTabStopTokenHandler(SwNodeOffset indexOfSectionNode, const SwPageDesc &defaultPageDescription, bool tabPositionIsRelativeToParagraphIndent, TabStopReferencePolicy referencePolicy)
ToxTabStopTokenHandler::HandledTabStopToken HandleTabStopToken(const SwFormToken &aToken, const SwTextNode &targetNode, const SwRootFrame *currentLayout) const override
Handle a tab stop token.
tools::Long CalculatePageMarginFromPageDescription(const SwTextNode &targetNode) const
Calculate the page margin from the page description.
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
tools::Long const nRightMargin
Dialog to specify the properties of date form field.
long Long
SvxTabAdjust eTabAlign
Definition: tox.hxx:250
SwTwips nTabStopPosition
Definition: tox.hxx:247
bool bWithTab
Definition: tox.hxx:255
sal_Unicode cTabFillChar
Definition: tox.hxx:254
#define cDfltDecimalChar
Any result