2014-06-01 14:30:36 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ToxTabStopTokenHandler.hxx"
|
|
|
|
|
|
|
|
#include "editeng/tstpitem.hxx"
|
|
|
|
#include "editeng/lrspitem.hxx"
|
|
|
|
|
|
|
|
#include "cntfrm.hxx"
|
|
|
|
#include "fmtfsize.hxx"
|
|
|
|
#include "fmtpdsc.hxx"
|
|
|
|
#include "frmfmt.hxx"
|
|
|
|
#include "ndtxt.hxx"
|
|
|
|
#include "pagedesc.hxx"
|
|
|
|
#include "pagefrm.hxx"
|
|
|
|
#include "swrect.hxx"
|
|
|
|
#include "tox.hxx"
|
|
|
|
|
|
|
|
namespace sw {
|
|
|
|
|
|
|
|
DefaultToxTabStopTokenHandler::DefaultToxTabStopTokenHandler(sal_uInt32 indexOfSectionNode,
|
|
|
|
const SwPageDesc& defaultPageDescription,
|
|
|
|
bool tabPositionIsRelativeToParagraphIndent,
|
|
|
|
TabStopReferencePolicy referencePolicy)
|
|
|
|
: mIndexOfSectionNode(indexOfSectionNode),
|
|
|
|
mDefaultPageDescription(defaultPageDescription),
|
|
|
|
mTabPositionIsRelativeToParagraphIndent(tabPositionIsRelativeToParagraphIndent),
|
|
|
|
mTabStopReferencePolicy(referencePolicy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ToxTabStopTokenHandler::HandledTabStopToken
|
|
|
|
DefaultToxTabStopTokenHandler::HandleTabStopToken(
|
2015-05-20 13:05:49 +02:00
|
|
|
const SwFormToken& aToken, const SwTextNode& targetNode, const SwRootFrm *currentLayout) const
|
2014-06-01 14:30:36 +02:00
|
|
|
{
|
|
|
|
HandledTabStopToken result;
|
|
|
|
|
|
|
|
if (aToken.bWithTab) { // #i21237#
|
|
|
|
result.text = "\t";
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether a tab adjustment has been specified.
|
|
|
|
if (SVX_TAB_ADJUST_END > aToken.eTabAlign) {
|
2015-05-20 13:05:49 +02:00
|
|
|
const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>( targetNode.SwContentNode::GetAttr(RES_LR_SPACE, true) );
|
2014-06-01 14:30:36 +02:00
|
|
|
|
|
|
|
long nTabPosition = aToken.nTabStopPosition;
|
2015-05-20 13:05:49 +02:00
|
|
|
if (!mTabPositionIsRelativeToParagraphIndent && rLR.GetTextLeft()) {
|
|
|
|
nTabPosition -= rLR.GetTextLeft();
|
2014-06-01 14:30:36 +02:00
|
|
|
}
|
|
|
|
result.tabStop = SvxTabStop(nTabPosition, aToken.eTabAlign, cDfltDecimalChar, aToken.cTabFillChar);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwRect aNdRect;
|
|
|
|
if (CanUseLayoutRectangle(targetNode, currentLayout)) {
|
|
|
|
aNdRect = targetNode.FindLayoutRect(true);
|
|
|
|
}
|
|
|
|
long nRightMargin;
|
|
|
|
if (aNdRect.IsEmpty()) {
|
|
|
|
nRightMargin = CalculatePageMarginFromPageDescription(targetNode);
|
|
|
|
} else {
|
|
|
|
nRightMargin = aNdRect.Width();
|
|
|
|
}
|
|
|
|
//#i24363# tab stops relative to indent
|
|
|
|
if (mTabStopReferencePolicy == TABSTOPS_RELATIVE_TO_INDENT) {
|
|
|
|
// left margin of paragraph style
|
2015-05-20 13:05:49 +02:00
|
|
|
const SvxLRSpaceItem& rLRSpace = targetNode.GetTextColl()->GetLRSpace();
|
2014-06-01 14:30:36 +02:00
|
|
|
nRightMargin -= rLRSpace.GetLeft();
|
2015-05-20 13:05:49 +02:00
|
|
|
nRightMargin -= rLRSpace.GetTextFirstLineOfst();
|
2014-06-01 14:30:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result.tabStop = SvxTabStop(nRightMargin, SVX_TAB_ADJUST_RIGHT, cDfltDecimalChar, aToken.cTabFillChar);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2015-05-20 13:05:49 +02:00
|
|
|
DefaultToxTabStopTokenHandler::CalculatePageMarginFromPageDescription(const SwTextNode& targetNode) const
|
2014-06-01 14:30:36 +02:00
|
|
|
{
|
2015-05-13 09:54:50 +02:00
|
|
|
size_t nPgDescNdIdx = targetNode.GetIndex() + 1;
|
2014-06-01 14:30:36 +02:00
|
|
|
const SwPageDesc *pPageDesc = targetNode.FindPageDesc(false, &nPgDescNdIdx);
|
|
|
|
if (!pPageDesc || nPgDescNdIdx < mIndexOfSectionNode) {
|
|
|
|
// Use default page description, if none is found or the found one is given by a Node before the
|
|
|
|
// table-of-content section.
|
|
|
|
pPageDesc = &mDefaultPageDescription;
|
|
|
|
}
|
2015-05-20 13:05:49 +02:00
|
|
|
const SwFrameFormat& rPgDscFormat = pPageDesc->GetMaster();
|
|
|
|
long result = rPgDscFormat.GetFrmSize().GetWidth() - rPgDscFormat.GetLRSpace().GetLeft()
|
|
|
|
- rPgDscFormat.GetLRSpace().GetRight();
|
2014-06-01 14:30:36 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*static*/ bool
|
2015-05-20 13:05:49 +02:00
|
|
|
DefaultToxTabStopTokenHandler::CanUseLayoutRectangle(const SwTextNode& targetNode, const SwRootFrm *currentLayout)
|
2014-06-01 14:30:36 +02:00
|
|
|
{
|
|
|
|
const SwPageDesc* pageDescription =
|
2015-05-20 13:05:49 +02:00
|
|
|
static_cast<const SwFormatPageDesc&>( targetNode.SwContentNode::GetAttr(RES_PAGEDESC)).GetPageDesc();
|
2014-06-01 14:30:36 +02:00
|
|
|
|
|
|
|
if (!pageDescription) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const SwFrm* pFrm = targetNode.getLayoutFrm(currentLayout, 0, 0, true);
|
|
|
|
if (!pFrm) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pFrm = pFrm->FindPageFrm();
|
|
|
|
if (!pFrm) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const SwPageFrm* pageFrm = static_cast<const SwPageFrm*>(pFrm);
|
|
|
|
if (pageDescription != pageFrm->GetPageDesc()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|