diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2017-02-11 02:43:52 +0100 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@canonical.com> | 2017-02-14 15:44:28 +0000 |
commit | 4ae93f7d3b063d13ff757884444a468212227ef9 (patch) | |
tree | 1ea140821bedb3a8565fe0de7ee720efd3bdab3f /sw | |
parent | 183a7fc3ca46876a3ac10832bcd068d559132b4d (diff) |
give SwFlyDrawContact a clear owner: SwFlyFrameFormat
Change-Id: Ida24ef9ae65ae8658645496369673d886e0935cc
Reviewed-on: https://gerrit.libreoffice.org/34141
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/frmfmt.hxx | 13 | ||||
-rw-r--r-- | sw/source/core/draw/dcontact.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/layout/atrfrm.cxx | 14 | ||||
-rw-r--r-- | sw/source/core/layout/fly.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 19 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8graf.cxx | 17 |
6 files changed, 47 insertions, 37 deletions
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx index b55ca5d7abd0..6daa2ad2b848 100644 --- a/sw/inc/frmfmt.hxx +++ b/sw/inc/frmfmt.hxx @@ -174,11 +174,15 @@ public: // The FlyFrame-Format +class SdrModel; +class SwFlyDrawContact; + class SW_DLLPUBLIC SwFlyFrameFormat: public SwFrameFormat { friend class SwDoc; OUString msTitle; OUString msDesc; + std::unique_ptr<SwFlyDrawContact> m_pContact; /** Both not existent. it stores the previous position of Prt rectangle from RequestObjectResize @@ -190,12 +194,13 @@ class SW_DLLPUBLIC SwFlyFrameFormat: public SwFrameFormat SwFlyFrameFormat &operator=( const SwFlyFrameFormat &rCpy ) = delete; protected: - SwFlyFrameFormat( SwAttrPool& rPool, const OUString &rFormatNm, - SwFrameFormat *pDrvdFrame ) - : SwFrameFormat( rPool, rFormatNm, pDrvdFrame, RES_FLYFRMFMT ) - {} + SwFlyFrameFormat(SwAttrPool& rPool, const OUString& rFormatNm, SwFrameFormat* pDrvdFrame); public: + SwFlyDrawContact* GetContact() + { return m_pContact.get(); }; + void InitContact(SdrModel* pSdrModel); + void ClearContact(); virtual ~SwFlyFrameFormat() override; /// Creates the views. diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx index 6d2c08ba0b51..b0e2e9a01025 100644 --- a/sw/source/core/draw/dcontact.cxx +++ b/sw/source/core/draw/dcontact.cxx @@ -599,7 +599,7 @@ void SwFlyDrawContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint switch(pDrawFrameFormatHint->m_eId) { case sw::DrawFrameFormatHintId::DYING_FLYFRAMEFORMAT: - delete this; + dynamic_cast<SwFlyFrameFormat*>(const_cast<SwModify*>(&rMod))->ClearContact(); break; default: ; diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 1b420b73d0ba..aff63bdec6e1 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2866,6 +2866,20 @@ void SwFrameFormats::dumpAsXml(xmlTextWriterPtr pWriter, const char* pName) cons IMPL_FIXEDMEMPOOL_NEWDEL( SwFlyFrameFormat ) +SwFlyFrameFormat::SwFlyFrameFormat(SwAttrPool& rPool, const OUString& rFormatNm, SwFrameFormat* pDrvdFrame) + : SwFrameFormat(rPool, rFormatNm, pDrvdFrame, RES_FLYFRMFMT) + , m_pContact(nullptr) +{} + +void SwFlyFrameFormat::InitContact(SdrModel* pSdrModel) +{ + m_pContact = std::unique_ptr<SwFlyDrawContact>(new SwFlyDrawContact(this, pSdrModel)); +} +void SwFlyFrameFormat::ClearContact() +{ + m_pContact.reset(nullptr); +} + SwFlyFrameFormat::~SwFlyFrameFormat() { SwIterator<SwFlyFrame,SwFormat> aIter( *this ); diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 55f1ac2d5c8d..6e8cf9426d5e 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -397,25 +397,21 @@ void SwFlyFrame::InitDrawObj() // need to create a new Ref, else we create the Contact now. IDocumentDrawModelAccess& rIDDMA = GetFormat()->getIDocumentDrawModelAccess(); - SwFlyDrawContact *pContact = SwIterator<SwFlyDrawContact,SwFormat>( *GetFormat() ).First(); - if ( !pContact ) + if(!GetFormat()->GetContact()) { // #i52858# - method name changed - pContact = new SwFlyDrawContact( GetFormat(), - rIDDMA.GetOrCreateDrawModel() ); + GetFormat()->InitContact(rIDDMA.GetOrCreateDrawModel()); } - OSL_ENSURE( pContact, "InitDrawObj failed" ); + OSL_ENSURE(GetFormat()->GetContact(), "InitDrawObj failed"); // OD 2004-03-22 #i26791# - SetDrawObj( *(CreateNewRef( pContact )) ); + SetDrawObj( *(CreateNewRef( GetFormat()->GetContact() )) ); // Set the right Layer // OD 2004-01-19 #110582# - SdrLayerID nHeavenId = rIDDMA.GetHeavenId(); - SdrLayerID nHellId = rIDDMA.GetHellId(); // OD 2004-03-22 #i26791# - GetVirtDrawObj()->SetLayer( GetFormat()->GetOpaque().GetValue() - ? nHeavenId - : nHellId ); + GetVirtDrawObj()->SetLayer(GetFormat()->GetOpaque().GetValue() + ? rIDDMA.GetHeavenId() + : rIDDMA.GetHellId()); } void SwFlyFrame::FinitDrawObj() @@ -459,7 +455,6 @@ 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 } void SwFlyFrame::ChainFrames( SwFlyFrame *pMaster, SwFlyFrame *pFollow ) diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 4101171cab48..580522eceb28 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1360,23 +1360,20 @@ void SwXFrame::SetSelection(SwPaM& rCopySource) SdrObject *SwXFrame::GetOrCreateSdrObject(SwFlyFrameFormat &rFormat) { SdrObject* pObject = rFormat.FindSdrObject(); - if( !pObject ) + if(!pObject) { - SwDoc *pDoc = rFormat.GetDoc(); + SwDoc* pDoc = rFormat.GetDoc(); // #i52858# - method name changed SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(); - SwFlyDrawContact* pContactObject - = new SwFlyDrawContact( &rFormat, pDrawModel ); - pObject = pContactObject->GetMaster(); + rFormat.InitContact(pDrawModel); + pObject = rFormat.GetContact()->GetMaster(); const ::SwFormatSurround& rSurround = rFormat.GetSurround(); - pObject->SetLayer( - ( SURROUND_THROUGHT == rSurround.GetSurround() && - !rFormat.GetOpaque().GetValue() ) ? pDoc->getIDocumentDrawModelAccess().GetHellId() - : pDoc->getIDocumentDrawModelAccess().GetHeavenId() ); - pDrawModel->GetPage(0)->InsertObject( pObject ); + pObject->SetLayer((SURROUND_THROUGHT == rSurround.GetSurround() && !rFormat.GetOpaque().GetValue()) + ? pDoc->getIDocumentDrawModelAccess().GetHellId() + : pDoc->getIDocumentDrawModelAccess().GetHeavenId()); + pDrawModel->GetPage(0)->InsertObject(pObject); } - return pObject; } diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index 3bd74491fcbf..279960fccaff 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -2131,19 +2131,18 @@ SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord, } } -SdrObject* SwWW8ImplReader::CreateContactObject(SwFrameFormat* pFlyFormat) +SdrObject* SwWW8ImplReader::CreateContactObject(SwFrameFormat* pFormat) { - if (pFlyFormat) + if(pFormat) { - SdrObject* pNewObject = m_bNewDoc ? nullptr : pFlyFormat->FindRealSdrObject(); + SdrObject* pNewObject = m_bNewDoc ? nullptr : pFormat->FindRealSdrObject(); if (!pNewObject) - pNewObject = pFlyFormat->FindSdrObject(); - if (!pNewObject && dynamic_cast< const SwFlyFrameFormat *>( pFlyFormat ) != nullptr) + pNewObject = pFormat->FindSdrObject(); + SwFlyFrameFormat* pFlyFormat(nullptr); + if (!pNewObject && (pFlyFormat = dynamic_cast<SwFlyFrameFormat*>(pFormat))) { - SwFlyDrawContact* pContactObject - = new SwFlyDrawContact(static_cast<SwFlyFrameFormat*>(pFlyFormat), - m_pDrawModel); - pNewObject = pContactObject->GetMaster(); + pFlyFormat->InitContact(m_pDrawModel); + pNewObject = pFlyFormat->GetContact()->GetMaster(); } return pNewObject; } |