[Libreoffice-commits] core.git: sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Dec 13 10:01:37 UTC 2018


 sfx2/source/appl/workwin.cxx |   86 +++++++++++++++++++------------------------
 sfx2/source/inc/workwin.hxx  |    2 -
 2 files changed, 40 insertions(+), 48 deletions(-)

New commits:
commit 62ecafe8cffad810be842b73ee7ae5c3327edfb8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Dec 12 14:43:18 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Dec 13 11:01:12 2018 +0100

    use unique_ptr in SfxWorkWindow
    
    Change-Id: Id7133fd21a0d0d2a3138ba5f27e7637c9ed65d78
    Reviewed-on: https://gerrit.libreoffice.org/65024
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx
index 419b2b4d6d17..bde14fdef12c 100644
--- a/sfx2/source/appl/workwin.cxx
+++ b/sfx2/source/appl/workwin.cxx
@@ -428,7 +428,7 @@ void SfxWorkWindow::Sort_Impl()
     aSortedList.clear();
     for (size_t i = 0; i < aChildren.size(); ++i)
     {
-        SfxChild_Impl *pCli = aChildren[i];
+        SfxChild_Impl *pCli = aChildren[i].get();
         if (pCli)
         {
             decltype(aSortedList)::size_type k;
@@ -477,7 +477,8 @@ SfxWorkWindow::SfxWorkWindow( vcl::Window *pWin, SfxFrame *pFrm, SfxFrame* pMast
 
     // For the ObjectBars a integral place in the Childlist is reserved,
     // so that they always come in a defined order.
-    aChildren.insert( aChildren.begin(), SFX_OBJECTBAR_MAX, nullptr );
+    for (int i=0; i<SFX_OBJECTBAR_MAX; ++i)
+        aChildren.push_back( nullptr );
 
     // create and initialize layout manager listener
     Reference< css::frame::XFrame > xFrame = GetFrameInterface();
@@ -684,7 +685,7 @@ void SfxWorkWindow::FlushPendingChildSizes()
     // size to which they are getting resized towards.
     for (size_t i = 0; i < aChildren.size(); ++i)
     {
-        SfxChild_Impl *pCli = aChildren[i];
+        SfxChild_Impl *pCli = aChildren[i].get();
         if (!pCli || !pCli->pWin)
             continue;
         (void)pCli->pWin->GetSizePixel();
@@ -725,7 +726,7 @@ SvBorder SfxWorkWindow::Arrange_Impl()
 
     for (sal_uInt16 n : aSortedList)
     {
-        SfxChild_Impl* pCli = aChildren[n];
+        SfxChild_Impl* pCli = aChildren[n].get();
         if ( !pCli->pWin )
             continue;
 
@@ -873,13 +874,13 @@ SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl( vcl::Window& rWindow,
     if ( rWindow.GetParent() != pWorkWin )
         rWindow.SetParent( pWorkWin );
 
-    SfxChild_Impl *pChild = new SfxChild_Impl(rWindow, rWindow.GetSizePixel(),
+    auto pChild = o3tl::make_unique<SfxChild_Impl>(rWindow, rWindow.GetSizePixel(),
                                     eAlign, rWindow.IsVisible());
 
-    aChildren.push_back(pChild);
+    aChildren.push_back(std::move(pChild));
     bSorted = false;
     nChildren++;
-    return aChildren.back();
+    return aChildren.back().get();
 }
 
 SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl(std::shared_ptr<SfxModelessDialogController>& rController,
@@ -888,12 +889,12 @@ SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl(std::shared_ptr<SfxModelessDial
     DBG_ASSERT( aChildren.size() < 255, "too many children" );
     DBG_ASSERT( SfxChildAlignValid(eAlign), "invalid align" );
 
-    SfxChild_Impl *pChild = new SfxChild_Impl(rController, eAlign);
+    auto pChild = o3tl::make_unique<SfxChild_Impl>(rController, eAlign);
 
-    aChildren.push_back(pChild);
+    aChildren.push_back(std::move(pChild));
     bSorted = false;
     nChildren++;
-    return aChildren.back();
+    return aChildren.back().get();
 }
 
 void SfxWorkWindow::ReleaseChild_Impl( vcl::Window& rWindow )
@@ -903,21 +904,16 @@ void SfxWorkWindow::ReleaseChild_Impl( vcl::Window& rWindow )
     decltype(aChildren)::size_type nPos;
     for ( nPos = 0; nPos < aChildren.size(); ++nPos )
     {
-        pChild = aChildren[nPos];
+        pChild = aChildren[nPos].get();
         if ( pChild && pChild->pWin == &rWindow )
-            break;
-    }
-
-    if ( nPos < aChildren.size() )
-    {
-        bSorted = false;
-        nChildren--;
-        aChildren.erase(aChildren.begin() + nPos);
-        delete pChild;
-    }
-    else {
-        OSL_FAIL( "releasing unregistered child" );
+        {
+            bSorted = false;
+            nChildren--;
+            aChildren.erase(aChildren.begin() + nPos);
+            return;
+        }
     }
+    OSL_FAIL( "releasing unregistered child" );
 }
 
 void SfxWorkWindow::ReleaseChild_Impl(SfxModelessDialogController& rController)
@@ -927,21 +923,16 @@ void SfxWorkWindow::ReleaseChild_Impl(SfxModelessDialogController& rController)
     decltype(aChildren)::size_type nPos;
     for ( nPos = 0; nPos < aChildren.size(); ++nPos )
     {
-        pChild = aChildren[nPos];
+        pChild = aChildren[nPos].get();
         if (pChild && pChild->xController.get() == &rController)
-            break;
-    }
-
-    if ( nPos < aChildren.size() )
-    {
-        bSorted = false;
-        nChildren--;
-        aChildren.erase(aChildren.begin() + nPos);
-        delete pChild;
-    }
-    else {
-        OSL_FAIL( "releasing unregistered child" );
+        {
+            bSorted = false;
+            nChildren--;
+            aChildren.erase(aChildren.begin() + nPos);
+            return;
+        }
     }
+    OSL_FAIL( "releasing unregistered child" );
 }
 
 SfxChild_Impl* SfxWorkWindow::FindChild_Impl( const vcl::Window& rWindow ) const
@@ -950,7 +941,7 @@ SfxChild_Impl* SfxWorkWindow::FindChild_Impl( const vcl::Window& rWindow ) const
     sal_uInt16 nCount = aChildren.size();
     for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     {
-        SfxChild_Impl *pChild = aChildren[nPos];
+        SfxChild_Impl *pChild = aChildren[nPos].get();
         if ( pChild && pChild->pWin == &rWindow )
             return pChild;
     }
@@ -964,7 +955,7 @@ void SfxWorkWindow::ShowChildren_Impl()
 
     bool bInvisible = ( !IsVisible_Impl() || ( !pWorkWin->IsReallyVisible() && !pWorkWin->IsReallyShown() ));
 
-    for (SfxChild_Impl* pCli : aChildren)
+    for (std::unique_ptr<SfxChild_Impl>& pCli : aChildren)
     {
         if (!pCli)
             continue;
@@ -976,7 +967,7 @@ void SfxWorkWindow::ShowChildren_Impl()
             for (std::unique_ptr<SfxChildWin_Impl>& pCWin : aChildWins)
             {
                 SfxChild_Impl*    pChild  = pCWin->pCli;
-                if ( pChild == pCli )
+                if ( pChild == pCli.get() )
                 {
                     pCW = pCWin.get();
                     break;
@@ -1000,8 +991,9 @@ void SfxWorkWindow::ShowChildren_Impl()
                 {
                     if (!pCli->xController->getDialog()->get_visible())
                     {
-                        weld::DialogController::runAsync(pCli->xController,
-                            [=](sal_Int32 /*nResult*/){ pCli->xController->Close(); });
+                        auto xController = pCli->xController;
+                        weld::DialogController::runAsync(xController,
+                            [=](sal_Int32 /*nResult*/){ xController->Close(); });
                     }
                 }
                 else
@@ -1027,7 +1019,7 @@ void SfxWorkWindow::HideChildren_Impl()
 {
     for ( sal_uInt16 nPos = aChildren.size(); nPos > 0; --nPos )
     {
-        SfxChild_Impl *pChild = aChildren[nPos-1];
+        SfxChild_Impl *pChild = aChildren[nPos-1].get();
         if (!pChild)
             continue;
         if (pChild->xController)
@@ -1587,7 +1579,7 @@ void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild,
     decltype(aSortedList)::size_type n;
     for ( n=0; n<aSortedList.size(); ++n )
     {
-        SfxChild_Impl *pChild = aChildren[aSortedList[n]];
+        SfxChild_Impl *pChild = aChildren[aSortedList[n]].get();
         if ( pChild && pChild->pWin == pWin )
             break;
     }
@@ -1611,7 +1603,7 @@ void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild,
             // the inner rectangle!
             for (sal_uInt16 i : aSortedList)
             {
-                SfxChild_Impl* pCli = aChildren[i];
+                SfxChild_Impl* pCli = aChildren[i].get();
 
                 if ( pCli && pCli->nVisible == SfxChildVisibility::VISIBLE && pCli->pWin )
                 {
@@ -1698,7 +1690,7 @@ void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild,
                 return;
 
             SfxChildAlignment eAlign = SfxChildAlignment::NOALIGNMENT;
-            SfxChild_Impl *pCli = ( nPos != USHRT_MAX ) ? aChildren[nPos] : nullptr;
+            SfxChild_Impl *pCli = ( nPos != USHRT_MAX ) ? aChildren[nPos].get() : nullptr;
             if ( pCli && pDockWin )
             {
                 eAlign = pDockWin->GetAlignment();
@@ -2224,7 +2216,7 @@ void SfxWorkWindow::MakeChildrenVisible_Impl( bool bVis )
             Sort_Impl();
         for (sal_uInt16 n : aSortedList)
         {
-            SfxChild_Impl* pCli = aChildren[n];
+            SfxChild_Impl* pCli = aChildren[n].get();
             if ( (pCli->eAlign == SfxChildAlignment::NOALIGNMENT) || (IsDockingAllowed() && bInternalDockingAllowed) )
                 pCli->nVisible |= SfxChildVisibility::ACTIVE;
         }
@@ -2235,7 +2227,7 @@ void SfxWorkWindow::MakeChildrenVisible_Impl( bool bVis )
             Sort_Impl();
         for (sal_uInt16 n : aSortedList)
         {
-            SfxChild_Impl* pCli = aChildren[n];
+            SfxChild_Impl* pCli = aChildren[n].get();
             pCli->nVisible &= ~SfxChildVisibility::ACTIVE;
         }
     }
diff --git a/sfx2/source/inc/workwin.hxx b/sfx2/source/inc/workwin.hxx
index 38c41653dfdb..626c4f768cd3 100644
--- a/sfx2/source/inc/workwin.hxx
+++ b/sfx2/source/inc/workwin.hxx
@@ -195,7 +195,7 @@ class SfxWorkWindow final
     tools::Rectangle               aClientArea;
     tools::Rectangle               aUpperClientArea;
     VclPtr<SfxSplitWindow>  pSplit[SFX_SPLITWINDOWS_MAX];
-    std::vector<SfxChild_Impl*>
+    std::vector<std::unique_ptr<SfxChild_Impl>>
                             aChildren;
     std::vector<std::unique_ptr<SfxChildWin_Impl>>
                             aChildWins;


More information about the Libreoffice-commits mailing list