diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-27 10:27:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-29 13:44:02 +0200 |
commit | 8611f6e259b807b4f19c8dc0eab86ca648891ce3 (patch) | |
tree | fa2b0e463aafb51df754768f916ca9104969a557 /reportdesign/source/ui | |
parent | 25a997c15d39fb30676a375df8ea4ce1ed2e1acd (diff) |
ref-count SdrObject
Which means we can get rid of the majestic hack of ScCaptionPtr
Previously, SdrObject was manually managed, and the ownership
passed around in very complicated fashion.
Notes:
(*) SvxShape has a strong reference to SdrObject, where
previously it had a weak reference. It is now strong
since otherwise the SdrObject will go away very eagerly.
(*) SdrObject still has a weak reference to SvxShape
(*) In the existing places that an SdrObject is being
deleted, we now just clear the reference
(*) instead of SwVirtFlyDrawObj removing itself from the
page that contains inside it's destructor, make the call site
do the removing from the page.
(*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear
because this can be called from UNO (e.g. sfx2_complex JUnit test)
and the SdrObjects need the SolarMutex when destructing.
(*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel
destructor because the existing code wants mpDrawObj in
SwAnchoredObject to be sometimes owning, sometimes not, which
results in a cycle with the new code.
Change-Id: I4d79df1660e386388e5d51030653755bca02a163
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'reportdesign/source/ui')
-rw-r--r-- | reportdesign/source/ui/inc/UITools.hxx | 2 | ||||
-rw-r--r-- | reportdesign/source/ui/inc/dlgedfac.hxx | 2 | ||||
-rw-r--r-- | reportdesign/source/ui/misc/RptUndo.cxx | 7 | ||||
-rw-r--r-- | reportdesign/source/ui/misc/UITools.cxx | 4 | ||||
-rw-r--r-- | reportdesign/source/ui/report/ReportController.cxx | 27 | ||||
-rw-r--r-- | reportdesign/source/ui/report/ReportSection.cxx | 10 | ||||
-rw-r--r-- | reportdesign/source/ui/report/ViewsWindow.cxx | 8 | ||||
-rw-r--r-- | reportdesign/source/ui/report/dlgedfac.cxx | 6 |
8 files changed, 28 insertions, 38 deletions
diff --git a/reportdesign/source/ui/inc/UITools.hxx b/reportdesign/source/ui/inc/UITools.hxx index 13aafb14fc90..b86afa4a154e 100644 --- a/reportdesign/source/ui/inc/UITools.hxx +++ b/reportdesign/source/ui/inc/UITools.hxx @@ -139,7 +139,7 @@ namespace rptui */ SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects = false,SdrObject const * _pIgnore = nullptr, sal_Int16 _nIgnoreType=0); - SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> _pIgnoreList[], int _nIgnoreListLength); + SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, rtl::Reference<SdrUnoObj> _pIgnoreList[], int _nIgnoreListLength); /** checks whether the given OUnoObject object rectangle overlapps another object in that view. * diff --git a/reportdesign/source/ui/inc/dlgedfac.hxx b/reportdesign/source/ui/inc/dlgedfac.hxx index 6a79ef7805af..f98d9f9a4ee0 100644 --- a/reportdesign/source/ui/inc/dlgedfac.hxx +++ b/reportdesign/source/ui/inc/dlgedfac.hxx @@ -33,7 +33,7 @@ public: DlgEdFactory(); ~DlgEdFactory() COVERITY_NOEXCEPT_FALSE; - DECL_STATIC_LINK(DlgEdFactory, MakeObject, SdrObjCreatorParams, SdrObject*); + DECL_STATIC_LINK(DlgEdFactory, MakeObject, SdrObjCreatorParams, rtl::Reference<SdrObject>); }; } #endif // INCLUDED_REPORTDESIGN_SOURCE_UI_INC_DLGEDFAC_HXX diff --git a/reportdesign/source/ui/misc/RptUndo.cxx b/reportdesign/source/ui/misc/RptUndo.cxx index 3f9a752f6497..e4ec1d3817d5 100644 --- a/reportdesign/source/ui/misc/RptUndo.cxx +++ b/reportdesign/source/ui/misc/RptUndo.cxx @@ -131,13 +131,6 @@ OSectionUndo::~OSectionUndo() for (uno::Reference<drawing::XShape>& xShape : m_aControls) { rEnv.RemoveElement(xShape); - -#if OSL_DEBUG_LEVEL > 0 - SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape ); - SdrObject* pObject = pShape ? pShape->GetSdrObject() : nullptr; - OSL_ENSURE( pShape && pShape->HasSdrObjectOwnership() && pObject && !pObject->IsInserted(), - "OSectionUndo::~OSectionUndo: inconsistency in the shape/object ownership!" ); -#endif try { comphelper::disposeComponent(xShape); diff --git a/reportdesign/source/ui/misc/UITools.cxx b/reportdesign/source/ui/misc/UITools.cxx index 9a7a74ffe343..57b4c32a7a7b 100644 --- a/reportdesign/source/ui/misc/UITools.cxx +++ b/reportdesign/source/ui/misc/UITools.cxx @@ -869,7 +869,7 @@ SdrObject* isOver(const tools::Rectangle& _rRect, SdrPage const & _rPage, SdrVie return pOverlappedObj; } -static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> _pIgnore[], int _nListLength) +static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, rtl::Reference<SdrUnoObj> _pIgnore[], int _nListLength) { for(int i=0;i<_nListLength;i++) { @@ -882,7 +882,7 @@ static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, std::unique_ return false; } -SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> _pIgnoreList[], int _nIgnoreListLength) +SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, rtl::Reference<SdrUnoObj> _pIgnoreList[], int _nIgnoreListLength) { SdrObject* pOverlappedObj = nullptr; SdrObjListIter aIter(&_rPage,SdrIterMode::DeepNoGroups); diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx index b74301e230a4..59bc64749bac 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -3103,7 +3103,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co if ( aPos.X < nLeftMargin ) aPos.X = nLeftMargin; - SdrObject* pNewControl = nullptr; + rtl::Reference<SdrObject> pNewControl; uno::Reference< report::XReportComponent> xShapeProp; if ( _nObjectId == SdrObjKind::CustomShape ) { @@ -3115,7 +3115,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co OUString sCustomShapeType = getDesignView()->GetInsertObjString(); if ( sCustomShapeType.isEmpty() ) sCustomShapeType = "diamond"; - OReportSection::createDefault(sCustomShapeType,pNewControl); + OReportSection::createDefault(sCustomShapeType,pNewControl.get()); pNewControl->SetLogicRect(tools::Rectangle(3000,500,6000,3500)); // switch height and width } else if ( _nObjectId == SdrObjKind::OLE2 || SdrObjKind::ReportDesignSubReport == _nObjectId ) @@ -3127,7 +3127,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co pNewControl->SetLogicRect(tools::Rectangle(3000,500,8000,5500)); // switch height and width xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY_THROW); - OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pNewControl); + OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pNewControl.get()); if ( pObj && !pObj->IsEmpty() ) { pObj->initializeChart(getModel()); @@ -3135,8 +3135,8 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co } else { - std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pLabel; - std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl; + rtl::Reference<SdrUnoObj> pLabel; + rtl::Reference<SdrUnoObj> pControl; FmFormView::createControlLabelPair( getDesignView()->GetOutDev(), @@ -3156,10 +3156,10 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co pLabel, pControl); - pLabel.reset(); + pLabel.clear(); - pNewControl = pControl.release(); - OUnoObject* pObj = dynamic_cast<OUnoObject*>(pNewControl); + pNewControl = pControl; + OUnoObject* pObj = dynamic_cast<OUnoObject*>(pNewControl.get()); assert(pObj); if(pObj) { @@ -3222,7 +3222,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co aPos.X = nPaperWidth - nShapeWidth; xShapeProp->setPosition(aPos); - correctOverlapping(pNewControl,pSectionWindow->getReportSection()); + correctOverlapping(pNewControl.get(),pSectionWindow->getReportSection()); } void OReportController::createDateTime(const Sequence< PropertyValue >& _aArgs) @@ -3437,7 +3437,7 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) continue; Reference< XNumberFormats > xNumberFormats(xSupplier->getNumberFormats()); - std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl[2]; + rtl::Reference<SdrUnoObj> pControl[2]; const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN); const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin; OSectionView* pSectionViews[2]; @@ -3472,7 +3472,7 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) { OUString sDefaultName; size_t i = 0; - OUnoObject* pObjs[2]; + rtl::Reference<OUnoObject> pObjs[2]; for(i = 0; i < SAL_N_ELEMENTS(pControl); ++i) { pObjs[i] = dynamic_cast<OUnoObject*>(pControl[i].get()); @@ -3547,7 +3547,7 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) } xShapePropLabel->setPosition(aPosLabel); } - OUnoObject* pObj = dynamic_cast<OUnoObject*>(pControl[0].get()); + rtl::Reference<OUnoObject> pObj = dynamic_cast<OUnoObject*>(pControl[0].get()); assert(pObj); uno::Reference< report::XFixedText> xShapeProp(pObj->getUnoShape(),uno::UNO_QUERY_THROW); xShapeProp->setName(xShapeProp->getName() + sDefaultName ); @@ -3598,9 +3598,6 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) } } } - // not sure where the ownership of these passes too... - pControl[0].release(); - pControl[1].release(); } } } diff --git a/reportdesign/source/ui/report/ReportSection.cxx b/reportdesign/source/ui/report/ReportSection.cxx index cb0f1ee67cb0..1d9ccd42c4e9 100644 --- a/reportdesign/source/ui/report/ReportSection.cxx +++ b/reportdesign/source/ui/report/ReportSection.cxx @@ -252,15 +252,15 @@ void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyC if ( pObject ) { // Clone to target SdrModel - SdrObject* pNewObj(pObject->CloneSdrObject(*m_pModel)); - m_pPage->InsertObject(pNewObj, SAL_MAX_SIZE); + rtl::Reference<SdrObject> pNewObj(pObject->CloneSdrObject(*m_pModel)); + m_pPage->InsertObject(pNewObj.get(), SAL_MAX_SIZE); tools::Rectangle aRet(VCLPoint(rCopy->getPosition()),VCLSize(rCopy->getSize())); aRet.setHeight(aRet.getOpenHeight() + 1); aRet.setWidth(aRet.getOpenWidth() + 1); bool bOverlapping = true; while ( bOverlapping ) { - bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj) != nullptr; + bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj.get()) != nullptr; if ( bOverlapping ) { aRet.Move(0,aRet.getOpenHeight()+1); @@ -268,7 +268,7 @@ void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyC } } m_pView->AddUndo( m_pView->GetModel()->GetSdrUndoFactory().CreateUndoNewObject( *pNewObj ) ); - m_pView->MarkObj( pNewObj, m_pView->GetSdrPageView() ); + m_pView->MarkObj( pNewObj.get(), m_pView->GetSdrPageView() ); if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getOpenHeight() + aRet.Top()) > m_xSection->getHeight()) ) m_xSection->setHeight(aRet.getOpenHeight() + aRet.Top()); } @@ -340,7 +340,7 @@ void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedOb { try { - SdrObject* pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject())); + rtl::Reference<SdrObject> pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject())); aCopies.emplace_back(pNewObj->getUnoShape(),uno::UNO_QUERY); if ( _bEraseAnddNoClone ) { diff --git a/reportdesign/source/ui/report/ViewsWindow.cxx b/reportdesign/source/ui/report/ViewsWindow.cxx index 50269c10f4fc..996d2530a1e3 100644 --- a/reportdesign/source/ui/report/ViewsWindow.cxx +++ b/reportdesign/source/ui/report/ViewsWindow.cxx @@ -968,18 +968,18 @@ void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const tools::Recta if ( &rView != &_rSection ) { - SdrObject *pNewObj = new SdrUnoObj( + rtl::Reference<SdrObject> pNewObj = new SdrUnoObj( rView.getSdrModelFromSdrView(), "com.sun.star.form.component.FixedText"); pNewObj->SetLogicRect(_aRect); pNewObj->Move(Size(0, aNewPos.Y())); bool bChanged = rView.GetModel()->IsChanged(); - rReportSection.getPage()->InsertObject(pNewObj); + rReportSection.getPage()->InsertObject(pNewObj.get()); rView.GetModel()->SetChanged(bChanged); - m_aBegDragTempList.push_back(pNewObj); + m_aBegDragTempList.push_back(pNewObj.get()); - rView.MarkObj( pNewObj, rView.GetSdrPageView() ); + rView.MarkObj( pNewObj.get(), rView.GetSdrPageView() ); } const tools::Long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height(); aNewPos.AdjustY( -nSectionHeight ); diff --git a/reportdesign/source/ui/report/dlgedfac.cxx b/reportdesign/source/ui/report/dlgedfac.cxx index 7429d5517500..fe05fcdf2b97 100644 --- a/reportdesign/source/ui/report/dlgedfac.cxx +++ b/reportdesign/source/ui/report/dlgedfac.cxx @@ -40,9 +40,9 @@ DlgEdFactory::~DlgEdFactory() COVERITY_NOEXCEPT_FALSE IMPL_STATIC_LINK( - DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* ) + DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, rtl::Reference<SdrObject> ) { - SdrObject* pNewObj = nullptr; + rtl::Reference<SdrObject> pNewObj; if ( aParams.nInventor == SdrInventor::ReportDesign ) { @@ -66,7 +66,7 @@ IMPL_STATIC_LINK( case SdrObjKind::ReportDesignVerticalFixedLine: case SdrObjKind::ReportDesignHorizontalFixedLine: { - OUnoObject* pObj = new OUnoObject(aParams.rSdrModel, SERVICE_FIXEDLINE + rtl::Reference<OUnoObject> pObj = new OUnoObject(aParams.rSdrModel, SERVICE_FIXEDLINE ,OUString("com.sun.star.awt.UnoControlFixedLineModel") ,aParams.nObjIdentifier); pNewObj = pObj; |