LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ppt - slidepersist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 156 70.5 %
Date: 2012-12-17 Functions: 9 10 90.0 %
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 "oox/ppt/timenode.hxx"
      21             : #include "oox/ppt/pptshape.hxx"
      22             : #include "oox/ppt/slidepersist.hxx"
      23             : #include "oox/drawingml/fillproperties.hxx"
      24             : #include "oox/drawingml/shapepropertymap.hxx"
      25             : #include "oox/helper/propertyset.hxx"
      26             : #include "oox/vml/vmldrawing.hxx"
      27             : #include "oox/core/xmlfilterbase.hxx"
      28             : 
      29             : #include <com/sun/star/style/XStyle.hpp>
      30             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      31             : #include <com/sun/star/container/XNamed.hpp>
      32             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      33             : #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::oox::core;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::drawing;
      39             : using namespace ::com::sun::star::container;
      40             : using namespace ::com::sun::star::animations;
      41             : 
      42             : namespace oox { namespace ppt {
      43             : 
      44          20 : SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes,
      45             :     const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
      46             :         oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
      47          20 : : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
      48             : , mxPage( rxPage )
      49             : , maShapesPtr( pShapesPtr )
      50             : , mnLayoutValueToken( 0 )
      51             : , mbMaster( bMaster )
      52             : , mbNotes ( bNotes )
      53             : , maDefaultTextStylePtr( pDefaultTextStyle )
      54          20 : , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
      55          20 : , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
      56          20 : , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
      57         100 : , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
      58             : {
      59          20 :     if ( pDefaultTextStyle )
      60             :     {
      61             :     /*
      62             :         maTitleTextStylePtr->apply( *pDefaultTextStyle.get() );
      63             :         maBodyTextStylePtr->apply( *pDefaultTextStyle.get() );
      64             :         maNotesTextStylePtr->apply( *pDefaultTextStyle.get() );
      65             :         maOtherTextStylePtr->apply( *pDefaultTextStyle.get() );
      66             :     */
      67             :     }
      68             : #if OSL_DEBUG_LEVEL > 0
      69             :     mxDebugPage = mxPage;
      70             : #endif
      71          20 : }
      72             : 
      73             : #if OSL_DEBUG_LEVEL > 0
      74             : ::com::sun::star::uno::WeakReference< ::com::sun::star::drawing::XDrawPage > SlidePersist::mxDebugPage;
      75             : #endif
      76             : 
      77          20 : SlidePersist::~SlidePersist()
      78             : {
      79          20 : }
      80             : 
      81           8 : sal_Int16 SlidePersist::getLayoutFromValueToken()
      82             : {
      83           8 :     sal_Int16 nLayout = 20;     // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
      84           8 :     switch( mnLayoutValueToken )
      85             :     {
      86           0 :         case XML_blank:             nLayout = 20; break;
      87           0 :         case XML_chart:             nLayout =  2; break;
      88           0 :         case XML_chartAndTx:        nLayout =  7; break;
      89           0 :         case XML_clipArtAndTx:      nLayout =  9; break;
      90           0 :         case XML_clipArtAndVertTx:  nLayout = 24; break;
      91           0 :         case XML_fourObj:           nLayout = 18; break;
      92           2 :         case XML_obj:               nLayout = 11; break;
      93           0 :         case XML_objAndTx:          nLayout = 13; break;
      94           0 :         case XML_objOverTx:         nLayout = 14; break;
      95           0 :         case XML_tbl:               nLayout =  8; break;
      96           2 :         case XML_title:             nLayout =  0; break;
      97           0 :         case XML_titleOnly:         nLayout = 19; break;
      98             :         case XML_twoObj:
      99           0 :         case XML_twoColTx:          nLayout =  3; break;
     100           0 :         case XML_twoObjAndTx:       nLayout = 15; break;
     101           0 :         case XML_twoObjOverTx:      nLayout = 16; break;
     102           2 :         case XML_tx:                nLayout =  1; break;
     103           0 :         case XML_txAndChart:        nLayout =  4; break;
     104           0 :         case XML_txAndClipArt:      nLayout =  6; break;
     105           0 :         case XML_txAndMedia:        nLayout =  6; break;
     106           0 :         case XML_txAndObj:          nLayout = 10; break;
     107           0 :         case XML_txAndTwoObj:       nLayout = 12; break;
     108           0 :         case XML_txOverObj:         nLayout = 17; break;
     109           0 :         case XML_vertTitleAndTx:    nLayout = 22; break;
     110           0 :         case XML_vertTitleAndTxOverChart: nLayout = 21; break;
     111           0 :         case XML_vertTx:            nLayout = 23; break;
     112             : 
     113             :         case XML_twoTxTwoObj:
     114             :         case XML_twoObjAndObj:
     115             :         case XML_objTx:
     116             :         case XML_picTx:
     117             :         case XML_secHead:
     118             :         case XML_objOnly:
     119             :         case XML_objAndTwoObj:
     120             :         case XML_mediaAndTx:
     121             :         case XML_dgm:
     122             :         case XML_cust:
     123             :         default:
     124           2 :             nLayout = 20;
     125             :     }
     126           8 :     return nLayout;
     127             : }
     128             : 
     129          18 : void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
     130             : {
     131          18 :     applyTextStyles( rFilterBase );
     132             : 
     133          18 :     Reference< XShapes > xShapes( getPage(), UNO_QUERY );
     134             : 
     135          18 :     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
     136          18 :     std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
     137          62 :     while( aShapesIter != rShapes.end() )
     138             :     {
     139          26 :         std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
     140          26 :         std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
     141         138 :         while( aChildIter != rChildren.end() )
     142             :         {
     143          86 :             PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
     144          86 :             basegfx::B2DHomMatrix aTransformation;
     145          86 :             if ( pPPTShape )
     146          86 :                 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, 0, &getShapeMap() );
     147             :             else
     148           0 :                 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, 0, &getShapeMap() );
     149          86 :             aChildIter++;
     150          86 :         }
     151             :     }
     152             : 
     153          18 :     Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
     154          18 :     if( xNodeSupplier.is() )
     155             :     {
     156          16 :         Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
     157          16 :         if( xNode.is() && !maTimeNodeList.empty() )
     158             :         {
     159           0 :             SlidePersistPtr pSlidePtr( shared_from_this() );
     160           0 :             TimeNodePtr pNode(maTimeNodeList.front());
     161             :             OSL_ENSURE( pNode, "pNode" );
     162             : 
     163           0 :             pNode->setNode( rFilterBase, xNode, pSlidePtr );
     164          16 :         }
     165          18 :     }
     166          18 : }
     167             : 
     168          18 : void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
     169             : {
     170          18 :     if ( mpBackgroundPropertiesPtr )
     171             :     {
     172           6 :         sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
     173           6 :             maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
     174             : 
     175           6 :         ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
     176           6 :         mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
     177           6 :         PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
     178             :     }
     179          18 : }
     180             : 
     181         128 : void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
     182             :     oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
     183             : {
     184         128 :     ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
     185         128 :     if( pTextParagraphPropertiesPtr == NULL )
     186             :     {
     187             :         // no properties. return
     188         128 :         return;
     189             :     }
     190             : 
     191         128 :     PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
     192             : 
     193         128 :     PropertySet aPropSet( rxPropSet );
     194         128 :     aPropSet.setProperties( rTextParagraphPropertyMap );
     195         128 :     pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
     196             : }
     197             : 
     198          18 : void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
     199             : {
     200          18 :     if ( mbMaster )
     201             :     {
     202             :         try
     203             :         {
     204           8 :             Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
     205           8 :             Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
     206           8 :             Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
     207             : 
     208           8 :             if ( aXNameAccess.is() && aXNamed.is() )
     209             :             {
     210           8 :                 oox::drawingml::TextListStylePtr pTextListStylePtr;
     211           8 :                 rtl::OUString aStyle;
     212           8 :                 rtl::OUString aFamily;
     213             : 
     214           8 :                 const rtl::OUString sOutline( RTL_CONSTASCII_USTRINGPARAM( "outline1" ) );
     215           8 :                 const rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "title" ) );
     216           8 :                 const rtl::OUString sStandard( RTL_CONSTASCII_USTRINGPARAM( "standard" ) );
     217           8 :                 const rtl::OUString sSubtitle( RTL_CONSTASCII_USTRINGPARAM( "subtitle" ) );
     218             : 
     219          40 :                 for( int i = 0; i < 4; i++ )    // todo: aggregation of bodystyle (subtitle)
     220             :                 {
     221          32 :                     switch( i )
     222             :                     {
     223             :                         case 0 :    // title style
     224             :                         {
     225           8 :                             pTextListStylePtr = maTitleTextStylePtr;
     226           8 :                             aStyle = sTitle;
     227           8 :                             aFamily= aXNamed->getName();
     228           8 :                             break;
     229             :                         }
     230             :                         case 1 :    // body style
     231             :                         {
     232           8 :                             pTextListStylePtr = maBodyTextStylePtr;
     233           8 :                             aStyle = sOutline;
     234           8 :                             aFamily= aXNamed->getName();
     235           8 :                             break;
     236             :                         }
     237             :                         case 3 :    // notes style
     238             :                         {
     239           8 :                             pTextListStylePtr = maNotesTextStylePtr;
     240           8 :                             aStyle = sTitle;
     241           8 :                             aFamily= aXNamed->getName();
     242           8 :                             break;
     243             :                         }
     244             :                         case 4 :    // standard style
     245             :                         {
     246           0 :                             pTextListStylePtr = maOtherTextStylePtr;
     247           0 :                             aStyle = sStandard;
     248           0 :                             aFamily = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
     249           0 :                             break;
     250             :                         }
     251             :                         case 5 :    // subtitle
     252             :                         {
     253           0 :                             pTextListStylePtr = maBodyTextStylePtr;
     254           0 :                             aStyle = sSubtitle;
     255           0 :                             aFamily = aXNamed->getName();
     256           0 :                             break;
     257             :                         }
     258             :                     }
     259          32 :                     Reference< container::XNameAccess > xFamilies;
     260          32 :                     if ( aXNameAccess->hasByName( aFamily ) )
     261             :                     {
     262          32 :                         if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
     263             :                         {
     264          32 :                             if ( xFamilies->hasByName( aStyle ) )
     265             :                             {
     266          32 :                                 Reference< style::XStyle > aXStyle;
     267          32 :                                 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
     268             :                                 {
     269          32 :                                     Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
     270          32 :                                     setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
     271          32 :                                     setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
     272          32 :                                     if ( i == 1 /* BodyStyle */ )
     273             :                                     {
     274          40 :                                         for ( int nLevel = 1; nLevel < 5; nLevel++ )
     275             :                                         {
     276             :                                             {
     277          32 :                                                 sal_Char pOutline[ 9 ] = "outline1";
     278          32 :                                                 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
     279          32 :                                                 rtl::OUString sOutlineStyle( rtl::OUString::createFromAscii( pOutline ) );
     280          32 :                                                 if ( xFamilies->hasByName( sOutlineStyle ) )
     281             :                                                 {
     282          32 :                                                     xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
     283          32 :                                                     if( aXStyle.is() )
     284          32 :                                                         xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
     285          32 :                                                 }
     286             :                                             }
     287          32 :                                             setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
     288          32 :                                             setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
     289             :                                         }
     290          32 :                                     }
     291          32 :                                 }
     292             :                             }
     293             :                         }
     294             :                     }
     295          40 :                 }
     296           8 :             }
     297             :         }
     298           0 :         catch( const Exception& )
     299             :         {
     300             :         }
     301             :     }
     302          18 : }
     303             : 
     304           0 : void SlidePersist::hideShapesAsMasterShapes()
     305             : {
     306           0 :     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
     307           0 :     std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
     308           0 :     while( aShapesIter != rShapes.end() )
     309             :     {
     310           0 :         while( aShapesIter != rShapes.end() )
     311             :         {
     312           0 :             std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
     313           0 :             std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
     314           0 :             while( aChildIter != rChildren.end() ) {
     315           0 :                 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter++).get() );
     316             :                 OSL_TRACE("hide shape with id: %s", rtl::OUStringToOString(pPPTShape->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
     317           0 :                 pPPTShape->setHiddenMasterShape( true );
     318             :             }
     319             :         }
     320             :     }
     321           0 : }
     322             : 
     323         174 : } }
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10