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

Takeshi Abe tabe at fixedpoint.jp
Tue Dec 12 06:59:21 UTC 2017


 svtools/source/brwbox/brwbox2.cxx |   15 +++++++--------
 svtools/source/brwbox/datwin.cxx  |   18 ++++++------------
 svtools/source/brwbox/datwin.hxx  |    5 ++---
 3 files changed, 15 insertions(+), 23 deletions(-)

New commits:
commit de37c379847afcef8ddf3f03f84cca1b61104851
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Mon Dec 11 22:28:32 2017 +0900

    svtools: Simplify BrowserDataWin with std::unique_ptr
    
    Change-Id: Ib63b60c1f5326cfc1b163164ae5a783ea8ba1919
    Reviewed-on: https://gerrit.libreoffice.org/46256
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svtools/source/brwbox/brwbox2.cxx b/svtools/source/brwbox/brwbox2.cxx
index f1030cd9ec31..8ff0f3e860e5 100644
--- a/svtools/source/brwbox/brwbox2.cxx
+++ b/svtools/source/brwbox/brwbox2.cxx
@@ -27,6 +27,7 @@
 #include <tools/multisel.hxx>
 #include <tools/fract.hxx>
 #include <algorithm>
+#include <memory>
 
 using namespace ::com::sun::star::datatransfer;
 
@@ -234,7 +235,7 @@ void BrowseBox::ToggleSelection()
     bNotToggleSel = true;
 
     // accumulate areas of rows to highlight
-    RectangleList aHighlightList;
+    std::vector<tools::Rectangle> aHighlightList;
     long nLastRowInRect = 0; // for the CFront
 
     // don't highlight handle column
@@ -257,20 +258,18 @@ void BrowseBox::ToggleSelection()
             Point( nOfsX, (nRow-nTopRow)*GetDataRowHeight() ),
             Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) );
         if ( aHighlightList.size() && nLastRowInRect == ( nRow - 1 ) )
-            aHighlightList[ 0 ]->Union( aAddRect );
+            aHighlightList[ 0 ].Union( aAddRect );
         else
-            aHighlightList.insert( aHighlightList.begin(), new tools::Rectangle( aAddRect ) );
+            aHighlightList.emplace( aHighlightList.begin(), aAddRect );
         nLastRowInRect = nRow;
     }
 
     // unhighlight the old selection (if any)
-    for ( size_t i = aHighlightList.size(); i > 0; )
+    while ( !aHighlightList.empty() )
     {
-        tools::Rectangle *pRect = aHighlightList[ --i ];
-        pDataWin->Invalidate( *pRect );
-        delete pRect;
+        pDataWin->Invalidate( aHighlightList.back() );
+        aHighlightList.pop_back();
     }
-    aHighlightList.clear();
 
     // unhighlight old column selection (if any)
     for ( long nColId = pColSel ? pColSel->FirstSelected() : BROWSER_ENDOFSELECTION;
diff --git a/svtools/source/brwbox/datwin.cxx b/svtools/source/brwbox/datwin.cxx
index 2378e91ed4f5..69d6501a24da 100644
--- a/svtools/source/brwbox/datwin.cxx
+++ b/svtools/source/brwbox/datwin.cxx
@@ -214,8 +214,6 @@ void BrowserDataWin::dispose()
 {
     bInDtor = true;
 
-    for (tools::Rectangle* i : aInvalidRegion)
-        delete i;
     aInvalidRegion.clear();
     pHeaderBar.clear();
     pEventWin.clear();
@@ -283,7 +281,7 @@ void BrowserDataWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rect
     {
         if (bInPaint)
         {
-            aInvalidRegion.push_back(new tools::Rectangle(rRect));
+            aInvalidRegion.emplace_back(rRect);
             return;
         }
         bInPaint = true;
@@ -293,7 +291,7 @@ void BrowserDataWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rect
     }
     else
     {
-        aInvalidRegion.push_back(new tools::Rectangle(rRect));
+        aInvalidRegion.emplace_back(rRect);
     }
 }
 
@@ -637,10 +635,8 @@ void BrowserDataWin::SetUpdateMode( bool bMode )
 
 void BrowserDataWin::DoOutstandingInvalidations()
 {
-    for (tools::Rectangle* i : aInvalidRegion) {
-        Control::Invalidate( *i );
-        delete i;
-    }
+    for (auto& rRect : aInvalidRegion)
+        Control::Invalidate( rRect );
     aInvalidRegion.clear();
 }
 
@@ -649,10 +645,8 @@ void BrowserDataWin::Invalidate( InvalidateFlags nFlags )
 {
     if ( !GetUpdateMode() )
     {
-        for (tools::Rectangle* i : aInvalidRegion)
-            delete i;
         aInvalidRegion.clear();
-        aInvalidRegion.push_back( new tools::Rectangle( Point( 0, 0 ), GetOutputSizePixel() ) );
+        aInvalidRegion.emplace_back( Point( 0, 0 ), GetOutputSizePixel() );
     }
     else
         Window::Invalidate( nFlags );
@@ -662,7 +656,7 @@ void BrowserDataWin::Invalidate( InvalidateFlags nFlags )
 void BrowserDataWin::Invalidate( const tools::Rectangle& rRect, InvalidateFlags nFlags )
 {
     if ( !GetUpdateMode() )
-        aInvalidRegion.push_back( new tools::Rectangle( rRect ) );
+        aInvalidRegion.emplace_back( rRect );
     else
         Window::Invalidate( rRect, nFlags );
 }
diff --git a/svtools/source/brwbox/datwin.hxx b/svtools/source/brwbox/datwin.hxx
index 81366e31548e..ab8ba930d193 100644
--- a/svtools/source/brwbox/datwin.hxx
+++ b/svtools/source/brwbox/datwin.hxx
@@ -25,13 +25,12 @@
 #include <vcl/timer.hxx>
 #include <vcl/image.hxx>
 #include <svtools/transfer.hxx>
+#include <memory>
 #include <vector>
 
 
 #define MIN_COLUMNWIDTH  2
 
-typedef ::std::vector< tools::Rectangle* > RectangleList;
-
 
 class ButtonFrame
 {
@@ -101,7 +100,7 @@ public:
 
     OUString        aRealRowCount;  // to show in VScrollBar
 
-    RectangleList   aInvalidRegion; // invalidated Rectangles during !UpdateMode
+    std::vector<tools::Rectangle> aInvalidRegion; // invalidated Rectangles during !UpdateMode
     bool            bInPaint;       // TRUE while in Paint
     bool            bInCommand;     // TRUE while in Command
     bool            bNoScrollBack;  // only scroll forward


More information about the Libreoffice-commits mailing list