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-17 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          88 : PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
      52             : : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
      53          88 : , mpSlidePersistPtr( pSlidePersistPtr )
      54             : {
      55          88 : }
      56             : 
      57         242 : oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      58             : {
      59         242 :     oox::drawingml::ShapePtr aShapePtr;
      60         242 :     oox::drawingml::ShapePtr aChoiceShapePtr1;
      61         242 :     oox::drawingml::ShapePtr aChoiceShapePtr2;
      62         242 :     std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
      63         660 :     while( aRevIter != rShapes.rend() )
      64             :     {
      65         218 :         if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
      66             :         {
      67          30 :             if( !oSubTypeIndex.has() && aChoiceShapePtr1 == NULL )
      68          14 :                 aChoiceShapePtr1 = *aRevIter;
      69          16 :             else if( aChoiceShapePtr2 == NULL )
      70          16 :                 aChoiceShapePtr2 = *aRevIter;
      71          30 :             if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
      72             :             {
      73          12 :                 aShapePtr = *aRevIter;
      74          12 :                 break;
      75             :             }
      76             :         }
      77         206 :         std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
      78         206 :         aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
      79         206 :         if ( aShapePtr.get() )
      80          30 :             break;
      81         176 :         ++aRevIter;
      82             :     }
      83         242 :     if( aShapePtr == NULL )
      84         200 :         return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
      85          42 :     return aShapePtr;
      86             : }
      87             : 
      88             : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
      89          32 : oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
      90             :     const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
      91             : {
      92          32 :     oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
      93          32 :     return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
      94             : }
      95             : 
      96         694 : Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
      97             : {
      98         694 :     Reference< XFastContextHandler > xRet;
      99         694 :     if( getNamespace( aElementToken ) == NMSP_dsp )
     100           0 :         aElementToken = NMSP_ppt | getBaseToken( aElementToken );
     101             : 
     102         694 :     switch( aElementToken )
     103             :     {
     104             :         // nvSpPr CT_ShapeNonVisual begin
     105             :         //  case PPT_TOKEN( drElemPr ):
     106             :         //      break;
     107             :         case PPT_TOKEN( cNvPr ):
     108             :         {
     109          88 :             AttributeList aAttribs( xAttribs );
     110          88 :             mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
     111          88 :             mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
     112          88 :             mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
     113          88 :             break;
     114             :         }
     115             :         case PPT_TOKEN( ph ):
     116             :         {
     117          84 :             sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
     118          84 :             mpShapePtr->setSubType( nSubType );
     119          84 :             if( xAttribs->hasAttribute( XML_idx ) )
     120          52 :                 mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
     121          84 :             if ( nSubType )
     122             :             {
     123          84 :                 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
     124          84 :                 if ( pPPTShapePtr )
     125             :                 {
     126          84 :                     oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
     127          84 :                     if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
     128             :                     {
     129             :                         // inheriting properties from placeholder objects by cloning shape
     130          38 :                         sal_Int32 nFirstPlaceholder = 0;
     131          38 :                         sal_Int32 nSecondPlaceholder = 0;
     132          38 :                         switch( nSubType )
     133             :                         {
     134             :                             case XML_ctrTitle :     // slide/layout
     135           2 :                                   nFirstPlaceholder = XML_ctrTitle;
     136           2 :                                   nSecondPlaceholder = XML_title;
     137           2 :                               break;
     138             : 
     139             :                               case XML_subTitle :       // slide/layout
     140           4 :                                   nFirstPlaceholder = XML_subTitle;
     141           4 :                                   nSecondPlaceholder = XML_title;
     142           4 :                               break;
     143             : 
     144             :                              case XML_obj :         // slide/layout
     145           4 :                                   nFirstPlaceholder = XML_obj;
     146           4 :                                   nSecondPlaceholder = XML_body;
     147           4 :                               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          28 :                                   nFirstPlaceholder = nSubType;
     163             :                               default:
     164          28 :                                   break;
     165             :                         }
     166          38 :                           if ( nFirstPlaceholder )
     167             :                           {
     168          38 :                               oox::drawingml::ShapePtr pPlaceholder;
     169          38 :                               if ( eShapeLocation == Layout )       // for layout objects the referenced object can be found within the same shape tree
     170             :                               {
     171          24 :                                   if( pPPTShapePtr->getSubTypeIndex().has() )
     172          14 :                                       pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
     173          24 :                                   if ( !pPlaceholder.get() )
     174          20 :                                       pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
     175          40 :                                                                       mpSlidePersistPtr->getShapes()->getChildren() );
     176             :                               }
     177          14 :                               else if ( eShapeLocation == Slide )   // normal slide shapes have to search within the corresponding master tree for referenced objects
     178             :                               {
     179          14 :                                   SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
     180          14 :                                   if ( pMasterPersist.get() ) {
     181          14 :                                       if( pPPTShapePtr->getSubTypeIndex().has() )
     182          10 :                                           pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
     183             :                                       // TODO: Check if this is required for non-notes pages as well...
     184          16 :                                       if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
     185           2 :                                                                                                      pPlaceholder->getSubType() != nSecondPlaceholder ) )
     186             :                                       {
     187             :                                           pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
     188          12 :                                                                           pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
     189             :                                       }
     190          14 :                                   }
     191             :                               }
     192          38 :                               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          36 :                                   mpShapePtr->applyShapeReference( *pPlaceholder.get() );
     196          36 :                                   PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
     197          36 :                                   if ( pPPTShape )
     198          36 :                                       pPPTShape->setReferenced( sal_True );
     199          36 :                                   pPPTShapePtr->setPlaceholder( pPlaceholder );
     200          38 :                               }
     201             :                           }
     202             :                     }
     203             :                   }
     204             : 
     205             :               }
     206          84 :               break;
     207             :         }
     208             : 
     209             :         // nvSpPr CT_ShapeNonVisual end
     210             : 
     211             :         case PPT_TOKEN( spPr ):
     212          88 :             xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
     213          88 :             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          86 :             oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
     222          86 :             xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
     223          86 :             mpShapePtr->setTextBody( xTextBody );
     224          86 :             xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
     225          86 :             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         694 :     if( !xRet.is() )
     235         520 :         xRet.set( this );
     236             : 
     237         694 :     return xRet;
     238             : }
     239             : 
     240             : 
     241         174 : } }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10