tdf#107225 tdf#122887 sw: fix reanchoring of textboxes
This commit fixes the following commits:
-tdf#130805 SwTextBoxHelper::create:
fix frame position in shape
(2479ae3ee20fc5f3cbb0c88eb09110a36e86710c)
-tdf#130802 SwTextBoxHelper::syncFlyFrameAttr:
fix dragging
(c1c93987acbb83d8352656d77ee515e98c63d46b)
Change-Id: I31abf364549778a4bbd3c4effc84df7d8b59d9e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98915
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx
index 57f8af0..a582fdd 100644
--- a/sw/source/core/doc/DocumentLayoutManager.cxx
+++ b/sw/source/core/doc/DocumentLayoutManager.cxx
@@ -471,7 +471,8 @@ SwFrameFormat *DocumentLayoutManager::CopyLayoutFormat(
boxAnchor.SetType(RndStdIds::FLY_AT_CHAR);
}
// presumably these anchors are supported though not sure
assert(RndStdIds::FLY_AT_CHAR == boxAnchor.GetAnchorId() || RndStdIds::FLY_AT_PARA == boxAnchor.GetAnchorId());
assert(RndStdIds::FLY_AT_CHAR == boxAnchor.GetAnchorId() || RndStdIds::FLY_AT_PARA == boxAnchor.GetAnchorId()
|| boxAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE);
SwFrameFormat* pDestTextBox = CopyLayoutFormat(*pSourceTextBox,
boxAnchor, bSetTextFlyAtt, bMakeFrames);
SwAttrSet aSet(pDest->GetAttrSet());
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index fb1a9f4..d80440c9 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -141,6 +141,36 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape)
text::WritingMode eMode;
if (xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_WRITINGMODE) >>= eMode)
syncProperty(pShape, RES_FRAMEDIR, 0, uno::makeAny(sal_Int16(eMode)));
const SwFormatAnchor& rAnch = pShape->GetAnchor();
if ((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PAGE && rAnch.GetPageNum() != 0)
|| ((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PARA
|| rAnch.GetAnchorId() == RndStdIds::FLY_AT_CHAR)
&& rAnch.GetContentAnchor()))
{
SfxItemSet aTxFrmSet(pFormat->GetDoc()->GetAttrPool(), aFrameFormatSetRange);
SwFormatAnchor aNewAnch = pFormat->GetAnchor();
if (pShape->GetAnchor().GetContentAnchor())
aNewAnch.SetAnchor(pShape->GetAnchor().GetContentAnchor());
if (pShape->GetAnchor().GetPageNum() > 0)
aNewAnch.SetPageNum(pShape->GetAnchor().GetPageNum());
aNewAnch.SetType(pShape->GetAnchor().GetAnchorId());
aTxFrmSet.Put(aNewAnch);
SwFormatVertOrient aVOri(pFormat->GetVertOrient());
SwFormatHoriOrient aHOri(pFormat->GetHoriOrient());
aVOri.SetVertOrient(pShape->GetVertOrient().GetVertOrient());
aHOri.SetHoriOrient(pShape->GetHoriOrient().GetHoriOrient());
aVOri.SetRelationOrient(pShape->GetVertOrient().GetRelationOrient());
aHOri.SetRelationOrient(pShape->GetHoriOrient().GetRelationOrient());
aTxFrmSet.Put(aVOri);
aTxFrmSet.Put(aHOri);
if (aTxFrmSet.Count())
pFormat->SetFormatAttr(aTxFrmSet);
}
}
void SwTextBoxHelper::destroy(SwFrameFormat* pShape)
@@ -695,14 +725,22 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const&
SfxItemIter aIter(rSet);
const SfxPoolItem* pItem = aIter.GetCurItem();
const RndStdIds aAnchId = rShape.GetAnchor().GetAnchorId();
if ((aAnchId == RndStdIds::FLY_AT_PAGE && rShape.GetAnchor().GetPageNum() != 0)
|| ((aAnchId == RndStdIds::FLY_AT_PARA || aAnchId == RndStdIds::FLY_AT_CHAR)
&& rShape.GetAnchor().GetContentAnchor()))
{
SwFormatAnchor aNewAnch = pFormat->GetAnchor();
if (rShape.GetAnchor().GetContentAnchor())
aNewAnch.SetAnchor(rShape.GetAnchor().GetContentAnchor());
if (rShape.GetAnchor().GetPageNum() > 0)
aNewAnch.SetPageNum(rShape.GetAnchor().GetPageNum());
aNewAnch.SetType(rShape.GetAnchor().GetAnchorId());
aTextBoxSet.Put(aNewAnch);
}
do
{
if (rShape.GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR)
{
const SwFormatAnchor& rShapeAnch = rShape.GetAnchor();
aTextBoxSet.Put(rShapeAnch);
}
switch (pItem->Which())
{
case RES_VERT_ORIENT:
@@ -714,10 +752,9 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const&
if (!aRect.IsEmpty())
aOrient.SetPos(aOrient.GetPos() + aRect.getY());
if (rShape.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PAGE)
{
if (rShape.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PAGE
&& rShape.GetAnchor().GetPageNum() != 0)
aOrient.SetRelationOrient(rShape.GetVertOrient().GetRelationOrient());
}
aTextBoxSet.Put(aOrient);
// restore height (shrunk for extending beyond the page bottom - tdf#91260)
@@ -738,10 +775,9 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const&
if (!aRect.IsEmpty())
aOrient.SetPos(aOrient.GetPos() + aRect.getX());
if (rShape.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PAGE)
{
if (rShape.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PAGE
&& rShape.GetAnchor().GetPageNum() != 0)
aOrient.SetRelationOrient(rShape.GetHoriOrient().GetRelationOrient());
}
aTextBoxSet.Put(aOrient);
}
break;
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index c671a7a..24da5bbb7 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -610,6 +610,10 @@ Point SwFEShell::FindAnchorPos( const Point& rAbsPos, bool bMoveIt )
new SwHandleAnchorNodeChg( *pFlyFrameFormat, aAnch ));
}
rFormat.GetDoc()->SetAttr( aAnch, rFormat );
if (SwTextBoxHelper::getOtherTextBoxFormat(&rFormat, RES_DRAWFRMFMT))
{
SwTextBoxHelper::syncFlyFrameAttr(rFormat, rFormat.GetAttrSet());
}
}
// #i28701# - no call of method
// <CheckCharRectAndTopOfLine()> for to-character anchored