LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ppt - pptshapecontext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 96 101 95.0 %
Date: 2012-12-27 Functions: 6 6 100.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 <com/sun/star/xml/sax/FastToken.hpp>
      21             : #include <com/sun/star/drawing/LineStyle.hpp>
      22             : #include <com/sun/star/beans/XMultiPropertySet.hpp>
      23             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      24             : #include <com/sun/star/container/XNamed.hpp>
      25             : 
      26             : #include "oox/helper/attributelist.hxx"
      27             : #include "oox/ppt/pptshape.hxx"
      28             : #include "oox/ppt/pptshapecontext.hxx"
      29             : #include "oox/ppt/pptshapepropertiescontext.hxx"
      30             : #include "oox/ppt/slidepersist.hxx"
      31             : #include "oox/drawingml/shapestylecontext.hxx"
      32             : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
      33             : #include "oox/drawingml/lineproperties.hxx"
      34             : #include "oox/drawingml/drawingmltypes.hxx"
      35             : #include "oox/drawingml/customshapegeometry.hxx"
      36             : #include "oox/drawingml/textbodycontext.hxx"
      37             : #include "oox/drawingml/transform2dcontext.hxx"
      38             : 
      39             : using rtl::OUString;
      40             : using namespace oox::core;
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::drawing;
      44             : using namespace ::com::sun::star::beans;
      45             : using namespace ::com::sun::star::text;
      46             : using namespace ::com::sun::star::xml::sax;
      47             : 
      48             : namespace oox { namespace ppt {
      49             : 
      50             : // CT_Shape
      51          44 : PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
      52             : : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      53          44 : , mpSlidePersistPtr( pSlidePersistPtr )
      54             : {
      55          44 : }
      56             : 
      57         121 : oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      58             : {
      59         121 :     oox::drawingml::ShapePtr aShapePtr;
      60         121 :     oox::drawingml::ShapePtr aChoiceShapePtr1;
      61         121 :     oox::drawingml::ShapePtr aChoiceShapePtr2;
      62         121 :     std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
      63         330 :     while( aRevIter != rShapes.rend() )
      64             :     {
      65         109 :         if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
      66             :         {
      67          15 :             if( !oSubTypeIndex.has() && aChoiceShapePtr1 == NULL )
      68           7 :                 aChoiceShapePtr1 = *aRevIter;
      69           8 :             else if( aChoiceShapePtr2 == NULL )
      70           8 :                 aChoiceShapePtr2 = *aRevIter;
      71          15 :             if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
      72             :             {
      73           6 :                 aShapePtr = *aRevIter;
      74           6 :                 break;
      75             :             }
      76             :         }
      77         103 :         std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
      78         103 :         aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
      79         103 :         if ( aShapePtr.get() )
      80          15 :             break;
      81          88 :         ++aRevIter;
      82             :     }
      83         121 :     if( aShapePtr == NULL )
      84         100 :         return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
      85          21 :     return aShapePtr;
      86             : }
      87             : 
      88             : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
      89          16 : oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
      90             :     const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      91             : {
      92          16 :     oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
      93          16 :     return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
      94             : }
      95             : 
      96         347 : Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
      97             : {
      98         347 :     Reference< XFastContextHandler > xRet;
      99         347 :     if( getNamespace( aElementToken ) == NMSP_dsp )
     100           0 :         aElementToken = NMSP_ppt | getBaseToken( aElementToken );
     101             : 
     102         347 :     switch( aElementToken )
     103             :     {
     104             :         // nvSpPr CT_ShapeNonVisual begin
     105             :         //  case PPT_TOKEN( drElemPr ):
     106             :         //      break;
     107             :         case PPT_TOKEN( cNvPr ):
     108             :         {
     109          44 :             AttributeList aAttribs( xAttribs );
     110          44 :             mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
     111          44 :             mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
     112          44 :             mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
     113          44 :             break;
     114             :         }
     115             :         case PPT_TOKEN( ph ):
     116             :         {
     117          42 :             sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
     118          42 :             mpShapePtr->setSubType( nSubType );
     119          42 :             if( xAttribs->hasAttribute( XML_idx ) )
     120          26 :                 mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
     121          42 :             if ( nSubType )
     122             :             {
     123          42 :                 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
     124          42 :                 if ( pPPTShapePtr )
     125             :                 {
     126          42 :                     oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
     127          42 :                     if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
     128             :                     {
     129             :                         // inheriting properties from placeholder objects by cloning shape
     130          19 :                         sal_Int32 nFirstPlaceholder = 0;
     131          19 :                         sal_Int32 nSecondPlaceholder = 0;
     132          19 :                         switch( nSubType )
     133             :                         {
     134             :                             case XML_ctrTitle :     // slide/layout
     135           1 :                                   nFirstPlaceholder = XML_ctrTitle;
     136           1 :                                   nSecondPlaceholder = XML_title;
     137           1 :                               break;
     138             : 
     139             :                               case XML_subTitle :       // slide/layout
     140           2 :                                   nFirstPlaceholder = XML_subTitle;
     141           2 :                                   nSecondPlaceholder = XML_title;
     142           2 :                               break;
     143             : 
     144             :                              case XML_obj :         // slide/layout
     145           2 :                                   nFirstPlaceholder = XML_obj;
     146           2 :                                   nSecondPlaceholder = XML_body;
     147           2 :                               break;
     148             : 
     149             :                             case XML_dt :           // slide/layout/master/notes/notesmaster/handoutmaster
     150             :                               case XML_sldNum :     // slide/layout/master/notes/notesmaster/handoutmaster
     151             :                               case XML_ftr :            // slide/layout/master/notes/notesmaster/handoutmaster
     152             :                               case XML_hdr :            // notes/notesmaster/handoutmaster
     153             :                               case XML_body :           // slide/layout/master/notes/notesmaster
     154             :                               case XML_title :      // slide/layout/master/
     155             :                               case XML_chart :      // slide/layout
     156             :                               case XML_tbl :            // slide/layout
     157             :                               case XML_clipArt :        // slide/layout
     158             :                               case XML_dgm :            // slide/layout
     159             :                               case XML_media :      // slide/layout
     160             :                               case XML_sldImg :     // notes/notesmaster
     161             :                               case XML_pic :            // slide/layout
     162          14 :                                   nFirstPlaceholder = nSubType;
     163             :                               default:
     164          14 :                                   break;
     165             :                         }
     166          19 :                           if ( nFirstPlaceholder )
     167             :                           {
     168          19 :                               oox::drawingml::ShapePtr pPlaceholder;
     169          19 :                               if ( eShapeLocation == Layout )       // for layout objects the referenced object can be found within the same shape tree
     170             :                               {
     171          12 :                                   if( pPPTShapePtr->getSubTypeIndex().has() )
     172           7 :                                       pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
     173          12 :                                   if ( !pPlaceholder.get() )
     174          10 :                                       pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
     175          20 :                                                                       mpSlidePersistPtr->getShapes()->getChildren() );
     176             :                               }
     177           7 :                               else if ( eShapeLocation == Slide )   // normal slide shapes have to search within the corresponding master tree for referenced objects
     178             :                               {
     179           7 :                                   SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
     180           7 :                                   if ( pMasterPersist.get() ) {
     181           7 :                                       if( pPPTShapePtr->getSubTypeIndex().has() )
     182           5 :                                           pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
     183             :                                       // TODO: Check if this is required for non-notes pages as well...
     184           8 :                                       if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
     185           1 :                                                                                                      pPlaceholder->getSubType() != nSecondPlaceholder ) )
     186             :                                       {
     187             :                                           pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
     188           6 :                                                                           pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
     189             :                                       }
     190           7 :                                   }
     191             :                               }
     192          19 :                               if ( pPlaceholder.get() )
     193             :                               {
     194             :                                   OSL_TRACE("shape %s will get shape reference %s applied", rtl::OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
     195          18 :                                   mpShapePtr->applyShapeReference( *pPlaceholder.get() );
     196          18 :                                   PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
     197          18 :                                   if ( pPPTShape )
     198          18 :                                       pPPTShape->setReferenced( sal_True );
     199          18 :                                   pPPTShapePtr->setPlaceholder( pPlaceholder );
     200          19 :                               }
     201             :                           }
     202             :                     }
     203             :                   }
     204             : 
     205             :               }
     206          42 :               break;
     207             :         }
     208             : 
     209             :         // nvSpPr CT_ShapeNonVisual end
     210             : 
     211             :         case PPT_TOKEN( spPr ):
     212          44 :             xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
     213          44 :             break;
     214             : 
     215             :         case PPT_TOKEN( style ):
     216           0 :             xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
     217           0 :             break;
     218             : 
     219             :         case PPT_TOKEN( txBody ):
     220             :         {
     221          43 :             oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
     222          43 :             xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
     223          43 :             mpShapePtr->setTextBody( xTextBody );
     224          43 :             xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
     225          43 :             break;
     226             :         }
     227             :         case PPT_TOKEN( txXfrm ):
     228             :         {
     229           0 :             xRet = new oox::drawingml::Transform2DContext( *this, xAttribs, *mpShapePtr, true );
     230           0 :             break;
     231             :         }
     232             :     }
     233             : 
     234         347 :     if( !xRet.is() )
     235         260 :         xRet.set( this );
     236             : 
     237         347 :     return xRet;
     238             : }
     239             : 
     240             : 
     241          51 : } }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10