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 SvxTextLeftMarginItem const& rTextLeftMargin(
54 targetNode.SwContentNode::GetAttr(RES_MARGIN_TEXTLEFT));
55 tools::Long nTabPosition = aToken.nTabStopPosition;
56 if (!mTabPositionIsRelativeToParagraphIndent && rTextLeftMargin.GetTextLeft() != 0)
57 {
58 nTabPosition -= rTextLeftMargin.GetTextLeft();
59 }
60 result.tabStop = SvxTabStop(nTabPosition, aToken.eTabAlign, cDfltDecimalChar, aToken.cTabFillChar);
61 return result;
62 }
63
64 SwRect aNdRect;
65 if (CanUseLayoutRectangle(targetNode, currentLayout)) {
66 aNdRect = targetNode.FindLayoutRect(true);
67 }
69 if (aNdRect.IsEmpty()) {
71 } else {
72 nRightMargin = aNdRect.Width();
73 }
74 //#i24363# tab stops relative to indent
76 // left margin of paragraph style
77 SvxFirstLineIndentItem const& rFirstLine(
78 targetNode.GetTextColl()->GetFirstLineIndent());
79 SvxTextLeftMarginItem const& rTextLeftMargin(
80 targetNode.GetTextColl()->GetTextLeftMargin());
81 nRightMargin -= rTextLeftMargin.GetLeft(rFirstLine);
83 }
84
85 result.tabStop = SvxTabStop(nRightMargin, SvxTabAdjust::Right, cDfltDecimalChar, aToken.cTabFillChar);
86 return result;
87}
88
91{
92 SwNodeOffset nPgDescNdIdx = targetNode.GetIndex() + 1;
93 const SwPageDesc *pPageDesc = targetNode.FindPageDesc(&nPgDescNdIdx);
94 if (!pPageDesc || nPgDescNdIdx < mIndexOfSectionNode) {
95 // Use default page description, if none is found or the found one is given by a Node before the
96 // table-of-content section.
97 pPageDesc = &mDefaultPageDescription;
98 }
99 const SwFrameFormat& rPgDscFormat = pPageDesc->GetMaster();
100 tools::Long result = rPgDscFormat.GetFrameSize().GetWidth() - rPgDscFormat.GetLRSpace().GetLeft()
101 - rPgDscFormat.GetLRSpace().GetRight();
102 // Also consider borders
103 const SvxBoxItem& rBox = rPgDscFormat.GetBox();
104 result -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) + rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
105 return result;
106}
107
108
109/*static*/ bool
111{
112 const SwPageDesc* pageDescription =
113 targetNode.SwContentNode::GetAttr(RES_PAGEDESC).GetPageDesc();
114
115 if (!pageDescription) {
116 return false;
117 }
118 const SwFrame* pFrame = targetNode.getLayoutFrame(currentLayout);
119 if (!pFrame) {
120 return false;
121 }
122 pFrame = pFrame->FindPageFrame();
123 if (!pFrame) {
124 return false;
125 }
126 const SwPageFrame* pageFrame = static_cast<const SwPageFrame*>(pFrame);
127 return pageDescription == pageFrame->GetPageDesc();
128}
129
130}
131
132/* 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 GetLeft() const
tools::Long GetWidth() const
tools::Long GetLeft(SvxFirstLineIndentItem const &rFirstLine) const
tools::Long GetTextLeft() const
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
SwRect FindLayoutRect(const bool bPrtArea=false, const Point *pPoint=nullptr) const
Definition: node.cxx:1231
const SvxBoxItem & GetBox(bool=true) const
Definition: frmatr.hxx:108
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:98
const SvxTextLeftMarginItem & GetTextLeftMargin(bool=true) const
Definition: frmatr.hxx:88
const SvxFirstLineIndentItem & GetFirstLineIndent(bool=true) const
Definition: frmatr.hxx:90
Style of a layout element.
Definition: frmfmt.hxx:72
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
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:60
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:147
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:85
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:895
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(99)
constexpr TypedWhichId< SvxTextLeftMarginItem > RES_MARGIN_TEXTLEFT(92)
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