[Libreoffice-commits] core.git: include/svx reportdesign/source svx/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 5 10:06:55 UTC 2018


 include/svx/fmview.hxx                             |    6 +--
 reportdesign/source/ui/inc/UITools.hxx             |    2 -
 reportdesign/source/ui/misc/UITools.cxx            |    6 +--
 reportdesign/source/ui/report/ReportController.cxx |   42 +++++++--------------
 svx/source/form/fmview.cxx                         |    6 ++-
 svx/source/form/fmvwimp.cxx                        |   37 +++++++++---------
 svx/source/inc/fmvwimp.hxx                         |   11 ++---
 svx/source/svdraw/svdmodel.cxx                     |   11 ++---
 8 files changed, 52 insertions(+), 69 deletions(-)

New commits:
commit 42b629bc7f700d6f1d1b922e5c6aab119b8edf27
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Oct 4 15:11:13 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Oct 5 12:06:26 2018 +0200

    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 <noel.grandin at collabora.co.uk>

diff --git a/include/svx/fmview.hxx b/include/svx/fmview.hxx
index 90125b46f5b0..cec43527f499 100644
--- a/include/svx/fmview.hxx
+++ b/include/svx/fmview.hxx
@@ -95,15 +95,13 @@ public:
         sal_uInt16 _nControlObjectID,
         SdrInventor _nInventor,
         sal_uInt16 _nLabelObjectID,
-        SdrPage* _pLabelPage,
-        SdrPage* _pControlPage,
 
         // tdf#118963 Need a SdrModel for SdrObject creation. To make the
         // demand clear, hand over a SdrMldel&
         SdrModel& _rModel,
 
-        SdrUnoObj*& _rpLabel,
-        SdrUnoObj*& _rpControl
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl
     );
 
     virtual SdrPageView* ShowSdrPage(SdrPage* pPage) override;
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<SdrUnoObj, SdrObjectFreeOp> _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<SdrUnoObj, SdrObjectFreeOp> _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<SdrUnoObj, SdrObjectFreeOp> _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<SdrUnoObj, SdrObjectFreeOp> pLabel;
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> 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<OUnoObject*>(pControl);
+        pNewControl = pControl.release();
+        OUnoObject* pObj = dynamic_cast<OUnoObject*>(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<SdrUnoObj, SdrObjectFreeOp> 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];
@@ -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<OUnoObject*>(pControl[i]);
+                        pObjs[i] = dynamic_cast<OUnoObject*>(pControl[i].get());
                         uno::Reference<beans::XPropertySet> 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<OUnoObject*>(pControl[0]);
+                    OUnoObject* pObj = dynamic_cast<OUnoObject*>(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();
             }
         }
     }
diff --git a/svx/source/form/fmview.cxx b/svx/source/form/fmview.cxx
index 15df6aa0adfb..e4670a1fb714 100644
--- a/svx/source/form/fmview.cxx
+++ b/svx/source/form/fmview.cxx
@@ -566,13 +566,15 @@ FmFormObj* FmFormView::getMarkedGrid() const
 void FmFormView::createControlLabelPair( OutputDevice const * _pOutDev, sal_Int32 _nXOffsetMM, sal_Int32 _nYOffsetMM,
     const Reference< XPropertySet >& _rxField, const Reference< XNumberFormats >& _rxNumberFormats,
     sal_uInt16 _nControlObjectID, SdrInventor _nInventor, sal_uInt16 _nLabelObjectID,
-    SdrPage* _pLabelPage, SdrPage* _pControlPage, SdrModel& _rModel, SdrUnoObj*& _rpLabel, SdrUnoObj*& _rpControl )
+    SdrModel& _rModel,
+    std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
+    std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl )
 {
     FmXFormView::createControlLabelPair(
         *_pOutDev, _nXOffsetMM, _nYOffsetMM,
         _rxField, _rxNumberFormats,
         _nControlObjectID, "", _nInventor, _nLabelObjectID,
-        _pLabelPage, _pControlPage, _rModel,
+        _rModel,
         _rpLabel, _rpControl
     );
 }
diff --git a/svx/source/form/fmvwimp.cxx b/svx/source/form/fmvwimp.cxx
index 491a9c548ad2..ec0df8ee71a7 100644
--- a/svx/source/form/fmvwimp.cxx
+++ b/svx/source/form/fmvwimp.cxx
@@ -1333,8 +1333,8 @@ SdrObject* FmXFormView::implCreateFieldControl( const svx::ODataAccessDescriptor
         if (!nOBJID)
             return nullptr;
 
-        SdrUnoObj* pLabel( nullptr );
-        SdrUnoObj* pControl( nullptr );
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pLabel;
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl;
         if  (   !createControlLabelPair( *pOutDev, 0, 0, xField, xNumberFormats, nOBJID, sLabelPostfix,
                     pLabel, pControl, xDataSource, sDataSource, sCommand, nCommandType )
             )
@@ -1347,23 +1347,22 @@ SdrObject* FmXFormView::implCreateFieldControl( const svx::ODataAccessDescriptor
         bool bCheckbox = ( OBJ_FM_CHECKBOX == nOBJID );
         OSL_ENSURE( !bCheckbox || !pLabel, "FmXFormView::implCreateFieldControl: why was there a label created for a check box?" );
         if ( bCheckbox )
-            return pControl;
+            return pControl.release();
 
         SdrObjGroup* pGroup  = new SdrObjGroup(getView()->getSdrModelFromSdrView());
         SdrObjList* pObjList = pGroup->GetSubList();
-        pObjList->InsertObject( pLabel );
-        pObjList->InsertObject( pControl );
+        pObjList->InsertObject( pLabel.release() );
+        pObjList->InsertObject( pControl.release() );
 
         if ( bDateNTimeField )
         {   // so far we created a date field only, but we also need a time field
-            pLabel = pControl = nullptr;
             if  (   createControlLabelPair( *pOutDev, 0, 1000, xField, xNumberFormats, OBJ_FM_TIMEFIELD,
                         SvxResId(RID_STR_POSTFIX_TIME), pLabel, pControl,
                         xDataSource, sDataSource, sCommand, nCommandType )
                 )
             {
-                pObjList->InsertObject( pLabel );
-                pObjList->InsertObject( pControl );
+                pObjList->InsertObject( pLabel.release() );
+                pObjList->InsertObject( pControl.release() );
             }
         }
 
@@ -1436,8 +1435,8 @@ SdrObject* FmXFormView::implCreateXFormsControl( const svx::OXFormsDescriptor &_
         // xform control or submission button?
         if ( !xSubmission.is() )
         {
-            SdrUnoObj* pLabel( nullptr );
-            SdrUnoObj* pControl( nullptr );
+            std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pLabel;
+            std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl;
             if  (   !createControlLabelPair( *pOutDev, 0, 0, nullptr, xNumberFormats, nOBJID, sLabelPostfix,
                         pLabel, pControl, nullptr, "", "", -1 )
                 )
@@ -1457,14 +1456,14 @@ SdrObject* FmXFormView::implCreateXFormsControl( const svx::OXFormsDescriptor &_
             bool bCheckbox = ( OBJ_FM_CHECKBOX == nOBJID );
             OSL_ENSURE( !bCheckbox || !pLabel, "FmXFormView::implCreateXFormsControl: why was there a label created for a check box?" );
             if ( bCheckbox )
-                return pControl;
+                return pControl.release();
 
 
             // group objects
             SdrObjGroup* pGroup  = new SdrObjGroup(getView()->getSdrModelFromSdrView());
             SdrObjList* pObjList = pGroup->GetSubList();
-            pObjList->InsertObject(pLabel);
-            pObjList->InsertObject(pControl);
+            pObjList->InsertObject(pLabel.release());
+            pObjList->InsertObject(pControl.release());
 
             return pGroup;
         }
@@ -1512,7 +1511,8 @@ SdrObject* FmXFormView::implCreateXFormsControl( const svx::OXFormsDescriptor &_
 bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int32 _nXOffsetMM, sal_Int32 _nYOffsetMM,
         const Reference< XPropertySet >& _rxField, const Reference< XNumberFormats >& _rxNumberFormats,
         sal_uInt16 _nControlObjectID, const OUString& _rFieldPostfix,
-        SdrUnoObj*& _rpLabel, SdrUnoObj*& _rpControl,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl,
         const Reference< XDataSource >& _rxDataSource, const OUString& _rDataSourceName,
         const OUString& _rCommand, const sal_Int32 _nCommandType )
 {
@@ -1526,8 +1526,6 @@ bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int
         _rFieldPostfix,
         SdrInventor::FmForm,
         OBJ_FM_FIXEDTEXT,
-        nullptr,
-        nullptr,
 
         // tdf#118963 Hand over a SdrModel to SdrObject-creation. It uses the local m_pView
         // and already returning false when nullptr == getView() could be done, but m_pView
@@ -1559,7 +1557,8 @@ bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int
     const Reference< XPropertySet >& _rxField,
     const Reference< XNumberFormats >& _rxNumberFormats, sal_uInt16 _nControlObjectID,
     const OUString& _rFieldPostfix, SdrInventor _nInventor, sal_uInt16 _nLabelObjectID,
-    SdrPage* /*_pLabelPage*/, SdrPage* /*_pControlPage*/, SdrModel& _rModel, SdrUnoObj*& _rpLabel, SdrUnoObj*& _rpControl)
+    SdrModel& _rModel,
+    std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel, std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl)
 {
     sal_Int32 nDataType = 0;
     OUString sFieldName;
@@ -1714,8 +1713,8 @@ bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int
         FormControlFactory::initializeFieldDependentProperties( _rxField, xControlSet, _rxNumberFormats );
     }
 
-    _rpLabel = pLabel.release();
-    _rpControl = pControl.release();
+    _rpLabel = std::move(pLabel);
+    _rpControl = std::move(pControl);
     return true;
 }
 
diff --git a/svx/source/inc/fmvwimp.hxx b/svx/source/inc/fmvwimp.hxx
index 5fb1403bec42..f56a70e5db25 100644
--- a/svx/source/inc/fmvwimp.hxx
+++ b/svx/source/inc/fmvwimp.hxx
@@ -25,6 +25,7 @@
 #include <memory>
 
 #include <svx/svdmark.hxx>
+#include <svx/svdobj.hxx>
 #include "fmdocumentclassification.hxx"
 
 #include <com/sun/star/form/XForm.hpp>
@@ -259,15 +260,13 @@ private:
         const OUString& _rFieldPostfix,
         SdrInventor _nInventor,
         sal_uInt16 _nLabelObjectID,
-        SdrPage* _pLabelPage,
-        SdrPage* _pControlPage,
 
         // tdf#118963 Need a SdrModel for SdrObject creation. To make the
         // demand clear, hand over a SdrMldel&
         SdrModel& _rModel,
 
-        SdrUnoObj*& _rpLabel,
-        SdrUnoObj*& _rpControl
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl
     );
 
     bool    createControlLabelPair(
@@ -278,8 +277,8 @@ private:
         const css::uno::Reference< css::util::XNumberFormats >& _rxNumberFormats,
         sal_uInt16 _nControlObjectID,
         const OUString& _rFieldPostfix,
-        SdrUnoObj*& _rpLabel,
-        SdrUnoObj*& _rpControl,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpLabel,
+        std::unique_ptr<SdrUnoObj, SdrObjectFreeOp>& _rpControl,
         const css::uno::Reference< css::sdbc::XDataSource >& _rxDataSource,
         const OUString& _rDataSourceName,
         const OUString& _rCommand,
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index 405ef170ab23..2c1576d4988a 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -348,9 +348,9 @@ void SdrModel::Undo()
             pDo->Undo();
             if(!pRedoStack)
                 pRedoStack.reset(new std::deque<std::unique_ptr<SfxUndoAction>>);
-            SfxUndoAction* p = pUndoStack->front().release();
+            std::unique_ptr<SfxUndoAction> p = std::move(pUndoStack->front());
             pUndoStack->pop_front();
-            pRedoStack->emplace_front(p);
+            pRedoStack->emplace_front(std::move(p));
             mbUndoEnabled = bWasUndoEnabled;
         }
     }
@@ -372,9 +372,9 @@ void SdrModel::Redo()
             pDo->Redo();
             if(!pUndoStack)
                 pUndoStack.reset(new std::deque<std::unique_ptr<SfxUndoAction>>);
-            SfxUndoAction* p = pRedoStack->front().release();
+            std::unique_ptr<SfxUndoAction> p = std::move(pRedoStack->front());
             pRedoStack->pop_front();
-            pUndoStack->emplace_front(p);
+            pUndoStack->emplace_front(std::move(p));
             mbUndoEnabled = bWasUndoEnabled;
         }
     }
@@ -514,8 +514,7 @@ void SdrModel::EndUndo()
             {
                 if(pCurrentUndoGroup->GetActionCount()!=0)
                 {
-                    SdrUndoAction* pUndo=pCurrentUndoGroup.release();
-                    ImpPostUndoAction(std::unique_ptr<SdrUndoAction>(pUndo));
+                    ImpPostUndoAction(std::move(pCurrentUndoGroup));
                 }
                 else
                 {


More information about the Libreoffice-commits mailing list