[Libreoffice-commits] core.git: drawinglayer/Library_drawinglayer.mk emfio/Library_emfio.mk filter/CppunitTest_filter_pict_test.mk filter/Library_flash.mk filter/Library_gie.mk filter/source include/salhelper include/vcl sd/Library_sdui.mk sd/source slideshow/Library_slideshow.mk svx/source vcl/Executable_outdevgrind.mk vcl/README.GDIMetaFile vcl/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Apr 12 10:25:34 UTC 2018


 drawinglayer/Library_drawinglayer.mk        |    1 
 emfio/Library_emfio.mk                      |    1 
 filter/CppunitTest_filter_pict_test.mk      |    1 
 filter/Library_flash.mk                     |    1 
 filter/Library_gie.mk                       |    1 
 filter/source/svg/svgexport.cxx             |    2 
 filter/source/svg/svgwriter.cxx             |    1 
 include/salhelper/simplereferenceobject.hxx |    2 
 include/vcl/gdimtf.hxx                      |   10 
 include/vcl/metaact.hxx                     |  122 +++++-----
 sd/Library_sdui.mk                          |    1 
 sd/source/ui/unoidl/unopage.cxx             |    4 
 slideshow/Library_slideshow.mk              |    1 
 svx/source/dialog/_bmpmask.cxx              |   17 -
 vcl/Executable_outdevgrind.mk               |    1 
 vcl/README.GDIMetaFile                      |    4 
 vcl/source/gdi/gdimetafiletools.cxx         |    1 
 vcl/source/gdi/gdimtf.cxx                   |   71 +-----
 vcl/source/gdi/metaact.cxx                  |  329 +++++++++-------------------
 vcl/source/gdi/print2.cxx                   |    2 
 vcl/source/gdi/svmconverter.cxx             |   12 -
 vcl/source/graphic/UnoGraphicProvider.cxx   |    6 
 22 files changed, 214 insertions(+), 377 deletions(-)

New commits:
commit 5dd762ddc1829a86e7b4e23076143bc01d6073ad
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 09:53:27 2018 +0200

    hold MetaAction by rtl::Reference
    
    instead of yet another private implementation of manual reference
    counting
    
    Change-Id: Iefb1d2e595e45a2dfdc3be54e1c51b64afeaf9d8
    Reviewed-on: https://gerrit.libreoffice.org/52753
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk
index f9e61604fce7..91c137d56c29 100644
--- a/drawinglayer/Library_drawinglayer.mk
+++ b/drawinglayer/Library_drawinglayer.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,drawinglayer,\
     cppuhelper \
     i18nlangtag \
     sal \
+    salhelper \
     svl \
     svt \
     tk \
diff --git a/emfio/Library_emfio.mk b/emfio/Library_emfio.mk
index f133d498c97d..d1a0a29395c2 100644
--- a/emfio/Library_emfio.mk
+++ b/emfio/Library_emfio.mk
@@ -47,6 +47,7 @@ $(eval $(call gb_Library_use_libraries,emfio,\
     sal \
     comphelper \
     tl \
+    salhelper \
     sax \
     vcl \
     svt \
diff --git a/filter/CppunitTest_filter_pict_test.mk b/filter/CppunitTest_filter_pict_test.mk
index bba3113a4473..431166e6e3cd 100644
--- a/filter/CppunitTest_filter_pict_test.mk
+++ b/filter/CppunitTest_filter_pict_test.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,filter_pict_test, \
 	comphelper \
 	basegfx \
 	sal \
+	salhelper \
 	test \
 	tk \
 	tl \
diff --git a/filter/Library_flash.mk b/filter/Library_flash.mk
index c0fc10a66e45..7abba3682a56 100644
--- a/filter/Library_flash.mk
+++ b/filter/Library_flash.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_Library_use_libraries,flash,\
 	cppuhelper \
 	cppu \
 	sal \
+	salhelper \
 ))
 
 $(eval $(call gb_Library_use_externals,flash,\
diff --git a/filter/Library_gie.mk b/filter/Library_gie.mk
index d1513b25aed6..679114e67f68 100644
--- a/filter/Library_gie.mk
+++ b/filter/Library_gie.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Library_use_libraries,gie,\
     tk \
     cppu \
     sal \
+    salhelper \
 ))
 
 $(eval $(call gb_Library_add_exception_objects,gie,\
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index f4ab91bb6461..b6878dba5ae9 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -2004,12 +2004,10 @@ bool SVGFilter::implCreateObjectsFromShape( const Reference< css::drawing::XDraw
                                         if( bIsTextShapeStarted && ( nType == MetaActionType::BMPSCALE  || nType == MetaActionType::BMPEXSCALE ) )
                                         {
                                             GDIMetaFile aEmbeddedBitmapMtf;
-                                            pAction->Duplicate();
                                             aEmbeddedBitmapMtf.AddAction( pAction );
                                             aEmbeddedBitmapMtf.SetPrefSize( aSize );
                                             aEmbeddedBitmapMtf.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
                                             mEmbeddedBitmapActionSet.insert( ObjectRepresentation( rxShape, aEmbeddedBitmapMtf ) );
-                                            pAction->Duplicate();
                                             aMtf.AddAction( pAction );
                                         }
                                     }
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index 12b872a0a588..b414cc573f46 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -1871,7 +1871,6 @@ BitmapChecksum SVGActionWriter::GetChecksum( const MetaAction* pAction )
 {
     GDIMetaFile aMtf;
     MetaAction* pA = const_cast<MetaAction*>(pAction);
-    pA->Duplicate();
     aMtf.AddAction( pA );
     return aMtf.GetChecksum();
 }
diff --git a/include/salhelper/simplereferenceobject.hxx b/include/salhelper/simplereferenceobject.hxx
index 662c31a72350..d8f86f52d00a 100644
--- a/include/salhelper/simplereferenceobject.hxx
+++ b/include/salhelper/simplereferenceobject.hxx
@@ -91,9 +91,9 @@ public:
 protected:
     virtual ~SimpleReferenceObject() COVERITY_NOEXCEPT_FALSE;
 
-private:
     oslInterlockedCount m_nCount;
 
+private:
     /** not implemented
      */
     SimpleReferenceObject(SimpleReferenceObject &) SAL_DELETED_FUNCTION;
diff --git a/include/vcl/gdimtf.hxx b/include/vcl/gdimtf.hxx
index 07fd8444492e..ccf3380c8f5a 100644
--- a/include/vcl/gdimtf.hxx
+++ b/include/vcl/gdimtf.hxx
@@ -58,7 +58,7 @@ VCL_DLLPUBLIC SvStream& WriteGDIMetaFile( SvStream& rOStm, const GDIMetaFile& rG
 class VCL_DLLPUBLIC GDIMetaFile final
 {
 private:
-    ::std::vector< MetaAction* > m_aList;
+    ::std::vector< rtl::Reference<MetaAction> > m_aList;
     size_t          m_nCurrentActionElement;
 
     MapMode         m_aPrefMapMode;
@@ -157,14 +157,14 @@ public:
 
     size_t          GetActionSize() const;
 
-    void            AddAction( MetaAction* pAction );
-    void            AddAction( MetaAction* pAction, size_t nPos );
-    void            push_back( MetaAction* pAction );
+    void            AddAction( rtl::Reference<MetaAction> pAction );
+    void            AddAction( rtl::Reference<MetaAction> pAction, size_t nPos );
+    void            push_back( rtl::Reference<MetaAction> pAction );
     /**
      * @param pAction takes ownership
      * @param nAction the action to replace
      */
-    MetaAction*     ReplaceAction( MetaAction* pAction, size_t nAction );
+    void ReplaceAction( rtl::Reference<MetaAction> pAction, size_t nAction );
 
     MetaAction*     FirstAction();
     MetaAction*     NextAction();
diff --git a/include/vcl/metaact.hxx b/include/vcl/metaact.hxx
index 8deb04222fc8..2578cfd26c3e 100644
--- a/include/vcl/metaact.hxx
+++ b/include/vcl/metaact.hxx
@@ -36,6 +36,8 @@
 #include <vcl/gfxlink.hxx>
 #include <vcl/lineinfo.hxx>
 #include <vcl/metaactiontypes.hxx>
+#include <salhelper/simplereferenceobject.hxx>
+#include <rtl/ref.hxx>
 
 class SvStream;
 enum class DrawTextFlags;
@@ -60,22 +62,24 @@ struct ImplMetaWriteData
     {}
 };
 
-class VCL_DLLPUBLIC MetaAction
+class VCL_DLLPUBLIC MetaAction : public salhelper::SimpleReferenceObject
 {
 private:
-    sal_uLong            mnRefCount;
     MetaActionType       mnType;
 
 protected:
-    virtual             ~MetaAction();
+    virtual             ~MetaAction() override;
 
 public:
                         MetaAction();
     explicit            MetaAction( MetaActionType nType );
+                        MetaAction( MetaAction const & );
 
     virtual void        Execute( OutputDevice* pOut );
 
-    virtual MetaAction* Clone();
+    oslInterlockedCount GetRefCount() { return m_nCount; }
+
+    virtual rtl::Reference<MetaAction> Clone();
 
     virtual void        Move( long nHorzMove, long nVertMove );
     virtual void        Scale( double fScaleX, double fScaleY );
@@ -84,10 +88,6 @@ public:
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData );
 
     MetaActionType      GetType() const { return mnType; }
-    sal_uLong           GetRefCount() const { return mnRefCount; }
-    void                ResetRefCount() { mnRefCount = 1; }
-    void                Duplicate()  { mnRefCount++; }
-    void                Delete() { if ( 0 == --mnRefCount ) delete this; }
 
 public:
     static MetaAction*  ReadMetaAction( SvStream& rIStm, ImplMetaReadData* pData );
@@ -105,7 +105,7 @@ protected:
     virtual             ~MetaPixelAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -129,7 +129,7 @@ protected:
     virtual             ~MetaPointAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -155,7 +155,7 @@ protected:
     virtual             ~MetaLineAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -183,7 +183,7 @@ protected:
     virtual             ~MetaRectAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -209,7 +209,7 @@ protected:
     virtual             ~MetaRoundRectAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -236,7 +236,7 @@ protected:
     virtual             ~MetaEllipseAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -262,7 +262,7 @@ protected:
     virtual             ~MetaArcAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -291,7 +291,7 @@ protected:
     virtual             ~MetaPieAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -320,7 +320,7 @@ protected:
     virtual             ~MetaChordAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -348,7 +348,7 @@ protected:
     virtual             ~MetaPolyLineAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -374,7 +374,7 @@ protected:
     virtual             ~MetaPolygonAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -398,7 +398,7 @@ protected:
     virtual             ~MetaPolyPolygonAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -425,7 +425,7 @@ protected:
     virtual             ~MetaTextAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -464,7 +464,7 @@ public:
 
     virtual void        Execute( OutputDevice* pOut ) override;
 
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
 
     virtual void    Move( long nHorzMove, long nVertMove ) override;
     virtual void    Scale( double fScaleX, double fScaleY ) override;
@@ -495,7 +495,7 @@ protected:
     virtual             ~MetaStretchTextAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -527,7 +527,7 @@ protected:
     virtual             ~MetaTextRectAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -558,7 +558,7 @@ protected:
     virtual             ~MetaTextLineAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -589,7 +589,7 @@ protected:
     virtual             ~MetaBmpAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -616,7 +616,7 @@ protected:
     virtual             ~MetaBmpScaleAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -647,7 +647,7 @@ protected:
     virtual             ~MetaBmpScalePartAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -678,7 +678,7 @@ protected:
     virtual             ~MetaBmpExAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -705,7 +705,7 @@ protected:
     virtual             ~MetaBmpExScaleAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -736,7 +736,7 @@ protected:
     virtual             ~MetaBmpExScalePartAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -768,7 +768,7 @@ protected:
     virtual             ~MetaMaskAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -799,7 +799,7 @@ protected:
     virtual             ~MetaMaskScaleAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -833,7 +833,7 @@ protected:
     virtual             ~MetaMaskScalePartAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -866,7 +866,7 @@ protected:
     virtual             ~MetaGradientAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -892,7 +892,7 @@ protected:
     virtual             ~MetaGradientExAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -918,7 +918,7 @@ protected:
     virtual             ~MetaHatchAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -944,7 +944,7 @@ protected:
     virtual             ~MetaWallpaperAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -971,7 +971,7 @@ protected:
     virtual             ~MetaClipRegionAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -996,7 +996,7 @@ protected:
     virtual             ~MetaISectRectClipRegionAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1020,7 +1020,7 @@ protected:
     virtual             ~MetaISectRegionClipRegionAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1045,7 +1045,7 @@ protected:
     virtual             ~MetaMoveClipRegionAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1070,7 +1070,7 @@ protected:
     virtual             ~MetaLineColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1093,7 +1093,7 @@ protected:
     virtual             ~MetaFillColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1115,7 +1115,7 @@ protected:
     virtual             ~MetaTextColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1137,7 +1137,7 @@ protected:
     virtual             ~MetaTextFillColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1160,7 +1160,7 @@ protected:
     virtual             ~MetaTextLineColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1183,7 +1183,7 @@ protected:
     virtual             ~MetaOverlineColorAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1205,7 +1205,7 @@ protected:
     virtual             ~MetaTextAlignAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1226,7 +1226,7 @@ protected:
     virtual             ~MetaMapModeAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1249,7 +1249,7 @@ protected:
     virtual             ~MetaFontAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1272,7 +1272,7 @@ protected:
     virtual             ~MetaPushAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1290,7 +1290,7 @@ protected:
     virtual             ~MetaPopAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 };
@@ -1307,7 +1307,7 @@ protected:
     virtual             ~MetaRasterOpAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1329,7 +1329,7 @@ protected:
     virtual             ~MetaTransparentAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1357,7 +1357,7 @@ protected:
     virtual             ~MetaFloatTransparentAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1388,7 +1388,7 @@ protected:
     virtual             ~MetaEPSAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1417,7 +1417,7 @@ protected:
     virtual             ~MetaRefPointAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1451,7 +1451,7 @@ public:
     virtual void        Scale( double fScaleX, double fScaleY ) override;
 
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1473,7 +1473,7 @@ protected:
     virtual             ~MetaLayoutModeAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
@@ -1494,7 +1494,7 @@ protected:
     virtual             ~MetaTextLanguageAction() override;
 public:
     virtual void        Execute( OutputDevice* pOut ) override;
-    virtual MetaAction* Clone() override;
+    virtual rtl::Reference<MetaAction> Clone() override;
     virtual void        Write( SvStream& rOStm, ImplMetaWriteData* pData ) override;
     virtual void        Read( SvStream& rIStm, ImplMetaReadData* pData ) override;
 
diff --git a/sd/Library_sdui.mk b/sd/Library_sdui.mk
index b928144145a2..c2ca40f6ed95 100644
--- a/sd/Library_sdui.mk
+++ b/sd/Library_sdui.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_Library_use_libraries,sdui,\
     fwl \
     fwe \
     sal \
+    salhelper \
     sd \
     sfx \
     sot \
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index e5e48f13d411..4def39c4a18e 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -1112,8 +1112,8 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName )
                 if (xMetaFile)
                 {
                     Size    aSize( GetPage()->GetSize() );
-                    xMetaFile->AddAction( static_cast<MetaAction*>(new MetaFillColorAction( COL_WHITE, true )), 0 );
-                    xMetaFile->AddAction( static_cast<MetaAction*>(new MetaRectAction( ::tools::Rectangle( Point(), aSize ) )), 1 );
+                    xMetaFile->AddAction( new MetaFillColorAction( COL_WHITE, true ), 0 );
+                    xMetaFile->AddAction( new MetaRectAction( ::tools::Rectangle( Point(), aSize ) ), 1 );
                     xMetaFile->SetPrefMapMode(MapMode(MapUnit::Map100thMM));
                     xMetaFile->SetPrefSize( aSize );
 
diff --git a/slideshow/Library_slideshow.mk b/slideshow/Library_slideshow.mk
index 346d5b3a7b0c..d7367458c3b0 100644
--- a/slideshow/Library_slideshow.mk
+++ b/slideshow/Library_slideshow.mk
@@ -46,6 +46,7 @@ $(eval $(call gb_Library_use_libraries,slideshow,\
     cppu \
     cppuhelper \
     sal \
+    salhelper \
     svt \
     tl \
     utl \
diff --git a/svx/source/dialog/_bmpmask.cxx b/svx/source/dialog/_bmpmask.cxx
index d436061d9511..74955710061b 100644
--- a/svx/source/dialog/_bmpmask.cxx
+++ b/svx/source/dialog/_bmpmask.cxx
@@ -728,8 +728,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                     if( bReplace )
                         pAct = new MetaPixelAction( pAct->GetPoint(), aCol );
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -744,8 +742,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                     if( bReplace )
                         pAct = new MetaLineColorAction( aCol, !pTrans[ i ] );
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -760,8 +756,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                     if( bReplace )
                         pAct = new MetaFillColorAction( aCol, !pTrans[ i ] );
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -776,8 +770,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                     if( bReplace )
                         pAct = new MetaTextColorAction( aCol );
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -792,8 +784,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                     if( bReplace )
                         pAct = new MetaTextFillColorAction( aCol, !pTrans[ i ] );
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -812,8 +802,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
                         aFont.SetColor( aCol );
                         pAct = new MetaFontAction( aFont );
                     }
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -832,8 +820,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
                         aWall.SetColor( aCol );
                         pAct = new MetaWallpaperAction( pAct->GetRect(), aWall );
                     }
-                    else
-                        pAct->Duplicate();
 
                     aMtf.AddAction( pAct );
                 }
@@ -903,7 +889,6 @@ GDIMetaFile SvxBmpMask::ImpMask( const GDIMetaFile& rMtf )
 
                 default:
                 {
-                    pAction->Duplicate();
                     aMtf.AddAction( pAction );
                 }
                 break;
@@ -967,8 +952,6 @@ GDIMetaFile SvxBmpMask::ImpReplaceTransparency( const GDIMetaFile& rMtf, const C
     for ( size_t i = 0; i < nActionCount; i++ )
     {
         MetaAction* pAct = rMtf.GetAction( i );
-
-        pAct->Duplicate();
         aMtf.AddAction( pAct );
     }
 
diff --git a/vcl/Executable_outdevgrind.mk b/vcl/Executable_outdevgrind.mk
index 7b60d5e1b8c0..7c12e24ac327 100644
--- a/vcl/Executable_outdevgrind.mk
+++ b/vcl/Executable_outdevgrind.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Executable_use_libraries,outdevgrind,\
     cppu \
     cppuhelper \
     comphelper \
+    salhelper \
 ))
 
 $(eval $(call gb_Executable_add_exception_objects,outdevgrind,\
diff --git a/vcl/README.GDIMetaFile b/vcl/README.GDIMetaFile
index 2c8879de0c25..98be38d086d8 100644
--- a/vcl/README.GDIMetaFile
+++ b/vcl/README.GDIMetaFile
@@ -153,10 +153,6 @@ READ AND WRITE FUNCTIONS
 INTROSPECTIVE FUNCTIONS
 
 - GetType
-- GetRefCount                               - reference counter
-- ResetRefCount                             - reset to 1
-- Duplicate                                 - increment refcounter
-- Delete                                    - delete if all instances no longer being referenced
 
 
 
diff --git a/vcl/source/gdi/gdimetafiletools.cxx b/vcl/source/gdi/gdimetafiletools.cxx
index 2170f2a9be2a..84cd0e373739 100644
--- a/vcl/source/gdi/gdimetafiletools.cxx
+++ b/vcl/source/gdi/gdimetafiletools.cxx
@@ -1042,7 +1042,6 @@ void clipMetafileContentAgainstOwnRegions(GDIMetaFile& rSource)
         }
         else
         {
-            const_cast< MetaAction* >(pAction)->Duplicate();
             aTarget.AddAction(const_cast< MetaAction* >(pAction));
         }
     }
diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx
index 630619a2a059..06700e436c5d 100644
--- a/vcl/source/gdi/gdimtf.cxx
+++ b/vcl/source/gdi/gdimtf.cxx
@@ -136,10 +136,8 @@ GDIMetaFile::GDIMetaFile( const GDIMetaFile& rMtf ) :
     m_bRecord         ( false ),
     m_bUseCanvas      ( rMtf.m_bUseCanvas )
 {
-    // Increment RefCount of MetaActions
     for( size_t i = 0, n = rMtf.GetActionSize(); i < n; ++i )
     {
-        rMtf.GetAction( i )->Duplicate();
         m_aList.push_back( rMtf.GetAction( i ) );
     }
 
@@ -164,33 +162,29 @@ size_t GDIMetaFile::GetActionSize() const
 
 MetaAction* GDIMetaFile::GetAction( size_t nAction ) const
 {
-    return (nAction < m_aList.size()) ? m_aList[ nAction ] : nullptr;
+    return (nAction < m_aList.size()) ? m_aList[ nAction ].get() : nullptr;
 }
 
 MetaAction* GDIMetaFile::FirstAction()
 {
     m_nCurrentActionElement = 0;
-    return m_aList.empty() ? nullptr : m_aList[ 0 ];
+    return m_aList.empty() ? nullptr : m_aList[ 0 ].get();
 }
 
 MetaAction* GDIMetaFile::NextAction()
 {
-    return ( m_nCurrentActionElement + 1 < m_aList.size() ) ? m_aList[ ++m_nCurrentActionElement ] : nullptr;
+    return ( m_nCurrentActionElement + 1 < m_aList.size() ) ? m_aList[ ++m_nCurrentActionElement ].get() : nullptr;
 }
 
-MetaAction* GDIMetaFile::ReplaceAction( MetaAction* pAction, size_t nAction )
+void GDIMetaFile::ReplaceAction( rtl::Reference<MetaAction> pAction, size_t nAction )
 {
     if ( nAction >= m_aList.size() )
     {
-        // this method takes ownership of pAction and is
-        // therefore responsible for deleting it
-        pAction->Delete();
-        return nullptr;
+        return;
     }
     //fdo#39995 This doesn't increment the incoming action ref-count nor does it
     //decrement the outgoing action ref-count
     std::swap(pAction, m_aList[nAction]);
-    return pAction;
 }
 
 GDIMetaFile& GDIMetaFile::operator=( const GDIMetaFile& rMtf )
@@ -202,7 +196,6 @@ GDIMetaFile& GDIMetaFile::operator=( const GDIMetaFile& rMtf )
         // Increment RefCount of MetaActions
         for( size_t i = 0, n = rMtf.GetActionSize(); i < n; ++i )
         {
-            rMtf.GetAction( i )->Duplicate();
             m_aList.push_back( rMtf.GetAction( i ) );
         }
 
@@ -258,8 +251,6 @@ void GDIMetaFile::Clear()
     if( m_bRecord )
         Stop();
 
-    for(MetaAction* i : m_aList)
-        i->Delete();
     m_aList.clear();
 }
 
@@ -320,7 +311,6 @@ void GDIMetaFile::Play( GDIMetaFile& rMtf )
         {
             if( pAction )
             {
-                pAction->Duplicate();
                 rMtf.AddAction( pAction );
             }
 
@@ -552,24 +542,21 @@ void GDIMetaFile::WindPrev()
             --m_nCurrentActionElement;
 }
 
-void GDIMetaFile::AddAction( MetaAction* pAction )
+void GDIMetaFile::AddAction( rtl::Reference<MetaAction> pAction )
 {
     m_aList.push_back( pAction );
 
     if( m_pPrev )
     {
-        pAction->Duplicate();
         m_pPrev->AddAction( pAction );
     }
 }
 
-void GDIMetaFile::AddAction( MetaAction* pAction, size_t nPos )
+void GDIMetaFile::AddAction( rtl::Reference<MetaAction> pAction, size_t nPos )
 {
     if ( nPos < m_aList.size() )
     {
-        ::std::vector< MetaAction* >::iterator it = m_aList.begin();
-        ::std::advance( it, nPos );
-        m_aList.insert( it, pAction );
+        m_aList.insert( m_aList.begin() + nPos, pAction );
     }
     else
     {
@@ -578,12 +565,11 @@ void GDIMetaFile::AddAction( MetaAction* pAction, size_t nPos )
 
     if( m_pPrev )
     {
-        pAction->Duplicate();
         m_pPrev->AddAction( pAction, nPos );
     }
 }
 
-void GDIMetaFile::push_back( MetaAction* pAction )
+void GDIMetaFile::push_back( rtl::Reference<MetaAction> pAction )
 {
     m_aList.push_back( pAction );
 }
@@ -640,8 +626,8 @@ void GDIMetaFile::Move( long nX, long nY )
 
         if( pAct->GetRefCount() > 1 )
         {
-            m_aList[ m_nCurrentActionElement ] = pModAct = pAct->Clone();
-            pAct->Delete();
+            m_aList[ m_nCurrentActionElement ] = pAct->Clone();
+            pModAct = m_aList[ m_nCurrentActionElement ].get();
         }
         else
             pModAct = pAct;
@@ -675,8 +661,8 @@ void GDIMetaFile::Move( long nX, long nY, long nDPIX, long nDPIY )
 
         if( pAct->GetRefCount() > 1 )
         {
-            m_aList[ m_nCurrentActionElement ] = pModAct = pAct->Clone();
-            pAct->Delete();
+            m_aList[ m_nCurrentActionElement ] = pAct->Clone();
+            pModAct = m_aList[ m_nCurrentActionElement ].get();
         }
         else
             pModAct = pAct;
@@ -709,8 +695,8 @@ void GDIMetaFile::Scale( double fScaleX, double fScaleY )
 
         if( pAct->GetRefCount() > 1 )
         {
-            m_aList[ m_nCurrentActionElement ] = pModAct = pAct->Clone();
-            pAct->Delete();
+            m_aList[ m_nCurrentActionElement ] = pAct->Clone();
+            pModAct = m_aList[ m_nCurrentActionElement ].get();
         }
         else
             pModAct = pAct;
@@ -754,7 +740,6 @@ void GDIMetaFile::Clip( const tools::Rectangle& i_rClipRect )
                 aNewReg.Intersect( pOldAct->GetRegion() );
             MetaClipRegionAction* pNewAct = new MetaClipRegionAction( aNewReg, true );
             m_aList[ m_nCurrentActionElement ] = pNewAct;
-            pOldAct->Delete();
         }
     }
 }
@@ -809,7 +794,6 @@ void GDIMetaFile::ImplAddGradientEx( GDIMetaFile&         rMtf,
     for( i=0; i < nAct; ++i )
     {
         MetaAction* pMetaAct = aGradMtf.GetAction( i );
-        pMetaAct->Duplicate();
         rMtf.AddAction( pMetaAct );
     }
 }
@@ -1132,7 +1116,6 @@ void GDIMetaFile::Rotate( long nAngle10 )
                            || pCommentAct->GetComment() == "XPATHFILL_SEQ_END" )
                     {
                         pAction->Execute( aMapVDev.get() );
-                        pAction->Duplicate();
                         aMtf.AddAction( pAction );
                     }
                 }
@@ -1192,7 +1175,6 @@ void GDIMetaFile::Rotate( long nAngle10 )
                     aMtf.AddAction( new MetaClipRegionAction( vcl::Region( ImplGetRotatedPolyPolygon( pAct->GetRegion().GetAsPolyPolygon(), aRotAnchor, aRotOffset, fSin, fCos ) ), true ) );
                 else
                 {
-                    pAction->Duplicate();
                     aMtf.AddAction( pAction );
                 }
             }
@@ -1216,7 +1198,6 @@ void GDIMetaFile::Rotate( long nAngle10 )
                     aMtf.AddAction( new MetaISectRegionClipRegionAction( vcl::Region( ImplGetRotatedPolyPolygon( rRegion.GetAsPolyPolygon(), aRotAnchor, aRotOffset, fSin, fCos ) ) ) );
                 else
                 {
-                    pAction->Duplicate();
                     aMtf.AddAction( pAction );
                 }
             }
@@ -1255,7 +1236,6 @@ void GDIMetaFile::Rotate( long nAngle10 )
             default:
             {
                 pAction->Execute( aMapVDev.get() );
-                pAction->Duplicate();
                 aMtf.AddAction( pAction );
 
                 // update rotation point and offset, if necessary
@@ -1845,9 +1825,7 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
             {
                 MetaLineColorAction* pAct = static_cast<MetaLineColorAction*>(pAction);
 
-                if( !pAct->IsSetting() )
-                    pAct->Duplicate();
-                else
+                if( pAct->IsSetting() )
                     pAct = new MetaLineColorAction( pFncCol( pAct->GetColor(), pColParam ), true );
 
                 aMtf.push_back( pAct );
@@ -1858,9 +1836,7 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
             {
                 MetaFillColorAction* pAct = static_cast<MetaFillColorAction*>(pAction);
 
-                if( !pAct->IsSetting() )
-                    pAct->Duplicate();
-                else
+                if( pAct->IsSetting() )
                     pAct = new MetaFillColorAction( pFncCol( pAct->GetColor(), pColParam ), true );
 
                 aMtf.push_back( pAct );
@@ -1878,9 +1854,7 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
             {
                 MetaTextFillColorAction* pAct = static_cast<MetaTextFillColorAction*>(pAction);
 
-                if( !pAct->IsSetting() )
-                    pAct->Duplicate();
-                else
+                if( pAct->IsSetting() )
                     pAct = new MetaTextFillColorAction( pFncCol( pAct->GetColor(), pColParam ), true );
 
                 aMtf.push_back( pAct );
@@ -1891,9 +1865,7 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
             {
                 MetaTextLineColorAction* pAct = static_cast<MetaTextLineColorAction*>(pAction);
 
-                if( !pAct->IsSetting() )
-                    pAct->Duplicate();
-                else
+                if( pAct->IsSetting() )
                     pAct = new MetaTextLineColorAction( pFncCol( pAct->GetColor(), pColParam ), true );
 
                 aMtf.push_back( pAct );
@@ -1904,9 +1876,7 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
             {
                 MetaOverlineColorAction* pAct = static_cast<MetaOverlineColorAction*>(pAction);
 
-                if( !pAct->IsSetting() )
-                    pAct->Duplicate();
-                else
+                if( pAct->IsSetting() )
                     pAct = new MetaOverlineColorAction( pFncCol( pAct->GetColor(), pColParam ), true );
 
                 aMtf.push_back( pAct );
@@ -2073,7 +2043,6 @@ void GDIMetaFile::ImplExchangeColors( ColorExchangeFnc pFncCol, const void* pCol
 
             default:
             {
-                pAction->Duplicate();
                 aMtf.push_back( pAction );
             }
             break;
diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx
index 4f9eda7ce819..013662a7ab5a 100644
--- a/vcl/source/gdi/metaact.cxx
+++ b/vcl/source/gdi/metaact.cxx
@@ -147,17 +147,20 @@ inline void ImplScaleLineInfo( LineInfo& rLineInfo, double fScaleX, double fScal
 } //anonymous namespace
 
 MetaAction::MetaAction() :
-    mnRefCount( 1 ),
     mnType( MetaActionType::NONE )
 {
 }
 
 MetaAction::MetaAction( MetaActionType nType ) :
-    mnRefCount( 1 ),
     mnType( nType )
 {
 }
 
+MetaAction::MetaAction( MetaAction const & rOther ) :
+    SimpleReferenceObject(), mnType( rOther.mnType )
+{
+}
+
 MetaAction::~MetaAction()
 {
 }
@@ -166,7 +169,7 @@ void MetaAction::Execute( OutputDevice* )
 {
 }
 
-MetaAction* MetaAction::Clone()
+rtl::Reference<MetaAction> MetaAction::Clone()
 {
     return new MetaAction;
 }
@@ -286,11 +289,9 @@ void MetaPixelAction::Execute( OutputDevice* pOut )
     pOut->DrawPixel( maPt, maColor );
 }
 
-MetaAction* MetaPixelAction::Clone()
+rtl::Reference<MetaAction> MetaPixelAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPixelAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPixelAction( *this );
 }
 
 void MetaPixelAction::Move( long nHorzMove, long nVertMove )
@@ -335,11 +336,9 @@ void MetaPointAction::Execute( OutputDevice* pOut )
     pOut->DrawPixel( maPt );
 }
 
-MetaAction* MetaPointAction::Clone()
+rtl::Reference<MetaAction> MetaPointAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPointAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPointAction( *this );
 }
 
 void MetaPointAction::Move( long nHorzMove, long nVertMove )
@@ -394,11 +393,9 @@ void MetaLineAction::Execute( OutputDevice* pOut )
         pOut->DrawLine( maStartPt, maEndPt, maLineInfo );
 }
 
-MetaAction* MetaLineAction::Clone()
+rtl::Reference<MetaAction> MetaLineAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaLineAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaLineAction( *this );
 }
 
 void MetaLineAction::Move( long nHorzMove, long nVertMove )
@@ -456,11 +453,9 @@ void MetaRectAction::Execute( OutputDevice* pOut )
     pOut->DrawRect( maRect );
 }
 
-MetaAction* MetaRectAction::Clone()
+rtl::Reference<MetaAction> MetaRectAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaRectAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaRectAction( *this );
 }
 
 void MetaRectAction::Move( long nHorzMove, long nVertMove )
@@ -508,11 +503,9 @@ void MetaRoundRectAction::Execute( OutputDevice* pOut )
     pOut->DrawRect( maRect, mnHorzRound, mnVertRound );
 }
 
-MetaAction* MetaRoundRectAction::Clone()
+rtl::Reference<MetaAction> MetaRoundRectAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaRoundRectAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaRoundRectAction( *this );
 }
 
 void MetaRoundRectAction::Move( long nHorzMove, long nVertMove )
@@ -558,11 +551,9 @@ void MetaEllipseAction::Execute( OutputDevice* pOut )
     pOut->DrawEllipse( maRect );
 }
 
-MetaAction* MetaEllipseAction::Clone()
+rtl::Reference<MetaAction> MetaEllipseAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaEllipseAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaEllipseAction( *this );
 }
 
 void MetaEllipseAction::Move( long nHorzMove, long nVertMove )
@@ -608,11 +599,9 @@ void MetaArcAction::Execute( OutputDevice* pOut )
     pOut->DrawArc( maRect, maStartPt, maEndPt );
 }
 
-MetaAction* MetaArcAction::Clone()
+rtl::Reference<MetaAction> MetaArcAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaArcAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaArcAction( *this );
 }
 
 void MetaArcAction::Move( long nHorzMove, long nVertMove )
@@ -666,11 +655,9 @@ void MetaPieAction::Execute( OutputDevice* pOut )
     pOut->DrawPie( maRect, maStartPt, maEndPt );
 }
 
-MetaAction* MetaPieAction::Clone()
+rtl::Reference<MetaAction> MetaPieAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPieAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPieAction( *this );
 }
 
 void MetaPieAction::Move( long nHorzMove, long nVertMove )
@@ -724,11 +711,9 @@ void MetaChordAction::Execute( OutputDevice* pOut )
     pOut->DrawChord( maRect, maStartPt, maEndPt );
 }
 
-MetaAction* MetaChordAction::Clone()
+rtl::Reference<MetaAction> MetaChordAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaChordAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaChordAction( *this );
 }
 
 void MetaChordAction::Move( long nHorzMove, long nVertMove )
@@ -788,11 +773,9 @@ void MetaPolyLineAction::Execute( OutputDevice* pOut )
         pOut->DrawPolyLine( maPoly, maLineInfo );
 }
 
-MetaAction* MetaPolyLineAction::Clone()
+rtl::Reference<MetaAction> MetaPolyLineAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPolyLineAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPolyLineAction( *this );
 }
 
 void MetaPolyLineAction::Move( long nHorzMove, long nVertMove )
@@ -859,11 +842,9 @@ void MetaPolygonAction::Execute( OutputDevice* pOut )
     pOut->DrawPolygon( maPoly );
 }
 
-MetaAction* MetaPolygonAction::Clone()
+rtl::Reference<MetaAction> MetaPolygonAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPolygonAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPolygonAction( *this );
 }
 
 void MetaPolygonAction::Move( long nHorzMove, long nVertMove )
@@ -923,11 +904,9 @@ void MetaPolyPolygonAction::Execute( OutputDevice* pOut )
     pOut->DrawPolyPolygon( maPolyPoly );
 }
 
-MetaAction* MetaPolyPolygonAction::Clone()
+rtl::Reference<MetaAction> MetaPolyPolygonAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPolyPolygonAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPolyPolygonAction( *this );
 }
 
 void MetaPolyPolygonAction::Move( long nHorzMove, long nVertMove )
@@ -1031,11 +1010,9 @@ void MetaTextAction::Execute( OutputDevice* pOut )
     pOut->DrawText( maPt, maStr, mnIndex, mnLen );
 }
 
-MetaAction* MetaTextAction::Clone()
+rtl::Reference<MetaAction> MetaTextAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextAction( *this );
 }
 
 void MetaTextAction::Move( long nHorzMove, long nVertMove )
@@ -1126,11 +1103,9 @@ void MetaTextArrayAction::Execute( OutputDevice* pOut )
     pOut->DrawTextArray( maStartPt, maStr, mpDXAry.get(), mnIndex, mnLen );
 }
 
-MetaAction* MetaTextArrayAction::Clone()
+rtl::Reference<MetaAction> MetaTextArrayAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextArrayAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextArrayAction( *this );
 }
 
 void MetaTextArrayAction::Move( long nHorzMove, long nVertMove )
@@ -1257,11 +1232,9 @@ void MetaStretchTextAction::Execute( OutputDevice* pOut )
     pOut->DrawStretchText( maPt, mnWidth, maStr, mnIndex, mnLen );
 }
 
-MetaAction* MetaStretchTextAction::Clone()
+rtl::Reference<MetaAction> MetaStretchTextAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaStretchTextAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaStretchTextAction( *this );
 }
 
 void MetaStretchTextAction::Move( long nHorzMove, long nVertMove )
@@ -1326,11 +1299,9 @@ void MetaTextRectAction::Execute( OutputDevice* pOut )
     pOut->DrawText( maRect, maStr, mnStyle );
 }
 
-MetaAction* MetaTextRectAction::Clone()
+rtl::Reference<MetaAction> MetaTextRectAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextRectAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextRectAction( *this );
 }
 
 void MetaTextRectAction::Move( long nHorzMove, long nVertMove )
@@ -1395,11 +1366,9 @@ void MetaTextLineAction::Execute( OutputDevice* pOut )
     pOut->DrawTextLine( maPos, mnWidth, meStrikeout, meUnderline, meOverline );
 }
 
-MetaAction* MetaTextLineAction::Clone()
+rtl::Reference<MetaAction> MetaTextLineAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextLineAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextLineAction( *this );
 }
 
 void MetaTextLineAction::Move( long nHorzMove, long nVertMove )
@@ -1469,11 +1438,9 @@ void MetaBmpAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmap( maPt, maBmp );
 }
 
-MetaAction* MetaBmpAction::Clone()
+rtl::Reference<MetaAction> MetaBmpAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaBmpAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpAction( *this );
 }
 
 void MetaBmpAction::Move( long nHorzMove, long nVertMove )
@@ -1524,11 +1491,9 @@ void MetaBmpScaleAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmap( maPt, maSz, maBmp );
 }
 
-MetaAction* MetaBmpScaleAction::Clone()
+rtl::Reference<MetaAction> MetaBmpScaleAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaBmpScaleAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpScaleAction( *this );
 }
 
 void MetaBmpScaleAction::Move( long nHorzMove, long nVertMove )
@@ -1587,11 +1552,9 @@ void MetaBmpScalePartAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmap( maDstPt, maDstSz, maSrcPt, maSrcSz, maBmp );
 }
 
-MetaAction* MetaBmpScalePartAction::Clone()
+rtl::Reference<MetaAction> MetaBmpScalePartAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaBmpScalePartAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpScalePartAction( *this );
 }
 
 void MetaBmpScalePartAction::Move( long nHorzMove, long nVertMove )
@@ -1649,11 +1612,9 @@ void MetaBmpExAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmapEx( maPt, maBmpEx );
 }
 
-MetaAction* MetaBmpExAction::Clone()
+rtl::Reference<MetaAction> MetaBmpExAction::Clone()
 {
-    MetaBmpExAction* pClone = new MetaBmpExAction( *this );
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpExAction( *this );
 }
 
 void MetaBmpExAction::Move( long nHorzMove, long nVertMove )
@@ -1704,11 +1665,9 @@ void MetaBmpExScaleAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmapEx( maPt, maSz, maBmpEx );
 }
 
-MetaAction* MetaBmpExScaleAction::Clone()
+rtl::Reference<MetaAction> MetaBmpExScaleAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaBmpExScaleAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpExScaleAction( *this );
 }
 
 void MetaBmpExScaleAction::Move( long nHorzMove, long nVertMove )
@@ -1767,11 +1726,9 @@ void MetaBmpExScalePartAction::Execute( OutputDevice* pOut )
     pOut->DrawBitmapEx( maDstPt, maDstSz, maSrcPt, maSrcSz, maBmpEx );
 }
 
-MetaAction* MetaBmpExScalePartAction::Clone()
+rtl::Reference<MetaAction> MetaBmpExScalePartAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaBmpExScalePartAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaBmpExScalePartAction( *this );
 }
 
 void MetaBmpExScalePartAction::Move( long nHorzMove, long nVertMove )
@@ -1832,11 +1789,9 @@ void MetaMaskAction::Execute( OutputDevice* pOut )
     pOut->DrawMask( maPt, maBmp, maColor );
 }
 
-MetaAction* MetaMaskAction::Clone()
+rtl::Reference<MetaAction> MetaMaskAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaMaskAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaMaskAction( *this );
 }
 
 void MetaMaskAction::Move( long nHorzMove, long nVertMove )
@@ -1889,11 +1844,9 @@ void MetaMaskScaleAction::Execute( OutputDevice* pOut )
     pOut->DrawMask( maPt, maSz, maBmp, maColor );
 }
 
-MetaAction* MetaMaskScaleAction::Clone()
+rtl::Reference<MetaAction> MetaMaskScaleAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaMaskScaleAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaMaskScaleAction( *this );
 }
 
 void MetaMaskScaleAction::Move( long nHorzMove, long nVertMove )
@@ -1954,11 +1907,9 @@ void MetaMaskScalePartAction::Execute( OutputDevice* pOut )
     pOut->DrawMask( maDstPt, maDstSz, maSrcPt, maSrcSz, maBmp, maColor, MetaActionType::MASKSCALE );
 }
 
-MetaAction* MetaMaskScalePartAction::Clone()
+rtl::Reference<MetaAction> MetaMaskScalePartAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaMaskScalePartAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaMaskScalePartAction( *this );
 }
 
 void MetaMaskScalePartAction::Move( long nHorzMove, long nVertMove )
@@ -2018,11 +1969,9 @@ void MetaGradientAction::Execute( OutputDevice* pOut )
     pOut->DrawGradient( maRect, maGradient );
 }
 
-MetaAction* MetaGradientAction::Clone()
+rtl::Reference<MetaAction> MetaGradientAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaGradientAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaGradientAction( *this );
 }
 
 void MetaGradientAction::Move( long nHorzMove, long nVertMove )
@@ -2067,16 +2016,13 @@ void MetaGradientExAction::Execute( OutputDevice* pOut )
 {
     if( pOut->GetConnectMetaFile() )
     {
-        Duplicate();
         pOut->GetConnectMetaFile()->AddAction( this );
     }
 }
 
-MetaAction* MetaGradientExAction::Clone()
+rtl::Reference<MetaAction> MetaGradientExAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaGradientExAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaGradientExAction( *this );
 }
 
 void MetaGradientExAction::Move( long nHorzMove, long nVertMove )
@@ -2128,11 +2074,9 @@ void MetaHatchAction::Execute( OutputDevice* pOut )
     pOut->DrawHatch( maPolyPoly, maHatch );
 }
 
-MetaAction* MetaHatchAction::Clone()
+rtl::Reference<MetaAction> MetaHatchAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaHatchAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaHatchAction( *this );
 }
 
 void MetaHatchAction::Move( long nHorzMove, long nVertMove )
@@ -2185,11 +2129,9 @@ void MetaWallpaperAction::Execute( OutputDevice* pOut )
     pOut->DrawWallpaper( maRect, maWallpaper );
 }
 
-MetaAction* MetaWallpaperAction::Clone()
+rtl::Reference<MetaAction> MetaWallpaperAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaWallpaperAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaWallpaperAction( *this );
 }
 
 void MetaWallpaperAction::Move( long nHorzMove, long nVertMove )
@@ -2238,11 +2180,9 @@ void MetaClipRegionAction::Execute( OutputDevice* pOut )
         pOut->SetClipRegion();
 }
 
-MetaAction* MetaClipRegionAction::Clone()
+rtl::Reference<MetaAction> MetaClipRegionAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaClipRegionAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaClipRegionAction( *this );
 }
 
 void MetaClipRegionAction::Move( long nHorzMove, long nVertMove )
@@ -2288,11 +2228,9 @@ void MetaISectRectClipRegionAction::Execute( OutputDevice* pOut )
     pOut->IntersectClipRegion( maRect );
 }
 
-MetaAction* MetaISectRectClipRegionAction::Clone()
+rtl::Reference<MetaAction> MetaISectRectClipRegionAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaISectRectClipRegionAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaISectRectClipRegionAction( *this );
 }
 
 void MetaISectRectClipRegionAction::Move( long nHorzMove, long nVertMove )
@@ -2336,11 +2274,9 @@ void MetaISectRegionClipRegionAction::Execute( OutputDevice* pOut )
     pOut->IntersectClipRegion( maRegion );
 }
 
-MetaAction* MetaISectRegionClipRegionAction::Clone()
+rtl::Reference<MetaAction> MetaISectRegionClipRegionAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaISectRegionClipRegionAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaISectRegionClipRegionAction( *this );
 }
 
 void MetaISectRegionClipRegionAction::Move( long nHorzMove, long nVertMove )
@@ -2386,11 +2322,9 @@ void MetaMoveClipRegionAction::Execute( OutputDevice* pOut )
     pOut->MoveClipRegion( mnHorzMove, mnVertMove );
 }
 
-MetaAction* MetaMoveClipRegionAction::Clone()
+rtl::Reference<MetaAction> MetaMoveClipRegionAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaMoveClipRegionAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaMoveClipRegionAction( *this );
 }
 
 void MetaMoveClipRegionAction::Scale( double fScaleX, double fScaleY )
@@ -2437,11 +2371,9 @@ void MetaLineColorAction::Execute( OutputDevice* pOut )
         pOut->SetLineColor();
 }
 
-MetaAction* MetaLineColorAction::Clone()
+rtl::Reference<MetaAction> MetaLineColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaLineColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaLineColorAction( *this );
 }
 
 void MetaLineColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2481,11 +2413,9 @@ void MetaFillColorAction::Execute( OutputDevice* pOut )
         pOut->SetFillColor();
 }
 
-MetaAction* MetaFillColorAction::Clone()
+rtl::Reference<MetaAction> MetaFillColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaFillColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaFillColorAction( *this );
 }
 
 void MetaFillColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2520,11 +2450,9 @@ void MetaTextColorAction::Execute( OutputDevice* pOut )
     pOut->SetTextColor( maColor );
 }
 
-MetaAction* MetaTextColorAction::Clone()
+rtl::Reference<MetaAction> MetaTextColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextColorAction( *this );
 }
 
 void MetaTextColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2562,11 +2490,9 @@ void MetaTextFillColorAction::Execute( OutputDevice* pOut )
         pOut->SetTextFillColor();
 }
 
-MetaAction* MetaTextFillColorAction::Clone()
+rtl::Reference<MetaAction> MetaTextFillColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextFillColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextFillColorAction( *this );
 }
 
 void MetaTextFillColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2606,11 +2532,9 @@ void MetaTextLineColorAction::Execute( OutputDevice* pOut )
         pOut->SetTextLineColor();
 }
 
-MetaAction* MetaTextLineColorAction::Clone()
+rtl::Reference<MetaAction> MetaTextLineColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextLineColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextLineColorAction( *this );
 }
 
 void MetaTextLineColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2650,11 +2574,9 @@ void MetaOverlineColorAction::Execute( OutputDevice* pOut )
         pOut->SetOverlineColor();
 }
 
-MetaAction* MetaOverlineColorAction::Clone()
+rtl::Reference<MetaAction> MetaOverlineColorAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaOverlineColorAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaOverlineColorAction( *this );
 }
 
 void MetaOverlineColorAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2690,11 +2612,9 @@ void MetaTextAlignAction::Execute( OutputDevice* pOut )
     pOut->SetTextAlign( maAlign );
 }
 
-MetaAction* MetaTextAlignAction::Clone()
+rtl::Reference<MetaAction> MetaTextAlignAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextAlignAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextAlignAction( *this );
 }
 
 void MetaTextAlignAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2729,11 +2649,9 @@ void MetaMapModeAction::Execute( OutputDevice* pOut )
     pOut->SetMapMode( maMapMode );
 }
 
-MetaAction* MetaMapModeAction::Clone()
+rtl::Reference<MetaAction> MetaMapModeAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaMapModeAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaMapModeAction( *this );
 }
 
 void MetaMapModeAction::Scale( double fScaleX, double fScaleY )
@@ -2784,11 +2702,9 @@ void MetaFontAction::Execute( OutputDevice* pOut )
     pOut->SetFont( maFont );
 }
 
-MetaAction* MetaFontAction::Clone()
+rtl::Reference<MetaAction> MetaFontAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaFontAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaFontAction( *this );
 }
 
 void MetaFontAction::Scale( double fScaleX, double fScaleY )
@@ -2836,11 +2752,9 @@ void MetaPushAction::Execute( OutputDevice* pOut )
     pOut->Push( mnFlags );
 }
 
-MetaAction* MetaPushAction::Clone()
+rtl::Reference<MetaAction> MetaPushAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPushAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPushAction( *this );
 }
 
 void MetaPushAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2870,11 +2784,9 @@ void MetaPopAction::Execute( OutputDevice* pOut )
     pOut->Pop();
 }
 
-MetaAction* MetaPopAction::Clone()
+rtl::Reference<MetaAction> MetaPopAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaPopAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaPopAction( *this );
 }
 
 void MetaPopAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2907,11 +2819,9 @@ void MetaRasterOpAction::Execute( OutputDevice* pOut )
     pOut->SetRasterOp( meRasterOp );
 }
 
-MetaAction* MetaRasterOpAction::Clone()
+rtl::Reference<MetaAction> MetaRasterOpAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaRasterOpAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaRasterOpAction( *this );
 }
 
 void MetaRasterOpAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -2948,11 +2858,9 @@ void MetaTransparentAction::Execute( OutputDevice* pOut )
     pOut->DrawTransparent( maPolyPoly, mnTransPercent );
 }
 
-MetaAction* MetaTransparentAction::Clone()
+rtl::Reference<MetaAction> MetaTransparentAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTransparentAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTransparentAction( *this );
 }
 
 void MetaTransparentAction::Move( long nHorzMove, long nVertMove )
@@ -3015,11 +2923,9 @@ void MetaFloatTransparentAction::Execute( OutputDevice* pOut )
     pOut->DrawTransparent( maMtf, maPoint, maSize, maGradient );
 }
 
-MetaAction* MetaFloatTransparentAction::Clone()
+rtl::Reference<MetaAction> MetaFloatTransparentAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaFloatTransparentAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaFloatTransparentAction( *this );
 }
 
 void MetaFloatTransparentAction::Move( long nHorzMove, long nVertMove )
@@ -3076,11 +2982,9 @@ void MetaEPSAction::Execute( OutputDevice* pOut )
     pOut->DrawEPS( maPoint, maSize, maGfxLink, &maSubst );
 }
 
-MetaAction* MetaEPSAction::Clone()
+rtl::Reference<MetaAction> MetaEPSAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaEPSAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaEPSAction( *this );
 }
 
 void MetaEPSAction::Move( long nHorzMove, long nVertMove )
@@ -3138,11 +3042,9 @@ void MetaRefPointAction::Execute( OutputDevice* pOut )
         pOut->SetRefPoint();
 }
 
-MetaAction* MetaRefPointAction::Clone()
+rtl::Reference<MetaAction> MetaRefPointAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaRefPointAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaRefPointAction( *this );
 }
 
 void MetaRefPointAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -3206,16 +3108,13 @@ void MetaCommentAction::Execute( OutputDevice* pOut )
 {
     if ( pOut->GetConnectMetaFile() )
     {
-        Duplicate();
         pOut->GetConnectMetaFile()->AddAction( this );
     }
 }
 
-MetaAction* MetaCommentAction::Clone()
+rtl::Reference<MetaAction> MetaCommentAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaCommentAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaCommentAction( *this );
 }
 
 void MetaCommentAction::Move( long nXMove, long nYMove )
@@ -3388,11 +3287,9 @@ void MetaLayoutModeAction::Execute( OutputDevice* pOut )
     pOut->SetLayoutMode( mnLayoutMode );
 }
 
-MetaAction* MetaLayoutModeAction::Clone()
+rtl::Reference<MetaAction> MetaLayoutModeAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaLayoutModeAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaLayoutModeAction( *this );
 }
 
 void MetaLayoutModeAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
@@ -3428,11 +3325,9 @@ void MetaTextLanguageAction::Execute( OutputDevice* pOut )
     pOut->SetDigitLanguage( meTextLanguage );
 }
 
-MetaAction* MetaTextLanguageAction::Clone()
+rtl::Reference<MetaAction> MetaTextLanguageAction::Clone()
 {
-    MetaAction* pClone = static_cast<MetaAction*>(new MetaTextLanguageAction( *this ));
-    pClone->ResetRefCount();
-    return pClone;
+    return new MetaTextLanguageAction( *this );
 }
 
 void MetaTextLanguageAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
diff --git a/vcl/source/gdi/print2.cxx b/vcl/source/gdi/print2.cxx
index 8bccc523ad9c..e131b061557b 100644
--- a/vcl/source/gdi/print2.cxx
+++ b/vcl/source/gdi/print2.cxx
@@ -1088,7 +1088,6 @@ bool OutputDevice::RemoveTransparenciesFromMetaFile( const GDIMetaFile& rInMtf,
         {
             // simply add this action (above, we inserted the actions
             // starting at index 0 up to and including nLastBgAction)
-            component.first->Duplicate();
             rOutMtf.AddAction( component.first );
         }
 
@@ -1300,7 +1299,6 @@ bool OutputDevice::RemoveTransparenciesFromMetaFile( const GDIMetaFile& rInMtf,
                 else
                 {
                     // simply add this action
-                    pCurrAct->Duplicate();
                     rOutMtf.AddAction( pCurrAct );
                 }
 
diff --git a/vcl/source/gdi/svmconverter.cxx b/vcl/source/gdi/svmconverter.cxx
index a3a12575ebab..a9773ffbd682 100644
--- a/vcl/source/gdi/svmconverter.cxx
+++ b/vcl/source/gdi/svmconverter.cxx
@@ -669,13 +669,11 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                         // Subdivided for better quality for older usages
                         if(1 == aInputPolyPolygon.Count())
                         {
-                            MetaAction* pAction = rMtf.ReplaceAction(
+                            rMtf.ReplaceAction(
                                 new MetaPolyLineAction(
                                     aInputPolyPolygon.GetObject(0),
                                     pPolyLineAction->GetLineInfo()),
                                 nLastPolygonAction);
-                            if(pAction)
-                                pAction->Delete();
                         }
                     }
                     else
@@ -688,12 +686,10 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                             // same sub-polygon count
                             if(pPolyPolygonAction->GetPolyPolygon().Count() == aInputPolyPolygon.Count())
                             {
-                                MetaAction* pAction = rMtf.ReplaceAction(
+                                rMtf.ReplaceAction(
                                     new MetaPolyPolygonAction(
                                         aInputPolyPolygon),
                                     nLastPolygonAction);
-                                if(pAction)
-                                    pAction->Delete();
                             }
                         }
                         else
@@ -705,12 +701,10 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                                 // replace MetaPolygonAction
                                 if(1 == aInputPolyPolygon.Count())
                                 {
-                                    MetaAction* pAction = rMtf.ReplaceAction(
+                                    rMtf.ReplaceAction(
                                         new MetaPolygonAction(
                                             aInputPolyPolygon.GetObject(0)),
                                         nLastPolygonAction);
-                                    if(pAction)
-                                        pAction->Delete();
                                 }
                             }
                         }
diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx b/vcl/source/graphic/UnoGraphicProvider.cxx
index dd51f7533728..50c273006b85 100644
--- a/vcl/source/graphic/UnoGraphicProvider.cxx
+++ b/vcl/source/graphic/UnoGraphicProvider.cxx
@@ -655,15 +655,13 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
                         ImplApplyBitmapResolution( aGraphic, nImageResolution,
                             aGraphic.GetSizePixel(), awt::Size( aSize100thmm2.Width(), aSize100thmm2.Height() ) );
 
-                        MetaAction* pNewAction;
+                        rtl::Reference<MetaAction> pNewAction;
                         if ( pAction->GetType() == MetaActionType::BMPSCALE )
                             pNewAction = new MetaBmpScaleAction ( aPos, aSize, aGraphic.GetBitmap() );
                         else
                             pNewAction = new MetaBmpExScaleAction( aPos, aSize, aGraphic.GetBitmapEx() );
 
-                        MetaAction* pDeleteAction = aMtf.ReplaceAction( pNewAction, i );
-                        if(pDeleteAction)
-                            pDeleteAction->Delete();
+                        aMtf.ReplaceAction( pNewAction, i );
                         break;
                     }
                     default:


More information about the Libreoffice-commits mailing list