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

Noel Grandin noel.grandin at collabora.co.uk
Tue Mar 6 09:07:24 UTC 2018


 sdext/source/pdfimport/inc/genericelements.hxx     |   32 +--
 sdext/source/pdfimport/inc/treevisiting.hxx        |   16 -
 sdext/source/pdfimport/tree/drawtreevisiting.cxx   |  122 +++++++-------
 sdext/source/pdfimport/tree/drawtreevisiting.hxx   |   48 ++---
 sdext/source/pdfimport/tree/genericelements.cxx    |   76 ++++-----
 sdext/source/pdfimport/tree/pdfiprocessor.cxx      |   12 -
 sdext/source/pdfimport/tree/style.cxx              |    2 
 sdext/source/pdfimport/tree/writertreevisiting.cxx |  176 ++++++++++-----------
 sdext/source/pdfimport/tree/writertreevisiting.hxx |   48 ++---
 9 files changed, 263 insertions(+), 269 deletions(-)

New commits:
commit a9ef943769b06e6bdffe7326f288b27e08a95698
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 11:09:43 2018 +0200

    loplugin:useuniqueptr in sdext
    
    Change-Id: I0870d4b1e85465b07e3d9cdb05520fcb37dfc267
    Reviewed-on: https://gerrit.libreoffice.org/50659
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sdext/source/pdfimport/inc/genericelements.hxx b/sdext/source/pdfimport/inc/genericelements.hxx
index 9a5db64016fd..fb3fcf93703d 100644
--- a/sdext/source/pdfimport/inc/genericelements.hxx
+++ b/sdext/source/pdfimport/inc/genericelements.hxx
@@ -77,7 +77,7 @@ namespace pdfi
             : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
         {
             if( pParent )
-                pParent->Children.push_back( this );
+                pParent->Children.emplace_back( this );
         }
 
     public:
@@ -87,7 +87,7 @@ namespace pdfi
             To be implemented by every tree node that needs to be
             visitable.
          */
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) = 0;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt ) = 0;
         /// Apply visitor to all children
         void applyToChildren( ElementTreeVisitor& );
         /// Union element geometry with given element
@@ -100,18 +100,18 @@ namespace pdfi
         /** el must be a valid dereferenceable iterator of el->Parent->Children
             pNewParent must not be NULL
         */
-        static void setParent( std::list<Element*>::iterator const & el, Element* pNewParent );
+        static void setParent( std::list<std::unique_ptr<Element>>::iterator const & el, Element* pNewParent );
 
         double              x, y, w, h;
         sal_Int32           StyleId;
         Element*            Parent;
-        std::list<Element*> Children;
+        std::list<std::unique_ptr<Element>> Children;
     };
 
     struct ListElement : public Element
     {
         ListElement() : Element( nullptr ) {}
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
     };
 
     struct HyperlinkElement : public Element
@@ -121,7 +121,7 @@ namespace pdfi
         HyperlinkElement( Element* pParent, const OUString& rURI )
         : Element( pParent ), URI( rURI ) {}
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
 
         OUString URI;
     };
@@ -166,7 +166,7 @@ namespace pdfi
         : DrawElement( pParent, nGCId ) {}
 
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
     };
 
     struct TextElement : public GraphicalElement
@@ -177,7 +177,7 @@ namespace pdfi
         : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
 
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
 
         OUStringBuffer Text;
         sal_Int32           FontId;
@@ -190,7 +190,7 @@ namespace pdfi
         explicit ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {}
 
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt ) override;
 
         // returns true only if only a single line is contained
         bool isSingleLined( PDFIProcessor const & rProc ) const;
@@ -213,7 +213,7 @@ namespace pdfi
                          const basegfx::B2DPolyPolygon& rPolyPoly,
                          sal_Int8 nAction );
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt ) override;
 
         void updateGeometry();
 
@@ -233,7 +233,7 @@ namespace pdfi
         : DrawElement( pParent, nGCId ), Image( nImage ) {}
 
     public:
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
 
         ImageId Image;
     };
@@ -249,11 +249,11 @@ namespace pdfi
         {}
     private:
         // helper method for resolveHyperlinks
-        bool resolveHyperlink( const std::list<Element*>::iterator& link_it, std::list<Element*>& rElements );
+        bool resolveHyperlink( const std::list<std::unique_ptr<Element>>::iterator& link_it, std::list<std::unique_ptr<Element>>& rElements );
     public:
         virtual ~PageElement() override;
 
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt ) override;
 
         static void updateParagraphGeometry( Element* pEle );
         void resolveHyperlinks();
@@ -266,8 +266,8 @@ namespace pdfi
         double         BottomMargin;
         double         LeftMargin;
         double         RightMargin;
-        Element*       HeaderElement;
-        Element*       FooterElement;
+        std::unique_ptr<Element> HeaderElement;
+        std::unique_ptr<Element> FooterElement;
     };
 
     struct DocumentElement : public Element
@@ -278,7 +278,7 @@ namespace pdfi
     public:
         virtual ~DocumentElement() override;
 
-        virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& ) override;
+        virtual void visitedBy( ElementTreeVisitor&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
     };
 
     // this class is the differentiator of document types: it will create
diff --git a/sdext/source/pdfimport/inc/treevisiting.hxx b/sdext/source/pdfimport/inc/treevisiting.hxx
index ec6d429d2ab9..8c950ec97262 100644
--- a/sdext/source/pdfimport/inc/treevisiting.hxx
+++ b/sdext/source/pdfimport/inc/treevisiting.hxx
@@ -43,14 +43,14 @@ namespace pdfi
      */
     struct ElementTreeVisitor
     {
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) = 0;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) = 0;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) = 0;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) = 0;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) = 0;
         virtual ~ElementTreeVisitor() {}
     };
     typedef std::shared_ptr<ElementTreeVisitor> ElementTreeVisitorSharedPtr;
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
index 715d3e6a3000..81c2a945366e 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -67,12 +67,12 @@ const Reference< XCharacterClassification >& DrawXmlEmitter::GetCharacterClassif
     return mxCharClass;
 }
 
-void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator&   )
+void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Children.empty() )
         return;
 
-    const char* pType = dynamic_cast<DrawElement*>(elem.Children.front()) ? "draw:a" : "text:a";
+    const char* pType = dynamic_cast<DrawElement*>(elem.Children.front().get()) ? "draw:a" : "text:a";
 
     PropertyMap aProps;
     aProps[ "xlink:type" ] = "simple";
@@ -81,8 +81,8 @@ void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >:
     aProps[ "xlink:show" ] = "new";
 
     m_rEmitContext.rEmitter.beginTag( pType, aProps );
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -90,7 +90,7 @@ void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >:
     m_rEmitContext.rEmitter.endTag( pType );
 }
 
-void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::const_iterator&   )
+void DrawXmlEmitter::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Text.isEmpty() )
         return;
@@ -152,8 +152,8 @@ void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::cons
         }
     }
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -162,7 +162,7 @@ void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::cons
     m_rEmitContext.rEmitter.endTag( "text:span" );
 }
 
-void DrawXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator&   )
+void DrawXmlEmitter::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     PropertyMap aProps;
     if( elem.StyleId != -1 )
@@ -174,8 +174,8 @@ void DrawXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >:
         pTagType = "text:h";
     m_rEmitContext.rEmitter.beginTag( pTagType, aProps );
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -242,20 +242,20 @@ void DrawXmlEmitter::fillFrameProps( DrawElement&       rElem,
     }
 }
 
-void DrawXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::const_iterator&   )
+void DrawXmlEmitter::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Children.empty() )
         return;
 
-    bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front()) != nullptr);
+    bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front().get()) != nullptr);
     PropertyMap aFrameProps;
     fillFrameProps( elem, aFrameProps, m_rEmitContext, false );
     m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps );
     if( bTextBox )
         m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() );
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -266,7 +266,7 @@ void DrawXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::con
     m_rEmitContext.rEmitter.endTag( "draw:frame" );
 }
 
-void DrawXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlEmitter::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.updateGeometry();
     /* note:
@@ -335,7 +335,7 @@ void DrawXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::
     m_rEmitContext.rEmitter.endTag( "draw:path" );
 }
 
-void DrawXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlEmitter::visit( ImageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     PropertyMap aImageProps;
     m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps );
@@ -345,7 +345,7 @@ void DrawXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::con
     m_rEmitContext.rEmitter.endTag( "draw:image" );
 }
 
-void DrawXmlEmitter::visit( PageElement& elem, const std::list< Element* >::const_iterator&   )
+void DrawXmlEmitter::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     PropertyMap aPageProps;
     aPageProps[ "draw:master-page-name" ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId );
@@ -355,8 +355,8 @@ void DrawXmlEmitter::visit( PageElement& elem, const std::list< Element* >::cons
     if( m_rEmitContext.xStatusIndicator.is() )
         m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber );
 
-    std::list< Element* >::iterator this_it = elem.Children.begin();
-    while( this_it != elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -365,14 +365,14 @@ void DrawXmlEmitter::visit( PageElement& elem, const std::list< Element* >::cons
     m_rEmitContext.rEmitter.endTag("draw:page");
 }
 
-void DrawXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+void DrawXmlEmitter::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
     m_rEmitContext.rEmitter.beginTag( m_bWriteDrawDocument ? "office:drawing" : "office:presentation",
                                       PropertyMap() );
 
-    std::list< Element* >::iterator this_it = elem.Children.begin();
-    while( this_it != elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -383,24 +383,24 @@ void DrawXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::
 }
 
 
-void DrawXmlOptimizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+void DrawXmlOptimizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void DrawXmlOptimizer::visit( TextElement&, const std::list< Element* >::const_iterator&)
+void DrawXmlOptimizer::visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
 }
 
-void DrawXmlOptimizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlOptimizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.applyToChildren(*this);
 }
 
-void DrawXmlOptimizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+void DrawXmlOptimizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& elemIt )
+void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& elemIt )
 {
     /* note: optimize two consecutive PolyPolyElements that
      *  have the same path but one of which is a stroke while
@@ -412,12 +412,12 @@ void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >
     // find following PolyPolyElement in parent's children list
     if( elemIt == elem.Parent->Children.end() )
         return;
-    std::list< Element* >::const_iterator next_it = elemIt;
+    auto next_it = elemIt;
     ++next_it;
     if( next_it == elem.Parent->Children.end() )
         return;
 
-    PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
+    PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(next_it->get());
     // TODO(F2): this comparison fails for OOo-generated polygons with beziers.
     if( !pNext || pNext->PolyPoly != elem.PolyPoly )
         return;
@@ -452,7 +452,7 @@ void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >
         elem.Children.splice( elem.Children.end(), pNext->Children );
         // workaround older compilers that do not have std::list::erase(const_iterator)
 #if HAVE_BROKEN_CONST_ITERATORS
-        std::list< Element* >::iterator tmpIt = elem.Parent->Children.begin();
+        auto tmpIt = elem.Parent->Children.begin();
         std::advance(tmpIt, std::distance(elem.Parent->Children.cbegin(), next_it));
         elem.Parent->Children.erase(tmpIt);
 #else
@@ -462,14 +462,14 @@ void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >
     }
 }
 
-void DrawXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlOptimizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     optimizeTextElements( elem );
 
     elem.applyToChildren(*this);
 }
 
-void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlOptimizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     if( m_rProcessor.getStatusIndicator().is() )
         m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
@@ -485,7 +485,7 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
 
     // find paragraphs in text
     ParagraphElement* pCurPara = nullptr;
-    std::list< Element* >::iterator page_element, next_page_element;
+    std::list< std::unique_ptr<Element> >::iterator page_element, next_page_element;
     next_page_element = elem.Children.begin();
     double fCurLineHeight = 0.0; // average height of text items in current para
     int nCurLineElements = 0; // number of line contributing elements in current para
@@ -495,17 +495,17 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
     while( next_page_element != elem.Children.end() )
     {
         page_element = next_page_element++;
-        ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(*page_element);
+        ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(page_element->get());
         if( pPagePara )
         {
             pCurPara = pPagePara;
             // adjust line height and text items
             fCurLineHeight = 0.0;
             nCurLineElements = 0;
-            for( std::list< Element* >::iterator it = pCurPara->Children.begin();
+            for( auto it = pCurPara->Children.begin();
                  it != pCurPara->Children.end(); ++it )
             {
-                TextElement* pTestText = dynamic_cast<TextElement*>(*it);
+                TextElement* pTestText = dynamic_cast<TextElement*>(it->get());
                 if( pTestText )
                 {
                     fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
@@ -515,10 +515,10 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
             continue;
         }
 
-        HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*page_element);
-        DrawElement* pDraw = dynamic_cast<DrawElement*>(*page_element);
+        HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(page_element->get());
+        DrawElement* pDraw = dynamic_cast<DrawElement*>(page_element->get());
         if( ! pDraw && pLink && ! pLink->Children.empty() )
-            pDraw = dynamic_cast<DrawElement*>(pLink->Children.front() );
+            pDraw = dynamic_cast<DrawElement*>(pLink->Children.front().get() );
         if( pDraw )
         {
             // insert small drawing objects as character, else leave them page bound
@@ -539,12 +539,12 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
             // or perhaps the draw element begins a new paragraph
             else if( next_page_element != elem.Children.end() )
             {
-                TextElement* pText = dynamic_cast<TextElement*>(*next_page_element);
+                TextElement* pText = dynamic_cast<TextElement*>(next_page_element->get());
                 if( ! pText )
                 {
-                    ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*next_page_element);
+                    ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(next_page_element->get());
                     if( pPara && ! pPara->Children.empty() )
-                        pText = dynamic_cast<TextElement*>(pPara->Children.front());
+                        pText = dynamic_cast<TextElement*>(pPara->Children.front().get());
                 }
                 if( pText && // check there is a text
                     pDraw->h < pText->h*1.5 && // and it is approx the same height
@@ -573,9 +573,9 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
             }
         }
 
-        TextElement* pText = dynamic_cast<TextElement*>(*page_element);
+        TextElement* pText = dynamic_cast<TextElement*>(page_element->get());
         if( ! pText && pLink && ! pLink->Children.empty() )
-            pText = dynamic_cast<TextElement*>(pLink->Children.front());
+            pText = dynamic_cast<TextElement*>(pLink->Children.front().get());
         if( pText )
         {
             Element* pGeo = pLink ? static_cast<Element*>(pLink) :
@@ -632,14 +632,14 @@ void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::co
             // set parent
             pCurPara->Parent = &elem;
             //insert new paragraph before current element
-            page_element = elem.Children.insert( page_element, pCurPara );
+            page_element = elem.Children.insert( page_element, std::unique_ptr<Element>(pCurPara) );
             // forward iterator to current element again
             ++ page_element;
             // update next_element which is now invalid
             next_page_element = page_element;
             ++ next_page_element;
        }
-        Element* pCurEle = *page_element;
+        Element* pCurEle = page_element->get();
         Element::setParent( page_element, pCurPara );
         OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" );
         if( pText || pDraw )
@@ -678,17 +678,17 @@ void DrawXmlOptimizer::optimizeTextElements(Element& rParent)
     }
 
     // concatenate child elements with same font id
-    std::list< Element* >::iterator next = rParent.Children.begin();
-    std::list< Element* >::iterator it = next++;
+    auto next = rParent.Children.begin();
+    auto it = next++;
 
     while( next != rParent.Children.end() )
     {
         bool bConcat = false;
-        TextElement* pCur = dynamic_cast<TextElement*>(*it);
+        TextElement* pCur = dynamic_cast<TextElement*>(it->get());
 
         if( pCur )
         {
-            TextElement* pNext = dynamic_cast<TextElement*>(*next);
+            TextElement* pNext = dynamic_cast<TextElement*>(next->get());
             bool isComplex = false;
             OUString str(pCur->Text.getStr());
             for(int i=0; i< str.getLength(); i++)
@@ -742,7 +742,7 @@ void DrawXmlOptimizer::optimizeTextElements(Element& rParent)
                 }
             }
         }
-        else if( dynamic_cast<HyperlinkElement*>(*it) )
+        else if( dynamic_cast<HyperlinkElement*>(it->get()) )
             optimizeTextElements( **it );
         if ( bConcat )
             next = it;
@@ -752,13 +752,13 @@ void DrawXmlOptimizer::optimizeTextElements(Element& rParent)
     }
 }
 
-void DrawXmlOptimizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+void DrawXmlOptimizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     elem.applyToChildren(*this);
 }
 
 
-void DrawXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     // xxx TODO copied from DrawElement
     const GraphicsContext& rGC = m_rProcessor.getGraphicsContext(elem.GCId );
@@ -821,7 +821,7 @@ void DrawXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >
     elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
 }
 
-void DrawXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
@@ -836,7 +836,7 @@ void SetFontsizeProperties(PropertyMap& props, double fontSize)
     props["style:font-size-complex"] = aFSize;
 }
 
-void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId );
     PropertyMap aProps;
@@ -899,7 +899,7 @@ void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::co
     elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
 }
 
-void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 
     PropertyMap aProps;
@@ -924,7 +924,7 @@ void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element*
     elem.applyToChildren(*this);
 }
 
-void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&)
+void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     PropertyMap props1;
     props1[ "style:family" ] = "graphic";
@@ -970,11 +970,11 @@ void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::c
     elem.applyToChildren(*this);
 }
 
-void DrawXmlFinalizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void DrawXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     if( m_rProcessor.getStatusIndicator().is() )
         m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
@@ -988,7 +988,7 @@ void DrawXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::co
     elem.LeftMargin = elem.w;
     elem.RightMargin = 0;
 
-    for( std::list< Element* >::const_iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+    for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
     {
         if( (*it)->x < elem.LeftMargin )
             elem.LeftMargin = (*it)->x;
@@ -1075,7 +1075,7 @@ void DrawXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::co
     elem.applyToChildren(*this);
 }
 
-void DrawXmlFinalizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator& )
+void DrawXmlFinalizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.applyToChildren(*this);
 }
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.hxx b/sdext/source/pdfimport/tree/drawtreevisiting.hxx
index 7cdfb04885bb..c0482b1c4111 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.hxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.hxx
@@ -44,14 +44,14 @@ namespace pdfi
             m_rProcessor(rProcessor)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 
     class DrawXmlFinalizer : public ElementTreeVisitor
@@ -67,14 +67,14 @@ namespace pdfi
             m_rProcessor(rProcessor)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 
     class DrawXmlEmitter : public ElementTreeVisitor
@@ -100,14 +100,14 @@ namespace pdfi
             m_bWriteDrawDocument(eDocType==DRAW_DOC)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 }
 
diff --git a/sdext/source/pdfimport/tree/genericelements.cxx b/sdext/source/pdfimport/tree/genericelements.cxx
index ccb2fd53c932..8fa84c64c414 100644
--- a/sdext/source/pdfimport/tree/genericelements.cxx
+++ b/sdext/source/pdfimport/tree/genericelements.cxx
@@ -34,9 +34,6 @@ namespace pdfi
 
 Element::~Element()
 {
-    for (auto const& child : Children)
-        delete child;
-    Children.clear();
 }
 
 void Element::applyToChildren( ElementTreeVisitor& rVisitor )
@@ -45,7 +42,7 @@ void Element::applyToChildren( ElementTreeVisitor& rVisitor )
         (*it)->visitedBy( rVisitor, it );
 }
 
-void Element::setParent( std::list<Element*>::iterator const & el, Element* pNewParent )
+void Element::setParent( std::list<std::unique_ptr<Element>>::iterator const & el, Element* pNewParent )
 {
     if( pNewParent )
     {
@@ -95,32 +92,32 @@ void Element::emitStructure( int nLevel)
 }
 #endif
 
-void ListElement::visitedBy( ElementTreeVisitor& visitor, const std::list< Element* >::const_iterator& )
+void ListElement::visitedBy( ElementTreeVisitor& visitor, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     // this is only an inner node
     applyToChildren(visitor);
 }
 
 void HyperlinkElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                                  const std::list< Element* >::const_iterator& rParentIt )
+                                  const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
     rVisitor.visit(*this,rParentIt);
 }
 
 void TextElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                             const std::list< Element* >::const_iterator& rParentIt )
+                             const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
     rVisitor.visit(*this,rParentIt);
 }
 
 void FrameElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                              const std::list< Element* >::const_iterator& rParentIt )
+                              const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
     rVisitor.visit(*this,rParentIt);
 }
 
 void ImageElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                              const std::list< Element* >::const_iterator& rParentIt)
+                              const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt)
 {
     rVisitor.visit( *this, rParentIt);
 }
@@ -153,7 +150,7 @@ void PolyPolyElement::updateGeometry()
 }
 
 void PolyPolyElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                                 const std::list< Element* >::const_iterator& rParentIt)
+                                 const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt)
 {
     rVisitor.visit( *this, rParentIt);
 }
@@ -183,22 +180,22 @@ void PolyPolyElement::emitStructure( int nLevel)
 #endif
 
 void ParagraphElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                                  const std::list< Element* >::const_iterator& rParentIt )
+                                  const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
     rVisitor.visit(*this,rParentIt);
 }
 
 bool ParagraphElement::isSingleLined( PDFIProcessor const & rProc ) const
 {
-    std::list< Element* >::const_iterator it = Children.begin();
+    auto it = Children.begin();
     TextElement* pText = nullptr, *pLastText = nullptr;
     while( it != Children.end() )
     {
         // a paragraph containing subparagraphs cannot be single lined
-        if( dynamic_cast< ParagraphElement* >(*it) != nullptr )
+        if( dynamic_cast< ParagraphElement* >(it->get()) != nullptr )
             return false;
 
-        pText = dynamic_cast< TextElement* >(*it);
+        pText = dynamic_cast< TextElement* >(it->get());
         if( pText )
         {
             const FontAttributes& rFont = rProc.getFont( pText->FontId );
@@ -223,9 +220,9 @@ bool ParagraphElement::isSingleLined( PDFIProcessor const & rProc ) const
 double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
 {
     double line_h = 0;
-    for( std::list< Element* >::const_iterator it = Children.begin(); it != Children.end(); ++it )
+    for( auto it = Children.begin(); it != Children.end(); ++it )
     {
-        ParagraphElement* pPara = dynamic_cast< ParagraphElement* >(*it);
+        ParagraphElement* pPara = dynamic_cast< ParagraphElement* >(it->get());
         TextElement* pText = nullptr;
         if( pPara )
         {
@@ -233,7 +230,7 @@ double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
             if( lh > line_h )
                 line_h = lh;
         }
-        else if( (pText = dynamic_cast< TextElement* >( *it )) != nullptr )
+        else if( (pText = dynamic_cast< TextElement* >( it->get() )) != nullptr )
         {
             const FontAttributes& rFont = rProc.getFont( pText->FontId );
             double lh = pText->h;
@@ -249,22 +246,20 @@ double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
 TextElement* ParagraphElement::getFirstTextChild() const
 {
     TextElement* pText = nullptr;
-    for( std::list< Element* >::const_iterator it = Children.begin();
+    for( auto it = Children.begin();
          it != Children.end() && ! pText; ++it )
     {
-        pText = dynamic_cast<TextElement*>(*it);
+        pText = dynamic_cast<TextElement*>(it->get());
     }
     return pText;
 }
 
 PageElement::~PageElement()
 {
-    delete HeaderElement;
-    delete FooterElement;
 }
 
 void PageElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                             const std::list< Element* >::const_iterator& rParentIt )
+                             const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
      rVisitor.visit(*this, rParentIt);
 }
@@ -272,24 +267,24 @@ void PageElement::visitedBy( ElementTreeVisitor&                          rVisit
 void PageElement::updateParagraphGeometry( Element* pEle )
 {
     // update geometry of children
-    for( std::list< Element* >::iterator it = pEle->Children.begin();
+    for( auto it = pEle->Children.begin();
          it != pEle->Children.end(); ++it )
     {
-        updateParagraphGeometry( *it );
+        updateParagraphGeometry( it->get() );
     }
     // if this is a paragraph itself, then update according to children geometry
     if( dynamic_cast<ParagraphElement*>(pEle) )
     {
-        for( std::list< Element* >::iterator it = pEle->Children.begin();
+        for( auto it = pEle->Children.begin();
              it != pEle->Children.end(); ++it )
         {
             Element* pChild = nullptr;
-            TextElement* pText = dynamic_cast<TextElement*>(*it);
+            TextElement* pText = dynamic_cast<TextElement*>(it->get());
             if( pText )
                 pChild = pText;
             else
             {
-                ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*it);
+                ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(it->get());
                 if( pPara )
                     pChild = pPara;
             }
@@ -299,18 +294,18 @@ void PageElement::updateParagraphGeometry( Element* pEle )
     }
 }
 
-bool PageElement::resolveHyperlink( const std::list<Element*>::iterator& link_it, std::list<Element*>& rElements )
+bool PageElement::resolveHyperlink( const std::list<std::unique_ptr<Element>>::iterator& link_it, std::list<std::unique_ptr<Element>>& rElements )
 {
-    HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*link_it);
+    HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(link_it->get());
     if( ! pLink ) // sanity check
         return false;
 
-    for( std::list<Element*>::iterator it = rElements.begin(); it != rElements.end(); ++it )
+    for( auto it = rElements.begin(); it != rElements.end(); ++it )
     {
         if( (*it)->x >= pLink->x && (*it)->x + (*it)->w <= pLink->x + pLink->w &&
             (*it)->y >= pLink->y && (*it)->y + (*it)->h <= pLink->y + pLink->h )
         {
-            TextElement* pText = dynamic_cast<TextElement*>(*it);
+            TextElement* pText = dynamic_cast<TextElement*>(it->get());
             if( pText )
             {
                 if( pLink->Children.empty() )
@@ -320,7 +315,7 @@ bool PageElement::resolveHyperlink( const std::list<Element*>::iterator& link_it
                     pLink->Parent = (*it)->Parent;
                 }
                 // move text element into hyperlink
-                std::list<Element*>::iterator next = it;
+                auto next = it;
                 ++next;
                 Element::setParent( it, pLink );
                 it = next;
@@ -330,13 +325,13 @@ bool PageElement::resolveHyperlink( const std::list<Element*>::iterator& link_it
             // a link can contain multiple text elements or a single frame
             if( ! pLink->Children.empty() )
                 continue;
-            if( dynamic_cast<ParagraphElement*>(*it)  )
+            if( dynamic_cast<ParagraphElement*>(it->get())  )
             {
                 if( resolveHyperlink( link_it, (*it)->Children ) )
                     break;
                 continue;
             }
-            FrameElement* pFrame = dynamic_cast<FrameElement*>(*it);
+            FrameElement* pFrame = dynamic_cast<FrameElement*>(it->get());
             if( pFrame )
             {
                 // insert the hyperlink before the frame
@@ -357,7 +352,6 @@ void PageElement::resolveHyperlinks()
     {
         if( ! resolveHyperlink( Hyperlinks.Children.begin(), Children ) )
         {
-            delete Hyperlinks.Children.front();
             Hyperlinks.Children.pop_front();
         }
     }
@@ -373,10 +367,10 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
     // FIXME: currently the algorithm used is quadratic
     // this could be solved by some sorting beforehand
 
-    std::list< Element* >::iterator poly_it = Children.begin();
+    auto poly_it = Children.begin();
     while( poly_it != Children.end() )
     {
-        PolyPolyElement* pPoly = dynamic_cast< PolyPolyElement* >(*poly_it);
+        PolyPolyElement* pPoly = dynamic_cast< PolyPolyElement* >(poly_it->get());
         if( ! pPoly || ! pPoly->Children.empty() )
         {
             ++poly_it;
@@ -413,10 +407,10 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
             u_y = r_x; r_x = l_x; l_x = u_y;
         }
         u_y = aPoly.getB2DPoint(0).getY();
-        for( std::list< Element*>::iterator it = Children.begin();
+        for( auto it = Children.begin();
              it != Children.end(); ++it )
         {
-            Element* pEle = *it;
+            Element* pEle = it->get();
             if( pEle->y <= u_y && pEle->y + pEle->h*1.1 >= u_y )
             {
                 // first: is the element underlined completely ?
@@ -450,7 +444,7 @@ void PageElement::resolveUnderlines( PDFIProcessor const & rProc )
         }
         if( bRemovePoly )
         {
-            std::list< Element* >::iterator next_it = poly_it;
+            auto next_it = poly_it;
             ++next_it;
             Children.erase( poly_it );
             delete pPoly;
@@ -466,7 +460,7 @@ DocumentElement::~DocumentElement()
 }
 
 void DocumentElement::visitedBy( ElementTreeVisitor&                          rVisitor,
-                                 const std::list< Element* >::const_iterator& rParentIt)
+                                 const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt)
 {
     rVisitor.visit(*this, rParentIt);
 }
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index 6599d7430b4c..67b20c8a3f44 100644
--- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
@@ -543,7 +543,7 @@ void PDFIProcessor::emit( XmlEmitter&               rEmitter,
         rVisitorFactory.createOptimizingVisitor(*this));
     // FIXME: localization
     startIndicator( " " );
-    m_pDocument->visitedBy( *optimizingVisitor, std::list<Element*>::const_iterator());
+    m_pDocument->visitedBy( *optimizingVisitor, std::list<std::unique_ptr<Element>>::const_iterator());
 
 #if OSL_DEBUG_LEVEL > 0
     m_pDocument->emitStructure( 0 );
@@ -555,7 +555,7 @@ void PDFIProcessor::emit( XmlEmitter&               rEmitter,
         rVisitorFactory.createStyleCollectingVisitor(aStyles,*this));
     // FIXME: localization
 
-    m_pDocument->visitedBy( *finalizingVisitor, std::list<Element*>::const_iterator() );
+    m_pDocument->visitedBy( *finalizingVisitor, std::list<std::unique_ptr<Element>>::const_iterator() );
 
     EmitContext aContext( rEmitter, aStyles, m_aImages, *this, m_xStatusIndicator, m_xContext );
     ElementTreeVisitorSharedPtr aEmittingVisitor(
@@ -589,7 +589,7 @@ void PDFIProcessor::emit( XmlEmitter&               rEmitter,
     // emit style list
     aStyles.emit( aContext, *aEmittingVisitor );
 
-    m_pDocument->visitedBy( *aEmittingVisitor, std::list<Element*>::const_iterator() );
+    m_pDocument->visitedBy( *aEmittingVisitor, std::list<std::unique_ptr<Element>>::const_iterator() );
     aContext.rEmitter.endTag( "office:document" );
     endIndicator();
 }
@@ -625,7 +625,7 @@ void PDFIProcessor::endIndicator()
         m_xStatusIndicator->end();
 }
 
-static bool lr_tb_sort( Element* pLeft, Element* pRight )
+static bool lr_tb_sort( std::unique_ptr<Element> const & pLeft, std::unique_ptr<Element> const & pRight )
 {
     // Ensure irreflexivity (which could be compromised if h or w is negative):
     if (pLeft == pRight)
@@ -637,9 +637,9 @@ static bool lr_tb_sort( Element* pLeft, Element* pRight )
     // of the same order as font height whereas the real paint area
     // of text is usually smaller
     double fudge_factor_left = 0.0, fudge_factor_right = 0.0;
-    if( dynamic_cast< TextElement* >(pLeft) )
+    if( dynamic_cast< TextElement* >(pLeft.get()) )
         fudge_factor_left = 0.1;
-    if (dynamic_cast< TextElement* >(pRight))
+    if (dynamic_cast< TextElement* >(pRight.get()))
         fudge_factor_right = 0.1;
 
     // Allow negative height
diff --git a/sdext/source/pdfimport/tree/style.cxx b/sdext/source/pdfimport/tree/style.cxx
index 87f6178ec238..bceb36003acb 100644
--- a/sdext/source/pdfimport/tree/style.cxx
+++ b/sdext/source/pdfimport/tree/style.cxx
@@ -201,7 +201,7 @@ void StyleContainer::impl_emitStyle( sal_Int32           nStyleId,
             rContext.rEmitter.write( rStyle.Contents );
         if( rStyle.ContainedElement )
             rStyle.ContainedElement->visitedBy( rContainedElemVisitor,
-                                                std::list<Element*>::iterator() );
+                                                std::list<std::unique_ptr<Element>>::iterator() );
         rContext.rEmitter.endTag( rStyle.Name.getStr() );
     }
 }
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx
index 981882945350..e66a5fea81a9 100644
--- a/sdext/source/pdfimport/tree/writertreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx
@@ -36,12 +36,12 @@ using namespace ::com::sun::star;
 namespace pdfi
 {
 
-void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator&   )
+void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Children.empty() )
         return;
 
-    const char* pType = dynamic_cast<DrawElement*>(elem.Children.front()) ? "draw:a" : "text:a";
+    const char* pType = dynamic_cast<DrawElement*>(elem.Children.front().get()) ? "draw:a" : "text:a";
 
     PropertyMap aProps;
     aProps[ "xlink:type" ] = "simple";
@@ -50,8 +50,8 @@ void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element*
     aProps[ "xlink:show" ] = "new";
 
     m_rEmitContext.rEmitter.beginTag( pType, aProps );
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -59,7 +59,7 @@ void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element*
     m_rEmitContext.rEmitter.endTag( pType );
 }
 
-void WriterXmlEmitter::visit( TextElement& elem, const std::list< Element* >::const_iterator&   )
+void WriterXmlEmitter::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Text.isEmpty() )
         return;
@@ -73,8 +73,8 @@ void WriterXmlEmitter::visit( TextElement& elem, const std::list< Element* >::co
 
     m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
     m_rEmitContext.rEmitter.write( elem.Text.makeStringAndClear() );
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -83,7 +83,7 @@ void WriterXmlEmitter::visit( TextElement& elem, const std::list< Element* >::co
     m_rEmitContext.rEmitter.endTag( "text:span" );
 }
 
-void WriterXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator&   )
+void WriterXmlEmitter::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     PropertyMap aProps;
     if( elem.StyleId != -1 )
@@ -95,8 +95,8 @@ void WriterXmlEmitter::visit( ParagraphElement& elem, const std::list< Element*
         pTagType = "text:h";
     m_rEmitContext.rEmitter.beginTag( pTagType, aProps );
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -203,20 +203,20 @@ void WriterXmlEmitter::fillFrameProps( DrawElement&       rElem,
     }
 }
 
-void WriterXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::const_iterator&   )
+void WriterXmlEmitter::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( elem.Children.empty() )
         return;
 
-    bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front()) != nullptr);
+    bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front().get()) != nullptr);
     PropertyMap aFrameProps;
     fillFrameProps( elem, aFrameProps, m_rEmitContext );
     m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps );
     if( bTextBox )
         m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() );
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it = elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
@@ -227,7 +227,7 @@ void WriterXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::c
     m_rEmitContext.rEmitter.endTag( "draw:frame" );
 }
 
-void WriterXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlEmitter::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.updateGeometry();
     /* note:
@@ -293,7 +293,7 @@ void WriterXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >
     m_rEmitContext.rEmitter.endTag( "draw:path" );
 }
 
-void WriterXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlEmitter::visit( ImageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     PropertyMap aImageProps;
     m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps );
@@ -303,34 +303,34 @@ void WriterXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::c
     m_rEmitContext.rEmitter.endTag( "draw:image" );
 }
 
-void WriterXmlEmitter::visit( PageElement& elem, const std::list< Element* >::const_iterator&   )
+void WriterXmlEmitter::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&   )
 {
     if( m_rEmitContext.xStatusIndicator.is() )
         m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber );
 
-    std::list< Element* >::iterator this_it =  elem.Children.begin();
-    while( this_it !=elem.Children.end() && *this_it != &elem )
+    auto this_it =  elem.Children.begin();
+    while( this_it != elem.Children.end() && this_it->get() != &elem )
     {
         (*this_it)->visitedBy( *this, this_it );
         ++this_it;
     }
 }
 
-void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
     m_rEmitContext.rEmitter.beginTag( "office:text", PropertyMap() );
 
-    for( std::list< Element* >::iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+    for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
     {
-        PageElement* pPage = dynamic_cast<PageElement*>(*it);
+        PageElement* pPage = dynamic_cast<PageElement*>(it->get());
         if( pPage )
         {
             // emit only page anchored objects
             // currently these are only DrawElement types
-            for( std::list< Element* >::iterator child_it = pPage->Children.begin(); child_it != pPage->Children.end(); ++child_it )
+            for( auto child_it = pPage->Children.begin(); child_it != pPage->Children.end(); ++child_it )
             {
-                if( dynamic_cast<DrawElement*>(*child_it) != nullptr )
+                if( dynamic_cast<DrawElement*>(child_it->get()) != nullptr )
                     (*child_it)->visitedBy( *this, child_it );
             }
         }
@@ -339,9 +339,9 @@ void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >
     // do not emit page anchored objects, they are emitted before
     // (must precede all pages in writer document) currently these are
     // only DrawElement types
-    for( std::list< Element* >::iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+    for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
     {
-        if( dynamic_cast<DrawElement*>(*it) == nullptr )
+        if( dynamic_cast<DrawElement*>(it->get()) == nullptr )
             (*it)->visitedBy( *this, it );
     }
 
@@ -350,24 +350,24 @@ void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >
 }
 
 
-void WriterXmlOptimizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+void WriterXmlOptimizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void WriterXmlOptimizer::visit( TextElement&, const std::list< Element* >::const_iterator&)
+void WriterXmlOptimizer::visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
 }
 
-void WriterXmlOptimizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlOptimizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.applyToChildren(*this);
 }
 
-void WriterXmlOptimizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+void WriterXmlOptimizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& elemIt )
+void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& elemIt )
 {
     /* note: optimize two consecutive PolyPolyElements that
      *  have the same path but one of which is a stroke while
@@ -378,12 +378,12 @@ void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element*
     // find following PolyPolyElement in parent's children list
     if( elemIt == elem.Parent->Children.end() )
         return;
-    std::list< Element* >::const_iterator next_it = elemIt;
+    auto next_it = elemIt;
     ++next_it;
     if( next_it == elem.Parent->Children.end() )
         return;
 
-    PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
+    PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(next_it->get());
     if( !pNext || pNext->PolyPoly != elem.PolyPoly )
         return;
 
@@ -413,7 +413,7 @@ void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element*
         elem.Children.splice( elem.Children.end(), pNext->Children );
         // workaround older compilers that do not have std::list::erase(const_iterator)
 #if HAVE_BROKEN_CONST_ITERATORS
-        std::list< Element* >::iterator tmpIt = elem.Parent->Children.begin();
+        auto tmpIt = elem.Parent->Children.begin();
         std::advance(tmpIt, std::distance(elem.Parent->Children.cbegin(), next_it));
         elem.Parent->Children.erase(tmpIt);
 #else
@@ -423,7 +423,7 @@ void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element*
     }
 }
 
-void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& rParentIt)
+void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt)
 {
     optimizeTextElements( elem );
 
@@ -432,12 +432,12 @@ void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element
     if( elem.Parent && rParentIt != elem.Parent->Children.end() )
     {
         // find if there is a previous paragraph that might be a heading for this one
-        std::list<Element*>::const_iterator prev = rParentIt;
+        auto prev = rParentIt;
         ParagraphElement* pPrevPara = nullptr;
         while( prev != elem.Parent->Children.begin() )
         {
             --prev;
-            pPrevPara = dynamic_cast< ParagraphElement* >(*prev);
+            pPrevPara = dynamic_cast< ParagraphElement* >(prev->get());
             if( pPrevPara )
             {
                 /* What constitutes a heading ? current hints are:
@@ -480,7 +480,7 @@ void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element
     }
 }
 
-void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlOptimizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     if( m_rProcessor.getStatusIndicator().is() )
         m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
@@ -496,7 +496,7 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
 
     // find paragraphs in text
     ParagraphElement* pCurPara = nullptr;
-    std::list< Element* >::iterator page_element, next_page_element;
+    std::list< std::unique_ptr<Element> >::iterator page_element, next_page_element;
     next_page_element = elem.Children.begin();
     double fCurLineHeight = 0.0; // average height of text items in current para
     int nCurLineElements = 0; // number of line contributing elements in current para
@@ -506,17 +506,17 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
     while( next_page_element != elem.Children.end() )
     {
         page_element = next_page_element++;
-        ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(*page_element);
+        ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(page_element->get());
         if( pPagePara )
         {
             pCurPara = pPagePara;
             // adjust line height and text items
             fCurLineHeight = 0.0;
             nCurLineElements = 0;
-            for( std::list< Element* >::iterator it = pCurPara->Children.begin();
+            for( auto it = pCurPara->Children.begin();
                  it != pCurPara->Children.end(); ++it )
             {
-                TextElement* pTestText = dynamic_cast<TextElement*>(*it);
+                TextElement* pTestText = dynamic_cast<TextElement*>(it->get());
                 if( pTestText )
                 {
                     fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
@@ -526,10 +526,10 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
             continue;
         }
 
-        HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*page_element);
-        DrawElement* pDraw = dynamic_cast<DrawElement*>(*page_element);
+        HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(page_element->get());
+        DrawElement* pDraw = dynamic_cast<DrawElement*>(page_element->get());
         if( ! pDraw && pLink && ! pLink->Children.empty() )
-            pDraw = dynamic_cast<DrawElement*>(pLink->Children.front() );
+            pDraw = dynamic_cast<DrawElement*>(pLink->Children.front().get() );
         if( pDraw )
         {
             // insert small drawing objects as character, else leave them page bound
@@ -550,12 +550,12 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
             // or perhaps the draw element begins a new paragraph
             else if( next_page_element != elem.Children.end() )
             {
-                TextElement* pText = dynamic_cast<TextElement*>(*next_page_element);
+                TextElement* pText = dynamic_cast<TextElement*>(next_page_element->get());
                 if( ! pText )
                 {
-                    ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*next_page_element);
+                    ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(next_page_element->get());
                     if( pPara && ! pPara->Children.empty() )
-                        pText = dynamic_cast<TextElement*>(pPara->Children.front());
+                        pText = dynamic_cast<TextElement*>(pPara->Children.front().get());
                 }
                 if( pText && // check there is a text
                     pDraw->h < pText->h*1.5 && // and it is approx the same height
@@ -584,9 +584,9 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
             }
         }
 
-        TextElement* pText = dynamic_cast<TextElement*>(*page_element);
+        TextElement* pText = dynamic_cast<TextElement*>(page_element->get());
         if( ! pText && pLink && ! pLink->Children.empty() )
-            pText = dynamic_cast<TextElement*>(pLink->Children.front());
+            pText = dynamic_cast<TextElement*>(pLink->Children.front().get());
         if( pText )
         {
             Element* pGeo = pLink ? static_cast<Element*>(pLink) :
@@ -638,14 +638,14 @@ void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::
             // set parent
             pCurPara->Parent = &elem;
             //insert new paragraph before current element
-            page_element = elem.Children.insert( page_element, pCurPara );
+            page_element = elem.Children.insert( page_element, std::unique_ptr<Element>(pCurPara) );
             // forward iterator to current element again
             ++ page_element;
             // update next_element which is now invalid
             next_page_element = page_element;
             ++ next_page_element;
         }
-        Element* pCurEle = *page_element;
+        Element* pCurEle = page_element->get();
         Element::setParent( page_element, pCurPara );
         OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" );
         if( pText || pDraw )
@@ -673,25 +673,25 @@ void WriterXmlOptimizer::checkHeaderAndFooter( PageElement& rElem )
     // detect header
     // Note: the following assumes that the pages' children have been
     // sorted geometrically
-    std::list< Element* >::iterator it = rElem.Children.begin();
+    auto it = rElem.Children.begin();
     while( it != rElem.Children.end() )
     {
-        ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*it);
+        ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(it->get());
         if( pPara )
         {
             if( pPara->y+pPara->h < rElem.h*0.15 && pPara->isSingleLined( m_rProcessor ) )
             {
-                std::list< Element* >::iterator next_it = it;
+                auto next_it = it;
                 ParagraphElement* pNextPara = nullptr;
                 while( ++next_it != rElem.Children.end() && pNextPara == nullptr )
                 {
-                    pNextPara = dynamic_cast<ParagraphElement*>(*next_it);
+                    pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
                 }
                 if( pNextPara && pNextPara->y > pPara->y+pPara->h*2 )
                 {
-                    rElem.HeaderElement = pPara;
+                    rElem.HeaderElement = std::move(*it);
                     pPara->Parent = nullptr;
-                    rElem.Children.remove( pPara );
+                    rElem.Children.erase( it );
                 }
             }
             break;
@@ -700,25 +700,25 @@ void WriterXmlOptimizer::checkHeaderAndFooter( PageElement& rElem )
     }
 
     // detect footer
-    std::list< Element* >::reverse_iterator rit = rElem.Children.rbegin();
+    std::list< std::unique_ptr<Element> >::reverse_iterator rit = rElem.Children.rbegin();
     while( rit != rElem.Children.rend() )
     {
-        ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*rit);
+        ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(rit->get());
         if( pPara )
         {
             if( pPara->y > rElem.h*0.85 && pPara->isSingleLined( m_rProcessor ) )
             {
-                std::list< Element* >::reverse_iterator next_it = rit;
+                std::list< std::unique_ptr<Element> >::reverse_iterator next_it = rit;
                 ParagraphElement* pNextPara = nullptr;
                 while( ++next_it != rElem.Children.rend() && pNextPara == nullptr )
                 {
-                    pNextPara = dynamic_cast<ParagraphElement*>(*next_it);
+                    pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
                 }
                 if( pNextPara && pNextPara->y < pPara->y-pPara->h*2 )
                 {
-                    rElem.FooterElement = pPara;
+                    rElem.FooterElement = std::move(*rit);
                     pPara->Parent = nullptr;
-                    rElem.Children.remove( pPara );
+                    rElem.Children.erase( std::next(rit).base() );
                 }
             }
             break;
@@ -736,8 +736,8 @@ void WriterXmlOptimizer::optimizeTextElements(Element& rParent)
     }
 
     // concatenate child elements with same font id
-    std::list< Element* >::iterator next = rParent.Children.begin();
-    std::list< Element* >::iterator it = next++;
+    auto next = rParent.Children.begin();
+    auto it = next++;
     FrameElement* pFrame = dynamic_cast<FrameElement*>(rParent.Parent);
     bool bRotatedFrame = false;
     if( pFrame )
@@ -749,10 +749,10 @@ void WriterXmlOptimizer::optimizeTextElements(Element& rParent)
     while( next != rParent.Children.end() )
     {
         bool bConcat = false;
-        TextElement* pCur = dynamic_cast<TextElement*>(*it);
+        TextElement* pCur = dynamic_cast<TextElement*>(it->get());
         if( pCur )
         {
-            TextElement* pNext = dynamic_cast<TextElement*>(*next);
+            TextElement* pNext = dynamic_cast<TextElement*>(next->get());
             if( pNext )
             {
                 const GraphicsContext& rCurGC = m_rProcessor.getGraphicsContext( pCur->GCId );
@@ -824,7 +824,7 @@ void WriterXmlOptimizer::optimizeTextElements(Element& rParent)
                 }
             }
         }
-        else if( dynamic_cast<HyperlinkElement*>(*it) )
+        else if( dynamic_cast<HyperlinkElement*>(it->get()) )
             optimizeTextElements( **it );
         if( bConcat )
         {
@@ -839,13 +839,13 @@ void WriterXmlOptimizer::optimizeTextElements(Element& rParent)
     }
 }
 
-void WriterXmlOptimizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+void WriterXmlOptimizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     elem.applyToChildren(*this);
 }
 
 
-void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     // xxx TODO copied from DrawElement
     const GraphicsContext& rGC = m_rProcessor.getGraphicsContext(elem.GCId );
@@ -900,11 +900,11 @@ void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element*
     elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
 }
 
-void WriterXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
-void WriterXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId );
     PropertyMap aProps;
@@ -958,7 +958,7 @@ void WriterXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::
     elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
 }
 
-void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& rParentIt )
+void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
 {
     PropertyMap aParaProps;
 
@@ -1001,10 +1001,10 @@ void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element
 
         // check whether to leave some space to next paragraph
         // find whether there is a next paragraph
-        std::list< Element* >::const_iterator it = rParentIt;
+        auto it = rParentIt;
         const ParagraphElement* pNextPara = nullptr;
         while( ++it != elem.Parent->Children.end() && ! pNextPara )
-            pNextPara = dynamic_cast< const ParagraphElement* >(*it);
+            pNextPara = dynamic_cast< const ParagraphElement* >(it->get());
         if( pNextPara )
         {
             if( pNextPara->y - (elem.y+elem.h) > convmm2Px( 10 ) )
@@ -1030,7 +1030,7 @@ void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element
     elem.applyToChildren(*this);
 }
 
-void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&)
+void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
 {
     PropertyMap aProps;
     aProps[ "style:family" ] = "graphic";
@@ -1058,7 +1058,7 @@ void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >:
     elem.applyToChildren(*this);
 }
 
-void WriterXmlFinalizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
 }
 
@@ -1086,7 +1086,7 @@ void WriterXmlFinalizer::setFirstOnPage( ParagraphElement&    rElem,
     }
 }
 
-void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     if( m_rProcessor.getStatusIndicator().is() )
         m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
@@ -1101,9 +1101,9 @@ void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::
     elem.RightMargin = 0;
     // first element should be a paragraph
     ParagraphElement* pFirstPara = nullptr;
-    for( std::list< Element* >::const_iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+    for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
     {
-        if( dynamic_cast<ParagraphElement*>( *it ) )
+        if( dynamic_cast<ParagraphElement*>( it->get() ) )
         {
             if( (*it)->x < elem.LeftMargin )
                 elem.LeftMargin = (*it)->x;
@@ -1114,7 +1114,7 @@ void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::
             if( (*it)->y + (*it)->h > elem.h - elem.BottomMargin )
                 elem.BottomMargin = elem.h - ((*it)->y + (*it)->h);
             if( ! pFirstPara )
-                pFirstPara = dynamic_cast<ParagraphElement*>( *it );
+                pFirstPara = dynamic_cast<ParagraphElement*>( it->get() );
         }
     }
     if( elem.HeaderElement && elem.HeaderElement->y < elem.TopMargin )
@@ -1199,14 +1199,14 @@ void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::
     StyleContainer::Style aFooterStyle( "style:footer", PropertyMap() );
     if( elem.HeaderElement )
     {
-        elem.HeaderElement->visitedBy( *this, std::list<Element*>::iterator() );
-        aHeaderStyle.ContainedElement = elem.HeaderElement;
+        elem.HeaderElement->visitedBy( *this, std::list<std::unique_ptr<Element>>::iterator() );
+        aHeaderStyle.ContainedElement = elem.HeaderElement.get();
         aMPStyle.SubStyles.push_back( &aHeaderStyle );
     }
     if( elem.FooterElement )
     {
-        elem.FooterElement->visitedBy( *this, std::list<Element*>::iterator() );
-        aFooterStyle.ContainedElement = elem.FooterElement;
+        elem.FooterElement->visitedBy( *this, std::list<std::unique_ptr<Element>>::iterator() );
+        aFooterStyle.ContainedElement = elem.FooterElement.get();
         aMPStyle.SubStyles.push_back( &aFooterStyle );
     }
     elem.StyleId = m_rStyleContainer.impl_getStyleId( aMPStyle,false );
@@ -1222,12 +1222,12 @@ void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::
     {
         pFirstPara = ElementFactory::createParagraphElement( nullptr );
         pFirstPara->Parent = &elem;
-        elem.Children.push_front( pFirstPara );
+        elem.Children.push_front( std::unique_ptr<Element>(pFirstPara) );
     }
     setFirstOnPage(*pFirstPara, m_rStyleContainer, aMasterPageName);
 }
 
-void WriterXmlFinalizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator& )
+void WriterXmlFinalizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
 {
     elem.applyToChildren(*this);
 }
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.hxx b/sdext/source/pdfimport/tree/writertreevisiting.hxx
index 0fe5c51a09da..c93330d94a1c 100644
--- a/sdext/source/pdfimport/tree/writertreevisiting.hxx
+++ b/sdext/source/pdfimport/tree/writertreevisiting.hxx
@@ -38,14 +38,14 @@ namespace pdfi
             m_rProcessor(rProcessor)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 
     class WriterXmlFinalizer : public ElementTreeVisitor
@@ -65,14 +65,14 @@ namespace pdfi
             m_rProcessor(rProcessor)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 
     class WriterXmlEmitter : public ElementTreeVisitor
@@ -88,14 +88,14 @@ namespace pdfi
             m_rEmitContext(rEmitContext)
         {}
 
-        virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) override;
-        virtual void visit( TextElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( FrameElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( ImageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( PageElement&, const std::list< Element* >::const_iterator&  ) override;
-        virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator&  ) override;
+        virtual void visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& ) override;
+        virtual void visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ParagraphElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( FrameElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PolyPolyElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( PageElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
+        virtual void visit( DocumentElement&, const std::list< std::unique_ptr<Element> >::const_iterator&  ) override;
     };
 }
 


More information about the Libreoffice-commits mailing list