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 | |
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')
-rw-r--r-- | reportdesign/inc/RptObject.hxx | 22 | ||||
-rw-r--r-- | reportdesign/inc/RptPage.hxx | 2 | ||||
-rw-r--r-- | reportdesign/source/core/api/Shape.cxx | 2 | ||||
-rw-r--r-- | reportdesign/source/core/inc/ReportDrawPage.hxx | 2 | ||||
-rw-r--r-- | reportdesign/source/core/sdr/ReportDrawPage.cxx | 2 | ||||
-rw-r--r-- | reportdesign/source/core/sdr/RptObject.cxx | 44 | ||||
-rw-r--r-- | reportdesign/source/core/sdr/RptPage.cxx | 13 | ||||
-rw-r--r-- | reportdesign/source/core/sdr/UndoActions.cxx | 6 | ||||
-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 |
16 files changed, 46 insertions, 113 deletions
diff --git a/reportdesign/inc/RptObject.hxx b/reportdesign/inc/RptObject.hxx index 2e53c1f7f29b..566dc20a13fc 100644 --- a/reportdesign/inc/RptObject.hxx +++ b/reportdesign/inc/RptObject.hxx @@ -66,7 +66,6 @@ protected: mutable rtl::Reference<OPropertyMediator> m_xMediator; mutable css::uno::Reference< css::beans::XPropertyChangeListener> m_xPropertyChangeListener; mutable css::uno::Reference< css::report::XReportComponent> m_xReportComponent; - css::uno::Reference< css::uno::XInterface > m_xKeepShapeAlive; OUString m_sComponentName; bool m_bIsListening; @@ -83,13 +82,9 @@ protected: /** called by instances of derived classes to implement their overriding of getUnoShape */ - css::uno::Reference< css::drawing::XShape > + static css::uno::Reference< css::drawing::XShape > getUnoShapeOf( SdrObject& _rSdrObject ); -private: - static void ensureSdrObjectOwnership( - const css::uno::Reference< css::uno::XInterface >& _rxShape ); - public: OObjectBase(const OObjectBase&) = delete; OObjectBase& operator=(const OObjectBase&) = delete; @@ -107,11 +102,7 @@ public: css::uno::Reference< css::report::XSection> getSection() const; const OUString& getServiceName() const { return m_sComponentName; } - /** releases the reference to our UNO shape (m_xKeepShapeAlive) - */ - void releaseUnoShape() { m_xKeepShapeAlive.clear(); } - - static SdrObject* createObject( + static rtl::Reference<SdrObject> createObject( SdrModel& rTargetModel, const css::uno::Reference< css::report::XReportComponent>& _xComponent); static SdrObjKind getObjectType(const css::uno::Reference< css::report::XReportComponent>& _xComponent); @@ -129,7 +120,7 @@ private: virtual ~OCustomShape() override; public: - static OCustomShape* Create( + static rtl::Reference<OCustomShape> Create( SdrModel& rSdrModel, const css::uno::Reference< css::report::XReportComponent>& _xComponent) { @@ -173,7 +164,7 @@ private: virtual ~OOle2Obj() override; public: - static OOle2Obj* Create( + static rtl::Reference<OOle2Obj> Create( SdrModel& rSdrModel, const css::uno::Reference< css::report::XReportComponent>& _xComponent, SdrObjKind _nType) @@ -187,7 +178,7 @@ public: virtual SdrObjKind GetObjIdentifier() const override; virtual SdrInventor GetObjInventor() const override; // Clone() should make a complete copy of the object. - virtual OOle2Obj* CloneSdrObject(SdrModel& rTargetModel) const override; + virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) const override; virtual void initializeOle() override; void initializeChart( const css::uno::Reference< css::frame::XModel>& _xModel); @@ -269,10 +260,9 @@ public: virtual css::uno::Reference< css::drawing::XShape > getUnoShape() override; virtual SdrObjKind GetObjIdentifier() const override; virtual SdrInventor GetObjInventor() const override; - virtual OUnoObject* CloneSdrObject(SdrModel& rTargetModel) const override; + virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) const override; private: - virtual void setUnoShape( const css::uno::Reference< css::drawing::XShape >& rxUnoShape ) override; void impl_initializeModel_nothrow(); }; diff --git a/reportdesign/inc/RptPage.hxx b/reportdesign/inc/RptPage.hxx index 1b5a5c332cfc..ea2b53f53a0e 100644 --- a/reportdesign/inc/RptPage.hxx +++ b/reportdesign/inc/RptPage.hxx @@ -57,7 +57,7 @@ public: virtual rtl::Reference<SdrPage> CloneSdrPage(SdrModel& rTargetModel) const override; virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override; - virtual SdrObject* RemoveObject(size_t nObjNum) override; + virtual rtl::Reference<SdrObject> RemoveObject(size_t nObjNum) override; /** returns the index inside the object list which belongs to the report component. @param _xObject the report component diff --git a/reportdesign/source/core/api/Shape.cxx b/reportdesign/source/core/api/Shape.cxx index b97deeb1995e..6a52b032116a 100644 --- a/reportdesign/source/core/api/Shape.cxx +++ b/reportdesign/source/core/api/Shape.cxx @@ -298,7 +298,7 @@ uno::Reference< util::XCloneable > SAL_CALL OShape::createClone( ) SdrObject* pObject = SdrObject::getSdrObjectFromXShape( xSource ); if ( pObject ) { - SdrObject* pClone(pObject->CloneSdrObject(pObject->getSdrModelFromSdrObject())); + rtl::Reference<SdrObject> pClone(pObject->CloneSdrObject(pObject->getSdrModelFromSdrObject())); if ( pClone ) { xSet.set(pClone->getUnoShape(),uno::UNO_QUERY_THROW ); diff --git a/reportdesign/source/core/inc/ReportDrawPage.hxx b/reportdesign/source/core/inc/ReportDrawPage.hxx index e1b432247e0d..b4c10d93eb6c 100644 --- a/reportdesign/source/core/inc/ReportDrawPage.hxx +++ b/reportdesign/source/core/inc/ReportDrawPage.hxx @@ -31,7 +31,7 @@ namespace reportdesign OReportDrawPage(const OReportDrawPage&) = delete; void operator =(const OReportDrawPage&) = delete; protected: - virtual SdrObject *CreateSdrObject_( const css::uno::Reference< css::drawing::XShape > & xShape ) override; + virtual rtl::Reference<SdrObject> CreateSdrObject_( const css::uno::Reference< css::drawing::XShape > & xShape ) override; virtual css::uno::Reference< css::drawing::XShape > CreateShape( SdrObject *pObj ) const override; public: OReportDrawPage(SdrPage* pPage,const css::uno::Reference< css::report::XSection >& _xSection); diff --git a/reportdesign/source/core/sdr/ReportDrawPage.cxx b/reportdesign/source/core/sdr/ReportDrawPage.cxx index b36b9acaadfc..9c88a39990c1 100644 --- a/reportdesign/source/core/sdr/ReportDrawPage.cxx +++ b/reportdesign/source/core/sdr/ReportDrawPage.cxx @@ -42,7 +42,7 @@ OReportDrawPage::OReportDrawPage(SdrPage* _pPage { } -SdrObject* OReportDrawPage::CreateSdrObject_(const uno::Reference< drawing::XShape > & xDescr) +rtl::Reference<SdrObject> OReportDrawPage::CreateSdrObject_(const uno::Reference< drawing::XShape > & xDescr) { uno::Reference< report::XReportComponent> xReportComponent(xDescr,uno::UNO_QUERY); if ( xReportComponent.is() ) diff --git a/reportdesign/source/core/sdr/RptObject.cxx b/reportdesign/source/core/sdr/RptObject.cxx index 029359db63b0..dde0896855b2 100644 --- a/reportdesign/source/core/sdr/RptObject.cxx +++ b/reportdesign/source/core/sdr/RptObject.cxx @@ -86,17 +86,17 @@ SdrObjKind OObjectBase::getObjectType(const uno::Reference< report::XReportCompo return SdrObjKind::OLE2; } -SdrObject* OObjectBase::createObject( +rtl::Reference<SdrObject> OObjectBase::createObject( SdrModel& rTargetModel, const uno::Reference< report::XReportComponent>& _xComponent) { - SdrObject* pNewObj = nullptr; + rtl::Reference<SdrObject> pNewObj; SdrObjKind nType = OObjectBase::getObjectType(_xComponent); switch( nType ) { case SdrObjKind::ReportDesignFixedText: { - OUnoObject* pUnoObj = new OUnoObject( + rtl::Reference<OUnoObject> pUnoObj = new OUnoObject( rTargetModel, _xComponent, OUString("com.sun.star.form.component.FixedText"), @@ -160,8 +160,6 @@ SdrObject* OObjectBase::createObject( if ( pNewObj ) pNewObj->SetDoNotInsertIntoPageAutomatically( true ); - ensureSdrObjectOwnership( _xComponent ); - return pNewObj; } @@ -415,27 +413,6 @@ bool OObjectBase::supportsService( const OUString& _sServiceName ) const } -void OObjectBase::ensureSdrObjectOwnership( const uno::Reference< uno::XInterface >& _rxShape ) -{ - // UNDO in the report designer is implemented at the level of the XShapes, not - // at the level of SdrObjects. That is, if an object is removed from the report - // design, then this happens by removing the XShape from the UNO DrawPage, and - // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO - // action. - // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects - // which are removed from it, which is deadly for us. To prevent this, - // we give the XShape implementation the ownership of the SdrObject, which - // ensures the SvxDrawPage won't delete it. - SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( _rxShape ); - OSL_ENSURE( pShape, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" ); - if ( pShape ) - { - OSL_ENSURE( !pShape->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" ); - pShape->TakeSdrObjectOwnership(); - } -} - - uno::Reference< drawing::XShape > OObjectBase::getUnoShapeOf( SdrObject& _rSdrObject ) { uno::Reference< drawing::XShape > xShape( _rSdrObject.getWeakUnoShape() ); @@ -446,9 +423,6 @@ uno::Reference< drawing::XShape > OObjectBase::getUnoShapeOf( SdrObject& _rSdrOb if ( !xShape.is() ) return xShape; - ensureSdrObjectOwnership( xShape ); - - m_xKeepShapeAlive = xShape; return xShape; } @@ -566,7 +540,6 @@ uno::Reference< drawing::XShape > OCustomShape::getUnoShape() void OCustomShape::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape ) { SdrObjCustomShape::setUnoShape( rxUnoShape ); - releaseUnoShape(); m_xReportComponent.clear(); } @@ -894,13 +867,7 @@ uno::Reference< drawing::XShape > OUnoObject::getUnoShape() return OObjectBase::getUnoShapeOf( *this ); } -void OUnoObject::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape ) -{ - SdrUnoObj::setUnoShape( rxUnoShape ); - releaseUnoShape(); -} - -OUnoObject* OUnoObject::CloneSdrObject(SdrModel& rTargetModel) const +rtl::Reference<SdrObject> OUnoObject::CloneSdrObject(SdrModel& rTargetModel) const { return new OUnoObject(rTargetModel, *this); } @@ -1093,7 +1060,6 @@ uno::Reference< drawing::XShape > OOle2Obj::getUnoShape() void OOle2Obj::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape ) { SdrOle2Obj::setUnoShape( rxUnoShape ); - releaseUnoShape(); m_xReportComponent.clear(); } @@ -1114,7 +1080,7 @@ static uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider } // Clone() should make a complete copy of the object. -OOle2Obj* OOle2Obj::CloneSdrObject(SdrModel& rTargetModel) const +rtl::Reference<SdrObject> OOle2Obj::CloneSdrObject(SdrModel& rTargetModel) const { return new OOle2Obj(rTargetModel, *this); } diff --git a/reportdesign/source/core/sdr/RptPage.cxx b/reportdesign/source/core/sdr/RptPage.cxx index 135d2e1ec21b..0132ccf725a2 100644 --- a/reportdesign/source/core/sdr/RptPage.cxx +++ b/reportdesign/source/core/sdr/RptPage.cxx @@ -82,9 +82,9 @@ void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent } } -SdrObject* OReportPage::RemoveObject(size_t nObjNum) +rtl::Reference<SdrObject> OReportPage::RemoveObject(size_t nObjNum) { - SdrObject* pObj = SdrPage::RemoveObject(nObjNum); + rtl::Reference<SdrObject> pObj = SdrPage::RemoveObject(nObjNum); if (getSpecialMode()) { return pObj; @@ -94,7 +94,7 @@ SdrObject* OReportPage::RemoveObject(size_t nObjNum) reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection); uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY); pSection->notifyElementRemoved(xShape); - if (dynamic_cast< const OUnoObject *>( pObj ) != nullptr) + if (dynamic_cast< const OUnoObject *>( pObj.get() ) != nullptr) { OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj); uno::Reference< container::XChild> xChild(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY); @@ -178,13 +178,6 @@ void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos) reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection); uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY); pSection->notifyElementAdded(xShape); - - // now that the shape is inserted into its structures, we can allow the OObjectBase - // to release the reference to it - OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj ); - OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" ); - if ( pObjectBase ) - pObjectBase->releaseUnoShape(); } } // rptui diff --git a/reportdesign/source/core/sdr/UndoActions.cxx b/reportdesign/source/core/sdr/UndoActions.cxx index d4ff2d8f9d26..a63161a1b977 100644 --- a/reportdesign/source/core/sdr/UndoActions.cxx +++ b/reportdesign/source/core/sdr/UndoActions.cxx @@ -118,12 +118,6 @@ OUndoContainerAction::~OUndoContainerAction() OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv(); rEnv.RemoveElement( m_xOwnElement ); -#if OSL_DEBUG_LEVEL > 0 - SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xChild ); - SdrObject* pObject = pShape ? pShape->GetSdrObject() : nullptr; - OSL_ENSURE( pObject == nullptr || (pShape->HasSdrObjectOwnership() && !pObject->IsInserted()), - "OUndoContainerAction::~OUndoContainerAction: inconsistency in the shape/object ownership!" ); -#endif // -> dispose it try { 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; |