summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-11-24 14:49:10 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-11-24 20:19:37 +0100
commite0fb00bbf821a842c2747060cc60b5a7e58e5775 (patch)
tree1a03dcfe325f6c092cb5405d41223787e074b22d /sw
parentcd198a34113e8fa8d1060c815b0320a52b089059 (diff)
ofz#41274 use FrameDeleteWatch to update if SwFlyFrameFormat is deleted
Change-Id: I105b5a384ff2310f15e9718cfbaacaee3b57118a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125776 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/ww8/ww8par2.cxx10
-rw-r--r--sw/source/filter/ww8/ww8par2.hxx8
-rw-r--r--sw/source/filter/ww8/ww8par6.cxx60
3 files changed, 48 insertions, 30 deletions
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 80ab5bf19716..cf07cb7cf038 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -2453,7 +2453,7 @@ void WW8TabDesc::CreateSwTable()
// Because SW cannot handle multi-page floating frames,
// _any unnecessary_ floating tables have been converted to inline.
tools::Long nLeft = 0;
- if ( m_pIo->m_xSFlyPara && !m_pIo->m_xSFlyPara->pFlyFormat )
+ if (m_pIo->m_xSFlyPara && !m_pIo->m_xSFlyPara->GetFlyFormat())
{
// Get the table orientation from the fly
// Do we also need to check m_pIo->m_xSFlyPara->bTogglePos/IsPosToggle()? [Probably not - layout-only concern]
@@ -2527,7 +2527,7 @@ void WW8TabDesc::CreateSwTable()
{
SwFormatFrameSize aFrameSize(SwFrameSize::Fixed, m_nSwWidth);
// Don't set relative width if the table is in a floating frame
- if ( m_nPercentWidth && (!m_pIo->m_xSFlyPara || !m_pIo->m_xSFlyPara->pFlyFormat) )
+ if ( m_nPercentWidth && (!m_pIo->m_xSFlyPara || !m_pIo->m_xSFlyPara->GetFlyFormat()) )
aFrameSize.SetWidthPercent(m_nPercentWidth);
m_pTable->GetFrameFormat()->SetFormatAttr(aFrameSize);
m_aItemSet.Put(aFrameSize);
@@ -2540,12 +2540,12 @@ void WW8TabDesc::CreateSwTable()
if (text::HoriOrientation::LEFT_AND_WIDTH == m_eOri)
{
if (!m_pIo->m_nInTable && m_pIo->InLocalApo() && m_pIo->m_xSFlyPara &&
- m_pIo->m_xSFlyPara->pFlyFormat && GetMinLeft())
+ m_pIo->m_xSFlyPara->GetFlyFormat() && GetMinLeft())
{
//If we are inside a frame and we have a border, the frames
//placement does not consider the tables border, which word
//displays outside the frame, so adjust here.
- SwFormatHoriOrient aHori(m_pIo->m_xSFlyPara->pFlyFormat->GetHoriOrient());
+ SwFormatHoriOrient aHori(m_pIo->m_xSFlyPara->GetFlyFormat()->GetHoriOrient());
sal_Int16 eHori = aHori.GetHoriOrient();
if ((eHori == text::HoriOrientation::NONE) || (eHori == text::HoriOrientation::LEFT) ||
(eHori == text::HoriOrientation::LEFT_AND_WIDTH))
@@ -2554,7 +2554,7 @@ void WW8TabDesc::CreateSwTable()
//the maximum is what word does ?
aHori.SetPos(m_pIo->m_xSFlyPara->nXPos + GetMinLeft());
aHori.SetHoriOrient(text::HoriOrientation::NONE);
- m_pIo->m_xSFlyPara->pFlyFormat->SetFormatAttr(aHori);
+ m_pIo->m_xSFlyPara->GetFlyFormat()->SetFormatAttr(aHori);
}
}
else // Not directly in a floating frame.
diff --git a/sw/source/filter/ww8/ww8par2.hxx b/sw/source/filter/ww8/ww8par2.hxx
index 709ca3447c0e..b8b24862b59b 100644
--- a/sw/source/filter/ww8/ww8par2.hxx
+++ b/sw/source/filter/ww8/ww8par2.hxx
@@ -44,8 +44,9 @@ private:
struct WW8SwFlyPara
{
- SwFlyFrameFormat* pFlyFormat;
-
+private:
+ std::unique_ptr<FrameDeleteWatch> m_xFlyFormat;
+public:
// part 1: directly derived Sw attributes
sal_Int16 nXPos, nYPos; // Position
sal_Int16 nLeMgn, nRiMgn; // borders
@@ -81,6 +82,9 @@ struct WW8SwFlyPara
const sal_Int32 nIniFlyDy );
void BoxUpWidth( tools::Long nWidth );
+ SwFlyFrameFormat* GetFlyFormat() const;
+ void SetFlyFormat(SwFlyFrameFormat* pNewFlyFormat);
+
std::unique_ptr<SwWW8FltAnchorStack> xOldAnchorStck;
};
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 57f73675b17e..66900d1a8cc6 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -1895,7 +1895,6 @@ WW8SwFlyPara::WW8SwFlyPara( SwPaM& rPaM,
const sal_uInt32 nPgWidth,
const sal_Int32 nIniFlyDx,
const sal_Int32 nIniFlyDy ):
-pFlyFormat(nullptr),
nXPos(0),
nYPos(0),
nLeMgn(rWW.nLeMgn),
@@ -2146,7 +2145,22 @@ void WW8SwFlyPara::BoxUpWidth( tools::Long nInWidth )
{
if( bAutoWidth && nInWidth > nNewNetWidth )
nNewNetWidth = nInWidth;
-};
+}
+
+SwFlyFrameFormat* WW8SwFlyPara::GetFlyFormat() const
+{
+ if (!m_xFlyFormat)
+ return nullptr;
+ return static_cast<SwFlyFrameFormat*>(m_xFlyFormat->GetFormat());
+}
+
+void WW8SwFlyPara::SetFlyFormat(SwFlyFrameFormat* pNewFlyFormat)
+{
+ if (pNewFlyFormat)
+ m_xFlyFormat.reset(new FrameDeleteWatch(pNewFlyFormat));
+ else
+ m_xFlyFormat.reset();
+}
// The class WW8FlySet is derived from SfxItemSetFixed and does not
// provide more, but is easier to handle for me.
@@ -2477,31 +2491,31 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p
if (pTabPos && pTabPos->bNoFly)
{
- m_xSFlyPara->pFlyFormat = nullptr;
+ m_xSFlyPara->SetFlyFormat(nullptr);
}
else
{
// ofz#34749 we shouldn't anchor anything into an 'extra' paragraph scheduled for
// removal at end of import, but check if that scenario is happening
m_aExtraneousParas.check_anchor_destination(m_pPaM->GetNode().GetTextNode());
- m_xSFlyPara->pFlyFormat = m_rDoc.MakeFlySection(WW8SwFlyPara::eAnchor,
- m_pPaM->GetPoint(), &aFlySet);
- OSL_ENSURE(m_xSFlyPara->pFlyFormat->GetAnchor().GetAnchorId() ==
+ m_xSFlyPara->SetFlyFormat(m_rDoc.MakeFlySection(WW8SwFlyPara::eAnchor,
+ m_pPaM->GetPoint(), &aFlySet));
+ OSL_ENSURE(m_xSFlyPara->GetFlyFormat()->GetAnchor().GetAnchorId() ==
WW8SwFlyPara::eAnchor, "Not the anchor type requested!");
}
- if (m_xSFlyPara->pFlyFormat)
+ if (SwFlyFrameFormat* pFlyFormat = m_xSFlyPara->GetFlyFormat())
{
if (!m_pDrawModel)
GraphicCtor();
- SdrObject* pOurNewObject = CreateContactObject(m_xSFlyPara->pFlyFormat);
+ SdrObject* pOurNewObject = CreateContactObject(pFlyFormat);
m_xWWZOrder->InsertTextLayerObject(pOurNewObject);
}
- if (RndStdIds::FLY_AS_CHAR != WW8SwFlyPara::eAnchor && m_xSFlyPara->pFlyFormat)
+ if (RndStdIds::FLY_AS_CHAR != WW8SwFlyPara::eAnchor && m_xSFlyPara->GetFlyFormat())
{
- m_xAnchorStck->AddAnchor(*m_pPaM->GetPoint(), m_xSFlyPara->pFlyFormat);
+ m_xAnchorStck->AddAnchor(*m_pPaM->GetPoint(), m_xSFlyPara->GetFlyFormat());
}
// remember Pos in body text
@@ -2513,8 +2527,8 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p
m_xSFlyPara->xOldAnchorStck = std::move(m_xAnchorStck);
m_xAnchorStck.reset(new SwWW8FltAnchorStack(m_rDoc, m_nFieldFlags));
- if (m_xSFlyPara->pFlyFormat)
- MoveInsideFly(m_xSFlyPara->pFlyFormat);
+ if (SwFlyFrameFormat* pFlyFormat = m_xSFlyPara->GetFlyFormat())
+ MoveInsideFly(pFlyFormat);
// 1) ReadText() is not called recursively because the length of
// the Apo is unknown at that time, and ReadText() needs it.
@@ -2653,7 +2667,7 @@ void SwWW8ImplReader::StopApo()
SwNodeIndex aPref(m_pPaM->GetPoint()->nNode, -1);
SwTwips nNewWidth =
- MoveOutsideFly(m_xSFlyPara->pFlyFormat, *m_xSFlyPara->xMainTextPos->GetPoint());
+ MoveOutsideFly(m_xSFlyPara->GetFlyFormat(), *m_xSFlyPara->xMainTextPos->GetPoint());
if (nNewWidth)
m_xSFlyPara->BoxUpWidth(nNewWidth);
@@ -2661,7 +2675,7 @@ void SwWW8ImplReader::StopApo()
SwTextNode* pNd = aPref.GetNode().GetTextNode();
SwTextNode* pJoinNext = nullptr;
- if (pNd && m_xSFlyPara->pFlyFormat)
+ if (pNd && m_xSFlyPara->GetFlyFormat())
{
/*
#i582#
@@ -2693,8 +2707,8 @@ void SwWW8ImplReader::StopApo()
pJoinNext = pNd;
}
- if (m_xSFlyPara->pFlyFormat)
- m_xSFlyPara->pFlyFormat->SetFormatAttr(SvxBrushItem(aBg, RES_BACKGROUND));
+ if (SwFlyFrameFormat* pFlyFormat = m_xSFlyPara->GetFlyFormat())
+ pFlyFormat->SetFormatAttr(SvxBrushItem(aBg, RES_BACKGROUND));
DeleteAnchorStack();
if (pJoinNext)
@@ -2706,11 +2720,11 @@ void SwWW8ImplReader::StopApo()
// function, the extension of the SW-fly has to be set
// manually as the SW fly has no auto function to adjust the
// frame´s size.
- if (m_xSFlyPara->nNewNetWidth > MINFLY && m_xSFlyPara->pFlyFormat) // BoxUpWidth ?
+ if (m_xSFlyPara->nNewNetWidth > MINFLY && m_xSFlyPara->GetFlyFormat()) // BoxUpWidth ?
{
tools::Long nW = m_xSFlyPara->nNewNetWidth;
nW += m_xSFlyPara->nWidth - m_xSFlyPara->nNetWidth; // border for it
- m_xSFlyPara->pFlyFormat->SetFormatAttr(
+ m_xSFlyPara->GetFlyFormat()->SetFormatAttr(
SwFormatFrameSize(m_xSFlyPara->eHeightFix, nW, m_xSFlyPara->nHeight));
}
/*
@@ -2721,10 +2735,10 @@ void SwWW8ImplReader::StopApo()
#i27204# Added AutoWidth setting. Left the old CalculateFlySize in place
so that if the user unselects autowidth, the width doesn't max out
*/
- else if (!m_xWFlyPara->nSp28 && m_xSFlyPara->pFlyFormat)
+ else if (!m_xWFlyPara->nSp28 && m_xSFlyPara->GetFlyFormat())
{
using namespace sw::util;
- SfxItemSet aFlySet( m_xSFlyPara->pFlyFormat->GetAttrSet() );
+ SfxItemSet aFlySet( m_xSFlyPara->GetFlyFormat()->GetAttrSet() );
SwFormatFrameSize aSize(ItemGet<SwFormatFrameSize>(aFlySet, RES_FRM_SIZE));
@@ -2741,7 +2755,7 @@ void SwWW8ImplReader::StopApo()
aSize.SetWidth(nNewWidth);
aSize.SetWidthSizeType(SwFrameSize::Variable);
- m_xSFlyPara->pFlyFormat->SetFormatAttr(aSize);
+ m_xSFlyPara->GetFlyFormat()->SetFormatAttr(aSize);
}
m_xSFlyPara->xMainTextPos.reset();
@@ -2751,8 +2765,8 @@ void SwWW8ImplReader::StopApo()
}
//#i8062#
- if (m_xSFlyPara && m_xSFlyPara->pFlyFormat)
- m_xFormatOfJustInsertedApo.reset(new FrameDeleteWatch(m_xSFlyPara->pFlyFormat));
+ if (m_xSFlyPara && m_xSFlyPara->GetFlyFormat())
+ m_xFormatOfJustInsertedApo.reset(new FrameDeleteWatch(m_xSFlyPara->GetFlyFormat()));
m_xSFlyPara.reset();
m_xWFlyPara.reset();