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

Generated by: LCOV version 1.10