LCOV - code coverage report
Current view: top level - oox/source/ppt - slidefragmenthandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 82 78.0 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 117 284 41.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "comphelper/anytostring.hxx"
      21                 :            : #include "cppuhelper/exc_hlp.hxx"
      22                 :            : 
      23                 :            : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      24                 :            : #include <com/sun/star/container/XNamed.hpp>
      25                 :            : 
      26                 :            : #include "oox/helper/propertyset.hxx"
      27                 :            : #include "oox/core/xmlfilterbase.hxx"
      28                 :            : #include "headerfootercontext.hxx"
      29                 :            : #include "oox/ppt/backgroundproperties.hxx"
      30                 :            : #include "oox/ppt/slidefragmenthandler.hxx"
      31                 :            : #include "oox/ppt/slidetimingcontext.hxx"
      32                 :            : #include "oox/ppt/slidetransitioncontext.hxx"
      33                 :            : #include "oox/ppt/slidemastertextstylescontext.hxx"
      34                 :            : #include "oox/ppt/pptshapegroupcontext.hxx"
      35                 :            : #include "oox/ppt/pptshape.hxx"
      36                 :            : #include "oox/vml/vmldrawing.hxx"
      37                 :            : #include "oox/vml/vmldrawingfragment.hxx"
      38                 :            : #include "oox/drawingml/clrschemecontext.hxx"
      39                 :            : #include "oox/ppt/pptimport.hxx"
      40                 :            : 
      41                 :            : 
      42                 :            : using rtl::OUString;
      43                 :            : using namespace ::com::sun::star;
      44                 :            : using namespace ::oox::core;
      45                 :            : using namespace ::oox::drawingml;
      46                 :            : using namespace ::com::sun::star::uno;
      47                 :            : using namespace ::com::sun::star::drawing;
      48                 :            : using namespace ::com::sun::star::xml::sax;
      49                 :            : using namespace ::com::sun::star::container;
      50                 :            : 
      51                 :            : namespace oox { namespace ppt {
      52                 :            : 
      53                 :         33 : SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation ) throw()
      54                 :            : : FragmentHandler2( rFilter, rFragmentPath )
      55                 :            : , mpSlidePersistPtr( pPersistPtr )
      56 [ +  - ][ +  - ]:         33 : , meShapeLocation( eShapeLocation )
      57                 :            : {
      58 [ +  - ][ +  - ]:         33 :     OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "vmlDrawing" ) );
      59         [ -  + ]:         33 :     if( !aVMLDrawingFragmentPath.isEmpty() )
      60         [ #  # ]:          0 :         getFilter().importFragment( new oox::vml::DrawingFragment(
      61 [ #  # ][ #  # ]:         33 :             getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
         [ #  # ][ #  # ]
      62                 :         33 : }
      63                 :            : 
      64         [ +  - ]:         33 : SlideFragmentHandler::~SlideFragmentHandler() throw()
      65                 :            : {
      66                 :            :     // convert and insert all VML shapes (mostly form controls)
      67 [ +  - ][ +  - ]:         33 :     mpSlidePersistPtr->getDrawing()->convertAndInsert();
      68         [ -  + ]:         57 : }
      69                 :            : 
      70                 :        489 : ::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      71                 :            : {
      72   [ +  +  +  +  :        489 :     switch( aElementToken )
          +  -  -  +  -  
          -  +  -  +  +  
             +  +  -  + ]
      73                 :            :     {
      74                 :            :     case PPT_TOKEN( sldMaster ):        // CT_SlideMaster
      75                 :            :     case PPT_TOKEN( handoutMaster ):    // CT_HandoutMaster
      76                 :            :     case PPT_TOKEN( sld ):              // CT_CommonSlideData
      77                 :            :     {
      78         [ +  - ]:         18 :         Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
      79         [ +  - ]:         18 :         PropertyMap aPropMap;
      80         [ +  - ]:         18 :         PropertySet aSlideProp( xSlide );
      81                 :            : 
      82 [ +  - ][ +  - ]:         18 :         aPropMap[ PROP_Visible ] = Any( rAttribs.getBool( XML_show, sal_True ) );
                 [ +  - ]
      83         [ +  - ]:         18 :         aSlideProp.setProperties( aPropMap );
      84                 :            : 
      85         [ +  - ]:         18 :         return this;
      86                 :            :     }
      87                 :            :     case PPT_TOKEN( notes ):            // CT_NotesSlide
      88                 :            :     {
      89                 :            :         // Import notesMaster
      90 [ +  - ][ +  - ]:          3 :         PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
      91 [ +  - ][ +  - ]:          3 :         OUString aNotesFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "notesMaster" ) );
      92                 :            : 
      93                 :          3 :         std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
      94                 :          3 :         std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
      95 [ +  - ][ +  + ]:          6 :         while( aIter != rMasterPages.end() )
      96                 :            :         {
      97         [ -  + ]:          3 :             if( (*aIter)->getPath() == aNotesFragmentPath )
      98                 :            :             {
      99 [ #  # ][ #  # ]:          0 :                 if( !mpSlidePersistPtr->getMasterPersist() )
                 [ #  # ]
     100 [ #  # ][ #  # ]:          0 :                     mpSlidePersistPtr->setMasterPersist( *aIter );
                 [ #  # ]
     101                 :          0 :                 break;
     102                 :            :             }
     103                 :          3 :             ++aIter;
     104                 :            :         }
     105 [ +  - ][ +  - ]:          3 :         if( aIter == rMasterPages.end() && !mpSlidePersistPtr->getMasterPersist() )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  -  
             #  #  #  # ]
     106                 :            :         {
     107 [ +  - ][ +  - ]:          3 :             TextListStylePtr pTextListStyle(new TextListStyle);
                 [ +  - ]
     108                 :            :             SlidePersistPtr pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_True, mpSlidePersistPtr->getPage(),
     109 [ +  - ][ +  - ]:          3 :                                 ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr->getNotesTextStyle() ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     110                 :            :             //pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
     111                 :          3 :             pMasterPersistPtr->setPath( aNotesFragmentPath );
     112         [ +  - ]:          3 :             rFilter.getMasterPages().push_back( pMasterPersistPtr );
     113 [ +  - ][ +  - ]:          3 :             FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
     114         [ +  - ]:          3 :             rFilter.importFragment( xMasterFragmentHandler );
     115                 :            :             //pMasterPersistPtr->createBackground( rFilter );
     116                 :            :             //pMasterPersistPtr->createXShapes( rFilter );
     117 [ +  - ][ +  - ]:          3 :             mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
         [ +  - ][ +  - ]
                 [ +  - ]
     118                 :            :         }
     119                 :          3 :         return this;
     120                 :            :     }
     121                 :            :     case PPT_TOKEN( notesMaster ):      // CT_NotesMaster
     122                 :          3 :         return this;
     123                 :            :     case PPT_TOKEN( cSld ):             // CT_CommonSlideData
     124         [ +  - ]:         33 :         maSlideName = rAttribs.getString(XML_name, OUString());
     125                 :         33 :         return this;
     126                 :            : 
     127                 :            :     case PPT_TOKEN( spTree ):           // CT_GroupShape
     128                 :            :         {
     129                 :            :             // TODO Convert this to FragmentHandler2
     130                 :            :             return new PPTShapeGroupContext(
     131                 :            :                 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
     132 [ +  - ][ +  - ]:         33 :                 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     133                 :            :         }
     134                 :            :         break;
     135                 :            : 
     136                 :            :     case PPT_TOKEN( controls ):
     137                 :          0 :         return this;
     138                 :            :     case PPT_TOKEN( control ):
     139                 :            :         {
     140         [ #  # ]:          0 :             ::oox::vml::ControlInfo aInfo;
     141 [ #  # ][ #  # ]:          0 :             aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
     142 [ #  # ][ #  # ]:          0 :             aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     143         [ #  # ]:          0 :             aInfo.maName = rAttribs.getXString( XML_name, OUString() );
     144 [ #  # ][ #  # ]:          0 :             mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
                 [ #  # ]
     145                 :            :         }
     146                 :          0 :         return this;
     147                 :            : 
     148                 :            :     case PPT_TOKEN( timing ): // CT_SlideTiming
     149                 :          3 :         return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
     150                 :            :     case PPT_TOKEN( transition ): // CT_SlideTransition
     151                 :          0 :         return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
     152                 :            :     case PPT_TOKEN( hf ):
     153         [ #  # ]:          0 :         return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
     154                 :            : 
     155                 :            :     // BackgroundGroup
     156                 :            :     case PPT_TOKEN( bg ):
     157                 :          9 :         return this;
     158                 :            :     case PPT_TOKEN( bgPr ):             // CT_BackgroundProperties
     159                 :            :         {
     160 [ #  # ][ #  # ]:          0 :             FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
                 [ #  # ]
     161 [ #  # ][ #  # ]:          0 :             mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
                 [ #  # ]
     162 [ #  # ][ #  # ]:          0 :             return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
     163                 :            :         }
     164                 :            :         break;
     165                 :            : 
     166                 :            :     case PPT_TOKEN( bgRef ):            // a:CT_StyleMatrixReference
     167                 :            :         {
     168                 :          9 :             const FillProperties *pFillProperties = NULL;
     169 [ +  - ][ +  - ]:          9 :             if( mpSlidePersistPtr->getTheme() )
                 [ +  + ]
     170 [ +  - ][ +  - ]:          6 :                 pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
         [ +  - ][ +  - ]
     171 [ +  + ][ +  - ]:          9 :             FillPropertiesPtr pFillPropertiesPtr( pFillProperties ? new FillProperties( *pFillProperties ) : new FillProperties() );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     172         [ +  - ]:          9 :             ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
     173 [ +  - ][ +  - ]:          9 :             mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
                 [ +  - ]
     174         [ +  - ]:          9 :             return ret;
     175                 :            :         }
     176                 :            :         break;
     177                 :            : 
     178                 :            :     case PPT_TOKEN( clrMap ):           // CT_ColorMapping
     179                 :            :         {
     180 [ +  - ][ +  - ]:         12 :             oox::drawingml::ClrMapPtr pClrMapPtr( new oox::drawingml::ClrMap() );
                 [ +  - ]
     181 [ +  - ][ +  - ]:         12 :             ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs.getFastAttributeList(), *pClrMapPtr );
     182 [ +  - ][ +  - ]:         12 :             mpSlidePersistPtr->setClrMap( pClrMapPtr );
                 [ +  - ]
     183         [ +  - ]:         12 :             return ret;
     184                 :            :         }
     185                 :            :         break;
     186                 :            :     case PPT_TOKEN( clrMapOvr ):        // CT_ColorMappingOverride
     187                 :            :     case PPT_TOKEN( sldLayoutIdLst ):   // CT_SlideLayoutIdList
     188                 :         24 :         return this;
     189                 :            :     case PPT_TOKEN( txStyles ):         // CT_SlideMasterTextStyles
     190         [ +  - ]:          6 :         return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
     191                 :            :         break;
     192                 :            :     case PPT_TOKEN( custDataLst ):      // CT_CustomerDataList
     193                 :            :     case PPT_TOKEN( tagLst ):           // CT_TagList
     194                 :          0 :         return this;
     195                 :            :     }
     196                 :            : 
     197                 :        489 :     return this;
     198                 :            : }
     199                 :            : 
     200                 :         33 : void SlideFragmentHandler::finalizeImport()
     201                 :            : {
     202                 :            :     try
     203                 :            :     {
     204         [ +  - ]:         33 :         Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
     205         [ +  - ]:         33 :         PropertySet aSlideProp( xSlide );
     206         [ +  - ]:         33 :         aSlideProp.setProperties( maSlideProperties );
     207         [ +  + ]:         33 :         if ( !maSlideName.isEmpty() )
     208                 :            :         {
     209         [ +  - ]:          9 :             Reference< XNamed > xNamed( xSlide, UNO_QUERY );
     210         [ +  - ]:          9 :             if( xNamed.is() )
     211 [ +  - ][ +  - ]:          9 :                 xNamed->setName( maSlideName );
     212 [ +  - ][ #  # ]:         33 :         }
     213                 :            :     }
     214                 :          0 :     catch( uno::Exception& )
     215                 :            :     {
     216                 :            :         OSL_FAIL( (rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
     217                 :            :                     "exception caught: ") +
     218                 :            :             rtl::OUStringToOString(
     219                 :            :                 comphelper::anyToString( cppu::getCaughtException() ),
     220                 :            :                 RTL_TEXTENCODING_UTF8 )).getStr() );
     221                 :            :     }
     222                 :         33 : }
     223                 :            : 
     224 [ +  - ][ +  - ]:        285 : } }
     225                 :            : 
     226                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10