summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2017-04-23 01:53:13 +0200
committerBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>2017-04-24 18:01:20 +0200
commit83e5014a9339d7d92323517f5615b1c18c860e22 (patch)
tree725816040ca490450ed8786335edad20a9414707 /sw
parent9223d88542a5b9272f98f37feb84cd78beacac42 (diff)
move SwFlyDrawContact ownership to SwFlyFrameFormat
Change-Id: I19a65638c7489f74cc7ae5fc08364a103551cd1a Reviewed-on: https://gerrit.libreoffice.org/36878 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/frmfmt.hxx5
-rw-r--r--sw/source/core/draw/dcontact.cxx6
-rw-r--r--sw/source/core/layout/atrfrm.cxx24
-rw-r--r--sw/source/core/layout/fly.cxx4
-rw-r--r--sw/source/core/unocore/unoframe.cxx5
-rw-r--r--sw/source/filter/ww8/ww8graf.cxx4
6 files changed, 37 insertions, 11 deletions
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index c62895056200..c0da19b899a6 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -27,6 +27,7 @@
#include <list>
class SwFlyFrame;
+class SwFlyDrawContact;
class SwAnchoredObject;
class Graphic;
class ImageMap;
@@ -185,6 +186,7 @@ class SW_DLLPUBLIC SwFlyFrameFormat: public SwFrameFormat
so it can be used to move frames of non-resizable objects to align them correctly
when they get borders (this is done in SwWrtShell::CalcAndGetScale) */
Point m_aLastFlyFramePrtRectPos;
+ SwFlyDrawContact* m_pContact;
SwFlyFrameFormat( const SwFlyFrameFormat &rCpy ) = delete;
SwFlyFrameFormat &operator=( const SwFlyFrameFormat &rCpy ) = delete;
@@ -193,6 +195,7 @@ protected:
SwFlyFrameFormat( SwAttrPool& rPool, const OUString &rFormatNm,
SwFrameFormat *pDrvdFrame )
: SwFrameFormat( rPool, rFormatNm, pDrvdFrame, RES_FLYFRMFMT )
+ , m_pContact(nullptr)
{}
public:
@@ -244,6 +247,8 @@ public:
void SetLastFlyFramePrtRectPos( const Point &rPoint ) { m_aLastFlyFramePrtRectPos = rPoint; }
DECL_FIXEDMEMPOOL_NEWDEL(SwFlyFrameFormat)
+ SwFlyDrawContact* GetOrCreateContact();
+ void ClearContact();
};
//The DrawFrame-Format
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 65a3cb2bead2..8c36edad704b 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -508,9 +508,7 @@ SwVirtFlyDrawObj* SwFlyDrawContact::CreateNewRef(SwFlyFrame* pFly, SwFlyFrameFor
// need to create a new Ref, else we create the Contact now.
IDocumentDrawModelAccess& rIDDMA = pFormat->getIDocumentDrawModelAccess();
- SwFlyDrawContact *pContact = SwIterator<SwFlyDrawContact,SwFormat>( *pFormat ).First();
- if ( !pContact )
- pContact = new SwFlyDrawContact(pFormat, rIDDMA.GetOrCreateDrawModel());
+ SwFlyDrawContact* pContact = pFormat->GetOrCreateContact();
SwVirtFlyDrawObj* pDrawObj(new SwVirtFlyDrawObj(*pContact->GetMaster(), pFly));
pDrawObj->SetModel(pContact->GetMaster()->GetModel());
pDrawObj->SetUserCall(pContact);
@@ -660,7 +658,7 @@ void SwFlyDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint
switch(pDrawFrameFormatHint->m_eId)
{
case sw::DrawFrameFormatHintId::DYING_FLYFRAMEFORMAT:
- delete this;
+ const_cast<SwFlyFrameFormat*>(dynamic_cast<const SwFlyFrameFormat*>(&rMod))->ClearContact();
break;
default:
;
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 8863b5ee6526..c000dc0c8ea8 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -77,6 +77,7 @@
#include <HandleAnchorNodeChg.hxx>
#include <calbck.hxx>
#include <pagedeschint.hxx>
+#include <drawdoc.hxx>
#ifndef NDEBUG
#include <ndtxt.hxx>
@@ -2845,8 +2846,31 @@ SwFlyFrameFormat::~SwFlyFrameFormat()
} while( nullptr != ( pLast = aIter.Next() ));
CallSwClientNotify(sw::DrawFrameFormatHint(sw::DrawFrameFormatHintId::DYING_FLYFRAMEFORMAT));
+ ClearContact();
}
+SwFlyDrawContact* SwFlyFrameFormat::GetOrCreateContact()
+{
+ IDocumentDrawModelAccess& rIDDMA = getIDocumentDrawModelAccess();
+#ifdef DBG_UTIL
+ SwFlyDrawContact* pContact = SwIterator<SwFlyDrawContact,SwFormat>( *this ).First();
+ assert(pContact == m_pContact);
+#endif
+ if(!m_pContact)
+ m_pContact = new SwFlyDrawContact(this, rIDDMA.GetOrCreateDrawModel());
+ return m_pContact;
+}
+
+void SwFlyFrameFormat::ClearContact()
+{
+#ifdef DBG_UTIL
+ SwFlyDrawContact* pContact = SwIterator<SwFlyDrawContact,SwFormat>( *this ).First();
+ assert(pContact == m_pContact);
+#endif
+ delete m_pContact;
+ m_pContact = nullptr;
+};
+
/// Creates the Frames if the format describes a paragraph-bound frame.
/// MA: 1994-02-14: creates the Frames also for frames anchored at page.
void SwFlyFrameFormat::MakeFrames()
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 5afdad4b5296..e2bf037f10af 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -382,7 +382,9 @@ void SwFlyFrame::FinitDrawObj()
pContact->GetMaster()->SetUserCall(nullptr);
GetVirtDrawObj()->SetUserCall(nullptr); // Else calls delete of the ContactObj
delete GetVirtDrawObj(); // Deregisters itself at the Master
- delete pContact; // Destroys the Master itself
+ assert(dynamic_cast<SwFlyFrameFormat*>(pFormat));
+ if(pContact)
+ static_cast<SwFlyFrameFormat*>(pFormat)->ClearContact();
}
void SwFlyFrame::ChainFrames( SwFlyFrame *pMaster, SwFlyFrame *pFollow )
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 335987d46300..ded1ed2d72c9 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1364,9 +1364,7 @@ SdrObject *SwXFrame::GetOrCreateSdrObject(SwFlyFrameFormat &rFormat)
{
SwDoc *pDoc = rFormat.GetDoc();
// #i52858# - method name changed
- SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
- SwFlyDrawContact* pContactObject
- = new SwFlyDrawContact( &rFormat, pDrawModel );
+ SwFlyDrawContact* pContactObject(rFormat.GetOrCreateContact());
pObject = pContactObject->GetMaster();
const ::SwFormatSurround& rSurround = rFormat.GetSurround();
@@ -1374,6 +1372,7 @@ SdrObject *SwXFrame::GetOrCreateSdrObject(SwFlyFrameFormat &rFormat)
( css::text::WrapTextMode_THROUGH == rSurround.GetSurround() &&
!rFormat.GetOpaque().GetValue() ) ? pDoc->getIDocumentDrawModelAccess().GetHellId()
: pDoc->getIDocumentDrawModelAccess().GetHeavenId() );
+ SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
pDrawModel->GetPage(0)->InsertObject( pObject );
}
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index d81ce19773fe..2b9d0584f1d3 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -2150,9 +2150,7 @@ SdrObject* SwWW8ImplReader::CreateContactObject(SwFrameFormat* pFlyFormat)
pNewObject = pFlyFormat->FindSdrObject();
if (!pNewObject && dynamic_cast< const SwFlyFrameFormat *>( pFlyFormat ) != nullptr)
{
- SwFlyDrawContact* pContactObject
- = new SwFlyDrawContact(static_cast<SwFlyFrameFormat*>(pFlyFormat),
- m_pDrawModel);
+ SwFlyDrawContact* pContactObject(static_cast<SwFlyFrameFormat*>(pFlyFormat)->GetOrCreateContact());
pNewObject = pContactObject->GetMaster();
}
return pNewObject;