From 42b629bc7f700d6f1d1b922e5c6aab119b8edf27 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 4 Oct 2018 15:11:13 +0200 Subject: use more std::unique_ptr in FmFormView::createControlLabelPair Change-Id: I36f364739e5a37f9adc0fbad8a49a71947b7318b Reviewed-on: https://gerrit.libreoffice.org/61399 Tested-by: Jenkins Reviewed-by: Noel Grandin --- reportdesign/source/ui/inc/UITools.hxx | 2 +- reportdesign/source/ui/misc/UITools.cxx | 6 ++-- reportdesign/source/ui/report/ReportController.cxx | 42 ++++++++-------------- 3 files changed, 18 insertions(+), 32 deletions(-) (limited to 'reportdesign') diff --git a/reportdesign/source/ui/inc/UITools.hxx b/reportdesign/source/ui/inc/UITools.hxx index c58354960c99..90b60c5ba37b 100644 --- a/reportdesign/source/ui/inc/UITools.hxx +++ b/reportdesign/source/ui/inc/UITools.hxx @@ -140,7 +140,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, SdrUnoObj* _pIgnoreList[], int _nIgnoreListLength); + SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, std::unique_ptr _pIgnoreList[], int _nIgnoreListLength); /** checks whether the given OUnoObject object rectangle overlapps another object in that view. * diff --git a/reportdesign/source/ui/misc/UITools.cxx b/reportdesign/source/ui/misc/UITools.cxx index 00fe7ea80bbb..8bbfd8820fb0 100644 --- a/reportdesign/source/ui/misc/UITools.cxx +++ b/reportdesign/source/ui/misc/UITools.cxx @@ -867,11 +867,11 @@ SdrObject* isOver(const tools::Rectangle& _rRect, SdrPage const & _rPage, SdrVie return pOverlappedObj; } -static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, SdrUnoObj* _pIgnore[], int _nListLength) +static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, std::unique_ptr _pIgnore[], int _nListLength) { for(int i=0;i<_nListLength;i++) { - SdrObject *pIgnore = _pIgnore[i]; + SdrObject *pIgnore = _pIgnore[i].get(); if (pIgnore == _pObjToCheck) { return true; @@ -880,7 +880,7 @@ static bool checkArrayForOccurrence(SdrObject const * _pObjToCheck, SdrUnoObj* _ return false; } -SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, SdrUnoObj * _pIgnoreList[], int _nIgnoreListLength) +SdrObject* isOver(const tools::Rectangle& _rRect,SdrPage const & _rPage,SdrView const & _rView,bool _bAllObjects, std::unique_ptr _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 411b8eb034b8..92c417dd5c45 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -3134,8 +3134,8 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co } else { - SdrUnoObj* pLabel( nullptr ); - SdrUnoObj* pControl( nullptr ); + std::unique_ptr pLabel; + std::unique_ptr pControl; FmFormView::createControlLabelPair( getDesignView(), @@ -3146,8 +3146,6 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co _nObjectId, SdrInventor::ReportDesign, OBJ_DLG_FIXEDTEXT, - nullptr, - pSectionWindow->getReportSection().getPage(), // tdf#118963 Need a SdrModel for SdrObject creation. Dereferencing // m_aReportModel seems pretty safe, it's done in other places, initialized @@ -3157,12 +3155,10 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co pLabel, pControl); - // always use SdrObject::Free(...) for SdrObjects (!) - SdrObject* pTemp(pLabel); - SdrObject::Free(pTemp); + pLabel.reset(); - pNewControl = pControl; - OUnoObject* pObj = dynamic_cast(pControl); + pNewControl = pControl.release(); + OUnoObject* pObj = dynamic_cast(pNewControl); assert(pObj); if(pObj) { @@ -3440,9 +3436,7 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) continue; Reference< XNumberFormats > xNumberFormats(xSupplier->getNumberFormats()); - SdrUnoObj* pControl[2]; - pControl[0] = nullptr; - pControl[1] = nullptr; + std::unique_ptr pControl[2]; const sal_Int32 nRightMargin = getStyleProperty(m_xReportDefinition,PROPERTY_RIGHTMARGIN); const sal_Int32 nPaperWidth = getStyleProperty(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin; OSectionView* pSectionViews[2]; @@ -3459,8 +3453,6 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) nOBJID, SdrInventor::ReportDesign, OBJ_DLG_FIXEDTEXT, - pSectionWindow[1]->getReportSection().getPage(), - pSectionWindow[0]->getReportSection().getPage(), // tdf#118963 Need a SdrModel for SdrObject creation. Dereferencing // m_aReportModel seems pretty safe, it's done in other places, initialized @@ -3482,7 +3474,7 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) OUnoObject* pObjs[2]; for(i = 0; i < SAL_N_ELEMENTS(pControl); ++i) { - pObjs[i] = dynamic_cast(pControl[i]); + pObjs[i] = dynamic_cast(pControl[i].get()); uno::Reference xUnoProp(pObjs[i]->GetUnoControlModel(),uno::UNO_QUERY_THROW); uno::Reference< report::XReportComponent> xShapeProp(pObjs[i]->getUnoShape(),uno::UNO_QUERY_THROW); xUnoProp->setPropertyValue(PROPERTY_NAME,xShapeProp->getPropertyValue(PROPERTY_NAME)); @@ -3553,21 +3545,21 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) } xShapePropLabel->setPosition(aPosLabel); } - OUnoObject* pObj = dynamic_cast(pControl[0]); + OUnoObject* pObj = dynamic_cast(pControl[0].get()); uno::Reference< report::XFixedText> xShapeProp(pObj->getUnoShape(),uno::UNO_QUERY_THROW); xShapeProp->setName(xShapeProp->getName() + sDefaultName ); for(i = 0; i < SAL_N_ELEMENTS(pControl); ++i) // insert controls { - correctOverlapping(pControl[i],pSectionWindow[1-i]->getReportSection()); + correctOverlapping(pControl[i].get(), pSectionWindow[1-i]->getReportSection()); } if (!bLabelAboveTextField ) { if ( pSectionViews[0] == pSectionViews[1] ) { - tools::Rectangle aLabel = getRectangleFromControl(pControl[0]); - tools::Rectangle aTextfield = getRectangleFromControl(pControl[1]); + tools::Rectangle aLabel = getRectangleFromControl(pControl[0].get()); + tools::Rectangle aTextfield = getRectangleFromControl(pControl[1].get()); // create a Union of the given Label and Textfield tools::Rectangle aLabelAndTextfield( aLabel ); @@ -3603,15 +3595,9 @@ void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs) } } } - } - else - { - for(SdrUnoObj* i : pControl) - { - // always use SdrObject::Free(...) for SdrObjects (!) - SdrObject* pTemp(i); - SdrObject::Free(pTemp); - } + // not sure where the ownership of these passes too... + pControl[0].release(); + pControl[1].release(); } } } -- cgit v1.2.3