LCOV - code coverage report
Current view: top level - oox/source/ppt - slidefragmenthandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 105 66.7 %
Date: 2015-06-13 12:38:46 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          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             : #include <osl/diagnose.h>
      26             : 
      27             : #include "oox/helper/propertyset.hxx"
      28             : #include "oox/core/xmlfilterbase.hxx"
      29             : #include "headerfootercontext.hxx"
      30             : #include "oox/ppt/backgroundproperties.hxx"
      31             : #include "oox/ppt/slidefragmenthandler.hxx"
      32             : #include "oox/ppt/slidetimingcontext.hxx"
      33             : #include "oox/ppt/slidetransitioncontext.hxx"
      34             : #include "oox/ppt/slidemastertextstylescontext.hxx"
      35             : #include "oox/ppt/pptshapegroupcontext.hxx"
      36             : #include "oox/ppt/pptshape.hxx"
      37             : #include "oox/vml/vmldrawing.hxx"
      38             : #include "oox/vml/vmldrawingfragment.hxx"
      39             : #include "drawingml/clrschemecontext.hxx"
      40             : #include "drawingml/textliststyle.hxx"
      41             : #include "oox/ppt/pptimport.hxx"
      42             : 
      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         292 : SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation )
      54             : : FragmentHandler2( rFilter, rFragmentPath )
      55             : , mpSlidePersistPtr( pPersistPtr )
      56         292 : , meShapeLocation( eShapeLocation )
      57             : {
      58         292 :     OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "vmlDrawing" );
      59         292 :     if( !aVMLDrawingFragmentPath.isEmpty() )
      60           1 :         getFilter().importFragment( new oox::vml::DrawingFragment(
      61           2 :             getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
      62         292 : }
      63             : 
      64         788 : SlideFragmentHandler::~SlideFragmentHandler()
      65             : {
      66             :     // convert and insert all VML shapes (mostly form controls)
      67         292 :     mpSlidePersistPtr->getDrawing()->convertAndInsert();
      68         496 : }
      69             : 
      70        3388 : ::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
      71             : {
      72        3388 :     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         182 :         Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
      79         364 :         PropertyMap aPropMap;
      80         364 :         PropertySet aSlideProp( xSlide );
      81             : 
      82         182 :         aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
      83         182 :         aSlideProp.setProperties( aPropMap );
      84             : 
      85         364 :         return this;
      86             :     }
      87             :     case PPT_TOKEN( notes ):            // CT_NotesSlide
      88             :     {
      89             :         // Import notesMaster
      90          11 :         PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
      91          11 :         OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "notesMaster" );
      92             : 
      93          11 :         std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
      94          11 :         std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
      95          34 :         while( aIter != rMasterPages.end() )
      96             :         {
      97          12 :             if( (*aIter)->getPath() == aNotesFragmentPath )
      98             :             {
      99           0 :                 if( !mpSlidePersistPtr->getMasterPersist() )
     100           0 :                     mpSlidePersistPtr->setMasterPersist( *aIter );
     101           0 :                 break;
     102             :             }
     103          12 :             ++aIter;
     104             :         }
     105          11 :         if( aIter == rMasterPages.end() && !mpSlidePersistPtr->getMasterPersist() )
     106             :         {
     107          11 :             TextListStylePtr pTextListStyle(new TextListStyle);
     108             :             SlidePersistPtr pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, true, true, mpSlidePersistPtr->getPage(),
     109          22 :                                 ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr->getNotesTextStyle() ) );
     110          11 :             pMasterPersistPtr->setPath( aNotesFragmentPath );
     111          11 :             rFilter.getMasterPages().push_back( pMasterPersistPtr );
     112          22 :             FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
     113          11 :             rFilter.importFragment( xMasterFragmentHandler );
     114          22 :             mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
     115             :         }
     116          11 :         return this;
     117             :     }
     118             :     case PPT_TOKEN( notesMaster ):      // CT_NotesMaster
     119          11 :         return this;
     120             :     case PPT_TOKEN( cSld ):             // CT_CommonSlideData
     121         292 :         maSlideName = rAttribs.getString(XML_name, OUString());
     122         292 :         return this;
     123             : 
     124             :     case PPT_TOKEN( spTree ):           // CT_GroupShape
     125             :         {
     126             :             // TODO Convert this to FragmentHandler2
     127             :             return new PPTShapeGroupContext(
     128             :                 *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
     129         292 :                 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) );
     130             :         }
     131             :         break;
     132             : 
     133             :     case PPT_TOKEN( controls ):
     134           0 :         return this;
     135             :     case PPT_TOKEN( control ):
     136             :         {
     137           0 :             ::oox::vml::ControlInfo aInfo;
     138           0 :             aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
     139           0 :             aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     140           0 :             aInfo.maName = rAttribs.getXString( XML_name, OUString() );
     141           0 :             mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
     142             :         }
     143           0 :         return this;
     144             : 
     145             :     case PPT_TOKEN( timing ): // CT_SlideTiming
     146          35 :         return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
     147             :     case PPT_TOKEN( transition ): // CT_SlideTransition
     148          12 :         return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
     149             :     case PPT_TOKEN( hf ):
     150           7 :         return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
     151             : 
     152             :     // BackgroundGroup
     153             :     case PPT_TOKEN( bg ):
     154          88 :         return this;
     155             :     case PPT_TOKEN( bgPr ):             // CT_BackgroundProperties
     156             :         {
     157          39 :             FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
     158          39 :             mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
     159          39 :             return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
     160             :         }
     161           0 :         break;
     162             : 
     163             :     case PPT_TOKEN( bgRef ):            // a:CT_StyleMatrixReference
     164             :         {
     165          49 :             const FillProperties *pFillProperties = NULL;
     166          49 :             if( mpSlidePersistPtr->getTheme() )
     167          45 :                 pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
     168          49 :             FillPropertiesPtr pFillPropertiesPtr( pFillProperties ? new FillProperties( *pFillProperties ) : new FillProperties() );
     169          98 :             ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
     170          49 :             mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
     171          98 :             return ret;
     172             :         }
     173             :         break;
     174             : 
     175             :     case A_TOKEN( overrideClrMapping ):
     176             :     case PPT_TOKEN( clrMap ):           // CT_ColorMapping
     177             :         {
     178         103 :             oox::drawingml::ClrMapPtr pClrMapPtr( ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr.get() || !mpSlidePersistPtr->getClrMap().get() ) ? new oox::drawingml::ClrMap() : new oox::drawingml::ClrMap( *mpSlidePersistPtr->getClrMap() ) );
     179         206 :             ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
     180         103 :             mpSlidePersistPtr->setClrMap( pClrMapPtr );
     181         206 :             return ret;
     182             :         }
     183             :         break;
     184             :     case PPT_TOKEN( clrMapOvr ):        // CT_ColorMappingOverride
     185             :     case PPT_TOKEN( sldLayoutIdLst ):   // CT_SlideLayoutIdList
     186         215 :         return this;
     187             :     case PPT_TOKEN( txStyles ):         // CT_SlideMasterTextStyles
     188          56 :         return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
     189             :     case PPT_TOKEN( custDataLst ):      // CT_CustomerDataList
     190             :     case PPT_TOKEN( tagLst ):           // CT_TagList
     191           0 :         return this;
     192             : 
     193             :     //for Comments
     194             :     case PPT_TOKEN( cmLst ):
     195           0 :         break;
     196             :     case PPT_TOKEN( cm ):
     197           0 :         if(!mpSlidePersistPtr->getCommentsList().cmLst.empty())
     198             :         {
     199             :             // set comment text for earlier comment
     200           0 :             mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
     201             :         }
     202             :         // insert a new comment in vector commentsList
     203           0 :         mpSlidePersistPtr->getCommentsList().cmLst.push_back(Comment());
     204           0 :         mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString()));
     205           0 :         mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString()));
     206           0 :         mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));
     207           0 :         break;
     208             : 
     209             :     case PPT_TOKEN( pos ):
     210           0 :         mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
     211             :             rAttribs.getString(XML_x, OUString()),
     212           0 :             rAttribs.getString(XML_y, OUString()));
     213           0 :         break;
     214             : 
     215             :     case PPT_TOKEN( cmAuthor ):
     216           0 :         CommentAuthor _author;
     217           0 :         _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString());
     218           0 :         _author.id = rAttribs.getString(XML_id, OUString());
     219           0 :         _author.initials = rAttribs.getString(XML_initials, OUString());
     220           0 :         _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString());
     221           0 :         _author.name = rAttribs.getString(XML_name, OUString());
     222           0 :         mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
     223           0 :         break;
     224             :     }
     225             : 
     226        1996 :     return this;
     227             : }
     228           0 : void SlideFragmentHandler::onCharacters( const OUString& rChars)
     229             : {
     230           0 :     maCharVector.push_back(rChars);
     231           0 : }
     232         292 : void SlideFragmentHandler::finalizeImport()
     233             : {
     234             :     try
     235             :     {
     236         292 :         Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
     237         584 :         PropertySet aSlideProp( xSlide );
     238         292 :         aSlideProp.setProperties( maSlideProperties );
     239         292 :         if ( !maSlideName.isEmpty() )
     240             :         {
     241          88 :             Reference< XNamed > xNamed( xSlide, UNO_QUERY );
     242          88 :             if( xNamed.is() )
     243          88 :                 xNamed->setName( maSlideName );
     244         292 :         }
     245             :     }
     246           0 :     catch( uno::Exception& )
     247             :     {
     248             :         OSL_FAIL( OString("oox::ppt::SlideFragmentHandler::EndElement(), "
     249             :                     "exception caught: " +
     250             :             OUStringToOString(
     251             :                 comphelper::anyToString( cppu::getCaughtException() ),
     252             :                 RTL_TEXTENCODING_UTF8 )).getStr());
     253             :     }
     254         292 : }
     255             : 
     256         246 : } }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11